-
Notifications
You must be signed in to change notification settings - Fork 680
/
Copy pathjerryscript-core.h
859 lines (757 loc) · 34.7 KB
/
jerryscript-core.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JERRYSCRIPT_CORE_H
#define JERRYSCRIPT_CORE_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "jerryscript-compiler.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
/** \addtogroup jerry Jerry engine interface
* @{
*/
/**
* Major version of JerryScript API.
*/
#define JERRY_API_MAJOR_VERSION 2
/**
* Minor version of JerryScript API.
*/
#define JERRY_API_MINOR_VERSION 4
/**
* Patch version of JerryScript API.
*/
#define JERRY_API_PATCH_VERSION 0
/**
* JerryScript init flags.
*/
typedef enum
{
JERRY_INIT_EMPTY = (0u), /**< empty flag set */
JERRY_INIT_SHOW_OPCODES = (1u << 0), /**< dump byte-code to log after parse */
JERRY_INIT_SHOW_REGEXP_OPCODES = (1u << 1), /**< dump regexp byte-code to log after compilation */
JERRY_INIT_MEM_STATS = (1u << 2), /**< dump memory statistics */
JERRY_INIT_MEM_STATS_SEPARATE = (1u << 3), /**< deprecated, an unused placeholder now */
JERRY_INIT_DEBUGGER = (1u << 4), /**< deprecated, an unused placeholder now */
} jerry_init_flag_t;
/**
* JerryScript API Error object types.
*/
typedef enum
{
JERRY_ERROR_NONE = 0, /**< No Error */
JERRY_ERROR_COMMON, /**< Error */
JERRY_ERROR_EVAL, /**< EvalError */
JERRY_ERROR_RANGE, /**< RangeError */
JERRY_ERROR_REFERENCE, /**< ReferenceError */
JERRY_ERROR_SYNTAX, /**< SyntaxError */
JERRY_ERROR_TYPE, /**< TypeError */
JERRY_ERROR_URI /**< URIError */
} jerry_error_t;
/**
* JerryScript feature types.
*/
typedef enum
{
JERRY_FEATURE_CPOINTER_32_BIT, /**< 32 bit compressed pointers */
JERRY_FEATURE_ERROR_MESSAGES, /**< error messages */
JERRY_FEATURE_JS_PARSER, /**< js-parser */
JERRY_FEATURE_MEM_STATS, /**< memory statistics */
JERRY_FEATURE_PARSER_DUMP, /**< parser byte-code dumps */
JERRY_FEATURE_REGEXP_DUMP, /**< regexp byte-code dumps */
JERRY_FEATURE_SNAPSHOT_SAVE, /**< saving snapshot files */
JERRY_FEATURE_SNAPSHOT_EXEC, /**< executing snapshot files */
JERRY_FEATURE_DEBUGGER, /**< debugging */
JERRY_FEATURE_VM_EXEC_STOP, /**< stopping ECMAScript execution */
JERRY_FEATURE_JSON, /**< JSON support */
JERRY_FEATURE_PROMISE, /**< promise support */
JERRY_FEATURE_TYPEDARRAY, /**< Typedarray support */
JERRY_FEATURE_DATE, /**< Date support */
JERRY_FEATURE_REGEXP, /**< Regexp support */
JERRY_FEATURE_LINE_INFO, /**< line info available */
JERRY_FEATURE_LOGGING, /**< logging */
JERRY_FEATURE_SYMBOL, /**< symbol support */
JERRY_FEATURE_DATAVIEW, /**< DataView support */
JERRY_FEATURE_PROXY, /**< Proxy support */
JERRY_FEATURE_MAP, /**< Map support */
JERRY_FEATURE_SET, /**< Set support */
JERRY_FEATURE_WEAKMAP, /**< WeakMap support */
JERRY_FEATURE_WEAKSET, /**< WeakSet support */
JERRY_FEATURE_BIGINT, /**< BigInt support */
JERRY_FEATURE_REALM, /**< realm support */
JERRY_FEATURE__COUNT /**< number of features. NOTE: must be at the end of the list */
} jerry_feature_t;
/**
* Option flags for jerry_parse and jerry_parse_function functions.
*/
typedef enum
{
JERRY_PARSE_NO_OPTS = 0, /**< no options passed */
JERRY_PARSE_STRICT_MODE = (1 << 0) /**< enable strict mode */
} jerry_parse_opts_t;
/**
* GC operational modes.
*/
typedef enum
{
JERRY_GC_PRESSURE_LOW, /**< free unused objects, but keep memory
* allocated for performance improvements
* such as property hash tables for large objects */
JERRY_GC_PRESSURE_HIGH /**< free as much memory as possible */
} jerry_gc_mode_t;
/**
* Jerry regexp flags.
*/
typedef enum
{
JERRY_REGEXP_FLAG_GLOBAL = (1u << 1), /**< Globally scan string */
JERRY_REGEXP_FLAG_IGNORE_CASE = (1u << 2), /**< Ignore case */
JERRY_REGEXP_FLAG_MULTILINE = (1u << 3), /**< Multiline string scan */
JERRY_REGEXP_FLAG_STICKY = (1u << 4), /**< ECMAScript v11, 21.2.5.14 */
JERRY_REGEXP_FLAG_UNICODE = (1u << 5), /**< ECMAScript v11, 21.2.5.17 */
JERRY_REGEXP_FLAG_DOTALL = (1u << 6) /**< ECMAScript v11, 21.2.5.3 */
} jerry_regexp_flags_t;
/**
* Character type of JerryScript.
*/
typedef uint8_t jerry_char_t;
/**
* Size type of JerryScript.
*/
typedef uint32_t jerry_size_t;
/**
* Length type of JerryScript.
*/
typedef uint32_t jerry_length_t;
/**
* Description of a JerryScript value.
*/
typedef uint32_t jerry_value_t;
/**
* Description of ECMA property descriptor.
*/
typedef struct
{
/** Is [[Value]] defined? */
bool is_value_defined;
/** Is [[Get]] defined? */
bool is_get_defined;
/** Is [[Set]] defined? */
bool is_set_defined;
/** Is [[Writable]] defined? */
bool is_writable_defined;
/** [[Writable]] */
bool is_writable;
/** Is [[Enumerable]] defined? */
bool is_enumerable_defined;
/** [[Enumerable]] */
bool is_enumerable;
/** Is [[Configurable]] defined? */
bool is_configurable_defined;
/** [[Configurable]] */
bool is_configurable;
/** Is data accessor property */
bool is_data_accessor;
/** [[Value]] */
jerry_value_t value;
/** [[Get]] */
jerry_value_t getter;
/** [[Set]] */
jerry_value_t setter;
} jerry_property_descriptor_t;
/**
* Description of JerryScript heap memory stats.
* It is for memory profiling.
*/
typedef struct
{
size_t version; /**< the version of the stats struct */
size_t size; /**< heap total size */
size_t allocated_bytes; /**< currently allocated bytes */
size_t peak_allocated_bytes; /**< peak allocated bytes */
size_t reserved[4]; /**< padding for future extensions */
} jerry_heap_stats_t;
/**
* Type of an external function handler.
*/
typedef jerry_value_t (*jerry_external_handler_t) (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_count);
/**
* Native free callback of an object.
*/
typedef void (*jerry_object_native_free_callback_t) (void *native_p);
/**
* Callback which tells whether the ECMAScript execution should be stopped.
*
* As long as the function returns with undefined the execution continues.
* When a non-undefined value is returned the execution stops and the value
* is thrown by the engine (if the error flag is not set for the returned
* value the engine automatically sets it).
*
* Note: if the function returns with a non-undefined value it
* must return with the same value for future calls.
*/
typedef jerry_value_t (*jerry_vm_exec_stop_callback_t) (void *user_p);
/**
* Function type applied for each data property of an object.
*/
typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name,
const jerry_value_t property_value,
void *user_data_p);
/**
* Function type applied for each object in the engine.
*/
typedef bool (*jerry_objects_foreach_t) (const jerry_value_t object,
void *user_data_p);
/**
* Function type applied for each matching object in the engine.
*/
typedef bool (*jerry_objects_foreach_by_native_info_t) (const jerry_value_t object,
void *object_data_p,
void *user_data_p);
/**
* User context item manager
*/
typedef struct
{
/**
* Callback responsible for initializing a context item, or NULL to zero out the memory. This is called lazily, the
* first time jerry_get_context_data () is called with this manager.
*
* @param [in] data The buffer that JerryScript allocated for the manager. The buffer is zeroed out. The size is
* determined by the bytes_needed field. The buffer is kept alive until jerry_cleanup () is called.
*/
void (*init_cb) (void *data);
/**
* Callback responsible for deinitializing a context item, or NULL. This is called as part of jerry_cleanup (),
* right *before* the VM has been cleaned up. This is a good place to release strong references to jerry_value_t's
* that the manager may be holding.
* Note: because the VM has not been fully cleaned up yet, jerry_object_native_info_t free_cb's can still get called
* *after* all deinit_cb's have been run. See finalize_cb for a callback that is guaranteed to run *after* all
* free_cb's have been run.
*
* @param [in] data The buffer that JerryScript allocated for the manager.
*/
void (*deinit_cb) (void *data);
/**
* Callback responsible for finalizing a context item, or NULL. This is called as part of jerry_cleanup (),
* right *after* the VM has been cleaned up and destroyed and jerry_... APIs cannot be called any more. At this point,
* all values in the VM have been cleaned up. This is a good place to clean up native state that can only be cleaned
* up at the very end when there are no more VM values around that may need to access that state.
*
* @param [in] data The buffer that JerryScript allocated for the manager. After returning from this callback,
* the data pointer may no longer be used.
*/
void (*finalize_cb) (void *data);
/**
* Number of bytes to allocate for this manager. This is the size of the buffer that JerryScript will allocate on
* behalf of the manager. The pointer to this buffer is passed into init_cb, deinit_cb and finalize_cb. It is also
* returned from the jerry_get_context_data () API.
*/
size_t bytes_needed;
} jerry_context_data_manager_t;
/**
* Function type for allocating buffer for JerryScript context.
*/
typedef void *(*jerry_context_alloc_t) (size_t size, void *cb_data_p);
/**
* Type information of a native pointer.
*/
typedef struct
{
jerry_object_native_free_callback_t free_cb; /**< the free callback of the native pointer */
} jerry_object_native_info_t;
/**
* An opaque declaration of the JerryScript context structure.
*/
typedef struct jerry_context_t jerry_context_t;
/**
* Enum that contains the supported binary operation types
*/
typedef enum
{
JERRY_BIN_OP_EQUAL = 0u, /**< equal comparison (==) */
JERRY_BIN_OP_STRICT_EQUAL, /**< strict equal comparison (===) */
JERRY_BIN_OP_LESS, /**< less relation (<) */
JERRY_BIN_OP_LESS_EQUAL, /**< less or equal relation (<=) */
JERRY_BIN_OP_GREATER, /**< greater relation (>) */
JERRY_BIN_OP_GREATER_EQUAL, /**< greater or equal relation (>=)*/
JERRY_BIN_OP_INSTANCEOF, /**< instanceof operation */
JERRY_BIN_OP_ADD, /**< addition operator (+) */
JERRY_BIN_OP_SUB, /**< subtraction operator (-) */
JERRY_BIN_OP_MUL, /**< multiplication operator (*) */
JERRY_BIN_OP_DIV, /**< division operator (/) */
JERRY_BIN_OP_REM, /**< remainder operator (%) */
} jerry_binary_operation_t;
/**
* General engine functions.
*/
void jerry_init (jerry_init_flag_t flags);
void jerry_cleanup (void);
void jerry_register_magic_strings (const jerry_char_t * const *ex_str_items_p,
uint32_t count,
const jerry_length_t *str_lengths_p);
void jerry_gc (jerry_gc_mode_t mode);
void *jerry_get_context_data (const jerry_context_data_manager_t *manager_p);
bool jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p);
/**
* Parser and executor functions.
*/
bool jerry_run_simple (const jerry_char_t *script_source_p, size_t script_source_size, jerry_init_flag_t flags);
jerry_value_t jerry_parse (const jerry_char_t *resource_name_p, size_t resource_name_length,
const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
jerry_value_t jerry_parse_function (const jerry_char_t *resource_name_p, size_t resource_name_length,
const jerry_char_t *arg_list_p, size_t arg_list_size,
const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
jerry_value_t jerry_run (const jerry_value_t func_val);
jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
jerry_value_t jerry_run_all_enqueued_jobs (void);
/**
* Get the global context.
*/
jerry_value_t jerry_get_global_object (void);
/**
* Checker functions of 'jerry_value_t'.
*/
bool jerry_value_is_abort (const jerry_value_t value);
bool jerry_value_is_array (const jerry_value_t value);
bool jerry_value_is_boolean (const jerry_value_t value);
bool jerry_value_is_constructor (const jerry_value_t value);
bool jerry_value_is_error (const jerry_value_t value);
bool jerry_value_is_function (const jerry_value_t value);
bool jerry_value_is_async_function (const jerry_value_t value);
bool jerry_value_is_number (const jerry_value_t value);
bool jerry_value_is_null (const jerry_value_t value);
bool jerry_value_is_object (const jerry_value_t value);
bool jerry_value_is_promise (const jerry_value_t value);
bool jerry_value_is_proxy (const jerry_value_t value);
bool jerry_value_is_string (const jerry_value_t value);
bool jerry_value_is_symbol (const jerry_value_t value);
bool jerry_value_is_bigint (const jerry_value_t value);
bool jerry_value_is_undefined (const jerry_value_t value);
/**
* JerryScript API value type information.
*/
typedef enum
{
JERRY_TYPE_NONE = 0u, /**< no type information */
JERRY_TYPE_UNDEFINED, /**< undefined type */
JERRY_TYPE_NULL, /**< null type */
JERRY_TYPE_BOOLEAN, /**< boolean type */
JERRY_TYPE_NUMBER, /**< number type */
JERRY_TYPE_STRING, /**< string type */
JERRY_TYPE_OBJECT, /**< object type */
JERRY_TYPE_FUNCTION, /**< function type */
JERRY_TYPE_ERROR, /**< error/abort type */
JERRY_TYPE_SYMBOL, /**< symbol type */
JERRY_TYPE_BIGINT, /**< bigint type */
} jerry_type_t;
/**
* JerryScript object type information.
*/
typedef enum
{
JERRY_OBJECT_TYPE_NONE = 0u, /**< Non object type */
JERRY_OBJECT_TYPE_GENERIC, /**< Generic JavaScript object without any internal property */
JERRY_OBJECT_TYPE_ARRAY, /**< Array object */
JERRY_OBJECT_TYPE_PROXY, /**< Proxy object */
JERRY_OBJECT_TYPE_FUNCTION, /**< Function object (see jerry_function_get_type) */
JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_get_typedarray_type) */
JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_get_type) */
JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */
JERRY_OBJECT_TYPE_ARGUMENTS, /**< Arguments object */
JERRY_OBJECT_TYPE_BOOLEAN, /**< Boolean object */
JERRY_OBJECT_TYPE_DATE, /**< Date object */
JERRY_OBJECT_TYPE_NUMBER, /**< Number object */
JERRY_OBJECT_TYPE_REGEXP, /**< RegExp object */
JERRY_OBJECT_TYPE_STRING, /**< String object */
JERRY_OBJECT_TYPE_SYMBOL, /**< Symbol object */
JERRY_OBJECT_TYPE_GENERATOR, /**< Generator object */
JERRY_OBJECT_TYPE_BIGINT, /**< BigInt object */
} jerry_object_type_t;
/**
* JerryScript function object type information.
*/
typedef enum
{
JERRY_FUNCTION_TYPE_NONE = 0u, /**< Non function type */
JERRY_FUNCTION_TYPE_GENERIC, /**< Generic JavaScript function */
JERRY_FUNCTION_TYPE_ACCESSOR, /**< Accessor function */
JERRY_FUNCTION_TYPE_BOUND, /**< Bound function */
JERRY_FUNCTION_TYPE_ARROW, /**< Arrow fuction */
JERRY_FUNCTION_TYPE_GENERATOR, /**< Generator function */
} jerry_function_type_t;
/**
* JerryScript iterator object type information.
*/
typedef enum
{
JERRY_ITERATOR_TYPE_NONE = 0u, /**< Non iterator type */
JERRY_ITERATOR_TYPE_ARRAY, /**< Array iterator */
JERRY_ITERATOR_TYPE_STRING, /**< String iterator */
JERRY_ITERATOR_TYPE_MAP, /**< Map iterator */
JERRY_ITERATOR_TYPE_SET, /**< Set iterator */
} jerry_iterator_type_t;
/**
* JerryScript object property filter options.
*/
typedef enum
{
JERRY_PROPERTY_FILTER_ALL = 0, /**< List all property keys independently
* from key type or property value attributes
* (equivalent to Reflect.ownKeys call) */
JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN = (1 << 0), /**< Include keys from the objects's
* prototype chain as well */
JERRY_PROPERTY_FILTER_EXLCUDE_NON_CONFIGURABLE = (1 << 1), /**< Exclude property key if
* the property is non-configurable */
JERRY_PROPERTY_FILTER_EXLCUDE_NON_ENUMERABLE = (1 << 2), /**< Exclude property key if
* the property is non-enumerable */
JERRY_PROPERTY_FILTER_EXLCUDE_NON_WRITABLE = (1 << 3), /**< Exclude property key if
* the property is non-writable */
JERRY_PROPERTY_FILTER_EXLCUDE_STRINGS = (1 << 4), /**< Exclude property key if it is a string */
JERRY_PROPERTY_FILTER_EXLCUDE_SYMBOLS = (1 << 5), /**< Exclude property key if it is a symbol */
JERRY_PROPERTY_FILTER_EXLCUDE_INTEGER_INDICES = (1 << 6), /**< Exclude property key if it is an integer index */
JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER = (1 << 7), /**< By default integer index property keys are
* converted to string. Enabling this flags keeps
* integer index property keys as numbers. */
} jerry_property_filter_t;
jerry_type_t jerry_value_get_type (const jerry_value_t value);
jerry_object_type_t jerry_object_get_type (const jerry_value_t value);
jerry_function_type_t jerry_function_get_type (const jerry_value_t value);
jerry_iterator_type_t jerry_iterator_get_type (const jerry_value_t value);
/**
* Checker function of whether the specified compile feature is enabled.
*/
bool jerry_is_feature_enabled (const jerry_feature_t feature);
/**
* Binary operations
*/
jerry_value_t jerry_binary_operation (jerry_binary_operation_t op,
const jerry_value_t lhs,
const jerry_value_t rhs);
/**
* Error manipulation functions.
*/
jerry_value_t jerry_create_abort_from_value (jerry_value_t value, bool release);
jerry_value_t jerry_create_error_from_value (jerry_value_t value, bool release);
jerry_value_t jerry_get_value_from_error (jerry_value_t value, bool release);
/**
* Error object function(s).
*/
jerry_error_t jerry_get_error_type (jerry_value_t value);
/**
* Getter functions of 'jerry_value_t'.
*/
bool jerry_get_boolean_value (const jerry_value_t value);
double jerry_get_number_value (const jerry_value_t value);
/**
* Functions for string values.
*/
jerry_size_t jerry_get_string_size (const jerry_value_t value);
jerry_size_t jerry_get_utf8_string_size (const jerry_value_t value);
jerry_length_t jerry_get_string_length (const jerry_value_t value);
jerry_length_t jerry_get_utf8_string_length (const jerry_value_t value);
jerry_size_t jerry_string_to_char_buffer (const jerry_value_t value, jerry_char_t *buffer_p, jerry_size_t buffer_size);
jerry_size_t jerry_string_to_utf8_char_buffer (const jerry_value_t value,
jerry_char_t *buffer_p,
jerry_size_t buffer_size);
jerry_size_t jerry_substring_to_char_buffer (const jerry_value_t value,
jerry_length_t start_pos,
jerry_length_t end_pos,
jerry_char_t *buffer_p,
jerry_size_t buffer_size);
jerry_size_t jerry_substring_to_utf8_char_buffer (const jerry_value_t value,
jerry_length_t start_pos,
jerry_length_t end_pos,
jerry_char_t *buffer_p,
jerry_size_t buffer_size);
/**
* Functions for array object values.
*/
uint32_t jerry_get_array_length (const jerry_value_t value);
/**
* Converters of 'jerry_value_t'.
*/
bool jerry_value_to_boolean (const jerry_value_t value);
jerry_value_t jerry_value_to_number (const jerry_value_t value);
jerry_value_t jerry_value_to_object (const jerry_value_t value);
jerry_value_t jerry_value_to_primitive (const jerry_value_t value);
jerry_value_t jerry_value_to_string (const jerry_value_t value);
jerry_value_t jerry_value_to_bigint (const jerry_value_t value);
double jerry_value_as_integer (const jerry_value_t value);
int32_t jerry_value_as_int32 (const jerry_value_t value);
uint32_t jerry_value_as_uint32 (const jerry_value_t value);
/**
* Acquire types with reference counter (increase the references).
*/
jerry_value_t jerry_acquire_value (jerry_value_t value);
/**
* Release the referenced values.
*/
void jerry_release_value (jerry_value_t value);
/**
* Create functions of API values.
*/
jerry_value_t jerry_create_array (uint32_t size);
jerry_value_t jerry_create_boolean (bool value);
jerry_value_t jerry_create_error (jerry_error_t error_type, const jerry_char_t *message_p);
jerry_value_t jerry_create_error_sz (jerry_error_t error_type, const jerry_char_t *message_p,
jerry_size_t message_size);
jerry_value_t jerry_create_external_function (jerry_external_handler_t handler_p);
jerry_value_t jerry_create_number (double value);
jerry_value_t jerry_create_number_infinity (bool sign);
jerry_value_t jerry_create_number_nan (void);
jerry_value_t jerry_create_null (void);
jerry_value_t jerry_create_object (void);
jerry_value_t jerry_create_promise (void);
jerry_value_t jerry_create_proxy (const jerry_value_t target, const jerry_value_t handler);
jerry_value_t jerry_create_regexp (const jerry_char_t *pattern, uint16_t flags);
jerry_value_t jerry_create_regexp_sz (const jerry_char_t *pattern, jerry_size_t pattern_size, uint16_t flags);
jerry_value_t jerry_create_string_from_utf8 (const jerry_char_t *str_p);
jerry_value_t jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p, jerry_size_t str_size);
jerry_value_t jerry_create_string (const jerry_char_t *str_p);
jerry_value_t jerry_create_string_sz (const jerry_char_t *str_p, jerry_size_t str_size);
jerry_value_t jerry_create_external_string (const jerry_char_t *str_p,
jerry_object_native_free_callback_t free_cb);
jerry_value_t jerry_create_external_string_sz (const jerry_char_t *str_p, jerry_size_t str_size,
jerry_object_native_free_callback_t free_cb);
jerry_value_t jerry_create_symbol (const jerry_value_t value);
jerry_value_t jerry_create_bigint (const uint64_t *digits_p, uint32_t size, bool sign);
jerry_value_t jerry_create_undefined (void);
jerry_value_t jerry_create_realm (void);
/**
* General API functions of JS objects.
*/
jerry_value_t jerry_has_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
jerry_value_t jerry_has_own_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
bool jerry_has_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
bool jerry_delete_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
bool jerry_delete_property_by_index (const jerry_value_t obj_val, uint32_t index);
bool jerry_delete_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
jerry_value_t jerry_get_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
jerry_value_t jerry_get_property_by_index (const jerry_value_t obj_val, uint32_t index);
jerry_value_t jerry_get_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val);
jerry_value_t jerry_set_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val,
const jerry_value_t value_to_set);
jerry_value_t jerry_set_property_by_index (const jerry_value_t obj_val, uint32_t index,
const jerry_value_t value_to_set);
bool jerry_set_internal_property (const jerry_value_t obj_val, const jerry_value_t prop_name_val,
const jerry_value_t value_to_set);
void jerry_init_property_descriptor_fields (jerry_property_descriptor_t *prop_desc_p);
jerry_value_t jerry_define_own_property (const jerry_value_t obj_val,
const jerry_value_t prop_name_val,
const jerry_property_descriptor_t *prop_desc_p);
bool jerry_get_own_property_descriptor (const jerry_value_t obj_val,
const jerry_value_t prop_name_val,
jerry_property_descriptor_t *prop_desc_p);
void jerry_free_property_descriptor_fields (const jerry_property_descriptor_t *prop_desc_p);
jerry_value_t jerry_call_function (const jerry_value_t func_obj_val, const jerry_value_t this_val,
const jerry_value_t args_p[], jerry_size_t args_count);
jerry_value_t jerry_construct_object (const jerry_value_t func_obj_val, const jerry_value_t args_p[],
jerry_size_t args_count);
jerry_value_t jerry_get_object_keys (const jerry_value_t obj_val);
jerry_value_t jerry_get_prototype (const jerry_value_t obj_val);
jerry_value_t jerry_set_prototype (const jerry_value_t obj_val, const jerry_value_t proto_obj_val);
bool jerry_get_object_native_pointer (const jerry_value_t obj_val,
void **out_native_pointer_p,
const jerry_object_native_info_t *native_pointer_info_p);
void jerry_set_object_native_pointer (const jerry_value_t obj_val,
void *native_pointer_p,
const jerry_object_native_info_t *native_info_p);
bool jerry_delete_object_native_pointer (const jerry_value_t obj_val,
const jerry_object_native_info_t *native_info_p);
bool jerry_objects_foreach (jerry_objects_foreach_t foreach_p,
void *user_data);
bool jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_info_p,
jerry_objects_foreach_by_native_info_t foreach_p,
void *user_data_p);
bool jerry_foreach_object_property (const jerry_value_t obj_val, jerry_object_property_foreach_t foreach_p,
void *user_data_p);
jerry_value_t jerry_object_get_property_names (const jerry_value_t obj_val, jerry_property_filter_t filter);
jerry_value_t jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc_p);
jerry_value_t jerry_to_property_descriptor (jerry_value_t obj_value, jerry_property_descriptor_t *out_prop_desc_p);
/**
* Promise functions.
*/
jerry_value_t jerry_resolve_or_reject_promise (jerry_value_t promise, jerry_value_t argument, bool is_resolve);
/**
* Enum values representing various Promise states.
*/
typedef enum
{
JERRY_PROMISE_STATE_NONE = 0u, /**< Invalid/Unknown state (possibly called on a non-promise object). */
JERRY_PROMISE_STATE_PENDING, /**< Promise is in "Pending" state. */
JERRY_PROMISE_STATE_FULFILLED, /**< Promise is in "Fulfilled" state. */
JERRY_PROMISE_STATE_REJECTED, /**< Promise is in "Rejected" state. */
} jerry_promise_state_t;
jerry_value_t jerry_get_promise_result (const jerry_value_t promise);
jerry_promise_state_t jerry_get_promise_state (const jerry_value_t promise);
/**
* Symbol functions.
*/
/**
* List of well-known symbols.
*/
typedef enum
{
JERRY_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well-known symbol */
JERRY_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well-known symbol */
JERRY_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well-known symbol */
JERRY_SYMBOL_ITERATOR, /**< @@iterator well-known symbol */
JERRY_SYMBOL_MATCH, /**< @@match well-known symbol */
JERRY_SYMBOL_REPLACE, /**< @@replace well-known symbol */
JERRY_SYMBOL_SEARCH, /**< @@search well-known symbol */
JERRY_SYMBOL_SPECIES, /**< @@species well-known symbol */
JERRY_SYMBOL_SPLIT, /**< @@split well-known symbol */
JERRY_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well-known symbol */
JERRY_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well-known symbol */
JERRY_SYMBOL_UNSCOPABLES, /**< @@unscopables well-known symbol */
} jerry_well_known_symbol_t;
jerry_value_t jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol);
jerry_value_t jerry_get_symbol_description (const jerry_value_t symbol);
jerry_value_t jerry_get_symbol_descriptive_string (const jerry_value_t symbol);
/**
* Realm functions.
*/
jerry_value_t jerry_set_realm (jerry_value_t realm_value);
jerry_value_t jerry_realm_get_this (jerry_value_t realm_value);
jerry_value_t jerry_realm_set_this (jerry_value_t realm_value, jerry_value_t this_value);
/**
* BigInt functions.
*/
uint32_t jerry_get_bigint_size_in_digits (jerry_value_t value);
void jerry_get_bigint_digits (jerry_value_t value, uint64_t *digits_p, uint32_t size, bool *sign_p);
/**
* Proxy functions.
*/
jerry_value_t jerry_get_proxy_target (jerry_value_t proxy_value);
/**
* Input validator functions.
*/
bool jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, jerry_size_t buf_size);
bool jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, jerry_size_t buf_size);
/*
* Dynamic memory management functions.
*/
void *jerry_heap_alloc (size_t size);
void jerry_heap_free (void *mem_p, size_t size);
/*
* External context functions.
*/
jerry_context_t *jerry_create_context (uint32_t heap_size, jerry_context_alloc_t alloc, void *cb_data_p);
/**
* Miscellaneous functions.
*/
void jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, void *user_p, uint32_t frequency);
jerry_value_t jerry_get_backtrace (uint32_t max_depth);
jerry_value_t jerry_get_backtrace_from (uint32_t max_depth, jerry_value_t ignored_function);
jerry_value_t jerry_get_resource_name (const jerry_value_t value);
jerry_value_t jerry_get_new_target (void);
/**
* Array buffer components.
*/
bool jerry_value_is_arraybuffer (const jerry_value_t value);
jerry_value_t jerry_create_arraybuffer (const jerry_length_t size);
jerry_value_t jerry_create_arraybuffer_external (const jerry_length_t size,
uint8_t *buffer_p,
jerry_object_native_free_callback_t free_cb);
jerry_length_t jerry_arraybuffer_write (const jerry_value_t value,
jerry_length_t offset,
const uint8_t *buf_p,
jerry_length_t buf_size);
jerry_length_t jerry_arraybuffer_read (const jerry_value_t value,
jerry_length_t offset,
uint8_t *buf_p,
jerry_length_t buf_size);
jerry_length_t jerry_get_arraybuffer_byte_length (const jerry_value_t value);
uint8_t *jerry_get_arraybuffer_pointer (const jerry_value_t value);
jerry_value_t jerry_is_arraybuffer_detachable (const jerry_value_t value);
jerry_value_t jerry_detach_arraybuffer (const jerry_value_t value);
/**
* DataView functions.
*/
jerry_value_t
jerry_create_dataview (const jerry_value_t value,
const jerry_length_t byte_offset,
const jerry_length_t byte_length);
bool
jerry_value_is_dataview (const jerry_value_t value);
jerry_value_t
jerry_get_dataview_buffer (const jerry_value_t dataview,
jerry_length_t *byte_offset,
jerry_length_t *byte_length);
/**
* TypedArray functions.
*/
/**
* TypedArray types.
*/
typedef enum
{
JERRY_TYPEDARRAY_INVALID = 0,
JERRY_TYPEDARRAY_UINT8,
JERRY_TYPEDARRAY_UINT8CLAMPED,
JERRY_TYPEDARRAY_INT8,
JERRY_TYPEDARRAY_UINT16,
JERRY_TYPEDARRAY_INT16,
JERRY_TYPEDARRAY_UINT32,
JERRY_TYPEDARRAY_INT32,
JERRY_TYPEDARRAY_FLOAT32,
JERRY_TYPEDARRAY_FLOAT64,
JERRY_TYPEDARRAY_BIGINT64,
JERRY_TYPEDARRAY_BIGUINT64,
} jerry_typedarray_type_t;
/**
* Container types.
*/
typedef enum
{
JERRY_CONTAINER_TYPE_INVALID = 0, /**< Invalid container */
JERRY_CONTAINER_TYPE_MAP, /**< Map type */
JERRY_CONTAINER_TYPE_SET, /**< Set type */
JERRY_CONTAINER_TYPE_WEAKMAP, /**< WeakMap type */
JERRY_CONTAINER_TYPE_WEAKSET, /**< WeakSet type */
} jerry_container_type_t;
bool jerry_value_is_typedarray (jerry_value_t value);
jerry_value_t jerry_create_typedarray (jerry_typedarray_type_t type_name, jerry_length_t length);
jerry_value_t jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name,
const jerry_value_t arraybuffer,
jerry_length_t byte_offset,
jerry_length_t length);
jerry_value_t jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name,
const jerry_value_t arraybuffer);
jerry_typedarray_type_t jerry_get_typedarray_type (jerry_value_t value);
jerry_length_t jerry_get_typedarray_length (jerry_value_t value);
jerry_value_t jerry_get_typedarray_buffer (jerry_value_t value,
jerry_length_t *byte_offset,
jerry_length_t *byte_length);
jerry_value_t jerry_json_parse (const jerry_char_t *string_p, jerry_size_t string_size);
jerry_value_t jerry_json_stringify (const jerry_value_t object_to_stringify);
jerry_value_t jerry_create_container (jerry_container_type_t container_type,
const jerry_value_t *arguments_list_p,
jerry_length_t arguments_list_len);
jerry_container_type_t jerry_get_container_type (const jerry_value_t value);
/**
* @}
*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !JERRYSCRIPT_CORE_H */