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