diff --git a/docs/01.CONFIGURATION.md b/docs/01.CONFIGURATION.md index 209dc3f8c6..aee35fd277 100644 --- a/docs/01.CONFIGURATION.md +++ b/docs/01.CONFIGURATION.md @@ -190,7 +190,7 @@ This option is enabled by default. ### Memory statistics -This option can be used to provide memory usage statistics either upon engine termination, or during runtime using the `jerry_get_memory_stats` jerry API function. +This option can be used to provide memory usage statistics either upon engine termination, or during runtime using the `jerry_heap_stats` jerry API function. The feature can create a significant performance overhead, and should only be used for measurement purposes. This option is disabled by default. | Options | | diff --git a/docs/02.API-REFERENCE.md b/docs/02.API-REFERENCE.md index 3591953a82..74fa54a45e 100644 --- a/docs/02.API-REFERENCE.md +++ b/docs/02.API-REFERENCE.md @@ -25,7 +25,7 @@ Enum that contains JerryScript API value types: - JERRY_TYPE_STRING - string type - JERRY_TYPE_OBJECT - object type - JERRY_TYPE_FUNCTION - function type - - JERRY_TYPE_ERROR - error/abort type + - JERRY_TYPE_EXCEPTION - exception/abort type - JERRY_TYPE_SYMBOL - symbol type - JERRY_TYPE_BIGINT - bigint type @@ -46,13 +46,13 @@ Enum that contains JerryScript **object** value types: - JERRY_OBJECT_TYPE_MODULE - Module object (see [jerry_parse](#jerry_parse)) - JERRY_OBJECT_TYPE_PROMISE - Promise object - JERRY_OBJECT_TYPE_DATAVIEW - Dataview object - - JERRY_OBJECT_TYPE_FUNCTION - Function object (see [jerry_function_get_type](#jerry_function_get_type)) - - JERRY_OBJECT_TYPE_TYPEDARRAY - %TypedArray% object (see [jerry_get_typedarray_type](#jerry_get_typedarray_type)) - - JERRY_OBJECT_TYPE_ITERATOR - Iterator object (see [jerry_iterator_get_type](#jerry_get_typedarray_type)) - - JERRY_OBJECT_TYPE_CONTAINER - Container object (see [jerry_get_container_type](#jerry_get_container_type)) - - JERRY_OBJECT_TYPE_ERROR - Error object - - JERRY_OBJECT_TYPE_ARRAYBUFFER - Array buffer object - - JERRY_OBJECT_TYPE_SHARED_ARRAYBUFFER - Shared Array buffer object + - JERRY_OBJECT_TYPE_FUNCTION - Function object (see [jerry_function_type](#jerry_function_type)) + - JERRY_OBJECT_TYPE_TYPEDARRAY - %TypedArray% object (see [jerry_typedarray_type](#jerry_typedarray_type)) + - JERRY_OBJECT_TYPE_ITERATOR - Iterator object (see [jerry_iterator_type](#jerry_typedarray_type)) + - JERRY_OBJECT_TYPE_CONTAINER - Container object (see [jerry_container_type](#jerry_container_type)) + - JERRY_OBJECT_TYPE_ERROR - Error object (see [jerry_error_type](#jerry_error_type)) + - JERRY_OBJECT_TYPE_ARRAYBUFFER - ArrayBuffer object + - JERRY_OBJECT_TYPE_SHARED_ARRAYBUFFER - SharedArrayBuffer object - JERRY_OBJECT_TYPE_ARGUMENTS - Arguments object - JERRY_OBJECT_TYPE_BOOLEAN - Boolean object @@ -96,7 +96,7 @@ Enum that contains JerryScript **iterator** value types: *New in version 2.4*. -## jerry_proxy_object_options_t +## jerry_proxy_custom_behavior_t These option bits allow specializing Proxies with non-standard behaviour. These flags are recommended only for those trusted Proxies, whose handlers @@ -131,7 +131,7 @@ Enum that contains JerryScript **property filter** options bits: ## jerry_error_t -Possible types of an error: +Possible types of an Error object: - JERRY_ERROR_COMMON - common error - JERRY_ERROR_EVAL - eval error @@ -142,9 +142,9 @@ Possible types of an error: - JERRY_ERROR_URI - URI error There is also a special value `JERRY_ERROR_NONE` which is not an error type -this value can only be returned by the [jerry_get_error_type](#jerry_get_error_type). +this value can only be returned by the [jerry_error_type](#jerry_error_type). -*Changed in version 2.0*: The `JERRY_ERROR_NONE` was added to be used by the [jerry_get_error_type](#jerry_get_error_type) method. +*Changed in version 2.0*: The `JERRY_ERROR_NONE` was added to be used by the [jerry_error_type](#jerry_error_type) method. ## jerry_feature_t @@ -153,7 +153,7 @@ Possible compile time enabled feature types: - 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_HEAP_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 @@ -255,14 +255,14 @@ Option bits for [jerry_parse_options_t](#jerry_parse_options_t). - JERRY_PARSE_STRICT_MODE - Enable strict mode - JERRY_PARSE_MODULE - Parse source as an ECMAScript module - JERRY_PARSE_HAS_ARGUMENT_LIST - `argument_list` field is valid, this also means that function parsing will be done - - JERRY_PARSE_HAS_RESOURCE - `resource_name` field is valid + - JERRY_PARSE_HAS_SOURCE_NAME - `source_name` field is valid - JERRY_PARSE_HAS_START - `start_line` and `start_column` fields are valid - JERRY_PARSE_HAS_USER_VALUE - `user_value` field is valid *New in version [[NEXT_RELEASE]]*. Using both `JERRY_PARSE_MODULE` and `JERRY_PARSE_HAS_ARGUMENT_LIST` is an invalid combination and will result in -an error during parsing. +an exception during parsing. **See also** @@ -282,10 +282,10 @@ memory blocks but the performance may drop after the garbage collection. *New in version 2.0*. -## jerry_backtrace_frame_types_t +## jerry_frame_type_t List of backtrace frame types returned by -[jerry_backtrace_get_frame_type](#jerry_backtrace_get_frame_type). +[jerry_frame_type](#jerry_frame_type). - JERRY_BACKTRACE_FRAME_JS - indicates that the frame is created for a JavaScript function/method @@ -328,7 +328,7 @@ Flags for [jerry_exec_snapshot](#jerry_exec_snapshot) functions: - JERRY_SNAPSHOT_EXEC_COPY_DATA - copy snapshot data into memory (see below) - JERRY_SNAPSHOT_EXEC_ALLOW_STATIC - allow executing static snapshots - JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION - load snapshot as function instead of executing it - - JERRY_SNAPSHOT_EXEC_HAS_RESOURCE - `resource_name` field is valid + - JERRY_SNAPSHOT_EXEC_HAS_RESOURCE - `source_name` field is valid in [jerry_exec_snapshot_option_values_t](#jerry_exec_snapshot_option_values_t) - JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE - `user_value` field is valid in [jerry_exec_snapshot_option_values_t](#jerry_exec_snapshot_option_values_t) @@ -390,13 +390,12 @@ typedef uint32_t jerry_length_t; **Summary** -JerryScript value can be a boolean, number, null, object, string or undefined. The value has an error flag, -that indicates whether is an error or not. Every type has an error flag not only objects. The error flag should -be cleared before the value is passed as an argument, otherwise it can lead to a type error. The error objects -created by API functions has the error flag set. +A JerryScript value can be undefined, null, boolean, number, string, object, or an exception value. Exception values +represent thrown exceptions during execution. Exception values cannot be passed as an argument to regular API function, +only to those that work with exception values specifically. Returned and created values by the API functions must be freed with -[jerry_release_value](#jerry_release_value) when they are no longer needed. +[jerry_value_free](#jerry_value_free) when they are no longer needed. **Prototype** @@ -422,7 +421,7 @@ 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. + * first time jerry_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. @@ -455,7 +454,7 @@ typedef struct /** * 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. + * returned from the jerry_context_data () API. */ size_t bytes_needed; } jerry_context_data_manager_t; @@ -494,7 +493,7 @@ typedef struct jerry_context_t jerry_context_t; *New in version 2.0*. -## jerry_container_operation_t +## jerry_container_op_t Enum that contains the supported container operation types - JERRY_CONTAINER_OP_ADD - Set/WeakSet add operation @@ -507,7 +506,7 @@ Enum that contains the supported container operation types *New in version [[NEXT_RELEASE]]*. -## jerry_binary_operation_t +## jerry_binary_op_t Enum that contains the supported binary operation types - JERRY_BIN_OP_EQUAL - equal comparison (==) @@ -527,7 +526,7 @@ Enum that contains the supported binary operation types **See also** -- [jerry_binary_operation](#jerry_binary_operation) +- [jerry_binary_op](#jerry_binary_op) ## jerry_property_descriptor_flags_t @@ -543,7 +542,7 @@ Enum that contains the flags of property descriptors. - JERRY_PROP_IS_VALUE_DEFINED - Is [[Value]] defined? - JERRY_PROP_IS_GET_DEFINED - Is [[Get]] defined? - JERRY_PROP_IS_SET_DEFINED - Is [[Set]] defined? - - JERRY_PROP_SHOULD_THROW - Should throw on error, instead of returning with false + - JERRY_PROP_SHOULD_THROW - Should throw in case of an exception, instead of returning with false *New in version [[NEXT_RELEASE]]*. @@ -565,9 +564,9 @@ typedef struct uint32_t options; /**< combination of jerry_parse_option_enable_feature_t values */ jerry_value_t argument_list; /**< function argument list if JERRY_PARSE_HAS_ARGUMENT_LIST is set in options * Note: must be string value */ - jerry_value_t resource_name; /**< resource name string (usually a file name) - * if JERRY_PARSE_HAS_RESOURCE is set in options - * Note: must be string value */ + jerry_value_t source_name; /**< resource name string (usually a file name) + * if JERRY_PARSE_HAS_SOURCE_NAME is set in options + * Note: must be string value */ uint32_t start_line; /**< start line of the source code if JERRY_PARSE_HAS_START is set in options */ uint32_t start_column; /**< start column of the source code if JERRY_PARSE_HAS_START is set in options */ jerry_value_t user_value; /**< user value assigned to all functions created by this script including eval @@ -589,7 +588,7 @@ typedef struct **Summary** Description of ECMA property descriptor. This struct can be used -for the [jerry_define_own_property](#jerry_define_own_property) method to +for the [jerry_object_define_own_prop](#jerry_object_define_own_prop) method to configure how the property should be registered. The naming scheme is similar to the JavaScript `Object.defineProperty` method. @@ -617,48 +616,48 @@ typedef struct **See also** - [jerry_property_descriptor_flags_t](#jerry_property_descriptor_flags_t) -- [jerry_define_own_property](#jerry_define_own_property) +- [jerry_object_define_own_prop](#jerry_object_define_own_prop) -## jerry_backtrace_location_t +## jerry_frame_location_t **Summary** Source code location data retrieved by -[jerry_backtrace_get_location](#jerry_backtrace_get_location). +[jerry_frame_location](#jerry_frame_location). **Prototype** ```c typedef struct { - jerry_value_t resource_name; /**< resource name */ + jerry_value_t source_name; /**< resource name */ jerry_size_t line; /**< line index */ jerry_size_t column; /**< column index */ -} jerry_backtrace_location_t; +} jerry_frame_location_t; ``` *New in version [[NEXT_RELEASE]]*. -## jerry_backtrace_frame_t +## jerry_frame_t **Summary** -Backtrace frame data passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) +Backtrace frame data passed to the [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) handler. This is an internal data structure which fields can be accessed by helper functions -such as [jerry_backtrace_get_location](#jerry_backtrace_get_location). +such as [jerry_frame_location](#jerry_frame_location). **Prototype** ```c /** - * Internal data structure for jerry_backtrace_frame_t definition. + * Internal data structure for jerry_frame_t definition. */ -struct jerry_backtrace_frame_internal_t; +struct jerry_frame_internal_t; /** - * Backtrace frame data passed to the jerry_backtrace_callback_t handler. + * Backtrace frame data passed to the jerry_backtrace_cb_t handler. */ -typedef struct jerry_backtrace_frame_internal_t jerry_backtrace_frame_t; +typedef struct jerry_frame_internal_t jerry_frame_t; ``` *New in version [[NEXT_RELEASE]]*. @@ -687,7 +686,7 @@ typedef struct **See also** -- [jerry_get_memory_stats](#jerry_get_memory_stats) +- [jerry_heap_stats](#jerry_heap_stats) ## jerry_call_info_t @@ -701,7 +700,7 @@ Call related information passed to [jerry_external_handler_t](#jerry_external_ha typedef struct jerry_call_info_t { jerry_value_t function; /**< invoked function object */ - jerry_value_t this_value; /**< this value passed to the function */ + jerry_value_t this_value; /**< this value passed to the function */ jerry_value_t new_target; /**< current new target value, undefined for non-constructor calls */ } jerry_call_info_t; ``` @@ -731,11 +730,11 @@ typedef jerry_value_t (*jerry_external_handler_t) (const jerry_call_info_t *call - `args_p` - the function arguments, array of JavaScript values. - `args_count` - the number of arguments. - return value - - The function's return value. If there is no return value, use [jerry_create_undefined()](#jerry_create_undefined). + - The function's return value. If there is no return value, use [jerry_undefined()](#jerry_undefined). **See also** -- [jerry_create_external_function](#jerry_create_external_function) +- [jerry_function_external](#jerry_function_external) ## jerry_value_free_callback_t @@ -756,16 +755,16 @@ typedef void (*jerry_value_free_callback_t) (void *native_p); **See also** -- [jerry_create_external_string](#jerry_create_external_string) -- [jerry_create_external_string_sz](#jerry_create_external_string_sz) -- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external) +- [jerry_string_external_sz](#jerry_string_external_sz) +- [jerry_string_external](#jerry_string_external) +- [jerry_arraybuffer_external](#jerry_arraybuffer_external) -## jerry_object_native_free_callback_t +## jerry_object_native_free_cb_t **Summary** Native free callback of an object. The callback receives both the memory pointer and the type -information passed to [jerry_set_object_native_pointer](#jerry_set_object_native_pointer). +information passed to [jerry_object_set_native_ptr](#jerry_object_set_native_ptr). *Note*: - Referred values by this method must have at least 1 reference. (Correct API usage satisfies this condition) @@ -773,11 +772,11 @@ information passed to [jerry_set_object_native_pointer](#jerry_set_object_native **Prototype** ```c -typedef void (*jerry_object_native_free_callback_t) (void *native_p, struct jerry_object_native_info_t *info_p); +typedef void (*jerry_object_native_free_cb_t) (void *native_p, struct jerry_object_native_info_t *info_p); ``` -- `native_p` - native pointer passed to [jerry_set_object_native_pointer](#jerry_set_object_native_pointer). -- `info_p` - native type info passed to [jerry_set_object_native_pointer](#jerry_set_object_native_pointer). +- `native_p` - native pointer passed to [jerry_object_set_native_ptr](#jerry_object_set_native_ptr). +- `info_p` - native type info passed to [jerry_object_set_native_ptr](#jerry_object_set_native_ptr). *New in version 2.0*: Renamed from `jerry_object_free_callback_t`. @@ -789,18 +788,18 @@ typedef void (*jerry_object_native_free_callback_t) (void *native_p, struct jerr - [jerry_object_native_info_t](#jerry_object_native_info_t) -## jerry_external_string_free_callback_t +## jerry_external_string_free_cb_t **Summary** Free callback for external strings. See -[jerry_string_set_external_free_callback](#jerry_string_set_external_free_callback) +[jerry_string_external_free_cb](#jerry_string_external_free_cb) for more information. **Prototype** ```c -typedef void (*jerry_external_string_free_callback_t) (jerry_char_t *string_p, +typedef void (*jerry_external_string_free_cb_t) (jerry_char_t *string_p, jerry_size_t string_size, void *user_p); ``` @@ -813,11 +812,11 @@ typedef void (*jerry_external_string_free_callback_t) (jerry_char_t *string_p, **See also** -- [jerry_string_set_external_free_callback](#jerry_string_set_external_free_callback) -- [jerry_create_external_string](#jerry_create_external_string) -- [jerry_create_external_string_sz](#jerry_create_external_string_sz) +- [jerry_string_external_free_cb](#jerry_string_external_free_cb) +- [jerry_string_external_sz](#jerry_string_external_sz) +- [jerry_string_external](#jerry_string_external) -## jerry_error_object_created_callback_t +## jerry_error_object_created_cb_t **Summary** @@ -832,33 +831,33 @@ Error object. **Prototype** ```c -typedef void (*jerry_error_object_created_callback_t) (const jerry_value_t error_object, void *user_p); +typedef void (*jerry_error_object_created_cb_t) (const jerry_value_t error_object, void *user_p); ``` - `error_object` - the newly created Error object. -- `user_p` - pointer passed to [jerry_set_error_object_created_callback](#jerry_set_error_object_created_callback). +- `user_p` - pointer passed to [jerry_error_created_cb](#jerry_error_created_cb). *New in version 2.4*. **See also** -- [jerry_set_error_object_created_callback](#jerry_set_error_object_created_callback) +- [jerry_error_created_cb](#jerry_error_created_cb) ## jerry_module_state_t An enum representing the current status of a module - - JERRY_MODULE_STATE_INVALID - Return value for jerry_module_get_state when its argument is not a module + - JERRY_MODULE_STATE_INVALID - Return value for jerry_module_state when its argument is not a module - JERRY_MODULE_STATE_UNLINKED - Module is currently unlinked - JERRY_MODULE_STATE_LINKING - Module is currently being linked - JERRY_MODULE_STATE_LINKED - Module has been linked (its dependencies has been resolved) - JERRY_MODULE_STATE_EVALUATING - Module is currently being evaluated - JERRY_MODULE_STATE_EVALUATED - Module has been evaluated (its source code has been executed) - - JERRY_MODULE_STATE_ERROR - An error has been encountered before the evaluated state is reached + - JERRY_MODULE_STATE_ERROR - An exception has been encountered before the evaluated state is reached *New in version [[NEXT_RELEASE]]*. -## jerry_module_resolve_callback_t +## jerry_module_resolve_cb_t **Summary** @@ -866,12 +865,12 @@ Callback which is called by [jerry_module_link](#jerry_module_link) to get the r *Note*: - If realms are enabled, the returned module should be created in the current realm - (see: [jerry_get_global_object](#jerry_get_global_object)) + (see: [jerry_current_realm](#jerry_current_realm)) **Prototype** ```c -typedef jerry_value_t (*jerry_module_resolve_callback_t) (const jerry_value_t specifier, +typedef jerry_value_t (*jerry_module_resolve_cb_t) (const jerry_value_t specifier, const jerry_value_t referrer, void *user_p); ``` @@ -881,15 +880,15 @@ typedef jerry_value_t (*jerry_module_resolve_callback_t) (const jerry_value_t sp - `user_p` - pointer passed to [jerry_module_link](#jerry_module_link). - return value - a module object - if it can be resolved successfully - - an error - otherwise + - an exception - otherwise *New in version [[NEXT_RELEASE]]*. **See also** - [jerry_module_link](#jerry_module_link) -- [jerry_get_global_object](#jerry_get_global_object) +- [jerry_current_realm](#jerry_current_realm) -## jerry_module_import_callback_t +## jerry_module_import_cb_t **Summary** @@ -899,39 +898,39 @@ Callback which is called when an import is resolved dynamically to get the refer - If the function returns with a promise, the import call returns with this promise. The application should try to resolve the requested module later. If the module is evaluated successfully, the returned promise should be resolved with the namespace object of the - module. Otherwise, the returned promise should be rejected with an error. + module. Otherwise, the returned promise should be rejected with an exception. - If the function returns with a resolved module, a promise is created and resolved with the namespace object of the module. The import call returns with the resolved promise. - - If the function returns with an error, a promise is created and rejected with the - return error. The import call returns with the rejected promise. + - If the function returns with an exception, a promise is created and rejected with the + returned exception. The import call returns with the rejected promise. - All other return values are considered invalid. In this case the import call returns with a rejected promise. The rejected promise has a fixed error message, it does not specify the reason of the fail. - If realms are enabled, the returned module should be created in the current realm - (see: [jerry_get_global_object](#jerry_get_global_object)) + (see: [jerry_current_realm](#jerry_current_realm)) **Prototype** ```c -typedef jerry_value_t (*jerry_module_import_callback_t) (const jerry_value_t specifier, +typedef jerry_value_t (*jerry_module_import_cb_t) (const jerry_value_t specifier, const jerry_value_t user_value, void *user_p); ``` - `specifier` - a module specifier string (usually used as a path to the module) - `user_value` - the user value assigned to the script (see [jerry_parse_options_t](#jerry_parse_options_t)) -- `user_p` - pointer passed to [jerry_module_set_import_callback](#jerry_module_set_import_callback). +- `user_p` - pointer passed to [jerry_module_import_cb](#jerry_module_import_cb). - return value - promise or resolved module - if the operation is successful - - an error - otherwise + - an exception - otherwise *New in version [[NEXT_RELEASE]]*. **See also** -- [jerry_module_set_import_callback](#jerry_module_set_import_callback) -- [jerry_get_global_object](#jerry_get_global_object) +- [jerry_module_import_cb](#jerry_module_import_cb) +- [jerry_current_realm](#jerry_current_realm) -## jerry_module_state_changed_callback_t +## jerry_module_state_changed_cb_t **Summary** @@ -940,7 +939,7 @@ Callback which is called after the module enters into linked, evaluated or error **Prototype** ```c -typedef void (*jerry_module_state_changed_callback_t) (jerry_module_state_t new_state, +typedef void (*jerry_module_state_changed_cb_t) (jerry_module_state_t new_state, const jerry_value_t module, const jerry_value_t value, void *user_p); @@ -949,15 +948,15 @@ typedef void (*jerry_module_state_changed_callback_t) (jerry_module_state_t new_ - `new_state` - new state of the module. - `module` - a module whose state is changed - `value` - depends on the state: undefined for linked, module script result for evaluated, - and error value for error state. -- `user_p` - pointer passed to [jerry_module_set_state_changed_callback](#jerry_module_set_state_changed_callback). + and exception value for error state. +- `user_p` - pointer passed to [jerry_module_state_changed_cb](#jerry_module_state_changed_cb). *New in version [[NEXT_RELEASE]]*. **See also** -- [jerry_module_set_state_changed_callback](#jerry_module_set_state_changed_callback) +- [jerry_module_state_changed_cb](#jerry_module_state_changed_cb) -## jerry_module_import_meta_callback_t +## jerry_module_import_meta_cb_t **Summary** @@ -968,21 +967,21 @@ the callback can set the initial status of the object (e.g. add properties or se **Prototype** ```c -typedef void (*jerry_module_import_meta_callback_t) (const jerry_value_t module, +typedef void (*jerry_module_import_meta_cb_t) (const jerry_value_t module, const jerry_value_t meta_object, void *user_p); ``` - `module` - module whose import.meta object is requested. - `meta_object` - import.meta object created for the module. -- `user_p` - pointer passed to [jerry_module_set_import_meta_callback](#jerry_module_set_import_meta_callback). +- `user_p` - pointer passed to [jerry_module_import_meta_cb](#jerry_module_import_meta_cb). *New in version [[NEXT_RELEASE]]*. **See also** -- [jerry_module_set_import_meta_callback](#jerry_module_set_import_meta_callback) +- [jerry_module_import_meta_cb](#jerry_module_import_meta_cb) -## jerry_native_module_evaluate_callback_t +## jerry_native_module_evaluate_cb_t **Summary** @@ -990,25 +989,25 @@ Callback which is called by [jerry_module_evaluate](#jerry_module_evaluate) to e Note: - Native pointers can be used to assign private data to a native module, - see [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) + see [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) **Prototype** ```c -typedef jerry_value_t (*jerry_native_module_evaluate_callback_t) (const jerry_value_t native_module); +typedef jerry_value_t (*jerry_native_module_evaluate_cb_t) (const jerry_value_t native_module); ``` - `native_module` - a native module - return value - - any non-error value - if the module is evaluated successfully - - an error - otherwise + - any non-exception value - if the module is evaluated successfully + - an exception - otherwise *New in version [[NEXT_RELEASE]]*. **See also** - [jerry_module_evaluate](#jerry_module_evaluate) -## jerry_backtrace_callback_t +## jerry_backtrace_cb_t **Summary** @@ -1018,10 +1017,10 @@ for each stack frame. **Prototype** ```c -typedef bool (*jerry_backtrace_callback_t) (jerry_backtrace_frame_t *frame_p, void *user_p); +typedef bool (*jerry_backtrace_cb_t) (jerry_frame_t *frame_p, void *user_p); ``` -- `frame_p` - pointer to [jerry_backtrace_frame_t](#jerry_backtrace_frame_t) data. +- `frame_p` - pointer to [jerry_frame_t](#jerry_frame_t) data. - `user_p` - pointer passed to [jerry_backtrace_capture](#jerry_backtrace_capture). - return value - true, to continue capturing more frames @@ -1032,7 +1031,7 @@ typedef bool (*jerry_backtrace_callback_t) (jerry_backtrace_frame_t *frame_p, vo **See also** - [jerry_backtrace_capture](#jerry_backtrace_capture) -- [jerry_backtrace_frame_t](#jerry_backtrace_frame_t) +- [jerry_frame_t](#jerry_frame_t) ## jerry_object_native_info_t @@ -1050,15 +1049,15 @@ The buffer pointed by the native pointer can have a fixed number of jerry values which refer to other values as long as the object is alive. The starting byte offset and the number of these values are specified by `offset_of_references` and `number_of_references` fields respectively. Before a buffer is attached to an -object by [jerry_set_object_native_pointer](#jerry_set_object_native_pointer), +object by [jerry_object_set_native_ptr](#jerry_object_set_native_ptr), the values must be initialized to undefined by -[jerry_native_pointer_init_references](#jerry_native_pointer_init_references). +[jerry_native_ptr_init](#jerry_native_ptr_init). When a buffer is no longer attached to any object, the -[jerry_native_pointer_release_references](#jerry_native_pointer_release_references) +[jerry_native_ptr_free](#jerry_native_ptr_free) must be called to release the values. A single buffer can be attached to any number of living objects. When a buffer is currently attached to at least one object, the references can be updated by -[jerry_native_pointer_set_reference](#jerry_native_pointer_set_reference). +[jerry_native_ptr_set](#jerry_native_ptr_set). However, if the buffer is no longer attached to an object, the finalize function must be called even if the buffer is reattached to another object later. In this case, calling the init function after the finalization is optional, because the @@ -1069,7 +1068,7 @@ finalize function also initializes all values to undefined. ```c typedef struct { - jerry_object_native_free_callback_t free_cb; /**< the free callback of the native pointer */ + jerry_object_native_free_cb_t free_cb; /**< the free callback of the native pointer */ uint16_t number_of_references; /**< the number of value references which are marked by the garbage collector */ uint16_t offset_of_references; /**< byte offset indicating the start offset of value * references in the user allocated buffer */ @@ -1082,57 +1081,57 @@ typedef struct **See also** -- [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) -- [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) -- [jerry_delete_object_native_pointer](#jerry_delete_object_native_pointer) -- [jerry_native_pointer_init_references](#jerry_native_pointer_init_references) -- [jerry_native_pointer_release_references](#jerry_native_pointer_release_references) -- [jerry_native_pointer_set_reference](#jerry_native_pointer_set_reference) +- [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) +- [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) +- [jerry_object_delete_native_ptr](#jerry_object_delete_native_ptr) +- [jerry_native_ptr_init](#jerry_native_ptr_init) +- [jerry_native_ptr_free](#jerry_native_ptr_free) +- [jerry_native_ptr_set](#jerry_native_ptr_set) -## jerry_object_property_foreach_t +## jerry_object_property_foreach_cb_t **Summary** -Function type used as a callback for the [jerry_foreach_object_property](#jerry_foreach_object_property) +Function type used as a callback for the [jerry_object_foreach](#jerry_object_foreach) method. A function with this type must return "true" to continue the iteration or "false" to finish the iteration on the object's properties. **Prototype** ```c -typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name, +typedef bool (*jerry_object_property_foreach_cb_t) (const jerry_value_t property_name, const jerry_value_t property_value, void *user_data_p); ``` - `property_name` - a property name, this is not always a string. - `property_value` - the value for the given property. -- `user_data_p` - optional user data pointer supplied via the (jerry_foreach_object_property)[#jerry_foreach_object_property] method. +- `user_data_p` - optional user data pointer supplied via the (jerry_object_foreach)[#jerry_object_foreach] method. - return value - true, to continue the iteration - false, to stop the iteration **See also** -- [jerry_foreach_object_property](#jerry_foreach_object_property) +- [jerry_object_foreach](#jerry_object_foreach) -## jerry_objects_foreach_t +## jerry_foreach_live_object_cb_t **Summary** -Function type used as a callback for the (jerry_objects_foreach)[#jerry_objects_foreach] method. +Function type used as a callback for the (jerry_foreach_live_object)[#jerry_foreach_live_object] method. A function with this type must return "true" to continue the iteration or "false" to finish the iteration on the object's properties. **Prototype** ```c -typedef bool (*jerry_objects_foreach_t) (const jerry_value_t object, - void *user_data_p); +typedef bool (*jerry_foreach_live_object_cb_t) (const jerry_value_t object, + void *user_data_p); ``` - `object` - the current JavaScript object in the for-each iteration. -- `user_data_p` - optional user data pointer supplied via the (jerry_objects_foreach)[#jerry_objects_foreach] method. +- `user_data_p` - optional user data pointer supplied via the (jerry_foreach_live_object)[#jerry_foreach_live_object] method. - return value - true, to continue the iteration - false, to stop the iteration @@ -1141,27 +1140,27 @@ typedef bool (*jerry_objects_foreach_t) (const jerry_value_t object, **See also** -- [jerry_objects_foreach](#jerry_objects_foreach) +- [jerry_foreach_live_object](#jerry_foreach_live_object) -## jerry_objects_foreach_by_native_info_t +## jerry_foreach_live_object_with_info_cb_t **Summary** -Function type used as a callback for the (jerry_objects_foreach_by_native_info)[#jerry_objects_foreach_by_native_info] +Function type used as a callback for the (jerry_foreach_live_object_with_info)[#jerry_foreach_live_object_with_info] method. A function with this type must return "true" to continue the iteration or "false" to finish the iteration on the object's properties. **Prototype** ```c -typedef bool (*jerry_objects_foreach_by_native_info_t) (const jerry_value_t object, - void *object_data_p, - void *user_data_p); +typedef bool (*jerry_foreach_live_object_with_info_cb_t) (const jerry_value_t object, + void *object_data_p, + void *user_data_p); ``` - `object` - the current JavaScript object in the for-each iteration. - `object_data_p` - the current object's native data pointer. -- `user_data_p` - optional user data pointer supplied via the (jerry_objects_foreach_by_native_info)[#jerry_objects_foreach_by_native_info] method. +- `user_data_p` - optional user data pointer supplied via the (jerry_foreach_live_object_with_info)[#jerry_foreach_live_object_with_info] method. - return value - true, to continue the iteration - false, to stop the iteration @@ -1170,56 +1169,54 @@ typedef bool (*jerry_objects_foreach_by_native_info_t) (const jerry_value_t obje **See also** -- [jerry_objects_foreach_by_native_info](#jerry_objects_foreach_by_native_info) +- [jerry_foreach_live_object_with_info](#jerry_foreach_live_object_with_info) -## jerry_vm_exec_stop_callback_t +## jerry_halt_cb_t **Summary** -Callback which tells whether the ECMAScript execution should be stopped. -If it returns with undefined value the ECMAScript execution continues. -Otherwise the result is thrown by the engine (if the error flag is not -set for the returned value the engine automatically sets it). The -callback function might be called again even if it threw an error. -In this case the function must throw the same error again. +Callback which is called periodically by the engine, and polls whether the ECMAScript execution should be stopped. If +the callback returns with an undefined value the ECMAScript execution continues. Otherwise the result is thrown by the +engine as an exception, and execution returns to the caller. The callback function might be called again even if it +threw an exception. In this case the function must throw the same exception again. **Prototype** ```c -typedef jerry_value_t (*jerry_vm_exec_stop_callback_t) (void *user_p); +typedef jerry_value_t (*jerry_halt_cb_t) (void *user_p); ``` *New in version 2.0*. **See also** -- [jerry_set_vm_exec_stop_callback](#jerry_set_vm_exec_stop_callback) +- [jerry_halt_cb](#jerry_halt_cb) -## jerry_vm_throw_callback_t +## jerry_throw_cb_t **Summary** Callback which is called when a value is thrown in an ECMAScript code. The callback -should not change the `error_value`. The callback is not called again until the value +should not change the `exception_value`. The callback is not called again until the value is caught. Note: - - The engine considers errors thrown by external functions as never caught. The + - The engine considers exceptions thrown by external functions as never caught. The application can maintain a status flag to ignore the next call of the callback if necessary. - See: [jerry_create_external_function](#jerry_create_external_function) + See: [jerry_function_external](#jerry_function_external) **Prototype** ```c -typedef void (*jerry_vm_throw_callback_t) (const jerry_value_t error_value, void *user_p); +typedef void (*jerry_throw_cb_t) (const jerry_value_t error_value, void *user_p); ``` *New in [[NEXT_RELEASE]]*. **See also** -- [jerry_set_vm_throw_callback](#jerry_set_vm_throw_callback) +- [jerry_throw_cb](#jerry_throw_cb) ## jerry_promise_state_t @@ -1236,11 +1233,11 @@ Possible values: **See also** -- [jerry_get_promise_result](#jerry_get_promise_result) +- [jerry_promise_result](#jerry_promise_result) ## jerry_promise_event_type_t -Event types for [jerry_promise_callback_t](#jerry_promise_callback_t) callback function. +Event types for [jerry_promise_event_cb_t](#jerry_promise_event_cb_t) callback function. The description of the `object` and `value` arguments are provided for each type. Possible values: @@ -1293,13 +1290,13 @@ Possible values: **See also** -- [jerry_promise_callback_t](#jerry_promise_callback_t) -- [jerry_promise_set_callback](#jerry_promise_set_callback) +- [jerry_promise_event_cb_t](#jerry_promise_event_cb_t) +- [jerry_promise_event_cb](#jerry_promise_event_cb) ## jerry_promise_event_filter_t -Filter types for [jerry_promise_set_callback](#jerry_promise_set_callback) callback function. +Filter types for [jerry_promise_event_cb](#jerry_promise_event_cb) callback function. The callback is only called for those events which are enabled by the filters. The events are described in [jerry_promise_event_type_t](#jerry_promise_event_type_t). @@ -1333,10 +1330,10 @@ Possible values: **See also** - [jerry_promise_event_type_t](#jerry_promise_event_type_t) -- [jerry_promise_set_callback](#jerry_promise_set_callback) +- [jerry_promise_event_cb](#jerry_promise_event_cb) -## jerry_promise_callback_t +## jerry_promise_event_cb_t **Summary** @@ -1347,7 +1344,7 @@ description of [jerry_promise_event_type_t](#jerry_promise_event_type_t). **Prototype** ```c -typedef void (*jerry_promise_callback_t) (jerry_promise_event_type_t event_type, +typedef void (*jerry_promise_event_cb_t) (jerry_promise_event_type_t event_type, const jerry_value_t object, const jerry_value_t value, void *user_p); ``` @@ -1355,14 +1352,14 @@ typedef void (*jerry_promise_callback_t) (jerry_promise_event_type_t event_type, - `event_type` - type of the event notification. - `object` - object corresponding to the event. - `value` - optional value argument. -- `user_data_p` - optional user data pointer supplied via the (jerry_promise_set_callback)[#jerry_promise_set_callback] method. +- `user_data_p` - optional user data pointer supplied via the (jerry_promise_event_cb)[#jerry_promise_event_cb] method. *New in version [[NEXT_RELEASE]]*. **See also** - [jerry_promise_event_type_t](#jerry_promise_event_type_t) -- [jerry_promise_set_callback](#jerry_promise_set_callback) +- [jerry_promise_event_cb](#jerry_promise_event_cb) ## jerry_typedarray_type_t @@ -1391,7 +1388,7 @@ TypedArray support is not in the engine. **See also** -- [jerry_get_typedarray_type](#jerry_get_typedarray_type) +- [jerry_typedarray_type](#jerry_typedarray_type) ## jerry_exec_snapshot_option_values_t @@ -1405,9 +1402,9 @@ Various configuration options for [jerry_exec_snapshot](#jerry_exec_snapshot) ```c typedef struct { - jerry_value_t resource_name; /**< resource name string (usually a file name) - * if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts - * Note: non-string values are ignored */ + jerry_value_t source_name; /**< resource name string (usually a file name) + * if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts + * Note: non-string values are ignored */ jerry_value_t user_value; /**< user value assigned to all functions created by this script including * eval calls executed by the script if JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE * is set in exec_snapshot_opts */ @@ -1434,7 +1431,7 @@ Possible values: **See also** - [jerry_source_info_t](#jerry_source_info_t) -- [jerry_get_source_info](#jerry_get_source_info) +- [jerry_source_info](#jerry_source_info) ## jerry_source_info_t @@ -1460,7 +1457,7 @@ typedef struct **See also** - [jerry_source_info_enabled_fields_t](#jerry_source_info_enabled_fields_t) -- [jerry_get_source_info](#jerry_get_source_info) +- [jerry_source_info](#jerry_source_info) ## jerry_arraybuffer_type_t @@ -1475,10 +1472,10 @@ Enum that contains the JerryScript type of an array buffer: **See also** -- [jerry_arraybuffer_allocate_t](#jerry_arraybuffer_allocate_t) -- [jerry_arraybuffer_free_t](#jerry_arraybuffer_free_t) +- [jerry_arraybuffer_allocate_cb_t](#jerry_arraybuffer_allocate_cb_t) +- [jerry_arraybuffer_free_cb_t](#jerry_arraybuffer_free_cb_t) -## jerry_arraybuffer_allocate_t +## jerry_arraybuffer_allocate_cb_t **Summary** @@ -1486,22 +1483,24 @@ Callback for allocating the backing store of array buffer or shared array buffer *Note*: - The value referenced by `arraybuffer_user_p` is always NULL unless the buffer is created by - [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external) or - [jerry_create_shared_arraybuffer_external](#jerry_create_shared_arraybuffer_external). + [jerry_arraybuffer_external](#jerry_arraybuffer_external) or + [jerry_shared_arraybuffer_external](#jerry_shared_arraybuffer_external). The value referenced by `arraybuffer_user_p` can be changed, and the new value is passed to - [jerry_arraybuffer_free_t](#jerry_arraybuffer_free_t). + [jerry_arraybuffer_free_cb_t](#jerry_arraybuffer_free_cb_t). **Prototype** ```c -typedef uint8_t *(*jerry_arraybuffer_allocate_t) (jerry_arraybuffer_type_t buffer_type, uint32_t buffer_size, - void **arraybuffer_user_p, void *user_p); +typedef uint8_t *(*jerry_arraybuffer_allocate_cb_t) (jerry_arraybuffer_type_t buffer_type, + uint32_t buffer_size, + void **arraybuffer_user_p, + void *user_p); ``` - `buffer_type` - type of the array buffer object, see: [jerry_arraybuffer_type_t](#jerry_arraybuffer_type_t). - `buffer_size` - size of the requested buffer. - `arraybuffer_user_p` - [in/out] user pointer assigned to the array buffer or shared array buffer object. -- `user_p` - user pointer passed to [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- `user_p` - user pointer passed to [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) - return value - Pointer to the buffer, if the allocation is successful, NULL otherwise. @@ -1509,9 +1508,9 @@ typedef uint8_t *(*jerry_arraybuffer_allocate_t) (jerry_arraybuffer_type_t buffe **See also** -- [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) -## jerry_arraybuffer_free_t +## jerry_arraybuffer_free_cb_t **Summary** @@ -1519,28 +1518,31 @@ Callback for freeing the backing store of array buffer or shared array buffer ob *Note*: - The value passed to `arraybuffer_user_p` is always NULL unless the buffer is created by - [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external) or - [jerry_create_shared_arraybuffer_external](#jerry_create_shared_arraybuffer_external), - or the value is modified by [jerry_arraybuffer_allocate_t](#jerry_arraybuffer_allocate_t). + [jerry_arraybuffer_external](#jerry_arraybuffer_external) or + [jerry_shared_arraybuffer_external](#jerry_shared_arraybuffer_external), + or the value is modified by [jerry_arraybuffer_allocate_cb_t](#jerry_arraybuffer_allocate_cb_t). **Prototype** ```c -typedef void (*jerry_arraybuffer_free_t) (jerry_arraybuffer_type_t buffer_type, uint8_t *buffer_p, - uint32_t buffer_size, void *arraybuffer_user_p, void *user_p); +typedef void (*jerry_arraybuffer_free_cb_t) (jerry_arraybuffer_type_t buffer_type, + uint8_t *buffer_p, + uint32_t buffer_size, + void *arraybuffer_user_p, + void *user_p); ``` - `buffer_type` - type of the array buffer object, see: [jerry_arraybuffer_type_t](#jerry_arraybuffer_type_t). - `buffer_p` - pointer to the allocated buffer. - `buffer_size` - size of the allocated buffer. - `arraybuffer_user_p` - [in/out] user pointer assigned to the array buffer or shared array buffer object. -- `user_p` - user pointer passed to [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- `user_p` - user pointer passed to [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) *New in version [[NEXT_RELEASE]]*. **See also** -- [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) # General engine functions @@ -1606,7 +1608,7 @@ jerry_cleanup (void); - [jerry_init](#jerry_init) -## jerry_get_context_data +## jerry_context_data **Summary** @@ -1621,12 +1623,12 @@ Retrieve a pointer to the item stored within the current context by the given ma ```c void * -jerry_get_context_data (const jerry_context_data_manager *manager_p); +jerry_context_data (const jerry_context_data_manager *manager_p); ``` - `manager_p`: the manager of this context data item. -- return value: the item created by `manager_p` when `jerry_get_context_data ()` was first called, or a new item created - by `manager_p`, which will be stored for future identical calls to `jerry_get_context_data ()`, and which will be +- return value: the item created by `manager_p` when `jerry_context_data ()` was first called, or a new item created + by `manager_p`, which will be stored for future identical calls to `jerry_context_data ()`, and which will be deinitialized using the `deinit_cb` callback provided by `manager_p` when the context will be destroyed. *New in version 2.0*. @@ -1653,7 +1655,7 @@ my_context_data_new (void *user_data_p) /* * Initialize my_data_p. JerryScript will store it on the current context and return it whenever - * jerry_get_context_data () is called with a pointer to my_manager as defined below. + * jerry_context_data () is called with a pointer to my_manager as defined below. */ } @@ -1681,7 +1683,7 @@ static const jerry_context_data_manager_t my_manager = static void someplace_in_the_code (void) { - my_context_data_t *my_data = (my_context_data_t *) jerry_get_context_data (&my_manager); + my_context_data_t *my_data = (my_context_data_t *) jerry_context_data (&my_manager); /* Perform useful things using the data found in my_data */ } ``` @@ -1702,9 +1704,9 @@ Registers an external magic string array. ```c void -jerry_register_magic_strings (const jerry_char_t * const *ex_str_items_p, - uint32_t count, - const jerry_length_t *str_lengths_p); +jerry_register_magic_strings (const jerry_char_t * const *ex_str_items_p, + uint32_t count, + const jerry_length_t *str_lengths_p); ``` - `ex_str_items_p` - character arrays, representing external magic strings' contents @@ -1751,7 +1753,7 @@ main (void) - [jerry_get_literals_from_snapshot](#jerry_get_literals_from_snapshot) -## jerry_get_memory_stats +## jerry_heap_stats **Summary** @@ -1761,21 +1763,21 @@ Get heap memory stats. - The engine must be initialized with the `JERRY_INIT_MEM_STATS` option to allow heap statistic collections. See [jerry_init](#jerry_init) - This API depends on a build option (`JERRY_MEM_STATS`) and can be checked - in runtime with the `JERRY_FEATURE_MEM_STATS` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + in runtime with the `JERRY_FEATURE_HEAP_STATS` feature enum value, + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c bool -jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p); +jerry_heap_stats (jerry_heap_stats_t *out_stats_p); ``` - `out_stats_p` - out parameter, that provides the heap statistics. - return value - true, if stats were written into the `out_stats_p` pointer. - - false, otherwise. Usually it is because the `JERRY_FEATURE_MEM_STATS` feature is not enabled. + - false, otherwise. Usually it is because the `JERRY_FEATURE_HEAP_STATS` feature is not enabled. *New in version 2.0*. @@ -1786,7 +1788,7 @@ jerry_init (JERRY_INIT_MEM_STATS); // ... jerry_heap_stats_t stats = {0}; -bool get_stats_ret = jerry_get_memory_stats (&stats); +bool get_stats_ret = jerry_heap_stats (&stats); ``` **See also** @@ -1794,7 +1796,7 @@ bool get_stats_ret = jerry_get_memory_stats (&stats); - [jerry_init](#jerry_init) -## jerry_gc +## jerry_heap_gc **Summary** @@ -1804,7 +1806,7 @@ Performs garbage collection. ```c void -jerry_gc (jerry_gc_mode_t mode); +jerry_heap_gc (jerry_gc_mode_t mode); ``` - `mode` - operational mode, see [jerry_gc_mode_t](#jerry_gc_mode_t) @@ -1823,10 +1825,10 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object_value = jerry_create_object (); - jerry_release_value (object_value); + jerry_value_t object_value = jerry_object (); + jerry_value_free (object_value); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); jerry_cleanup (); } @@ -1842,60 +1844,13 @@ main (void) Functions to parse and run JavaScript source code. -## jerry_run_simple - -**Summary** - -The simplest way to run JavaScript. - -**Prototype** - -```c -bool -jerry_run_simple (const jerry_char_t *script_source_p, - size_t script_source_size, - jerry_init_flag_t flags); -``` - -- `script_source_p` - source code, it must be a valid utf8 string. -- `script_source_size` - size of source code buffer, in bytes. -- `jerry_init_flag_t` - combination of various engine configuration flags -- return value - - true, if run was successful - - false, otherwise - -**Example** - -[doctest]: # () - -```c -#include "jerryscript.h" - -int -main (void) -{ - const jerry_char_t script[] = "print ('Hello, World!');"; - - jerry_run_simple (script, sizeof (script) - 1, JERRY_INIT_EMPTY); - return 0; -} -``` - -**See also** - -- [jerry_init](#jerry_init) -- [jerry_cleanup](#jerry_cleanup) -- [jerry_parse](#jerry_parse) -- [jerry_run](#jerry_run) - - ## jerry_parse **Summary** Parse a script, module, or function and create a compiled code using a character string. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -1912,11 +1867,11 @@ jerry_parse (const jerry_char_t *source_p, - `options_p` - additional parsing options, can be NULL if not used - return value - function object value, if script was parsed successfully, - - thrown error, otherwise + - thrown exception, otherwise -*Changed in version 2.0*: Added `resource_name_p`, and `resource_name_length` arguments. +*Changed in version 2.0*: Added `source_name_p`, and `source_name_length` arguments. -*Changed in version [[NEXT_RELEASE]]*: The `resource_name_p`, `resource_name_length`, and `parse_opts` arguments are replaced by `options_p`. +*Changed in version [[NEXT_RELEASE]]*: The `source_name_p`, `source_name_length`, and `parse_opts` arguments are replaced by `options_p`. This function replaces the `jerry_parse_function` method. **Example 1** @@ -1935,19 +1890,19 @@ main (void) const jerry_char_t script[] = "print ('Hello, World!');"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_STRICT_MODE | JERRY_PARSE_HAS_RESOURCE | JERRY_PARSE_HAS_START; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "hello.js"); + parse_options.options = JERRY_PARSE_STRICT_MODE | JERRY_PARSE_HAS_SOURCE_NAME | JERRY_PARSE_HAS_START; + parse_options.source_name = jerry_string_sz ("hello.js"); /* This example script is extracted from the middle of a file. */ parse_options.start_line = 10; parse_options.start_column = 1; jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); /* Run the "parsed_code" script with "jerry_run". */ - jerry_release_value (jerry_run (parsed_code)); - jerry_release_value (parsed_code); + jerry_value_free (jerry_run (parsed_code)); + jerry_value_free (parsed_code); jerry_cleanup (); return 0; @@ -1969,27 +1924,27 @@ main (void) /* Specify the argument list to parse a function. */ jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "a, b"); + parse_options.argument_list = jerry_string_sz ("a, b"); const jerry_char_t function_code[] = "return a + b;"; jerry_value_t parsed_function = jerry_parse (function_code, sizeof (function_code) - 1, &parse_options); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_options.argument_list); /* Use the "parsed_function" as a normal JavaScript function. */ jerry_value_t args[] = { - jerry_create_number (3), - jerry_create_number (4), + jerry_number (3), + jerry_number (4), }; jerry_size_t argc = sizeof (args) / sizeof (args[0]); - jerry_value_t call_result = jerry_call_function (parsed_function, - jerry_create_undefined(), - args, - argc); + jerry_value_t call_result = jerry_call (parsed_function, + jerry_undefined(), + args, + argc); /* use the function result */ - jerry_release_value (call_result); - jerry_release_value (parsed_function); + jerry_value_free (call_result); + jerry_value_free (parsed_function); jerry_cleanup (); return 0; @@ -2008,7 +1963,7 @@ main (void) Parse a script, module, or function and create a compiled code using a string value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -2023,7 +1978,7 @@ jerry_parse_value (const jerry_value_t source_value, - `options_p` - additional parsing options, can be NULL if not used - return value - function object value, if script was parsed successfully, - - thrown error, otherwise + - thrown exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -2039,19 +1994,19 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t script_value = jerry_create_string ((const jerry_char_t *) "print ('Hello, World!');"); + jerry_value_t script_value = jerry_string_sz ("print ('Hello, World!');"); jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_STRICT_MODE | JERRY_PARSE_HAS_RESOURCE | JERRY_PARSE_HAS_START; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "hello.js"); + parse_options.options = JERRY_PARSE_STRICT_MODE | JERRY_PARSE_HAS_SOURCE_NAME | JERRY_PARSE_HAS_START; + parse_options.source_name = jerry_string_sz ("hello.js"); /* This example script is extracted from the middle of a file. */ parse_options.start_line = 10; parse_options.start_column = 1; jerry_value_t parsed_code = jerry_parse_value (script_value, &parse_options); - jerry_release_value (parse_options.resource_name); - jerry_release_value (script_value); - jerry_release_value (parsed_code); + jerry_value_free (parse_options.source_name); + jerry_value_free (script_value); + jerry_value_free (parsed_code); jerry_cleanup (); return 0; @@ -2072,7 +2027,7 @@ Run a Script or Module created by [jerry_parse](#jerry_parse). *Notes*: - The code should be previously parsed with `jerry_parse`. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -2085,7 +2040,7 @@ jerry_run (const jerry_value_t func_val); - `func_val` - function to run - return value - result of bytecode, if run was successful - - thrown error, otherwise + - thrown exception, otherwise **Example** @@ -2105,17 +2060,17 @@ main (void) /* Setup Global scope code */ jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, NULL); - if (!jerry_value_is_error (parsed_code)) + if (!jerry_value_is_exception (parsed_code)) { /* Execute the parsed source code in the Global scope */ jerry_value_t ret_value = jerry_run (parsed_code); /* Returned value must be freed */ - jerry_release_value (ret_value); + jerry_value_free (ret_value); } /* Parsed source code must be freed */ - jerry_release_value (parsed_code); + jerry_value_free (parsed_code); /* Cleanup engine */ jerry_cleanup (); @@ -2133,7 +2088,7 @@ main (void) Perform JavaScript `eval` function call (ECMA-262 v5.1 sec-15.1.2.1). -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -2149,7 +2104,7 @@ jerry_eval (const jerry_char_t *source_p, - `source_size` - length of the source code - `parse_opts` - combination of [jerry_parse_option_enable_feature_t](#jerry_parse_option_enable_feature_t) flags. The following flags are allowed: JERRY_PARSE_STRICT_MODE -- return value - result of eval, may be an error value. +- return value - result of eval, may be an exception value. **Example** @@ -2163,29 +2118,29 @@ jerry_eval (const jerry_char_t *source_p, **See also** -- [jerry_create_external_function](#jerry_create_external_function) +- [jerry_function_external](#jerry_function_external) - [jerry_external_handler_t](#jerry_external_handler_t) -## jerry_run_all_enqueued_jobs +## jerry_run_microtasks **Summary** -Run enqueued Promise jobs until the first thrown error or until all get executed. +Run enqueued Promise tasks until the first thrown exception or until all tasks get executed. -*Important Note*: The job queue is not guaranteed to be empty, after the function call has returned a value. -Therefore, this function is best used in a while loop, handling each error it returns, until the job queue is empty. +*Important Note*: The task queue is not guaranteed to be empty after the function call has returned a value. +Therefore, this function is best used in a while loop, handling each exception it returns, until the queue is empty. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_run_all_enqueued_jobs (void) +jerry_run_microtasks (void) ``` -- return value - result of last executed job, may be error value. +- return value - result of last executed job, may be an exception value. *New in version 2.0*. @@ -2209,16 +2164,16 @@ main (void) jerry_value_t job_value; while (true) { - job_value = jerry_run_all_enqueued_jobs (); + job_value = jerry_run_microtasks (); - if (jerry_value_is_error (job_value)) + if (jerry_value_is_exception (job_value)) { if (jerry_value_is_abort (job_value)) { // Terminate the engine } - // Handle the error here + // Handle the exception here } else { @@ -2227,9 +2182,9 @@ main (void) } } - jerry_release_value (job_value); - jerry_release_value (script_value); - jerry_release_value (parsed_code); + jerry_value_free (job_value); + jerry_value_free (script_value); + jerry_value_free (parsed_code); jerry_cleanup (); return 0; @@ -2239,20 +2194,20 @@ main (void) # Get the global context -## jerry_get_global_object +## jerry_current_realm **Summary** Get the Global object. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_global_object (void); +jerry_current_realm (void); ``` - return value - api value of global object @@ -2261,18 +2216,18 @@ jerry_get_global_object (void); ```c { - jerry_value_t glob_obj_val = jerry_get_global_object (); + jerry_value_t glob_obj_val = jerry_current_realm (); ... // Do something with global object, ex: add properties - jerry_release_value (glob_obj_val); + jerry_value_free (glob_obj_val); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_define_own_property](#jerry_define_own_property) +- [jerry_value_free](#jerry_value_free) +- [jerry_object_define_own_prop](#jerry_object_define_own_prop) # Checker functions @@ -2283,7 +2238,7 @@ Functions to check the type of an API value ([jerry_value_t](#jerry_value_t)). **Summary** -Returns whether the given `jerry_value_t` has the error and abort value set. +Returns whether the given `jerry_value_t` is an abort exception value. **Prototype** @@ -2294,7 +2249,7 @@ jerry_value_is_abort (const jerry_value_t value); - `value` - api value - return value - - true, if the given `jerry_value_t` has the error and abort value set + - true, if the given `jerry_value_t` is an abort exception - false, otherwise *New in version 2.0*. @@ -2304,21 +2259,21 @@ jerry_value_is_abort (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_abort (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** - [jerry_value_t](#jerry_value_t) -- [jerry_value_is_error](#jerry_value_is_error) +- [jerry_value_is_exception](#jerry_value_is_exception) ## jerry_value_is_array @@ -2343,20 +2298,20 @@ jerry_value_is_array (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_array (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_arraybuffer @@ -2367,7 +2322,7 @@ Returns whether the given `jerry_value_t` is an ArrayBuffer object. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -2389,21 +2344,21 @@ jerry_value_is_arraybuffer (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_arraybuffer (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_create_arraybuffer](#jerry_create_arraybuffer) -- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external) +- [jerry_arraybuffer](#jerry_arraybuffer) +- [jerry_arraybuffer_external](#jerry_arraybuffer_external) ## jerry_value_is_shared_arraybuffer @@ -2414,7 +2369,7 @@ Returns whether the given `jerry_value_t` is a SharedArrayBuffer object. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -2436,21 +2391,21 @@ jerry_value_is_shared_arraybuffer (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_shared_arraybuffer (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_create_shared_arraybuffer](#jerry_create_shared_arraybuffer) -- [jerry_create_shared_arraybuffer_external](#jerry_create_shared_arraybuffer_external) +- [jerry_shared_arraybuffer](#jerry_shared_arraybuffer) +- [jerry_shared_arraybuffer_external](#jerry_shared_arraybuffer_external) ## jerry_value_is_boolean @@ -2476,20 +2431,20 @@ jerry_value_is_boolean (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_boolean (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_true @@ -2516,20 +2471,20 @@ jerry_value_is_true (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_true (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_false @@ -2556,20 +2511,20 @@ jerry_value_is_false (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_false (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_constructor @@ -2594,20 +2549,20 @@ jerry_value_is_constructor (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_constructor (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_dataview @@ -2618,7 +2573,7 @@ Returns whether the given `jerry_value_t` is a DataView object value. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_DATAVIEW`) and can be checked in runtime with the `JERRY_FEATURE_DATAVIEW` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -2647,16 +2602,16 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t arraybuffer = jerry_create_arraybuffer (16); - jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 16); + jerry_value_t arraybuffer = jerry_arraybuffer (16); + jerry_value_t dataview = jerry_dataview (arraybuffer, 0, 16); if (jerry_value_is_dataview (dataview)) { // usage of dataview } - jerry_release_value (dataview); - jerry_release_value (arraybuffer); + jerry_value_free (dataview); + jerry_value_free (arraybuffer); jerry_cleanup (); return 0; @@ -2665,26 +2620,26 @@ main (void) **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_dataview](#jerry_create_dataview) +- [jerry_value_free](#jerry_value_free) +- [jerry_dataview](#jerry_dataview) -## jerry_value_is_error +## jerry_value_is_exception **Summary** -Returns whether the given `jerry_value_t` is error value. +Returns whether the given `jerry_value_t` is an exception value. **Prototype** ```c bool -jerry_value_is_error (const jerry_value_t value); +jerry_value_is_exception (const jerry_value_t value); ``` - `value` - api value - return value - - true, if the given `jerry_value_t` is error value. + - true, if the given `jerry_value_t` is an exception value. - false, otherwise *New in version 2.0*. @@ -2694,14 +2649,14 @@ jerry_value_is_error (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - if (jerry_value_is_error (value)) + if (jerry_value_is_exception (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -2733,20 +2688,20 @@ jerry_value_is_function (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_function (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_async_function @@ -2774,20 +2729,20 @@ jerry_value_is_async_function (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_async_function (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_number @@ -2812,20 +2767,20 @@ jerry_value_is_number (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_number (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_null @@ -2851,20 +2806,20 @@ jerry_value_is_null (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_null (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_object @@ -2890,20 +2845,20 @@ jerry_value_is_object (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_object (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_promise @@ -2915,7 +2870,7 @@ Returns whether the given `jerry_value_t` is a promise value. *Notes*: - This API depends on a build option (`JERRY_ESNEXT`) and can be checked in runtime with the `JERRY_FEATURE_PROMISE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -2940,21 +2895,21 @@ jerry_value_is_promise (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_promise (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_promise](#jerry_create_promise) +- [jerry_value_free](#jerry_value_free) +- [jerry_promise](#jerry_promise) ## jerry_value_is_proxy @@ -2966,7 +2921,7 @@ Returns whether the given `jerry_value_t` is a proxy value. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_PROXY`) and can be checked in runtime with the `JERRY_FEATURE_PROXY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -2989,22 +2944,22 @@ jerry_value_is_proxy (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_proxy (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_proxy](#jerry_create_proxy) -- [jerry_create_special_proxy](#jerry_create_special_proxy) +- [jerry_value_free](#jerry_value_free) +- [jerry_proxy](#jerry_proxy) +- [jerry_proxy_custom](#jerry_proxy_custom) ## jerry_value_is_string @@ -3030,20 +2985,20 @@ jerry_value_is_string (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_string (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) ## jerry_value_is_symbol @@ -3055,7 +3010,7 @@ Returns whether the given `jerry_value_t` is a symbol value. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_SYMBOL`) and can be checked in runtime with the `JERRY_FEATURE_SYMBOL` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -3084,17 +3039,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t string_value = jerry_create_string ((const jerry_char_t *) "Symbol description string"); - jerry_value_t symbol_value = jerry_create_symbol (string_value); + jerry_value_t string_value = jerry_string_sz ("Symbol description string"); + jerry_value_t symbol_value = jerry_symbol_with_description (string_value); - jerry_release_value (string_value); + jerry_value_free (string_value); if (jerry_value_is_symbol (symbol_value)) { // usage of symbol_value } - jerry_release_value (symbol_value); + jerry_value_free (symbol_value); jerry_cleanup (); return 0; @@ -3103,8 +3058,8 @@ main (void) **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_symbol](#jerry_create_symbol) +- [jerry_value_free](#jerry_value_free) +- [jerry_symbol](#jerry_symbol) ## jerry_value_is_bigint @@ -3116,7 +3071,7 @@ Returns whether the given `jerry_value_t` is a bigint value. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_BIGINT`) and can be checked in runtime with the `JERRY_FEATURE_BIGINT` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -3145,17 +3100,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t string_value = jerry_create_string ((const jerry_char_t *) "12345678"); + jerry_value_t string_value = jerry_string_sz ("12345678"); jerry_value_t bigint_value = jerry_value_to_bigint (string_value); - jerry_release_value (string_value); + jerry_value_free (string_value); if (jerry_value_is_bigint (bigint_value)) { // usage of bigint_value } - jerry_release_value (bigint_value); + jerry_value_free (bigint_value); jerry_cleanup (); return 0; @@ -3164,8 +3119,8 @@ main (void) **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_bigint](#jerry_create_bigint) +- [jerry_value_free](#jerry_value_free) +- [jerry_bigint](#jerry_bigint) - [jerry_value_to_bigint](#jerry_value_to_bigint) @@ -3178,7 +3133,7 @@ Checks whether the given `jerry_value_t` is a TypedArray object or not. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -3207,14 +3162,14 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t value = jerry_create_typedarray (JERRY_TYPEDARRAY_UINT16, 15); + jerry_value_t value = jerry_typedarray (JERRY_TYPEDARRAY_UINT16, 15); if (jerry_value_is_typedarray (value)) { /* "value" is a typedarray. */ } - jerry_release_value (value); + jerry_value_free (value); jerry_cleanup (); @@ -3224,10 +3179,10 @@ main (void) **See also** -- [jerry_create_typedarray](#jerry_create_typedarray) +- [jerry_typedarray](#jerry_typedarray) -## jerry_get_container_type +## jerry_container_type **Summary** @@ -3237,14 +3192,14 @@ Checks whether the given `jerry_value_t` is the given `jerry_container_type_t` t - This API function depends on a build option (`JERRY_BUILTIN_CONTAINER`) and can be checked runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET` feature enum values. - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c jerry_container_type_t -jerry_get_container_type (const jerry_value_t value) +jerry_container_type (const jerry_value_t value) ``` - `value` - Container object @@ -3265,14 +3220,14 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t value = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); + jerry_value_t value = jerry_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); - if (jerry_get_container_type (value) == JERRY_CONTAINER_TYPE_MAP) + if (jerry_container_type (value) == JERRY_CONTAINER_TYPE_MAP) { /* "value" is a map. */ } - jerry_release_value (value); + jerry_value_free (value); jerry_cleanup (); @@ -3282,7 +3237,7 @@ main (void) **See also** -- [jerry_create_container](#jerry_create_container) +- [jerry_container](#jerry_container) - [jerry_container_type_t](#jerry_container_type_t) @@ -3309,22 +3264,22 @@ jerry_value_is_undefined (const jerry_value_t value) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_undefined (value)) { ... } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_value_get_type +## jerry_value_type **Summary** @@ -3339,7 +3294,7 @@ value has its own enum value. ```c jerry_type_t -jerry_value_get_type (const jerry_value_t value); +jerry_value_type (const jerry_value_t value); ``` - `value` - JavaScript value to check. @@ -3352,16 +3307,16 @@ jerry_value_get_type (const jerry_value_t value); ```c { - jerry_value_t number = jerry_create_number (3.3); + jerry_value_t number = jerry_number (3.3); - jerry_type_t type_info = jerry_value_get_type (number); + jerry_type_t type_info = jerry_value_type (number); if (type_info == JERRY_TYPE_NUMBER) { /* ... */ } - jerry_release_value (number); + jerry_value_free (number); } ``` @@ -3369,7 +3324,7 @@ jerry_value_get_type (const jerry_value_t value); - [jerry_type_t](#jerry_type_t) -## jerry_object_get_type +## jerry_object_type **Summary** @@ -3379,15 +3334,15 @@ for a given value as a [jerry_object_type_t](#jerry_object_type_t) enum value. Note: For non-object parameters `JERRY_OBJECT_TYPE_NONE` is returned. Note: the returned type can be checked for more detailed type information in the following cases: - `JERRY_OBJECT_TYPE_CONTAINER`, *see also:* [jerry_container_get_type](#jerry_container_get_type) - - `JERRY_OBJECT_TYPE_FUNCTION`, *see also:* [jerry_function_get_type](#jerry_function_get_type) - - `JERRY_OBJECT_TYPE_ITERATOR`, *see also:* [jerry_iterator_get_type](#jerry_iterator_get_type) - - `JERRY_OBJECT_TYPE_TYPEDARRAY`, *see also:* [jerry_get_typedarray_type](#jerry_get_typedarray_type) + - `JERRY_OBJECT_TYPE_FUNCTION`, *see also:* [jerry_function_type](#jerry_function_type) + - `JERRY_OBJECT_TYPE_ITERATOR`, *see also:* [jerry_iterator_type](#jerry_iterator_type) + - `JERRY_OBJECT_TYPE_TYPEDARRAY`, *see also:* [jerry_typedarray_type](#jerry_typedarray_type) **Prototype** ```c jerry_object_type_t -jerry_object_get_type (const jerry_value_t value); +jerry_object_type (const jerry_value_t value); ``` - `value` - JavaScript value to check. @@ -3400,16 +3355,16 @@ jerry_object_get_type (const jerry_value_t value); ```c { - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); - jerry_object_type_t object_type_info = jerry_object_get_type (object); + jerry_object_type_t object_type_info = jerry_object_type (object); if (type_info == JERRY_OBJECT_TYPE_GENERIC) { /* ... */ } - jerry_release_value (object); + jerry_value_free (object); } ``` @@ -3417,7 +3372,7 @@ jerry_object_get_type (const jerry_value_t value); - [jerry_object_type_t](#jerry_object_type_t) -## jerry_function_get_type +## jerry_function_type **Summary** @@ -3428,7 +3383,7 @@ for a given value as a [jerry_function_type_t](#jerry_function_type_t) enum valu ```c jerry_function_type_t -jerry_function_get_type (const jerry_value_t value); +jerry_function_type (const jerry_value_t value); ``` - `value` - JavaScript value to check. @@ -3446,14 +3401,14 @@ Note: For non-function parameters `JERRY_FUNCTION_TYPE_NONE` is returned. const jerry_char_t script[] = "function f() {}; f"; jerry_value_t function_object = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); - jerry_function_type_t function_type_info = jerry_function_get_type (function_object); + jerry_function_type_t function_type_info = jerry_function_type (function_object); if (type_info == JERRY_FUNCTION_TYPE_GENERIC) { /* ... */ } - jerry_release_value (function_object); + jerry_value_free (function_object); } ``` @@ -3461,7 +3416,7 @@ Note: For non-function parameters `JERRY_FUNCTION_TYPE_NONE` is returned. - [jerry_function_type_t](#jerry_function_type_t) -## jerry_iterator_get_type +## jerry_iterator_type **Summary** @@ -3472,7 +3427,7 @@ for a given value as a [jerry_iterator_type_t](#jerry_iterator_type_t) enum valu ```c jerry_iterator_type_t -jerry_iterator_get_type (const jerry_value_t value); +jerry_iterator_type (const jerry_value_t value); ``` - `value` - JavaScript value to check. @@ -3490,14 +3445,14 @@ Note: For non-iterator parameters `JERRY_ITERATOR_TYPE_NONE` is returned. const jerry_char_t script[] = "[1, 2, 3].values()"; jerry_value_t iterator = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); - jerry_iterator_type_t iterator_type_info = jerry_iterator_get_type (iterator); + jerry_iterator_type_t iterator_type_info = jerry_iterator_type (iterator); if (type_info == JERRY_ITERATOR_TYPE_ARRAY) { /* ... */ } - jerry_release_value (iterator); + jerry_value_free (iterator); } ``` @@ -3505,7 +3460,7 @@ Note: For non-iterator parameters `JERRY_ITERATOR_TYPE_NONE` is returned. - [jerry_iterator_type_t](#jerry_iterator_type_t) -## jerry_is_feature_enabled +## jerry_feature_enabled **Summary** @@ -3515,7 +3470,7 @@ Returns whether the specified compile time feature is enabled. ```c bool -jerry_is_feature_enabled (const jerry_feature_t feature); +jerry_feature_enabled (const jerry_feature_t feature); ``` - `feature` - jerry feature @@ -3532,7 +3487,7 @@ jerry_is_feature_enabled (const jerry_feature_t feature); /* ... */ jerry_feature_t feature = JERRY_FEATURE_SNAPSHOT_SAVE; - if (jerry_is_feature_enabled (feature)) + if (jerry_feature_enabled (feature)) { /* ... */ } @@ -3547,30 +3502,30 @@ jerry_is_feature_enabled (const jerry_feature_t feature); # Binary operations -## jerry_binary_operation +## jerry_binary_op **Summary** Perform binary operation on the given operands (==, ===, <, >, etc.). -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_binary_operation (jerry_binary_operation_t op, - const jerry_value_t lhs, - const jerry_value_t rhs); +jerry_binary_op (jerry_binary_op_t op, + const jerry_value_t lhs, + const jerry_value_t rhs); ``` - `op` - binary operation - `lhs` - left-hand side operand - `rhs` - right-hand side operand - return value - - error, if argument has an error flag or operation is unsuccessful or unsupported - - true/false, the result of the binary operation on the given operands otherwise + - exception, if operation is unsuccessful or unsupported + - the result of the binary operation on the given operands otherwise *New in version 2.0*. @@ -3580,10 +3535,10 @@ jerry_binary_operation (jerry_binary_operation_t op, { jerry_value_t value1; jerry_value_t value2; - ... // create or acquire value - jerry_value_t result = jerry_binary_operation (JERRY_BIN_OP_EQUAL, value1, value2) + ... // create or copy value + jerry_value_t result = jerry_binary_op (JERRY_BIN_OP_EQUAL, value1, value2) - if (!jerry_value_is_error (result)) + if (!jerry_value_is_exception (result)) { if (jerry_value_is_true (result)) { @@ -3599,9 +3554,9 @@ jerry_binary_operation (jerry_binary_operation_t op, ... // handle error } - jerry_release_value (value1); - jerry_release_value (value2); - jerry_release_value (result); + jerry_value_free (value1); + jerry_value_free (value2); + jerry_value_free (result); } ``` @@ -3617,7 +3572,7 @@ my_constructor (const jerry_call_info_t *call_info_p, const jerry_value_t argv[], const jerry_length_t argc) { - return jerry_create_undefined (); + return jerry_undefined (); } int @@ -3625,32 +3580,32 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t base_obj = jerry_create_object (); - jerry_value_t constructor = jerry_create_external_function (my_constructor); + jerry_value_t base_obj = jerry_object (); + jerry_value_t constructor = jerry_function_external (my_constructor); /* External functions does not have a prototype by default, so we need to create one */ - jerry_value_t prototype_str = jerry_create_string ((const jerry_char_t *) ("prototype")); - jerry_release_value (jerry_set_property (constructor, prototype_str, base_obj)); - jerry_release_value (prototype_str); + jerry_value_t prototype_str = jerry_string_sz ("prototype"); + jerry_value_free (jerry_object_set (constructor, prototype_str, base_obj)); + jerry_value_free (prototype_str); /* Construct the instance. */ - jerry_value_t instance_val = jerry_construct_object (constructor, NULL, 0); + jerry_value_t instance_val = jerry_construct (constructor, NULL, 0); /* Call the API function of 'instanceof'. */ - jerry_value_t is_instance = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, - instance_val, - constructor); - if (!jerry_value_is_error (is_instance) + jerry_value_t is_instance = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, + instance_val, + constructor); + if (!jerry_value_is_exception (is_instance) && jerry_value_is_true (is_instance)) { /* ... */ } /* Free all of the jerry values and cleanup the engine. */ - jerry_release_value (base_obj); - jerry_release_value (constructor); - jerry_release_value (instance_val); - jerry_release_value (is_instance); + jerry_value_free (base_obj); + jerry_value_free (constructor); + jerry_value_free (instance_val); + jerry_value_free (is_instance); jerry_cleanup (); return 0; @@ -3659,14 +3614,14 @@ main (void) **See also** -- [jerry_binary_operation_t](#jerry_binary_operation_t) +- [jerry_binary_op_t](#jerry_binary_op_t) -# Error manipulation functions +# Exception manipulation functions -*Changed in version 2.0*: The error handling and manipulation was modified and the old methods were replaced. +*Changed in version 2.0*: The exception handling and manipulation was modified and the old methods were replaced. -## jerry_create_abort_from_value +## jerry_throw_abort **Summary** @@ -3674,21 +3629,21 @@ Create (api) abort from a value. This function creates an API abort value from an API value. The second argument defines whether the input value must be released or not. If it is set to `true`, -then a [`jerry_release_value`](#jerry_release_value) function will be called +then a [`jerry_value_free`](#jerry_value_free) function will be called for the first argument, so the api value won't be available after the call of -`jerry_create_abort_from_value`. The second argument should be false if both value +`jerry_throw_abort`. The second argument should be false if both value and created abort value are needed. **Prototype** ```c jerry_value_t -jerry_create_abort_from_value (jerry_value_t value, bool release); +jerry_throw_abort (jerry_value_t value, bool take_ownersip); ``` - `value` - api value -- `release` - raw boolean, defines whether input value must be released -- return value - abort (api) value +- `take_ownership` - raw boolean, defines whether input value should be copied +- return value - abort exception value *New in version 2.0*. @@ -3697,12 +3652,12 @@ jerry_create_abort_from_value (jerry_value_t value, bool release); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t abort = jerry_create_abort_from_value (value, true); + jerry_value_t abort = jerry_throw_abort (value, true); // using the 'value' variable after release is invalid. - jerry_release_value (abort); + jerry_value_free (abort); } ``` @@ -3711,45 +3666,45 @@ jerry_create_abort_from_value (jerry_value_t value, bool release); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t abort = jerry_create_abort_from_value (value, false); + jerry_value_t abort = jerry_throw_abort (value, false); // both 'abort' and 'value' can be used and must be released when they are no longer needed - jerry_release_value (abort); - jerry_release_value (value); + jerry_value_free (abort); + jerry_value_free (value); } ``` **See also** - [jerry_value_t](#jerry_value_t) -- [jerry_get_value_from_error](#jerry_get_value_from_error) -- [jerry_create_error_from_value](#jerry_create_error_from_value) +- [jerry_exception_value](#jerry_exception_value) +- [jerry_exception](#jerry_exception) -## jerry_create_error_from_value +## jerry_exception **Summary** -Create (api) error from a value. +Create exception from a value. -This function creates an API error value from an API value. The second argument defines +This function creates an API exception value from an API value. The second argument defines whether the input value must be released or not. If it is set to `true`, -then a [`jerry_release_value`](#jerry_release_value) function will be called +then a [`jerry_value_free`](#jerry_value_free) function will be called for the first argument, so the api value won't be available after the call of -`jerry_create_error_from_value`. The second argument should be false if both value -and created error value are needed. +`jerry_exception`. The second argument should be false if both value +and created exception are needed. **Prototype** ```c jerry_value_t -jerry_create_error_from_value (jerry_value_t value, bool release); +jerry_throw_value (jerry_value_t value, bool take_ownership); ``` - `value` - api value -- `release` - raw boolean, defines whether input value must be released -- return value - error (api) value +- `take_ownership` - raw boolean, defines whether input value should be copied +- return value - exception value *New in version 2.0*. @@ -3758,13 +3713,13 @@ jerry_create_error_from_value (jerry_value_t value, bool release); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t error = jerry_create_error_from_value (value, true); + jerry_value_t exception = jerry_throw_value (value, true); // using the 'value' variable after release is invalid. - jerry_release_value (error); + jerry_value_free (exception); } ``` @@ -3773,42 +3728,39 @@ jerry_create_error_from_value (jerry_value_t value, bool release); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t error = jerry_create_error_from_value (value, false); - // both 'error' and 'value' can be used and must be released when they are no longer needed + jerry_value_t exception = jerry_throw_value (value, false); + // both 'exception' and 'value' can be used and must be released when they are no longer needed - jerry_release_value (error); - jerry_release_value (value); + jerry_value_free (exception); + jerry_value_free (value); } ``` **See also** - [jerry_value_t](#jerry_value_t) -- [jerry_get_value_from_error](#jerry_get_value_from_error) -- [jerry_create_abort_from_value](#jerry_create_abort_from_value) +- [jerry_exception_value](#jerry_exception_value) +- [jerry_throw_abort](#jerry_throw_abort) -## jerry_get_error_type +## jerry_error_type **Summary** -Returns the type of the Error object if possible. +Returns the type of the Error object if possible. If a non-error object is used as the input for the function the +method will return `JERRY_ERROR_NONE` indicating that the value was not an Error object. -If a non-error object is used as the input for the function the method -will return `JERRY_ERROR_NONE` indicating that the value was not -an Error object. However it is still possible that the value contains -error semantics. To correctly detect if a value have error use the -[jerry_value_is_error](#jerry_value_is_error) method. +Note: If an exception value is passed as an argument, the function will inspect the contained value instead. **Prototype** ```c jerry_error_t -jerry_get_error_type (const jerry_value_t value); +jerry_error_type (const jerry_value_t value); ``` -- `value` - api value (possible error object) +- `value` - api value (possible exception object) - return value - JERRY_ERROR_NONE if the input is not an error object - one of the [jerry_error_t](#jerry_error_t) value @@ -3819,46 +3771,45 @@ jerry_get_error_type (const jerry_value_t value); ```c { - jerry_value_t error_obj = jerry_create_error (JERRY_ERROR_RANGE, - (const jerry_char_t *) "error msg"); - jerry_error_t error_type = jerry_get_error_type (error_obj); + jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, "error msg"); + jerry_error_t error_type = jerry_error_type (error_obj); // error_type is now JERRY_ERROR_RANGE. - jerry_release_value (error_obj); + jerry_value_free (error_obj); } ``` **See also** -- [jerry_create_error](#jerry_create_error) -- [jerry_value_is_error](#jerry_value_is_error) +- [jerry_error](#jerry_error) +- [jerry_value_is_exception](#jerry_value_is_exception) -## jerry_get_value_from_error +## jerry_exception_value **Summary** -Get the value from an error. +Get the value contained in an exception. -Many API functions cannot be called with an error value. -This function extracts the API value from an error. The second argument defines -whether the input error value must be released or not. If it is set to `true`, -then a [`jerry_release_value`](#jerry_release_value) function will be called -for the first argument, so the error value won't be available after the call of -`jerry_get_value_from_error`. The second argument should be false if both error -and its represented value are needed. +Many API functions cannot be called with an exception value. +This function extracts the API value from an exception. The second argument defines +whether the input exception value should be released or not. If it is set to `true`, +then a [`jerry_value_free`](#jerry_value_free) function will be called +for the first argument, so the exception value won't be available after the call of +`jerry_exception_value`. The second argument should be false if both the exception +and its contained value are needed. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_value_from_error (jerry_value_t value, bool release) +jerry_exception_value (jerry_value_t value, bool release) ``` -- `value` - error (api) value +- `value` - exception value - `release` - raw boolean, defines whether input value must be released - return value - api value @@ -3869,13 +3820,13 @@ jerry_get_value_from_error (jerry_value_t value, bool release) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t error = jerry_create_error_from_value (value, true); - jerry_value_t value_from_error = jerry_get_value_from_error (error, true); - // using the 'error' variable after release is invalid. + jerry_value_t exception = jerry_throw_value (value, true); + jerry_value_t value_from_error = jerry_exception_value (exception, true); + // using the 'exception' variable after release is invalid. - jerry_release_value (value_from_error); + jerry_value_free (value_from_error); } ``` @@ -3884,34 +3835,34 @@ jerry_get_value_from_error (jerry_value_t value, bool release) ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t error = jerry_create_error_from_value (value, true); - jerry_value_t value_from_error = jerry_get_value_from_error (error, false); - // both 'error' and 'value_from_error' can be used and must be released when they are no longer needed + jerry_value_t exception = jerry_throw_value (value, true); + jerry_value_t value_from_error = jerry_exception_value (exception, false); + // both 'exception' and 'value_from_error' can be used and must be released when they are no longer needed - jerry_release_value (value_from_error); - jerry_release_value (error); + jerry_value_free (value_from_error); + jerry_value_free (exception); } ``` **See also** - [jerry_value_t](#jerry_value_t) -- [jerry_create_error_from_value](#jerry_create_error_from_value) -- [jerry_create_abort_from_value](#jerry_create_abort_from_value) +- [jerry_exception](#jerry_exception) +- [jerry_throw_abort](#jerry_throw_abort) -## jerry_set_error_object_created_callback +## jerry_error_created_cb **Summary** Set the decorator callback for newly created Error objects. The operation of the callback -is described in [jerry_error_object_created_callback_t](#jerry_error_object_created_callback_t). +is described in [jerry_error_object_created_cb_t](#jerry_error_object_created_cb_t). **Prototype** ```c -void jerry_set_error_object_created_callback (jerry_error_object_created_callback_t callback, void *user_p); +void jerry_error_created_cb (jerry_error_object_created_cb_t callback, void *user_p); ``` - `callback` - callback function, the previously set value is overwritten, and setting NULL @@ -3936,10 +3887,9 @@ void main(void) { jerry_init (JERRY_INIT_EMPTY); - jerry_set_error_object_created_callback (error_object_created_callback, NULL); + jerry_error_created_cb (error_object_created_callback, NULL); - jerry_release_value (jerry_create_error (JERRY_ERROR_COMMON, - (const jerry_char_t *) "Message")); + jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, "Message")); jerry_cleanup (); } /* main */ @@ -3947,27 +3897,27 @@ void main(void) **See also** -- [jerry_error_object_created_callback_t](#jerry_error_object_created_callback_t) +- [jerry_error_object_created_cb_t](#jerry_error_object_created_cb_t) -## jerry_set_vm_throw_callback +## jerry_throw_cb **Summary** -The callback passed to this function is called when an error is thrown +The callback passed to this function is called when an exception is thrown in ECMAScript code. The callback is not called again until the value is -caught. See: [jerry_vm_throw_callback_t](#jerry_vm_throw_callback_t). +caught. See: [jerry_throw_cb_t](#jerry_throw_cb_t). *Notes*: - This API depends on a build option (`JERRY_VM_THROW`) and can be checked in runtime with the `JERRY_FEATURE_VM_THROW` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c void -jerry_set_vm_throw_callback (jerry_vm_throw_callback_t throw_cb, - void *user_p); +jerry_throw_cb (jerry_throw_cb_t throw_cb, + void *user_p); ``` - `throw_cb` - callback which is called on throws (passing NULL disables this feature) @@ -3983,7 +3933,7 @@ jerry_set_vm_throw_callback (jerry_vm_throw_callback_t throw_cb, #include "jerryscript.h" static void -vm_throw_callback (const jerry_value_t error_value, /**< captured error */ +vm_throw_callback (const jerry_value_t error_value, /**< captured exception */ void *user_p) /**< user pointer */ { (void) error_value; @@ -3999,11 +3949,11 @@ main (void) jerry_init (JERRY_INIT_EMPTY); int counter = 0; - jerry_set_vm_throw_callback (vm_throw_callback, &counter); + jerry_throw_cb (vm_throw_callback, &counter); const jerry_char_t script[] = "try { throw new Error('1') } catch (e) { throw new Error('2') }"; - jerry_release_value (jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS)); + jerry_value_free (jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS)); /* The counter contains 2. */ @@ -4014,31 +3964,31 @@ main (void) **See also** -- [jerry_vm_throw_callback_t](#jerry_vm_throw_callback_t) -- [jerry_error_is_throw_captured](#jerry_error_is_throw_captured) -- [jerry_error_set_throw_capture](#jerry_error_set_throw_capture) +- [jerry_throw_cb_t](#jerry_throw_cb_t) +- [jerry_exception_is_captured](#jerry_exception_is_captured) +- [jerry_exception_allow_capture](#jerry_exception_allow_capture) -## jerry_error_is_throw_captured +## jerry_exception_is_captured **Summary** -Checks whether the callback set by [jerry_set_vm_throw_callback](#jerry_set_vm_throw_callback) -captured the error. +Checks whether the callback set by [jerry_throw_cb](#jerry_throw_cb) +captured the exception. *Notes*: - This API depends on a build option (`JERRY_VM_THROW`) and can be checked in runtime with the `JERRY_FEATURE_VM_THROW` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -bool jerry_error_is_throw_captured (jerry_value_t value); +bool jerry_exception_is_captured (jerry_value_t value); ``` -- `value` - api value (should be an error reference) +- `value` - api value (should be an exception) - return value - - true, if the vm throw callback captured the error + - true, if the vm throw callback captured the exception - false, otherwise *New in version [[NEXT_RELEASE]]*. @@ -4051,7 +4001,7 @@ bool jerry_error_is_throw_captured (jerry_value_t value); #include "jerryscript.h" static void -vm_throw_callback (const jerry_value_t error_value, /**< captured error */ +vm_throw_callback (const jerry_value_t error_value, /**< captured exception */ void *user_p) /**< user pointer */ { (void) error_value; @@ -4064,17 +4014,17 @@ main (void) jerry_init (JERRY_INIT_EMPTY); int counter = 0; - jerry_set_vm_throw_callback (vm_throw_callback, &counter); + jerry_throw_cb (vm_throw_callback, &counter); const jerry_char_t script[] = "throw new Error()"; jerry_value_t result_value = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); - if (jerry_error_is_throw_captured (result_value)) + if (jerry_exception_is_captured (result_value)) { /* Code enters here, because the vm_throw_callback function is called. */ } - jerry_release_value (result_value); + jerry_value_free (result_value); jerry_cleanup (); return 0; @@ -4083,28 +4033,28 @@ main (void) **See also** -- [jerry_set_vm_throw_callback](#jerry_set_vm_throw_callback) -- [jerry_error_set_throw_capture](#jerry_error_set_throw_capture) +- [jerry_throw_cb](#jerry_throw_cb) +- [jerry_exception_allow_capture](#jerry_exception_allow_capture) -## jerry_error_set_throw_capture +## jerry_exception_allow_capture **Summary** -Sets whether the callback set by [jerry_set_vm_throw_callback](#jerry_set_vm_throw_callback) -should capture the error or not. +Sets whether the callback set by [jerry_throw_cb](#jerry_throw_cb) +should capture the exception or not. *Notes*: - This API depends on a build option (`JERRY_VM_THROW`) and can be checked in runtime with the `JERRY_FEATURE_VM_THROW` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -void jerry_error_set_throw_capture (jerry_value_t value, bool should_capture); +void jerry_exception_allow_capture (jerry_value_t value, bool should_capture); ``` -- `value` - api value (should be an error reference) +- `value` - api value (should be an exception) - `should_capture` - callback should capture this error *New in version [[NEXT_RELEASE]]*. @@ -4117,7 +4067,7 @@ void jerry_error_set_throw_capture (jerry_value_t value, bool should_capture); #include "jerryscript.h" static void -vm_throw_callback (const jerry_value_t error_value, /**< captured error */ +vm_throw_callback (const jerry_value_t error_value, /**< captured exception */ void *user_p) /**< user pointer */ { (void) error_value; @@ -4133,10 +4083,10 @@ throw_exception (const jerry_call_info_t *call_info_p, /**< call info */ (void) argv; (void) argc; - jerry_value_t result_value = jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Error!"); + jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, "Error!"); /* Ignore calling the vm_throw_callback function. */ - jerry_error_set_throw_capture (result_value, false); + jerry_exception_allow_capture (result_value, false); return result_value; } @@ -4146,19 +4096,19 @@ main (void) jerry_init (JERRY_INIT_EMPTY); int counter = 0; - jerry_set_vm_throw_callback (vm_throw_callback, &counter); + jerry_throw_cb (vm_throw_callback, &counter); - jerry_value_t global_object_value = jerry_get_global_object (); - jerry_value_t function_value = jerry_create_external_function (throw_exception); - jerry_value_t function_name_value = jerry_create_string ((const jerry_char_t *) "throw_exception"); + jerry_value_t global_object_value = jerry_current_realm (); + jerry_value_t function_value = jerry_function_external (throw_exception); + jerry_value_t function_name_value = jerry_string_sz ("throw_exception"); - jerry_release_value (jerry_set_property (global_object_value, function_name_value, function_value)); - jerry_release_value (function_name_value); - jerry_release_value (function_value); - jerry_release_value (global_object_value); + jerry_value_free (jerry_object_set (global_object_value, function_name_value, function_value)); + jerry_value_free (function_name_value); + jerry_value_free (function_value); + jerry_value_free (global_object_value); const jerry_char_t script[] = "throw_exception()"; - jerry_release_value (jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS)); + jerry_value_free (jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS)); jerry_cleanup (); return 0; @@ -4167,15 +4117,15 @@ main (void) **See also** -- [jerry_set_vm_throw_callback](#jerry_set_vm_throw_callback) -- [jerry_error_is_throw_captured](#jerry_error_is_throw_captured) +- [jerry_throw_cb](#jerry_throw_cb) +- [jerry_exception_is_captured](#jerry_exception_is_captured) # Getter functions of 'jerry_value_t' Get raw data from API values. -## jerry_get_number_value +## jerry_value_as_number **Summary** @@ -4187,7 +4137,7 @@ If the argument passed is not a number `0.0` will be returned. ```c double -jerry_get_number_value (const jerry_value_t value); +jerry_value_as_number (const jerry_value_t value); ``` - `value` - api value @@ -4200,29 +4150,29 @@ jerry_get_number_value (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value if (jerry_value_is_number (value)) { - double raw_value = jerry_get_number_value (value); + double raw_value = jerry_value_as_number (value); ... // usage of raw value } - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** - [jerry_value_is_number](#jerry_value_is_number) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) # Functions for string values -## jerry_get_string_size +## jerry_string_size **Summary** @@ -4233,7 +4183,7 @@ This is effectively the number of bytes required to store the string's character ```c jerry_size_t -jerry_get_string_size (const jerry_value_t value); +jerry_string_size (const jerry_value_t value, JERRY_ENCODING_CESU8); ``` - `value` - api value - return value - number of bytes in the buffer needed to represent the string. @@ -4242,75 +4192,32 @@ jerry_get_string_size (const jerry_value_t value); ```c { - const jerry_char_t char_array[] = "a string"; - jerry_value_t string = jerry_create_string (char_array); + const char char_array[] = "a string"; + jerry_value_t string = jerry_string_sz (char_array); - jerry_size_t string_size = jerry_get_string_size (string); + jerry_size_t string_size = jerry_string_size (string, JERRY_ENCODING_CESU8); ... // usage of string_size - jerry_release_value (string); + jerry_value_free (string); } ``` **See also** -- [jerry_create_string](#jerry_create_string) -- [jerry_get_string_length](#jerry_get_string_length) -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) +- [jerry_string_sz](#jerry_string_sz) +- [jerry_string_length](#jerry_string_length) +- [jerry_validate_string](#jerry_validate_string) -## jerry_get_utf8_string_size - -**Summary** - -Get the size of an utf8-encoded string. Returns zero, if the value parameter is not a string. -This is effectively the number of bytes required to store the utf8 encoded string's characters. - -*Note*: The difference from [jerry_get_string_size](#jerry_get_string_size) is that it returns with utf-8 string size -instead of the cesu-8 string size. - -**Prototype** - -```c -jerry_size_t -jerry_get_utf8_string_size (const jerry_value_t value); -``` -- `value` - api value -- return value - number of bytes in the buffer needed to represent the utf8-encoded string. - -*New in version 2.0*. - -**Example** - -```c -{ - const jerry_char_t char_array[] = "a string"; - jerry_value_t string = jerry_create_string (char_array); - - jerry_size_t string_size = jerry_get_utf8_string_size (string); - - ... // usage of string_size - - jerry_release_value (string); -} -``` - -**See also** - -- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8) -- [jerry_get_utf8_string_length](#jerry_get_utf8_string_length) -- [jerry_is_valid_utf8_string](#jerry_is_valid_utf8_string) - - -## jerry_get_string_length +## jerry_string_length **Summary** Get the length of a string. Returns zero, if the value parameter is not a string. *Notes:* -- The difference from [jerry_get_string_size](#jerry_get_string_size) is that it +- The difference from [jerry_string_size](#jerry_string_size) is that it returns the number of bytes used for the string. - This is **not** the number of bytes required to store the string. @@ -4318,7 +4225,7 @@ Get the length of a string. Returns zero, if the value parameter is not a string ```c jerry_length_t -jerry_get_string_length (const jerry_value_t value); +jerry_string_length (const jerry_value_t value); ``` - `value` - api value @@ -4328,100 +4235,54 @@ jerry_get_string_length (const jerry_value_t value); ```c { - const jerry_char_t char_array[] = "a string"; - jerry_value_t string = jerry_create_string (char_array); - - jerry_length_t string_length = jerry_get_string_length (string); - - ... // usage of string_length - - jerry_release_value (string); -} -``` - -**See also** - -- [jerry_create_string](#jerry_create_string) -- [jerry_get_string_size](#jerry_get_string_size) -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) - - -## jerry_get_utf8_string_length - -**Summary** - -Get the length of an UTF-8 encoded string. Returns zero, if the value parameter is not a string. - -*Notes*: -- The difference from [jerry_get_string_length](#jerry_get_string_length) is that it - returns with utf-8 string length instead of the cesu-8 string length. -- This is **not** the number of bytes required to store the string. - -**Prototype** - -```c -jerry_length_t -jerry_get_utf8_string_length (const jerry_value_t value); -``` - -- `value` - input string value -- return value - number of characters in the string - -*New in version 2.0*. - -**Example** - -```c -{ - const jerry_char_t char_array[] = "a string"; - jerry_value_t string = jerry_create_string_from_utf8 (char_array); + const char char_array[] = "a string"; + jerry_value_t string = jerry_string_sz (char_array); - jerry_length_t string_length = jerry_get_utf8_string_length (string); + jerry_length_t string_length = jerry_string_length (string); ... // usage of string_length - jerry_release_value (string); + jerry_value_free (string); } ``` **See also** -- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8) -- [jerry_get_utf8_string_size](#jerry_get_utf8_string_size) -- [jerry_is_valid_utf8_string](#jerry_is_valid_utf8_string) +- [jerry_string_sz](#jerry_string_sz) +- [jerry_string_size](#jerry_string_size) +- [jerry_validate_string](#jerry_validate_string) -## jerry_string_to_char_buffer +## jerry_string_to_buffer **Summary** Copy the characters of a string into a specified cesu-8 buffer. The '\0' character could occur in the character buffer. Returns 0, -if the value parameter is not a string or the buffer is not large -enough for the whole string. +if the input value is not a string. *Note*: Does not put '\0' to the end of string, the return value identifies the number of valid bytes in the output buffer. -*Note*: If the size of the string in jerry value is larger than the size of the -target buffer, the copy will fail. To copy a substring the -[jerry_substring_to_char_buffer](#jerry_substring_to_char_buffer) API function -is recommended instead. +*Note*: If the size of the string is larger than the size of the +target buffer, the string will be cropped. **Prototype** ```c jerry_size_t -jerry_string_to_char_buffer (const jerry_value_t value, - jerry_char_t *buffer_p, - jerry_size_t buffer_size); +jerry_string_to_buffer (const jerry_value_t value, + jerry_char_t *buffer_p, + jerry_size_t buffer_size, + jerry_encoding_t encoding); ``` - `value` - input string value - `buffer_p` - pointer to output buffer - `buffer_size` - size of the buffer -- return value - number of bytes, actually copied to the buffer +- `encoding` - encoding oh the string data +- return value - number of bytes copied to the buffer **Example** @@ -4438,17 +4299,17 @@ main (void) jerry_init (JERRY_INIT_EMPTY); jerry_value_t value; - // create or acquire value - value = jerry_create_string ((const jerry_char_t *) "Demo string"); + // create or copy value + value = jerry_string_sz ("Demo string"); // Read the string into a byte buffer. - jerry_size_t string_size = jerry_get_string_size (value); + jerry_size_t string_size = jerry_string_size (value, JERRY_ENCODING_CESU8); jerry_char_t *string_buffer_p = (jerry_char_t *) malloc (sizeof (jerry_char_t) * (string_size + 1)); - jerry_size_t copied_bytes = jerry_string_to_char_buffer (value, string_buffer_p, string_size); + jerry_size_t copied_bytes = jerry_string_to_buffer (value, string_buffer_p, string_size, JERRY_ENCODING_CESU8); string_buffer_p[copied_bytes] = '\0'; - jerry_release_value (value); + jerry_value_free (value); jerry_cleanup (); @@ -4461,188 +4322,12 @@ main (void) **See also** -- [jerry_create_string](#jerry_create_string) -- [jerry_get_string_size](#jerry_get_string_size) -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) -- [jerry_substring_to_char_buffer](#jerry_substring_to_char_buffer) +- [jerry_string_sz](#jerry_string_sz) +- [jerry_string_size](#jerry_string_size) +- [jerry_strig_to_buffer](#jerry_strig_to_buffer) -## jerry_string_to_utf8_char_buffer - -**Summary** - -Copy the characters of a string into a specified utf-8 buffer. -The '\0' character could occur in character buffer. Returns 0, -if the value parameter is not a string or the buffer is not -large enough for the whole string. - -*Note*: Does not put '\0' to the end of string, the return value identifies -the number of valid bytes in the output buffer. - -*Note*: If the size of the string in jerry value is larger than the size of the -target buffer, the copy will fail. To copy a substring the -[jerry_substring_to_utf8_char_buffer](#jerry_substring_to_utf8_char_buffer) -API function is recommended instead. - -**Prototype** - -```c -jerry_size_t -jerry_string_to_utf8_char_buffer (const jerry_value_t value, - jerry_char_t *buffer_p, - jerry_size_t buffer_size); -``` - -- `value` - input string value -- `buffer_p` - pointer to output buffer -- `buffer_size` - size of the buffer -- return value - number of bytes, actually copied to the buffer - -*New in version 2.0*. - -**Example** - -```c -{ - jerry_value_t value; - ... // create or acquire value - - jerry_size_t req_sz = jerry_get_utf8_string_size (value); - jerry_char_t str_buf_p[req_sz]; - - jerry_size_t bytes_copied = jerry_string_to_utf8_char_buffer (value, str_buf_p, req_sz); - - jerry_release_value (value); -} -``` - -**See also** - -- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8) -- [jerry_get_utf8_string_size](#jerry_get_utf8_string_size) -- [jerry_is_valid_utf8_string](#jerry_is_valid_utf8_string) -- [jerry_substring_to_utf8_char_buffer](#jerry_substring_to_utf8_char_buffer) - - -## jerry_substring_to_char_buffer - -**Summary** - -Copy the characters of a cesu-8 encoded substring into a specified buffer. -The '\0' character could occur in character buffer. Returns 0, if the value -parameter is not a string. It will extract the substring between the -specified start position and the end position (or the end of the string, -whichever comes first). - -*Note*: Does not put '\0' to the end of string, the return value identifies -the number of valid bytes in the output buffer. - -**Prototype** - -```c -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); -``` - -- `value` - input string value -- `start_pos` - position of the first character -- `end_pos` - position of the last character -- `buffer_p` - pointer to output buffer -- `buffer_size` - size of the buffer -- return value - number of bytes, actually copied to the buffer - -*New in version 2.0*. - -**Example** - -```c -{ - jerry_value_t value; - ... // create or acquire value - - jerry_size_t req_sz = jerry_get_string_size (value); - jerry_char_t str_buf_p[req_sz]; - jerry_length_t start_pos = 0; - jerry_length_t end_pos = jerry_get_string_length (value); - - jerry_substring_to_char_buffer (value, start_pos, end_pos, str_buf_p, req_sz); - - jerry_release_value (value); -} -``` - -**See also** - -- [jerry_create_string](#jerry_create_string) -- [jerry_get_string_size](#jerry_get_string_size) -- [jerry_get_string_length](#jerry_get_string_length) -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) - - -## jerry_substring_to_utf8_char_buffer - -**Summary** - -Copy the characters of an utf-8 encoded substring into a specified buffer. -The '\0' character could occur in character buffer. Returns 0, if the value -parameter is not a string. It will extract the substring between the specified -start position and the end position (or the end of the string, whichever -comes first). - -*Note*: Does not put '\0' to the end of string, the return value identifies -the number of valid bytes in the output buffer. - -**Prototype** - -```c -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); -``` - -- `value` - input string value -- `start_pos` - position of the first character -- `end_pos` - position of the last character -- `buffer_p` - pointer to output buffer -- `buffer_size` - size of the buffer -- return value - number of bytes, actually copied to the buffer - -*New in version 2.0*. - -**Example** - -```c -{ - jerry_value_t value; - ... // create or acquire value - - jerry_size_t req_sz = jerry_get_utf8_string_size (value); - jerry_char_t str_buf_p[req_sz]; - jerry_length_t start_pos = 0; - jerry_length_t end_pos = jerry_get_utf8_string_length (value); - - jerry_substring_to_utf8_char_buffer (value, start_pos, end_pos, str_buf_p, req_sz); - - jerry_release_value (value); -} -``` - -**See also** - -- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8) -- [jerry_get_utf8_string_size](#jerry_get_utf8_string_size) -- [jerry_get_utf8_string_length](#jerry_get_utf8_string_length) -- [jerry_is_valid_utf8_string](#jerry_is_valid_utf8_string) - - -# jerry_string_set_external_free_callback +# jerry_string_external_free_cb **Summary** @@ -4659,7 +4344,7 @@ first external string is created. **Prototype** ```c -void jerry_string_set_external_free_callback (jerry_external_string_free_callback_t callback_p); +void jerry_string_external_free_cb (jerry_external_string_free_cb_t callback_p); ``` - `callback_p` - callback which is called when an external string is freed. @@ -4687,12 +4372,12 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_string_set_external_free_callback (external_string_free_callback); + jerry_string_external_free_cb (external_string_free_callback); const char *string_p = "This is a long external string, should not be duplicated!"; - jerry_value_t external_string = jerry_create_external_string ((jerry_char_t *) string_p, NULL); + jerry_value_t external_string = jerry_string_external_sz (string_p, NULL); /* The external_string_free_callback is called. */ - jerry_release_value (external_string); + jerry_value_free (external_string); jerry_cleanup (); return 0; @@ -4701,13 +4386,13 @@ main (void) **See also** -- [jerry_external_string_free_callback_t](#jerry_external_string_free_callback_t) -- [jerry_string_get_external_user_pointer](#jerry_string_get_external_user_pointer) -- [jerry_create_external_string](#jerry_create_external_string) -- [jerry_create_external_string_sz](#jerry_create_external_string_sz) +- [jerry_external_string_free_cb_t](#jerry_external_string_free_cb_t) +- [jerry_string_user_ptr](#jerry_string_user_ptr) +- [jerry_string_external_sz](#jerry_string_external_sz) +- [jerry_string_external](#jerry_string_external) -# jerry_string_get_external_user_pointer +# jerry_string_user_ptr **Summary** @@ -4717,13 +4402,13 @@ Returns the user pointer assigned to an external string. - In some cases (e.g. when the string is also a magic string registered by [jerry_register_magic_strings](#jerry_register_magic_strings)), the string is a normal string without a user pointer even if it is created - by [jerry_create_external_string](#jerry_create_external_string). + by [jerry_string_external_sz](#jerry_string_external_sz). **Prototype** ```c -void *jerry_string_get_external_user_pointer (const jerry_value_t value, - bool *is_external); +void *jerry_string_user_ptr (const jerry_value_t value, + bool *is_external); ``` - `value` - string value. @@ -4752,10 +4437,10 @@ main (void) const char *string_p = "This is a long external string, should not be duplicated!"; - jerry_value_t external_string = jerry_create_external_string ((jerry_char_t *) string_p, (void *) &user_value); + jerry_value_t external_string = jerry_string_external_sz (string_p, (void *) &user_value); bool is_external; - void *user_p = jerry_string_get_external_user_pointer (external_string, &is_external); + void *user_p = jerry_string_user_ptr (external_string, &is_external); if (is_external) { @@ -4763,7 +4448,7 @@ main (void) printf("User pointer of an external string: %p\n", user_p); } - jerry_release_value (external_string); + jerry_value_free (external_string); jerry_cleanup (); return 0; @@ -4773,13 +4458,13 @@ main (void) **See also** - [jerry_string_set_external_string_free_callback](#jerry_string_set_external_string_free_callback) -- [jerry_create_external_string](#jerry_create_external_string) -- [jerry_create_external_string_sz](#jerry_create_external_string_sz) +- [jerry_string_external_sz](#jerry_string_external_sz) +- [jerry_string_external](#jerry_string_external) # Functions for array object values -## jerry_get_array_length +## jerry_array_length **Summary** @@ -4789,7 +4474,7 @@ Get length of an array object. Returns zero, if the given parameter is not an ar ```c uint32_t -jerry_get_array_length (const jerry_value_t value); +jerry_array_length (const jerry_value_t value); ``` - `value` - input array value @@ -4800,17 +4485,17 @@ jerry_get_array_length (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - uint32_t len = jerry_get_array_length (value); + uint32_t len = jerry_array_length (value); - jerry_release_value (value); + jerry_value_free (value); } ``` **See also** -- [jerry_create_array](#jerry_create_array) +- [jerry_array](#jerry_array) # Converters of 'jerry_value_t' @@ -4840,11 +4525,11 @@ jerry_value_to_boolean (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value bool b = jerry_value_to_boolean (value); - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -4859,7 +4544,7 @@ jerry_value_to_boolean (const jerry_value_t value); Call ToNumber operation on the api value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -4872,19 +4557,19 @@ jerry_value_to_number (const jerry_value_t value); - `value` - api value - return value - converted number value, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value jerry_value_t number_value = jerry_value_to_number (value); - jerry_release_value (number_value); - jerry_release_value (value); + jerry_value_free (number_value); + jerry_value_free (value); } ``` @@ -4899,7 +4584,7 @@ jerry_value_to_number (const jerry_value_t value); Call ToObject operation on the api value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -4912,19 +4597,19 @@ jerry_value_to_object (const jerry_value_t value); - `value` - api value - return value - converted object value, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value jerry_value_t object_value = jerry_value_to_object (value); - jerry_release_value (object_value); - jerry_release_value (value); + jerry_value_free (object_value); + jerry_value_free (value); } ``` @@ -4938,7 +4623,7 @@ jerry_value_to_object (const jerry_value_t value); Call ToPrimitive operation on the api value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -4951,19 +4636,19 @@ jerry_value_to_primitive (const jerry_value_t value); - `value` - api value - return value - converted primitive value, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value jerry_value_t prim_value = jerry_value_to_primitive (value); - jerry_release_value (prim_value); - jerry_release_value (value); + jerry_value_free (prim_value); + jerry_value_free (value); } ``` @@ -4977,7 +4662,7 @@ jerry_value_to_primitive (const jerry_value_t value); Call the ToString ecma builtin operation on the api value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -4990,19 +4675,19 @@ jerry_value_to_string (const jerry_value_t value); - `value` - api value - return value - converted string value, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value jerry_value_t string_value = jerry_value_to_string (value); - jerry_release_value (string_value); - jerry_release_value (value); + jerry_value_free (string_value); + jerry_value_free (value); } ``` @@ -5017,7 +4702,7 @@ jerry_value_to_string (const jerry_value_t value); Call the BigInt constructor ecma builtin operation on the api value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -5030,7 +4715,7 @@ jerry_value_to_bigint (const jerry_value_t value); - `value` - api value - return value - converted BigInt value, if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.4*. @@ -5039,20 +4724,20 @@ jerry_value_to_bigint (const jerry_value_t value); ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value jerry_value_t bigint_value = jerry_value_to_bigint (value); - jerry_release_value (bigint_value); - jerry_release_value (value); + jerry_value_free (bigint_value); + jerry_value_free (value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) - [jerry_value_is_bigint](#jerry_value_is_bigint) -- [jerry_get_bigint_digits](#jerry_get_bigint_digits) +- [jerry_bigint_to_digits](#jerry_bigint_to_digits) ## jerry_value_as_integer @@ -5079,9 +4764,9 @@ jerry_value_as_integer (const jerry_value_t value); ```c { - jerry_value_t number_val = jerry_create_number (123321); + jerry_value_t number_val = jerry_number (123321); double number = jerry_value_as_integer (number_val); - jerry_release_value (number_val); + jerry_value_free (number_val); } ``` @@ -5110,9 +4795,9 @@ jerry_value_as_int32 (const jerry_value_t value); ```c { - jerry_value_t number_val = jerry_create_number (123321); + jerry_value_t number_val = jerry_number (123321); int32_t number = jerry_value_as_int32 (number_val); - jerry_release_value (number_val); + jerry_value_free (number_val); } ``` @@ -5141,9 +4826,9 @@ jerry_value_as_uint32 (const jerry_value_t value); ```c { - jerry_value_t number_val = jerry_create_number (123321); + jerry_value_t number_val = jerry_number (123321); uint32_t number = jerry_value_as_uint32 (number_val); - jerry_release_value (number_val); + jerry_value_free (number_val); } ``` @@ -5158,17 +4843,17 @@ These APIs all depend on module support. Link modules to their dependencies. The dependencies are resolved by a user callback. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c jerry_value_t jerry_module_link (const jerry_value_t module_val, - jerry_module_resolve_callback_t callback, void *user_p) + jerry_module_resolve_cb_t callback, void *user_p) ``` - `module_val` - module object in unlinked state @@ -5177,7 +4862,7 @@ jerry_value_t jerry_module_link (const jerry_value_t module_val, - `user_p` - user pointer passed to the callback - return - true - if linking is successful - - error - otherwise + - exception - otherwise *New in version [[NEXT_RELEASE]]*. @@ -5202,11 +4887,11 @@ module_resolve_callback (const jerry_value_t specifier, const jerry_char_t script[] = "export var a = 5"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "b.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("b.mjs"); jerry_value_t result = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); return result; } /* module_resolve_callback */ @@ -5218,15 +4903,15 @@ main (void) const jerry_char_t script[] = "import a from 'b.mjs'"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t ret_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); jerry_module_link (ret_value, module_resolve_callback, NULL); - jerry_release_value (ret_value); + jerry_value_free (ret_value); jerry_cleanup (); return 0; @@ -5234,18 +4919,18 @@ main (void) ``` **See also** -- [jerry_module_resolve_callback_t](#jerry_module_resolve_callback_t) +- [jerry_module_resolve_cb_t](#jerry_module_resolve_cb_t) ## jerry_module_evaluate Evaluate a module and its dependencies. The module must be in linked state. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** @@ -5256,7 +4941,7 @@ jerry_value_t jerry_module_evaluate (const jerry_value_t module_val); - `module_val` - module object - return - result of module bytecode execution - if evaluation was successful - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -5276,16 +4961,16 @@ main (void) const jerry_char_t script[] = "export var a = 6"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - jerry_release_value (jerry_module_link (module_value, NULL, NULL)); - jerry_release_value (jerry_module_evaluate (module_value)); + jerry_value_free (jerry_module_link (module_value, NULL, NULL)); + jerry_value_free (jerry_module_evaluate (module_value)); - jerry_release_value (module_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5296,7 +4981,7 @@ main (void) - [jerry_module_link](#jerry_module_link) -## jerry_module_get_state +## jerry_module_state **Summary** @@ -5306,12 +4991,12 @@ are listed in [jerry_module_state_t](#jerry_module_state_t) *Notes*: - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -jerry_module_state_t jerry_module_get_state (const jerry_value_t module_val); +jerry_module_state_t jerry_module_state (const jerry_value_t module_val); ``` - `module_val` - module object @@ -5337,18 +5022,18 @@ main (void) const jerry_char_t script[] = "import a from 'b.mjs'"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (jerry_module_get_state (module_value) == JERRY_MODULE_STATE_UNLINKED) + if (jerry_module_state (module_value) == JERRY_MODULE_STATE_UNLINKED) { printf ("Module parsing has been successful\n"); } - jerry_release_value (module_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5359,7 +5044,7 @@ main (void) - [jerry_module_state_t](#jerry_module_state_t) -## jerry_module_set_state_changed_callback +## jerry_module_state_changed_cb **Summary** @@ -5368,13 +5053,13 @@ Sets a callback which is called after a module state is changed to linked, evalu *Notes*: - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -void jerry_module_set_state_changed_callback (jerry_module_state_changed_callback_t callback, - void *user_p); +void jerry_module_state_changed_cb (jerry_module_state_changed_cb_t callback, + void *user_p); ``` - `callback` - callback, which is called after the state change. @@ -5413,18 +5098,18 @@ main (void) const jerry_char_t script[] = "12"; - jerry_module_set_state_changed_callback (module_state_changed, NULL); + jerry_module_state_changed_cb (module_state_changed, NULL); jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - jerry_release_value (jerry_module_link (module_value, NULL, NULL)); + jerry_value_free (jerry_module_link (module_value, NULL, NULL)); - jerry_release_value (module_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5434,9 +5119,9 @@ main (void) **See also** - [jerry_module_state_t](#jerry_module_state_t) -- [jerry_module_state_changed_callback_t](#jerry_module_state_changed_callback_t) +- [jerry_module_state_changed_cb_t](#jerry_module_state_changed_cb_t) -## jerry_module_set_import_meta_callback +## jerry_module_import_meta_cb **Summary** @@ -5445,13 +5130,13 @@ Sets a callback which is called when an import.meta expression of a module is ev *Notes*: - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -void jerry_module_set_import_meta_callback (jerry_module_import_meta_callback_t callback, - void *user_p); +void jerry_module_import_meta_cb (jerry_module_import_meta_cb_t callback, + void *user_p); ``` - `callback` - callback, which is called when an import.meta @@ -5476,12 +5161,12 @@ module_import_meta_callback (const jerry_value_t module, /**< module */ (void) user_p; /* Create a property for the meta object */ - jerry_value_t property_name_value = jerry_create_string ((const jerry_char_t *) "prop"); - jerry_value_t property_value = jerry_create_string ((const jerry_char_t *) "prop"); - jerry_value_t result_value = jerry_set_property (meta_object, property_name_value, property_value); - jerry_release_value (result_value); - jerry_release_value (property_value); - jerry_release_value (property_name_value); + jerry_value_t property_name_value = jerry_string_sz ("prop"); + jerry_value_t property_value = jerry_string_sz ("prop"); + jerry_value_t result_value = jerry_object_set (meta_object, property_name_value, property_value); + jerry_value_free (result_value); + jerry_value_free (property_value); + jerry_value_free (property_name_value); } /* module_import_meta_callback */ int @@ -5491,17 +5176,17 @@ main (void) const jerry_char_t script[] = "import.meta"; - jerry_module_set_import_meta_callback (module_import_meta_callback, NULL); + jerry_module_import_meta_cb (module_import_meta_callback, NULL); jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_MODULE; jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (jerry_module_link (module_value, NULL, NULL)); - jerry_release_value (jerry_module_evaluate (module_value)); + jerry_value_free (jerry_module_link (module_value, NULL, NULL)); + jerry_value_free (jerry_module_evaluate (module_value)); - jerry_release_value (module_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5510,25 +5195,25 @@ main (void) **See also** -- [jerry_module_import_meta_callback_t](#jerry_module_import_meta_callback_t) +- [jerry_module_import_meta_cb_t](#jerry_module_import_meta_cb_t) -## jerry_module_get_number_of_requests +## jerry_module_request_count **Summary** Returns the number of import/export requests of a module. -The requests can be queried by [jerry_module_get_request](#jerry_module_get_request). +The requests can be queried by [jerry_module_request](#jerry_module_request). *Notes*: - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -size_t jerry_module_get_number_of_requests (const jerry_value_t module_val); +size_t jerry_module_request_count (const jerry_value_t module_val); ``` - `module_val` - module object @@ -5555,16 +5240,16 @@ main (void) "import a from 'c.mjs'"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); /* Prints 2. */ - printf ("Number of requests: %d\n", (int) jerry_module_get_number_of_requests (module_value)); + printf ("Number of requests: %d\n", (int) jerry_module_request_count (module_value)); - jerry_release_value (module_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5573,11 +5258,11 @@ main (void) **See also** -- [jerry_module_get_request](#jerry_module_get_request) +- [jerry_module_request](#jerry_module_request) - [jerry_parse](#jerry_parse) - [jerry_module_link](#jerry_module_link) -## jerry_module_get_request +## jerry_module_request **Summary** @@ -5587,26 +5272,26 @@ are strings. If [jerry_module_link](#jerry_module_link) is completed successfull all returned values are module objects instead. If linking is in progress or fails, the successfully resolved dependencies are module objects, the rest are strings. The number of requests can be queried by -[jerry_module_get_number_of_requests](#jerry_module_get_number_of_requests). +[jerry_module_request_count](#jerry_module_request_count). *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -jerry_value_t jerry_module_get_request (const jerry_value_t module_val, size_t request_index); +jerry_value_t jerry_module_request (const jerry_value_t module_val, size_t request_index); ``` - `module_val` - module object - return - string, if the request has not been resolved yet - module object, if the request has been resolved successfully - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -5627,21 +5312,21 @@ main (void) const jerry_char_t file[] = "a.mjs"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - jerry_value_t request_value = jerry_module_get_request (module_value, 0); + jerry_value_t request_value = jerry_module_request (module_value, 0); /* Returns with b.mjs */ - jerry_release_value (request_value); + jerry_value_free (request_value); - request_value = jerry_module_get_request (module_value, 1); + request_value = jerry_module_request (module_value, 1); /* Returns with c.mjs */ - jerry_release_value (request_value); + jerry_value_free (request_value); - jerry_release_value (module_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5650,31 +5335,31 @@ main (void) **See also** -- [jerry_module_get_number_of_requests](#jerry_module_get_number_of_requests) +- [jerry_module_request_count](#jerry_module_request_count) - [jerry_parse](#jerry_parse) - [jerry_module_link](#jerry_module_link) -## jerry_module_get_namespace +## jerry_module_namespace Returns the namespace object of a module *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -jerry_value_t jerry_module_get_namespace (const jerry_value_t module_val); +jerry_value_t jerry_module_namespace (const jerry_value_t module_val); ``` - `module_val` - module object - return - object, if namespace object is available - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -5694,21 +5379,21 @@ main (void) const jerry_char_t script[] = "export var a = 6"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "a.mjs"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("a.mjs"); jerry_value_t module_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - jerry_release_value (jerry_module_link (module_value, NULL, NULL)); - jerry_release_value (jerry_module_evaluate (module_value)); + jerry_value_free (jerry_module_link (module_value, NULL, NULL)); + jerry_value_free (jerry_module_evaluate (module_value)); - jerry_value_t namespace_value = jerry_module_get_namespace (module_value); + jerry_value_t namespace_value = jerry_module_namespace (module_value); /* Exports can be checked. */ - jerry_release_value (namespace_value); - jerry_release_value (module_value); + jerry_value_free (namespace_value); + jerry_value_free (module_value); jerry_cleanup (); return 0; @@ -5720,7 +5405,7 @@ main (void) - [jerry_module_link](#jerry_module_link) - [jerry_module_evaluate](#jerry_module_evaluate) -## jerry_module_set_import_callback +## jerry_module_import_cb Sets the callback which is called when dynamic imports are resolved. The resolver receives the `user_value` assigned to the currently executed script, which should @@ -5729,19 +5414,19 @@ provide all the information that is necessary for the resolve. *Notes*: - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The possible return values of the callback is explained - in [jerry_module_import_callback_t](#jerry_module_import_callback_t) + in [jerry_module_import_cb_t](#jerry_module_import_cb_t) **Prototype** ```c void -jerry_module_set_import_callback (jerry_module_import_callback_t callback_p, - void *user_p) +jerry_module_import_cb (jerry_module_import_cb_t callback_p, + void *user_p) ``` -- `callback_p` - a [jerry_module_import_callback_t](#jerry_module_import_callback_t) callback which handles `import()` calls +- `callback_p` - a [jerry_module_import_cb_t](#jerry_module_import_cb_t) callback which handles `import()` calls - `user_p` - user pointer passed to the callback *New in version [[NEXT_RELEASE]]*. @@ -5771,12 +5456,12 @@ resolve_dynamic (const jerry_value_t specifier, /**< module specifier */ /* This very simple command queue supports only one task. */ resolve_module_task_t *task_p = (resolve_module_task_t *) user_p; - task_p->specifier = jerry_acquire_value (specifier); - task_p->user_value = jerry_acquire_value (user_value); + task_p->specifier = jerry_value_copy (specifier); + task_p->user_value = jerry_value_copy (user_value); /* This Promise should be evaluated later. */ - jerry_value_t promise = jerry_create_promise (); - task_p->promise = jerry_acquire_value (promise); + jerry_value_t promise = jerry_promise (); + task_p->promise = jerry_value_copy (promise); return promise; } @@ -5786,7 +5471,7 @@ main (void) jerry_init (JERRY_INIT_EMPTY); resolve_module_task_t task; - jerry_module_set_import_callback (resolve_dynamic, &task); + jerry_module_import_cb (resolve_dynamic, &task); const jerry_char_t script[] = "import('modules/my_module.mjs').then(\n" " function (namespace) { /* use namespace */},\n" @@ -5794,47 +5479,47 @@ main (void) ")"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE | JERRY_PARSE_HAS_USER_VALUE; + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME | JERRY_PARSE_HAS_USER_VALUE; /* Resource is usually used for debugging purposes, e.g. for generating backtrace. */ - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "dir/my_script.js"); + parse_options.source_name = jerry_string_sz ("dir/my_script.js"); /* User value should provide information for resolving dynamic imports. * In this case it contains the full path excluding the filename. */ - parse_options.user_value = jerry_create_string ((const jerry_char_t *) "/home/user/dir"); + parse_options.user_value = jerry_string_sz ("/home/user/dir"); jerry_value_t script_value = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); - jerry_release_value (parse_options.user_value); - jerry_release_value (jerry_run (script_value)); - jerry_release_value (script_value); + jerry_value_free (parse_options.source_name); + jerry_value_free (parse_options.user_value); + jerry_value_free (jerry_run (script_value)); + jerry_value_free (script_value); /* The application resolves both the module and the promise using the specifier * and the user_value. In this example the specifier is modules/my_module.mjs. */ const jerry_char_t module_script[] = "export var a = 5"; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE | JERRY_PARSE_HAS_USER_VALUE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "modules/my_module.mjs"); - parse_options.user_value = jerry_create_string ((const jerry_char_t *) "/home/user/dir/modules"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME | JERRY_PARSE_HAS_USER_VALUE; + parse_options.source_name = jerry_string_sz ("modules/my_module.mjs"); + parse_options.user_value = jerry_string_sz ("/home/user/dir/modules"); jerry_value_t module_value = jerry_parse (module_script, sizeof (module_script) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); - jerry_release_value (parse_options.user_value); - jerry_release_value (jerry_module_link (module_value, NULL, NULL)); - jerry_release_value (jerry_module_evaluate (module_value)); + jerry_value_free (parse_options.source_name); + jerry_value_free (parse_options.user_value); + jerry_value_free (jerry_module_link (module_value, NULL, NULL)); + jerry_value_free (jerry_module_evaluate (module_value)); /* The promise must be resolved with the namespace object, not the module. */ - jerry_value_t namespace_value = jerry_module_get_namespace (module_value); - jerry_release_value (jerry_resolve_or_reject_promise (task.promise, namespace_value, true)); + jerry_value_t namespace_value = jerry_module_namespace (module_value); + jerry_value_free (jerry_promise_resolve (task.promise, namespace_value)); - jerry_release_value (namespace_value); - jerry_release_value (module_value); - jerry_release_value (task.specifier); - jerry_release_value (task.user_value); - jerry_release_value (task.promise); + jerry_value_free (namespace_value); + jerry_value_free (module_value); + jerry_value_free (task.specifier); + jerry_value_free (task.user_value); + jerry_value_free (task.promise); /* Process promise handlers. */ - jerry_release_value (jerry_run_all_enqueued_jobs ()); + jerry_value_free (jerry_run_microtasks ()); jerry_cleanup (); return 0; @@ -5842,39 +5527,39 @@ main (void) ``` **See also** -- [jerry_module_import_callback_t](#jerry_module_import_callback_t) +- [jerry_module_import_cb_t](#jerry_module_import_cb_t) -## jerry_native_module_create +## jerry_native_module Creates a native module with a list of exports. The initial state of the module is linked. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - Native pointers can be used to assign private data to a native module, - see [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) + see [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) - When `callback` is `NULL`, no function is called when the module is evaluated, only its state is changed to evaluated. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c jerry_value_t -jerry_native_module_create (jerry_native_module_evaluate_callback_t callback, - const jerry_value_t * const exports_p, - size_t number_of_exports); +jerry_native_module (jerry_native_module_evaluate_cb_t callback, + const jerry_value_t * const exports_p, + size_t number_of_exports); ``` -- `callback` - a [jerry_native_module_evaluate_callback_t](#jerry_native_module_evaluate_callback_t) callback +- `callback` - a [jerry_native_module_evaluate_cb_t](#jerry_native_module_evaluate_cb_t) callback which is called by [jerry_module_evaluate](#jerry_module_evaluate) to evaluate the native module. - `exports_p` - list of the exported bindings of the module, must be valid string identifiers. - `number_of_exports` - number of exports in the `exports_p` list. - return - a native module, if the module is successfully created - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -5892,15 +5577,15 @@ main (void) jerry_value_t exports[2] = { - jerry_create_string ((const jerry_char_t *) "first_export"), - jerry_create_string ((const jerry_char_t *) "second_export") + jerry_string_sz ("first_export"), + jerry_string_sz ("second_export") }; - jerry_value_t native_module = jerry_native_module_create (NULL, exports, 2); + jerry_value_t native_module = jerry_native_module (NULL, exports, 2); - jerry_release_value (exports[0]); - jerry_release_value (exports[1]); - jerry_release_value (native_module); + jerry_value_free (exports[0]); + jerry_value_free (exports[1]); + jerry_value_free (native_module); jerry_cleanup (); return 0; @@ -5911,33 +5596,33 @@ main (void) - [jerry_module_link](#jerry_module_link) - [jerry_module_evaluate](#jerry_module_evaluate) -- [jerry_native_module_get_export](#jerry_native_module_get_export) -- [jerry_native_module_set_export](#jerry_native_module_set_export) +- [jerry_native_module_get](#jerry_native_module_get) +- [jerry_native_module_set](#jerry_native_module_set) -## jerry_native_module_get_export +## jerry_native_module_get Gets the value of an export binding which belongs to a native module. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c jerry_value_t -jerry_native_module_get_export (const jerry_value_t native_module_val, - const jerry_value_t export_name_val); +jerry_native_module_get (const jerry_value_t native_module_val, + const jerry_value_t export_name_val); ``` - `native_module_val` - a native module object. - `export_name_val` - string identifier of the export. - return - value of the export, if success - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -5953,15 +5638,15 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t export = jerry_create_string ((const jerry_char_t *) "an_export"); + jerry_value_t export = jerry_string_sz ("an_export"); - jerry_value_t native_module = jerry_native_module_create (NULL, &export, 1); + jerry_value_t native_module = jerry_native_module (NULL, &export, 1); - jerry_value_t value = jerry_native_module_get_export (native_module, export); - jerry_release_value (value); + jerry_value_t value = jerry_native_module_get (native_module, export); + jerry_value_free (value); - jerry_release_value (export); - jerry_release_value (native_module); + jerry_value_free (export); + jerry_value_free (native_module); jerry_cleanup (); return 0; @@ -5970,27 +5655,27 @@ main (void) **See also** -- [jerry_native_module_create](#jerry_native_module_create) -- [jerry_native_module_set_export](#jerry_native_module_set_export) +- [jerry_native_module](#jerry_native_module) +- [jerry_native_module_set](#jerry_native_module_set) -## jerry_native_module_set_export +## jerry_native_module_set Sets the value of an export binding which belongs to a native module. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_MODULE_SYSTEM`) and can be checked in runtime with the `JERRY_FEATURE_MODULE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c jerry_value_t -jerry_value_t jerry_native_module_set_export (const jerry_value_t native_module_val, - const jerry_value_t export_name_val, - const jerry_value_t value_to_set) +jerry_value_t jerry_native_module_set (const jerry_value_t native_module_val, + const jerry_value_t export_name_val, + const jerry_value_t value_to_set) ``` - `native_module_val` - a native module object. @@ -5998,7 +5683,7 @@ jerry_value_t jerry_native_module_set_export (const jerry_value_t native_module_ - `value_to_set` - new value of the export. - return - true, if success - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -6014,17 +5699,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t export = jerry_create_string ((const jerry_char_t *) "an_export"); + jerry_value_t export = jerry_string_sz ("an_export"); - jerry_value_t native_module = jerry_native_module_create (NULL, &export, 1); + jerry_value_t native_module = jerry_native_module (NULL, &export, 1); - jerry_value_t number = jerry_create_number (3.5); - jerry_value_t value = jerry_native_module_set_export (native_module, export, number); - jerry_release_value (value); - jerry_release_value (number); + jerry_value_t number = jerry_number (3.5); + jerry_value_t value = jerry_native_module_set (native_module, export, number); + jerry_value_free (value); + jerry_value_free (number); - jerry_release_value (export); - jerry_release_value (native_module); + jerry_value_free (export); + jerry_value_free (native_module); jerry_cleanup (); return 0; @@ -6033,25 +5718,25 @@ main (void) **See also** -- [jerry_native_module_create](#jerry_native_module_create) -- [jerry_native_module_get_export](#jerry_native_module_get_export) +- [jerry_native_module](#jerry_native_module) +- [jerry_native_module_get](#jerry_native_module_get) # Functions for promise objects These APIs all depend on the es.next profile (or on some build options). -## jerry_get_promise_result +## jerry_promise_result **Summary** The function returns the result of a Promise object. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_ESNEXT`) and can be checked in runtime with the `JERRY_FEATURE_PROMISE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -6059,7 +5744,7 @@ The function returns the result of a Promise object. ```c jerry_value_t -jerry_get_promise_result (const jerry_value_t promise); +jerry_promise_result (const jerry_value_t promise); ``` - `promise` - the input Promise object. @@ -6083,44 +5768,43 @@ jerry_get_promise_result (const jerry_value_t promise); static void example (void) { - // acquire/create a promise object. - jerry_value_t promise = jerry_create_promise (); + // create a promise object. + jerry_value_t promise = jerry_promise (); { // prepare the argument for the resolve or reject. - jerry_value_t argument = jerry_create_number (33); + jerry_value_t argument = jerry_number (33); - jerry_value_t is_ok = jerry_resolve_or_reject_promise (promise, - argument, - true); - // 'is_ok' should be checked if it is an error or not. + jerry_value_t is_ok = jerry_promise_resolve (promise, argument); + + // 'is_ok' should be checked if it is an exception or not. // skipped in this example - jerry_release_value (is_ok); - jerry_release_value (argument); + jerry_value_free (is_ok); + jerry_value_free (argument); } - jerry_value_t promise_result = jerry_get_promise_result (promise); + jerry_value_t promise_result = jerry_promise_result (promise); // 'promise_result' is now the number 33. - jerry_release_value (promise_result); - jerry_release_value (promise); + jerry_value_free (promise_result); + jerry_value_free (promise); } ``` **See also** -- [jerry_create_promise](#jerry_create_promise) +- [jerry_promise](#jerry_promise) - [jerry_promise_state_t](#jerry_promise_state_t) -## jerry_get_promise_state +## jerry_promise_state **Summary** *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_ESNEXT`) and can be checked in runtime with the `JERRY_FEATURE_PROMISE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -6128,7 +5812,7 @@ example (void) ```c jerry_promise_state_t -jerry_get_promise_state (const jerry_value_t promise); +jerry_promise_state (const jerry_value_t promise); ``` - `promise` - the input promise object. @@ -6151,38 +5835,37 @@ jerry_get_promise_state (const jerry_value_t promise); static void example (void) { - // acquire/create a promise object. - jerry_value_t promise = jerry_create_promise (); + // create a promise object. + jerry_value_t promise = jerry_promise (); - jerry_promise_state_t start_state = jerry_get_promise_state (promise); + jerry_promise_state_t start_state = jerry_promise_state (promise); // a Promise have a default state of JERRY_PROMISE_STATE_PENDING { // prepare the argument for the resolve or reject. - jerry_value_t argument = jerry_create_number (33); + jerry_value_t argument = jerry_number (33); + + jerry_value_t is_ok = jerry_promise_resolve (promise, argument); - jerry_value_t is_ok = jerry_resolve_or_reject_promise (promise, - argument, - true); - // 'is_ok' should be checked if it is an error or not. + // 'is_ok' should be checked if it is an exception or not. // skipped in this example - jerry_release_value (is_ok); - jerry_release_value (argument); + jerry_value_free (is_ok); + jerry_value_free (argument); } - jerry_promise_state_t current_state = jerry_get_promise_state (promise); + jerry_promise_state_t current_state = jerry_promise_state (promise); // at this point the Promise should be in the JERRY_PROMISE_STATE_FULFILLED state. - jerry_release_value (promise); + jerry_value_free (promise); } ``` **See also** -- [jerry_create_promise](#jerry_create_promise) +- [jerry_promise](#jerry_promise) - [jerry_promise_state_t](#jerry_promise_state_t) -## jerry_promise_set_callback +## jerry_promise_event_cb **Summary** @@ -6191,14 +5874,14 @@ Sets a callback for tracking Promise and async operations. *Notes*: - This API depends on a build option (`JERRY_PROMISE_CALLBACK`) and can be checked in runtime with the `JERRY_FEATURE_PROMISE_CALLBACK` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -void jerry_promise_set_callback (jerry_promise_event_filter_t filters, jerry_promise_callback_t callback, - void *user_p); +void jerry_promise_event_cb (jerry_promise_event_filter_t filters, jerry_promise_event_cb_t callback, + void *user_p); ``` - `filters` - combination of [jerry_promise_event_filter_t](#jerry_promise_event_filter_t) options @@ -6239,13 +5922,13 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_CREATE, promise_callback, NULL); + jerry_promise_event_cb (JERRY_PROMISE_EVENT_FILTER_CREATE, promise_callback, NULL); const char *source_p = "var p = Promise.resolve(0)\n" "p.then(function (v) { return v; })"; - jerry_release_value (jerry_eval ((const jerry_char_t *) source_p, - strlen (source_p), - JERRY_PARSE_NO_OPTS)); + jerry_value_free (jerry_eval ((const jerry_char_t *) source_p, + strlen (source_p), + JERRY_PARSE_NO_OPTS)); jerry_cleanup (); return 0; @@ -6254,10 +5937,10 @@ main (void) **See also** -- [jerry_create_promise](#jerry_create_promise) +- [jerry_promise](#jerry_promise) - [jerry_promise_state_t](#jerry_promise_state_t) -## jerry_from_property_descriptor +## jerry_property_descriptor_to_object **Summary** @@ -6265,21 +5948,21 @@ This API function is equivalent to FromPropertyDescriptor operation defined in E It returns with an ECMAScript Object which represents the property attributes. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc_p) +jerry_property_descriptor_to_object (const jerry_property_descriptor_t *src_prop_desc_p) ``` - `src_prop_desc_p` - the input property descriptor. - return - [jerry_value_t](#jerry_value_t) - - jerry value - if success - - value marked with error flag - otherwise + - object value - if success + - exception - otherwise *New in version 2.4*. @@ -6293,22 +5976,22 @@ jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc static void example (void) { - jerry_value_t prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "value"); + jerry_value_t prop_name = jerry_string_sz ("value"); - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); prop_desc.value = prop_name; prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED; - jerry_value_t from_object = jerry_from_property_descriptor (&prop_desc); + jerry_value_t from_object = jerry_property_descriptor_to_object (&prop_desc); - jerry_release_value (prop_name); - jerry_release_value (from_object); + jerry_value_free (prop_name); + jerry_value_free (from_object); jerry_property_descriptor_free (&prop_desc); } ``` -## jerry_to_property_descriptor +## jerry_property_descriptor_from_object **Summary** @@ -6316,14 +5999,14 @@ This API function is equivalent to ToPropertyDescriptor operation defined in ECM It decodes the ECMAScript object and fills the fields of a JerryScript property descriptor. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_to_property_descriptor (jerry_value_t obj_value, jerry_property_descriptor_t *out_prop_desc_p); +jerry_property_descriptor_from_object (jerry_value_t obj_value, jerry_property_descriptor_t *out_prop_desc_p); ``` - `obj_value` - the input object @@ -6331,7 +6014,7 @@ jerry_to_property_descriptor (jerry_value_t obj_value, jerry_property_descriptor - return - [jerry_value_t](#jerry_value_t) - true, if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.4*. @@ -6345,34 +6028,34 @@ jerry_to_property_descriptor (jerry_value_t obj_value, jerry_property_descriptor static void example (void) { - jerry_value_t object = jerry_create_object (); - jerry_value_t prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "value"); - jerry_value_t value = jerry_create_boolean (true); + jerry_value_t object = jerry_object (); + jerry_value_t prop_name = jerry_string_sz ("value"); + jerry_value_t value = jerry_boolean (true); jerry_property_descriptor_t prop_desc; - jerry_release_value (jerry_set_property (object, prop_name, prop_name)); + jerry_value_free (jerry_object_set (object, prop_name, prop_name)); - jerry_release_value (jerry_to_property_descriptor (object, &prop_desc)); + jerry_value_free (jerry_property_descriptor_from_object (object, &prop_desc)); - jerry_release_value (object); - jerry_release_value (prop_name); - jerry_release_value (value); + jerry_value_free (object); + jerry_value_free (prop_name); + jerry_value_free (value); jerry_property_descriptor_free (&prop_desc); } ``` -## jerry_resolve_or_reject_promise +## jerry_promise_resolve **Summary** -Resolve or reject the promise with an argument. +Resolve the promise with an argument. *Note*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_ESNEXT`) and can be checked in runtime with the `JERRY_FEATURE_PROMISE` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -6380,17 +6063,15 @@ Resolve or reject the promise with an argument. ```c jerry_value_t -jerry_resolve_or_reject_promise (jerry_value_t promise, - jerry_value_t argument, - bool is_resolve) +jerry_promise_resolve (jerry_value_t promise, + jerry_value_t argument); ``` - `promise` - the promise value -- `argument` - the argument for resolve or reject -- `is_resolve` - whether the promise should be resolved or rejected +- `argument` - the argument value - return value - - undefined jerry value - success of resolve or reject - - jerry value with error flag - otherwise + - undefined - if resolve call was successful + - exception - otherwise *New in version 2.0*. @@ -6400,49 +6081,107 @@ jerry_resolve_or_reject_promise (jerry_value_t promise, ```c { - jerry_value_t promise = ... // acquire/create a promise object. + jerry_value_t promise = ... // create/copy a promise object. ... - bool is_resolve = ... // whether the promise should be resolved or rejected - jerry_value_t argument = ... // prepare the argument for the resolve or reject. + jerry_value_t argument = ... // prepare the argument for resolve. - jerry_value_t is_ok = jerry_resolve_or_reject_promise (promise, - argument, - is_resolve); + jerry_value_t is_ok = jerry_promise_resolve (promise, argument); - if (jerry_value_is_error (is_ok)) + if (jerry_value_is_exception (is_ok)) { - // handle the error. + // handle the exception. } - jerry_release_value (is_ok); - jerry_release_value (argument); - jerry_release_value (promise); + jerry_value_free (is_ok); + jerry_value_free (argument); + jerry_value_free (promise); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_value_is_error](#jerry_value_is_error) +- [jerry_value_free](#jerry_value_free) +- [jerry_value_is_exception](#jerry_value_is_exception) + +## jerry_promise_reject + +**Summary** + +Reject the promise with an argument. + +*Note*: +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it + is no longer needed. +- This API depends on a build option (`JERRY_ESNEXT`) and can be checked + in runtime with the `JERRY_FEATURE_PROMISE` feature enum value, + see: [jerry_feature_enabled](#jerry_feature_enabled). +- The es.next profile enables this by default. + + +**Prototype** + +```c +jerry_value_t +jerry_promise_reject (jerry_value_t promise, + jerry_value_t argument); +``` + +- `promise` - the promise value +- `argument` - the argument value +- return value + - undefined - if reject call was successful + - exception - otherwise + +*New in version 2.0*. + +*Changed in version [[NEXT_RELEASE]]*: Build option dependency changed from `JERRY_BUILTIN_PROMISE` to `JERRY_ESNEXT`. + +**Example** + +```c +{ + jerry_value_t promise = ... // create/copy a promise object. + + ... + + jerry_value_t argument = ... // prepare the argument for reject. + + jerry_value_t is_ok = jerry_promise_reject (promise, argument); + + if (jerry_value_is_exception (is_ok)) + { + // handle the exception. + } + + jerry_value_free (is_ok); + jerry_value_free (argument); + jerry_value_free (promise); +} +``` + +**See also** + +- [jerry_value_free](#jerry_value_free) +- [jerry_value_is_exception](#jerry_value_is_exception) # Functions for symbols These APIs all depend on the es.next profile (or on build options). -## jerry_get_well_known_symbol +## jerry_symbol **Summary** Get the well-known symbol corresponding to the given [well-known symbol id](#jerry_well_known_symbol_t). *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_SYMBOL`) and can be checked in runtime with the `JERRY_FEATURE_SYMBOL` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. - If the symbol support is not enabled an undefined will be returned. @@ -6450,7 +6189,7 @@ Get the well-known symbol corresponding to the given [well-known symbol id](#jer ```c jerry_value_t -jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol); +jerry_symbol (jerry_well_known_symbol_t symbol); ``` - `symbol` - [jerry_well_known_symbol_t](#jerry_well_known_symbol_t) enum value @@ -6472,15 +6211,15 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t array_value = jerry_create_array (5); - jerry_value_t symbol_iterator = jerry_get_well_known_symbol (JERRY_SYMBOL_ITERATOR); - jerry_value_t array_iterator = jerry_get_property (array_value, symbol_iterator); + jerry_value_t array_value = jerry_array (5); + jerry_value_t symbol_iterator = jerry_symbol (JERRY_SYMBOL_ITERATOR); + jerry_value_t array_iterator = jerry_object_get (array_value, symbol_iterator); // usage of array_iterator - jerry_release_value (array_iterator); - jerry_release_value (symbol_iterator); - jerry_release_value (array_value); + jerry_value_free (array_iterator); + jerry_value_free (symbol_iterator); + jerry_value_free (array_value); jerry_cleanup (); return 0; @@ -6491,32 +6230,32 @@ main (void) - [jerry_well_known_symbol_t](#jerry_well_known_symbol_t) -## jerry_get_symbol_description +## jerry_symbol_description **Summary** Returns with the `[[Description]]` internal property of a symbol value. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_SYMBOL`) and can be checked in runtime with the `JERRY_FEATURE_SYMBOL` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. -- If the symbol support is not enabled an error will be returned. +- If symbol support is not enabled an exception will be returned. **Prototype** ```c jerry_value_t -jerry_get_symbol_description (const jerry_value_t value); +jerry_symbol_description (const jerry_value_t value); ``` - `value` - symbol value - return value - string or undefined value containing the symbol's description - if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.4*. @@ -6532,17 +6271,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t string_value = jerry_create_string ((const jerry_char_t *) "foo"); - jerry_value_t symbol_value = jerry_create_symbol (string_value); + jerry_value_t string_value = jerry_string_sz ("foo"); + jerry_value_t symbol_value = jerry_symbol_with_description (string_value); - jerry_release_value (string_value); + jerry_value_free (string_value); - jerry_value_t symbol_description = jerry_get_symbol_description (symbol_value); + jerry_value_t symbol_description = jerry_symbol_description (symbol_value); // usage of symbol_desc_string - jerry_release_value (symbol_description); - jerry_release_value (symbol_value); + jerry_value_free (symbol_description); + jerry_value_free (symbol_value); jerry_cleanup (); return 0; @@ -6551,9 +6290,9 @@ main (void) **See also** -- [jerry_get_symbol_descriptive_string](#jerry_get_symbol_descriptive_string) +- [jerry_symbol_descriptive_string](#jerry_symbol_descriptive_string) -## jerry_get_symbol_descriptive_string +## jerry_symbol_descriptive_string **Summary** @@ -6561,25 +6300,25 @@ Call the SymbolDescriptiveString ecma builtin operation on the API value. Based on ECMA 262 v6 19.4.3.2.1 this is in the form of `Symbol()`. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_SYMBOL`) and can be checked in runtime with the `JERRY_FEATURE_SYMBOL` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. -- If the symbol support is not enabled an error will be returned. +- If symbol support is not enabled an exception will be returned. **Prototype** ```c jerry_value_t -jerry_get_symbol_descriptive_string (const jerry_value_t value); +jerry_symbol_descriptive_string (const jerry_value_t value); ``` - `value` - symbol value - return value - string value containing the symbol's descriptive string - if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.0*. @@ -6595,17 +6334,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t string_value = jerry_create_string ((const jerry_char_t *) "foo"); - jerry_value_t symbol_value = jerry_create_symbol (string_value); + jerry_value_t string_value = jerry_string_sz ("foo"); + jerry_value_t symbol_value = jerry_symbol_with_description (string_value); - jerry_release_value (string_value); + jerry_value_free (string_value); - jerry_value_t symbol_desc_string = jerry_get_symbol_descriptive_string (symbol_value); + jerry_value_t symbol_desc_string = jerry_symbol_descriptive_string (symbol_value); // usage of symbol_desc_string - jerry_release_value (symbol_desc_string); - jerry_release_value (symbol_value); + jerry_value_free (symbol_desc_string); + jerry_value_free (symbol_value); jerry_cleanup (); return 0; @@ -6614,32 +6353,32 @@ main (void) **See also** -- [jerry_get_symbol_description](#jerry_get_symbol_description) +- [jerry_symbol_description](#jerry_symbol_description) # Functions for BigInts These APIs all depend on build option (`JERRY_BUILTIN_BIGINT`). -## jerry_get_bigint_size_in_digits +## jerry_bigint_digit_count **Summary** Returns the size of uint64 digits of a BigInt value. This value is the minimum size of the buffer which can hold all digits of a BigInt value when -the digits are retrieved by `[jerry_get_bigint_digits](#jerry_get_bigint_digits)`. +the digits are retrieved by `[jerry_bigint_to_digits](#jerry_bigint_to_digits)`. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_BIGINT`) and can be checked in runtime with the `JERRY_FEATURE_BIGINT` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it + see: [jerry_feature_enabled](#jerry_feature_enabled). +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c uint32_t -jerry_get_bigint_size_in_digits (jerry_value_t value) +jerry_bigint_digit_count (jerry_value_t value) ``` - `value` - BigInt value @@ -6662,12 +6401,12 @@ main (void) jerry_init (JERRY_INIT_EMPTY); uint64_t digits[4] = { 0x1, 0x1, 0x0, 0x0 }; - jerry_value_t bigint_value = jerry_create_bigint (digits, 4, true); + jerry_value_t bigint_value = jerry_bigint (digits, 4, true); /* Prints two, because the leading zeroes in digits buffer are discarded. */ - printf("size: %d\n", (int) jerry_get_bigint_size_in_digits (bigint_value)); + printf("size: %d\n", (int) jerry_bigint_digit_count (bigint_value)); - jerry_release_value (bigint_value); + jerry_value_free (bigint_value); jerry_cleanup (); return 0; @@ -6677,31 +6416,31 @@ main (void) **See also** - [jerry_value_is_bigint](#jerry_value_is_bigint) -- [jerry_get_bigint_digits](#jerry_get_bigint_digits) +- [jerry_bigint_to_digits](#jerry_bigint_to_digits) -## jerry_get_bigint_digits +## jerry_bigint_to_digits **Summary** Copies the uint64 digits of a BigInt value into a buffer. This function supports any buffer sizes. If the buffer size is smaller than the size returned by -`[jerry_get_bigint_size_in_digits](#jerry_get_bigint_size_in_digits)`, only the +`[jerry_bigint_digit_count](#jerry_bigint_digit_count)`, only the least significant digits are copied into the buffer. If the buffer size is greater, the unused digits are filled with zero. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_BIGINT`) and can be checked in runtime with the `JERRY_FEATURE_BIGINT` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it + see: [jerry_feature_enabled](#jerry_feature_enabled). +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c void -jerry_get_bigint_digits (jerry_value_t value, uint64_t *digits_p, uint32_t size, bool *sign_p) +jerry_bigint_to_digits (jerry_value_t value, uint64_t *digits_p, uint32_t size, bool *sign_p) ``` - `value` - BigInt value @@ -6725,13 +6464,13 @@ main (void) jerry_init (JERRY_INIT_EMPTY); uint64_t digits[4] = { 0x1, 0x1, 0x0, 0x0 }; - jerry_value_t bigint_value = jerry_create_bigint (digits, 4, true); + jerry_value_t bigint_value = jerry_bigint (digits, 4, true); uint64_t get_digits[4]; bool sign; - jerry_get_bigint_digits (bigint_value, get_digits, 2, &sign); + jerry_bigint_to_digits (bigint_value, get_digits, 2, &sign); - jerry_release_value (bigint_value); + jerry_value_free (bigint_value); jerry_cleanup (); return 0; @@ -6741,14 +6480,14 @@ main (void) **See also** - [jerry_value_is_bigint](#jerry_value_is_bigint) -- [jerry_get_bigint_size_in_digits](#jerry_get_bigint_size_in_digits) +- [jerry_bigint_digit_count](#jerry_bigint_digit_count) # Functions for Proxy objects These APIs all depend on build option (`JERRY_BUILTIN_PROXY`). -## jerry_get_proxy_target +## jerry_proxy_target **Summary** @@ -6757,7 +6496,7 @@ Gets the target object of a Proxy object. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_PROXY`) and can be checked in runtime with the `JERRY_FEATURE_PROXY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -6765,12 +6504,12 @@ Gets the target object of a Proxy object. ```c jerry_value_t -jerry_get_proxy_target (jerry_value_t proxy_value); +jerry_proxy_target (jerry_value_t proxy_value); ``` - `proxy_value` - Proxy object value - return value - - type error - if proxy_value is not a Proxy object + - type error exception - if proxy_value is not a Proxy object - target object - otherwise *New in version 2.4*. @@ -6779,29 +6518,29 @@ jerry_get_proxy_target (jerry_value_t proxy_value); ```c { - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); - jerry_release_value (target); - jerry_release_value (handler); + jerry_value_free (target); + jerry_value_free (handler); - target = jerry_get_proxy_target (proxy); + target = jerry_proxy_target (proxy); // ... usage of the target - jerry_release_value (target); - jerry_release_value (proxy); + jerry_value_free (target); + jerry_value_free (proxy); } ``` **See also** -- [jerry_create_proxy](#jerry_create_proxy) -- [jerry_create_special_proxy](#jerry_create_special_proxy) -- [jerry_get_proxy_handler](#jerry_get_proxy_handler) +- [jerry_proxy](#jerry_proxy) +- [jerry_proxy_custom](#jerry_proxy_custom) +- [jerry_proxy_handler](#jerry_proxy_handler) -## jerry_get_proxy_handler +## jerry_proxy_handler **Summary** @@ -6810,7 +6549,7 @@ Gets the handler object of a Proxy object. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_PROXY`) and can be checked in runtime with the `JERRY_FEATURE_PROXY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. @@ -6818,12 +6557,12 @@ Gets the handler object of a Proxy object. ```c jerry_value_t -jerry_get_proxy_handler (jerry_value_t proxy_value); +jerry_proxy_handler (jerry_value_t proxy_value); ``` - `proxy_value` - Proxy object value - return value - - type error - if proxy_value is not a Proxy object + - type error exception - if proxy_value is not a Proxy object - handler object - otherwise *New in version [[NEXT_RELEASE]]*. @@ -6832,74 +6571,74 @@ jerry_get_proxy_handler (jerry_value_t proxy_value); ```c { - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); - jerry_release_value (target); - jerry_release_value (handler); + jerry_value_free (target); + jerry_value_free (handler); - handler = jerry_get_proxy_handler (proxy); + handler = jerry_proxy_handler (proxy); // ... usage of the handler - jerry_release_value (handler); - jerry_release_value (proxy); + jerry_value_free (handler); + jerry_value_free (proxy); } ``` **See also** -- [jerry_create_proxy](#jerry_create_proxy) -- [jerry_create_special_proxy](#jerry_create_special_proxy) -- [jerry_get_proxy_target](#jerry_get_proxy_target) +- [jerry_proxy](#jerry_proxy) +- [jerry_proxy_custom](#jerry_proxy_custom) +- [jerry_proxy_target](#jerry_proxy_target) -# Acquire and release API values +# Copy and free API values -## jerry_acquire_value +## jerry_value_copy **Summary** -Acquires the specified Jerry API value. +Copies the specified Jerry API value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_acquire_value (jerry_value_t value); +jerry_value_copy (jerry_value_t value); ``` - `value` - api value -- return value - acquired value that may be used outside of the engine +- return value - copied value **Example** ```c { - jerry_value_t object_value = jerry_create_object (); + jerry_value_t object_value = jerry_object (); - jerry_value_t acquired_object = jerry_acquire_value (object_value); + jerry_value_t copied_object = jerry_value_copy (object_value); - jerry_release_value (object_value); + jerry_value_free (object_value); - // acquired_object refers to the created object and makes it + // copied_object refers to the created object and makes it // available after the release of 'object_value' - jerry_release_value (acquired_object); + jerry_value_free (copied_object); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) - [jerry_value_t](#jerry_value_t) -## jerry_release_value +## jerry_value_free **Summary** @@ -6909,7 +6648,7 @@ Release specified Jerry API value. ```c void -jerry_release_value (jerry_value_t value); +jerry_value_free (jerry_value_t value); ``` - `value` - api value @@ -6918,11 +6657,11 @@ jerry_release_value (jerry_value_t value); ```c { - jerry_value_t object_value = jerry_create_object (); + jerry_value_t object_value = jerry_object (); ... - jerry_release_value (object_value); + jerry_value_free (object_value); } ``` @@ -6931,23 +6670,23 @@ jerry_release_value (jerry_value_t value); Function for creating [API values](#jerry_value_t). -*Note*: Every created API value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Every created API value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. -## jerry_create_array +## jerry_array **Summary** Create an array object value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_array (uint32_t size); +jerry_array (uint32_t size); ``` - `size` - size of array; @@ -6957,21 +6696,21 @@ jerry_create_array (uint32_t size); ```c { - jerry_value_t array = jerry_create_array (10); + jerry_value_t array = jerry_array (10); ... - jerry_release_value (array); + jerry_value_free (array); } ``` **See also** -- [jerry_set_property_by_index](#jerry_set_property_by_index) -- [jerry_get_property_by_index](#jerry_get_property_by_index) +- [jerry_object_set_index](#jerry_object_set_index) +- [jerry_object_get_index](#jerry_object_get_index) -## jerry_create_arraybuffer +## jerry_arraybuffer **Summary** @@ -6980,15 +6719,15 @@ Create a jerry_value_t representing an ArrayBuffer object. *Note*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). -- Returned value must be freed with [jerry_release_value](#jerry_release_value) + see: [jerry_feature_enabled](#jerry_feature_enabled). +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_arraybuffer (jerry_length_t size); +jerry_arraybuffer (jerry_length_t size); ``` - `size` - size of the backing store allocated for the array buffer **in bytes**. @@ -7000,11 +6739,11 @@ jerry_create_arraybuffer (jerry_length_t size); ```c { - jerry_value_t buffer_value = jerry_create_arraybuffer (15); + jerry_value_t buffer_value = jerry_arraybuffer (15); ... // use the ArrayBuffer - jerry_release_value (buffer_value); + jerry_value_free (buffer_value); } ``` @@ -7013,10 +6752,10 @@ jerry_create_arraybuffer (jerry_length_t size); - [jerry_arraybuffer_read](#jerry_arraybuffer_read) - [jerry_arraybuffer_write](#jerry_arraybuffer_write) - [jerry_value_is_arraybuffer](#jerry_value_is_arraybuffer) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_arraybuffer_external +## jerry_arraybuffer_external **Summary** @@ -7030,18 +6769,19 @@ so the user can release the buffer which was provided. *Note*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - If `buffer_p` is NULL, the buffer is allocated by the allocator callback passed to - [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) -- Returned value must be freed with [jerry_release_value](#jerry_release_value) + [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_arraybuffer_external (const jerry_length_t size - uint8_t *buffer_p, void *arraybuffer_user_p); +jerry_arraybuffer_external (uint8_t *buffer_p, + const jerry_length_t size + void *arraybuffer_user_p); ``` - `size` - size of the buffer **in bytes**. @@ -7059,25 +6799,25 @@ jerry_create_arraybuffer_external (const jerry_length_t size ```c { uint8_t buffer_p[15]; - jerry_value_t buffer_value = jerry_create_arraybuffer_external (15, buffer_p, NULL); + jerry_value_t buffer_value = jerry_arraybuffer_external (buffer_p, 15, NULL); ... // use the array buffer - jerry_release_value (buffer_value); + jerry_value_free (buffer_value); } ``` **See also** -- [jerry_get_arraybuffer_pointer](#jerry_get_arraybuffer_pointer) +- [jerry_arraybuffer_data](#jerry_arraybuffer_data) - [jerry_arraybuffer_read](#jerry_arraybuffer_read) - [jerry_arraybuffer_write](#jerry_arraybuffer_write) - [jerry_value_is_arraybuffer](#jerry_value_is_arraybuffer) -- [jerry_release_value](#jerry_release_value) -- [jerry_object_native_free_callback_t](#jerry_object_native_free_callback_t) +- [jerry_value_free](#jerry_value_free) +- [jerry_object_native_free_cb_t](#jerry_object_native_free_cb_t) -## jerry_create_shared_arraybuffer +## jerry_shared_arraybuffer **Summary** @@ -7085,14 +6825,14 @@ Create a jerry_value_t representing a SharedArrayBuffer object. *Note*: - This API depends on a build option (`JERRY_BUILTIN_SHAREDARRAYBUFFER`). -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_shared_arraybuffer (jerry_length_t size); +jerry_shared_arraybuffer (jerry_length_t size); ``` - `size` - size of the backing store allocated for the shared array buffer **in bytes**. @@ -7104,11 +6844,11 @@ jerry_create_shared_arraybuffer (jerry_length_t size); ```c { - jerry_value_t buffer_value = jerry_create_shared_arraybuffer (15); + jerry_value_t buffer_value = jerry_shared_arraybuffer (15); ... // use the SharedArrayBuffer - jerry_release_value (buffer_value); + jerry_value_free (buffer_value); } ``` @@ -7117,10 +6857,10 @@ jerry_create_shared_arraybuffer (jerry_length_t size); - [jerry_arraybuffer_read](#jerry_arraybuffer_read) - [jerry_arraybuffer_write](#jerry_arraybuffer_write) - [jerry_value_is_shared_arraybuffer](#jerry_value_is_shared_arraybuffer) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_shared_arraybuffer_external +## jerry_shared_arraybuffer_external **Summary** @@ -7134,21 +6874,21 @@ so the user can release the buffer which was provided. *Note*: - This API depends on a build option (`JERRY_BUILTIN_SHAREDARRAYBUFFER`). - If `buffer_p` is NULL, the buffer is allocated by the allocator callback passed to - [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) -- Returned value must be freed with [jerry_release_value](#jerry_release_value) + [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_shared_arraybuffer_external (const jerry_length_t size - uint8_t *buffer_p, - jerry_value_free_callback_t free_cb); +jerry_shared_arraybuffer_external (uint8_t *buffer_p, + const jerry_length_t size, + jerry_value_free_callback_t free_cb); ``` -- `size` - size of the buffer **in bytes**. - `buffer_p` - the backing store used by the shared array buffer object. +- `size` - size of the buffer **in bytes**. - `arraybuffer_user_p` - user pointer assigned to the shared array buffer object. - return value - value of the newly constructed shared array buffer object. @@ -7160,25 +6900,25 @@ jerry_create_shared_arraybuffer_external (const jerry_length_t size ```c { uint8_t buffer_p[15]; - jerry_value_t buffer_value = jerry_create_shared_arraybuffer_external (15, buffer_p, NULL); + jerry_value_t buffer_value = jerry_shared_arraybuffer_external (buffer_p, 15, NULL); ... // use the shared array buffer - jerry_release_value (buffer_value); + jerry_value_free (buffer_value); } ``` **See also** -- [jerry_get_arraybuffer_pointer](#jerry_get_arraybuffer_pointer) +- [jerry_arraybuffer_data](#jerry_arraybuffer_data) - [jerry_arraybuffer_read](#jerry_arraybuffer_read) - [jerry_arraybuffer_write](#jerry_arraybuffer_write) - [jerry_value_is_shared_arraybuffer](#jerry_value_is_shared_arraybuffer) -- [jerry_release_value](#jerry_release_value) -- [jerry_object_native_free_callback_t](#jerry_object_native_free_callback_t) +- [jerry_value_free](#jerry_value_free) +- [jerry_object_native_free_cb_t](#jerry_object_native_free_cb_t) -## jerry_create_boolean +## jerry_boolean **Summary** @@ -7186,13 +6926,13 @@ Create a jerry_value_t representing a boolean value from the given boolean param *Notes*: - The boolean values (true/false) are fixed constants. Their values can be copied any number of times without calling - [jerry_acquire_value](#jerry_acquire_value), and freeing it with [jerry_release_value](#jerry_release_value) is optional. + [jerry_value_copy](#jerry_value_copy), and freeing it with [jerry_value_free](#jerry_value_free) is optional. **Prototype** ```c jerry_value_t -jerry_create_boolean (bool value); +jerry_boolean (bool value); ``` - `value` - raw boolean value. @@ -7202,108 +6942,104 @@ jerry_create_boolean (bool value); ```c { - jerry_value_t boolean_value = jerry_create_boolean (true); + jerry_value_t boolean_value = jerry_boolean (true); ... // usage of the value - jerry_release_value (boolean_value); + jerry_value_free (boolean_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_error +## jerry_error **Summary** -Create new JavaScript error object. +Create new JavaScript Error object with the specified error message. Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`. -Creating an error with no error type is not valid. +Creating an Error object with no error type is not valid. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_error (jerry_error_t error_type, - const jerry_char_t *message_p); +jerry_error (jerry_error_t error_type, + jerry_value_t message); ``` - `error_type` - type of error -- `message_p` - value of 'message' property of constructed error object -- return value - value of the constructed error object +- `message` - error message string +- return value - constructed error object **Example** ```c { - jerry_value_t error_obj = jerry_create_error (JERRY_ERROR_TYPE, - (const jerry_char_t *) "error"); + jerry_value_t message = jerry_string_sz ("error"); + jerry_value_t error_obj = jerry_error (JERRY_ERROR_COMMON, message); ... // usage of error_obj - jerry_release_value (error_obj); + jerry_value_free (error_obj); + jerry_value_free (message); } ``` **See also** -- [jerry_value_is_error](#jerry_value_is_error) -- [jerry_get_value_from_error](#jerry_get_value_from_error) -- [jerry_create_error_from_value](#jerry_create_error_from_value) +- [jerry_value_is_exception](#jerry_value_is_exception) +- [jerry_exception_value](#jerry_exception_value) +- [jerry_exception](#jerry_exception) -## jerry_create_error_sz +## jerry_error_sz **Summary** -Create new JavaScript error object. +Create new JavaScript Error object, using the a zero-terminated string as the error message. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_error_sz (jerry_error_t error_type, - const jerry_char_t *message_p, - jerry_size_t message_size); +jerry_error_sz (jerry_error_t error_type, + const char *message_p); ``` - `error_type` - type of the error - `message_p` - value of 'message' property of the constructed error object -- `message_size` - size of the message in bytes -- return value - value of the constructed error object +- return value - constructed error object **Example** ```c { - const jerry_char_t message[] = "error"; - jerry_value_t error_obj = jerry_create_error_sz (JERRY_ERROR_COMMON, - message, - sizeof (message) - 1); + jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, "error"); ... // usage of error_obj - jerry_release_value (error_obj); + jerry_value_free (error_obj); } ``` **See also** -- [jerry_create_error](#jerry_create_error) +- [jerry_error](#jerry_error) -## jerry_create_dataview +## jerry_dataview **Summary** @@ -7311,16 +7047,16 @@ Create new JavaScript DataView object. *Note*: - This API depends on the es.next profile. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_dataview (const jerry_value_t array_buffer, - const jerry_length_t byte_offset, - const jerry_length_t byte_length) +jerry_dataview (const jerry_value_t array_buffer, + const jerry_length_t byte_offset, + const jerry_length_t byte_length) ``` - `array_buffer` - arrayBuffer to create DataView from @@ -7328,7 +7064,7 @@ jerry_create_dataview (const jerry_value_t array_buffer, - `byte_length` - number of elements in the byte array - return value - value of the constructed DataView object - if success - - created error - otherwise + - exception - otherwise *New in version 2.0*. @@ -7344,13 +7080,13 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t arraybuffer = jerry_create_arraybuffer (16); - jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 16); + jerry_value_t arraybuffer = jerry_arraybuffer (16); + jerry_value_t dataview = jerry_dataview (arraybuffer, 0, 16); // usage of dataview - jerry_release_value (dataview); - jerry_release_value (arraybuffer); + jerry_value_free (dataview); + jerry_value_free (arraybuffer); jerry_cleanup (); return 0; @@ -7360,23 +7096,23 @@ main (void) **See also** - [jerry_value_is_dataview](#jerry_value_is_dataview) -- [jerry_create_arraybuffer](#jerry_create_arraybuffer) +- [jerry_arraybuffer](#jerry_arraybuffer) -## jerry_create_external_function +## jerry_function_external **Summary** Create an external function object. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_external_function (jerry_external_handler_t handler_p); +jerry_function_external (jerry_external_handler_t handler_p); ``` - `handler_p` - pointer to native handler of the function object @@ -7398,7 +7134,7 @@ handler (const jerry_call_info_t *call_info_p, { printf ("Native handler called!\n"); - return jerry_create_boolean (true); + return jerry_boolean (true); } int @@ -7406,17 +7142,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t func_val = jerry_create_external_function (handler); - jerry_value_t glob_obj = jerry_get_global_object (); + jerry_value_t func_val = jerry_function_external (handler); + jerry_value_t glob_obj = jerry_current_realm (); // after this, script can invoke the native handler through "handler_field (1, 2, 3);" - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field"); + jerry_value_t prop_name = jerry_string_sz ("handler_field"); // set property and release the return value without any check - jerry_release_value (jerry_set_property (glob_obj, prop_name, func_val)); - jerry_release_value (prop_name); + jerry_value_free (jerry_object_set (glob_obj, prop_name, func_val)); + jerry_value_free (prop_name); - jerry_release_value (func_val); - jerry_release_value (glob_obj); + jerry_value_free (func_val); + jerry_value_free (glob_obj); // Test the method by calling it const char *test_src = "handler_field ();"; @@ -7424,7 +7160,7 @@ main (void) strlen (test_src), JERRY_PARSE_NO_OPTS); // release the eval result - jerry_release_value (ret_val); + jerry_value_free (ret_val); jerry_cleanup (); return 0; } @@ -7433,24 +7169,24 @@ main (void) **See also** - [jerry_external_handler_t](#jerry_external_handler_t) -- [jerry_set_property](#jerry_set_property) -- [jerry_call_function](#jerry_call_function) +- [jerry_object_set](#jerry_object_set) +- [jerry_call](#jerry_call) -## jerry_create_number +## jerry_number **Summary** Creates a `jerry_value_t` representing a number value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_number (double value); +jerry_number (double value); ``` - `value` - double value from which a `jerry_value_t` will be created @@ -7460,35 +7196,35 @@ jerry_create_number (double value); ```c { - jerry_value_t number_value = jerry_create_number (3.14); + jerry_value_t number_value = jerry_number (3.14); ... // usage of the value - jerry_release_value (number_value); + jerry_value_free (number_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_number_infinity](#jerry_create_number_infinity) -- [jerry_create_number_nan](#jerry_create_number_nan) +- [jerry_value_free](#jerry_value_free) +- [jerry_infinity](#jerry_infinity) +- [jerry_nan](#jerry_nan) -## jerry_create_number_infinity +## jerry_infinity **Summary** Creates a `jerry_value_t` representing a positive or negative infinity value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_number_infinity (bool sign); +jerry_infinity (bool sign); ``` - `sign` - true for negative Infinity and false for positive Infinity @@ -7498,35 +7234,35 @@ jerry_create_number_infinity (bool sign); ```c { - jerry_value_t positive_inf_value = jerry_create_number_infinity (false); + jerry_value_t positive_inf_value = jerry_infinity (false); ... // usage of the positive_inf_value - jerry_release_value (positive_inf_value); + jerry_value_free (positive_inf_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_number](#jerry_create_number) -- [jerry_create_number_nan](#jerry_create_number_nan) +- [jerry_value_free](#jerry_value_free) +- [jerry_number](#jerry_number) +- [jerry_nan](#jerry_nan) -## jerry_create_number_nan +## jerry_nan **Summary** Creates a `jerry_value_t` representing a not-a-number value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_number_nan (void); +jerry_nan (void); ``` - return value - a `jerry_value_t` representing the not-a-number value @@ -7535,22 +7271,22 @@ jerry_create_number_nan (void); ```c { - jerry_value_t nan_value = jerry_create_number_nan (); + jerry_value_t nan_value = jerry_nan (); ... // usage of the nan_value - jerry_release_value (nan_value); + jerry_value_free (nan_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) -- [jerry_create_number](#jerry_create_number) -- [jerry_create_number_infinity](#jerry_create_number_infinity) +- [jerry_value_free](#jerry_value_free) +- [jerry_number](#jerry_number) +- [jerry_infinity](#jerry_infinity) -## jerry_create_null +## jerry_null **Summary** @@ -7558,13 +7294,13 @@ Creates and returns a `jerry_value_t` with type null object. *Notes*: - The null value is a fixed constant. Its value can be copied any number of times without calling - [jerry_acquire_value](#jerry_acquire_value), and freeing it with [jerry_release_value](#jerry_release_value) is optional. + [jerry_value_copy](#jerry_value_copy), and freeing it with [jerry_value_free](#jerry_value_free) is optional. **Prototype** ```c jerry_value_t -jerry_create_null (void); +jerry_null (void); ``` - return value - a `jerry_value_t` representing null. @@ -7573,33 +7309,33 @@ jerry_create_null (void); ```c { - jerry_value_t null_value = jerry_create_null (); + jerry_value_t null_value = jerry_null (); ... // usage of the value - jerry_release_value (null_value); + jerry_value_free (null_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_object +## jerry_object **Summary** Create new JavaScript object, like with new Object(). -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_object (void); +jerry_object (void); ``` - return value - value of the created object @@ -7608,36 +7344,36 @@ jerry_create_object (void); ```c { - jerry_value_t object_value = jerry_create_object (); + jerry_value_t object_value = jerry_object (); ... // usage of object_value - jerry_release_value (object_value); + jerry_value_free (object_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_promise +## jerry_promise **Summary** Create an empty promise object which can be resolved or rejected later -by calling jerry_resolve_or_reject_promise. +by calling jerry_promise_resolve or jerry_promise_reject. *Note*: - This API depends on the es.next profile. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_promise (void) +jerry_promise (void) ``` - return value - value of the newly created promise @@ -7648,21 +7384,22 @@ jerry_create_promise (void) ```c { - jerry_value_t p = jerry_create_promise (); + jerry_value_t p = jerry_promise (); ...// usage of the promise - jerry_release_value (p); + jerry_value_free (p); } ``` **See also** -- [jerry_resolve_or_reject_promise](#jerry_resolve_or_reject_promise) -- [jerry_release_value](#jerry_release_value) +- [jerry_promise_resolve](#jerry_promise_resolve) +- [jerry_promise_reject](#jerry_promise_reject) +- [jerry_value_free](#jerry_value_free) -## jerry_create_proxy +## jerry_proxy **Summary** @@ -7670,20 +7407,20 @@ Create a new Proxy object with the given target and handler. *Note*: - This API depends on the es.next profile. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_proxy (const jerry_value_t target, - const jerry_value_t handler); +jerry_proxy (const jerry_value_t target, + const jerry_value_t handler); ``` - `target` - proxy target - `handler` - proxy handler -- return thrown error - if the Proxy construction fails +- return exception - if the Proxy construction fails value of the newly created proxy object - otherwise *New in version 2.3*. @@ -7700,16 +7437,16 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); - jerry_release_value (target); - jerry_release_value (handler); + jerry_value_free (target); + jerry_value_free (handler); // usage of the proxy - jerry_release_value (proxy); + jerry_value_free (proxy); jerry_cleanup (); } @@ -7718,11 +7455,11 @@ main (void) **See also** - [jerry_value_is_proxy](#jerry_value_is_proxy) -- [jerry_create_special_proxy](#jerry_create_special_proxy) -- [jerry_release_value](#jerry_release_value) +- [jerry_proxy_custom](#jerry_proxy_custom) +- [jerry_value_free](#jerry_value_free) -## jerry_create_special_proxy +## jerry_proxy_custom **Summary** @@ -7731,22 +7468,22 @@ The behaviour of the Proxy can be specialized with an options argument. *Note*: - This API depends on the es.next profile. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_special_proxy (const jerry_value_t target, - const jerry_value_t handler, - uint32_t options); +jerry_proxy_custom (const jerry_value_t target, + const jerry_value_t handler, + uint32_t options); ``` - `target` - proxy target - `handler` - proxy handler -- `options` - any combination of [jerry_proxy_object_options_t](#jerry_proxy_object_options_t) options -- return thrown error - if the Proxy construction fails +- `options` - any combination of [jerry_proxy_custom_behavior_t](#jerry_proxy_custom_behavior_t) options +- return thrown exception - if the Proxy construction fails value of the newly created proxy object - otherwise *New in version [[NEXT_RELEASE]]*. @@ -7763,16 +7500,16 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_special_proxy (target, handler, JERRY_PROXY_SKIP_RESULT_VALIDATION); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy_custom (target, handler, JERRY_PROXY_SKIP_RESULT_VALIDATION); - jerry_release_value (target); - jerry_release_value (handler); + jerry_value_free (target); + jerry_value_free (handler); // usage of the proxy - jerry_release_value (proxy); + jerry_value_free (proxy); jerry_cleanup (); } @@ -7781,67 +7518,68 @@ main (void) **See also** - [jerry_value_is_proxy](#jerry_value_is_proxy) -- [jerry_create_special_proxy](#jerry_create_special_proxy) -- [jerry_release_value](#jerry_release_value) +- [jerry_proxy_custom](#jerry_proxy_custom) +- [jerry_value_free](#jerry_value_free) -## jerry_create_string +## jerry_string_sz **Summary** -Create string from a valid CESU8 string. +Create string from a zero-terminated ASCII string. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_string (const jerry_char_t *str_p); +jerry_string_sz (const char *str_p); ``` - `str_p` - non-null pointer to string -- return value - value of the created string +- return value - created string **Example** ```c { - const jerry_char_t char_array[] = "a string"; - jerry_value_t string_value = jerry_create_string (char_array); + const char char_array[] = "a string"; + jerry_value_t string_value = jerry_string_sz (char_array); ... // usage of string_value - jerry_release_value (string_value); + jerry_value_free (string_value); } ``` **See also** -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) -- [jerry_create_string_sz](#jerry_create_string_sz) +- [jerry_string](#jerry_string) -## jerry_create_string_sz +## jerry_string **Summary** -Create string from a valid CESU8 string. +Create a string from a buffer using the specified encoding. The data in the buffer must be valid for the encoding. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_string_sz (const jerry_char_t *str_p, - jerry_size_t str_size) +jerry_string (const jerry_char_t *buffer_p, + jerry_size_t buf_size, + jerry_encoding_t encoding) ``` -- `str_p` - non-null pointer to string -- `str_size` - size of the string +- `buffer_p` - non-null pointer to buffer +- `buf_size` - size of the buffer +- `encoding` - encoding of the string data - return value - value of the created string **Example** @@ -7849,128 +7587,41 @@ jerry_create_string_sz (const jerry_char_t *str_p, ```c { const jerry_char_t char_array[] = "a string"; - jerry_value_t string_value = jerry_create_string_sz (char_array, - sizeof (char_array) - 1); + jerry_value_t string_value = jerry_string (char_array, + sizeof (char_array) - 1, + JERRY_ENCODING_CESU8); ... // usage of string_value - jerry_release_value (string_value); + jerry_value_free (string_value); } ``` **See also** -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) -- [jerry_create_string](#jerry_create_string) - - -## jerry_create_string_from_utf8 - -**Summary** - -Create string from a valid UTF8 string. - -*Note*: - - The difference from [jerry_create_string](#jerry_create_string) is that it accepts utf-8 string instead of cesu-8 string. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it -is no longer needed. - -**Prototype** - -```c -jerry_value_t -jerry_create_string_from_utf8 (const jerry_char_t *str_p); -``` - -- `str_p` - non-null pointer to string -- return value - value of the created string - -*New in version 2.0*. - -**Example** - -```c -{ - const jerry_char_t char_array[] = "a string"; - jerry_value_t string_value = jerry_create_string_from_utf8 (char_array); - - ... // usage of string_value - - jerry_release_value (string_value); -} -``` - -**See also** - -- [jerry_is_valid_utf8_string](#jerry_is_valid_utf8_string) -- [jerry_create_string_sz_from_utf8](#jerry_create_string_sz_from_utf8) +- [jerry_validate_string](#jerry_validate_string) +- [jerry_string_sz](#jerry_string_sz) -## jerry_create_string_sz_from_utf8 +## jerry_string_external_sz **Summary** -Create string from a valid UTF8 string. - -*Note*: - - The difference from [jerry_create_string_sz](#jerry_create_string_sz) is that it accepts utf-8 string instead of cesu-8 string. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it -is no longer needed. - -**Prototype** - -```c -jerry_value_t -jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p, - jerry_size_t str_size) -``` - -- `str_p` - non-null pointer to string -- `str_size` - size of the string -- return value - value of the created string - -*New in version 2.0*. - -**Example** - -```c -{ - const jerry_char_t char_array[] = "a string"; - jerry_value_t string_value = jerry_create_string_sz_from_utf8 (char_array, - sizeof (char_array) - 1); - - ... // usage of string_value - - jerry_release_value (string_value); -} - -``` - -**See also** - -- [jerry_is_valid_utf8_string](#jerry_is_valid_utf8_string) -- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8) - - -## jerry_create_external_string - -**Summary** - -Create an external string from a valid CESU8 string. The string buffer passed to the function +Create an external string from a zero-terminated ASCII string. The string buffer passed to the function should not be modified until the free callback is called. This function can be used to avoid the duplication of large strings. *Note*: - - The free callback can be set by [jerry_string_set_external_free_callback](#jerry_string_set_external_free_callback) - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - The free callback can be set by [jerry_string_external_free_cb](#jerry_string_external_free_cb) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_external_string (const jerry_char_t *str_p, void *user_p); +jerry_string_external_sz (const char *str_p, void *user_p); ``` - `str_p` - non-null pointer to string @@ -7986,23 +7637,21 @@ jerry_create_external_string (const jerry_char_t *str_p, void *user_p); ```c { const char* string_p = "a large and immutable string: this is a story about ...."; - jerry_value_t string_value = jerry_create_external_string ((const jerry_char_t *) string_p, - NULL); + jerry_value_t string_value = jerry_string_external_sz (string_p, NULL); ... // usage of string_value - jerry_release_value (string_value); + jerry_value_free (string_value); } ``` **See also** -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) -- [jerry_create_external_string_sz](#jerry_create_external_string_sz) -- [jerry_string_set_external_free_callback](#jerry_string_set_external_free_callback) +- [jerry_string_external](#jerry_string_external) +- [jerry_string_external_free_cb](#jerry_string_external_free_cb) -## jerry_create_external_string_sz +## jerry_string_external **Summary** @@ -8011,17 +7660,17 @@ should not be modified until the free callback is called. This function can be u the duplication of large strings. *Note*: - - The free callback can be set by [jerry_string_set_external_free_callback](#jerry_string_set_external_free_callback) - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - The free callback can be set by [jerry_string_external_free_cb](#jerry_string_external_free_cb) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_external_string_sz (const jerry_char_t *str_p, - jerry_size_t str_size, - void *user_p); +jerry_string_external (const jerry_char_t *str_p, + jerry_size_t str_size, + void *user_p); ``` - `str_p` - non-null pointer to string @@ -8038,47 +7687,47 @@ jerry_create_external_string_sz (const jerry_char_t *str_p, ```c { const char* string_p = "a large and immutable string: this is a story about ...."; - jerry_value_t string_value = jerry_create_external_string_sz ((const jerry_char_t *) string_p, - strlen (string_p), - NULL); + jerry_value_t string_value = jerry_string_external ((const jerry_char_t *) string_p, + strlen (string_p), + NULL); ... // usage of string_value - jerry_release_value (string_value); + jerry_value_free (string_value); } ``` **See also** -- [jerry_is_valid_cesu8_string](#jerry_is_valid_cesu8_string) -- [jerry_create_external_string](#jerry_create_external_string) -- [jerry_string_set_external_free_callback](#jerry_string_set_external_free_callback) +- [jerry_validate_string](#jerry_validate_string) +- [jerry_string_external_sz](#jerry_string_external_sz) +- [jerry_string_external_free_cb](#jerry_string_external_free_cb) -## jerry_create_symbol +## jerry_symbol **Summary** Create symbol from an API value. *Note*: - - The given argument is converted to string. This operation can throw an error. + - The given argument is converted to string. This operation can throw an exception. - This API depends on the es.next profile. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_symbol (const jerry_value_t value) +jerry_symbol_with_description (const jerry_value_t value) ``` - `value` - API value - return value - value of the created symbol, if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.0*. @@ -8094,15 +7743,15 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t string_value = jerry_create_string ((const jerry_char_t *) "Symbol description string"); - jerry_value_t symbol_value = jerry_create_symbol (string_value); + jerry_value_t string_value = jerry_string_sz ("Symbol description string"); + jerry_value_t symbol_value = jerry_symbol_with_description (string_value); // The description value is no longer needed - jerry_release_value (string_value); + jerry_value_free (string_value); // usage of symbol_value - jerry_release_value (symbol_value); + jerry_value_free (symbol_value); jerry_cleanup (); } @@ -8111,10 +7760,10 @@ main (void) **See also** - [jerry_value_is_symbol](#jerry_value_is_symbol) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_bigint +## jerry_bigint **Summary** @@ -8123,15 +7772,15 @@ Create BigInt value from uint64 digits *Note*: - This API depends on a build option (`JERRY_BUILTIN_BIGINT`) and can be checked in runtime with the `JERRY_FEATURE_BIGINT` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). -- Returned value must be freed with [jerry_release_value](#jerry_release_value) + see: [jerry_feature_enabled](#jerry_feature_enabled). +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_bigint (const uint64_t *digits_p, uint32_t size, bool sign) +jerry_bigint (const uint64_t *digits_p, uint32_t size, bool sign) ``` - `digits_p` - array of uint64 digits, least significant digit first @@ -8139,7 +7788,7 @@ jerry_create_bigint (const uint64_t *digits_p, uint32_t size, bool sign) - `sign` - false if the created value should be positive, and true if the created value should be negative - return value - value of the created bigint, if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.4*. @@ -8156,11 +7805,11 @@ main (void) jerry_init (JERRY_INIT_EMPTY); uint64_t digits[2] = { 0x1, 0x1 }; - jerry_value_t bigint_value = jerry_create_bigint (digits, 2, true); + jerry_value_t bigint_value = jerry_bigint (digits, 2, true); // usage of bigint_value - jerry_release_value (bigint_value); + jerry_value_free (bigint_value); jerry_cleanup (); } @@ -8168,26 +7817,26 @@ main (void) **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) - [jerry_value_is_bigint](#jerry_value_is_bigint) -- [jerry_get_bigint_digits](#jerry_get_bigint_digits) +- [jerry_bigint_to_digits](#jerry_bigint_to_digits) -## jerry_create_regexp +## jerry_regexp_sz **Summary** -Returns a `jerry_value_t` RegExp object or an error, if the construction of the object fails. -Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t). -These flags can be combined together with the binary OR operator or used on their own as enum values. +Returns a RegExp object created from the argument ASCII string pattern, or an exception if the construction of the +object fails. Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t). These flags can be +combined together with the binary OR operator or used on their own as enum values. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_regexp (const jerry_char_t *pattern_p, uint16_t flags); +jerry_regexp_sz (const jerry_char_t *pattern_p, uint16_t flags); ``` - `pattern_p` - the RegExp pattern as a zero-terminated UTF-8 string @@ -8203,30 +7852,30 @@ jerry_create_regexp (const jerry_char_t *pattern_p, uint16_t flags); jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]"; uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE; - jerry_value_t regexp = jerry_create_regexp (pattern_p, pattern_flags); + jerry_value_t regexp = jerry_regexp_sz (pattern_p, pattern_flags); ... - jerry_release_value (regexp); + jerry_value_free (regexp); } ``` -## jerry_create_regexp_sz +## jerry_regexp **Summary** -Returns a `jerry_value_t` RegExp object or an error, if the construction of the object fails. -Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t). -These flags can be combined together with the binary OR operator or used on their own as enum values. +Returns a RegExp object from the argument pattern, or an exception if the construction of the object fails. Optional +flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t). These flags can be combined together with the +binary OR operator or used on their own as enum values. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_create_regexp_sz (const jerry_char_t *pattern_p, jerry_size_t pattern_size, uint16_t flags); +jerry_regexp (const jerry_value_t pattern, uint16_t flags); ``` - `pattern_p` - the RegExp pattern as a zero-terminated UTF-8 string @@ -8242,18 +7891,21 @@ jerry_create_regexp_sz (const jerry_char_t *pattern_p, jerry_size_t pattern_size { jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]"; jerry_size_t pattern_size = sizeof (pattern_p) - 1; + jerry_value_t pattern_str = jerry_string (pattern_p, pattern_size, JERRY_ENCODING_UTF8); + uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE; - jerry_value_t regexp = jerry_create_regexp_sz (pattern_p, pattern_size, pattern_flags); + jerry_value_t regexp = jerry_regexp (pattern_str, pattern_flags); + jerry_value_free (pattern_str); ... - jerry_release_value (regexp); + jerry_value_free (regexp); } ``` -## jerry_create_typedarray +## jerry_typedarray **Summary** @@ -8263,18 +7915,18 @@ For the new object the type of the TypedArray (see: [jerry_typedarray_type_t](#j and element count can be specified. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c jerry_value_t -jerry_create_typedarray (jerry_typedarray_type_t type_name, jerry_length_t item_count); +jerry_typedarray (jerry_typedarray_type_t type_name, jerry_length_t item_count); ``` - `type_name` - type of TypedArray to create @@ -8287,11 +7939,11 @@ jerry_create_typedarray (jerry_typedarray_type_t type_name, jerry_length_t item_ ```c { - jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_UINT16, 15); + jerry_value_t array = jerry_typedarray (JERRY_TYPEDARRAY_UINT16, 15); ... // use the TypedArray - jerry_release_value (array); + jerry_value_free (array); } ``` @@ -8299,10 +7951,10 @@ jerry_create_typedarray (jerry_typedarray_type_t type_name, jerry_length_t item_ - [jerry_typedarray_type_t](#jerry_typedarray_type_t) - [jerry_value_is_typedarray](#jerry_value_is_typedarray) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_typedarray_for_arraybuffer +## jerry_typedarray_with_buffer **Summary** @@ -8313,32 +7965,32 @@ For the new object the type of the TypedArray (see: [jerry_typedarray_type_t](#j and element count can be specified. The developer must ensure that the ArrayBuffer has the correct length for the given -type of TypedArray otherwise an error is generated. +type of TypedArray otherwise an exception is generated. The JavaScript equivalent of this function is: `new %TypedArray%(arraybuffer)` where `%TypedArray%` is one of the allowed TypedArray functions. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c jerry_value_t -jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name, - const jerry_value_t arraybuffer); +jerry_typedarray_with_buffer (jerry_typedarray_type_t type_name, + const jerry_value_t arraybuffer); ``` - `type_name` - type of TypedArray to create - `arraybuffer` - the ArrayBuffer to use for the new TypedArray - return value - the new TypedArray as a `jerry_value_t` - - Error if the ArrayBuffer does not have enough space for the given type of TypedArray + - exception if the ArrayBuffer does not have enough space for the given type of TypedArray *New in version 2.0*. @@ -8346,13 +7998,13 @@ jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name, ```c { - jerry_value_t buffer = jerry_create_array_buffer (12 * 2); - jerry_value_t array = jerry_create_typedarray_for_arraybuffer (JERRY_TYPEDARRAY_UINT16, buffer); - jerry_release_value (buffer); + jerry_value_t buffer = jerry_array_buffer (12 * 2); + jerry_value_t array = jerry_typedarray_with_buffer (JERRY_TYPEDARRAY_UINT16, buffer); + jerry_value_free (buffer); ... // use the TypedArray - jerry_release_value (array); + jerry_value_free (array); } ``` @@ -8360,10 +8012,10 @@ jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name, - [jerry_typedarray_type_t](#jerry_typedarray_type_t) - [jerry_value_is_typedarray](#jerry_value_is_typedarray) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_typedarray_for_arraybuffer_sz +## jerry_typedarray_with_buffer_span **Summary** @@ -8374,27 +8026,27 @@ For the new object the type of the TypedArray (see: [jerry_typedarray_type_t](#j and element count can be specified. The developer must ensure that the ArrayBuffer has the correct length for the given -type of TypedArray otherwise an error is generated. +type of TypedArray otherwise an exception is generated. The JavaScript equivalent of this function is: `new %TypedArray%(arraybuffer, byteOffset, length)` where `%TypedArray%` is one of the allowed TypedArray functions. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c 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_typedarray_with_buffer_span (jerry_typedarray_type_t type_name, + const jerry_value_t arraybuffer, + jerry_length_t byte_offset, + jerry_length_t length); ``` - `type_name` - type of TypedArray to create @@ -8403,7 +8055,7 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, - `length` - number of elements to used from the ArrayBuffer (this is not the same as the byteLength) - return value - the new TypedArray as a `jerry_value_t` - - Error if the ArrayBuffer does not have enough space for the given type of TypedArray + - exception if the ArrayBuffer does not have enough space for the given type of TypedArray *New in version 2.0*. @@ -8411,13 +8063,13 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, ```c { - jerry_value_t buffer = jerry_create_array_buffer (12 * 2); - jerry_value_t array = jerry_create_typedarray_for_arraybuffer_sz (JERRY_TYPEDARRAY_UINT16, buffer, 4, 10); - jerry_release_value (buffer); + jerry_value_t buffer = jerry_array_buffer (12 * 2); + jerry_value_t array = jerry_typedarray_with_buffer_span (JERRY_TYPEDARRAY_UINT16, buffer, 4, 10); + jerry_value_free (buffer); ... // use the TypedArray - jerry_release_value (array); + jerry_value_free (array); } ``` @@ -8425,10 +8077,10 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, - [jerry_typedarray_type_t](#jerry_typedarray_type_t) - [jerry_value_is_typedarray](#jerry_value_is_typedarray) -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_container +## jerry_container **Summary** @@ -8436,21 +8088,21 @@ Create a jerry_value_t representing a given type container object. *Notes*: - This method is expected to work the same way as the JavaScript Map constructor. -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_CONTAINER`) and can be checked in runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET` feature enum values. - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c 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 (jerry_container_type_t container_type, + const jerry_value_t *arguments_list_p, + jerry_length_t arguments_list_len); ``` - `container_type` - Type of the container to be created, see `jerry_container_type_t`. @@ -8474,12 +8126,12 @@ main (void) jerry_char_t src[] = "[1,2,3,4].entries()"; jerry_value_t iterable = jerry_eval (src, sizeof (src) - 1, JERRY_PARSE_NO_OPTS); - jerry_value_t map = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, &iterable, 1); - jerry_release_value (iterable); + jerry_value_t map = jerry_container (JERRY_CONTAINER_TYPE_MAP, &iterable, 1); + jerry_value_free (iterable); // use the Map - jerry_release_value (map); + jerry_value_free (map); jerry_cleanup (); return 0; @@ -8489,24 +8141,24 @@ main (void) **See also** - [jerry_container_type_t](#jerry_container_type_t) -- [jerry_get_container_type](#jerry_get_container_type) +- [jerry_container_type](#jerry_container_type) -## jerry_create_undefined +## jerry_undefined **Summary** Creates a `jerry_value_t` representing an undefined value. *Notes*: -- The undefined value is a fixed constant. Its value can be copied any number of times without calling [jerry_acquire_value](#jerry_acquire_value), and freeing it with [jerry_release_value](#jerry_release_value) is optional. +- The undefined value is a fixed constant. Its value can be copied any number of times without calling [jerry_value_copy](#jerry_value_copy), and freeing it with [jerry_value_free](#jerry_value_free) is optional. **Prototype** ```c jerry_value_t -jerry_create_undefined (void); +jerry_undefined (void); ``` - return value - value of undefined @@ -8515,38 +8167,38 @@ jerry_create_undefined (void); ```c { - jerry_value_t undefined_value = jerry_create_undefined (); + jerry_value_t undefined_value = jerry_undefined (); ... // usage of the value - jerry_release_value (undefined_value); + jerry_value_free (undefined_value); } ``` **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) -## jerry_create_realm +## jerry_realm **Summary** Creates a `jerry_value_t` representing a new global object. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_BUILTIN_REALMS`) and can be checked in runtime with the `JERRY_FEATURE_REALM` feature enum value. - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c jerry_value_t -jerry_create_realm (void); +jerry_realm (void); ``` - return value - realm object value @@ -8565,11 +8217,11 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t realm_value = jerry_create_realm (); + jerry_value_t realm_value = jerry_realm (); // usage of the value - jerry_release_value (realm_value); + jerry_value_free (realm_value); jerry_cleanup (); return 0; @@ -8578,37 +8230,37 @@ main (void) **See also** -- [jerry_release_value](#jerry_release_value) +- [jerry_value_free](#jerry_value_free) # General API functions of JS objects -## jerry_has_property +## jerry_object_has **Summary** Checks whether the object or its prototype objects have the given property. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_has_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_has (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value - `prop_name_val` - property name - return value - JavaScript value that evaluates to - - raised error - if the operation fail - - true/false API value - depend on whether the property exists + - exception - if the operation fail + - true/false API value - depend on whether the property exists *Changed in version 2.0*: The return value type is now a JavaScript value and not a primitive boolean value. -*Changed in version 2.3*: The return value can be an error value. +*Changed in version 2.3*: The return value can be an exception value. **Example** @@ -8622,15 +8274,15 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("handler_field"); - jerry_value_t has_prop_js = jerry_has_property (global_object, prop_name); + jerry_value_t has_prop_js = jerry_object_has (global_object, prop_name); bool has_prop = jerry_value_is_true (has_prop_js); - jerry_release_value (has_prop_js); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (has_prop_js); + jerry_value_free (prop_name); + jerry_value_free (global_object); jerry_cleanup (); @@ -8640,36 +8292,36 @@ main (void) **See also** -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property](#jerry_delete_property) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete](#jerry_object_delete) -## jerry_has_own_property +## jerry_object_has_own **Summary** Checks whether the object has the given property. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_has_own_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_has_own (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value - `prop_name_val` - property name - return value - JavaScript value that evaluates to - - raised error - if the operation fails + - exception - if the operation fails - true/false API value - depend on whether the property exists *Changed in version 2.0*: The return value type is now a JavaScript value and not a primitive boolean value. -*Changed in version 2.3*: The return value can be an error value. +*Changed in version 2.3*: The return value can be an exception value. **Example** @@ -8683,15 +8335,15 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("handler_field"); - jerry_value_t has_prop_js = jerry_has_own_property (global_object, prop_name); + jerry_value_t has_prop_js = jerry_object_has_own (global_object, prop_name); bool has_prop = jerry_value_is_true (has_prop_js); - jerry_release_value (has_prop_js); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (has_prop_js); + jerry_value_free (prop_name); + jerry_value_free (global_object); jerry_cleanup (); @@ -8701,28 +8353,28 @@ main (void) **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_delete_property](#jerry_delete_property) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_delete](#jerry_object_delete) -## jerry_has_internal_property +## jerry_object_has_internal **Summary** Checks whether the object has the given internal property. *Note*: - - Properties which were not created with [jerry_set_internal_property](#jerry_set_internal_property) are excluded + - Properties which were not created with [jerry_object_set_internal](#jerry_object_set_internal) are excluded during the operation. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c bool -jerry_has_internal_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_has_internal (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value @@ -8745,13 +8397,13 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("hidden_property"); - bool has_internal_js_prop = jerry_has_internal_property (global_object, prop_name); + bool has_internal_js_prop = jerry_object_has_internal (global_object, prop_name); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (prop_name); + jerry_value_free (global_object); return 0; } @@ -8759,12 +8411,12 @@ main (void) **See also** -- [jerry_delete_internal_property](#jerry_delete_internal_property) -- [jerry_get_internal_property](#jerry_get_internal_property) -- [jerry_set_internal_property](#jerry_set_internal_property) +- [jerry_object_delete_internal](#jerry_object_delete_internal) +- [jerry_object_get_internal](#jerry_object_get_internal) +- [jerry_object_set_internal](#jerry_object_set_internal) -## jerry_delete_property +## jerry_object_delete **Summary** @@ -8774,8 +8426,8 @@ Delete a property from an object. ```c bool -jerry_delete_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_delete (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value @@ -8788,26 +8440,26 @@ jerry_delete_property (const jerry_value_t obj_val, ```c { - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("my_prop"); - bool delete_result = jerry_delete_property (global_object, prop_name); + bool delete_result = jerry_object_delete (global_object, prop_name); /* use "delete_result" */ - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (prop_name); + jerry_value_free (global_object); } ``` **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property_by_index](#jerry_delete_property_by_index) -- [jerry_get_property](#jerry_get_property) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete_index](#jerry_object_delete_index) +- [jerry_object_get](#jerry_object_get) -## jerry_delete_property_by_index +## jerry_object_delete_index **Summary** @@ -8817,8 +8469,8 @@ Delete indexed property from the specified object. ```c bool -jerry_delete_property_by_index (const jerry_value_t obj_val, - uint32_t index); +jerry_object_delete_index (const jerry_value_t obj_val, + uint32_t index); ``` - `obj_val` - object value @@ -8835,39 +8487,39 @@ jerry_delete_property_by_index (const jerry_value_t obj_val, { jerry_value_t object; - ... // create or acquire object + ... // create or copy object - bool delete_result = jerry_delete_property_by_index (object, 5); + bool delete_result = jerry_object_delete_index (object, 5); - jerry_release_value (object); + jerry_value_free (object); } ``` **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property](#jerry_delete_property) -- [jerry_get_property](#jerry_get_property) -- [jerry_set_property](#jerry_set_property) -- [jerry_get_property_by_index](#jerry_get_property_by_index) -- [jerry_set_property_by_index](#jerry_set_property_by_index) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete](#jerry_object_delete) +- [jerry_object_get](#jerry_object_get) +- [jerry_object_set](#jerry_object_set) +- [jerry_object_get_index](#jerry_object_get_index) +- [jerry_object_set_index](#jerry_object_set_index) -## jerry_delete_internal_property +## jerry_object_delete_internal **Summary** Delete an internal property from an object. -*Note*: Properties which were not created with [jerry_set_internal_property](#jerry_set_internal_property) are excluded +*Note*: Properties which were not created with [jerry_object_set_internal](#jerry_object_set_internal) are excluded during the operation. **Prototype** ```c bool -jerry_delete_internal_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_delete_internal (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value @@ -8882,46 +8534,46 @@ jerry_delete_internal_property (const jerry_value_t obj_val, ```c { - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("hidden_property"); - bool delete_result = jerry_delete_internal_property (global_object, prop_name); + bool delete_result = jerry_object_delete_internal (global_object, prop_name); /* use "delete_result" */ - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (prop_name); + jerry_value_free (global_object); } ``` **See also** -- [jerry_has_internal_property](#jerry_has_internal_property) -- [jerry_get_internal_property](#jerry_get_internal_property) -- [jerry_set_internal_property](#jerry_set_internal_property) +- [jerry_object_has_internal](#jerry_object_has_internal) +- [jerry_object_get_internal](#jerry_object_get_internal) +- [jerry_object_set_internal](#jerry_object_set_internal) -## jerry_get_property +## jerry_object_get **Summary** Get value of a property to the specified object with the given name. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_get (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value - `prop_name_val` - property name - return value - value of property, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** @@ -8935,16 +8587,16 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "Object"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("Object"); - jerry_value_t prop_value = jerry_get_property (global_object, prop_name); + jerry_value_t prop_value = jerry_object_get (global_object, prop_name); /* use "prop_value" then release it. */ - jerry_release_value (prop_value); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (prop_value); + jerry_value_free (prop_name); + jerry_value_free (global_object); return 0; } @@ -8952,30 +8604,30 @@ main (void) **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property](#jerry_delete_property) -- [jerry_delete_property_by_index](#jerry_delete_property_by_index) -- [jerry_set_property](#jerry_set_property) -- [jerry_get_property_by_index](#jerry_get_property_by_index) -- [jerry_set_property_by_index](#jerry_set_property_by_index) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete](#jerry_object_delete) +- [jerry_object_delete_index](#jerry_object_delete_index) +- [jerry_object_set](#jerry_object_set) +- [jerry_object_get_index](#jerry_object_get_index) +- [jerry_object_set_index](#jerry_object_set_index) -## jerry_get_property_by_index +## jerry_object_get_index **Summary** Get value by an index from the specified object. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_property_by_index (const jerry_value_t obj_val, - uint32_t index); +jerry_object_get_index (const jerry_value_t obj_val, + uint32_t index); ``` - `obj_val` - object value @@ -8990,28 +8642,28 @@ jerry_get_property_by_index (const jerry_value_t obj_val, { jerry_value_t object; - ... // create or acquire object + ... // create or copy object - jerry_value_t value = jerry_get_property_by_index (object, 5); + jerry_value_t value = jerry_object_get_index (object, 5); ... - jerry_release_value (value); - jerry_release_value (object); + jerry_value_free (value); + jerry_value_free (object); } ``` **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property](#jerry_delete_property) -- [jerry_delete_property_by_index](#jerry_delete_property_by_index) -- [jerry_get_property](#jerry_get_property) -- [jerry_set_property](#jerry_set_property) -- [jerry_set_property_by_index](#jerry_set_property_by_index) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete](#jerry_object_delete) +- [jerry_object_delete_index](#jerry_object_delete_index) +- [jerry_object_get](#jerry_object_get) +- [jerry_object_set](#jerry_object_set) +- [jerry_object_set_index](#jerry_object_set_index) -## jerry_get_own_property +## jerry_object_find_own **Summary** @@ -9021,7 +8673,7 @@ The receiver is passed as the `this` argument for getters, and the receiver argument for Proxy `get` traps. *Notes*: - - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it is no longer needed. + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - The `found_p` argument is ignored if its value is NULL. - The target value of `found_p` argument is set to false when the arguments are invalid, e.g. `obj_val` is not an object. @@ -9029,10 +8681,10 @@ argument for Proxy `get` traps. ```c jerry_value_t -jerry_get_own_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val, - const jerry_value_t receiver_val, - bool *found_p); +jerry_object_find_own (const jerry_value_t obj_val, + const jerry_value_t prop_name_val, + const jerry_value_t receiver_val, + bool *found_p); ``` - `obj_val` - object value @@ -9041,7 +8693,7 @@ jerry_get_own_property (const jerry_value_t obj_val, - `found_p` - [out] true, if the property is found or obj_val is a Proxy object, false otherwise - return value - value of property, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** @@ -9056,11 +8708,11 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "Object"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("Object"); bool found; - jerry_value_t prop_value = jerry_get_own_property (global_object, prop_name, global_object, &found); + jerry_value_t prop_value = jerry_object_find_own (global_object, prop_name, global_object, &found); if (found) { @@ -9069,9 +8721,9 @@ main (void) /* use "prop_value" then release it. */ - jerry_release_value (prop_value); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (prop_value); + jerry_value_free (prop_name); + jerry_value_free (global_object); return 0; } @@ -9079,27 +8731,27 @@ main (void) **See also** -- [jerry_get_property](#jerry_get_property) -- [jerry_get_property_by_index](#jerry_get_property_by_index) +- [jerry_object_get](#jerry_object_get) +- [jerry_object_get_index](#jerry_object_get_index) -## jerry_get_internal_property +## jerry_object_get_internal **Summary** Get value of an internal property to the specified object with the given name. *Note*: - - Properties which were not created with [jerry_set_internal_property](#jerry_set_internal_property) are excluded + - Properties which were not created with [jerry_object_set_internal](#jerry_object_set_internal) are excluded during the operation. - - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it + - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_internal_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val); +jerry_object_get_internal (const jerry_value_t obj_val, + const jerry_value_t prop_name_val); ``` - `obj_val` - object value @@ -9107,7 +8759,7 @@ jerry_get_internal_property (const jerry_value_t obj_val, - return value - value of property, if the internal property exists - undefined value, if the, if the internal does not property exists - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.2*. @@ -9123,16 +8775,16 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property"); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("hidden_property"); - jerry_value_t prop_value = jerry_get_internal_property (global_object, prop_name); + jerry_value_t prop_value = jerry_object_get_internal (global_object, prop_name); /* use "prop_value" then release it. */ - jerry_release_value (prop_value); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (prop_value); + jerry_value_free (prop_name); + jerry_value_free (global_object); return 0; } @@ -9140,27 +8792,27 @@ main (void) **See also** -- [jerry_has_internal_property](#jerry_has_internal_property) -- [jerry_delete_internal_property](#jerry_delete_internal_property) -- [jerry_set_internal_property](#jerry_set_internal_property) +- [jerry_object_has_internal](#jerry_object_has_internal) +- [jerry_object_delete_internal](#jerry_object_delete_internal) +- [jerry_object_set_internal](#jerry_object_set_internal) -## jerry_set_property +## jerry_object_set **Summary** Set a property to the specified object with the given name. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c 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_object_set (const jerry_value_t obj_val, + const jerry_value_t prop_name_val, + const jerry_value_t value_to_set) ``` - `obj_val` - object value @@ -9168,7 +8820,7 @@ jerry_set_property (const jerry_value_t obj_val, - `value_to_set` - value to set - return value - true, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** @@ -9176,52 +8828,52 @@ jerry_set_property (const jerry_value_t obj_val, { jerry_value_t value_to_set; - ... // create or acquire value to set + ... // create or copy value to set - jerry_value_t glob_obj = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop"); + jerry_value_t glob_obj = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("my_prop"); - jerry_value_t set_result = jerry_set_property (glob_obj, prop_name, value_to_set); + jerry_value_t set_result = jerry_object_set (glob_obj, prop_name, value_to_set); ... // check result of property set call - jerry_release_value (set_result); - jerry_release_value (prop_name); + jerry_value_free (set_result); + jerry_value_free (prop_name); ... - jerry_release_value (value_to_set); - jerry_release_value (glob_obj); + jerry_value_free (value_to_set); + jerry_value_free (glob_obj); } ``` **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property](#jerry_delete_property) -- [jerry_delete_property_by_index](#jerry_delete_property_by_index) -- [jerry_get_property](#jerry_get_property) -- [jerry_get_property_by_index](#jerry_get_property_by_index) -- [jerry_set_property_by_index](#jerry_set_property_by_index) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete](#jerry_object_delete) +- [jerry_object_delete_index](#jerry_object_delete_index) +- [jerry_object_get](#jerry_object_get) +- [jerry_object_get_index](#jerry_object_get_index) +- [jerry_object_set_index](#jerry_object_set_index) -## jerry_set_property_by_index +## jerry_object_set_index **Summary** Set indexed value in the specified object -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_set_property_by_index (const jerry_value_t obj_val, - uint32_t index, - const jerry_value_t value_to_set); +jerry_object_set_index (const jerry_value_t obj_val, + uint32_t index, + const jerry_value_t value_to_set); ``` - `obj_val` - object value @@ -9238,30 +8890,30 @@ jerry_set_property_by_index (const jerry_value_t obj_val, jerry_value_t object; jerry_value_t value_to_set; - ... // create or acquire object and value to set + ... // create or copy object and value to set - jerry_value_t ret_val = jerry_set_property_by_index (object, 5, value_to_set); + jerry_value_t ret_val = jerry_object_set_index (object, 5, value_to_set); ... - jerry_release_value (value_to_set); - jerry_release_value (ret_val); - jerry_release_value (object); + jerry_value_free (value_to_set); + jerry_value_free (ret_val); + jerry_value_free (object); } ``` **See also** -- [jerry_has_property](#jerry_has_property) -- [jerry_has_own_property](#jerry_has_own_property) -- [jerry_delete_property](#jerry_delete_property) -- [jerry_delete_property_by_index](#jerry_delete_property_by_index) -- [jerry_get_property](#jerry_get_property) -- [jerry_set_property](#jerry_set_property) -- [jerry_get_property_by_index](#jerry_get_property_by_index) +- [jerry_object_has](#jerry_object_has) +- [jerry_object_has_own](#jerry_object_has_own) +- [jerry_object_delete](#jerry_object_delete) +- [jerry_object_delete_index](#jerry_object_delete_index) +- [jerry_object_get](#jerry_object_get) +- [jerry_object_set](#jerry_object_set) +- [jerry_object_get_index](#jerry_object_get_index) -## jerry_set_internal_property +## jerry_object_set_internal **Summary** @@ -9269,16 +8921,16 @@ Set an internal property to the specified object with the given name. *Note*: - The property cannot be accessed from the JavaScript context, only from the public API. - - It is different from [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) in that any jerry API value + - It is different from [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) in that any jerry API value can be hidden from the JavaScript context, not only native pointers. **Prototype** ```c 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) +jerry_object_set_internal (const jerry_value_t obj_val, + const jerry_value_t prop_name_val, + const jerry_value_t value_to_set) ``` - `obj_val` - object value @@ -9286,7 +8938,7 @@ jerry_set_internal_property (const jerry_value_t obj_val, - `value_to_set` - value to set - return value - true, if success - - thrown error, otherwise + - thrown exception, otherwise *New in version 2.2*. @@ -9302,17 +8954,17 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "hidden_property"); - jerry_value_t value_to_set = jerry_create_number (5); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("hidden_property"); + jerry_value_t value_to_set = jerry_number (5); - bool set_result = jerry_set_internal_property (global_object, prop_name, value_to_set); + bool set_result = jerry_object_set_internal (global_object, prop_name, value_to_set); /* check the result of internal property set call */ - jerry_release_value (value_to_set); - jerry_release_value (prop_name); - jerry_release_value (global_object); + jerry_value_free (value_to_set); + jerry_value_free (prop_name); + jerry_value_free (global_object); return 0; } @@ -9320,12 +8972,12 @@ main (void) **See also** -- [jerry_has_internal_property](#jerry_has_internal_property) -- [jerry_delete_internal_property](#jerry_delete_internal_property) -- [jerry_get_internal_property](#jerry_get_internal_property) +- [jerry_object_has_internal](#jerry_object_has_internal) +- [jerry_object_delete_internal](#jerry_object_delete_internal) +- [jerry_object_get_internal](#jerry_object_get_internal) -## jerry_property_descriptor_create +## jerry_property_descriptor **Summary** @@ -9336,7 +8988,7 @@ the `jerry_property_descriptor_t` struct will be set to zero or false depending ```c jerry_property_descriptor_t -jerry_property_descriptor_create (void); +jerry_property_descriptor (void); ``` *New in version [[NEXT_RELEASE]]*: Replaces `jerry_init_property_descriptor_fields`. @@ -9345,7 +8997,7 @@ jerry_property_descriptor_create (void); ```c { - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); ... // usage of prop_desc @@ -9353,32 +9005,32 @@ jerry_property_descriptor_create (void); } ``` -For a more complete example see [jerry_define_own_property](#jerry_define_own_property). +For a more complete example see [jerry_object_define_own_prop](#jerry_object_define_own_prop). **See also** - [jerry_property_descriptor_t](#jerry_property_descriptor_t) -- [jerry_define_own_property](#jerry_define_own_property) -- [jerry_get_own_property_descriptor](#jerry_get_own_property_descriptor) +- [jerry_object_define_own_prop](#jerry_object_define_own_prop) +- [jerry_object_get_own_prop](#jerry_object_get_own_prop) - [jerry_property_descriptor_free](#jerry_property_descriptor_free) -## jerry_define_own_property +## jerry_object_define_own_prop **Summary** Define a property to the specified object with the given name. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c 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); +jerry_object_define_own_prop (const jerry_value_t obj_val, + const jerry_value_t prop_name_val, + const jerry_property_descriptor_t *prop_desc_p); ``` - `obj_val` - target object where the property should be registered @@ -9386,11 +9038,11 @@ jerry_define_own_property (const jerry_value_t obj_val, - `prop_desc_p` - pointer to property descriptor - return value - true, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** -Registering a simple value property via the `jerry_define_own_property` method: +Registering a simple value property via the `jerry_object_define_own_prop` method: [doctest]: # (name="02.API-REFERENCE-define-property.c") @@ -9402,14 +9054,14 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); // configure the property - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); - // create or acquire value to set + // create or copy value to set // For example: - jerry_value_t value_to_set = jerry_create_number (33); + jerry_value_t value_to_set = jerry_number (33); // set the property descriptor fields: // set the "JERRY_PROP_IS_VALUE_DEFINED" flag to indicate the "value" @@ -9427,28 +9079,28 @@ main (void) prop_desc.value = value_to_set; // add the property as "my_prop" for the global object - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop"); - jerry_value_t return_value = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); - if (jerry_value_is_error (return_value)) + jerry_value_t prop_name = jerry_string_sz ("my_prop"); + jerry_value_t return_value = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); + if (jerry_value_is_exception (return_value)) { // there was an error } // re-define the property with the enumerable flag set to false prop_desc.flags &= (uint16_t) ~JERRY_PROP_IS_ENUMERABLE; - return_value = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); - if (jerry_value_is_error (return_value)) + return_value = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); + if (jerry_value_is_exception (return_value)) { // there was an error } - // if there was no error at this point the global object should have a "my_prop" property + // if there was no exception at this point the global object should have a "my_prop" property - jerry_release_value (return_value); - jerry_release_value (prop_name); + jerry_value_free (return_value); + jerry_value_free (prop_name); jerry_property_descriptor_free (&prop_desc); - jerry_release_value (global_obj_val); + jerry_value_free (global_obj_val); jerry_cleanup (); return 0; @@ -9456,7 +9108,7 @@ main (void) ``` -Registering a getter/setter property via the `jerry_define_own_property` method: +Registering a getter/setter property via the `jerry_object_define_own_prop` method: [doctest]: # (name="02.API-REFERENCE-define-property-getset.c") @@ -9475,7 +9127,7 @@ method_getter (const jerry_call_info_t *call_info_p, counter++; printf("Getter called, returning: %d\n", counter); - return jerry_create_number (counter); + return jerry_number (counter); } static jerry_value_t @@ -9486,12 +9138,12 @@ method_setter (const jerry_call_info_t *call_info_p, // Note: the arguments count and type should be checked // in this example it is omitted! - double new_value = jerry_get_number_value (args[0]); + double new_value = jerry_value_as_number (args[0]); counter = (int) new_value; printf("Setter called, setting: %d\n", counter); - return jerry_create_undefined (); + return jerry_undefined (); } int @@ -9499,32 +9151,32 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); // configure the property - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); // set the property descriptor fields: prop_desc.flags |= JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED; - prop_desc.getter = jerry_create_external_function (method_getter); - prop_desc.setter = jerry_create_external_function (method_setter); + prop_desc.getter = jerry_function_external (method_getter); + prop_desc.setter = jerry_function_external (method_setter); // add the property as "my_prop" for the global object - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop"); - jerry_value_t return_value = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); - if (jerry_value_is_error (return_value)) + jerry_value_t prop_name = jerry_string_sz ("my_prop"); + jerry_value_t return_value = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); + if (jerry_value_is_exception (return_value)) { // there was an error } - // if there was no error at this point the global object should have a "my_prop" property + // if there was no exception at this point the global object should have a "my_prop" property - jerry_release_value (return_value); - jerry_release_value (prop_name); + jerry_value_free (return_value); + jerry_value_free (prop_name); jerry_property_descriptor_free (&prop_desc); - jerry_release_value (global_obj_val); + jerry_value_free (global_obj_val); // run an example js code to use the getter/setters @@ -9532,7 +9184,7 @@ main (void) jerry_value_t eval_result = jerry_eval ((const jerry_char_t *) src_p, strlen (src_p), JERRY_PARSE_NO_OPTS); // "eval_result" is the last result of "this.my_prop" that is "5" currently. - double result_number = jerry_get_number_value (eval_result); + double result_number = jerry_value_as_number (eval_result); printf("output: %lf\n", result_number); jerry_cleanup (); @@ -9544,12 +9196,12 @@ main (void) **See also** - [jerry_property_descriptor_t](#jerry_property_descriptor_t) -- [jerry_property_descriptor_create](#jerry_property_descriptor_create) -- [jerry_get_own_property_descriptor](#jerry_get_own_property_descriptor) +- [jerry_property_descriptor](#jerry_property_descriptor) +- [jerry_object_get_own_prop](#jerry_object_get_own_prop) - [jerry_property_descriptor_free](#jerry_property_descriptor_free) -## jerry_get_own_property_descriptor +## jerry_object_get_own_prop **Summary** @@ -9559,9 +9211,9 @@ Construct property descriptor from specified property. ```c jerry_value_t -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); +jerry_object_get_own_prop (const jerry_value_t obj_val, + const jerry_value_t prop_name_val, + jerry_property_descriptor_t *prop_desc_p); ``` - `obj_val` - object value @@ -9575,26 +9227,26 @@ jerry_get_own_property_descriptor (const jerry_value_t obj_val, ```c { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop"); - jerry_get_own_property_descriptor (global_obj_val, prop_name, &prop_desc); - jerry_release_value (prop_name); + jerry_value_t prop_name = jerry_string_sz ("my_prop"); + jerry_object_get_own_prop (global_obj_val, prop_name, &prop_desc); + jerry_value_free (prop_name); ... // usage of property descriptor jerry_property_descriptor_free (&prop_desc); - jerry_release_value (global_obj_val); + jerry_value_free (global_obj_val); } ``` **See also** - [jerry_property_descriptor_t](#jerry_property_descriptor_t) -- [jerry_property_descriptor_create](#jerry_property_descriptor_create) -- [jerry_define_own_property](#jerry_define_own_property) +- [jerry_property_descriptor](#jerry_property_descriptor) +- [jerry_object_define_own_prop](#jerry_object_define_own_prop) - [jerry_property_descriptor_free](#jerry_property_descriptor_free) @@ -9619,7 +9271,7 @@ jerry_property_descriptor_free (const jerry_property_descriptor_t *prop_desc_p); ```c { - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); ... // usage of property descriptor @@ -9629,30 +9281,29 @@ jerry_property_descriptor_free (const jerry_property_descriptor_t *prop_desc_p); **See also** -- [jerry_property_descriptor_create](#jerry_property_descriptor_create) -- [jerry_define_own_property](#jerry_define_own_property) -- [jerry_get_own_property_descriptor](#jerry_get_own_property_descriptor) +- [jerry_property_descriptor](#jerry_property_descriptor) +- [jerry_object_define_own_prop](#jerry_object_define_own_prop) +- [jerry_object_get_own_prop](#jerry_object_get_own_prop) -## jerry_call_function +## jerry_call **Summary** -Call function specified by a function value. Error flag must -not be set for any arguments of this function. Value of `this` -parameter should be set to `undefined` for non-method calls. +Call function specified by a function value. The argument values must not be exceptions. +Value of `this` parameter should be set to `undefined` for non-method calls. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c 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_call (const jerry_value_t func_obj_val, + const jerry_value_t this_val, + const jerry_value_t args_p[], + jerry_size_t args_count); ``` - `func_obj_val` - the function object to call @@ -9671,45 +9322,45 @@ jerry_call_function (const jerry_value_t func_obj_val, if (jerry_value_is_function (target_function)) { - jerry_value_t this_val = jerry_create_undefined (); - jerry_value_t ret_val = jerry_call_function (target_function, this_val, NULL, 0); + jerry_value_t this_val = jerry_undefined (); + jerry_value_t ret_val = jerry_call (target_function, this_val, NULL, 0); - if (!jerry_value_is_error (ret_val)) + if (!jerry_value_is_exception (ret_val)) { ... // handle return value } - jerry_release_value (ret_val); - jerry_release_value (this_val); + jerry_value_free (ret_val); + jerry_value_free (this_val); } - jerry_release_value (target_function); + jerry_value_free (target_function); } ``` **See also** - [jerry_is_function](#jerry_is_function) -- [jerry_create_external_function](#jerry_create_external_function) +- [jerry_function_external](#jerry_function_external) -## jerry_construct_object +## jerry_construct **Summary** Construct object, invoking specified function object as constructor. Error flag must not be set for any arguments of this function. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c 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_construct (const jerry_value_t func_obj_val, + const jerry_value_t args_p[], + jerry_size_t args_count); ``` - `func_obj_val` - function object to call @@ -9727,14 +9378,14 @@ jerry_construct_object (const jerry_value_t func_obj_val, if (jerry_is_constructor (val)) { - jerry_value_t ret_val = jerry_construct_object (val, NULL, 0); + jerry_value_t ret_val = jerry_construct (val, NULL, 0); - if (!jerry_value_is_error (ret_val)) + if (!jerry_value_is_exception (ret_val)) { ... // handle return value } - jerry_release_value (ret_val); + jerry_value_free (ret_val); } } ``` @@ -9744,112 +9395,112 @@ jerry_construct_object (const jerry_value_t func_obj_val, - [jerry_is_constructor](#jerry_is_constructor) -## jerry_get_object_keys +## jerry_object_keys **Summary** Get keys of the specified object value. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_object_keys (const jerry_value_t obj_val); +jerry_object_keys (const jerry_value_t obj_val); ``` - `obj_val` - object value - return value - array object value, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** ```c { jerry_value_t object; - ... // create or acquire object + ... // create or copy object - jerry_value_t keys_array = jerry_get_object_keys (object); + jerry_value_t keys_array = jerry_object_keys (object); ... // usage of keys_array - jerry_release_value (keys_array); + jerry_value_free (keys_array); } ``` **See also** -- [jerry_get_property](#jerry_get_property) -- [jerry_set_property](#jerry_set_property) +- [jerry_object_get](#jerry_object_get) +- [jerry_object_set](#jerry_object_set) -## jerry_get_prototype +## jerry_object_proto **Summary** Get the prototype of the specified object. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_prototype (const jerry_value_t obj_val); +jerry_object_proto (const jerry_value_t obj_val); ``` - `obj_val` - object value - return value - object value, if success - - null or thrown error, otherwise + - null or thrown exception, otherwise **Example** ```c { jerry_value_t object; - ... // create or acquire object + ... // create or copy object - jerry_value_t prototype = jerry_get_prototype (object); + jerry_value_t prototype = jerry_object_proto (object); ... // usage of prototype object - jerry_release_value (prototype); - jerry_release_value (object); + jerry_value_free (prototype); + jerry_value_free (object); } ``` **See also** -- [jerry_set_prototype](#jerry_set_prototype) +- [jerry_object_set_proto](#jerry_object_set_proto) -## jerry_set_prototype +## jerry_object_set_proto **Summary** Set the prototype of the specified object. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_set_prototype (const jerry_value_t obj_val, - const jerry_value_t proto_obj_val); +jerry_object_set_proto (const jerry_value_t obj_val, + const jerry_value_t proto_obj_val); ``` - `obj_val` - object value - `proto_obj_val` - prototype object value - return value - true, if success - - thrown error, otherwise + - thrown exception, otherwise **Example** @@ -9858,47 +9509,43 @@ jerry_set_prototype (const jerry_value_t obj_val, jerry_value_t object; jerry_value_t prototype; - ... // create or acquire object and prototype + ... // create or copy object and prototype - jerry_value_t ret_val = jerry_set_prototype (object, prototype); + jerry_value_t ret_val = jerry_object_set_proto (object, prototype); - jerry_release_value (ret_val); - jerry_release_value (prototype); - jerry_release_value (object); + jerry_value_free (ret_val); + jerry_value_free (prototype); + jerry_value_free (object); } ``` **See also** -- [jerry_get_prototype](#jerry_get_prototype) +- [jerry_object_proto](#jerry_object_proto) -## jerry_get_object_native_pointer +## jerry_object_get_native_ptr **Summary** Get native pointer by the given type information. The pointer and the type information are previously associated with the object by -[jerry_set_object_native_pointer](#jerry_set_object_native_pointer). +[jerry_object_set_native_ptr](#jerry_object_set_native_ptr). -*Note*: `out_native_pointer_p` can be NULL, and it means the - caller doesn't want to get the native_pointer. +*Note*: `native_info_p` can be NULL **Prototype** ```c -bool -jerry_get_object_native_pointer (const jerry_value_t obj_val, - void **out_native_pointer_p, - const jerry_object_native_info_t *native_info_p) +void * +jerry_object_get_native_ptr (const jerry_value_t object, + const jerry_object_native_info_t *native_info_p) ``` -- `obj_val` - object value to get native pointer from. -- `out_native_pointer_p` - native pointer (output parameter). +- `object` - object value to get native pointer from. - `native_info_p` - native pointer's type information. - return value - - true, if there is native pointer associated of the specified object with the given native type info - - false, otherwise + - native pointer associated with the argument object for the given native type info *New in version 2.0*: Changed from `jerry_get_object_native_handle`. @@ -9996,10 +9643,9 @@ print_buffer (char *data_p, static void do_stuff (jerry_value_t object) { - void *native_p; - bool has_p = jerry_get_object_native_pointer (object, &native_p, &buffer_obj_type_info); + void *native_p = jerry_object_get_native_ptr (object, &buffer_obj_type_info); - if (!has_p) + if (native_p == NULL) { // Process the error return; @@ -10013,9 +9659,9 @@ do_stuff (jerry_value_t object) if (need_shape_info) { - has_p = jerry_get_object_native_pointer (object, &native_p, &shape_obj_type_info); + native_p = jerry_object_get_native_ptr (object, &shape_obj_type_info); - if (!has_p) + if (native_p == NULL) { // Process the error return; @@ -10031,9 +9677,9 @@ do_stuff (jerry_value_t object) if (need_secret_info) { - has_p = jerry_get_object_native_pointer (object, &native_p, NULL); + native_p = jerry_object_get_native_ptr (object, NULL); - if (!has_p) + if (native_p == NULL) { // Process the error return; @@ -10041,7 +9687,7 @@ do_stuff (jerry_value_t object) printf("Secret: %d\n", (int)((uintptr_t) native_p)); // Usage of native_p - bool deleted = jerry_delete_object_native_pointer (object, NULL); + bool deleted = jerry_object_delete_native_ptr (object, NULL); if (deleted) { @@ -10055,29 +9701,29 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); buffer_native_object_t *buffer_p = (buffer_native_object_t *) malloc (sizeof (buffer_native_object_t)); buffer_p->length = 14; buffer_p->data_p = (char *) malloc (buffer_p->length * sizeof (char)); memcpy (buffer_p->data_p, "My buffer data", buffer_p->length); - jerry_set_object_native_pointer (object, buffer_p, &buffer_obj_type_info); + jerry_object_set_native_ptr (object, &buffer_obj_type_info, buffer_p); shape_native_object_t *shape_p = (shape_native_object_t *) malloc (sizeof (shape_native_object_t)); shape_p->area = 6; shape_p->perimeter = 12; - jerry_set_object_native_pointer (object, shape_p, &shape_obj_type_info); + jerry_object_set_native_ptr (object, &shape_obj_type_info, shape_p); // The native pointer can be NULL. This gives possibly to get notified via the native type info's // free callback when the object has been freed by the GC. - jerry_set_object_native_pointer (object, NULL, &destructor_obj_type_info); + jerry_object_set_native_ptr (object, &destructor_obj_type_info, NULL); // The native type info can be NULL as well. In this case the registered property is simply freed // when the object is freed by the GC. - jerry_set_object_native_pointer (object, SECRET_INFO, NULL); + jerry_object_set_native_ptr (object, NULL, SECRET_INFO); do_stuff (object); - jerry_release_value (object); + jerry_value_free (object); jerry_cleanup (); return 0; @@ -10086,17 +9732,17 @@ main (void) **See also** -- [jerry_create_object](#jerry_create_object) -- [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) +- [jerry_object](#jerry_object) +- [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) - [jerry_object_native_info_t](#jerry_object_native_info_t) -## jerry_set_object_native_pointer +## jerry_object_set_native_ptr **Summary** Set native pointer and an optional type information for the specified object. -You can get them by calling [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) later. +You can get them by calling [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) later. *Notes*: - If a native pointer was already set for the object with the same type information, its value is updated. @@ -10107,37 +9753,37 @@ You can get them by calling [jerry_get_object_native_pointer](#jerry_get_object_ - The free callback can invoke API functions. *Note*: If possible do not store API values in native pointers, rather check - [jerry_set_internal_property](#jerry_set_internal_property). + [jerry_object_set_internal](#jerry_object_set_internal). **Prototype** ```c void -jerry_set_object_native_pointer (const jerry_value_t obj_val, - void *native_p, - const jerry_object_native_info_t *info_p) +jerry_object_set_native_ptr (const jerry_value_t obj_val, + const jerry_object_native_info_t *info_p, + void *native_p); ``` - `obj_val` - object to set native pointer in. -- `native_p` - native pointer. - `info_p` - native pointer's type information or NULL. When used, this should be a long-lived pointer, usually a pointer to a `static const jerry_object_native_info_t` makes most sense. +- `native_p` - native pointer. *New in version 2.0*: Changed from `jerry_set_object_native_handle`. **Example** -See [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) for a +See [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) for a best-practice example. **See also** -- [jerry_create_object](#jerry_create_object) -- [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) +- [jerry_object](#jerry_object) +- [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) - [jerry_object_native_info_t](#jerry_object_native_info_t) -## jerry_delete_object_native_pointer +## jerry_object_delete_native_ptr **Summary** @@ -10154,8 +9800,8 @@ Delete the native pointer of the specified object associated with the given nati ```c bool -jerry_delete_object_native_pointer (const jerry_value_t obj_val, - const jerry_object_native_info_t *info_p) +jerry_object_delete_native_ptr (const jerry_value_t obj_val, + const jerry_object_native_info_t *info_p) ``` - `obj_val` - object to delete native pointer from. @@ -10165,25 +9811,25 @@ jerry_delete_object_native_pointer (const jerry_value_t obj_val, **Example** -See [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) for a +See [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) for a best-practice example. **See also** -- [jerry_create_object](#jerry_create_object) -- [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) -- [jerry_get_object_native_pointer](#jerry_set_object_native_pointer) +- [jerry_object](#jerry_object) +- [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) +- [jerry_object_get_native_ptr](#jerry_object_set_native_ptr) - [jerry_object_native_info_t](#jerry_object_native_info_t) -## jerry_native_pointer_init_references +## jerry_native_ptr_init **Summary** Initialize the references stored in a buffer pointed by a native pointer. The references are initialized to undefined. This function must be called before the buffer is attached to an object by -[jerry_set_object_native_pointer](#jerry_set_object_native_pointer). +[jerry_object_set_native_ptr](#jerry_object_set_native_ptr). *Note*: - The description of [jerry_object_native_info_t](#jerry_object_native_info_t) @@ -10193,8 +9839,8 @@ before the buffer is attached to an object by ```c void -jerry_native_pointer_init_references (void *native_pointer_p, - const jerry_object_native_info_t *native_info_p); +jerry_native_ptr_init (void *native_pointer_p, + const jerry_object_native_info_t *native_info_p); ``` - `native_pointer_p` - a valid non-NULL pointer to a native buffer. @@ -10223,7 +9869,7 @@ native_references_free_callback (void *native_p, /**< native pointer */ jerry_object_native_info_t *info_p) /**< native info */ { /* References must be finalized when a buffer is no longer attached. */ - jerry_native_pointer_release_references (native_p, info_p); + jerry_native_ptr_free (native_p, info_p); free (native_p); } /* native_references_free_callback */ @@ -10239,20 +9885,20 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object_value = jerry_create_object (); + jerry_value_t object_value = jerry_object (); user_buffer_t *buffer_p = (user_buffer_t *) malloc (sizeof (user_buffer_t)); /* References must be initialized before a buffer is attached. */ - jerry_native_pointer_init_references ((void *) buffer_p, &native_info); + jerry_native_ptr_init ((void *) buffer_p, &native_info); - jerry_set_object_native_pointer (object_value, (void *) buffer_p, &native_info); + jerry_object_set_native_ptr (object_value, &native_info, (void *) buffer_p); /* References can be modified after the buffer is attached. * This example sets a self reference. */ - jerry_native_pointer_set_reference (&buffer_p->a, object_value); + jerry_native_ptr_set (&buffer_p->a, object_value); - jerry_release_value (object_value); + jerry_value_free (object_value); jerry_cleanup (); return 0; @@ -10261,11 +9907,11 @@ main (void) **See also** -- [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) -- [jerry_native_pointer_release_references](#jerry_native_pointer_release_references) -- [jerry_native_pointer_set_reference](#jerry_native_pointer_set_reference) +- [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) +- [jerry_native_ptr_free](#jerry_native_ptr_free) +- [jerry_native_ptr_set](#jerry_native_ptr_set) -## jerry_native_pointer_release_references +## jerry_native_ptr_free **Summary** @@ -10273,7 +9919,7 @@ Release the value references stored in a buffer pointed by a native pointer. This function must be called after a buffer is no longer attached to any object, even if the buffer is attached to another object again. This function also initializes the values to undefined, so calling -[jerry_native_pointer_init_references](#jerry_native_pointer_init_references) +[jerry_native_ptr_init](#jerry_native_ptr_init) is optional before the buffer is attached again. *Note*: @@ -10284,8 +9930,8 @@ is optional before the buffer is attached again. ```c void -jerry_native_pointer_release_references (void *native_pointer_p, - const jerry_object_native_info_t *native_info_p); +jerry_native_ptr_free (void *native_pointer_p, + const jerry_object_native_info_t *native_info_p); ``` - `native_pointer_p` - a valid non-NULL pointer to a native buffer. @@ -10295,16 +9941,16 @@ jerry_native_pointer_release_references (void *native_pointer_p, **Example** -See the example of [jerry_native_pointer_init_references](#jerry_native_pointer_init_references). +See the example of [jerry_native_ptr_init](#jerry_native_ptr_init). **See also** -- [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) -- [jerry_native_pointer_init_references](#jerry_native_pointer_init_references) -- [jerry_native_pointer_set_reference](#jerry_native_pointer_set_reference) +- [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) +- [jerry_native_ptr_init](#jerry_native_ptr_init) +- [jerry_native_ptr_set](#jerry_native_ptr_set) -## jerry_native_pointer_set_reference +## jerry_native_ptr_set **Summary** @@ -10321,8 +9967,8 @@ part of a buffer which is currently assigned to an object. ```c void -jerry_native_pointer_set_reference (jerry_value_t *reference_p, - jerry_value_t value) +jerry_native_ptr_set (jerry_value_t *reference_p, + jerry_value_t value) ``` - `reference_p` - a valid non-NULL pointer to a reference in a native buffer. @@ -10332,16 +9978,16 @@ jerry_native_pointer_set_reference (jerry_value_t *reference_p, **Example** -See the example of [jerry_native_pointer_init_references](#jerry_native_pointer_init_references). +See the example of [jerry_native_ptr_init](#jerry_native_ptr_init). **See also** -- [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) -- [jerry_native_pointer_init_references](#jerry_native_pointer_init_references) -- [jerry_native_pointer_release_references](#jerry_native_pointer_release_references) +- [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) +- [jerry_native_ptr_init](#jerry_native_ptr_init) +- [jerry_native_ptr_free](#jerry_native_ptr_free) -## jerry_object_get_property_names +## jerry_object_property_names **Summary** @@ -10351,15 +9997,15 @@ Gets the property keys for the given object using the selected filters. ```c jerry_value_t -jerry_object_get_property_names (jerry_value_t obj_val, - jerry_property_filter_t filter); +jerry_object_property_names (jerry_value_t obj_val, + jerry_property_filter_t filter); ``` - `obj_val` - object value - `filter` - any combination of [jerry_property_filter_t](#jerry_property_filter_t) options - return value - array containing the filtered property keys in successful operation - - error marked with error flag, otherwise + - exception, otherwise *New in version 2.4*. @@ -10367,13 +10013,13 @@ jerry_object_get_property_names (jerry_value_t obj_val, ```c { - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t keys = jerry_object_get_property_names (object, JERRY_PROPERTY_FILTER_ALL); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t keys = jerry_object_property_names (object, JERRY_PROPERTY_FILTER_ALL); ... // usage of keys - jerry_release_value (keys); - jerry_release_value (global_object); + jerry_value_free (keys); + jerry_value_free (global_object); } ``` @@ -10381,7 +10027,7 @@ jerry_object_get_property_names (jerry_value_t obj_val, - [jerry_property_filter_t](#jerry_property_filter_t) -## jerry_foreach_object_property +## jerry_object_foreach **Summary** @@ -10394,9 +10040,9 @@ If the method returns `false` the iteration will end. ```c bool -jerry_foreach_object_property (jerry_value_t obj_val, - jerry_object_property_foreach_t foreach_p, - void *user_data_p); +jerry_object_foreach (jerry_value_t obj_val, + jerry_object_property_foreach_cb_t foreach_p, + void *user_data_p); ``` - `obj_val` - object value @@ -10432,11 +10078,10 @@ foreach_function (const jerry_value_t prop_name, { if (jerry_value_is_string (prop_name)) { jerry_char_t string_buffer[128]; - jerry_size_t copied_bytes = jerry_substring_to_char_buffer (prop_name, - 0, - 127, - string_buffer, - 127); + jerry_size_t copied_bytes = jerry_string_to_buffer (prop_name, + string_buffer, + 127, + JERRY_ENCODING_UTF8); string_buffer[copied_bytes] = '\0'; printf ("Property: %s\n", string_buffer); @@ -10455,25 +10100,25 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Construct an example object with a single property. */ - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); { - jerry_value_t test_property = jerry_create_string ((const jerry_char_t *) "DemoProp"); - jerry_value_t test_value = jerry_create_number (3); + jerry_value_t test_property = jerry_string_sz ("DemoProp"); + jerry_value_t test_value = jerry_number (3); /* By default all properties added to an object are enumerable. */ - jerry_value_t set_result = jerry_set_property (object, test_property, test_value); - /* The `set_result` should be checked if it is an error or not. */ - jerry_release_value (set_result); - jerry_release_value (test_value); - jerry_release_value (test_property); + jerry_value_t set_result = jerry_object_set (object, test_property, test_value); + /* The `set_result` should be checked if it is an exception or not. */ + jerry_value_free (set_result); + jerry_value_free (test_value); + jerry_value_free (test_property); } /* Iterate on the object's properties with the given user data. */ struct iteration_data user_data = { 0 }; - bool iteration_result = jerry_foreach_object_property (object, foreach_function, &user_data); + bool iteration_result = jerry_object_foreach (object, foreach_function, &user_data); /* Check and process the `iteration_result` if required. */ - jerry_release_value (object); + jerry_value_free (object); jerry_cleanup (); @@ -10483,9 +10128,9 @@ main (void) **See also** -- [jerry_object_property_foreach_t](#jerry_object_property_foreach_t) +- [jerry_object_property_foreach_cb_t](#jerry_object_property_foreach_cb_t) -## jerry_objects_foreach +## jerry_foreach_live_object **Summary** @@ -10494,14 +10139,14 @@ Iterate over all objects available in the engine. The "iterator" `foreach_p` method should return `true` value to continue the search. If the method returns `false` the search for the object is finished. -*Note*: Values obtained in `foreach_p` must be retained using [jerry_acquire_value](#jerry_acquire_value). +*Note*: Values obtained in `foreach_p` must be retained using [jerry_value_copy](#jerry_value_copy). **Prototype** ```c bool -jerry_objects_foreach (jerry_objects_foreach_t foreach_p, - void *user_data_p); +jerry_foreach_live_object (jerry_foreach_live_object_cb_t foreach_p, + void *user_data_p); ``` - `foreach_p` - function that will be invoked for each object. @@ -10537,16 +10182,16 @@ find_my_object (const jerry_value_t candidate, find_my_object_info_t *info_p = (find_my_object_info_t *) user_data_p; /* Check if the given object has the required property. */ - jerry_value_t has_property = jerry_has_property (candidate, info_p->property_name); + jerry_value_t has_property = jerry_object_has (candidate, info_p->property_name); bool object_found = jerry_value_is_true (has_property); if (object_found) { - /* We found it, so we acquire the value and record it. */ - info_p->result = jerry_acquire_value (candidate); + /* We found it, so we copy the value and record it. */ + info_p->result = jerry_value_copy (candidate); } - jerry_release_value (has_property); + jerry_value_free (has_property); /* If the object was not found continue the search. */ return !object_found; @@ -10562,46 +10207,46 @@ main (void) /* Create the test object. */ { - jerry_value_t test_object = jerry_create_object (); + jerry_value_t test_object = jerry_object (); { - jerry_value_t test_property = jerry_create_string ((const jerry_char_t *) "DemoProp"); - jerry_value_t test_value = jerry_create_number (3); - jerry_value_t set_result = jerry_set_property (test_object, test_property, test_value); - /* The `set_result` should be checked if it is an error or not. */ - jerry_release_value (set_result); - jerry_release_value (test_value); - jerry_release_value (test_property); + jerry_value_t test_property = jerry_string_sz ("DemoProp"); + jerry_value_t test_value = jerry_number (3); + jerry_value_t set_result = jerry_object_set (test_object, test_property, test_value); + /* The `set_result` should be checked if it is an exception or not. */ + jerry_value_free (set_result); + jerry_value_free (test_value); + jerry_value_free (test_property); } { /* Register the test object into the global object. */ - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t demo_property = jerry_create_string ((const jerry_char_t *) "DemoObject"); - jerry_value_t set_result = jerry_set_property (global_object, demo_property, test_object); - /* The `set_result` should be checked if it is an error or not. */ - jerry_release_value (set_result); - jerry_release_value (demo_property); - jerry_release_value (global_object); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t demo_property = jerry_string_sz ("DemoObject"); + jerry_value_t set_result = jerry_object_set (global_object, demo_property, test_object); + /* The `set_result` should be checked if it is an exception or not. */ + jerry_value_free (set_result); + jerry_value_free (demo_property); + jerry_value_free (global_object); } - jerry_release_value (test_object); + jerry_value_free (test_object); } /* Look up the test object base on a property name. */ find_my_object_info_t search_info = { - .property_name = jerry_create_string ((const jerry_char_t *) "DemoProp") + .property_name = jerry_string_sz ("DemoProp") }; - if (jerry_objects_foreach (find_my_object, &search_info)) + if (jerry_foreach_live_object (find_my_object, &search_info)) { /* The search was successful. Do something useful with search_info.result. */ // ... printf ("Object found\n"); /* Release the found object after we're done using it. */ - jerry_release_value (search_info.result); + jerry_value_free (search_info.result); } else { @@ -10611,7 +10256,7 @@ main (void) return_value = 1; } - jerry_release_value (search_info.property_name); + jerry_value_free (search_info.property_name); /* Engine cleanup */ jerry_cleanup (); @@ -10621,9 +10266,9 @@ main (void) **See also** -- [jerry_objects_foreach_t](#jerry_objects_foreach_t) +- [jerry_foreach_live_object_cb_t](#jerry_foreach_live_object_cb_t) -## jerry_objects_foreach_by_native_info +## jerry_foreach_live_object_with_info **Summary** @@ -10632,15 +10277,15 @@ Iterate over all objects in the engine matching a certain native data type. The "iterator" `foreach_p` method should return `true` value to continue the search. If the method returns `false` the search for the object is finished. -*Note*: Values obtained in `foreach_p` must be retained using [jerry_acquire_value](#jerry_acquire_value). +*Note*: Values obtained in `foreach_p` must be retained using [jerry_value_copy](#jerry_value_copy). **Prototype** ```c 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); +jerry_foreach_live_object_with_info (const jerry_object_native_info_t *native_info_p, + jerry_foreach_live_object_with_info_cb_t foreach_p, + void *user_data_p); ``` - `native_info_p` - native pointer's type information. @@ -10699,23 +10344,23 @@ static void add_object_with_nativeptr (int foo_value) { // construct object and native_set value: - jerry_value_t test_object = jerry_create_object (); + jerry_value_t test_object = jerry_object (); native_obj_t *native_obj_p = malloc (sizeof (*native_obj_p)); native_obj_p->foo = foo_value; native_obj_p->bar = true; - jerry_set_object_native_pointer (test_object, native_obj_p, &native_obj_type_info); + jerry_object_set_native_ptr (test_object, &native_obj_type_info, native_obj_p); /* Register the test object into the global object. */ - jerry_value_t global_object = jerry_get_global_object (); - jerry_value_t demo_property = jerry_create_string ((const jerry_char_t *) "DemoObject"); - jerry_value_t set_result = jerry_set_property (global_object, demo_property, test_object); - /* The `set_result` should be checked if it is an error or not. */ - jerry_release_value (set_result); - jerry_release_value (demo_property); - jerry_release_value (global_object); - - jerry_release_value (test_object); + jerry_value_t global_object = jerry_current_realm (); + jerry_value_t demo_property = jerry_string_sz ("DemoObject"); + jerry_value_t set_result = jerry_object_set (global_object, demo_property, test_object); + /* The `set_result` should be checked if it is an exception or not. */ + jerry_value_free (set_result); + jerry_value_free (demo_property); + jerry_value_free (global_object); + + jerry_value_free (test_object); } /* create_object_with_nativeptr */ /* @@ -10730,8 +10375,8 @@ find_object (const jerry_value_t candidate, void *data_p, void *user_data_p) if (find_data_p->match_foo_value == native_obj_p->foo) { - /* If the object was found, acquire it and store it in the user data. */ - find_data_p->found_object = jerry_acquire_value (candidate); + /* If the object was found, copy it and store it in the user data. */ + find_data_p->found_object = jerry_value_copy (candidate); find_data_p->found_native_data_p = native_obj_p; /* Stop traversing over the objects. */ @@ -10756,12 +10401,12 @@ main (void) .match_foo_value = 3, }; - if (jerry_objects_foreach_by_native_info (&native_obj_type_info, find_object, &find_data)) + if (jerry_foreach_live_object_with_info (&native_obj_type_info, find_object, &find_data)) { /* The object was found and is now stored in `find_data.found_object`. After using it, it must be released. */ printf ("Object found, native foo value: %d\n", find_data.found_native_data_p->foo); - jerry_release_value (find_data.found_object); + jerry_value_free (find_data.found_object); } else { @@ -10776,20 +10421,20 @@ main (void) **See also** -- [jerry_create_object](#jerry_create_object) -- [jerry_set_object_native_pointer](#jerry_set_object_native_pointer) -- [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) +- [jerry_object](#jerry_object) +- [jerry_object_set_native_ptr](#jerry_object_set_native_ptr) +- [jerry_object_get_native_ptr](#jerry_object_get_native_ptr) - [jerry_object_native_info_t](#jerry_object_native_info_t) -- [jerry_objects_foreach](#jerry_objects_foreach) +- [jerry_foreach_live_object](#jerry_foreach_live_object) # Input validator functions -## jerry_is_valid_utf8_string +## jerry_validate_string **Summary** -Check if a given character buffer is a valid UTF-8 string. +Check if a given character buffer is a valid in the specified encoding string. **Notes**: Calling this method is safe in any time. It can be called even before engine initialization. @@ -10798,12 +10443,14 @@ even before engine initialization. ```c bool -jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */ - jerry_size_t buf_size) /**< string size */ +jerry_validate_string (const jerry_char_t *buffer_p, /**< string data */ + jerry_size_t buf_size, /**< string size */ + jerry_encoding_t encoding); /**< encoding */ ``` -- `utf8_buf_p` - UTF-8 input string buffer. +- `buffer_p` - input string buffer. - `buf_size` - input string buffer size in bytes. +- `encoding` - string encoding - return value - true, if the provided string was a valid UTF-8 string. - false, if the string is not valid as an UTF-8 string. @@ -10823,89 +10470,21 @@ main (void) const jerry_char_t script[] = "print ('Hello, World!');"; const jerry_size_t script_size = sizeof (script) - 1; - if (jerry_is_valid_utf8_string (script, script_size)) - { - jerry_run_simple (script, script_size, JERRY_INIT_EMPTY); - } - - return 0; -} -``` - -**See also** - -- [jerry_run_simple](#jerry_run_simple) -- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8) -- [jerry_create_string_sz_from_utf8](#jerry_create_string_sz_from_utf8) -- [jerry_get_utf8_string_size](#jerry_get_utf8_string_size) -- [jerry_get_utf8_string_length](#jerry_get_utf8_string_length) -- [jerry_string_to_utf8_char_buffer](#jerry_string_to_utf8_char_buffer) -- [jerry_substring_to_utf8_char_buffer](#jerry_substring_to_utf8_char_buffer) - -## jerry_is_valid_cesu8_string - -**Summary** - -Check if a given character buffer is a valid CESU-8 string. - -**Notes**: Calling this method is safe in any time. It can be called -even before engine initialization. - -**Prototype** - -```c -bool -jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string */ - jerry_size_t buf_size) /**< string size */ -``` - -- `cesu8_buf_p` - CESU-8 input string buffer. -- `buf_size` - input string buffer size in bytes. -- return value - - true, if the provided string was a valid CESU-8 string. - - false, if the string is not valid as a CESU-8 string. - -*New in version 2.0*. - -**Example** - -[doctest]: # () - -```c -#include "jerryscript.h" - -int -main (void) -{ - jerry_init (JERRY_INIT_EMPTY); - - const jerry_char_t script[] = "Hello, World!"; - const jerry_size_t script_size = sizeof (script) - 1; - - if (jerry_is_valid_cesu8_string (script, script_size)) + if (!jerry_validate_string (script, script_size, JERRY_ENCODING_CESU8)) { - jerry_value_t string_value = jerry_create_string_sz (script, - script_size); - - // usage of string_value - - jerry_release_value (string_value); + return 1; } - jerry_cleanup (); return 0; } ``` **See also** -- [jerry_create_string](#jerry_create_string) -- [jerry_create_string_sz](#jerry_create_string_sz) -- [jerry_get_string_size](#jerry_get_string_size) -- [jerry_get_string_length](#jerry_get_string_length) -- [jerry_string_to_char_buffer](#jerry_string_to_char_buffer) -- [jerry_substring_to_char_buffer](#jerry_substring_to_char_buffer) - +- [jerry_string](#jerry_string) +- [jerry_string_size](#jerry_string_size) +- [jerry_string_length](#jerry_string_length) +- [jerry_string_to_buffer](#jerry_string_to_buffer) # Dynamic memory management functions @@ -10959,7 +10538,7 @@ void jerry_heap_free (void *mem_p, size_t size); # External context functions -## jerry_create_context +## jerry_context_create **Summary** @@ -10969,9 +10548,9 @@ Create an external JerryScript engine context. ```c jerry_context_t * -jerry_create_context (uint32_t heap_size, - jerry_context_alloc_t alloc, - void *cb_data_p); +jerry_context (uint32_t heap_size, + jerry_context_alloc_t alloc, + void *cb_data_p); ``` - `heap_size` - requested heap size of the JerryScript context @@ -11015,9 +10594,8 @@ context_alloc_fn (size_t size, void *cb_data) static void * thread_function (void *param) { - tls_context = jerry_create_context (512 * 1024, - context_alloc_fn, - NULL); + tls_context = jerry_context (512 * 1024, context_alloc_fn, NULL); + jerry_init (JERRY_INIT_EMPTY); /* Run JerryScript in the context (e.g.: jerry_parse & jerry_run) */ jerry_cleanup (); @@ -11067,11 +10645,11 @@ main (void) Generate snapshot from the specified source code. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_SNAPSHOT_SAVE`) and can be checked in runtime with - the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled). - If the feature is not enabled the function will return an error. + the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_feature_enabled](#jerry_feature_enabled). + If the feature is not enabled the function will return an exception. **Prototype** @@ -11091,12 +10669,12 @@ jerry_generate_snapshot (jerry_value_t compiled_code, - the size of the generated snapshot in bytes as number value, if it was generated successfully (i.e. there are no syntax errors in source code, buffer size is sufficient, and snapshot support is enabled in current configuration through JERRY_SNAPSHOT_SAVE) - - thrown error, otherwise. + - thrown exception, otherwise. *New in version 2.0*. -*Changed in version [[NEXT_RELEASE]]*: The `source_p`, `source_size`, `resource_name_p`, - and `resource_name_length` arguments are replaced by `compiled_code` +*Changed in version [[NEXT_RELEASE]]*: The `source_p`, `source_size`, `source_name_p`, + and `source_name_length` arguments are replaced by `compiled_code` which should contain a compiled ECMAScript script / function. The `jerry_generate_function_snapshot` is now removed and can be reproduced by calling `jerry_parse` with function arguments and using this method @@ -11125,14 +10703,14 @@ main (void) 0, global_mode_snapshot_buffer, buffer_size); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - if (!jerry_value_is_error (generate_result)) + if (!jerry_value_is_exception (generate_result)) { - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); } - jerry_release_value (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); return 0; @@ -11154,11 +10732,11 @@ main (void) Execute/load snapshot from the specified buffer. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API depends on a build option (`JERRY_SNAPSHOT_EXEC`) and can be checked in runtime with - the `JERRY_FEATURE_SNAPSHOT_EXEC` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled). - If the feature is not enabled the function will return an error. + the `JERRY_FEATURE_SNAPSHOT_EXEC` feature enum value, see [jerry_feature_enabled](#jerry_feature_enabled). + If the feature is not enabled the function will return an exception. **Prototype** @@ -11179,7 +10757,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, [jerry_exec_snapshot_option_values_t](#jerry_exec_snapshot_option_values_t). - return value - result of bytecode, if run was successful. - - thrown error, otherwise (an error is reported if the snapshot execution feature is not enabled). + - thrown exception, otherwise (an exception is reported if the snapshot execution feature is not enabled). *Changed in version 2.0*: Added `func_index` and `exec_snapshot_opts` arguments. Removed the `copy_bytecode` last argument. @@ -11211,12 +10789,12 @@ main (void) 0, snapshot_buffer, buffer_size); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - /* 'generate_result' variable should be checked whether it contains an error. */ + /* 'generate_result' variable should be checked whether it contains an exception. */ - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); jerry_init (JERRY_INIT_EMPTY); @@ -11228,7 +10806,7 @@ main (void) NULL); /* 'res' now contains 'string from snapshot' */ - jerry_release_value (res); + jerry_value_free (res); jerry_cleanup (); return 0; @@ -11254,7 +10832,7 @@ main (void) jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "a, b"); + parse_options.argument_list = jerry_string_sz ("a, b"); jerry_value_t parse_result = jerry_parse (function_to_snapshot, sizeof (function_to_snapshot) - 1, @@ -11265,13 +10843,13 @@ main (void) 0, snapshot_buffer, buffer_size); - jerry_release_value (parse_result); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_result); + jerry_value_free (parse_options.argument_list); - /* 'generate_result' variable should be checked whether it contains an error. */ + /* 'generate_result' variable should be checked whether it contains an exception. */ - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); jerry_init (JERRY_INIT_EMPTY); @@ -11283,19 +10861,19 @@ main (void) NULL); /* 'func' can be used now as a function object. */ - jerry_value_t this_value = jerry_create_undefined (); + jerry_value_t this_value = jerry_undefined (); jerry_value_t args[2]; - args[0] = jerry_create_number (1.0); - args[1] = jerry_create_number (2.0); + args[0] = jerry_number (1.0); + args[1] = jerry_number (2.0); - jerry_value_t res = jerry_call_function (func, this_value, args, 2); + jerry_value_t res = jerry_call (func, this_value, args, 2); /* 'res' now contains the value 3 as a jerry_value_t. */ - jerry_release_value (res); - jerry_release_value (args[0]); - jerry_release_value (args[1]); - jerry_release_value (this_value); - jerry_release_value (func); + jerry_value_free (res); + jerry_value_free (args[0]); + jerry_value_free (args[1]); + jerry_value_free (this_value); + jerry_value_free (func); jerry_cleanup (); return 0; @@ -11318,7 +10896,7 @@ None of these literals are magic strings. In C format only valid identifiers are *Note*: - This API depends on a build option (`JERRY_SNAPSHOT_SAVE`) and can be checked in runtime with - the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled). + the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_feature_enabled](#jerry_feature_enabled). If the feature is not enabled the function will return zero. **Prototype** @@ -11370,10 +10948,10 @@ main (void) 0, snapshot_buffer, buffer_size); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); const size_t literal_size = jerry_get_literals_from_snapshot (snapshot_buffer, snapshot_size, @@ -11402,7 +10980,7 @@ main (void) # Backtrace functions -## jerry_get_backtrace +## jerry_backtrace **Summary** @@ -11413,17 +10991,17 @@ The array length is zero if the backtrace is not available. This function is typically called from native callbacks. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This feature depends on build option (`JERRY_LINE_INFO`) and can be checked in runtime with the `JERRY_FEATURE_LINE_INFO` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c jerry_value_t -jerry_get_backtrace (uint32_t max_depth); +jerry_backtrace (uint32_t max_depth); ``` - `max_depth` - backtrace collection stops after reaching this value, 0 = unlimited @@ -11446,35 +11024,34 @@ backtrace_handler (const jerry_call_info_t *call_info_p, const jerry_value_t args_p[], const jerry_length_t args_count) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_LINE_INFO)) + if (!jerry_feature_enabled (JERRY_FEATURE_LINE_INFO)) { printf ("Line info disabled, no backtrace will be printed\n"); - return jerry_create_undefined (); + return jerry_undefined (); } /* If the line info feature is disabled an empty array will be returned. */ - jerry_value_t backtrace_array = jerry_get_backtrace (5); - uint32_t array_length = jerry_get_array_length (backtrace_array); + jerry_value_t backtrace_array = jerry_backtrace (5); + uint32_t array_length = jerry_array_length (backtrace_array); for (uint32_t idx = 0; idx < array_length; idx++) { - jerry_value_t property = jerry_get_property_by_index (backtrace_array, idx); + jerry_value_t property = jerry_object_get_index (backtrace_array, idx); jerry_char_t string_buffer[64]; - jerry_size_t copied_bytes = jerry_substring_to_char_buffer (property, - 0, - 63, - string_buffer, - 63); + jerry_size_t copied_bytes = jerry_string_to_buffer (property, + string_buffer, + 63, + JERRY_ENCODING_UTF8); string_buffer[copied_bytes] = '\0'; printf(" %d: %s\n", idx, string_buffer); - jerry_release_value (property); + jerry_value_free (property); } - jerry_release_value (backtrace_array); + jerry_value_free (backtrace_array); - return jerry_create_undefined (); + return jerry_undefined (); } /* backtrace_handler */ int @@ -11482,19 +11059,19 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); /* Register the "capture_backtrace" method. */ { - jerry_value_t func = jerry_create_external_function (backtrace_handler); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "backtrace"); - jerry_value_t result = jerry_set_property (global, name, func); - jerry_release_value (result); - jerry_release_value (name); - jerry_release_value (func); + jerry_value_t func = jerry_function_external (backtrace_handler); + jerry_value_t name = jerry_string_sz ("backtrace"); + jerry_value_t result = jerry_object_set (global, name, func); + jerry_value_free (result); + jerry_value_free (name); + jerry_value_free (func); } - jerry_release_value (global); + jerry_value_free (global); const char *source = ("function f() { g (); }\n" "function g() { h (); }\n" @@ -11502,21 +11079,21 @@ main (void) "f ();\n"); jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "demo_memory.js"); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("demo_memory.js"); jerry_value_t program = jerry_parse ((const jerry_char_t *) source, strlen (source), &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (!jerry_value_is_error (program)) + if (!jerry_value_is_exception (program)) { jerry_value_t run_result = jerry_run (program); - jerry_release_value (run_result); + jerry_value_free (run_result); } - jerry_release_value (program); + jerry_value_free (program); jerry_cleanup (); return 0; @@ -11525,8 +11102,7 @@ main (void) **See also** -- [jerry_get_backtrace_from](#jerry_get_backtrace_from) -- [jerry_create_external_function](#jerry_create_external_function) +- [jerry_function_external](#jerry_function_external) ## jerry_backtrace_capture @@ -11537,16 +11113,16 @@ Low-level function to capture each backtrace frame. The captured frame data is passed to a callback function. To improve performance, the majority of the frame data is not initialized when the callback function is called. The initialization of these fields can be done later by helper functions such -as [jerry_backtrace_get_location](#jerry_backtrace_get_location). +as [jerry_frame_location](#jerry_frame_location). **Prototype** ```c void -jerry_backtrace_capture (jerry_backtrace_callback_t callback, void *user_p); +jerry_backtrace_capture (jerry_backtrace_cb_t callback, void *user_p); ``` -- `callback` - a [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback +- `callback` - a [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) callback which is called for each captured frame - `user_p` - pointer passed to the `callback` function, can be NULL @@ -11562,7 +11138,7 @@ jerry_backtrace_capture (jerry_backtrace_callback_t callback, void *user_p); #include "jerryscript.h" static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, +backtrace_callback (jerry_frame_t *frame_p, void *user_p) { printf (" A stack frame is captured\n"); @@ -11580,7 +11156,7 @@ backtrace_handler (const jerry_call_info_t *call_info_p, jerry_backtrace_capture (&backtrace_callback, NULL); - return jerry_create_undefined (); + return jerry_undefined (); } /* backtrace_handler */ int @@ -11588,19 +11164,19 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); /* Register the "dump_backtrace" method. */ { - jerry_value_t func = jerry_create_external_function (backtrace_handler); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "backtrace"); - jerry_value_t result = jerry_set_property (global, name, func); - jerry_release_value (result); - jerry_release_value (name); - jerry_release_value (func); + jerry_value_t func = jerry_function_external (backtrace_handler); + jerry_value_t name = jerry_string_sz ("backtrace"); + jerry_value_t result = jerry_object_set (global, name, func); + jerry_value_free (result); + jerry_value_free (name); + jerry_value_free (func); } - jerry_release_value (global); + jerry_value_free (global); const char *source = ("function f() { g (); }\n" "function g() { h (); }\n" @@ -11608,21 +11184,21 @@ main (void) "f ();\n"); jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "demo_backtrace.js"); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("demo_backtrace.js"); jerry_value_t program = jerry_parse ((const jerry_char_t *) source, strlen (source), &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (!jerry_value_is_error (program)) + if (!jerry_value_is_exception (program)) { jerry_value_t run_result = jerry_run (program); - jerry_release_value (run_result); + jerry_value_free (run_result); } - jerry_release_value (program); + jerry_value_free (program); jerry_cleanup (); return 0; @@ -11631,15 +11207,15 @@ main (void) **See also** -- [jerry_get_backtrace](#jerry_get_backtrace) -- [jerry_backtrace_get_frame_type](#jerry_backtrace_get_frame_type) -- [jerry_backtrace_get_location](#jerry_backtrace_get_location) -- [jerry_backtrace_get_function](#jerry_backtrace_get_function) -- [jerry_backtrace_get_this](#jerry_backtrace_get_this) -- [jerry_backtrace_is_strict](#jerry_backtrace_is_strict) +- [jerry_backtrace_capture](#jerry_backtrace_capture) +- [jerry_frame_type](#jerry_frame_type) +- [jerry_frame_location](#jerry_frame_location) +- [jerry_frame_callee](#jerry_frame_callee) +- [jerry_frame_this](#jerry_frame_this) +- [jerry_frame_is_strict](#jerry_frame_is_strict) -## jerry_backtrace_get_frame_type +## jerry_frame_type **Summary** @@ -11650,13 +11226,13 @@ and the value becomes invalid after the callback returns. **Prototype** ```c -jerry_backtrace_frame_types_t -jerry_backtrace_get_frame_type (jerry_backtrace_frame_t *frame_p); +jerry_frame_type_t +jerry_frame_type (jerry_frame_t *frame_p); ``` -- `frame_p` - a frame passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback +- `frame_p` - a frame passed to the [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) callback - return value - - frame type listed in [jerry_backtrace_frame_types_t](#jerry_backtrace_frame_types_t) + - frame type listed in [jerry_frame_type_t](#jerry_frame_type_t) *New in version [[NEXT_RELEASE]]*. @@ -11667,10 +11243,10 @@ with the following callback function: ```c static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, +backtrace_callback (jerry_frame_t *frame_p, void *user_p) { - switch (jerry_backtrace_get_frame_type (frame_p)) + switch (jerry_frame_type (frame_p)) { case JERRY_BACKTRACE_FRAME_JS: { @@ -11693,7 +11269,7 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, - [jerry_backtrace_capture](#jerry_backtrace_capture) -## jerry_backtrace_get_location +## jerry_frame_location **Summary** @@ -11712,11 +11288,11 @@ becomes invalid after the callback returns. **Prototype** ```c -const jerry_backtrace_location_t * -jerry_backtrace_get_location (jerry_backtrace_frame_t *frame_p); +const jerry_frame_location_t * +jerry_frame_location (jerry_frame_t *frame_p); ``` -- `frame_p` - a frame passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback +- `frame_p` - a frame passed to the [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) callback - return value - pointer to the location private field if the location is available, - NULL otherwise @@ -11730,11 +11306,11 @@ with the following callback function: ```c static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, +backtrace_callback (jerry_frame_t *frame_p, void *user_p) { - const jerry_backtrace_location_t *location_p; - location_p = jerry_backtrace_get_location (frame_p); + const jerry_frame_location_t *location_p; + location_p = jerry_frame_location (frame_p); if (location_p == NULL) { @@ -11743,11 +11319,9 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, } jerry_char_t string_buffer[64]; - jerry_size_t copied_bytes = jerry_substring_to_char_buffer (location_p->resource_name, - 0, - 63, - string_buffer, - 63); + jerry_size_t copied_bytes = jerry_string_to_buffer (location_p->source_name, + string_buffer, + sizeof (string_buffer) - 1); string_buffer[copied_bytes] = '\0'; printf(" %s:%d:%d\n", string_buffer, (int) location_p->line, (int) location_p->column); return true; @@ -11759,7 +11333,7 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, - [jerry_backtrace_capture](#jerry_backtrace_capture) -## jerry_backtrace_get_function +## jerry_frame_callee **Summary** @@ -11777,10 +11351,10 @@ after the callback returns. ```c const jerry_value_t * -jerry_backtrace_get_function (jerry_backtrace_frame_t *frame_p); +jerry_frame_callee (jerry_frame_t *frame_p); ``` -- `frame_p` - a frame passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback +- `frame_p` - a frame passed to the [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) callback - return value - pointer to the called function if the function is available, - NULL otherwise @@ -11794,10 +11368,10 @@ with the following callback function: ```c static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, +backtrace_callback (jerry_frame_t *frame_p, void *user_p) { - jerry_value_t *function_p = jerry_backtrace_get_function (frame_p); + jerry_value_t *function_p = jerry_frame_callee (frame_p); if (function_p != NULL) { @@ -11815,7 +11389,7 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, - [jerry_backtrace_capture](#jerry_backtrace_capture) -## jerry_backtrace_get_this +## jerry_frame_this **Summary** @@ -11834,10 +11408,10 @@ after the callback returns. ```c const jerry_value_t * -jerry_backtrace_get_this (jerry_backtrace_frame_t *frame_p); +jerry_frame_this (jerry_frame_t *frame_p); ``` -- `frame_p` - a frame passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback +- `frame_p` - a frame passed to the [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) callback - return value - pointer to the 'this' binding if the binding is available, - NULL otherwise @@ -11851,10 +11425,10 @@ with the following callback function: ```c static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, +backtrace_callback (jerry_frame_t *frame_p, void *user_p) { - jerry_value_t *this_p = jerry_backtrace_get_this (frame_p); + jerry_value_t *this_p = jerry_frame_this (frame_p); if (this_p != NULL) { @@ -11872,7 +11446,7 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, - [jerry_backtrace_capture](#jerry_backtrace_capture) -## jerry_backtrace_is_strict +## jerry_frame_is_strict **Summary** @@ -11885,10 +11459,10 @@ becomes invalid after the callback returns. ```c bool -jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p); +jerry_frame_is_strict (jerry_frame_t *frame_p); ``` -- `frame_p` - a frame passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback +- `frame_p` - a frame passed to the [jerry_backtrace_cb_t](#jerry_backtrace_cb_t) callback - return value - true, if strict mode code is bound to the frame - false, otherwise @@ -11902,10 +11476,10 @@ with the following callback function: ```c static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, +backtrace_callback (jerry_frame_t *frame_p, void *user_p) { - if (jerry_backtrace_is_strict (frame_p)) + if (jerry_frame_is_strict (frame_p)) { printf ("Strict mode code is running"); return true; @@ -11923,18 +11497,17 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, # Miscellaneous functions -## jerry_set_vm_exec_stop_callback +## jerry_halt_cb **Summary** The callback passed to this function is periodically called when JerryScript executes an ECMAScript program. -If the callback returns with undefined value the ECMAScript execution -continues. Otherwise the result is thrown by the engine (if the error -flag is not set for the returned value the engine automatically sets -it). The callback function might be called again even if it threw -an error. In this case the function must throw the same error again. +If the callback returns with undefined value the ECMAScript execution continues. +Otherwise the result is thrown by the engine. The callback function might be +called again even if it threw an exception. In this case the function must throw the +same exception again. To reduce the CPU overhead of constantly checking the termination condition the callback is called when a backward jump is executed @@ -11945,15 +11518,15 @@ only every Nth event (backward jump, etc.) trigger the next check. *Notes*: - This API depends on a build option (`JERRY_VM_EXEC_STOP`) and can be checked in runtime with the `JERRY_FEATURE_VM_EXEC_STOP` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c void -jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, - void *user_p, - uint32_t frequency); +jerry_halt_cb (jerry_halt_cb_t stop_cb, + void *user_p, + uint32_t frequency); ``` - `stop_cb` - periodically called callback (passing NULL disables this feature) @@ -11977,11 +11550,11 @@ vm_exec_stop_callback (void *user_p) while (*countdown_p > 0) { (*countdown_p)--; - return jerry_create_undefined (); + return jerry_undefined (); } - // The error flag is added automatically. - return jerry_create_string ((const jerry_char_t *) "Abort script"); + // The value will be automatically wrapped into an exception. + return jerry_string_sz ("Abort script"); } int @@ -11990,23 +11563,23 @@ main (void) jerry_init (JERRY_INIT_EMPTY); int countdown = 10; - jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16); + jerry_halt_cb (vm_exec_stop_callback, &countdown, 16); // Infinite loop. const jerry_char_t script[] = "while(true) {}"; jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, NULL); - jerry_release_value (jerry_run (parsed_code)); - jerry_release_value (parsed_code); + jerry_value_free (jerry_run (parsed_code)); + jerry_value_free (parsed_code); jerry_cleanup (); } ``` **See also** -- [jerry_vm_exec_stop_callback_t](#jerry_vm_exec_stop_callback_t) +- [jerry_halt_cb_t](#jerry_halt_cb_t) -## jerry_get_resource_name +## jerry_source_name **Summary** @@ -12015,17 +11588,17 @@ Get the resource name (usually a file name) of the currently executed script or This function is typically called from native callbacks. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This feature depends on build option (`JERRY_LINE_INFO`) and can be checked in runtime with the `JERRY_FEATURE_LINE_INFO` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c jerry_value_t -jerry_get_resource_name (jerry_value_t value); +jerry_source_name (jerry_value_t value); ``` - `value` - api value to obtain the resource name from - return string value constructed from @@ -12045,58 +11618,58 @@ jerry_get_resource_name (jerry_value_t value); #include "jerryscript.h" static jerry_value_t -resource_name_handler (const jerry_call_info_t *call_info_p, - const jerry_value_t args_p[], - const jerry_length_t args_count) +source_name_handler (const jerry_call_info_t *call_info_p, + const jerry_value_t args_p[], + const jerry_length_t args_count) { - jerry_value_t undefined_value = jerry_create_undefined (); - jerry_value_t resource_name = jerry_get_resource_name (args_count > 0 ? args_p[0] : undefined_value); - jerry_release_value (undefined_value); + jerry_value_t undefined_value = jerry_undefined (); + jerry_value_t source_name = jerry_source_name (args_count > 0 ? args_p[0] : undefined_value); + jerry_value_free (undefined_value); - return resource_name; -} /* resource_name_handler */ + return source_name; +} /* source_name_handler */ int main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); /* Register the "resourceName" method. */ { - jerry_value_t func = jerry_create_external_function (resource_name_handler); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "resourceName"); - jerry_value_t result = jerry_set_property (global, name, func); - jerry_release_value (result); - jerry_release_value (name); - jerry_release_value (func); + jerry_value_t func = jerry_function_external (source_name_handler); + jerry_value_t name = jerry_string_sz ("resourceName"); + jerry_value_t result = jerry_object_set (global, name, func); + jerry_value_free (result); + jerry_value_free (name); + jerry_value_free (func); } - jerry_release_value (global); + jerry_value_free (global); const jerry_char_t source[] = "function myFunction() { return resourceName() }; myFunction()"; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "demo.js"); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("demo.js"); jerry_value_t program = jerry_parse (source, sizeof (source) - 1, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (!jerry_value_is_error (program)) + if (!jerry_value_is_exception (program)) { /* `run_result` contains "demo.js" */ jerry_value_t run_result = jerry_run (program); /* usage of `run_result` */ - jerry_release_value (run_result); + jerry_value_free (run_result); } - jerry_release_value (program); + jerry_value_free (program); jerry_cleanup (); return 0; @@ -12105,9 +11678,9 @@ main (void) **See also** -- [jerry_create_external_function](#jerry_create_external_function) +- [jerry_function_external](#jerry_function_external) -## jerry_get_user_value +## jerry_source_user_value **Summary** @@ -12116,14 +11689,14 @@ set by the parser when the JERRY_PARSE_HAS_USER_VALUE flag is set in the `option member of the [jerry_parse_options_t](#jerry_parse_options_t) structure. *Notes*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_user_value (const jerry_value_t value); +jerry_source_user_value (const jerry_value_t value); ``` - `value` - script / module / function value which executes ECMAScript code (native modules / functions do not have user value). @@ -12147,22 +11720,22 @@ main (void) const jerry_char_t script[] = "function abc() {} abc"; - jerry_value_t user_value = jerry_create_object (); + jerry_value_t user_value = jerry_object (); jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_USER_VALUE; parse_options.user_value = user_value; jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, &parse_options); - jerry_release_value (user_value); + jerry_value_free (user_value); - /* The jerry_get_user_value returns the object which - * was created by jerry_create_object before. */ + /* The jerry_source_user_value returns the object which + * was created by jerry_object before. */ - user_value = jerry_get_user_value (parsed_code); - jerry_release_value (parsed_code); + user_value = jerry_source_user_value (parsed_code); + jerry_value_free (parsed_code); - jerry_release_value (user_value); + jerry_value_free (user_value); jerry_cleanup (); return 0; } @@ -12174,7 +11747,7 @@ main (void) - [jerry_generate_snapshot](#jerry_generate_snapshot) - [jerry_exec_snapshot](#jerry_exec_snapshot) -## jerry_is_eval_code +## jerry_function_is_dynamic **Summary** @@ -12184,7 +11757,7 @@ Checks whether an ECMAScript code is compiled by eval like (eval, new Function, **Prototype** ```c -bool jerry_is_eval_code (const jerry_value_t value); +bool jerry_function_is_dynamic (const jerry_value_t value); ``` - `value` - script / module / function value which executes ECMAScript code - return @@ -12209,14 +11782,14 @@ main (void) jerry_value_t script_value = jerry_parse (script, sizeof (script) - 1, NULL); jerry_value_t function_value = jerry_run (script_value); - jerry_release_value (script_value); + jerry_value_free (script_value); - if (jerry_is_eval_code (function_value)) + if (jerry_function_is_dynamic (function_value)) { /* Code enters here. */ } - jerry_release_value (function_value); + jerry_value_free (function_value); jerry_cleanup (); return 0; } @@ -12228,7 +11801,7 @@ main (void) - [jerry_generate_snapshot](#jerry_generate_snapshot) - [jerry_exec_snapshot](#jerry_exec_snapshot) -## jerry_get_source_info +## jerry_source_info **Summary** @@ -12236,16 +11809,16 @@ Returns a newly created source info structure corresponding to the passed script The function is lower level than `toString()` operation, but provides more contextual information. *Notes*: -- Returned value must be freed with [jerry_free_source_info](#jerry_free_source_info) when it +- Returned value must be freed with [jerry_source_info_free](#jerry_source_info_free) when it is no longer needed. - This API depends on a build option (`JERRY_FUNCTION_TO_STRING`) and can be checked in runtime with the `JERRY_FEATURE_FUNCTION_TO_STRING` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -jerry_source_info_t *jerry_get_source_info (const jerry_value_t value); +jerry_source_info_t *jerry_source_info (const jerry_value_t value); ``` - `value` - script / module / function value which executes JavaScript code (native modules / functions do not have source info). @@ -12271,15 +11844,15 @@ main (void) jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, NULL); - jerry_source_info_t *source_info_p = jerry_get_source_info (parsed_code); - jerry_release_value (parsed_code); + jerry_source_info_t *source_info_p = jerry_source_info (parsed_code); + jerry_value_free (parsed_code); if (source_info_p != NULL) { - /* Check the information provided by jerry_get_source_info. */ + /* Check the information provided by jerry_source_info. */ } - jerry_free_source_info (source_info_p); + jerry_source_info_free (source_info_p); jerry_cleanup (); return 0; @@ -12288,36 +11861,36 @@ main (void) **See also** -- [jerry_free_source_info](#jerry_free_source_info) +- [jerry_source_info_free](#jerry_source_info_free) - [jerry_source_info_t](#jerry_source_info_t) -## jerry_free_source_info +## jerry_source_info_free **Summary** -Frees the the source info structure returned by [jerry_get_source_info](#jerry_get_source_info). +Frees the the source info structure returned by [jerry_source_info](#jerry_source_info). *Notes*: - This API depends on a build option (`JERRY_FUNCTION_TO_STRING`) and can be checked in runtime with the `JERRY_FEATURE_FUNCTION_TO_STRING` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** ```c -void jerry_free_source_info (jerry_source_info_t *source_info_p) +void jerry_source_info_free (jerry_source_info_t *source_info_p) ``` -- `source_info_p` - source info structure returned by [jerry_get_source_info](#jerry_get_source_info) +- `source_info_p` - source info structure returned by [jerry_source_info](#jerry_source_info) *New in version [[NEXT_RELEASE]]*. **Example** -See [jerry_get_source_info](#jerry_get_source_info) +See [jerry_source_info](#jerry_source_info) **See also** -- [jerry_get_source_info](#jerry_get_source_info) +- [jerry_source_info](#jerry_source_info) - [jerry_source_info_t](#jerry_source_info_t) @@ -12336,7 +11909,7 @@ by the application (i.e. the gc must not reclaim it). This is also true to the returned previously active realm, so there is no need to free the value after the restoration. The function can only fail if realms are not supported or the passed argument is not a realm. In this case the returned exception must -be freed by [jerry_release_value](#jerry_release_value). +be freed by [jerry_value_free](#jerry_value_free). This function is useful to parse a script, create a native function, load a snapshot or create an exception in another realm. Each ECMAScript code runs in the realm @@ -12345,7 +11918,7 @@ which was active when the code was parsed or loaded regardless of the current re *Notes*: - This feature depends on build option (`JERRY_BUILTIN_REALMS`) and can be checked in runtime with the `JERRY_FEATURE_REALM` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -12365,7 +11938,7 @@ jerry_set_realm (jerry_value_t realm_value); ```c { - jerry_value_t realm_value = jerry_create_realm (); + jerry_value_t realm_value = jerry_realm (); jerry_value_t old_realm = jerry_set_realm (realm_value); @@ -12377,9 +11950,9 @@ jerry_set_realm (jerry_value_t realm_value); **See also** -- [jerry_create_realm](#jerry_create_realm) +- [jerry_realm](#jerry_realm) -## jerry_realm_get_this +## jerry_realm_this **Summary** @@ -12390,18 +11963,18 @@ changed by [jerry_realm_set_this](#jerry_realm_set_this). *Notes*: - This feature depends on build option (`JERRY_BUILTIN_REALMS`) and can be checked in runtime with the `JERRY_FEATURE_REALM` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c jerry_value_t -jerry_realm_get_this (jerry_value_t realm_value) +jerry_realm_this (jerry_value_t realm_value) ``` - `realm_value` - realm value - return - - type error - if realm_value is not a realm + - type error exception- if realm_value is not a realm - 'this' binding object - otherwise *New in version 2.4*. @@ -12410,20 +11983,20 @@ jerry_realm_get_this (jerry_value_t realm_value) ```c { - jerry_value_t realm_value = jerry_create_realm (); + jerry_value_t realm_value = jerry_realm (); - jerry_value_t this_value = jerry_realm_get_this (realm_value); + jerry_value_t this_value = jerry_realm_this (realm_value); ... // usage of the this_value - jerry_release_value (this_value); - jerry_release_value (realm_value); + jerry_value_free (this_value); + jerry_value_free (realm_value); } ``` **See also** -- [jerry_create_realm](#jerry_create_realm) +- [jerry_realm](#jerry_realm) - [jerry_realm_set_this](#jerry_realm_set_this) ## jerry_realm_set_this @@ -12436,7 +12009,7 @@ any script on the realm. Otherwise the operation is undefined. *Notes*: - This feature depends on build option (`JERRY_BUILTIN_REALMS`) and can be checked in runtime with the `JERRY_FEATURE_REALM` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** @@ -12448,7 +12021,7 @@ jerry_realm_set_this (jerry_value_t realm_value, jerry_value_t this_value) - `realm_value` - realm value - `this_value` - new this value - return - - type error - if realm_value is not a realm or this_value is not object + - type error exception- if realm_value is not a realm or this_value is not object - true - otherwise *New in version 2.4*. @@ -12457,11 +12030,11 @@ jerry_realm_set_this (jerry_value_t realm_value, jerry_value_t this_value) ```c { - jerry_value_t realm_value = jerry_create_realm (); + jerry_value_t realm_value = jerry_realm (); jerry_value_t old_realm = jerry_set_realm (realm_value); /* The prototype of the object comes from the new realm. */ - jerry_value_t this_value = jerry_create_object (); + jerry_value_t this_value = jerry_object (); jerry_set_realm (old_realm); jerry_value_t result = jerry_realm_set_this (realm_value, this_value); @@ -12472,15 +12045,15 @@ jerry_realm_set_this (jerry_value_t realm_value, jerry_value_t this_value) **See also** -- [jerry_create_realm](#jerry_create_realm) +- [jerry_realm](#jerry_realm) - [jerry_set_realm](#jerry_set_realm) -- [jerry_realm_get_this](#jerry_realm_get_this) +- [jerry_realm_this](#jerry_realm_this) # ArrayBuffer and TypedArray functions These APIs all depend on the es.next profile. -## jerry_get_arraybuffer_byte_length +## jerry_arraybuffer_size **Summary** @@ -12491,7 +12064,7 @@ same value which was passed to the ArrayBuffer constructor call. ```c jerry_length_t -jerry_get_arraybuffer_byte_length (const jerry_value_t value); +jerry_arraybuffer_size (const jerry_value_t value); ``` - `value` - ArrayBuffer object @@ -12505,16 +12078,16 @@ jerry_get_arraybuffer_byte_length (const jerry_value_t value); ```c { - jerry_value_t buffer = jerry_create_arraybuffer (15); - jerry_length_t length = jerry_get_arraybuffer_byte_length (buffer); + jerry_value_t buffer = jerry_arraybuffer (15); + jerry_length_t length = jerry_arraybuffer_size (buffer); // length should be 15 - jerry_release_value (buffer); + jerry_value_free (buffer); } ``` **See also** -- [jerry_create_arraybuffer](#jerry_create_arraybuffer) +- [jerry_arraybuffer](#jerry_arraybuffer) ## jerry_arraybuffer_read @@ -12559,7 +12132,7 @@ jerry_arraybuffer_read (const jerry_value_t value, { uint8_t data[20]; jerry_value_t buffer; - // ... create the ArrayBuffer or acquire it from somewhere. + // ... create the ArrayBuffer or copy it from somewhere. jerry_value_t bytes_read; @@ -12570,15 +12143,15 @@ jerry_arraybuffer_read (const jerry_value_t value, // process the data variable - jerry_release_value (buffer); + jerry_value_free (buffer); } ``` **See also** -- [jerry_create_arraybuffer](#jerry_create_arraybuffer) +- [jerry_arraybuffer](#jerry_arraybuffer) - [jerry_arraybuffer_write](#jerry_arraybuffer_write) -- [jerry_get_arraybuffer_byte_length](#jerry_get_arraybuffer_byte_length) +- [jerry_arraybuffer_size](#jerry_arraybuffer_size) ## jerry_arraybuffer_write @@ -12630,7 +12203,7 @@ jerry_arraybuffer_write (const jerry_value_t value, } jerry_value_t buffer; - // ... create the ArrayBuffer or acquire it from somewhere. + // ... create the ArrayBuffer or copy it from somewhere. jerry_value_t bytes_written; @@ -12641,18 +12214,18 @@ jerry_arraybuffer_write (const jerry_value_t value, // use the ArrayBuffer - jerry_release_value (buffer); + jerry_value_free (buffer); } ``` **See also** -- [jerry_create_arraybuffer](#jerry_create_arraybuffer) +- [jerry_arraybuffer](#jerry_arraybuffer) - [jerry_arraybuffer_write](#jerry_arraybuffer_write) -- [jerry_get_arraybuffer_byte_length](#jerry_get_arraybuffer_byte_length) +- [jerry_arraybuffer_size](#jerry_arraybuffer_size) -## jerry_get_arraybuffer_pointer +## jerry_arraybuffer_data **Summary** @@ -12661,15 +12234,15 @@ The function allows access to the contents of the Array Buffer directly. **WARNING!** This operation is for expert use only! The programmer must ensure that the returned memory area is used correctly. That is there is no out of bounds reads or writes. The lifetime of the underlying -data buffer is managed by the ArrayBuffer value. Make sure to acquire the -value with [`jerry_acquire_value`](#jerry_acquire_value) if the data +data buffer is managed by the ArrayBuffer value. Make sure to copy the +value with [`jerry_value_copy`](#jerry_value_copy) if the data buffer is needed later. **Prototype** ```c uint8_t * -jerry_get_arraybuffer_pointer (const jerry_value_t value); +jerry_arraybuffer_data (const jerry_value_t value); ``` - `value` - Array Buffer object. @@ -12686,9 +12259,9 @@ jerry_get_arraybuffer_pointer (const jerry_value_t value); ```c { // create the ArrayBuffer - jerry_value_t buffer = jerry_create_arraybuffer (16); + jerry_value_t buffer = jerry_arraybuffer (16); - uint8_t *const data = jerry_get_arraybuffer_pointer (buffer); + uint8_t *const data = jerry_arraybuffer_data (buffer); for (int i = 0; i < 16; i++) { @@ -12698,15 +12271,15 @@ jerry_get_arraybuffer_pointer (const jerry_value_t value); // use the Array Buffer // release buffer as it is not needed after this point - jerry_release_value (buffer); + jerry_value_free (buffer); } ``` **See also** -- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external) +- [jerry_arraybuffer_external](#jerry_arraybuffer_external) -## jerry_is_arraybuffer_detachable +## jerry_arraybuffer_is_detachable **Summary** @@ -12716,13 +12289,13 @@ Get if the ArrayBuffer is detachable. ```c jerry_value_t -jerry_is_arraybuffer_detachable (const jerry_value_t value); +jerry_arraybuffer_is_detachable (const jerry_value_t value); ``` - `value` - ArrayBuffer to be detached - return - boolean value if success - - Error otherwise + - exception otherwise *New in version 2.2*. @@ -12731,43 +12304,43 @@ jerry_is_arraybuffer_detachable (const jerry_value_t value); ```c { // create the ArrayBuffer - jerry_value_t buffer = jerry_create_arraybuffer (16); + jerry_value_t buffer = jerry_arraybuffer (16); - jerry_value_t res = jerry_is_arraybuffer_detachable (buffer); + jerry_value_t res = jerry_arraybuffer_is_detachable (buffer); bool is_detachable = jerry_value_is_true (res); // release buffer as it is not needed after this point - jerry_release_value (res); - jerry_release_value (buffer); + jerry_value_free (res); + jerry_value_free (buffer); } ``` **See also** -- [jerry_detach_arraybuffer](#jerry_detach_arraybuffer) +- [jerry_arraybuffer_detach](#jerry_arraybuffer_detach) -## jerry_detach_arraybuffer +## jerry_arraybuffer_detach **Summary** Detach the underlying data block from ArrayBuffer and set its bytelength to 0. -This operation requires the ArrayBuffer to be external that created by -`jerry_create_arraybuffer_external`. +This operation requires the ArrayBuffer to be an external buffer created by +`jerry_arraybuffer_external`. **Prototype** ```c jerry_value_t -jerry_detach_arraybuffer (const jerry_value_t value); +jerry_arraybuffer_detach (const jerry_value_t value); ``` -*Note*: If the ArrayBuffer has been created with `jerry_create_arraybuffer_external` the optional free callback is called on a successful detach operation +*Note*: If the ArrayBuffer has been created with `jerry_arraybuffer_external` the optional free callback is called on a successful detach operation - `value` - ArrayBuffer to be detached - return - null value if success - - Error otherwise + - exception otherwise *New in version 2.2*. @@ -12778,19 +12351,19 @@ jerry_detach_arraybuffer (const jerry_value_t value); uint8_t buf[1]; jerry_size_t length = 1; // create the ArrayBuffer - jerry_value_t buffer = jerry_create_arraybuffer (length, buf, NULL); + jerry_value_t buffer = jerry_arraybuffer (length, buf, NULL); - jerry_value_t res = jerry_detach_arraybuffer (buffer); + jerry_value_t res = jerry_arraybuffer_detach (buffer); // release buffer as it is not needed after this point - jerry_release_value (res); - jerry_release_value (buffer); + jerry_value_free (res); + jerry_value_free (buffer); } ``` **See also** -- [jerry_is_arraybuffer_detachable](#jerry_is_arraybuffer_detachable) +- [jerry_arraybuffer_is_detachable](#jerry_arraybuffer_is_detachable) ## jerry_arraybuffer_has_buffer @@ -12801,7 +12374,7 @@ Checks whether a buffer is currently allocated for an array buffer or typed arra *Notes*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). **Prototype** @@ -12829,7 +12402,7 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t array_buffer_value = jerry_create_arraybuffer (1024 * 1024); + jerry_value_t array_buffer_value = jerry_arraybuffer (1024 * 1024); /* By default, the backing store of large array buffers * is allocated when it is used the first time. */ @@ -12839,7 +12412,7 @@ main (void) /* Code enters here in this case. */ } - jerry_release_value (array_buffer_value); + jerry_value_free (array_buffer_value); jerry_cleanup (); return 0; @@ -12848,12 +12421,12 @@ main (void) **See also** -- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external) -- [jerry_create_shared_arraybuffer_external](#jerry_create_shared_arraybuffer_external) -- [jerry_arraybuffer_set_compact_allocation_limit](#jerry_arraybuffer_set_compact_allocation_limit) -- [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- [jerry_arraybuffer_external](#jerry_arraybuffer_external) +- [jerry_shared_arraybuffer_external](#jerry_shared_arraybuffer_external) +- [jerry_arraybuffer_heap_allocation_limit](#jerry_arraybuffer_heap_allocation_limit) +- [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) -## jerry_arraybuffer_set_compact_allocation_limit +## jerry_arraybuffer_heap_allocation_limit **Summary** @@ -12865,7 +12438,7 @@ are not called for these array buffers. *Notes*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The default limit is 256 bytes. - When an array buffer is allocated in a single memory block, its backing store is not freed when the array buffer is detached. @@ -12876,7 +12449,7 @@ are not called for these array buffers. ```c void -jerry_arraybuffer_set_compact_allocation_limit (const jerry_length_t allocation_limit); +jerry_arraybuffer_heap_allocation_limit (const jerry_length_t allocation_limit); ``` - `allocation_limit` - maximum size of compact allocation. @@ -12895,9 +12468,9 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_arraybuffer_set_compact_allocation_limit (1); + jerry_arraybuffer_heap_allocation_limit (1); - jerry_value_t array_buffer_value = jerry_create_arraybuffer (1); + jerry_value_t array_buffer_value = jerry_arraybuffer (1); if (jerry_arraybuffer_has_buffer (array_buffer_value)) { @@ -12905,9 +12478,9 @@ main (void) * is allocated during buffer creation. */ } - jerry_release_value (array_buffer_value); + jerry_value_free (array_buffer_value); - array_buffer_value = jerry_create_arraybuffer (2); + array_buffer_value = jerry_arraybuffer (2); if (jerry_arraybuffer_has_buffer (array_buffer_value)) { @@ -12915,7 +12488,7 @@ main (void) * is allocated when it is used the first time. */ } - jerry_release_value (array_buffer_value); + jerry_value_free (array_buffer_value); jerry_cleanup (); return 0; @@ -12925,9 +12498,9 @@ main (void) **See also** - [jerry_arraybuffer_has_buffer](#jerry_arraybuffer_has_buffer) -- [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) -## jerry_arraybuffer_set_allocator_callbacks +## jerry_arraybuffer_allocator_cb **Summary** @@ -12936,7 +12509,7 @@ Set callbacks for allocating and freeing backing stores for array buffer objects *Notes*: - This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value, - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - This function is recommended to be called after [jerry_init](#jerry_init) before any array buffer is allocated. - The callbacks can be NULL to use the default callbacks. The default `allocate_callback` @@ -12948,9 +12521,9 @@ Set callbacks for allocating and freeing backing stores for array buffer objects ```c void -jerry_arraybuffer_set_allocator_callbacks (jerry_arraybuffer_allocate_t allocate_callback, - jerry_arraybuffer_free_t free_callback, - void *user_p) +jerry_arraybuffer_allocator_cb (jerry_arraybuffer_allocate_cb_t allocate_callback, + jerry_arraybuffer_free_cb_t free_callback, + void *user_p) ``` - `allocate_callback` - callback for allocating array buffer memory. @@ -12992,20 +12565,20 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_arraybuffer_set_allocator_callbacks (NULL, array_buffer_free_cb, NULL); + jerry_arraybuffer_allocator_cb (NULL, array_buffer_free_cb, NULL); /* The buffer of the array buffer object is allocated by the default * allocator using jerry_heap_alloc and freed by array_buffer_free_cb. */ const jerry_char_t script[] = "var result = new uint32Array(1024); result[0] = 1; result"; jerry_value_t array_buffer_value = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); - jerry_release_value (array_buffer_value); + jerry_value_free (array_buffer_value); /* The buffer of the array buffer object has a non-NULL * arraybuffer_user_p value, so it is not freed by array_buffer_free_cb. */ - array_buffer_value = jerry_create_arraybuffer_external (sizeof (global_buffer), global_buffer, global_buffer); - jerry_release_value (array_buffer_value); + array_buffer_value = jerry_arraybuffer_external (global_buffer, sizeof (global_buffer), global_buffer); + jerry_value_free (array_buffer_value); jerry_cleanup (); return 0; @@ -13015,9 +12588,9 @@ main (void) **See also** - [jerry_arraybuffer_has_buffer](#jerry_arraybuffer_has_buffer) -- [jerry_arraybuffer_set_allocator_callbacks](#jerry_arraybuffer_set_allocator_callbacks) +- [jerry_arraybuffer_allocator_cb](#jerry_arraybuffer_allocator_cb) -## jerry_get_dataview_buffer +## jerry_dataview_buffer **Summary** @@ -13025,16 +12598,16 @@ Get the ArrayBuffer object used by a DataView object. Additionally returns the byteLength and byteOffset properties of the DataView object. -For the returned ArrayBuffer the [jerry_release_value](#jerry_release_value) +For the returned ArrayBuffer the [jerry_value_free](#jerry_value_free) must be called when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_dataview_buffer (const jerry_value_t value, - jerry_length_t *byteOffset, - jerry_length_t *byteLength); +jerry_dataview_buffer (const jerry_value_t value, + jerry_length_t *byteOffset, + jerry_length_t *byteLength); ``` - `value` - DataView to get the ArrayBuffer from @@ -13058,11 +12631,11 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t arraybuffer = jerry_create_arraybuffer (16); - jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 16); + jerry_value_t arraybuffer = jerry_arraybuffer (16); + jerry_value_t dataview = jerry_dataview (arraybuffer, 0, 16); jerry_length_t byteOffset = 0; jerry_length_t byteLength = 0; - jerry_value_t buffer = jerry_get_dataview_buffer (dataview, &byteOffset, &byteLength); + jerry_value_t buffer = jerry_dataview_buffer (dataview, &byteOffset, &byteLength); // buffer is an ArrayBuffer object and ArrayBuffer operations can be performed on it // byteOffset is 0 @@ -13070,9 +12643,9 @@ main (void) // usage of buffer - jerry_release_value (buffer); - jerry_release_value (dataview); - jerry_release_value (arraybuffer); + jerry_value_free (buffer); + jerry_value_free (dataview); + jerry_value_free (arraybuffer); jerry_cleanup (); } @@ -13080,10 +12653,10 @@ main (void) **See also** -- [jerry_create_dataview](#jerry_create_dataview) +- [jerry_dataview](#jerry_dataview) -## jerry_get_typedarray_type +## jerry_typedarray_type **Summary** @@ -13096,7 +12669,7 @@ enum value. ```c jerry_typedarray_type_t -jerry_get_typedarray_type (jerry_value_t value); +jerry_typedarray_type (jerry_value_t value); ``` - `value` - TypedArray object to query for type. @@ -13111,23 +12684,23 @@ jerry_get_typedarray_type (jerry_value_t value); ```c { jerry_typedarray_type_t expected_type = JERRY_TYPEDARRAY_UINT32; - jerry_value_t typedarray = jerry_create_typedarray (expected_class, 25); + jerry_value_t typedarray = jerry_typedarray (expected_class, 25); - jerry_typedarray_type_t type = jerry_get_typedarray_type (typedarray); + jerry_typedarray_type_t type = jerry_typedarray_type (typedarray); // 'type' is now JERRY_TYPEDARRAY_UINT32 - jerry_release_value (typedarray); + jerry_value_free (typedarray); } ``` **See also** -- [jerry_create_typedarray](#jerry_create_typedarray) +- [jerry_typedarray](#jerry_typedarray) - [jerry_typedarray_type_t](#jerry_typedarray_type_t) -## jerry_get_typedarray_length +## jerry_typedarray_length **Summary** @@ -13139,7 +12712,7 @@ This is not the same as the byteLength property of a TypedArray object. ``` jerry_length_t -jerry_get_typedarray_length (jerry_value_t value); +jerry_typedarray_length (jerry_value_t value); ``` - `value` - TypedArray object to query @@ -13153,22 +12726,22 @@ jerry_get_typedarray_length (jerry_value_t value); ```c { - jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_INT32, 21); + jerry_value_t array = jerry_typedarray (JERRY_TYPEDARRAY_INT32, 21); - jerry_length_t element_count = jerry_get_typedarray_length (array); + jerry_length_t element_count = jerry_typedarray_length (array); // element_count is now 21. - jerry_release_value (array); + jerry_value_free (array); } ``` **See also** -- [jerry_create_typedarray](#jerry_create_typedarray) +- [jerry_typedarray](#jerry_typedarray) -## jerry_get_typedarray_buffer +## jerry_typedarray_buffer **Summary** @@ -13176,19 +12749,19 @@ Get the ArrayBuffer object used by a TypedArray object. Additionally returns the byteLength and byteOffset properties of the TypedArray object. -For the returned ArrayBuffer the [jerry_release_value](#jerry_release_value) +For the returned ArrayBuffer the [jerry_value_free](#jerry_value_free) must be called. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** ```c jerry_value_t -jerry_get_typedarray_buffer (jerry_value_t value, - jerry_length_t *byteOffset, - jerry_length_t *byteLength); +jerry_typedarray_buffer (jerry_value_t value, + jerry_length_t *byteOffset, + jerry_length_t *byteLength); ``` - `value` - TypedArray to get the ArrayBuffer from @@ -13204,24 +12777,24 @@ jerry_get_typedarray_buffer (jerry_value_t value, ```c { - jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_INT16, 11); + jerry_value_t array = jerry_typedarray (JERRY_TYPEDARRAY_INT16, 11); jerry_length_t byteLength = 0; jerry_length_t byteOffset = 0; - jerry_value_t buffer = jerry_get_typedarray_buffer (array, &byteOffset, &byteLength); + jerry_value_t buffer = jerry_typedarray_buffer (array, &byteOffset, &byteLength); // buffer is an ArrayBuffer object and ArrayBuffer operations can be performed on it - // byteLength is 11 * 2 (2 as the TypedArray stores Int16 that is 2 byte elements) + // byteLength is 11 * 2 (2 as the TypedArray stores Int16 that is 2 byte elements) // byteOffset is 0 - jerry_release_value (buffer); - jerry_release_value (array); + jerry_value_free (buffer); + jerry_value_free (array); } ``` **See also** -- [jerry_create_typedarray](#jerry_create_typedarray) +- [jerry_typedarray](#jerry_typedarray) # JSON functions @@ -13229,10 +12802,10 @@ jerry_get_typedarray_buffer (jerry_value_t value, **Summary** -Parses a JSON string creating a JavaScript value. The behaviour is equivalent with +Parses a CESU-8 or UTF-8 encoded string as a JSON string, creating a JavaScript value. The behaviour is equivalent with the "JSON.parse(string)" JS call. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -13247,7 +12820,7 @@ jerry_json_parse (const jerry_char_t *string_p, - `string_size` - size of the string. - return - `jerry_value_t` containing a JavaScript value. - - Error value in case of any parse error. + - exception value in case of any parse error. *New in version 2.0*. @@ -13269,7 +12842,7 @@ main (void) /* "obj" now contains and object created from the "data" JSON string. */ - jerry_release_value (obj); + jerry_value_free (obj); /* Cleanup engine */ jerry_cleanup (); @@ -13285,7 +12858,7 @@ main (void) Create a JSON string value from a JavaScript value. The behaviour is equivalent with the "JSON.stringify(input_value)" JS call. -*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +*Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. **Prototype** @@ -13298,7 +12871,7 @@ jerry_json_stringify (const jerry_value_t input_value); - `input_value` - a `jerry_value_t` to stringify. - return - `jerry_value_t` containing a JSON string. - - Error value in case of any stringification error. + - exception value in case of any stringification error. *New in version 2.0*. @@ -13315,21 +12888,21 @@ main (void) /* Initialize engine */ jerry_init (JERRY_INIT_EMPTY); - jerry_value_t obj = jerry_create_object (); + jerry_value_t obj = jerry_object (); { - jerry_value_t key = jerry_create_string ((const jerry_char_t *) "name"); - jerry_value_t value = jerry_create_string ((const jerry_char_t *) "John"); - jerry_release_value (jerry_set_property (obj, key, value)); - jerry_release_value (key); - jerry_release_value (value); + jerry_value_t key = jerry_string_sz ("name"); + jerry_value_t value = jerry_string_sz ("John"); + jerry_value_free (jerry_object_set (obj, key, value)); + jerry_value_free (key); + jerry_value_free (value); } jerry_value_t stringified = jerry_json_stringify (obj); /* "stringified" now contains a JSON string */ - jerry_release_value (stringified); - jerry_release_value (obj); + jerry_value_free (stringified); + jerry_value_free (obj); /* Cleanup engine */ jerry_cleanup (); @@ -13340,7 +12913,7 @@ main (void) # Container Functions -## jerry_get_array_from_container +## jerry_container_to_array **Summary** @@ -13352,7 +12925,7 @@ if the container object contains key-value structure and false if not. - This API function depends on a build option (`JERRY_BUILTIN_CONTAINER`) and can be checked runtime with the `JERRY_FEATURE_MAP, JERRY_FEATURE_SET, JERRY_FEATURE_WEAKMAP, JERRY_FEATURE_WEAKSET` feature enum values. - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. *New in version [[NEXT_RELEASE]]*. @@ -13361,15 +12934,15 @@ if the container object contains key-value structure and false if not. ```c jerry_value_t -jerry_get_array_from_container(jerry_value_t value, - bool *is_key_value_p); +jerry_container_to_array(jerry_value_t value, + bool *is_key_value_p); ``` - `value` - Map/Set or iterator object - `is_key_value` - Will be set to `true` if the given container has key-value pairs, `false` otherwise. - return value - jerry_value_t containing an array of values from the Map/Set or iterator object - - Error if the `value` is nor a Container or a Container Iterator. + - exception if the `value` is nor a Container or a Container Iterator. - `undefined` if the `value` is undefined/null. **Example** @@ -13386,15 +12959,15 @@ main (void) jerry_value_t iterable = jerry_eval (src, sizeof (src) - 1, JERRY_PARSE_NO_OPTS); bool is_key_value_container = false; - jerry_value_t buffer_from_map = jerry_get_array_from_container (iterable, &is_key_value_container); + jerry_value_t buffer_from_map = jerry_container_to_array (iterable, &is_key_value_container); /* The buffer_from_map contains two elements: 1 and 2, which is the key/value pair of the only item in the set. is_key_value set to true, as the original is a key-value structure (a Map Iterator) */ - jerry_release_value (iterable); - jerry_release_value (buffer_from_map); + jerry_value_free (iterable); + jerry_value_free (buffer_from_map); jerry_cleanup (); @@ -13404,33 +12977,33 @@ main (void) **See also** -- [jerry_create_container](#jerry_create_container) +- [jerry_container](#jerry_container) - [jerry_container_type_t](#jerry_container_type_t) -## jerry_container_operation +## jerry_container_op **Summary** Perform container operation on the given operands (add, delete, set, etc.). *Note*: -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. - This API function depends on a build option (`JERRY_BUILTIN_CONTAINER`) and can be checked runtime with the `JERRY_FEATURE_MAP` , `JERRY_FEATURE_SET` , `JERRY_FEATURE_WEAKMAP` , `JERRY_FEATURE_WEAKSET` feature enum values. - see: [jerry_is_feature_enabled](#jerry_is_feature_enabled). + see: [jerry_feature_enabled](#jerry_feature_enabled). - The es.next profile enables this by default. **Prototype** ```c jerry_value_t -jerry_container_operation (jerry_container_operation_t operation, - jerry_value_t container, - jerry_value_t *arguments, - uint32_t arguments_number) +jerry_container_op (jerry_container_op_t operation, + jerry_value_t container, + jerry_value_t *arguments, + uint32_t arguments_number) ``` - `operation` - container operation @@ -13438,7 +13011,7 @@ jerry_container_operation (jerry_container_operation_t operation, - `arguments` - array of arguments - `arguments_number` - number of arguments - result if the operation is successful - - error, otherwise + - exception, otherwise *New in version [[NEXT_RELEASE]]*. @@ -13454,23 +13027,23 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t map = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); - jerry_value_t key_str = jerry_create_string ((jerry_char_t *) "number"); - jerry_value_t number = jerry_create_number (10); + jerry_value_t map = jerry_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); + jerry_value_t key_str = jerry_string_sz ("number"); + jerry_value_t number = jerry_number (10); jerry_value_t args[2] = {key_str, number}; - jerry_value_t result = jerry_container_operation (JERRY_CONTAINER_OP_SET, map, args, 2); - jerry_release_value (result); + jerry_value_t result = jerry_container_op (JERRY_CONTAINER_OP_SET, map, args, 2); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_CLEAR, map, NULL, 0); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_CLEAR, map, NULL, 0); + jerry_value_free (result); - jerry_release_value (map); - jerry_release_value (key_str); - jerry_release_value (number); + jerry_value_free (map); + jerry_value_free (key_str); + jerry_value_free (number); jerry_cleanup (); return 0; @@ -13479,5 +13052,5 @@ main (void) **See also** -- [jerry_create_container](#jerry_create_container) +- [jerry_container](#jerry_container) - [jerry_container_type_t](#jerry_container_type_t) diff --git a/docs/03.API-EXAMPLE.md b/docs/03.API-EXAMPLE.md index 60f297cbdd..6a07c8a198 100644 --- a/docs/03.API-EXAMPLE.md +++ b/docs/03.API-EXAMPLE.md @@ -35,47 +35,14 @@ Test if the `pkg-config` works for JerryScript: $ pkg-config --cflags --libs libjerry-core libjerry-port-default libjerry-ext libjerry-math ``` -## Example 1. Execute JavaScript from your application - -The most basic example to test the engine is to create an `api-example-1.c` file containing the following code: - -[doctest]: # () - -```c -#include "jerryscript.h" - -int -main (void) -{ - const jerry_char_t script[] = "var str = 'Hello, World!';"; - - bool ret_value = jerry_run_simple (script, sizeof (script) - 1, JERRY_INIT_EMPTY); - - return (ret_value ? 0 : 1); -} -``` - -To compile it one can use the following command: - -```sh -$ gcc api-example-1.c -o api-example-1 $(pkg-config --cflags --libs libjerry-core libjerry-port-default libjerry-math) -``` - -If everything is correct the application returns with a zero exit code: - -``` -$ ./api-example-1 -$ echo $? -``` - ## Example 2. Split engine initialization and script execution. In this example the engine is initialized directly with the `jerry_init` method and cleaned up with the `jerry_cleanup` method. The example JavaScript code is directly parsed and executed via the `jerry_eval` method. Each `jerry_value_t` -returned by the API methods is freed with the `jerry_release_value` method. +returned by the API methods is freed with the `jerry_value_free` method. -To make sure that the code parsing and execution was ok, the `jerry_value_is_error` +To make sure that the code parsing and execution was ok, the `jerry_value_is_exception` method is used to check for any errors. Use the following code for the `api-example-2.c` file: @@ -103,10 +70,10 @@ main (void) JERRY_PARSE_NO_OPTS); /* Check if there was any error (syntax or runtime) */ - bool run_ok = !jerry_value_is_error (eval_ret); + bool run_ok = !jerry_value_is_exception (eval_ret); /* Parsed source code must be freed */ - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); /* Cleanup engine */ jerry_cleanup (); @@ -156,20 +123,20 @@ main (void) jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, NULL); /* Check if there is any JS code parse error */ - if (!jerry_value_is_error (parsed_code)) + if (!jerry_value_is_exception (parsed_code)) { /* Execute the parsed source code in the Global scope */ jerry_value_t ret_value = jerry_run (parsed_code); /* Check the execution return value if there is any error */ - run_ok = !jerry_value_is_error (ret_value); + run_ok = !jerry_value_is_exception (ret_value); /* Returned value must be freed */ - jerry_release_value (ret_value); + jerry_value_free (ret_value); } /* Parsed source code must be freed */ - jerry_release_value (parsed_code); + jerry_value_free (parsed_code); /* Cleanup engine */ jerry_cleanup (); @@ -200,10 +167,10 @@ In this example a very simple "print" method is added which prints out a static This method will be implemented in C and will be called from the JavaScript code. For this a few extra API methods are required: -- `jerry_get_global_object` -- `jerry_create_string` -- `jerry_set_property` -- `jerry_create_external_function` +- `jerry_current_realm` +- `jerry_string_sz` +- `jerry_object_set` +- `jerry_function_external` The `api-example-4.c` file should contain the following code: @@ -223,7 +190,7 @@ print_handler (const jerry_call_info_t *call_info_p, printf ("Print handler was called\n"); /* Return an "undefined" value to the JavaScript engine */ - return jerry_create_undefined (); + return jerry_undefined (); } int @@ -238,40 +205,40 @@ main (void) /* Add the "print" method for the JavaScript global object */ { /* Get the "global" object */ - jerry_value_t global_object = jerry_get_global_object (); + jerry_value_t global_object = jerry_current_realm (); /* Create a "print" JS string */ - jerry_value_t property_name_print = jerry_create_string ((const jerry_char_t *) "print"); + jerry_value_t property_name_print = jerry_string_sz ("print"); /* Create a function from a native C method (this function will be called from JS) */ - jerry_value_t property_value_func = jerry_create_external_function (print_handler); + jerry_value_t property_value_func = jerry_function_external (print_handler); /* Add the "print" property with the function value to the "global" object */ - jerry_value_t set_result = jerry_set_property (global_object, property_name_print, property_value_func); + jerry_value_t set_result = jerry_object_set (global_object, property_name_print, property_value_func); /* Check if there was no error when adding the property (in this case it should never happen) */ - if (jerry_value_is_error (set_result)) { + if (jerry_value_is_exception (set_result)) { printf ("Failed to add the 'print' property\n"); } /* Release all jerry_value_t-s */ - jerry_release_value (set_result); - jerry_release_value (property_value_func); - jerry_release_value (property_name_print); - jerry_release_value (global_object); + jerry_value_free (set_result); + jerry_value_free (property_value_func); + jerry_value_free (property_name_print); + jerry_value_free (global_object); } /* Setup Global scope code */ jerry_value_t parsed_code = jerry_parse (script, script_size, NULL); - if (!jerry_value_is_error (parsed_code)) + if (!jerry_value_is_exception (parsed_code)) { /* Execute the parsed source code in the Global scope */ jerry_value_t ret_value = jerry_run (parsed_code); /* Returned value must be freed */ - jerry_release_value (ret_value); + jerry_value_free (ret_value); } /* Parsed source code must be freed */ - jerry_release_value (parsed_code); + jerry_value_free (parsed_code); /* Cleanup engine */ jerry_cleanup (); @@ -304,7 +271,7 @@ argument (which probably comes from a JavaScript source) to a JS string and prin New API methods used: - `jerry_value_to_string` -- `jerry_string_to_utf8_char_buffer` +- `jerry_string_to_buffer` The `api-example-5.c` file should contain the following code: @@ -332,17 +299,17 @@ print_handler (const jerry_call_info_t *call_info_p, * Please note that if the string does not fit into the buffer nothing will be copied. * More details on the API reference page */ - jerry_size_t copied_bytes = jerry_string_to_utf8_char_buffer (string_value, buffer, sizeof (buffer) - 1); + jerry_size_t copied_bytes = jerry_string_to_buffer (string_value, buffer, sizeof (buffer) - 1, JERRY_ENCODING_UTF8); buffer[copied_bytes] = '\0'; /* Release the "toString" result */ - jerry_release_value (string_value); + jerry_value_free (string_value); printf ("%s\n", (const char *)buffer); } /* Return an "undefined" value to the JavaScript engine */ - return jerry_create_undefined (); + return jerry_undefined (); } int @@ -357,40 +324,40 @@ main (void) /* Add the "print" method for the JavaScript global object */ { /* Get the "global" object */ - jerry_value_t global_object = jerry_get_global_object (); + jerry_value_t global_object = jerry_current_realm (); /* Create a "print" JS string */ - jerry_value_t property_name_print = jerry_create_string ((const jerry_char_t *) "print"); + jerry_value_t property_name_print = jerry_string_sz ("print"); /* Create a function from a native C method (this function will be called from JS) */ - jerry_value_t property_value_func = jerry_create_external_function (print_handler); + jerry_value_t property_value_func = jerry_function_external (print_handler); /* Add the "print" property with the function value to the "global" object */ - jerry_value_t set_result = jerry_set_property (global_object, property_name_print, property_value_func); + jerry_value_t set_result = jerry_object_set (global_object, property_name_print, property_value_func); /* Check if there was no error when adding the property (in this case it should never happen) */ - if (jerry_value_is_error (set_result)) { + if (jerry_value_is_exception (set_result)) { printf ("Failed to add the 'print' property\n"); } /* Release all jerry_value_t-s */ - jerry_release_value (set_result); - jerry_release_value (property_value_func); - jerry_release_value (property_name_print); - jerry_release_value (global_object); + jerry_value_free (set_result); + jerry_value_free (property_value_func); + jerry_value_free (property_name_print); + jerry_value_free (global_object); } /* Setup Global scope code */ jerry_value_t parsed_code = jerry_parse (script, script_size, NULL); - if (!jerry_value_is_error (parsed_code)) + if (!jerry_value_is_exception (parsed_code)) { /* Execute the parsed source code in the Global scope */ jerry_value_t ret_value = jerry_run (parsed_code); /* Returned value must be freed */ - jerry_release_value (ret_value); + jerry_value_free (ret_value); } /* Parsed source code must be freed */ - jerry_release_value (parsed_code); + jerry_value_free (parsed_code); /* Cleanup engine */ jerry_cleanup (); @@ -440,23 +407,22 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Register 'print' function from the extensions to the global object */ - jerryx_handler_register_global ((const jerry_char_t *) "print", - jerryx_handler_print); + jerryx_handler_register_global ("print", jerryx_handler_print); /* Setup Global scope code */ jerry_value_t parsed_code = jerry_parse (script, script_size, NULL); - if (!jerry_value_is_error (parsed_code)) + if (!jerry_value_is_exception (parsed_code)) { /* Execute the parsed source code in the Global scope */ jerry_value_t ret_value = jerry_run (parsed_code); /* Returned value must be freed */ - jerry_release_value (ret_value); + jerry_value_free (ret_value); } /* Parsed source code must be freed */ - jerry_release_value (parsed_code); + jerry_value_free (parsed_code); /* Cleanup engine */ jerry_cleanup (); @@ -502,30 +468,29 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Register 'print' function from the extensions */ - jerryx_handler_register_global ((const jerry_char_t *) "print", - jerryx_handler_print); + jerryx_handler_register_global ("print", jerryx_handler_print); /* Getting pointer to the Global object */ - jerry_value_t global_object = jerry_get_global_object (); + jerry_value_t global_object = jerry_current_realm (); /* Constructing strings */ - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_var"); - jerry_value_t prop_value = jerry_create_string ((const jerry_char_t *) "Hello from C!"); + jerry_value_t prop_name = jerry_string_sz ("my_var"); + jerry_value_t prop_value = jerry_string_sz ("Hello from C!"); /* Setting the string value as a property of the Global object */ - jerry_value_t set_result = jerry_set_property (global_object, prop_name, prop_value); + jerry_value_t set_result = jerry_object_set (global_object, prop_name, prop_value); /* The 'set_result' should be checked if there was any error */ - if (jerry_value_is_error (set_result)) { + if (jerry_value_is_exception (set_result)) { printf ("Failed to add the 'my_var' property\n"); } - jerry_release_value (set_result); + jerry_value_free (set_result); /* Releasing string values, as it is no longer necessary outside of engine */ - jerry_release_value (prop_name); - jerry_release_value (prop_value); + jerry_value_free (prop_name); + jerry_value_free (prop_value); /* Releasing the Global object */ - jerry_release_value (global_object); + jerry_value_free (global_object); /* Now starting script that would output value of just initialized field */ jerry_value_t eval_ret = jerry_eval (script, @@ -533,7 +498,7 @@ main (void) JERRY_PARSE_NO_OPTS); /* Free JavaScript value, returned by eval */ - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); /* Freeing engine */ jerry_cleanup (); @@ -561,9 +526,9 @@ $ ./api-example-7 JerryScript value can be a boolean, number, null, object, string, undefined or some special type of objects (arraybuffer, symbols, etc). There is a special "error" value which wraps another value. This "error" can be created by throwing a JavaScript value from JS code -or via API method(s). It is advised to check for this error with the `jerry_value_is_error` method as not all API methods -can process error values. To extract the value from the "error" the API method `jerry_get_value_from_error` should be used. -If an error object is created via API method (for example with `jerry_create_error`) the "error" value is automatically created. +or via API method(s). It is advised to check for this error with the `jerry_value_is_exception` method as not all API methods +can process error values. To extract the value from the "error" the API method `jerry_exception_value` should be used. +If an error object is created via API method (for example with `jerry_error`) the "error" value is automatically created. Notice the difference between error value and error object: - The error object is a object which was constructed via one of the `Error` objects (available from the global object or from API). @@ -580,7 +545,7 @@ var error_object = new Error ("error message"); throw "message"; ``` -To check what type a given `jerry_value_t` is the `jerry_value_is_*` methods or the `jerry_value_get_type` could be used. +To check what type a given `jerry_value_t` is the `jerry_value_is_*` methods or the `jerry_value_type` could be used. For example the following code snippet could print out a few types (not all types are checked): [doctest]: # (test="compile") @@ -595,14 +560,14 @@ print_value (const jerry_value_t jsvalue) { jerry_value_t value; /* If there is an error extract the object from it */ - if (jerry_value_is_error (jsvalue)) + if (jerry_value_is_exception (jsvalue)) { printf ("Error value detected: "); - value = jerry_get_value_from_error (jsvalue, false); + value = jerry_exception_value (jsvalue, false); } else { - value = jerry_acquire_value (jsvalue); + value = jerry_value_copy (jsvalue); } if (jerry_value_is_undefined (value)) @@ -627,7 +592,7 @@ print_value (const jerry_value_t jsvalue) /* Float value */ else if (jerry_value_is_number (value)) { - printf ("number: %lf", jerry_get_number_value (value)); + printf ("number: %lf", jerry_value_as_number (value)); } /* String value */ else if (jerry_value_is_string (value)) @@ -635,11 +600,11 @@ print_value (const jerry_value_t jsvalue) jerry_char_t str_buf_p[256]; /* Determining required buffer size */ - jerry_size_t req_sz = jerry_get_string_size (value); + jerry_size_t req_sz = jerry_string_size (value, JERRY_ENCODING_CESU8); if (req_sz <= 255) { - jerry_string_to_char_buffer (value, str_buf_p, req_sz); + jerry_string_to_buffer (value, str_buf_p, req_sz, JERRY_ENCODING_CESU8); str_buf_p[req_sz] = '\0'; printf ("%s", (const char *) str_buf_p); } @@ -655,7 +620,7 @@ print_value (const jerry_value_t jsvalue) } printf ("\n"); - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -689,14 +654,14 @@ print_value (const jerry_value_t jsvalue) { jerry_value_t value; /* If there is an error extract the object from it */ - if (jerry_value_is_error (jsvalue)) + if (jerry_value_is_exception (jsvalue)) { printf ("Error value detected: "); - value = jerry_get_value_from_error (jsvalue, false); + value = jerry_exception_value (jsvalue, false); } else { - value = jerry_acquire_value (jsvalue); + value = jerry_value_copy (jsvalue); } if (jerry_value_is_undefined (value)) @@ -721,7 +686,7 @@ print_value (const jerry_value_t jsvalue) /* Float value */ else if (jerry_value_is_number (value)) { - printf ("number: %lf", jerry_get_number_value (value)); + printf ("number: %lf", jerry_value_as_number (value)); } /* String value */ else if (jerry_value_is_string (value)) @@ -729,11 +694,11 @@ print_value (const jerry_value_t jsvalue) jerry_char_t str_buf_p[256]; /* Determining required buffer size */ - jerry_size_t req_sz = jerry_get_string_size (value); + jerry_size_t req_sz = jerry_string_size (value, JERRY_ENCODING_CESU8); if (req_sz <= 255) { - jerry_string_to_char_buffer (value, str_buf_p, req_sz); + jerry_string_to_buffer (value, str_buf_p, req_sz, JERRY_ENCODING_CESU8); str_buf_p[req_sz] = '\0'; printf ("%s", (const char *) str_buf_p); } @@ -749,7 +714,7 @@ print_value (const jerry_value_t jsvalue) } printf ("\n"); - jerry_release_value (value); + jerry_value_free (value); } int @@ -761,8 +726,7 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Register 'print' function from the extensions */ - jerryx_handler_register_global ((const jerry_char_t *) "print", - jerryx_handler_print); + jerryx_handler_register_global ("print", jerryx_handler_print); while (!is_done) { @@ -805,7 +769,7 @@ main (void) /* Print out the value */ print_value (ret_val); - jerry_release_value (ret_val); + jerry_value_free (ret_val); } /* Cleanup engine */ @@ -853,7 +817,7 @@ get_msg_handler (const jerry_call_info_t *call_info_p, /**< call information */ const jerry_value_t *args_p, /**< function arguments */ const jerry_length_t args_cnt) /**< number of function arguments */ { - return jerry_create_string ((const jerry_char_t *) my_struct.msg); + return jerry_string_sz (my_struct.msg); } /* get_msg_handler */ int @@ -863,33 +827,32 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Register 'print' function from the extensions */ - jerryx_handler_register_global ((const jerry_char_t *) "print", - jerryx_handler_print); + jerryx_handler_register_global ("print", jerryx_handler_print); /* Do something with the native object */ my_struct.msg = "Hello, World!"; /* Create an empty JS object */ - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); /* Create a JS function object and wrap into a jerry value */ - jerry_value_t func_obj = jerry_create_external_function (get_msg_handler); + jerry_value_t func_obj = jerry_function_external (get_msg_handler); /* Set the native function as a property of the empty JS object */ - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "myFunc"); - jerry_release_value (jerry_set_property (object, prop_name, func_obj)); - jerry_release_value (prop_name); - jerry_release_value (func_obj); + jerry_value_t prop_name = jerry_string_sz ("myFunc"); + jerry_value_free (jerry_object_set (object, prop_name, func_obj)); + jerry_value_free (prop_name); + jerry_value_free (func_obj); /* Wrap the JS object (not empty anymore) into a jerry api value */ - jerry_value_t global_object = jerry_get_global_object (); + jerry_value_t global_object = jerry_current_realm (); /* Add the JS object to the global context */ - prop_name = jerry_create_string ((const jerry_char_t *) "MyObject"); - jerry_release_value (jerry_set_property (global_object, prop_name, object)); - jerry_release_value (prop_name); - jerry_release_value (object); - jerry_release_value (global_object); + prop_name = jerry_string_sz ("MyObject"); + jerry_value_free (jerry_object_set (global_object, prop_name, object)); + jerry_value_free (prop_name); + jerry_value_free (object); + jerry_value_free (global_object); /* Now we have a "builtin" object called MyObject with a function called myFunc() * @@ -905,7 +868,7 @@ main (void) jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); /* Free JavaScript value, returned by eval */ - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); /* Cleanup engine */ jerry_cleanup (); @@ -960,27 +923,27 @@ add_handler (const jerry_call_info_t *call_info_p, /**< call information */ /* Note: that the argument count check is ignored for the example's case */ /* Get 'this.x' */ - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "x"); - jerry_value_t x_val = jerry_get_property (call_info_p->this_value, prop_name); + jerry_value_t prop_name = jerry_string_sz ("x"); + jerry_value_t x_val = jerry_object_get (call_info_p->this_value, prop_name); - if (!jerry_value_is_error (x_val)) + if (!jerry_value_is_exception (x_val)) { /* Convert Jerry API values to double */ - double x = jerry_get_number_value (x_val); - double d = jerry_get_number_value (args_p[0]); + double x = jerry_value_as_number (x_val); + double d = jerry_value_as_number (args_p[0]); /* Add the parameter to 'x' */ - jerry_value_t res_val = jerry_create_number (x + d); + jerry_value_t res_val = jerry_number (x + d); /* Set the new value of 'this.x' */ - jerry_release_value (jerry_set_property (call_info_p->this_value, prop_name, res_val)); - jerry_release_value (res_val); + jerry_value_free (jerry_object_set (call_info_p->this_value, prop_name, res_val)); + jerry_value_free (res_val); } - jerry_release_value (x_val); - jerry_release_value (prop_name); + jerry_value_free (x_val); + jerry_value_free (prop_name); - return jerry_create_undefined (); + return jerry_undefined (); } /* add_handler */ int @@ -990,8 +953,7 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Register 'print' function from the extensions */ - jerryx_handler_register_global ((const jerry_char_t *) "print", - jerryx_handler_print); + jerryx_handler_register_global ("print", jerryx_handler_print); /* Create a JS object */ const jerry_char_t my_js_object[] = " \ @@ -1013,16 +975,16 @@ main (void) JERRY_PARSE_NO_OPTS); /* Create a JS function object and wrap into a jerry value */ - jerry_value_t add_func_obj = jerry_create_external_function (add_handler); + jerry_value_t add_func_obj = jerry_function_external (add_handler); /* Set the native function as a property of previously created MyObject */ - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "add2x"); - jerry_release_value (jerry_set_property (my_js_obj_val, prop_name, add_func_obj)); - jerry_release_value (add_func_obj); - jerry_release_value (prop_name); + jerry_value_t prop_name = jerry_string_sz ("add2x"); + jerry_value_free (jerry_object_set (my_js_obj_val, prop_name, add_func_obj)); + jerry_value_free (add_func_obj); + jerry_value_free (prop_name); /* Free JavaScript value, returned by eval (my_js_object) */ - jerry_release_value (my_js_obj_val); + jerry_value_free (my_js_obj_val); const jerry_char_t script[] = " \ var str = MyObject.foo (); \ @@ -1035,7 +997,7 @@ main (void) jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); /* Free JavaScript value, returned by eval */ - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); /* Cleanup engine */ jerry_cleanup (); @@ -1090,14 +1052,13 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Register the print function */ - jerryx_handler_register_global ((const jerry_char_t *) "print", - jerryx_handler_print); + jerryx_handler_register_global ("print", jerryx_handler_print); /* Evaluate the script */ jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); /* Free the JavaScript value returned by eval */ - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); /* Cleanup the engine */ jerry_cleanup (); diff --git a/docs/06.REFERENCE-COUNTING.md b/docs/06.REFERENCE-COUNTING.md index 629e4e6707..cb207ea76f 100644 --- a/docs/06.REFERENCE-COUNTING.md +++ b/docs/06.REFERENCE-COUNTING.md @@ -3,10 +3,10 @@ In JerryScript all `jerry_value_t` values are independent references to internal objects. Values returned by JerryScript API functions are always live references and must be released -by `jerry_release_value`. +by `jerry_value_free`. ```c - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); /* The value stored in the 'global' variable contains a live * reference to the global object. The system also keeps its @@ -14,9 +14,9 @@ by `jerry_release_value`. * are independent, and both must be destroyed before the global * object can be freed. */ - jerry_release_value (global); + jerry_value_free (global); - /* Without jerry_release_value() the global object will not + /* Without jerry_value_free() the global object will not * be freed even by jerry_cleanup(). After the reference * is released it becomes a dead reference and cannot be * used anymore. */ @@ -26,15 +26,15 @@ Multiple references might refer to the same internal object even though their `jerry_value_t` representation might be different. ```c - jerry_value_t pi_ref1 = jerry_create_number (3.14); - jerry_value_t pi_ref2 = jerry_acquire_value (pi_ref1); + jerry_value_t pi_ref1 = jerry_number (3.14); + jerry_value_t pi_ref2 = jerry_value_copy (pi_ref1); /* Both pi_ref1 and pi_ref2 refer to the same 3.14 value * although they might not be equal in C (pi_ref1 != pi_ref2). */ /* Both references must be released. */ - jerry_release_value (pi_ref1); - jerry_release_value (pi_ref2); + jerry_value_free (pi_ref1); + jerry_value_free (pi_ref2); ``` Releasing the same `jerry_value_t` twice to release two live @@ -42,8 +42,8 @@ references is not allowed and it might cause crashes. Hence the following code is an **INCORRECT WAY** of releasing the 3.14 value. ```c - jerry_release_value (pi_ref1); - jerry_release_value (pi_ref1); + jerry_value_free (pi_ref1); + jerry_value_free (pi_ref1); ``` JerryScript API functions returning with a `jerry_value_t` always @@ -53,7 +53,7 @@ stated in the documentation). The next example shows this behaviour through property getting and setting. ```c - jerry_value_t prop_value = jerry_get_property (...); + jerry_value_t prop_value = jerry_object_get (...); /* The prop_value must be released later because both the base * object and the prop_value have an independent reference to @@ -61,7 +61,7 @@ behaviour through property getting and setting. * prop_value contains a live reference to an error object. * This reference must be released as well. */ - if (jerry_value_is_error (prop_value)) + if (jerry_value_is_exception (prop_value)) { /* Errors can be handled here. */ } @@ -73,12 +73,12 @@ behaviour through property getting and setting. } /* The prop_value must be released. */ - jerry_release_value (prop_value); + jerry_value_free (prop_value); /* Property setting is the same. */ - jerry_value_t new_prop_value = jerry_create_number (2.718); - jerry_value_t result = jerry_set_property (..., new_prop_value); + jerry_value_t new_prop_value = jerry_number (2.718); + jerry_value_t result = jerry_object_set (..., new_prop_value); /* If the property set is successful, a new reference is created * for the value referenced by new_prop_value. The new_prop_value @@ -86,14 +86,14 @@ behaviour through property getting and setting. * is successful. */ /* The new_prop_value can be passed to other JerryScript API - * functions before the jerry_release_value () call. */ + * functions before the jerry_value_free () call. */ - jerry_release_value (new_prop_value); + jerry_value_free (new_prop_value); /* The reference stored in the 'result' variable is live whether * the operation is successful or not, and must also be freed. */ - if (jerry_value_is_error (result)) + if (jerry_value_is_exception (result)) { /* Errors can be handled here. */ } @@ -102,7 +102,7 @@ behaviour through property getting and setting. /* A reference to a true primitive value is returned. */ } - jerry_release_value (result); + jerry_value_free (result); ``` The simplest form of setting a property without error checking @@ -110,8 +110,8 @@ is the following: ```c /* There are no 'ifs' in this snippet. */ - jerry_release_value (jerry_set_property (..., new_prop_value)); - jerry_release_value (new_prop_value); + jerry_value_free (jerry_object_set (..., new_prop_value)); + jerry_value_free (new_prop_value); ``` The reference returned by a `jerry_external_handler_t` callback @@ -128,48 +128,48 @@ jerry_value_t my_external_handler (const jerry_value_t function_obj, * these references are automatically released after the handler * is returned. This approach reduces code size which is useful * on embedded systems. However you can create other references - * to them by calling jerry_acquire_value () if needed. */ + * to them by calling jerry_value_copy () if needed. */ /* Since the ownership of the reference is transferred to the * caller the following snippet is valid. */ /* If the value to be returned is needed for other purposes the - * jerry_acquire_value () can be used to create new references. */ - return jerry_create_string (...); + * jerry_value_copy () can be used to create new references. */ + return jerry_string (...); } ``` Duplicating a `jerry_value_t` in C does not create another live reference. ```c - jerry_value_t undef = jerry_create_undefined (); + jerry_value_t undef = jerry_undefined (); jerry_value_t undef2 = undef; /* Releasing either undef or undef2 is valid but not both. * After the release both references become dead (invalid). */ - jerry_release_value (undef2); + jerry_value_free (undef2); /* Dead references can be reassigned again. */ - undef = jerry_create_boolean (true); + undef = jerry_boolean (true); ``` References can be duplicated in C as long as only one of them is freed. ```c - jerry_value_t a = jerry_create_boolean (true); + jerry_value_t a = jerry_boolean (true); jerry_value_t b = a; jerry_value_t c = a; /* A new reference is assigned to 'a'. */ - a = jerry_create_boolean (false); + a = jerry_boolean (false); [...] - jerry_release_value (a); + jerry_value_free (a); /* The 'a' (boolean false) reference becomes dead (invalid). */ - jerry_release_value (c); + jerry_value_free (c); /* Both 'b' and 'c' (boolean true) references become dead. */ /* Since all references are released, no memory leak occurs. */ diff --git a/docs/07.DEBUGGER.md b/docs/07.DEBUGGER.md index ceb98f229d..ddf6aff86a 100644 --- a/docs/07.DEBUGGER.md +++ b/docs/07.DEBUGGER.md @@ -97,14 +97,14 @@ when a source code is received successfully. ```c typedef jerry_value_t -(*jerry_debugger_wait_for_source_callback_t) (const jerry_char_t *resource_name_p, - size_t resource_name_size, +(*jerry_debugger_wait_for_source_callback_t) (const jerry_char_t *source_name_p, + size_t source_name_size, const jerry_char_t *source_p, size_t source_size, void *user_p); ``` -- `resource_name_p` - resource (usually a file) name of the source code -- `resource_name_size` - size of resource name +- `source_name_p` - resource (usually a file) name of the source code +- `source_name_size` - size of resource name - `source_p` - source code character data - `source_size` - size of source code - `user_p` - custom pointer passed to [jerry_debugger_wait_for_client_source](#jerry_debugger_wait_for_client_source) @@ -306,8 +306,8 @@ jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t * Runs the source code received by jerry_debugger_wait_for_client_source. */ static jerry_value_t -wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource name */ - size_t resource_name_size, /**< size of resource name */ +wait_for_source_callback (const jerry_char_t *source_name_p, /**< resource name */ + size_t source_name_size, /**< size of resource name */ const jerry_char_t *source_p, /**< source code */ size_t source_size, /**< source code size */ void *user_p /**< user pointer */) @@ -315,19 +315,21 @@ wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource nam (void) user_p; jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) resource_name_p); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string ((const jerry_char_t *) source_name_p, + (jerry_size_t) source_name_size, + JERRY_ENCODING_UTF8); jerry_value_t ret_val = jerry_parse (source_p, source_size, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (!jerry_value_is_error (ret_val)) + if (!jerry_value_is_exception (ret_val)) { jerry_value_t func_val = ret_val; ret_val = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); } return ret_val; @@ -355,7 +357,7 @@ main (void) NULL, &run_result); - jerry_release_value (run_result); + jerry_value_free (run_result); } while (receive_status == JERRY_DEBUGGER_SOURCE_RECEIVED); diff --git a/docs/09.EXT-REFERENCE-ARG.md b/docs/09.EXT-REFERENCE-ARG.md index 08bd6d22c2..dab69ff3ca 100644 --- a/docs/09.EXT-REFERENCE-ARG.md +++ b/docs/09.EXT-REFERENCE-ARG.md @@ -244,7 +244,7 @@ my_external_handler (const jerry_value_t function_obj, mapping, 4); - if (jerry_value_is_error (rv)) + if (jerry_value_is_exception (rv)) { /* Handle error. */ return rv; @@ -255,7 +255,7 @@ my_external_handler (const jerry_value_t function_obj, * required_bool, required_str and optional_num can now be used. */ - return jerry_create_undefined (); /* Or return something more meaningful. */ + return jerry_undefined (); /* Or return something more meaningful. */ } ``` @@ -640,7 +640,7 @@ my_external_handler (const jerry_value_t function_obj, mapping, 1); - if (jerry_value_is_error (rv)) + if (jerry_value_is_exception (rv)) { /* Handle error. */ return rv; @@ -651,7 +651,7 @@ my_external_handler (const jerry_value_t function_obj, * required_bool, required_num and optional_num can now be used. */ - return jerry_create_undefined (); /* Or return something more meaningful. */ + return jerry_undefined (); /* Or return something more meaningful. */ } ``` @@ -731,7 +731,7 @@ my_external_handler (const jerry_value_t function_obj, mapping, 1); - if (jerry_value_is_error (rv)) + if (jerry_value_is_exception (rv)) { /* Handle error. */ return rv; @@ -742,7 +742,7 @@ my_external_handler (const jerry_value_t function_obj, * required_bool, required_num and optional_num can now be used. */ - return jerry_create_undefined (); /* Or return something more meaningful. */ + return jerry_undefined (); /* Or return something more meaningful. */ } ``` diff --git a/docs/10.EXT-REFERENCE-HANDLER.md b/docs/10.EXT-REFERENCE-HANDLER.md index 9484c5b560..e1d991fa0a 100644 --- a/docs/10.EXT-REFERENCE-HANDLER.md +++ b/docs/10.EXT-REFERENCE-HANDLER.md @@ -12,7 +12,7 @@ Set a property on a target object with a given name. *Note*: - The property name must be a zero terminated UTF-8 string. - There should be no '\0' (NULL) character in the name excluding the string terminator. -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. @@ -45,19 +45,19 @@ main (int argc, char **argv) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); - jerry_value_t value = jerry_create_number (3.3); + jerry_value_t value = jerry_number (3.3); jerry_value_t result = jerryx_set_property_str (global, "value", value); - if (jerry_value_is_error (result)) + if (jerry_value_is_exception (result)) { - /* The error type/reason can be extracted via the `jerry_get_value_from_error` method */ + /* The error type/reason can be extracted via the `jerry_exception_value` method */ printf ("Error during property configuration\r\n"); } - jerry_release_value (result); - jerry_release_value (value); - jerry_release_value (global); + jerry_value_free (result); + jerry_value_free (value); + jerry_value_free (global); jerry_cleanup(); return 0; @@ -73,7 +73,7 @@ Get the value of a property from the specified object with the given name. *Notes*: - The property name must be a zero terminated UTF-8 string. - There should be no '\0' (NULL) character in the name excluding the string terminator. -- Returned value must be freed with [jerry_release_value](#jerry_release_value) when it +- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed. @@ -104,14 +104,14 @@ main (int argc, char **argv) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); jerry_value_t math_object = jerryx_get_property_str (global, "Math"); /* use math_object */ - jerry_release_value (math_object); - jerry_release_value (global); + jerry_value_free (math_object); + jerry_value_free (global); jerry_cleanup(); return 0; @@ -125,7 +125,7 @@ main (int argc, char **argv) Check if a property exists on an object. *Notes*: -- The operation performed is the same as what the `jerry_has_property` method. +- The operation performed is the same as what the `jerry_object_has` method. - The property name must be a zero terminated UTF-8 string. - There should be no '\0' (NULL) character in the name excluding the string terminator. @@ -157,11 +157,11 @@ main (int argc, char **argv) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); bool have_math = jerryx_has_property_str (global, "Math"); - jerry_release_value (global); + jerry_value_free (global); jerry_cleanup(); return have_math ? 0 : 1; @@ -273,7 +273,7 @@ handler (const jerry_call_info_t *call_info_p, { printf ("native handler called!\n"); - return jerry_create_boolean (true); + return jerry_boolean (true); } int @@ -283,24 +283,24 @@ main (int argc, char **argv) jerryx_property_entry methods[] = { - { "demo", jerry_create_external_function (handler) }, + { "demo", jerry_function_external (handler) }, { NULL, 0 }, }; - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); jerryx_register_result reg = jerryx_set_properties (global, methods); /* if `reg.result` is undefined all methods are registered */ - if (jerry_value_is_error (reg.result)) + if (jerry_value_is_exception (reg.result)) { printf ("Only registered %d properties\r\n", reg.registered); /* clean up not registered property values */ jerryx_release_property_entry (methods, reg); /* clean up the error */ - jerry_release_value (reg.result); + jerry_value_free (reg.result); } - jerry_release_value (global); + jerry_value_free (global); jerry_cleanup(); @@ -314,8 +314,8 @@ To make property registration convenient, there are a set of macros to use when setting a property entry: * `JERRYX_PROPERTY_NUMBER(NAME, NUMBER)` - creates a number entry. -* `JERRYX_PROPERTY_STRING(NAME, STR)` - creates an UTF-8 string entry. This string must be zero terminated. -* `JERRYX_PROPERTY_STRING_SZ(NAME, STR, SIZE)` - creates an UTF-8 string entry using only `SIZE` bytes from the string. +* `JERRYX_PROPERTY_STRING(NAME, STR, SIZE)` - creates an UTF-8 string entry using `SIZE` bytes from the string. +* `JERRYX_PROPERTY_STRING_SZ(NAME, STR)` - creates an ASCII string entry. This string must be zero terminated. * `JERRYX_PROPERTY_BOOLEAN(NAME, VALUE)` - creates a boolean entry. * `JERRYX_PROPERTY_FUNCTION(NAME, NATIVE)` - creates a native C function entry. * `JERRYX_PROPERTY_UNDEFINED(NAME)` - creates an undefined property entry. @@ -336,7 +336,7 @@ handler (const jerry_call_info_t *call_info_p, { printf ("native handler called!\n"); - return jerry_create_boolean (true); + return jerry_boolean (true); } int @@ -357,20 +357,20 @@ main (int argc, char **argv) JERRYX_PROPERTY_LIST_END(), }; - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); jerryx_register_result reg = jerryx_set_properties (global, methods); /* if `reg.result` is undefined all methods are registered */ - if (jerry_value_is_error (reg.result)) + if (jerry_value_is_exception (reg.result)) { printf ("Only registered %d properties\r\n", reg.registered); /* clean up not registered property values */ jerryx_release_property_entry (methods, reg); /* clean up the error */ - jerry_release_value (reg.result); + jerry_value_free (reg.result); } - jerry_release_value (global); + jerry_value_free (global); jerry_cleanup(); @@ -551,14 +551,14 @@ jerryx_handler_print (const jerry_value_t func_obj_val, const jerry_value_t this Register a JavaScript function in the global object. -*Note*: Returned value must be freed with `jerry_release_value`, when it is no +*Note*: Returned value must be freed with `jerry_value_free`, when it is no longer needed. **Prototype** ```c jerry_value_t -jerryx_handler_register_global (const jerry_char_t *name_p, +jerryx_handler_register_global (const char *name_p, jerry_external_handler_t handler_p); ``` @@ -589,14 +589,14 @@ static const struct { static void register_common_functions (void) { - jerry_value_t ret = jerry_create_undefined (); + jerry_value_t ret = jerry_undefined (); - for (int i = 0; common_functions[i].name_p != NULL && !jerry_value_is_error (ret); i++) + for (int i = 0; common_functions[i].name_p != NULL && !jerry_value_is_exception (ret); i++) { - ret = jerryx_handler_register_global ((const jerry_char_t *) common_functions[i].name_p, + ret = jerryx_handler_register_global (common_functions[i].name_p, common_functions[i].handler_p); } - jerry_release_value (ret); + jerry_value_free (ret); } ``` diff --git a/docs/11.EXT-REFERENCE-AUTORELEASE.md b/docs/11.EXT-REFERENCE-AUTORELEASE.md index 65d548c8f1..7d46247e48 100644 --- a/docs/11.EXT-REFERENCE-AUTORELEASE.md +++ b/docs/11.EXT-REFERENCE-AUTORELEASE.md @@ -4,7 +4,7 @@ **Summary** -Macro for `const jerry_value_t` for which jerry_release_value() is +Macro for `const jerry_value_t` for which jerry_value_free() is automatically called when the variable goes out of scope. *Note*: The macro depends on compiler support. For GCC and LLVM/clang, the macro is implemented @@ -21,23 +21,23 @@ using the `__cleanup__` variable attribute. For other compilers, no support has static void foo (bool enable) { - JERRYX_AR_VALUE_T bar = jerry_create_string ((const jerry_char_t *) "..."); + JERRYX_AR_VALUE_T bar = jerry_string_sz ("..."); if (enable) { - JERRYX_AR_VALUE_T baz = jerry_get_global_object (); + JERRYX_AR_VALUE_T baz = jerry_current_realm (); /* bar and baz can now be used. */ /* - * jerry_release_value (baz) and jerry_release_value (bar) is called automatically before + * jerry_value_free (baz) and jerry_value_free (bar) is called automatically before * returning, because `baz` and `bar` go out of scope. */ return; } /* - * jerry_release_value (bar) is called automatically when the function returns, + * jerry_value_free (bar) is called automatically when the function returns, * because `bar` goes out of scope. */ } @@ -46,5 +46,5 @@ foo (bool enable) **See also** - [jerry_value_t](../docs/02.API-REFERENCE.md#jerry_value_t) -- [jerry_acquire_value](../docs/02.API-REFERENCE.md#jerry_acquire_value) -- [jerry_release_value](../docs/02.API-REFERENCE.md#jerry_release_value) +- [jerry_value_copy](../docs/02.API-REFERENCE.md#jerry_value_copy) +- [jerry_value_free](../docs/02.API-REFERENCE.md#jerry_value_free) diff --git a/docs/12.EXT-REFERENCE-MODULE.md b/docs/12.EXT-REFERENCE-MODULE.md index 0a1056ddf3..eb39d7e871 100644 --- a/docs/12.EXT-REFERENCE-MODULE.md +++ b/docs/12.EXT-REFERENCE-MODULE.md @@ -164,9 +164,9 @@ load_and_evaluate_js_file (const jerry_value_t name, jerry_value_t *result) char *js_file_contents = NULL; int file_size = 0; - jerry_size_t name_size = jerry_get_utf8_string_size (name); + jerry_size_t name_size = jerry_string_size (name, JERRY_ENCODING_UTF8); jerry_char_t name_string[name_size + 1]; - jerry_string_to_utf8_char_buffer (name, name_string, name_size); + jerry_string_to_buffer (name, name_string, name_size, JERRY_ENCODING_UTF8); name_string[name_size] = 0; FILE *js_file = fopen (name_string, "r"); @@ -205,7 +205,7 @@ canonicalize_file_path (const jerry_value_t name) /** * Since a file on the file system can be referred to by multiple relative paths, but only by one absolute path, the * absolute path becomes the canonical name for the module. Thus, to establish this canonical name, we must search - * name for "./" and "../", follow symlinks, etc., then create absolute_path via jerry_create_string () and return + * name for "./" and "../", follow symlinks, etc., then create absolute_path via jerry_string () and return * it, because it is the canonical name for this module. Thus, we avoid loading the same JavaScript file twice. */ @@ -271,7 +271,7 @@ loaded. static jerry_value_t my_module_on_resolve (void) { - return jerry_create_external_function (very_useful_function); + return jerry_function_external (very_useful_function); } /* my_module_on_resolve */ /* Note that there is no semicolon at the end of the next line. This is how it must be. */ diff --git a/docs/14.EXT-REFERENCE-HANDLE-SCOPE.md b/docs/14.EXT-REFERENCE-HANDLE-SCOPE.md index b79eb8ec6f..e5132a53a1 100644 --- a/docs/14.EXT-REFERENCE-HANDLE-SCOPE.md +++ b/docs/14.EXT-REFERENCE-HANDLE-SCOPE.md @@ -20,7 +20,7 @@ JerryScript only supports a single nested hierarchy of scopes. There is only one static jerry_value_t create_object (void) { - jerry_value_t obj = jerry_create_object (); + jerry_value_t obj = jerry_object (); return obj; } /* create_object */ @@ -41,7 +41,7 @@ main (void) jerry_init (JERRY_INIT_EMPTY); test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); jerry_cleanup (); } /* main */ @@ -66,7 +66,7 @@ create_object (void) { jerryx_escapable_handle_scope scope; jerryx_open_escapable_handle_scope (&scope); - jerry_value_t obj = jerryx_create_handle (jerry_create_object ()); + jerry_value_t obj = jerryx_create_handle (jerry_object ()); jerry_value_t escaped_obj; jerryx_escape_handle(scope, obj, &escaped_obj); @@ -93,7 +93,7 @@ main (void) jerry_init (JERRY_INIT_EMPTY); test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); jerry_cleanup (); } /* main */ @@ -102,8 +102,8 @@ main (void) **See also** - [jerry_value_t](../docs/02.API-REFERENCE.md#jerry_value_t) -- [jerry_acquire_value](../docs/02.API-REFERENCE.md#jerry_acquire_value) -- [jerry_release_value](../docs/02.API-REFERENCE.md#jerry_release_value) +- [jerry_value_copy](../docs/02.API-REFERENCE.md#jerry_value_copy) +- [jerry_value_free](../docs/02.API-REFERENCE.md#jerry_value_free) ## Pre-allocated list of handle scopes and handles diff --git a/docs/16.MIGRATION-GUIDE.md b/docs/16.MIGRATION-GUIDE.md index 9c71d63a1b..ba4a2bbb89 100644 --- a/docs/16.MIGRATION-GUIDE.md +++ b/docs/16.MIGRATION-GUIDE.md @@ -23,19 +23,19 @@ For more information on the current API methods please check the [API reference] ***Removed API types*** - `jerry_char_ptr_t` usage replaced with `jerry_char_t *` -- `jerry_object_free_callback_t` replaced by `jerry_object_native_free_callback_t` +- `jerry_object_free_callback_t` replaced by `jerry_object_native_free_cb_t` ***Removed API methods*** - `jerry_get_memory_limits` -- `jerry_get_object_native_handle` replaced by `jerry_get_object_native_pointer` -- `jerry_set_object_native_handle` replaced by `jerry_set_object_native_pointer` -- `jerry_value_set_abort_flag` replaced by `jerry_create_abort_from_value` +- `jerry_get_object_native_handle` replaced by `jerry_object_get_native_ptr` +- `jerry_set_object_native_handle` replaced by `jerry_object_set_native_ptr` +- `jerry_value_set_abort_flag` replaced by `jerry_throw_abort` - `jerry_value_has_abort_flag` replaced by `jerry_value_is_abort` -- `jerry_value_set_error_flag` replaced by `jerry_create_error_from_value` -- `jerry_value_has_error_flag` replaced by `jerry_value_is_error` -- `jerry_value_clear_error_flag` replaced by `jerry_get_value_from_error` -- `jerry_get_value_without_error_flag` replaced by `jerry_get_value_from_error` +- `jerry_value_set_error_flag` replaced by `jerry_exception` +- `jerry_value_has_error_flag` replaced by `jerry_value_is_exception` +- `jerry_value_clear_error_flag` replaced by `jerry_exception_value` +- `jerry_get_value_without_error_flag` replaced by `jerry_exception_value` - `jerry_parse_and_save_snapshot` replaced by `jerry_generate_snapshot` - `jerry_parse_and_save_function_snapshot` replaced by `jerry_generate_function_snapshot` @@ -57,8 +57,8 @@ The most important changes in the API are related to error handling and manipula ### jerry_value_set_abort_flag -This function was replaced with [`jerry_create_abort_from_value`](02.API-REFERENCE.md#jerry_create_abort_from_value). -Take note of the second argument of the new `jerry_create_abort_from_value` function which controls if the +This function was replaced with [`jerry_throw_abort`](02.API-REFERENCE.md#jerry_throw_abort). +Take note of the second argument of the new `jerry_throw_abort` function which controls if the first argument should be usable after the call or not. **Before** @@ -66,12 +66,12 @@ first argument should be usable after the call or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... jerry_value_set_abort_flag (&value); - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -80,13 +80,13 @@ first argument should be usable after the call or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... - jerry_value_t abort = jerry_create_abort_from_value (value, true); + jerry_value_t abort = jerry_throw_abort (value, true); // using the 'value' variable after release is invalid - jerry_release_value (abort); + jerry_value_free (abort); } ``` @@ -95,13 +95,13 @@ first argument should be usable after the call or not. ```c { jerry_value_t value; - ... // create or acquire value + ... // create or copy value - jerry_value_t abort = jerry_create_abort_from_value (value, false); + jerry_value_t abort = jerry_throw_abort (value, false); // both 'abort' and 'value' can be used and must be released when they are no longer needed - jerry_release_value (abort); - jerry_release_value (value); + jerry_value_free (abort); + jerry_value_free (value); } ``` @@ -114,7 +114,7 @@ This function was renamed to [`jerry_value_is_abort`](02.API-REFERENCE.md#jerry ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... if (jerry_value_has_abort_flag (value)) @@ -122,7 +122,7 @@ This function was renamed to [`jerry_value_is_abort`](02.API-REFERENCE.md#jerry // ... } - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -131,7 +131,7 @@ This function was renamed to [`jerry_value_is_abort`](02.API-REFERENCE.md#jerry ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... if (jerry_value_is_abort (value)) @@ -139,14 +139,14 @@ This function was renamed to [`jerry_value_is_abort`](02.API-REFERENCE.md#jerry // ... } - jerry_release_value (value); + jerry_value_free (value); } ``` ### jerry_value_set_error_flag -This function was replaced with [`jerry_create_error_from_value`](02.API-REFERENCE.md#jerry_create_error_from_value). -Take note of the second argument of the new `jerry_create_error_from_value` function which controls if the +This function was replaced with [`jerry_exception`](02.API-REFERENCE.md#jerry_exception). +Take note of the second argument of the new `jerry_exception` function which controls if the first argument should be usable after the call or not. **Before** @@ -154,12 +154,12 @@ first argument should be usable after the call or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... jerry_value_set_error_flag (&value); - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -168,13 +168,13 @@ first argument should be usable after the call or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... - jerry_value_t error = jerry_create_error_from_value (value, true); + jerry_value_t error = jerry_throw_value (value, true); // using the 'value' variable after release is invalid - jerry_release_value (error); + jerry_value_free (error); } ``` @@ -183,27 +183,27 @@ first argument should be usable after the call or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... - jerry_value_t error = jerry_create_error_from_value (value, false); + jerry_value_t error = jerry_throw_value (value, false); // both 'error' and 'value' can be used and must be released when they are no longer needed - jerry_release_value (error); - jerry_release_value (value); + jerry_value_free (error); + jerry_value_free (value); } ``` ### jerry_value_has_error_flag -This function was renamed to [`jerry_value_is_error`](02.API-REFERENCE.md#jerry_value_is_error). +This function was renamed to [`jerry_value_is_exception`](02.API-REFERENCE.md#jerry_value_is_exception). **Before** ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... if (jerry_value_has_error_flag (value)) @@ -211,7 +211,7 @@ This function was renamed to [`jerry_value_is_error`](02.API-REFERENCE.md#jerry // ... } - jerry_release_value (value); + jerry_value_free (value); } ``` @@ -220,21 +220,21 @@ This function was renamed to [`jerry_value_is_error`](02.API-REFERENCE.md#jerry ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... - if (jerry_value_is_error (value)) + if (jerry_value_is_exception (value)) { // ... } - jerry_release_value (value); + jerry_value_free (value); } ``` ### jerry_value_clear_error_flag AND jerry_get_value_without_error_flag -These functions were merged into [`jerry_get_value_from_error`](02.API-REFERENCE.md#jerry_get_value_from_error). +These functions were merged into [`jerry_exception_value`](02.API-REFERENCE.md#jerry_exception_value). Please note the second argument of the new function which controls if the first argument passed should be released or not. @@ -243,7 +243,7 @@ or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... jerry_value_set_error_flag (&value); @@ -251,8 +251,8 @@ or not. // or jerry_value_t real_value = jerry_get_value_without_error_flag (value); - jerry_release_value (value); - jerry_release_value (real_value); + jerry_value_free (value); + jerry_value_free (real_value); } ``` @@ -261,14 +261,14 @@ or not. ```c { jerry_value_t value; - // create or acquire value + // create or copy value // ... - jerry_value_t error = jerry_create_error_from_value (value, true); + jerry_value_t error = jerry_throw_value (value, true); - jerry_value_t real_value = jerry_get_value_from_error (error, true); + jerry_value_t real_value = jerry_exception_value (error, true); - jerry_release_value (real_value); + jerry_value_free (real_value); } ``` @@ -360,17 +360,17 @@ if there was no problem the return value is a number value containing the snapsh strlen ((const char *) code_to_snapshot_p), global_mode_snapshot_buffer, sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t)); - if (jerry_value_is_error (generate_result)) + if (jerry_value_is_exception (generate_result)) { // There was a problem during snapshot generation, for example there is a SyntaxError. // Use the "generate_result" to check the error. } else { - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); // use "global_mode_snapshot_buffer" } - jerry_release_value (generate_result); + jerry_value_free (generate_result); } ``` @@ -420,33 +420,33 @@ if there was no problem the return value is a number value containing the snapsh 0, func_snapshot_buffer, sizeof (func_snapshot_buffer) / sizeof (uint32_t)); - if (jerry_value_is_error (generate_result)) + if (jerry_value_is_exception (generate_result)) { // There was a problem during snapshot generation, for example there is a SyntaxError. // Use the "generate_result" to check the error. } else { - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); // use "func_snapshot_buffer" } - jerry_release_value (generate_result) + jerry_value_free (generate_result) } ``` ## Garbage collection -### jerry_gc +### jerry_heap_gc -The [`jerry_gc`](02.API-REFERENCE.md#jerry_gc) function was modified to handle an argument which represents the pressure for the garbage collector. +The [`jerry_heap_gc`](02.API-REFERENCE.md#jerry_heap_gc) function was modified to handle an argument which represents the pressure for the garbage collector. For more information checkout the [`jerry_gc_mode_t`](02.API-REFERENCE.md#jerry_gc_mode_t) reference. **Before** ```c { - jerry_gc (); + jerry_heap_gc (); } ``` @@ -454,7 +454,7 @@ For more information checkout the [`jerry_gc_mode_t`](02.API-REFERENCE.md#jerry_ ```c { - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); } ``` @@ -546,8 +546,8 @@ can be accessed with the corresponding The old functions were removed and replaced by new ones. - `jerry_object_free_callback_t` callback type is replaced by `jerry_object_native_info_t` -- `jerry_get_object_native_handle` is replaced by [`jerry_get_object_native_pointer`](02.API-REFERENCE.md#jerry_get_object_native_pointer) -- `jerry_set_object_native_handle` is replaced by [`jerry_set_object_native_pointer`](02.API-REFERENCE.md#jerry_set_object_native_pointer) +- `jerry_get_object_native_handle` is replaced by [`jerry_object_get_native_ptr`](02.API-REFERENCE.md#jerry_object_get_native_ptr) +- `jerry_set_object_native_handle` is replaced by [`jerry_object_set_native_ptr`](02.API-REFERENCE.md#jerry_object_set_native_ptr) **Before** @@ -571,7 +571,7 @@ void demo (void) { jerry_value_t this_val; - // create or acquire this_val + // create or copy this_val // ... struct my_info *info = (struct my_info *) malloc (sizeof (struct my_info)); @@ -621,20 +621,20 @@ void demo (void) { jerry_value_t this_val; - // create or acquire this_val + // create or copy this_val // ... struct my_info *info = (struct my_info *) malloc (sizeof (struct my_info)); info->data = 11; // setting the native handle - jerry_set_object_native_pointer (this_val, - info, - &my_info_type_info); + jerry_object_set_native_ptr (this_val, + info, + &my_info_type_info); // ... // reading back the native handle pointed by the "my_info_type_info" variable void *ptr = NULL; - bool has_p = jerry_get_object_native_pointer (this_val, &ptr, &my_info_type_info); + bool has_p = jerry_object_get_native_ptr (this_val, &ptr, &my_info_type_info); if (has_p) { struct my_info *obj_info = (struct my_info *) ptr; @@ -651,15 +651,15 @@ In this section the new API functions are listed. ***ArrayBuffer*** -- [`jerry_create_arraybuffer`](02.API-REFERENCE.md#jerry_create_arraybuffer) -- [`jerry_create_arraybuffer_external`](02.API-REFERENCE.md#jerry_create_arraybuffer_external) -- [`jerry_get_arraybuffer_pointer`](02.API-REFERENCE.md#jerry_get_arraybuffer_pointer) +- [`jerry_arraybuffer`](02.API-REFERENCE.md#jerry_arraybuffer) +- [`jerry_arraybuffer_external`](02.API-REFERENCE.md#jerry_arraybuffer_external) +- [`jerry_arraybuffer_data`](02.API-REFERENCE.md#jerry_arraybuffer_data) ***DataView*** -- [`jerry_create_dataview`](02.API-REFERENCE.md#jerry_create_dataview) +- [`jerry_dataview`](02.API-REFERENCE.md#jerry_dataview) - [`jerry_value_is_dataview`](02.API-REFERENCE.md#jerry_value_is_dataview) -- [`jerry_get_dataview_buffer`](02.API-REFERENCE.md#jerry_get_dataview_buffer) +- [`jerry_dataview_buffer`](02.API-REFERENCE.md#jerry_dataview_buffer) ***JSON*** @@ -668,43 +668,42 @@ In this section the new API functions are listed. ***Number*** -- [`jerry_create_number_infinity`](02.API-REFERENCE.md#jerry_create_number_infinity) -- [`jerry_create_number_nan`](02.API-REFERENCE.md#jerry_create_number_nan) +- [`jerry_infinity`](02.API-REFERENCE.md#jerry_infinity) +- [`jerry_nan`](02.API-REFERENCE.md#jerry_nan) ***Promise*** -- [`jerry_run_all_enqueued_jobs`](02.API-REFERENCE.md#jerry_run_all_enqueued_jobs) -- [`jerry_create_promise`](02.API-REFERENCE.md#jerry_create_promise) +- [`jerry_run_microtasks`](02.API-REFERENCE.md#jerry_run_microtasks) +- [`jerry_promise`](02.API-REFERENCE.md#jerry_promise) - [`jerry_resolve_or_reject_promise`](02.API-REFERENCE.md#jerry_resolve_or_reject_promise) - [`jerry_value_is_promise`](02.API-REFERENCE.md#jerry_value_is_promise) ***RegExp*** -- [`jerry_create_regexp`](02.API-REFERENCE.md#jerry_create_regexp) -- [`jerry_create_regexp_sz`](02.API-REFERENCE.md#jerry_create_regexp_sz) +- [`jerry_regexp_sz`](02.API-REFERENCE.md#jerry_regexp_sz) +- [`jerry_regexp_sz_sz`](02.API-REFERENCE.md#jerry_regexp_sz_sz) ***String*** -- [`jerry_substring_to_utf8_char_buffer`](02.API-REFERENCE.md#jerry_substring_to_utf8_char_buffer) -- [`jerry_get_utf8_string_size`](02.API-REFERENCE.md#jerry_get_utf8_string_size) -- [`jerry_get_utf8_string_length`](02.API-REFERENCE.md#jerry_get_utf8_string_length) -- [`jerry_create_string_from_utf8`](02.API-REFERENCE.md#jerry_create_string_from_utf8) -- [`jerry_create_string_sz_from_utf8`](02.API-REFERENCE.md#jerry_create_string_sz_from_utf8) +- [`jerry_string_size`](02.API-REFERENCE.md#jerry_string_size) +- [`jerry_string_length`](02.API-REFERENCE.md#jerry_string_length) +- [`jerry_string`](02.API-REFERENCE.md#jerry_string) +- [`jerry_string_sz`](02.API-REFERENCE.md#jerry_string_sz) ***Symbol*** -- [`jerry_create_symbol`](02.API-REFERENCE.md#jerry_create_symbol) -- [`jerry_get_symbol_descriptive_string`](02.API-REFERENCE.md#jerry_get_symbol_descriptive_string) +- [`jerry_symbol`](02.API-REFERENCE.md#jerry_symbol) +- [`jerry_symbol_descriptive_string`](02.API-REFERENCE.md#jerry_symbol_descriptive_string) - [`jerry_value_is_symbol`](02.API-REFERENCE.md#jerry_value_is_symbol) ***TypedArray*** -- [`jerry_create_typedarray`](02.API-REFERENCE.md#jerry_create_typedarray) -- [`jerry_create_typedarray_for_arraybuffer`](02.API-REFERENCE.md#jerry_create_typedarray_for_arraybuffer) -- [`jerry_create_typedarray_for_arraybuffer_sz`](02.API-REFERENCE.md#jerry_create_typedarray_for_arraybuffer_sz) -- [`jerry_get_typedarray_type`](02.API-REFERENCE.md#jerry_get_typedarray_type) -- [`jerry_get_typedarray_length`](02.API-REFERENCE.md#jerry_get_typedarray_length) -- [`jerry_get_typedarray_buffer`](02.API-REFERENCE.md#jerry_get_typedarray_buffer) +- [`jerry_typedarray`](02.API-REFERENCE.md#jerry_typedarray) +- [`jerry_typedarray_with_buffer`](02.API-REFERENCE.md#jerry_typedarray_with_buffer) +- [`jerry_typedarray_with_buffer_span`](02.API-REFERENCE.md#jerry_typedarray_with_buffer_span) +- [`jerry_typedarray_type`](02.API-REFERENCE.md#jerry_typedarray_type) +- [`jerry_typedarray_length`](02.API-REFERENCE.md#jerry_typedarray_length) +- [`jerry_typedarray_buffer`](02.API-REFERENCE.md#jerry_typedarray_buffer) - [`jerry_value_is_typedarray`](02.API-REFERENCE.md#jerry_value_is_typedarray) @@ -712,8 +711,8 @@ In this section the new API functions are listed. ***JerryScript instances*** -- [`jerry_create_context`](02.API-REFERENCE.md#jerry_create_context) -- [`jerry_get_context_data`](02.API-REFERENCE.md#jerry_get_context_data) +- [`jerry_context_create`](02.API-REFERENCE.md#jerry_context_create) +- [`jerry_context_data`](02.API-REFERENCE.md#jerry_context_data) ***Memory management*** @@ -725,22 +724,22 @@ In this section the new API functions are listed. ***Binary operations*** -- [`jerry_binary_operation`](02.API-REFERENCE.md#jerry_binary_operation) +- [`jerry_binary_op`](02.API-REFERENCE.md#jerry_binary_op) ***Error manipulating*** -- [`jerry_get_error_type`](02.API-REFERENCE.md#jerry_get_error_type) -- [`jerry_get_backtrace`](02.API-REFERENCE.md#jerry_get_backtrace) +- [`jerry_error_type`](02.API-REFERENCE.md#jerry_error_type) +- [`jerry_backtrace`](02.API-REFERENCE.md#jerry_backtrace) ***Native pointers*** -- [`jerry_delete_object_native_pointer`](02.API-REFERENCE.md#jerry_delete_object_native_pointer) -- [`jerry_objects_foreach_by_native_info`](02.API-REFERENCE.md#jerry_objects_foreach_by_native_info) +- [`jerry_object_delete_native_ptr`](02.API-REFERENCE.md#jerry_object_delete_native_ptr) +- [`jerry_foreach_live_object_with_info`](02.API-REFERENCE.md#jerry_foreach_live_object_with_info) ***Property*** -- [`jerry_delete_property_by_index`](02.API-REFERENCE.md#jerry_delete_property_by_index) -- [`jerry_objects_foreach`](02.API-REFERENCE.md#jerry_objects_foreach) +- [`jerry_object_delete_index`](02.API-REFERENCE.md#jerry_object_delete_index) +- [`jerry_foreach_live_object`](02.API-REFERENCE.md#jerry_foreach_live_object) ## Debugger @@ -756,9 +755,9 @@ In this section the new API functions are listed. ## Other -- [`jerry_is_feature_enabled`](02.API-REFERENCE.md#jerry_is_feature_enabled) +- [`jerry_feature_enabled`](02.API-REFERENCE.md#jerry_feature_enabled) - [`jerry_parse_and_save_literals`](02.API-REFERENCE.md#jerry_parse_and_save_literals) -- [`jerry_set_vm_exec_stop_callback`](02.API-REFERENCE.md#jerry_set_vm_exec_stop_callback) +- [`jerry_halt_cb`](02.API-REFERENCE.md#jerry_halt_cb) ## Port API functions diff --git a/jerry-core/api/jerry-debugger.c b/jerry-core/api/jerry-debugger.c index 1ced50293a..0d52f7a91a 100644 --- a/jerry-core/api/jerry-debugger.c +++ b/jerry-core/api/jerry-debugger.c @@ -103,7 +103,7 @@ jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t void *user_p, /**< user pointer passed to the callback */ jerry_value_t *return_value) /**< [out] parse and run return value */ { - *return_value = jerry_create_undefined (); + *return_value = jerry_undefined (); #if JERRY_DEBUGGER if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) @@ -146,13 +146,13 @@ jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t { JERRY_ASSERT (client_source_data_p != NULL); - jerry_char_t *resource_name_p = (jerry_char_t *) (client_source_data_p + 1); - size_t resource_name_size = strlen ((const char *) resource_name_p); + jerry_char_t *source_name_p = (jerry_char_t *) (client_source_data_p + 1); + size_t source_name_size = strlen ((const char *) source_name_p); - *return_value = callback_p (resource_name_p, - resource_name_size, - resource_name_p + resource_name_size + 1, - client_source_data_p->uint8_size - resource_name_size - 1, + *return_value = callback_p (source_name_p, + source_name_size, + source_name_p + source_name_size + 1, + client_source_data_p->uint8_size - source_name_size - 1, user_p); ret_type = JERRY_DEBUGGER_SOURCE_RECEIVED; diff --git a/jerry-core/api/jerry-snapshot.c b/jerry-core/api/jerry-snapshot.c index 04c33f45db..97841634ce 100644 --- a/jerry-core/api/jerry-snapshot.c +++ b/jerry-core/api/jerry-snapshot.c @@ -142,7 +142,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co size_t snapshot_buffer_size, /**< snapshot buffer size */ snapshot_globals_t *globals_p) /**< snapshot globals */ { - const jerry_char_t *error_buffer_too_small_p = (const jerry_char_t *) "Snapshot buffer too small"; + const char *error_buffer_too_small_p = "Snapshot buffer too small"; if (!ecma_is_value_empty (globals_p->snapshot_error)) { @@ -153,8 +153,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co if (globals_p->snapshot_buffer_write_offset > JERRY_SNAPSHOT_MAXIMUM_WRITE_OFFSET) { - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_maximum_snapshot_size); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_error_maximum_snapshot_size); return 0; } @@ -168,8 +167,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co #if JERRY_ESNEXT if (compiled_code_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS) { - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_tagged_template_literals); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_error_tagged_template_literals); return 0; } @@ -185,8 +183,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co /* Regular expression. */ if (globals_p->snapshot_buffer_write_offset + sizeof (ecma_compiled_code_t) > snapshot_buffer_size) { - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_buffer_too_small_p); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, error_buffer_too_small_p); return 0; } @@ -207,8 +204,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co buffer_p, buffer_size)) { - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_buffer_too_small_p); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, error_buffer_too_small_p); /* cannot return inside ECMA_FINALIZE_UTF8_STRING */ } @@ -242,7 +238,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co compiled_code_p, ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG)) { - globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_buffer_too_small_p); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, error_buffer_too_small_p); return 0; } @@ -316,7 +312,7 @@ static_snapshot_error_unsupported_literal (snapshot_globals_t *globals_p, /**< s ecma_object_t *error_object_p = ecma_new_standard_error (JERRY_ERROR_RANGE, ecma_stringbuilder_finalize (&builder)); - globals_p->snapshot_error = ecma_create_error_object_reference (error_object_p); + globals_p->snapshot_error = ecma_create_exception_from_object (error_object_p); } /* static_snapshot_error_unsupported_literal */ /** @@ -339,8 +335,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, if (globals_p->snapshot_buffer_write_offset >= JERRY_SNAPSHOT_MAXIMUM_WRITE_OFFSET) { - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_maximum_snapshot_size); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_error_maximum_snapshot_size); return 0; } @@ -354,8 +349,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, if (!CBC_IS_FUNCTION (compiled_code_p->status_flags)) { /* Regular expression literals are not supported. */ - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_regular_expression_not_supported); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_error_regular_expression_not_supported); return 0; } @@ -365,8 +359,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, compiled_code_p, ((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG)) { - globals_p->snapshot_error = - jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_snapshot_buffer_small); + globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_error_snapshot_buffer_small); return 0; } @@ -753,7 +746,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func if ((generate_snapshot_opts & ~allowed_options) != 0) { - return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_snapshot_flag_not_supported); + return jerry_throw_sz (JERRY_ERROR_RANGE, ecma_error_snapshot_flag_not_supported); } const ecma_compiled_code_t *bytecode_data_p = NULL; @@ -785,7 +778,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func if (JERRY_UNLIKELY (bytecode_data_p == NULL)) { - return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ECMA_ERR_MSG ("Unsupported compiled code")); + return jerry_throw_sz (JERRY_ERROR_RANGE, ECMA_ERR_MSG ("Unsupported compiled code")); } snapshot_globals_t globals; @@ -835,7 +828,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func &literals_num)) { JERRY_ASSERT (lit_map_p == NULL); - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) ecma_error_cannot_allocate_memory_literals); + return jerry_throw_sz (JERRY_ERROR_COMMON, ecma_error_cannot_allocate_memory_literals); } jerry_snapshot_set_offsets (buffer_p + (aligned_header_size / sizeof (uint32_t)), @@ -859,7 +852,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func JERRY_UNUSED (buffer_p); JERRY_UNUSED (buffer_size); - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Snapshot save is not supported"); + return jerry_throw_sz (JERRY_ERROR_COMMON, ECMA_ERR_MSG ("Snapshot save is not supported")); #endif /* JERRY_SNAPSHOT_SAVE */ } /* jerry_generate_snapshot */ @@ -867,7 +860,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func * Execute/load snapshot from specified buffer * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return result of bytecode - if run was successful * thrown error - otherwise @@ -890,7 +883,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ if ((exec_snapshot_opts & ~(allowed_opts)) != 0) { ecma_raise_range_error (ECMA_ERR_MSG ("Unsupported snapshot exec flags are specified")); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } const char *const invalid_version_error_p = "Invalid snapshot version or unsupported features present"; @@ -900,7 +893,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ if (snapshot_size <= sizeof (jerry_snapshot_header_t)) { ecma_raise_type_error (invalid_format_error_p); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } const jerry_snapshot_header_t *header_p = (const jerry_snapshot_header_t *) snapshot_data_p; @@ -909,19 +902,19 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ || !snapshot_check_global_flags (header_p->global_flags)) { ecma_raise_type_error (invalid_version_error_p); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } if (header_p->lit_table_offset > snapshot_size) { ecma_raise_type_error (invalid_version_error_p); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } if (func_index >= header_p->number_of_funcs) { ecma_raise_range_error (ECMA_ERR_MSG ("Function index is higher than maximum")); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } JERRY_ASSERT ((header_p->lit_table_offset % sizeof (uint32_t)) == 0); @@ -934,13 +927,13 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ if (!(exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_ALLOW_STATIC)) { ecma_raise_common_error (ECMA_ERR_MSG ("Static snapshots are not enabled")); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } if (exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_COPY_DATA) { ecma_raise_common_error (ECMA_ERR_MSG ("Static snapshots cannot be copied into memory")); - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } } else @@ -968,16 +961,16 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ #endif /* JERRY_BUILTIN_REALMS */ #if JERRY_RESOURCE_NAME - ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); + ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); if ((exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_HAS_RESOURCE) && option_values_p != NULL - && ecma_is_value_string (option_values_p->resource_name) > 0) + && ecma_is_value_string (option_values_p->source_name) > 0) { - ecma_ref_ecma_string (ecma_get_string_from_value (option_values_p->resource_name)); - resource_name = option_values_p->resource_name; + ecma_ref_ecma_string (ecma_get_string_from_value (option_values_p->source_name)); + source_name = option_values_p->source_name; } - script_p->resource_name = resource_name; + script_p->source_name = source_name; #endif /* JERRY_RESOURCE_NAME */ #if JERRY_FUNCTION_TO_STRING @@ -1050,7 +1043,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ if (ECMA_IS_VALUE_ERROR (ret_val)) { - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } return ret_val; @@ -1061,7 +1054,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */ JERRY_UNUSED (exec_snapshot_opts); JERRY_UNUSED (option_values_p); - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Snapshot execution is not supported"); + return jerry_throw_sz (JERRY_ERROR_COMMON, ECMA_ERR_MSG ("Snapshot execution is not supported")); #endif /* JERRY_SNAPSHOT_EXEC */ } /* jerry_exec_snapshot */ diff --git a/jerry-core/api/jerryscript.c b/jerry-core/api/jerryscript.c index 43b1d11ede..c160862ab0 100644 --- a/jerry-core/api/jerryscript.c +++ b/jerry-core/api/jerryscript.c @@ -103,7 +103,7 @@ JERRY_STATIC_ASSERT (((NUMBER_ARITHMETIC_SUBTRACTION + ECMA_NUMBER_ARITHMETIC_OP * Note: * By convention, there are some states when API could not be invoked. * - * The API can be and only be invoked when the ECMA_STATUS_API_AVAILABLE + * The API can be and only be invoked when the ECMA_STATUS_API_ENABLED * flag is set. * * This procedure checks whether the API is available, and terminates @@ -115,27 +115,31 @@ JERRY_STATIC_ASSERT (((NUMBER_ARITHMETIC_SUBTRACTION + ECMA_NUMBER_ARITHMETIC_OP * - between enter to and return from a native free callback */ static inline void JERRY_ATTR_ALWAYS_INLINE -jerry_assert_api_available (void) +jerry_assert_api_enabled (void) { - JERRY_ASSERT (JERRY_CONTEXT (status_flags) & ECMA_STATUS_API_AVAILABLE); -} /* jerry_assert_api_available */ + JERRY_ASSERT (JERRY_CONTEXT (status_flags) & ECMA_STATUS_API_ENABLED); +} /* jerry_assert_api_enabled */ /** * Turn on API availability */ static inline void JERRY_ATTR_ALWAYS_INLINE -jerry_make_api_available (void) +jerry_api_enable (void) { - JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_AVAILABLE; +#ifndef JERRY_NDEBUG + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_ENABLED; +#endif /* JERRY_NDEBUG */ } /* jerry_make_api_available */ /** * Turn off API availability */ static inline void JERRY_ATTR_ALWAYS_INLINE -jerry_make_api_unavailable (void) +jerry_api_disable (void) { - JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_API_AVAILABLE; +#ifndef JERRY_NDEBUG + JERRY_CONTEXT (status_flags) &= (uint32_t) ~ECMA_STATUS_API_ENABLED; +#endif /* JERRY_NDEBUG */ } /* jerry_make_api_unavailable */ /** @@ -144,28 +148,16 @@ jerry_make_api_unavailable (void) * @return return value for Jerry API functions */ static jerry_value_t -jerry_return (jerry_value_t value) /**< return value */ +jerry_return (const jerry_value_t value) /**< return value */ { if (ECMA_IS_VALUE_ERROR (value)) { - value = ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } return value; } /* jerry_return */ -/** - * Throw an API compatible return value. - * - * @return return value for Jerry API functions - */ -static inline jerry_value_t JERRY_ATTR_ALWAYS_INLINE -jerry_throw (jerry_value_t value) /**< return value */ -{ - JERRY_ASSERT (ECMA_IS_VALUE_ERROR (value)); - return ecma_create_error_reference_from_context (); -} /* jerry_throw */ - /** * Jerry engine initialization */ @@ -173,7 +165,7 @@ void jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ { /* This function cannot be called twice unless jerry_cleanup is called. */ - JERRY_ASSERT (!(JERRY_CONTEXT (status_flags) & ECMA_STATUS_API_AVAILABLE)); + JERRY_ASSERT (!(JERRY_CONTEXT (status_flags) & ECMA_STATUS_API_ENABLED)); /* Zero out all non-external members. */ memset ((char *) &JERRY_CONTEXT_STRUCT + offsetof (jerry_context_t, JERRY_CONTEXT_FIRST_MEMBER), @@ -182,7 +174,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ JERRY_CONTEXT (jerry_init_flags) = flags; - jerry_make_api_available (); + jerry_api_enable (); jmem_init (); ecma_init (); @@ -194,7 +186,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ void jerry_cleanup (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_DEBUGGER if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) @@ -218,7 +210,7 @@ jerry_cleanup (void) ecma_free_all_enqueued_jobs (); #endif /* JERRY_ESNEXT */ ecma_finalize (); - jerry_make_api_unavailable (); + jerry_api_disable (); for (jerry_context_data_header_t *this_p = JERRY_CONTEXT (context_data_p), *next_p = NULL; this_p != NULL; this_p = next_p) @@ -244,7 +236,7 @@ jerry_cleanup (void) * none was found. */ void * -jerry_get_context_data (const jerry_context_data_manager_t *manager_p) +jerry_context_data (const jerry_context_data_manager_t *manager_p) { void *ret = NULL; jerry_context_data_header_t *item_p; @@ -274,20 +266,20 @@ jerry_get_context_data (const jerry_context_data_manager_t *manager_p) } return ret; -} /* jerry_get_context_data */ +} /* jerry_context_data */ /** * Register external magic string array */ void -jerry_register_magic_strings (const jerry_char_t *const *ex_str_items_p, /**< character arrays, representing - * external magic strings' contents */ +jerry_register_magic_strings (const jerry_char_t *const *ext_strings_p, /**< character arrays, representing + * external magic strings' contents */ uint32_t count, /**< number of the strings */ const jerry_length_t *str_lengths_p) /**< lengths of all strings */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - lit_magic_strings_ex_set ((const lit_utf8_byte_t *const *) ex_str_items_p, + lit_magic_strings_ex_set ((const lit_utf8_byte_t *const *) ext_strings_p, count, (const lit_utf8_size_t *) str_lengths_p); } /* jerry_register_magic_strings */ @@ -296,9 +288,9 @@ jerry_register_magic_strings (const jerry_char_t *const *ex_str_items_p, /**< ch * Run garbage collection */ void -jerry_gc (jerry_gc_mode_t mode) /**< operational mode */ +jerry_heap_gc (jerry_gc_mode_t mode) /**< operational mode */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (mode == JERRY_GC_PRESSURE_LOW) { @@ -308,7 +300,7 @@ jerry_gc (jerry_gc_mode_t mode) /**< operational mode */ } ecma_free_unused_memory (JMEM_PRESSURE_HIGH); -} /* jerry_gc */ +} /* jerry_heap_gc */ /** * Get heap memory stats. @@ -317,7 +309,7 @@ jerry_gc (jerry_gc_mode_t mode) /**< operational mode */ * false - otherwise. Usually it is because the MEM_STATS feature is not enabled. */ bool -jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p) /**< [out] heap memory stats */ +jerry_heap_stats (jerry_heap_stats_t *out_stats_p) /**< [out] heap memory stats */ { #if JERRY_MEM_STATS if (out_stats_p == NULL) @@ -339,45 +331,9 @@ jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p) /**< [out] heap memory JERRY_UNUSED (out_stats_p); return false; #endif /* JERRY_MEM_STATS */ -} /* jerry_get_memory_stats */ - -/** - * Simple Jerry runner - * - * @return true - if run was successful - * false - otherwise - */ -bool -jerry_run_simple (const jerry_char_t *script_source_p, /**< script source */ - size_t script_source_size, /**< script source size */ - jerry_init_flag_t flags) /**< combination of Jerry flags */ -{ - bool result = false; - - jerry_init (flags); - - jerry_value_t parse_ret_val = jerry_parse (script_source_p, script_source_size, NULL); - - if (!ecma_is_value_error_reference (parse_ret_val)) - { - jerry_value_t run_ret_val = jerry_run (parse_ret_val); - - if (!ecma_is_value_error_reference (run_ret_val)) - { - result = true; - } - - jerry_release_value (run_ret_val); - } - - jerry_release_value (parse_ret_val); - jerry_cleanup (); - - return result; -} /* jerry_run_simple */ +} /* jerry_heap_stats */ #if JERRY_PARSER - /** * Common code for parsing a script, module, or function. * @@ -389,35 +345,36 @@ jerry_parse_common (void *source_p, /**< script source */ const jerry_parse_options_t *options_p, /**< parsing options, can be NULL if not used */ uint32_t parse_opts) /**< internal parsing options */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (options_p != NULL) { - const uint32_t allowed_options = (JERRY_PARSE_STRICT_MODE | JERRY_PARSE_MODULE | JERRY_PARSE_HAS_ARGUMENT_LIST - | JERRY_PARSE_HAS_RESOURCE | JERRY_PARSE_HAS_START | JERRY_PARSE_HAS_USER_VALUE); + const uint32_t allowed_options = + (JERRY_PARSE_STRICT_MODE | JERRY_PARSE_MODULE | JERRY_PARSE_HAS_ARGUMENT_LIST | JERRY_PARSE_HAS_SOURCE_NAME + | JERRY_PARSE_HAS_START | JERRY_PARSE_HAS_USER_VALUE); uint32_t options = options_p->options; if ((options & ~allowed_options) != 0 || ((options_p->options & JERRY_PARSE_HAS_ARGUMENT_LIST) && ((options_p->options & JERRY_PARSE_MODULE) || !ecma_is_value_string (options_p->argument_list))) - || ((options_p->options & JERRY_PARSE_HAS_RESOURCE) && !ecma_is_value_string (options_p->resource_name))) + || ((options_p->options & JERRY_PARSE_HAS_SOURCE_NAME) && !ecma_is_value_string (options_p->source_name))) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } } #if JERRY_DEBUGGER if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) && options_p != NULL - && (options_p->options & JERRY_PARSE_HAS_RESOURCE) && ecma_is_value_string (options_p->resource_name)) + && (options_p->options & JERRY_PARSE_HAS_SOURCE_NAME) && ecma_is_value_string (options_p->source_name)) { - ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (options_p->resource_name), - resource_name_start_p, - resource_name_size); + ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (options_p->source_name), + source_name_start_p, + source_name_size); jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME, JERRY_DEBUGGER_NO_SUBTYPE, - resource_name_start_p, - resource_name_size); - ECMA_FINALIZE_UTF8_STRING (resource_name_start_p, resource_name_size); + source_name_start_p, + source_name_size); + ECMA_FINALIZE_UTF8_STRING (source_name_start_p, source_name_size); } #endif /* JERRY_DEBUGGER */ @@ -431,7 +388,7 @@ jerry_parse_common (void *source_p, /**< script source */ #if JERRY_MODULE_SYSTEM JERRY_CONTEXT (module_current_p) = ecma_module_create (); #else /* !JERRY_MODULE_SYSTEM */ - return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ } @@ -447,7 +404,7 @@ jerry_parse_common (void *source_p, /**< script source */ } #endif /* JERRY_MODULE_SYSTEM */ - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } #if JERRY_MODULE_SYSTEM @@ -510,7 +467,7 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */ JERRY_UNUSED (source_size); JERRY_UNUSED (options_p); - return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (ecma_error_parser_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG (ecma_error_parser_not_supported_p)); #endif /* JERRY_PARSER */ } /* jerry_parse */ @@ -521,24 +478,21 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */ * thrown error - otherwise */ jerry_value_t -jerry_parse_value (const jerry_value_t source_value, /**< script source */ +jerry_parse_value (const jerry_value_t source, /**< script source */ const jerry_parse_options_t *options_p) /**< parsing options, can be NULL if not used */ { #if JERRY_PARSER - if (!ecma_is_value_string (source_value)) + if (!ecma_is_value_string (source)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_value_t source[1]; - source[0] = source_value; - - return jerry_parse_common ((void *) source, options_p, ECMA_PARSE_HAS_SOURCE_VALUE); + return jerry_parse_common ((void *) &source, options_p, ECMA_PARSE_HAS_SOURCE_VALUE); #else /* !JERRY_PARSER */ - JERRY_UNUSED (source_value); + JERRY_UNUSED (source); JERRY_UNUSED (options_p); - return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (ecma_error_parser_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG (ecma_error_parser_not_supported_p)); #endif /* JERRY_PARSER */ } /* jerry_parse_value */ @@ -546,26 +500,26 @@ jerry_parse_value (const jerry_value_t source_value, /**< script source */ * Run a Script or Module created by jerry_parse. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return result of bytecode - if run was successful * thrown error - otherwise */ jerry_value_t -jerry_run (const jerry_value_t func_val) /**< function to run */ +jerry_run (const jerry_value_t script) /**< script or module to run */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (func_val)) + if (!ecma_is_value_object (script)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_object_t *object_p = ecma_get_object_from_value (func_val); + ecma_object_t *object_p = ecma_get_object_from_value (script); if (!ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SCRIPT)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; @@ -582,46 +536,46 @@ jerry_run (const jerry_value_t func_val) /**< function to run */ * Perform eval * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return result of eval, may be error value. */ jerry_value_t jerry_eval (const jerry_char_t *source_p, /**< source code */ size_t source_size, /**< length of source code */ - uint32_t parse_opts) /**< jerry_parse_opts_t option bits */ + uint32_t flags) /**< jerry_parse_opts_t flags */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); uint32_t allowed_parse_options = JERRY_PARSE_STRICT_MODE; - if ((parse_opts & ~allowed_parse_options) != 0) + if ((flags & ~allowed_parse_options) != 0) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } parser_source_char_t source_char; source_char.source_p = source_p; source_char.source_size = source_size; - return jerry_return (ecma_op_eval_chars_buffer ((void *) &source_char, parse_opts)); + return jerry_return (ecma_op_eval_chars_buffer ((void *) &source_char, flags)); } /* jerry_eval */ /** * Link modules to their dependencies. The dependencies are resolved by a user callback. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true - if linking is successful, error - otherwise */ jerry_value_t -jerry_module_link (const jerry_value_t module_val, /**< root module */ - jerry_module_resolve_callback_t callback, /**< resolve module callback, uses - * jerry_port_module_resolve when NULL is passed */ +jerry_module_link (const jerry_value_t module, /**< root module */ + jerry_module_resolve_cb_t callback, /**< resolve module callback, uses + * jerry_port_module_resolve when NULL is passed */ void *user_p) /**< pointer passed to the resolve callback */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM if (callback == NULL) @@ -629,20 +583,20 @@ jerry_module_link (const jerry_value_t module_val, /**< root module */ callback = jerry_port_module_resolve; } - ecma_module_t *module_p = ecma_module_get_resolved_module (module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (module); if (module_p == NULL) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_not_module_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_not_module_p)); } return jerry_return (ecma_module_link (module_p, callback, user_p)); #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (module_val); + JERRY_UNUSED (module); JERRY_UNUSED (callback); JERRY_UNUSED (user_p); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ } /* jerry_module_link */ @@ -650,50 +604,50 @@ jerry_module_link (const jerry_value_t module_val, /**< root module */ * Evaluate a module and its dependencies. The module must be in linked state. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return result of module bytecode execution - if evaluation was successful * error - otherwise */ jerry_value_t -jerry_module_evaluate (const jerry_value_t module_val) /**< root module */ +jerry_module_evaluate (const jerry_value_t module) /**< root module */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (module); if (module_p == NULL) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_not_module_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_not_module_p)); } if (module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_LINKED) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Module must be in linked state"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Module must be in linked state")); } return jerry_return (ecma_module_evaluate (module_p)); #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (module_val); + JERRY_UNUSED (module); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ } /* jerry_module_evaluate */ /** * Returns the current status of a module * - * @return current status - if module_val is a module, + * @return current status - if module is a module, * JERRY_MODULE_STATE_INVALID - otherwise */ jerry_module_state_t -jerry_module_get_state (const jerry_value_t module_val) /**< module object */ +jerry_module_state (const jerry_value_t module) /**< module object */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (module); if (module_p == NULL) { @@ -702,20 +656,20 @@ jerry_module_get_state (const jerry_value_t module_val) /**< module object */ return (jerry_module_state_t) module_p->header.u.cls.u1.module_state; #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (module_val); + JERRY_UNUSED (module); return JERRY_MODULE_STATE_INVALID; #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_get_state */ +} /* jerry_module_state */ /** * Sets a callback which is called after a module state is changed to linked, evaluated, or error. */ void -jerry_module_set_state_changed_callback (jerry_module_state_changed_callback_t callback, /**< callback */ - void *user_p) /**< pointer passed to the callback */ +jerry_module_state_changed_cb (jerry_module_state_changed_cb_t callback, /**< callback */ + void *user_p) /**< pointer passed to the callback */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM JERRY_CONTEXT (module_state_changed_callback_p) = callback; @@ -724,16 +678,16 @@ jerry_module_set_state_changed_callback (jerry_module_state_changed_callback_t c JERRY_UNUSED (callback); JERRY_UNUSED (user_p); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_set_state_changed_callback */ +} /* jerry_module_state_changed_cb */ /** * Sets a callback which is called when an import.meta expression of a module is evaluated the first time. */ void -jerry_module_set_import_meta_callback (jerry_module_import_meta_callback_t callback, /**< callback */ - void *user_p) /**< pointer passed to the callback */ +jerry_module_import_meta_cb (jerry_module_import_meta_cb_t callback, /**< callback */ + void *user_p) /**< pointer passed to the callback */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM JERRY_CONTEXT (module_import_meta_callback_p) = callback; @@ -742,7 +696,7 @@ jerry_module_set_import_meta_callback (jerry_module_import_meta_callback_t callb JERRY_UNUSED (callback); JERRY_UNUSED (user_p); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_set_import_meta_callback */ +} /* jerry_module_import_meta_cb */ /** * Returns the number of import/export requests of a module @@ -750,12 +704,12 @@ jerry_module_set_import_meta_callback (jerry_module_import_meta_callback_t callb * @return number of import/export requests of a module */ size_t -jerry_module_get_number_of_requests (const jerry_value_t module_val) /**< module */ +jerry_module_request_count (const jerry_value_t module) /**< module */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (module); if (module_p == NULL) { @@ -774,34 +728,34 @@ jerry_module_get_number_of_requests (const jerry_value_t module_val) /**< module return number_of_requests; #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (module_val); + JERRY_UNUSED (module); return 0; #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_get_number_of_requests */ +} /* jerry_module_request_count */ /** * Returns the module request specified by the request_index argument * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return string - if the request has not been resolved yet, * module object - if the request has been resolved successfully, * error - otherwise */ jerry_value_t -jerry_module_get_request (const jerry_value_t module_val, /**< module */ - size_t request_index) /**< request index */ +jerry_module_request (const jerry_value_t module, /**< module */ + size_t request_index) /**< request index */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (module); if (module_p == NULL) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_not_module_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_not_module_p)); } ecma_module_node_t *node_p = module_p->imports_p; @@ -817,41 +771,41 @@ jerry_module_get_request (const jerry_value_t module_val, /**< module */ node_p = node_p->next_p; } - return jerry_throw (ecma_raise_range_error (ECMA_ERR_MSG ("Request is not available"))); + return jerry_throw_sz (JERRY_ERROR_RANGE, ECMA_ERR_MSG ("Request is not available")); #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (module_val); + JERRY_UNUSED (module); JERRY_UNUSED (request_index); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_get_request */ +} /* jerry_module_request */ /** * Returns the namespace object of a module * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return object - if namespace object is available, * error - otherwise */ jerry_value_t -jerry_module_get_namespace (const jerry_value_t module_val) /**< module */ +jerry_module_namespace (const jerry_value_t module) /**< module */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (module); if (module_p == NULL) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_not_module_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_not_module_p)); } if (module_p->header.u.cls.u1.module_state < JERRY_MODULE_STATE_LINKED || module_p->header.u.cls.u1.module_state > JERRY_MODULE_STATE_EVALUATED) { - return jerry_throw (ecma_raise_range_error (ECMA_ERR_MSG ("Namespace object is not available"))); + return jerry_throw_sz (JERRY_ERROR_RANGE, ECMA_ERR_MSG ("Namespace object is not available")); } JERRY_ASSERT (module_p->namespace_object_p != NULL); @@ -859,21 +813,21 @@ jerry_module_get_namespace (const jerry_value_t module_val) /**< module */ ecma_ref_object (module_p->namespace_object_p); return ecma_make_object_value (module_p->namespace_object_p); #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (module_val); + JERRY_UNUSED (module); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_get_namespace */ +} /* jerry_module_namespace */ /** * Sets the callback which is called when dynamic imports are resolved */ void -jerry_module_set_import_callback (jerry_module_import_callback_t callback_p, /**< callback which handles - * dynamic import calls */ - void *user_p) /**< user pointer passed to the callback */ +jerry_module_import_cb (jerry_module_import_cb_t callback_p, /**< callback which handles + * dynamic import calls */ + void *user_p) /**< user pointer passed to the callback */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM JERRY_CONTEXT (module_import_callback_p) = callback_p; @@ -882,38 +836,38 @@ jerry_module_set_import_callback (jerry_module_import_callback_t callback_p, /** JERRY_UNUSED (callback_p); JERRY_UNUSED (user_p); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_module_set_import_callback */ +} /* jerry_module_import_cb */ /** * Creates a native module with a list of exports. The initial state of the module is linked. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return native module - if the module is successfully created, * error - otherwise */ jerry_value_t -jerry_native_module_create (jerry_native_module_evaluate_callback_t callback, /**< evaluation callback for - * native modules */ - const jerry_value_t *const exports_p, /**< list of the exported bindings of the module, - * must be valid string identifiers */ - size_t number_of_exports) /**< number of exports in the exports_p list */ +jerry_native_module (jerry_native_module_evaluate_cb_t callback, /**< evaluation callback for + * native modules */ + const jerry_value_t *const exports_p, /**< list of the exported bindings of the module, + * must be valid string identifiers */ + size_t export_count) /**< number of exports in the exports_p list */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM ecma_object_t *global_object_p = ecma_builtin_get_global (); ecma_object_t *scope_p = ecma_create_decl_lex_env (ecma_get_global_environment (global_object_p)); ecma_module_names_t *local_exports_p = NULL; - for (size_t i = 0; i < number_of_exports; i++) + for (size_t i = 0; i < export_count; i++) { if (!ecma_is_value_string (exports_p[i])) { ecma_deref_object (scope_p); ecma_module_release_module_names (local_exports_p); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Module exports must be string values"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Module exports must be string values")); } ecma_string_t *name_str_p = ecma_get_string_from_value (exports_p[i]); @@ -957,7 +911,7 @@ jerry_native_module_create (jerry_native_module_evaluate_callback_t callback, /* { ecma_deref_object (scope_p); ecma_module_release_module_names (local_exports_p); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Module exports must be valid identifiers"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Module exports must be valid identifiers")); } if (ecma_find_named_property (scope_p, name_str_p) != NULL) @@ -994,142 +948,140 @@ jerry_native_module_create (jerry_native_module_evaluate_callback_t callback, /* #else /* !JERRY_MODULE_SYSTEM */ JERRY_UNUSED (callback); JERRY_UNUSED (exports_p); - JERRY_UNUSED (number_of_exports); + JERRY_UNUSED (export_count); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_native_module_create */ +} /* jerry_native_module */ /** * Gets the value of an export which belongs to a native module. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the export - if success * error - otherwise */ jerry_value_t -jerry_native_module_get_export (const jerry_value_t native_module_val, /**< a native module object */ - const jerry_value_t export_name_val) /**< string identifier of the export */ +jerry_native_module_get (const jerry_value_t native_module, /**< a native module object */ + const jerry_value_t export_name) /**< string identifier of the export */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (native_module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (native_module); if (module_p == NULL) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_not_module_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_not_module_p)); } - if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name_val)) + if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_property_t *property_p = - ecma_find_named_property (module_p->scope_p, ecma_get_string_from_value (export_name_val)); + ecma_property_t *property_p = ecma_find_named_property (module_p->scope_p, ecma_get_string_from_value (export_name)); if (property_p == NULL) { - return jerry_throw (ecma_raise_reference_error (ECMA_ERR_MSG (ecma_error_unknown_export_p))); + return jerry_throw_sz (JERRY_ERROR_REFERENCE, ECMA_ERR_MSG (ecma_error_unknown_export_p)); } return ecma_copy_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value); #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (native_module_val); - JERRY_UNUSED (export_name_val); + JERRY_UNUSED (native_module); + JERRY_UNUSED (export_name); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_native_module_get_export */ +} /* jerry_native_module_get */ /** * Sets the value of an export which belongs to a native module. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful * error - otherwise */ jerry_value_t -jerry_native_module_set_export (const jerry_value_t native_module_val, /**< a native module object */ - const jerry_value_t export_name_val, /**< string identifier of the export */ - const jerry_value_t value_to_set) /**< new value of the export */ +jerry_native_module_set (jerry_value_t native_module, /**< a native module object */ + const jerry_value_t export_name, /**< string identifier of the export */ + const jerry_value_t value) /**< new value of the export */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_MODULE_SYSTEM - ecma_module_t *module_p = ecma_module_get_resolved_module (native_module_val); + ecma_module_t *module_p = ecma_module_get_resolved_module (native_module); if (module_p == NULL) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_not_module_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_not_module_p)); } - if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name_val) - || ecma_is_value_error_reference (value_to_set)) + if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE) || !ecma_is_value_string (export_name) + || ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_property_t *property_p = - ecma_find_named_property (module_p->scope_p, ecma_get_string_from_value (export_name_val)); + ecma_property_t *property_p = ecma_find_named_property (module_p->scope_p, ecma_get_string_from_value (export_name)); if (property_p == NULL) { - return jerry_throw (ecma_raise_reference_error (ECMA_ERR_MSG (ecma_error_unknown_export_p))); + return jerry_throw_sz (JERRY_ERROR_REFERENCE, ECMA_ERR_MSG (ecma_error_unknown_export_p)); } - ecma_named_data_property_assign_value (module_p->scope_p, ECMA_PROPERTY_VALUE_PTR (property_p), value_to_set); + ecma_named_data_property_assign_value (module_p->scope_p, ECMA_PROPERTY_VALUE_PTR (property_p), value); return ECMA_VALUE_TRUE; #else /* !JERRY_MODULE_SYSTEM */ - JERRY_UNUSED (native_module_val); - JERRY_UNUSED (export_name_val); - JERRY_UNUSED (value_to_set); + JERRY_UNUSED (native_module); + JERRY_UNUSED (export_name); + JERRY_UNUSED (value); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_module_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_module_not_supported_p)); #endif /* JERRY_MODULE_SYSTEM */ -} /* jerry_native_module_set_export */ +} /* jerry_native_module_set */ /** - * Run enqueued Promise jobs until the first thrown error or until all get executed. + * Run enqueued microtasks created by Promise or AsyncFunction objects. + * Tasks are executed until an exception is thrown or all tasks are executed. * - * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * Note: returned value must be freed with jerry_value_free * - * @return result of last executed job, may be error value. + * @return result of last executed job, possibly an exception. */ jerry_value_t -jerry_run_all_enqueued_jobs (void) +jerry_run_microtasks (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT return ecma_process_all_enqueued_jobs (); #else /* !JERRY_ESNEXT */ return ECMA_VALUE_UNDEFINED; #endif /* JERRY_ESNEXT */ -} /* jerry_run_all_enqueued_jobs */ +} /* jerry_run_microtasks */ /** * Get global object * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return api value of global object */ jerry_value_t -jerry_get_global_object (void) +jerry_current_realm (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); ecma_object_t *global_obj_p = ecma_builtin_get_global (); ecma_ref_object (global_obj_p); return ecma_make_object_value (global_obj_p); -} /* jerry_get_global_object */ +} /* jerry_current_realm */ /** * Check if the specified value is an abort value. @@ -1140,16 +1092,16 @@ jerry_get_global_object (void) bool jerry_value_is_abort (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_error_reference (value)) + if (!ecma_is_value_exception (value)) { return false; } ecma_extended_primitive_t *error_ref_p = ecma_get_extended_primitive_from_value (value); - return (error_ref_p->refs_and_type & ECMA_ERROR_API_ABORT) != 0; + return (error_ref_p->refs_and_type & ECMA_ERROR_API_FLAG_ABORT) != 0; } /* jerry_value_is_abort */ /** @@ -1161,7 +1113,7 @@ jerry_value_is_abort (const jerry_value_t value) /**< api value */ bool jerry_value_is_array (const jerry_value_t value) /**< jerry api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return (ecma_is_value_object (value) && ecma_get_object_base_type (ecma_get_object_from_value (value)) == ECMA_OBJECT_BASE_TYPE_ARRAY); @@ -1176,7 +1128,7 @@ jerry_value_is_array (const jerry_value_t value) /**< jerry api value */ bool jerry_value_is_boolean (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_boolean (value); } /* jerry_value_is_boolean */ @@ -1190,7 +1142,7 @@ jerry_value_is_boolean (const jerry_value_t value) /**< api value */ bool jerry_value_is_true (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_true (value); } /* jerry_value_is_true */ @@ -1204,7 +1156,7 @@ jerry_value_is_true (const jerry_value_t value) /**< api value */ bool jerry_value_is_false (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_false (value); } /* jerry_value_is_false */ @@ -1218,7 +1170,7 @@ jerry_value_is_false (const jerry_value_t value) /**< api value */ bool jerry_value_is_constructor (const jerry_value_t value) /**< jerry api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_constructor (value); } /* jerry_value_is_constructor */ @@ -1230,12 +1182,12 @@ jerry_value_is_constructor (const jerry_value_t value) /**< jerry api value */ * false - otherwise */ bool -jerry_value_is_error (const jerry_value_t value) /**< api value */ +jerry_value_is_exception (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - return ecma_is_value_error_reference (value); -} /* jerry_value_is_error */ + return ecma_is_value_exception (value); +} /* jerry_value_is_exception */ /** * Check if the specified value is a function object value. @@ -1246,7 +1198,7 @@ jerry_value_is_error (const jerry_value_t value) /**< api value */ bool jerry_value_is_function (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_op_is_callable (value); } /* jerry_value_is_function */ @@ -1260,7 +1212,7 @@ jerry_value_is_function (const jerry_value_t value) /**< api value */ bool jerry_value_is_async_function (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT if (ecma_is_value_object (value)) @@ -1292,7 +1244,7 @@ jerry_value_is_async_function (const jerry_value_t value) /**< api value */ bool jerry_value_is_number (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_number (value); } /* jerry_value_is_number */ @@ -1306,7 +1258,7 @@ jerry_value_is_number (const jerry_value_t value) /**< api value */ bool jerry_value_is_null (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_null (value); } /* jerry_value_is_null */ @@ -1320,7 +1272,7 @@ jerry_value_is_null (const jerry_value_t value) /**< api value */ bool jerry_value_is_object (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_object (value); } /* jerry_value_is_object */ @@ -1334,7 +1286,7 @@ jerry_value_is_object (const jerry_value_t value) /**< api value */ bool jerry_value_is_promise (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT return (ecma_is_value_object (value) && ecma_is_promise (ecma_get_object_from_value (value))); #else /* !JERRY_ESNEXT */ @@ -1352,7 +1304,7 @@ jerry_value_is_promise (const jerry_value_t value) /**< api value */ bool jerry_value_is_proxy (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_PROXY return (ecma_is_value_object (value) && ECMA_OBJECT_IS_PROXY (ecma_get_object_from_value (value))); #else /* !JERRY_BUILTIN_PROXY */ @@ -1370,7 +1322,7 @@ jerry_value_is_proxy (const jerry_value_t value) /**< api value */ bool jerry_value_is_string (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_string (value); } /* jerry_value_is_string */ @@ -1384,7 +1336,7 @@ jerry_value_is_string (const jerry_value_t value) /**< api value */ bool jerry_value_is_symbol (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT return ecma_is_value_symbol (value); @@ -1403,7 +1355,7 @@ jerry_value_is_symbol (const jerry_value_t value) /**< api value */ bool jerry_value_is_bigint (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_BIGINT return ecma_is_value_bigint (value); @@ -1422,7 +1374,7 @@ jerry_value_is_bigint (const jerry_value_t value) /**< api value */ bool jerry_value_is_undefined (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_value_undefined (value); } /* jerry_value_is_undefined */ @@ -1433,13 +1385,13 @@ jerry_value_is_undefined (const jerry_value_t value) /**< api value */ * @return jerry_type_t value */ jerry_type_t -jerry_value_get_type (const jerry_value_t value) /**< input value to check */ +jerry_value_type (const jerry_value_t value) /**< input value to check */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return JERRY_TYPE_ERROR; + return JERRY_TYPE_EXCEPTION; } lit_magic_string_id_t lit_id = ecma_get_typeof_lit_id (value); @@ -1490,10 +1442,10 @@ jerry_value_get_type (const jerry_value_t value) /**< input value to check */ return ecma_is_value_null (value) ? JERRY_TYPE_NULL : JERRY_TYPE_OBJECT; } } -} /* jerry_value_get_type */ +} /* jerry_value_type */ /** - * Used by jerry_object_get_type to get the type of class objects + * Used by jerry_object_type to get the type of class objects */ static const uint8_t jerry_class_object_type[] = { /* These objects require custom property resolving. */ @@ -1574,9 +1526,9 @@ JERRY_STATIC_ASSERT (sizeof (jerry_class_object_type) == ECMA_OBJECT_CLASS__MAX, * jerry_object_type_t value - otherwise */ jerry_object_type_t -jerry_object_get_type (const jerry_value_t value) /**< input value to check */ +jerry_object_type (const jerry_value_t value) /**< input value to check */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_object (value)) { @@ -1619,7 +1571,7 @@ jerry_object_get_type (const jerry_value_t value) /**< input value to check */ } return JERRY_OBJECT_TYPE_GENERIC; -} /* jerry_object_get_type */ +} /* jerry_object_type */ /** * Get the function type of the given value @@ -1628,9 +1580,9 @@ jerry_object_get_type (const jerry_value_t value) /**< input value to check */ * jerry_function_type_t value - otherwise */ jerry_function_type_t -jerry_function_get_type (const jerry_value_t value) /**< input value to check */ +jerry_function_type (const jerry_value_t value) /**< input value to check */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (ecma_is_value_object (value)) { @@ -1685,7 +1637,7 @@ jerry_function_get_type (const jerry_value_t value) /**< input value to check */ } return JERRY_FUNCTION_TYPE_NONE; -} /* jerry_function_get_type */ +} /* jerry_function_type */ /** * Get the itearator type of the given value @@ -1694,9 +1646,9 @@ jerry_function_get_type (const jerry_value_t value) /**< input value to check */ * jerry_iterator_type_t value - otherwise */ jerry_iterator_type_t -jerry_iterator_get_type (const jerry_value_t value) /**< input value to check */ +jerry_iterator_type (const jerry_value_t value) /**< input value to check */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT if (ecma_is_value_object (value)) @@ -1738,7 +1690,7 @@ jerry_iterator_get_type (const jerry_value_t value) /**< input value to check */ #endif /* JERRY_ESNEXT */ return JERRY_ITERATOR_TYPE_NONE; -} /* jerry_iterator_get_type */ +} /* jerry_iterator_type */ /** * Check if the specified feature is enabled. @@ -1747,7 +1699,7 @@ jerry_iterator_get_type (const jerry_value_t value) /**< input value to check */ * false - otherwise */ bool -jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check */ +jerry_feature_enabled (const jerry_feature_t feature) /**< feature to check */ { JERRY_ASSERT (feature < JERRY_FEATURE__COUNT); @@ -1762,7 +1714,7 @@ jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check * || feature == JERRY_FEATURE_JS_PARSER #endif /* JERRY_PARSER */ #if JERRY_MEM_STATS - || feature == JERRY_FEATURE_MEM_STATS + || feature == JERRY_FEATURE_HEAP_STATS #endif /* JERRY_MEM_STATS */ #if JERRY_PARSER_DUMP_BYTE_CODE || feature == JERRY_FEATURE_PARSER_DUMP @@ -1838,7 +1790,7 @@ jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check * || feature == JERRY_FEATURE_FUNCTION_TO_STRING #endif /* JERRY_FUNCTION_TO_STRING */ ); -} /* jerry_is_feature_enabled */ +} /* jerry_feature_enabled */ /** * Perform binary operation on the given operands (==, ===, <, >, etc.). @@ -1847,18 +1799,18 @@ jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check * * true/false - the result of the binary operation on the given operands otherwise */ jerry_value_t -jerry_binary_operation (jerry_binary_operation_t op, /**< operation */ - const jerry_value_t lhs, /**< first operand */ - const jerry_value_t rhs) /**< second operand */ +jerry_binary_op (jerry_binary_op_t operation, /**< operation */ + const jerry_value_t lhs, /**< first operand */ + const jerry_value_t rhs) /**< second operand */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (lhs) || ecma_is_value_error_reference (rhs)) + if (ecma_is_value_exception (lhs) || ecma_is_value_exception (rhs)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } - switch (op) + switch (operation) { case JERRY_BIN_OP_EQUAL: { @@ -1888,7 +1840,7 @@ jerry_binary_operation (jerry_binary_operation_t op, /**< operation */ { if (!ecma_is_value_object (lhs) || !ecma_op_is_callable (rhs)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } ecma_object_t *proto_obj_p = ecma_get_object_from_value (rhs); @@ -1903,137 +1855,128 @@ jerry_binary_operation (jerry_binary_operation_t op, /**< operation */ case JERRY_BIN_OP_DIV: case JERRY_BIN_OP_REM: { - return jerry_return (do_number_arithmetic (op - ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET, lhs, rhs)); + return jerry_return (do_number_arithmetic (operation - ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET, lhs, rhs)); } default: { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Unsupported binary operation"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Unsupported binary operation")); } } -} /* jerry_binary_operation */ +} /* jerry_binary_op */ /** - * Create abort from an api value. - * - * Create abort value from an api value. If the second argument is true - * it will release the input api value. + * Create an abort value containing the argument value. If the second argument is true + * the function will take ownership ofthe input value, otherwise the value will be copied. * * @return api abort value */ jerry_value_t -jerry_create_abort_from_value (jerry_value_t value, /**< api value */ - bool release) /**< release api value */ +jerry_throw_abort (jerry_value_t value, /**< api value */ + bool take_ownership) /**< release api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (value))) { /* This is a rare case so it is optimized for * binary size rather than performance. */ if (jerry_value_is_abort (value)) { - return release ? value : jerry_acquire_value (value); + return take_ownership ? value : jerry_value_copy (value); } - value = jerry_get_value_from_error (value, release); - release = true; + value = jerry_exception_value (value, take_ownership); + take_ownership = true; } - if (!release) + if (!take_ownership) { value = ecma_copy_value (value); } - return ecma_create_error_reference (value, ECMA_ERROR_API_ABORT); -} /* jerry_create_abort_from_value */ + return ecma_create_exception (value, ECMA_ERROR_API_FLAG_ABORT); +} /* jerry_throw_abort */ /** - * Create error from an api value. + * Create an exception value containing the argument value. If the second argument is true + * the function will take ownership ofthe input value, otherwise the value will be copied. * - * Create error value from an api value. If the second argument is true - * it will release the input api value. - * - * @return api error value + * @return exception value */ jerry_value_t -jerry_create_error_from_value (jerry_value_t value, /**< api value */ - bool release) /**< release api value */ +jerry_throw_value (jerry_value_t value, /**< value */ + bool take_ownership) /**< take ownership of the value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (value))) { /* This is a rare case so it is optimized for * binary size rather than performance. */ if (!jerry_value_is_abort (value)) { - return release ? value : jerry_acquire_value (value); + return take_ownership ? value : jerry_value_copy (value); } - value = jerry_get_value_from_error (value, release); - release = true; + value = jerry_exception_value (value, take_ownership); + take_ownership = true; } - if (!release) + if (!take_ownership) { value = ecma_copy_value (value); } - return ecma_create_error_reference (value, 0); -} /* jerry_create_error_from_value */ + return ecma_create_exception (value, ECMA_ERROR_API_FLAG_NONE); +} /* jerry_throw_value */ /** - * Get the value from an error value. - * - * Extract the api value from an error. If the second argument is true - * it will release the input error value. - * - * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * Get the value contained in an exception. If the second argument is true + * it will release the argument exception value in the process. * - * @return jerry_value_t value + * @return value in exception */ jerry_value_t -jerry_get_value_from_error (jerry_value_t value, /**< api value */ - bool release) /**< release api value */ +jerry_exception_value (jerry_value_t value, /**< api value */ + bool free_exception) /**< release api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_error_reference (value)) + if (!ecma_is_value_exception (value)) { - return release ? value : ecma_copy_value (value); + return free_exception ? value : ecma_copy_value (value); } - jerry_value_t ret_val = jerry_acquire_value (ecma_get_extended_primitive_from_value (value)->u.value); + jerry_value_t ret_val = jerry_value_copy (ecma_get_extended_primitive_from_value (value)->u.value); - if (release) + if (free_exception) { - jerry_release_value (value); + jerry_value_free (value); } return ret_val; -} /* jerry_get_value_from_error */ +} /* jerry_exception_value */ /** * Set new decorator callback for Error objects. The decorator can * create or update any properties of the newly created Error object. */ void -jerry_set_error_object_created_callback (jerry_error_object_created_callback_t callback, /**< new callback */ - void *user_p) /**< user pointer passed to the callback */ +jerry_error_created_cb (jerry_error_object_created_cb_t callback, /**< new callback */ + void *user_p) /**< user pointer passed to the callback */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); JERRY_CONTEXT (error_object_created_callback_p) = callback; JERRY_CONTEXT (error_object_created_callback_user_p) = user_p; -} /* jerry_set_error_object_created_callback */ +} /* jerry_error_created_cb */ /** * When JERRY_VM_THROW is enabled, the callback passed to this * function is called when an error is thrown in ECMAScript code. */ void -jerry_set_vm_throw_callback (jerry_vm_throw_callback_t throw_cb, /**< callback which is called on throws */ - void *user_p) /**< pointer passed to the function */ +jerry_throw_cb (jerry_throw_cb_t throw_cb, /**< callback which is called on throws */ + void *user_p) /**< pointer passed to the function */ { #if JERRY_VM_THROW JERRY_CONTEXT (vm_throw_callback_p) = throw_cb; @@ -2042,45 +1985,45 @@ jerry_set_vm_throw_callback (jerry_vm_throw_callback_t throw_cb, /**< callback w JERRY_UNUSED (throw_cb); JERRY_UNUSED (user_p); #endif /* JERRY_VM_THROW */ -} /* jerry_set_vm_throw_callback */ +} /* jerry_throw_cb */ /** - * Checks whether the callback set by jerry_set_vm_throw_callback captured the error + * Checks whether the callback set by jerry_throw_cb captured the error * * @return true, if the vm throw callback captured the error * false, otherwise */ bool -jerry_error_is_throw_captured (jerry_value_t value) /**< api value */ +jerry_exception_is_captured (const jerry_value_t value) /**< exception value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_VM_THROW - if (!ecma_is_value_error_reference (value)) + if (!ecma_is_value_exception (value)) { return false; } ecma_extended_primitive_t *error_ref_p = ecma_get_extended_primitive_from_value (value); - return (error_ref_p->refs_and_type & ECMA_ERROR_API_THROW_CAPTURED) != 0; + return (error_ref_p->refs_and_type & ECMA_ERROR_API_FLAG_THROW_CAPTURED) != 0; #else /* !JERRY_VM_THROW */ JERRY_UNUSED (value); return false; #endif /* JERRY_VM_THROW */ -} /* jerry_error_is_throw_captured */ +} /* jerry_exception_is_captured */ /** - * Sets whether the callback set by jerry_set_vm_throw_callback should capture the error or not + * Sets whether the callback set by jerry_throw_cb should capture the exception or not */ void -jerry_error_set_throw_capture (jerry_value_t value, /**< api value */ +jerry_exception_allow_capture (jerry_value_t value, /**< exception value */ bool should_capture) /**< callback should capture this error */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_VM_THROW - if (!ecma_is_value_error_reference (value)) + if (!ecma_is_value_exception (value)) { return; } @@ -2089,16 +2032,29 @@ jerry_error_set_throw_capture (jerry_value_t value, /**< api value */ if (should_capture) { - error_ref_p->refs_and_type &= ~(uint32_t) ECMA_ERROR_API_THROW_CAPTURED; + error_ref_p->refs_and_type &= ~(uint32_t) ECMA_ERROR_API_FLAG_THROW_CAPTURED; return; } - error_ref_p->refs_and_type |= ECMA_ERROR_API_THROW_CAPTURED; + error_ref_p->refs_and_type |= ECMA_ERROR_API_FLAG_THROW_CAPTURED; #else /* !JERRY_VM_THROW */ JERRY_UNUSED (value); JERRY_UNUSED (should_capture); #endif /* JERRY_VM_THROW */ -} /* jerry_error_set_throw_capture */ +} /* jerry_exception_allow_capture */ + +/** + * Check if the given value is an Error object. + * + * @return true - if it is an Error object + * false - otherwise + */ +bool +jerry_value_is_error (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_object (value) + && ecma_object_class_is (ecma_get_object_from_value (value), ECMA_OBJECT_CLASS_ERROR); +} /* jerry_value_is_error */ /** * Return the type of the Error object if possible. @@ -2107,9 +2063,9 @@ jerry_error_set_throw_capture (jerry_value_t value, /**< api value */ * JERRY_ERROR_NONE - if the input value is not an Error object */ jerry_error_t -jerry_get_error_type (jerry_value_t value) /**< api value */ +jerry_error_type (jerry_value_t value) /**< api value */ { - if (JERRY_UNLIKELY (ecma_is_value_error_reference (value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (value))) { value = ecma_get_extended_primitive_from_value (value)->u.value; } @@ -2120,10 +2076,11 @@ jerry_get_error_type (jerry_value_t value) /**< api value */ } ecma_object_t *object_p = ecma_get_object_from_value (value); + /* TODO(check if error object) */ jerry_error_t error_type = ecma_get_error_type (object_p); return (jerry_error_t) error_type; -} /* jerry_get_error_type */ +} /* jerry_error_type */ /** * Get number from the specified value as a double. @@ -2131,9 +2088,9 @@ jerry_get_error_type (jerry_value_t value) /**< api value */ * @return stored number as double */ double -jerry_get_number_value (const jerry_value_t value) /**< api value */ +jerry_value_as_number (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_number (value)) { @@ -2141,7 +2098,7 @@ jerry_get_number_value (const jerry_value_t value) /**< api value */ } return (double) ecma_get_number_from_value (value); -} /* jerry_get_number_value */ +} /* jerry_value_as_number */ /** * Call ToBoolean operation on the api value. @@ -2152,9 +2109,9 @@ jerry_get_number_value (const jerry_value_t value) /**< api value */ bool jerry_value_to_boolean (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { return false; } @@ -2166,7 +2123,7 @@ jerry_value_to_boolean (const jerry_value_t value) /**< input value */ * Call ToNumber operation on the api value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return converted number value - if success * thrown error - otherwise @@ -2174,11 +2131,11 @@ jerry_value_to_boolean (const jerry_value_t value) /**< input value */ jerry_value_t jerry_value_to_number (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } ecma_number_t num; @@ -2186,7 +2143,7 @@ jerry_value_to_number (const jerry_value_t value) /**< input value */ if (ECMA_IS_VALUE_ERROR (ret_value)) { - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } return ecma_make_number_value (num); @@ -2196,7 +2153,7 @@ jerry_value_to_number (const jerry_value_t value) /**< input value */ * Call ToObject operation on the api value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return converted object value - if success * thrown error - otherwise @@ -2204,11 +2161,11 @@ jerry_value_to_number (const jerry_value_t value) /**< input value */ jerry_value_t jerry_value_to_object (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } return jerry_return (ecma_op_to_object (value)); @@ -2218,7 +2175,7 @@ jerry_value_to_object (const jerry_value_t value) /**< input value */ * Call ToPrimitive operation on the api value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return converted primitive value - if success * thrown error - otherwise @@ -2226,11 +2183,11 @@ jerry_value_to_object (const jerry_value_t value) /**< input value */ jerry_value_t jerry_value_to_primitive (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } return jerry_return (ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_NO)); @@ -2240,7 +2197,7 @@ jerry_value_to_primitive (const jerry_value_t value) /**< input value */ * Call the ToString ecma builtin operation on the api value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return converted string value - if success * thrown error - otherwise @@ -2248,17 +2205,17 @@ jerry_value_to_primitive (const jerry_value_t value) /**< input value */ jerry_value_t jerry_value_to_string (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } ecma_string_t *str_p = ecma_op_to_string (value); if (JERRY_UNLIKELY (str_p == NULL)) { - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } return ecma_make_string_value (str_p); @@ -2268,7 +2225,7 @@ jerry_value_to_string (const jerry_value_t value) /**< input value */ * Call the BigInt constructor ecma builtin operation on the api value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return BigInt value - if success * thrown error - otherwise @@ -2276,18 +2233,18 @@ jerry_value_to_string (const jerry_value_t value) /**< input value */ jerry_value_t jerry_value_to_bigint (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_BIGINT - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } return jerry_return (ecma_bigint_to_bigint (value, true)); #else /* !JERRY_BUILTIN_BIGINT */ JERRY_UNUSED (value); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_bigint_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_bigint_not_supported_p)); #endif /* JERRY_BUILTIN_BIGINT */ } /* jerry_value_to_bigint */ @@ -2302,7 +2259,7 @@ jerry_value_to_bigint (const jerry_value_t value) /**< input value */ double jerry_value_as_integer (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_number (value)) { @@ -2337,7 +2294,7 @@ jerry_value_as_integer (const jerry_value_t value) /**< input value */ int32_t jerry_value_as_int32 (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_number (value)) { @@ -2358,7 +2315,7 @@ jerry_value_as_int32 (const jerry_value_t value) /**< input value */ uint32_t jerry_value_as_uint32 (const jerry_value_t value) /**< input value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_number (value)) { @@ -2369,60 +2326,59 @@ jerry_value_as_uint32 (const jerry_value_t value) /**< input value */ } /* jerry_value_as_uint32 */ /** - * Acquire specified Jerry API value. + * Take additional ownership over the argument value. + * The value will be copied by reference when possible, changes made to the new value will be reflected + * in the original. * - * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. - * - * @return acquired api value + * @return copied value */ jerry_value_t -jerry_acquire_value (jerry_value_t value) /**< API value */ +jerry_value_copy (const jerry_value_t value) /**< value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (value))) { ecma_ref_extended_primitive (ecma_get_extended_primitive_from_value (value)); return value; } return ecma_copy_value (value); -} /* jerry_acquire_value */ +} /* jerry_value_copy */ /** - * Release specified Jerry API value + * Release ownership of the argument value */ void -jerry_release_value (jerry_value_t value) /**< API value */ +jerry_value_free (jerry_value_t value) /**< value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (value))) { - ecma_deref_error_reference (ecma_get_extended_primitive_from_value (value)); + ecma_deref_exception (ecma_get_extended_primitive_from_value (value)); return; } ecma_free_value (value); -} /* jerry_release_value */ +} /* jerry_value_free */ /** * Create an array object value * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the constructed array object */ jerry_value_t -jerry_create_array (uint32_t size) /**< size of array */ +jerry_array (jerry_length_t length) /**< length of array */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - ecma_object_t *array_p = ecma_op_new_array_object (size); + ecma_object_t *array_p = ecma_op_new_array_object (length); return ecma_make_object_value (array_p); -} /* jerry_create_array */ +} /* jerry_array */ /** * Create a jerry_value_t representing a boolean value from the given boolean parameter. @@ -2430,130 +2386,153 @@ jerry_create_array (uint32_t size) /**< size of array */ * @return value of the created boolean */ jerry_value_t -jerry_create_boolean (bool value) /**< bool value from which a jerry_value_t will be created */ +jerry_boolean (bool value) /**< bool value from which a jerry_value_t will be created */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return jerry_return (ecma_make_boolean_value (value)); -} /* jerry_create_boolean */ +} /* jerry_boolean */ /** - * Create an error object - * - * Note: - * - returned value must be freed with jerry_release_value, when it is no longer needed - * - the error flag is set for the returned value + * Create an Error object with the provided string value as the error message. + * If the message value is not a string, the created error will not have a message property. * - * @return value of the constructed error object + * @return Error object */ jerry_value_t -jerry_create_error (jerry_error_t error_type, /**< type of error */ - const jerry_char_t *message_p) /**< value of 'message' property - * of constructed error object */ +jerry_error (jerry_error_t error_type, /**< type of error */ + const jerry_value_t message) /**< message of the error */ { - return jerry_create_error_sz (error_type, (lit_utf8_byte_t *) message_p, lit_zt_utf8_string_size (message_p)); -} /* jerry_create_error */ + jerry_assert_api_enabled (); + + ecma_string_t *message_p = NULL; + if (ecma_is_value_string (message)) + { + message_p = ecma_get_string_from_value (message); + } + + ecma_object_t *error_object_p = ecma_new_standard_error ((jerry_error_t) error_type, message_p); + + return ecma_make_object_value (error_object_p); +} /* jerry_error */ /** - * Create an error object + * Create an Error object with a zero-terminated string as a message. If the message string is NULL, the created error + * will not have a message property. * - * Note: - * - returned value must be freed with jerry_release_value, when it is no longer needed - * - the error flag is set for the returned value - * - * @return value of the constructed error object + * @return Error object */ jerry_value_t -jerry_create_error_sz (jerry_error_t error_type, /**< type of error */ - const jerry_char_t *message_p, /**< value of 'message' property - * of constructed error object */ - jerry_size_t message_size) /**< size of the message in bytes */ +jerry_error_sz (jerry_error_t error_type, /**< type of error */ + const char *message_p) /**< value of 'message' property + * of constructed error object */ { - jerry_assert_api_available (); + jerry_value_t message = ECMA_VALUE_UNDEFINED; - if (message_p == NULL || message_size == 0) + if (message_p != NULL) { - return ecma_create_error_object_reference (ecma_new_standard_error ((jerry_error_t) error_type, NULL)); + message = jerry_string_sz (message_p); } - else - { - ecma_string_t *message_string_p = - ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) message_p, (lit_utf8_size_t) message_size); - ecma_object_t *error_object_p = ecma_new_standard_error ((jerry_error_t) error_type, message_string_p); + ecma_value_t error = jerry_error (error_type, message); + ecma_free_value (message); - ecma_deref_ecma_string (message_string_p); + return error; +} /* jerry_error_sz */ - return ecma_create_error_object_reference (error_object_p); - } -} /* jerry_create_error_sz */ +/** + * Create an exception by constructing an Error object with the specified type and the provided string value as the + * error message. If the message value is not a string, the created error will not have a message property. + * + * @return exception value + */ +jerry_value_t +jerry_throw (jerry_error_t error_type, /**< type of error */ + const jerry_value_t message) /**< message value */ +{ + return jerry_throw_value (jerry_error (error_type, message), true); +} /* jerry_throw */ + +/** + * Create an exception by constructing an Error object with the specified type and the provided zero-terminated ASCII + * string as the error message. If the message string is NULL, the created error will not have a message property. + * + * @return exception value + */ +jerry_value_t +jerry_throw_sz (jerry_error_t error_type, /**< type of error */ + const char *message_p) /**< value of 'message' property + * of constructed error object */ +{ + return jerry_throw_value (jerry_error_sz (error_type, message_p), true); +} /* jerry_throw_sz */ /** * Create an external function object * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the constructed function object */ jerry_value_t -jerry_create_external_function (jerry_external_handler_t handler_p) /**< pointer to native handler - * for the function */ +jerry_function_external (jerry_external_handler_t handler) /**< native handler + * for the function */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - ecma_object_t *func_obj_p = ecma_op_create_external_function_object (handler_p); + ecma_object_t *func_obj_p = ecma_op_create_external_function_object (handler); return ecma_make_object_value (func_obj_p); -} /* jerry_create_external_function */ +} /* jerry_function_external */ /** * Creates a jerry_value_t representing a number value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry_value_t created from the given double argument. */ jerry_value_t -jerry_create_number (double value) /**< double value from which a jerry_value_t will be created */ +jerry_number (double value) /**< double value from which a jerry_value_t will be created */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_make_number_value ((ecma_number_t) value); -} /* jerry_create_number */ +} /* jerry_number */ /** * Creates a jerry_value_t representing a positive or negative infinity value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry_value_t representing an infinity value. */ jerry_value_t -jerry_create_number_infinity (bool sign) /**< true for negative Infinity - * false for positive Infinity */ +jerry_infinity (bool sign) /**< true for negative Infinity + * false for positive Infinity */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_make_number_value (ecma_number_make_infinity (sign)); -} /* jerry_create_number_infinity */ +} /* jerry_infinity */ /** * Creates a jerry_value_t representing a not-a-number value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry_value_t representing a not-a-number value. */ jerry_value_t -jerry_create_number_nan (void) +jerry_nan (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_make_nan_value (); -} /* jerry_create_number_nan */ +} /* jerry_nan */ /** * Creates a jerry_value_t representing an undefined value. @@ -2561,12 +2540,12 @@ jerry_create_number_nan (void) * @return value of undefined */ jerry_value_t -jerry_create_undefined (void) +jerry_undefined (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ECMA_VALUE_UNDEFINED; -} /* jerry_create_undefined */ +} /* jerry_undefined */ /** * Creates and returns a jerry_value_t with type null object. @@ -2574,78 +2553,78 @@ jerry_create_undefined (void) * @return jerry_value_t representing null */ jerry_value_t -jerry_create_null (void) +jerry_null (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ECMA_VALUE_NULL; -} /* jerry_create_null */ +} /* jerry_null */ /** * Create new JavaScript object, like with new Object(). * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the created object */ jerry_value_t -jerry_create_object (void) +jerry_object (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_make_object_value (ecma_op_create_object_object_noarg ()); -} /* jerry_create_object */ +} /* jerry_object */ /** * Create an empty Promise object which can be resolve/reject later * by calling jerry_resolve_or_reject_promise. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the created object */ jerry_value_t -jerry_create_promise (void) +jerry_promise (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT ecma_value_t promise_value = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL); return promise_value; #else /* !JERRY_ESNEXT */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_promise_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_promise_not_supported_p)); #endif /* JERRY_ESNEXT */ -} /* jerry_create_promise */ +} /* jerry_promise */ /** * Create a new Proxy object with the given target and handler * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the created Proxy object */ jerry_value_t -jerry_create_proxy (const jerry_value_t target, /**< target argument */ - const jerry_value_t handler) /**< handler argument */ +jerry_proxy (const jerry_value_t target, /**< target argument */ + const jerry_value_t handler) /**< handler argument */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (target) || ecma_is_value_error_reference (handler)) + if (ecma_is_value_exception (target) || ecma_is_value_exception (handler)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } #if JERRY_BUILTIN_PROXY ecma_object_t *proxy_p = ecma_proxy_create (target, handler, 0); return jerry_return (proxy_p == NULL ? ECMA_VALUE_ERROR : ecma_make_object_value (proxy_p)); #else /* !JERRY_BUILTIN_PROXY */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Proxy is not supported"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Proxy is not supported")); #endif /* JERRY_BUILTIN_PROXY */ -} /* jerry_create_proxy */ +} /* jerry_proxy */ #if JERRY_BUILTIN_PROXY @@ -2658,195 +2637,186 @@ JERRY_STATIC_ASSERT ((int) JERRY_PROXY_SKIP_RESULT_VALIDATION == (int) ECMA_PROX * Create a new Proxy object with the given target, handler, and special options * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the created Proxy object */ jerry_value_t -jerry_create_special_proxy (const jerry_value_t target, /**< target argument */ - const jerry_value_t handler, /**< handler argument */ - uint32_t options) /**< jerry_proxy_object_options_t option bits */ +jerry_proxy_custom (const jerry_value_t target, /**< target argument */ + const jerry_value_t handler, /**< handler argument */ + uint32_t flags) /**< jerry_proxy_custom_behavior_t option bits */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (target) || ecma_is_value_error_reference (handler)) + if (ecma_is_value_exception (target) || ecma_is_value_exception (handler)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } #if JERRY_BUILTIN_PROXY - options &= JERRY_PROXY_SKIP_RESULT_VALIDATION; + flags &= JERRY_PROXY_SKIP_RESULT_VALIDATION; - ecma_object_t *proxy_p = ecma_proxy_create (target, handler, options); + ecma_object_t *proxy_p = ecma_proxy_create (target, handler, flags); return jerry_return (proxy_p == NULL ? ECMA_VALUE_ERROR : ecma_make_object_value (proxy_p)); #else /* !JERRY_BUILTIN_PROXY */ - JERRY_UNUSED (options); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Proxy is not supported"))); + JERRY_UNUSED (flags); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Proxy is not supported")); #endif /* JERRY_BUILTIN_PROXY */ -} /* jerry_create_special_proxy */ +} /* jerry_proxy_custom */ /** - * Create string from a valid UTF-8 string + * Create string value from the input zero-terminated ASCII string. * - * Note: - * returned value must be freed with jerry_release_value when it is no longer needed. - * - * @return value of the created string + * @return created string */ jerry_value_t -jerry_create_string_from_utf8 (const jerry_char_t *str_p) /**< pointer to string */ +jerry_string_sz (const char *str_p) /**< pointer to string */ { - return jerry_create_string_sz_from_utf8 (str_p, lit_zt_utf8_string_size ((lit_utf8_byte_t *) str_p)); -} /* jerry_create_string_from_utf8 */ + const jerry_char_t *data_p = (const jerry_char_t *) str_p; + return jerry_string (data_p, lit_zt_utf8_string_size (data_p), JERRY_ENCODING_CESU8); +} /* jerry_string_sz */ /** - * Create string from a valid UTF-8 string + * Create a string value from the input buffer using the specified encoding. + * The content of the buffer is assumed to be valid in the specified encoding, it's the callers responsibility to + * validate the input. * - * Note: - * returned value must be freed with jerry_release_value when it is no longer needed. + * See also: jerry_validate_string * - * @return value of the created string + * @return created string */ jerry_value_t -jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p, /**< pointer to string */ - jerry_size_t str_size) /**< string size */ +jerry_string (const jerry_char_t *buffer_p, /**< pointer to buffer */ + jerry_size_t buffer_size, /**< buffer size */ + jerry_encoding_t encoding) /**< buffer encoding */ { - jerry_assert_api_available (); - - ecma_string_t *ecma_str_p = - ecma_new_ecma_string_from_utf8_converted_to_cesu8 ((lit_utf8_byte_t *) str_p, (lit_utf8_size_t) str_size); - - return ecma_make_string_value (ecma_str_p); -} /* jerry_create_string_sz_from_utf8 */ + jerry_assert_api_enabled (); + ecma_string_t *ecma_str_p = NULL; + JERRY_ASSERT (jerry_validate_string (buffer_p, buffer_size, encoding)); -/** - * Create string from a valid CESU-8 string - * - * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. - * - * @return value of the created string - */ -jerry_value_t -jerry_create_string (const jerry_char_t *str_p) /**< pointer to string */ -{ - return jerry_create_string_sz (str_p, lit_zt_utf8_string_size ((lit_utf8_byte_t *) str_p)); -} /* jerry_create_string */ - -/** - * Create string from a valid CESU-8 string - * - * Note: - * returned value must be freed with jerry_release_value when it is no longer needed. - * - * @return value of the created string - */ -jerry_value_t -jerry_create_string_sz (const jerry_char_t *str_p, /**< pointer to string */ - jerry_size_t str_size) /**< string size */ -{ - jerry_assert_api_available (); + switch (encoding) + { + case JERRY_ENCODING_CESU8: + { + ecma_str_p = ecma_new_ecma_string_from_utf8 (buffer_p, buffer_size); + break; + } + case JERRY_ENCODING_UTF8: + { + ecma_str_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (buffer_p, buffer_size); + break; + } + default: + { + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Invalid encoding")); + } + } - ecma_string_t *ecma_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) str_p, (lit_utf8_size_t) str_size); return ecma_make_string_value (ecma_str_p); -} /* jerry_create_string_sz */ +} /* jerry_string */ /** - * Create external string from a valid CESU-8 string - * - * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * Create external string from input zero-terminated ASCII string. * - * @return value of the created external string + * @return created external string */ jerry_value_t -jerry_create_external_string (const jerry_char_t *str_p, /**< pointer to string */ - void *user_p) /**< user pointer passed to the callback when the string is freed */ +jerry_string_external_sz (const char *str_p, /**< pointer to string */ + void *user_p) /**< user pointer passed to the callback when the string is freed */ { - return jerry_create_external_string_sz (str_p, lit_zt_utf8_string_size ((lit_utf8_byte_t *) str_p), user_p); -} /* jerry_create_external_string */ + const jerry_char_t *data_p = (const jerry_char_t *) str_p; + return jerry_string_external (data_p, lit_zt_utf8_string_size (data_p), user_p); +} /* jerry_string_external_sz */ /** - * Create external string from a valid CESU-8 string + * Create external string from a valid CESU-8 encoded string. + * The content of the buffer is assumed be encoded correctly, it's the callers responsibility to + * validate the input. * - * Note: - * returned value must be freed with jerry_release_value when it is no longer needed. + * See also: jerry_validate_string * - * @return value of the created external string + * @return created external string */ jerry_value_t -jerry_create_external_string_sz (const jerry_char_t *str_p, /**< pointer to string */ - jerry_size_t str_size, /**< string size */ - void *user_p) /**< user pointer passed to the callback when the string is freed */ +jerry_string_external (const jerry_char_t *buffer_p, /**< pointer to string */ + jerry_size_t buffer_size, /**< string size */ + void *user_p) /**< user pointer passed to the callback when the string is freed */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - ecma_string_t *ecma_str_p = - ecma_new_ecma_external_string_from_cesu8 ((lit_utf8_byte_t *) str_p, (lit_utf8_size_t) str_size, user_p); + JERRY_ASSERT (jerry_validate_string (buffer_p, buffer_size, JERRY_ENCODING_CESU8)); + ecma_string_t *ecma_str_p = ecma_new_ecma_external_string_from_cesu8 (buffer_p, buffer_size, user_p); return ecma_make_string_value (ecma_str_p); -} /* jerry_create_external_string_sz */ +} /* jerry_string_external_sz_sz */ /** - * Create symbol from an api value + * Create symbol with a description value * - * Note: - * The given argument is converted to string. This operation can throw an error. - * returned value must be freed with jerry_release_value when it is no longer needed. + * Note: The given argument is converted to string. This operation can throw an exception. * - * @return value of the created symbol, if success - * thrown error, otherwise + * @return created symbol, + * or thrown exception */ jerry_value_t -jerry_create_symbol (const jerry_value_t value) /**< api value */ +jerry_symbol_with_description (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } #if JERRY_ESNEXT return jerry_return (ecma_op_create_symbol (&value, 1)); #else /* !JERRY_ESNEXT */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_symbol_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_symbol_not_supported_p)); #endif /* JERRY_ESNEXT */ -} /* jerry_create_symbol */ +} /* jerry_symbol_with_description */ /** - * Create BigInt from a sequence of uint64 digits + * Create BigInt from a sequence of uint64 digits. * - * @return value of the created bigint, if success - * thrown error, otherwise + * Note: This operation can throw an exception. + * + * @return created bigint, + * or thrown exception */ jerry_value_t -jerry_create_bigint (const uint64_t *digits_p, /**< BigInt digits (lowest digit first) */ - uint32_t size, /**< number of BigInt digits */ - bool sign) /**< sign bit, true if the result should be negative */ +jerry_bigint (const uint64_t *digits_p, /**< BigInt digits (lowest digit first) */ + uint32_t digit_count, /**< number of BigInt digits */ + bool sign) /**< sign bit, true if the result should be negative */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_BIGINT - return jerry_return (ecma_bigint_create_from_digits (digits_p, size, sign)); + return jerry_return (ecma_bigint_create_from_digits (digits_p, digit_count, sign)); #else /* !JERRY_BUILTIN_BIGINT */ JERRY_UNUSED (digits_p); - JERRY_UNUSED (size); + JERRY_UNUSED (digit_count); JERRY_UNUSED (sign); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_bigint_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_bigint_not_supported_p)); #endif /* JERRY_BUILTIN_BIGINT */ -} /* jerry_create_bigint */ +} /* jerry_bigint */ /** - * Calculates the size of the given pattern and creates a RegExp object. + * Creates a RegExp object with the given ASCII pattern and flags. + * * * @return value of the constructed RegExp object. */ jerry_value_t -jerry_create_regexp (const jerry_char_t *pattern_p, /**< zero-terminated UTF-8 string as RegExp pattern */ - uint16_t flags) /**< optional RegExp flags */ +jerry_regexp_sz (const char *pattern_p, /**< RegExp pattern as zero-terminated ASCII string */ + uint16_t flags) /**< RegExp flags */ { - return jerry_create_regexp_sz (pattern_p, lit_zt_utf8_string_size (pattern_p), flags); -} /* jerry_create_regexp */ + jerry_assert_api_enabled (); + + jerry_value_t pattern = jerry_string_sz (pattern_p); + jerry_value_t result = jerry_regexp (pattern, flags); + + jerry_value_free (pattern); + return result; +} /* jerry_regexp_sz */ /** * Creates a RegExp object with the given pattern and flags. @@ -2854,16 +2824,15 @@ jerry_create_regexp (const jerry_char_t *pattern_p, /**< zero-terminated UTF-8 s * @return value of the constructed RegExp object. */ jerry_value_t -jerry_create_regexp_sz (const jerry_char_t *pattern_p, /**< zero-terminated UTF-8 string as RegExp pattern */ - jerry_size_t pattern_size, /**< length of the pattern */ - uint16_t flags) /**< optional RegExp flags */ +jerry_regexp (const ecma_value_t pattern, /**< pattern string */ + uint16_t flags) /**< optional RegExp flags */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_REGEXP - if (!lit_is_valid_utf8_string (pattern_p, pattern_size, true)) + if (!ecma_is_value_string (pattern)) { - return jerry_throw (ecma_raise_common_error (ECMA_ERR_MSG ("Input must be a valid utf8 string"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Input pattern must be a string value")); } ecma_object_t *regexp_obj_p = ecma_op_regexp_alloc (NULL); @@ -2873,21 +2842,17 @@ jerry_create_regexp_sz (const jerry_char_t *pattern_p, /**< zero-terminated UTF- return ECMA_VALUE_ERROR; } - ecma_string_t *ecma_pattern = ecma_new_ecma_string_from_utf8 (pattern_p, pattern_size); - - jerry_value_t ret_val = ecma_op_create_regexp_with_flags (regexp_obj_p, ecma_make_string_value (ecma_pattern), flags); - ecma_deref_ecma_string (ecma_pattern); + jerry_value_t ret_val = ecma_op_create_regexp_with_flags (regexp_obj_p, pattern, flags); return ret_val; #else /* !JERRY_BUILTIN_REGEXP */ - JERRY_UNUSED (pattern_p); - JERRY_UNUSED (pattern_size); + JERRY_UNUSED (pattern); JERRY_UNUSED (flags); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("RegExp is not supported"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("RegExp is not supported")); #endif /* JERRY_BUILTIN_REGEXP */ -} /* jerry_create_regexp_sz */ +} /* jerry_regexp */ /** * Creates a new realm (global object). @@ -2895,17 +2860,17 @@ jerry_create_regexp_sz (const jerry_char_t *pattern_p, /**< zero-terminated UTF- * @return new realm object */ jerry_value_t -jerry_create_realm (void) +jerry_realm (void) { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_REALMS ecma_global_object_t *global_object_p = ecma_builtin_create_global_object (); return ecma_make_object_value ((ecma_object_t *) global_object_p); #else /* !JERRY_BUILTIN_REALMS */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Realms are disabled"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Realms are disabled")); #endif /* JERRY_BUILTIN_REALMS */ -} /* jerry_create_realm */ +} /* jerry_realm */ /** * Get length of an array object @@ -2915,10 +2880,10 @@ jerry_create_realm (void) * * @return length of the given array */ -uint32_t -jerry_get_array_length (const jerry_value_t value) /**< api value */ +jerry_length_t +jerry_array_length (const jerry_value_t value) /**< api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!jerry_value_is_object (value)) { @@ -2933,234 +2898,219 @@ jerry_get_array_length (const jerry_value_t value) /**< api value */ } return 0; -} /* jerry_get_array_length */ +} /* jerry_array_length */ /** - * Get size of Jerry string + * Get size of a string string value in the specified encoding. * - * Note: - * Returns 0, if the value parameter is not a string. - * - * @return number of bytes in the buffer needed to represent the string + * @return number of bytes required by the string, + * 0 - if value is not a string */ jerry_size_t -jerry_get_string_size (const jerry_value_t value) /**< input string */ +jerry_string_size (const jerry_value_t value, /**< input string */ + jerry_encoding_t encoding) /**< encoding */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_string (value)) { return 0; } - return ecma_string_get_size (ecma_get_string_from_value (value)); -} /* jerry_get_string_size */ + switch (encoding) + { + case JERRY_ENCODING_CESU8: + { + return ecma_string_get_size (ecma_get_string_from_value (value)); + } + case JERRY_ENCODING_UTF8: + { + return ecma_string_get_utf8_size (ecma_get_string_from_value (value)); + } + default: + { + return 0; + } + } +} /* jerry_string_size */ /** - * Get UTF-8 encoded string size from Jerry string + * Get length of a string value * - * Note: - * Returns 0, if the value parameter is not a string. - * - * @return number of bytes in the buffer needed to represent the UTF-8 encoded string + * @return number of characters in the string + * 0 - if value is not a string */ -jerry_size_t -jerry_get_utf8_string_size (const jerry_value_t value) /**< input string */ +jerry_length_t +jerry_string_length (const jerry_value_t value) /**< input string */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (!ecma_is_value_string (value)) { return 0; } - return ecma_string_get_utf8_size (ecma_get_string_from_value (value)); -} /* jerry_get_utf8_string_size */ + return ecma_string_get_length (ecma_get_string_from_value (value)); +} /* jerry_string_length */ /** - * Get length of Jerry string + * Copy the characters of a string into the specified buffer using the specified encoding. + * The string is truncated to fit the buffer. * - * Note: - * Returns 0, if the value parameter is not a string. - * - * @return number of characters in the string + * @return number of bytes copied to the buffer, + * 0 - if value is not a string */ -jerry_length_t -jerry_get_string_length (const jerry_value_t value) /**< input string */ +jerry_size_t +jerry_string_to_buffer (const jerry_value_t value, /**< input string value */ + jerry_char_t *buffer_p, /**< [out] output characters buffer */ + jerry_size_t buffer_size, /**< size of output buffer */ + jerry_encoding_t encoding) /**< output encoding */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_string (value)) + if (!ecma_is_value_string (value) || buffer_p == NULL) { return 0; } - return ecma_string_get_length (ecma_get_string_from_value (value)); -} /* jerry_get_string_length */ + ecma_string_t *str_p = ecma_get_string_from_value (value); + + return ecma_string_copy_to_buffer (str_p, (lit_utf8_byte_t *) buffer_p, buffer_size, encoding); +} /* jerry_string_to_char_buffer */ /** - * Get UTF-8 string length from Jerry string + * Create a substring of the input string value. + * Return an empty string if input value is not a string. * - * Note: - * Returns 0, if the value parameter is not a string. + * @param value the input string value + * @param start start position of the substring + * @param end end position of the substring * - * @return number of characters in the string + * @return created string */ -jerry_length_t -jerry_get_utf8_string_length (const jerry_value_t value) /**< input string */ +jerry_value_t +jerry_string_substr (const jerry_value_t value, jerry_length_t start, jerry_length_t end) { - jerry_assert_api_available (); - if (!ecma_is_value_string (value)) { - return 0; + return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY); } - return ecma_string_get_utf8_length (ecma_get_string_from_value (value)); -} /* jerry_get_utf8_string_length */ + return ecma_make_string_value (ecma_string_substr (ecma_get_string_from_value (value), start, end)); +} /* jerry_string_substr */ /** - * Copy the characters of a string into a specified buffer. - * - * Note: - * The '\0' character could occur in character buffer. - * Returns 0, if the value parameter is not a string or - * the buffer is not large enough for the whole string. - * - * Note: - * If the size of the string in jerry value is larger than the size of the - * target buffer, the copy will fail. - * To copy substring use jerry_substring_to_char_buffer() instead. + * Iterate over the input string value in the specified encoding, visiting each byte of the encoded string once. If + * the input value is not a string, the function will do nothing. * - * @return number of bytes, actually copied to the buffer. + * @param value the input string value + * @param cb callback function called for each byte of the encoded string. + * @param encoding the requested encoding for the string */ -jerry_size_t -jerry_string_to_char_buffer (const jerry_value_t value, /**< input string value */ - jerry_char_t *buffer_p, /**< [out] output characters buffer */ - jerry_size_t buffer_size) /**< size of output buffer */ +void +jerry_string_iterate (const jerry_value_t value, jerry_string_iterate_cb_t cb, jerry_encoding_t encoding) { - jerry_assert_api_available (); - - if (!ecma_is_value_string (value) || buffer_p == NULL) + if (!ecma_is_value_string (value)) { - return 0; + return; } ecma_string_t *str_p = ecma_get_string_from_value (value); + ECMA_STRING_TO_UTF8_STRING (str_p, buffer_p, buffer_size); - if (ecma_string_get_size (str_p) > buffer_size) + const lit_utf8_byte_t *current_p = buffer_p; + const lit_utf8_byte_t *end_p = buffer_p + buffer_size; + + switch (encoding) { - return 0; - } + case JERRY_ENCODING_UTF8: + { + while (current_p < end_p) + { + if (JERRY_UNLIKELY (*current_p >= LIT_UTF8_3_BYTE_MARKER)) + { + lit_code_point_t cp; + lit_utf8_size_t read_size = lit_read_code_point_from_cesu8 (current_p, end_p, &cp); - return ecma_string_copy_to_cesu8_buffer (str_p, (lit_utf8_byte_t *) buffer_p, buffer_size); -} /* jerry_string_to_char_buffer */ + lit_utf8_byte_t bytes[LIT_UTF8_MAX_BYTES_IN_CODE_POINT]; + lit_utf8_size_t encoded_size = lit_code_point_to_utf8 (cp, bytes); -/** - * Copy the characters of an utf-8 encoded string into a specified buffer. - * - * Note: - * The '\0' character could occur anywhere in the returned string - * Returns 0, if the value parameter is not a string or the buffer - * is not large enough for the whole string. - * - * Note: - * If the size of the string in jerry value is larger than the size of the - * target buffer, the copy will fail. - * To copy a substring use jerry_substring_to_utf8_char_buffer() instead. - * - * @return number of bytes copied to the buffer. - */ -jerry_size_t -jerry_string_to_utf8_char_buffer (const jerry_value_t value, /**< input string value */ - jerry_char_t *buffer_p, /**< [out] output characters buffer */ - jerry_size_t buffer_size) /**< size of output buffer */ -{ - jerry_assert_api_available (); + for (uint32_t i = 0; i < encoded_size; i++) + { + cb (bytes[i]); + } - if (!ecma_is_value_string (value) || buffer_p == NULL) - { - return 0; - } + current_p += read_size; + continue; + } - ecma_string_t *str_p = ecma_get_string_from_value (value); + cb (*current_p++); + } - if (ecma_string_get_utf8_size (str_p) > buffer_size) - { - return 0; - } + break; + } + case JERRY_ENCODING_CESU8: + { + while (current_p < end_p) + { + cb (*current_p++); + } - return ecma_string_copy_to_utf8_buffer (str_p, (lit_utf8_byte_t *) buffer_p, buffer_size); -} /* jerry_string_to_utf8_char_buffer */ + break; + } + default: + { + break; + } + } + ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size); +} /* jerry_string_iterate */ /** - * Copy the characters of an cesu-8 encoded substring into a specified buffer. + * Print char wrapper that casts the argument to an unsigned type * - * Note: - * The '\0' character could occur anywhere in the returned string - * Returns 0, if the value parameter is not a string. - * It will extract the substring beetween the specified start position - * and the end position (or the end of the string, whichever comes first). - * - * @return number of bytes copied to the buffer. + * @param byte encoded byte value */ -jerry_size_t -jerry_substring_to_char_buffer (const jerry_value_t value, /**< input string value */ - jerry_length_t start_pos, /**< position of the first character */ - jerry_length_t end_pos, /**< position of the last character */ - jerry_char_t *buffer_p, /**< [out] output characters buffer */ - jerry_size_t buffer_size) /**< size of output buffer */ +static void +jerry_print_char_wrapper (uint8_t byte) { - jerry_assert_api_available (); + static const char *const null_str_p = "\\u0000"; - if (!ecma_is_value_string (value) || buffer_p == NULL) + if (JERRY_UNLIKELY (byte == '\0')) { - return 0; - } + const char *curr_p = null_str_p; - ecma_string_t *str_p = ecma_get_string_from_value (value); + while (*curr_p != '\0') + { + jerry_port_print_char (*curr_p++); + } - return ecma_substring_copy_to_cesu8_buffer (str_p, start_pos, end_pos, (lit_utf8_byte_t *) buffer_p, buffer_size); -} /* jerry_substring_to_char_buffer */ + return; + } + + jerry_port_print_char ((char) byte); +} /* jerryx_print_char_wrapper */ /** - * Copy the characters of an utf-8 encoded substring into a specified buffer. - * - * Note: - * The '\0' character could occur anywhere in the returned string - * Returns 0, if the value parameter is not a string. - * It will extract the substring beetween the specified start position - * and the end position (or the end of the string, whichever comes first). + * Print the argument string in utf8 encoding using jerry_port_print_char. + * If the argument is not a string, the function does nothing. * - * @return number of bytes copied to the buffer. + * @param value the input string value */ -jerry_size_t -jerry_substring_to_utf8_char_buffer (const jerry_value_t value, /**< input string value */ - jerry_length_t start_pos, /**< position of the first character */ - jerry_length_t end_pos, /**< position of the last character */ - jerry_char_t *buffer_p, /**< [out] output characters buffer */ - jerry_size_t buffer_size) /**< size of output buffer */ +void +jerry_string_print (const jerry_value_t value) { - jerry_assert_api_available (); - - if (!ecma_is_value_string (value) || buffer_p == NULL) - { - return 0; - } - - ecma_string_t *str_p = ecma_get_string_from_value (value); - - return ecma_substring_copy_to_utf8_buffer (str_p, start_pos, end_pos, (lit_utf8_byte_t *) buffer_p, buffer_size); -} /* jerry_substring_to_utf8_char_buffer */ + jerry_string_iterate (value, &jerry_print_char_wrapper, JERRY_ENCODING_UTF8); +} /* jerry_string_print */ /** * Sets the global callback which is called when an external string is freed. */ void -jerry_string_set_external_free_callback (jerry_external_string_free_callback_t callback_p) /**< free callback */ +jerry_string_external_free_cb (jerry_external_string_free_cb_t callback) /**< free callback */ { - JERRY_CONTEXT (external_string_free_callback_p) = callback_p; -} /* jerry_string_set_external_free_callback */ + JERRY_CONTEXT (external_string_free_callback_p) = callback; +} /* jerry_string_external_free_cb */ /** * Returns the user pointer assigned to an external string. @@ -3169,9 +3119,9 @@ jerry_string_set_external_free_callback (jerry_external_string_free_callback_t c * NULL, otherwise */ void * -jerry_string_get_external_user_pointer (const jerry_value_t value, /**< string value */ - bool *is_external) /**< [out] true - if value is an external string, - * false - otherwise */ +jerry_string_user_ptr (const jerry_value_t value, /**< string value */ + bool *is_external) /**< [out] true - if value is an external string, + * false - otherwise */ { if (is_external != NULL) { @@ -3204,7 +3154,7 @@ jerry_string_get_external_user_pointer (const jerry_value_t value, /**< string v } return ((ecma_external_string_t *) string_p)->user_p; -} /* jerry_string_get_external_user_pointer */ +} /* jerry_string_user_ptr */ /** * Checks whether the object or it's prototype objects have the given property. @@ -3213,21 +3163,21 @@ jerry_string_get_external_user_pointer (const jerry_value_t value, /**< string v * true/false API value - depend on whether the property exists */ jerry_value_t -jerry_has_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name (string value) */ +jerry_object_has (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name (string value) */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return ECMA_VALUE_FALSE; } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); - ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (prop_name_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (key); return jerry_return (ecma_op_object_has_property (obj_p, prop_name_p)); -} /* jerry_has_property */ +} /* jerry_object_has */ /** * Checks whether the object has the given property. @@ -3236,18 +3186,18 @@ jerry_has_property (const jerry_value_t obj_val, /**< object value */ * ECMA_VALUE_{TRUE, FALSE} - based on whether the property exists */ jerry_value_t -jerry_has_own_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name (string value) */ +jerry_object_has_own (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name (string value) */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return ECMA_VALUE_FALSE; } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); - ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (prop_name_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (key); #if JERRY_BUILTIN_PROXY if (ECMA_OBJECT_IS_PROXY (obj_p)) @@ -3270,7 +3220,7 @@ jerry_has_own_property (const jerry_value_t obj_val, /**< object value */ #else /* !JERRY_BUILTIN_TYPEDARRAY */ return ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_has_own_property */ +} /* jerry_object_has_own */ /** * Checks whether the object has the given internal property. @@ -3279,17 +3229,17 @@ jerry_has_own_property (const jerry_value_t obj_val, /**< object value */ * false - otherwise */ bool -jerry_has_internal_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name value */ +jerry_object_has_internal (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return false; } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); ecma_string_t *internal_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_API_INTERNAL); @@ -3306,10 +3256,10 @@ jerry_has_internal_property (const jerry_value_t obj_val, /**< object value */ } ecma_object_t *internal_object_p = ecma_get_object_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value); - property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (prop_name_val)); + property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (key)); return property_p != NULL; -} /* jerry_has_internal_property */ +} /* jerry_object_has_internal */ /** * Delete a property from an object. @@ -3318,18 +3268,18 @@ jerry_has_internal_property (const jerry_value_t obj_val, /**< object value */ * false - otherwise */ bool -jerry_delete_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name (string value) */ +jerry_object_delete (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name (string value) */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return false; } ecma_value_t ret_value = - ecma_op_object_delete (ecma_get_object_from_value (obj_val), ecma_get_prop_name_from_value (prop_name_val), false); + ecma_op_object_delete (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key), false); #if JERRY_BUILTIN_PROXY if (ECMA_IS_VALUE_ERROR (ret_value)) @@ -3340,7 +3290,7 @@ jerry_delete_property (const jerry_value_t obj_val, /**< object value */ #endif /* JERRY_BUILTIN_PROXY */ return ecma_is_value_true (ret_value); -} /* jerry_delete_property */ +} /* jerry_object_delete */ /** * Delete indexed property from the specified object. @@ -3349,18 +3299,18 @@ jerry_delete_property (const jerry_value_t obj_val, /**< object value */ * false - otherwise */ bool -jerry_delete_property_by_index (const jerry_value_t obj_val, /**< object value */ - uint32_t index) /**< index to be written */ +jerry_object_delete_index (const jerry_value_t object, /**< object value */ + uint32_t index) /**< index to be written */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { return false; } ecma_string_t *str_idx_p = ecma_new_ecma_string_from_uint32 (index); - ecma_value_t ret_value = ecma_op_object_delete (ecma_get_object_from_value (obj_val), str_idx_p, false); + ecma_value_t ret_value = ecma_op_object_delete (ecma_get_object_from_value (object), str_idx_p, false); ecma_deref_ecma_string (str_idx_p); #if JERRY_BUILTIN_PROXY @@ -3372,7 +3322,7 @@ jerry_delete_property_by_index (const jerry_value_t obj_val, /**< object value * #endif /* JERRY_BUILTIN_PROXY */ return ecma_is_value_true (ret_value); -} /* jerry_delete_property_by_index */ +} /* jerry_object_delete_index */ /** * Delete an internal property from an object. @@ -3381,17 +3331,17 @@ jerry_delete_property_by_index (const jerry_value_t obj_val, /**< object value * * false - otherwise */ bool -jerry_delete_internal_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name value */ +jerry_object_delete_internal (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return false; } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); ecma_string_t *internal_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_API_INTERNAL); @@ -3408,7 +3358,7 @@ jerry_delete_internal_property (const jerry_value_t obj_val, /**< object value * } ecma_object_t *internal_object_p = ecma_get_object_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value); - property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (prop_name_val)); + property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (key)); if (property_p == NULL) { @@ -3418,89 +3368,88 @@ jerry_delete_internal_property (const jerry_value_t obj_val, /**< object value * ecma_delete_property (internal_object_p, ECMA_PROPERTY_VALUE_PTR (property_p)); return true; -} /* jerry_delete_internal_property */ +} /* jerry_object_delete_internal */ /** * Get value of a property to the specified object with the given name. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the property - if success * value marked with error flag - otherwise */ jerry_value_t -jerry_get_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name (string value) */ +jerry_object_get (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name (string value) */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } jerry_value_t ret_value = - ecma_op_object_get (ecma_get_object_from_value (obj_val), ecma_get_prop_name_from_value (prop_name_val)); + ecma_op_object_get (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key)); return jerry_return (ret_value); -} /* jerry_get_property */ +} /* jerry_object_get */ /** * Get value by an index from the specified object. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the property specified by the index - if success * value marked with error flag - otherwise */ jerry_value_t -jerry_get_property_by_index (const jerry_value_t obj_val, /**< object value */ - uint32_t index) /**< index to be written */ +jerry_object_get_index (const jerry_value_t object, /**< object value */ + uint32_t index) /**< index to be written */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_value_t ret_value = ecma_op_object_get_by_index (ecma_get_object_from_value (obj_val), index); + ecma_value_t ret_value = ecma_op_object_get_by_index (ecma_get_object_from_value (object), index); return jerry_return (ret_value); -} /* jerry_get_property_by_index */ +} /* jerry_object_get_index */ /** * Get the own property value of an object with the given name. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the property - if success * value marked with error flag - otherwise */ jerry_value_t -jerry_get_own_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val, /**< property name (string value) */ - const jerry_value_t receiver_val, /**< receiver object value */ - bool *found_p) /**< [out] true, if the property is found - * or obj_val is a Proxy object, false otherwise */ +jerry_object_find_own (const jerry_value_t object, /**< object value */ + const jerry_value_t key, /**< property name (string value) */ + const jerry_value_t receiver, /**< receiver object value */ + bool *found_p) /**< [out] true, if the property is found + * or object is a Proxy object, false otherwise */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (found_p != NULL) { *found_p = false; } - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val) - || !ecma_is_value_object (receiver_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key) || !ecma_is_value_object (receiver)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_object_t *object_p = ecma_get_object_from_value (obj_val); - ecma_string_t *property_name_p = ecma_get_prop_name_from_value (prop_name_val); + ecma_object_t *object_p = ecma_get_object_from_value (object); + ecma_string_t *property_name_p = ecma_get_prop_name_from_value (key); #if JERRY_BUILTIN_PROXY if (ECMA_OBJECT_IS_PROXY (object_p)) @@ -3510,11 +3459,11 @@ jerry_get_own_property (const jerry_value_t obj_val, /**< object value */ *found_p = true; } - return jerry_return (ecma_proxy_object_get (object_p, property_name_p, receiver_val)); + return jerry_return (ecma_proxy_object_get (object_p, property_name_p, receiver)); } #endif /* JERRY_BUILTIN_PROXY */ - ecma_value_t ret_value = ecma_op_object_find_own (receiver_val, object_p, property_name_p); + ecma_value_t ret_value = ecma_op_object_find_own (receiver, object_p, property_name_p); if (ecma_is_value_found (ret_value)) { @@ -3527,30 +3476,30 @@ jerry_get_own_property (const jerry_value_t obj_val, /**< object value */ } return ECMA_VALUE_UNDEFINED; -} /* jerry_get_own_property */ +} /* jerry_object_find_own */ /** * Get value of an internal property to the specified object with the given name. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return value of the internal property - if the internal property exists * undefined value - if the internal does not property exists * value marked with error flag - otherwise */ jerry_value_t -jerry_get_internal_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val) /**< property name value */ +jerry_object_get_internal (const jerry_value_t object, /**< object value */ + const jerry_value_t key) /**< property name value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); ecma_string_t *internal_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_API_INTERNAL); @@ -3567,7 +3516,7 @@ jerry_get_internal_property (const jerry_value_t obj_val, /**< object value */ } ecma_object_t *internal_object_p = ecma_get_object_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value); - property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (prop_name_val)); + property_p = ecma_find_named_property (internal_object_p, ecma_get_prop_name_from_value (key)); if (property_p == NULL) { @@ -3575,87 +3524,82 @@ jerry_get_internal_property (const jerry_value_t obj_val, /**< object value */ } return jerry_return (ecma_copy_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value)); -} /* jerry_get_internal_property */ +} /* jerry_object_get_internal */ /** * Set a property to the specified object with the given name. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful * value marked with error flag - otherwise */ jerry_value_t -jerry_set_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val, /**< property name (string value) */ - const jerry_value_t value_to_set) /**< value to set */ +jerry_object_set (const jerry_value_t object, /**< object value */ + const jerry_value_t key, /**< property name (string value) */ + const jerry_value_t value) /**< value to set */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value_to_set) || !ecma_is_value_object (obj_val) - || !ecma_is_value_prop_name (prop_name_val)) + if (ecma_is_value_exception (value) || !ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - return jerry_return (ecma_op_object_put (ecma_get_object_from_value (obj_val), - ecma_get_prop_name_from_value (prop_name_val), - value_to_set, - true)); -} /* jerry_set_property */ + return jerry_return ( + ecma_op_object_put (ecma_get_object_from_value (object), ecma_get_prop_name_from_value (key), value, true)); +} /* jerry_object_set */ /** * Set indexed value in the specified object * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful * value marked with error flag - otherwise */ jerry_value_t -jerry_set_property_by_index (const jerry_value_t obj_val, /**< object value */ - uint32_t index, /**< index to be written */ - const jerry_value_t value_to_set) /**< value to set */ +jerry_object_set_index (const jerry_value_t object, /**< object value */ + uint32_t index, /**< index to be written */ + const jerry_value_t value) /**< value to set */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value_to_set) || !ecma_is_value_object (obj_val)) + if (ecma_is_value_exception (value) || !ecma_is_value_object (object)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_value_t ret_value = - ecma_op_object_put_by_index (ecma_get_object_from_value (obj_val), index, value_to_set, true); + ecma_value_t ret_value = ecma_op_object_put_by_index (ecma_get_object_from_value (object), index, value, true); return jerry_return (ret_value); -} /* jerry_set_property_by_index */ +} /* jerry_object_set_index */ /** * Set an internal property to the specified object with the given name. * * Note: * - the property cannot be accessed from the JavaScript context, only from the public API - * - returned value must be freed with jerry_release_value, when it is no longer needed. + * - returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful * value marked with error flag - otherwise */ bool -jerry_set_internal_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val, /**< property name value */ - const jerry_value_t value_to_set) /**< value to set */ +jerry_object_set_internal (const jerry_value_t object, /**< object value */ + const jerry_value_t key, /**< property name value */ + const jerry_value_t value) /**< value to set */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (value_to_set) || !ecma_is_value_object (obj_val) - || !ecma_is_value_prop_name (prop_name_val)) + if (ecma_is_value_exception (value) || !ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return false; } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); ecma_string_t *internal_string_p = ecma_get_magic_string (LIT_INTERNAL_MAGIC_API_INTERNAL); @@ -3686,7 +3630,7 @@ jerry_set_internal_property (const jerry_value_t obj_val, /**< object value */ internal_object_p = ecma_get_object_from_value (ECMA_PROPERTY_VALUE_PTR (property_p)->value); } - ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (prop_name_val); + ecma_string_t *prop_name_p = ecma_get_prop_name_from_value (key); property_p = ecma_find_named_property (internal_object_p, prop_name_p); if (property_p == NULL) @@ -3696,15 +3640,15 @@ jerry_set_internal_property (const jerry_value_t obj_val, /**< object value */ ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE, NULL); - value_p->value = ecma_copy_value_if_not_object (value_to_set); + value_p->value = ecma_copy_value_if_not_object (value); } else { - ecma_named_data_property_assign_value (internal_object_p, ECMA_PROPERTY_VALUE_PTR (property_p), value_to_set); + ecma_named_data_property_assign_value (internal_object_p, ECMA_PROPERTY_VALUE_PTR (property_p), value); } return true; -} /* jerry_set_internal_property */ +} /* jerry_object_set_internal */ /** * Construct empty property descriptor, i.e.: @@ -3713,7 +3657,7 @@ jerry_set_internal_property (const jerry_value_t obj_val, /**< object value */ * @return empty property descriptor */ jerry_property_descriptor_t -jerry_property_descriptor_create (void) +jerry_property_descriptor (void) { jerry_property_descriptor_t prop_desc; @@ -3723,7 +3667,7 @@ jerry_property_descriptor_create (void) prop_desc.setter = ECMA_VALUE_UNDEFINED; return prop_desc; -} /* jerry_property_descriptor_create */ +} /* jerry_property_descriptor */ /** * Convert a ecma_property_descriptor_t to a jerry_property_descriptor_t @@ -3735,7 +3679,7 @@ jerry_property_descriptor_create (void) static jerry_property_descriptor_t jerry_property_descriptor_from_ecma (const ecma_property_descriptor_t *prop_desc_p) /**<[out] property_descriptor */ { - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); prop_desc.flags = prop_desc_p->flags; @@ -3788,7 +3732,7 @@ jerry_property_descriptor_to_ecma (const jerry_property_descriptor_t *prop_desc_ /* Copy data property info. */ if (prop_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) { - if (ecma_is_value_error_reference (prop_desc_p->value) + if (ecma_is_value_exception (prop_desc_p->value) || (prop_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED))) { prop_desc.value = ECMA_VALUE_ERROR; @@ -3803,7 +3747,7 @@ jerry_property_descriptor_to_ecma (const jerry_property_descriptor_t *prop_desc_ { ecma_value_t getter = prop_desc_p->getter; - if (ecma_is_value_error_reference (getter)) + if (ecma_is_value_exception (getter)) { prop_desc.value = ECMA_VALUE_ERROR; return prop_desc; @@ -3824,7 +3768,7 @@ jerry_property_descriptor_to_ecma (const jerry_property_descriptor_t *prop_desc_ { ecma_value_t setter = prop_desc_p->setter; - if (ecma_is_value_error_reference (setter)) + if (ecma_is_value_exception (setter)) { prop_desc.value = ECMA_VALUE_ERROR; return prop_desc; @@ -3872,27 +3816,27 @@ jerry_type_error_or_false (const char *msg_p, /**< message */ return ECMA_VALUE_FALSE; } - return jerry_throw (ecma_raise_type_error (msg_p)); + return jerry_throw_sz (JERRY_ERROR_TYPE, msg_p); } /* jerry_type_error_or_false */ /** * Define a property to the specified object with the given name. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful * false value - if the property cannot be defined and JERRY_PROP_SHOULD_THROW is not set * value marked with error flag - otherwise */ jerry_value_t -jerry_define_own_property (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val, /**< property name (string value) */ - const jerry_property_descriptor_t *prop_desc_p) /**< property descriptor */ +jerry_object_define_own_prop (const jerry_value_t object, /**< object value */ + const jerry_value_t key, /**< property name (string value) */ + const jerry_property_descriptor_t *prop_desc_p) /**< property descriptor */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return jerry_type_error_or_false (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p), prop_desc_p->flags); } @@ -3910,10 +3854,10 @@ jerry_define_own_property (const jerry_value_t obj_val, /**< object value */ return jerry_type_error_or_false (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p), prop_desc_p->flags); } - return jerry_return (ecma_op_object_define_own_property (ecma_get_object_from_value (obj_val), - ecma_get_prop_name_from_value (prop_name_val), + return jerry_return (ecma_op_object_define_own_property (ecma_get_object_from_value (object), + ecma_get_prop_name_from_value (key), &prop_desc)); -} /* jerry_define_own_property */ +} /* jerry_object_define_own_prop */ /** * Construct property descriptor from specified property. @@ -3922,27 +3866,27 @@ jerry_define_own_property (const jerry_value_t obj_val, /**< object value */ * false - otherwise, the prop_desc_p is unchanged */ jerry_value_t -jerry_get_own_property_descriptor (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t prop_name_val, /**< property name (string value) */ - jerry_property_descriptor_t *prop_desc_p) /**< property descriptor */ +jerry_object_get_own_prop (const jerry_value_t object, /**< object value */ + const jerry_value_t key, /**< property name (string value) */ + jerry_property_descriptor_t *prop_desc_p) /**< property descriptor */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || !ecma_is_value_prop_name (prop_name_val)) + if (!ecma_is_value_object (object) || !ecma_is_value_prop_name (key)) { return ECMA_VALUE_FALSE; } ecma_property_descriptor_t prop_desc; - ecma_value_t status = ecma_op_object_get_own_property_descriptor (ecma_get_object_from_value (obj_val), - ecma_get_prop_name_from_value (prop_name_val), + ecma_value_t status = ecma_op_object_get_own_property_descriptor (ecma_get_object_from_value (object), + ecma_get_prop_name_from_value (key), &prop_desc); #if JERRY_BUILTIN_PROXY if (ECMA_IS_VALUE_ERROR (status)) { - return jerry_throw (status); + return ecma_create_exception_from_context (); } #endif /* JERRY_BUILTIN_PROXY */ @@ -3991,27 +3935,27 @@ jerry_get_own_property_descriptor (const jerry_value_t obj_val, /**< object valu } return ECMA_VALUE_TRUE; -} /* jerry_get_own_property_descriptor */ +} /* jerry_object_get_own_prop */ /** * Free fields of property descriptor (setter, getter and value). */ void -jerry_property_descriptor_free (const jerry_property_descriptor_t *prop_desc_p) /**< property descriptor */ +jerry_property_descriptor_free (jerry_property_descriptor_t *prop_desc_p) /**< property descriptor */ { if (prop_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) { - jerry_release_value (prop_desc_p->value); + jerry_value_free (prop_desc_p->value); } if (prop_desc_p->flags & JERRY_PROP_IS_GET_DEFINED) { - jerry_release_value (prop_desc_p->getter); + jerry_value_free (prop_desc_p->getter); } if (prop_desc_p->flags & JERRY_PROP_IS_SET_DEFINED) { - jerry_release_value (prop_desc_p->setter); + jerry_value_free (prop_desc_p->setter); } } /* jerry_property_descriptor_free */ @@ -4019,92 +3963,92 @@ jerry_property_descriptor_free (const jerry_property_descriptor_t *prop_desc_p) * Call function specified by a function value * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * error flag must not be set for any arguments of this function. * * @return returned jerry value of the called function */ jerry_value_t -jerry_call_function (const jerry_value_t func_obj_val, /**< function object to call */ - const jerry_value_t this_val, /**< object for 'this' binding */ - const jerry_value_t args_p[], /**< function's call arguments */ - jerry_size_t args_count) /**< number of the arguments */ +jerry_call (const jerry_value_t func_object, /**< function object to call */ + const jerry_value_t this_value, /**< object for 'this' binding */ + const jerry_value_t args_p[], /**< function's call arguments */ + jerry_size_t args_count) /**< number of the arguments */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_error_reference (this_val)) + if (ecma_is_value_exception (this_value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } for (jerry_size_t i = 0; i < args_count; i++) { - if (ecma_is_value_error_reference (args_p[i])) + if (ecma_is_value_exception (args_p[i])) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } } - return jerry_return (ecma_op_function_validated_call (func_obj_val, this_val, args_p, args_count)); -} /* jerry_call_function */ + return jerry_return (ecma_op_function_validated_call (func_object, this_value, args_p, args_count)); +} /* jerry_call */ /** * Construct object value invoking specified function value as a constructor * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * error flag must not be set for any arguments of this function. * * @return returned jerry value of the invoked constructor */ jerry_value_t -jerry_construct_object (const jerry_value_t func_obj_val, /**< function object to call */ - const jerry_value_t args_p[], /**< function's call arguments - * (NULL if arguments number is zero) */ - jerry_size_t args_count) /**< number of the arguments */ +jerry_construct (const jerry_value_t func_object, /**< function object to call */ + const jerry_value_t args_p[], /**< function's call arguments + * (NULL if arguments number is zero) */ + jerry_size_t args_count) /**< number of the arguments */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!jerry_value_is_constructor (func_obj_val)) + if (!jerry_value_is_constructor (func_object)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } for (jerry_size_t i = 0; i < args_count; i++) { - if (ecma_is_value_error_reference (args_p[i])) + if (ecma_is_value_exception (args_p[i])) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } } - return jerry_return (ecma_op_function_construct (ecma_get_object_from_value (func_obj_val), - ecma_get_object_from_value (func_obj_val), + return jerry_return (ecma_op_function_construct (ecma_get_object_from_value (func_object), + ecma_get_object_from_value (func_object), args_p, args_count)); -} /* jerry_construct_object */ +} /* jerry_construct */ /** * Get keys of the specified object value * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return array object value - if success * value marked with error flag - otherwise */ jerry_value_t -jerry_get_object_keys (const jerry_value_t obj_val) /**< object value */ +jerry_object_keys (const jerry_value_t object) /**< object value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } ecma_collection_t *prop_names = - ecma_op_object_get_enumerable_property_names (ecma_get_object_from_value (obj_val), ECMA_ENUMERABLE_PROPERTY_KEYS); + ecma_op_object_get_enumerable_property_names (ecma_get_object_from_value (object), ECMA_ENUMERABLE_PROPERTY_KEYS); #if JERRY_BUILTIN_PROXY if (JERRY_UNLIKELY (prop_names == NULL)) @@ -4114,28 +4058,28 @@ jerry_get_object_keys (const jerry_value_t obj_val) /**< object value */ #endif /* JERRY_BUILTIN_PROXY */ return ecma_op_new_array_object_from_collection (prop_names, false); -} /* jerry_get_object_keys */ +} /* jerry_object_keys */ /** * Get the prototype of the specified object * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return prototype object or null value - if success * value marked with error flag - otherwise */ jerry_value_t -jerry_get_prototype (const jerry_value_t obj_val) /**< object value */ +jerry_object_proto (const jerry_value_t object) /**< object value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); #if JERRY_BUILTIN_PROXY if (ECMA_OBJECT_IS_PROXY (obj_p)) @@ -4153,7 +4097,7 @@ jerry_get_prototype (const jerry_value_t obj_val) /**< object value */ ecma_ref_object (proto_obj_p); return ecma_make_object_value (proto_obj_p); -} /* jerry_get_prototype */ +} /* jerry_object_proto */ /** * Set the prototype of the specified object @@ -4162,27 +4106,27 @@ jerry_get_prototype (const jerry_value_t obj_val) /**< object value */ * value marked with error flag - otherwise */ jerry_value_t -jerry_set_prototype (const jerry_value_t obj_val, /**< object value */ - const jerry_value_t proto_obj_val) /**< prototype object value */ +jerry_object_set_proto (const jerry_value_t object, /**< object value */ + const jerry_value_t proto) /**< prototype object value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val) || ecma_is_value_error_reference (proto_obj_val) - || (!ecma_is_value_object (proto_obj_val) && !ecma_is_value_null (proto_obj_val))) + if (!ecma_is_value_object (object) || ecma_is_value_exception (proto) + || (!ecma_is_value_object (proto) && !ecma_is_value_null (proto))) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); #if JERRY_BUILTIN_PROXY if (ECMA_OBJECT_IS_PROXY (obj_p)) { - return jerry_return (ecma_proxy_object_set_prototype_of (obj_p, proto_obj_val)); + return jerry_return (ecma_proxy_object_set_prototype_of (obj_p, proto)); } #endif /* JERRY_BUILTIN_PROXY */ - return ecma_op_ordinary_object_set_prototype_of (obj_p, proto_obj_val); -} /* jerry_set_prototype */ + return ecma_op_ordinary_object_set_prototype_of (obj_p, proto); +} /* jerry_object_set_proto */ /** * Utility to check if a given object can be used for the foreach api calls. @@ -4226,12 +4170,12 @@ jerry_object_is_valid_foreach (ecma_object_t *object_p) /**< object to test */ * false - otherwise - traversal visited all objects. */ bool -jerry_objects_foreach (jerry_objects_foreach_t foreach_p, /**< function pointer of the iterator function */ - void *user_data_p) /**< pointer to user data */ +jerry_foreach_live_object (jerry_foreach_live_object_cb_t callback, /**< function pointer of the iterator function */ + void *user_data_p) /**< pointer to user data */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - JERRY_ASSERT (foreach_p != NULL); + JERRY_ASSERT (callback != NULL); jmem_cpointer_t iter_cp = JERRY_CONTEXT (ecma_gc_objects_cp); @@ -4239,7 +4183,7 @@ jerry_objects_foreach (jerry_objects_foreach_t foreach_p, /**< function pointer { ecma_object_t *iter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, iter_cp); - if (jerry_object_is_valid_foreach (iter_p) && !foreach_p (ecma_make_object_value (iter_p), user_data_p)) + if (jerry_object_is_valid_foreach (iter_p) && !callback (ecma_make_object_value (iter_p), user_data_p)) { return true; } @@ -4248,7 +4192,7 @@ jerry_objects_foreach (jerry_objects_foreach_t foreach_p, /**< function pointer } return false; -} /* jerry_objects_foreach */ +} /* jerry_foreach_live_object */ /** * Traverse objects having a given native type info. @@ -4257,16 +4201,16 @@ jerry_objects_foreach (jerry_objects_foreach_t foreach_p, /**< function pointer * false - otherwise - traversal visited all objects. */ bool -jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_info_p, /**< the type info - * of the native pointer */ - jerry_objects_foreach_by_native_info_t foreach_p, /**< function to apply for +jerry_foreach_live_object_with_info (const jerry_object_native_info_t *native_info_p, /**< the type info + * of the native pointer */ + jerry_foreach_live_object_with_info_cb_t callback, /**< function to apply for * each matching object */ - void *user_data_p) /**< pointer to user data */ + void *user_data_p) /**< pointer to user data */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); JERRY_ASSERT (native_info_p != NULL); - JERRY_ASSERT (foreach_p != NULL); + JERRY_ASSERT (callback != NULL); ecma_native_pointer_t *native_pointer_p; @@ -4279,7 +4223,7 @@ jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_i if (jerry_object_is_valid_foreach (iter_p)) { native_pointer_p = ecma_get_native_pointer_value (iter_p, (void *) native_info_p); - if (native_pointer_p && !foreach_p (ecma_make_object_value (iter_p), native_pointer_p->native_p, user_data_p)) + if (native_pointer_p && !callback (ecma_make_object_value (iter_p), native_pointer_p->native_p, user_data_p)) { return true; } @@ -4289,7 +4233,7 @@ jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_i } return false; -} /* jerry_objects_foreach_by_native_info */ +} /* jerry_foreach_live_object_with_info */ /** * Get native pointer and its type information, associated with the given native type info. @@ -4297,37 +4241,31 @@ jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_i * Note: * If native pointer is present, its type information is returned in out_native_pointer_p * - * @return true - if there is an associated pointer, - * false - otherwise + * @return found native pointer, + * or NULL */ -bool -jerry_get_object_native_pointer (const jerry_value_t obj_val, /**< object to get native pointer from */ - void **out_native_pointer_p, /**< [out] native pointer */ - const jerry_object_native_info_t *native_info_p) /**< the type info - * of the native pointer */ +void * +jerry_object_get_native_ptr (const jerry_value_t object, /**< object to get native pointer from */ + const jerry_object_native_info_t *native_info_p) /**< the type info + * of the native pointer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { - return false; + return NULL; } - ecma_native_pointer_t *native_pointer_p; - native_pointer_p = ecma_get_native_pointer_value (ecma_get_object_from_value (obj_val), (void *) native_info_p); + ecma_object_t *obj_p = ecma_get_object_from_value (object); + ecma_native_pointer_t *native_pointer_p = ecma_get_native_pointer_value (obj_p, (void *) native_info_p); if (native_pointer_p == NULL) { - return false; - } - - if (out_native_pointer_p != NULL) - { - *out_native_pointer_p = native_pointer_p->native_p; + return NULL; } - return true; -} /* jerry_get_object_native_pointer */ + return native_pointer_p->native_p; +} /* jerry_object_get_native_ptr */ /** * Set native pointer and an optional type info for the specified object. @@ -4344,19 +4282,42 @@ jerry_get_object_native_pointer (const jerry_value_t obj_val, /**< object to get * a NULL value deletes the current type info. */ void -jerry_set_object_native_pointer (const jerry_value_t obj_val, /**< object to set native pointer in */ - void *native_pointer_p, /**< native pointer */ - const jerry_object_native_info_t *native_info_p) /**< object's native type info */ +jerry_object_set_native_ptr (const jerry_value_t object, /**< object to set native pointer in */ + const jerry_object_native_info_t *native_info_p, /**< object's native type info */ + void *native_pointer_p) /**< native pointer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_object (obj_val)) + if (ecma_is_value_object (object)) { - ecma_object_t *object_p = ecma_get_object_from_value (obj_val); + ecma_object_t *object_p = ecma_get_object_from_value (object); ecma_create_native_pointer_property (object_p, native_pointer_p, native_info_p); } -} /* jerry_set_object_native_pointer */ +} /* jerry_object_set_native_ptr */ + +/** + * Checks wether the argument object has a native poitner set for the specified native type info. + * + * @return true if the native pointer has been set, + * false otherwise + */ +bool +jerry_object_has_native_ptr (const jerry_value_t object, /**< object to set native pointer in */ + const jerry_object_native_info_t *native_info_p) /**< object's native type info */ +{ + jerry_assert_api_enabled (); + + if (!ecma_is_value_object (object)) + { + return false; + } + + ecma_object_t *obj_p = ecma_get_object_from_value (object); + ecma_native_pointer_t *native_pointer_p = ecma_get_native_pointer_value (obj_p, (void *) native_info_p); + + return native_pointer_p != NULL; +} /* jerry_object_has_native_ptr */ /** * Delete the previously set native pointer by the native type info from the specified object. @@ -4372,31 +4333,31 @@ jerry_set_object_native_pointer (const jerry_value_t obj_val, /**< object to set * false - otherwise */ bool -jerry_delete_object_native_pointer (const jerry_value_t obj_val, /**< object to delete native pointer from */ - const jerry_object_native_info_t *native_info_p) /**< object's native type info */ +jerry_object_delete_native_ptr (const jerry_value_t object, /**< object to delete native pointer from */ + const jerry_object_native_info_t *native_info_p) /**< object's native type info */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (ecma_is_value_object (obj_val)) + if (ecma_is_value_object (object)) { - ecma_object_t *object_p = ecma_get_object_from_value (obj_val); + ecma_object_t *object_p = ecma_get_object_from_value (object); return ecma_delete_native_pointer_property (object_p, (void *) native_info_p); } return false; -} /* jerry_delete_object_native_pointer */ +} /* jerry_object_delete_native_ptr */ /** * Initialize the references stored in a buffer pointed by a native pointer. * The references are initialized to undefined. */ void -jerry_native_pointer_init_references (void *native_pointer_p, /**< a valid non-NULL pointer to a native buffer */ - const jerry_object_native_info_t *native_info_p) /**< the type info of - * the native pointer */ +jerry_native_ptr_init (void *native_pointer_p, /**< a valid non-NULL pointer to a native buffer */ + const jerry_object_native_info_t *native_info_p) /**< the type info of + * the native pointer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (native_pointer_p == NULL || native_info_p == NULL) { @@ -4410,19 +4371,19 @@ jerry_native_pointer_init_references (void *native_pointer_p, /**< a valid non-N { *value_p++ = ECMA_VALUE_UNDEFINED; } -} /* jerry_native_pointer_init_references */ +} /* jerry_native_ptr_init */ /** * Release the value references after a buffer pointed by a native pointer * is not attached to an object anymore. All references are set to undefined - * similar to jerry_native_pointer_init_references. + * similar to jerry_native_ptr_init. */ void -jerry_native_pointer_release_references (void *native_pointer_p, /**< a valid non-NULL pointer to a native buffer */ - const jerry_object_native_info_t *native_info_p) /**< the type info of - * the native pointer */ +jerry_native_ptr_free (void *native_pointer_p, /**< a valid non-NULL pointer to a native buffer */ + const jerry_object_native_info_t *native_info_p) /**< the type info of + * the native pointer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (native_pointer_p == NULL || native_info_p == NULL) { @@ -4437,7 +4398,7 @@ jerry_native_pointer_release_references (void *native_pointer_p, /**< a valid no ecma_free_value_if_not_object (*value_p); *value_p++ = ECMA_VALUE_UNDEFINED; } -} /* jerry_native_pointer_release_references */ +} /* jerry_native_ptr_free */ /** * Updates a value reference inside the area specified by the number_of_references and @@ -4448,25 +4409,25 @@ jerry_native_pointer_release_references (void *native_pointer_p, /**< a valid no * Error references are not supported, they are replaced by undefined values. */ void -jerry_native_pointer_set_reference (jerry_value_t *reference_p, /**< a valid non-NULL pointer to - * a reference in a native buffer. */ - jerry_value_t value) /**< new value of the reference */ +jerry_native_ptr_set (jerry_value_t *reference_p, /**< a valid non-NULL pointer to + * a reference in a native buffer. */ + jerry_value_t value) /**< new value of the reference */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); if (reference_p == NULL) { return; } - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { value = ECMA_VALUE_UNDEFINED; } ecma_free_value_if_not_object (*reference_p); *reference_p = ecma_copy_value_if_not_object (value); -} /* jerry_native_pointer_set_reference */ +} /* jerry_native_ptr_set */ /** * Applies the given function to the every property in the object. @@ -4478,18 +4439,18 @@ jerry_native_pointer_set_reference (jerry_value_t *reference_p, /**< a valid non * if getter of field threw a exception or unhandled exceptions were thrown during traversal; */ bool -jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */ - jerry_object_property_foreach_t foreach_p, /**< foreach function */ - void *user_data_p) /**< user data for foreach function */ +jerry_object_foreach (const jerry_value_t object, /**< object value */ + jerry_object_property_foreach_cb_t foreach_p, /**< foreach function */ + void *user_data_p) /**< user data for foreach function */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { return false; } - ecma_object_t *object_p = ecma_get_object_from_value (obj_val); + ecma_object_t *object_p = ecma_get_object_from_value (object); ecma_collection_t *names_p = ecma_op_object_enumerate (object_p); #if JERRY_BUILTIN_PROXY @@ -4531,7 +4492,7 @@ jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */ jcontext_release_exception (); return false; -} /* jerry_foreach_object_property */ +} /* jerry_object_foreach */ /** * Gets the property keys for the given object using the selected filters. @@ -4540,17 +4501,17 @@ jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */ * value marked with error flag - otherwise */ jerry_value_t -jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */ - jerry_property_filter_t filter) /**< property filter options */ +jerry_object_property_names (const jerry_value_t object, /**< object */ + jerry_property_filter_t filter) /**< property filter options */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); - if (!ecma_is_value_object (obj_val)) + if (!ecma_is_value_object (object)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - ecma_object_t *obj_p = ecma_get_object_from_value (obj_val); + ecma_object_t *obj_p = ecma_get_object_from_value (object); ecma_object_t *obj_iter_p = obj_p; ecma_collection_t *result_p = ecma_new_collection (); @@ -4565,7 +4526,7 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */ if (prop_names_p == NULL) { ecma_deref_object (obj_iter_p); - return jerry_throw (ECMA_VALUE_ERROR); + return ecma_create_exception_from_context (); } #endif /* JERRY_BUILTIN_PROXY */ @@ -4616,7 +4577,7 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */ ecma_collection_free (prop_names_p); ecma_collection_free (result_p); ecma_deref_object (obj_iter_p); - return jerry_throw (ECMA_VALUE_ERROR); + return ecma_create_exception_from_context (); } #endif /* JERRY_BUILTIN_PROXY */ @@ -4696,7 +4657,7 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */ if (JERRY_UNLIKELY (proto_p == ECMA_OBJECT_POINTER_ERROR)) { ecma_collection_free (result_p); - return jerry_throw (ECMA_VALUE_ERROR); + return ecma_create_exception_from_context (); } obj_iter_p = proto_p; @@ -4705,7 +4666,7 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */ ecma_deref_object (obj_iter_p); return ecma_op_new_array_object_from_collection (result_p, false); -} /* jerry_object_get_property_names */ +} /* jerry_object_property_names */ /** * FromPropertyDescriptor abstract operation. @@ -4714,21 +4675,21 @@ jerry_object_get_property_names (const jerry_value_t obj_val, /**< object */ * value marked with error flag - otherwise */ jerry_value_t -jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc_p) /**< property descriptor */ +jerry_property_descriptor_to_object (const jerry_property_descriptor_t *src_prop_desc_p) /**< property descriptor */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); ecma_property_descriptor_t prop_desc = jerry_property_descriptor_to_ecma (src_prop_desc_p); if (ECMA_IS_VALUE_ERROR (prop_desc.value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } ecma_object_t *desc_obj_p = ecma_op_from_property_descriptor (&prop_desc); return ecma_make_object_value (desc_obj_p); -} /* jerry_from_property_descriptor */ +} /* jerry_property_descriptor_to_object */ /** * ToPropertyDescriptor abstract operation. @@ -4737,65 +4698,90 @@ jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc * thrown error - otherwise */ jerry_value_t -jerry_to_property_descriptor (jerry_value_t obj_value, /**< object value */ - jerry_property_descriptor_t *out_prop_desc_p) /**< [out] filled property descriptor - * if return value is true, - * unmodified otherwise */ +jerry_property_descriptor_from_object (const jerry_value_t object, /**< object value */ + jerry_property_descriptor_t *out_prop_desc_p) /**< [out] filled property + * descriptor if return value is + * true, unmodified otherwise */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); ecma_property_descriptor_t prop_desc; - jerry_value_t result = ecma_op_to_property_descriptor (obj_value, &prop_desc); + jerry_value_t result = ecma_op_to_property_descriptor (object, &prop_desc); if (ECMA_IS_VALUE_ERROR (result)) { - return jerry_throw (result); + return ecma_create_exception_from_context (); } JERRY_ASSERT (result == ECMA_VALUE_EMPTY); *out_prop_desc_p = jerry_property_descriptor_from_ecma (&prop_desc); return ECMA_VALUE_TRUE; -} /* jerry_to_property_descriptor */ +} /* jerry_property_descriptor_from_object */ /** - * Resolve or reject the promise with an argument. + * Resolve a promise value with an argument. * - * @return undefined value - if success - * value marked with error flag - otherwise + * @return undefined - if success, + * exception - otherwise */ jerry_value_t -jerry_resolve_or_reject_promise (jerry_value_t promise, /**< the promise value */ - jerry_value_t argument, /**< the argument */ - bool is_resolve) /**< whether the promise should be resolved or rejected */ +jerry_promise_resolve (jerry_value_t promise, /**< the promise value */ + const jerry_value_t argument) /**< the argument */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT - if (!ecma_is_value_object (promise) || !ecma_is_promise (ecma_get_object_from_value (promise))) + if (!jerry_value_is_promise (promise)) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); + } + + if (ecma_is_value_exception (argument)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } - if (ecma_is_value_error_reference (argument)) + return ecma_fulfill_promise_with_checks (promise, argument); +#else /* !JERRY_ESNEXT */ + JERRY_UNUSED (promise); + JERRY_UNUSED (argument); + + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_promise_not_supported_p)); +#endif /* JERRY_ESNEXT */ +} /* jerry_promise_resolve */ + +/** + * Reject a promise value with an argument. + * + * @return undefined - if success, + * exception - otherwise + */ +jerry_value_t +jerry_promise_reject (jerry_value_t promise, /**< the promise value */ + const jerry_value_t argument) /**< the argument */ +{ + jerry_assert_api_enabled (); + +#if JERRY_ESNEXT + if (!jerry_value_is_promise (promise)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } - if (is_resolve) + if (ecma_is_value_exception (argument)) { - return ecma_fulfill_promise_with_checks (promise, argument); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } return ecma_reject_promise_with_checks (promise, argument); #else /* !JERRY_ESNEXT */ JERRY_UNUSED (promise); JERRY_UNUSED (argument); - JERRY_UNUSED (is_resolve); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_promise_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_promise_not_supported_p)); #endif /* JERRY_ESNEXT */ -} /* jerry_resolve_or_reject_promise */ +} /* jerry_promise_reject */ /** * Get the result of a promise. @@ -4804,22 +4790,22 @@ jerry_resolve_or_reject_promise (jerry_value_t promise, /**< the promise value * * - Type error if the promise support was not enabled or the input was not a promise object */ jerry_value_t -jerry_get_promise_result (const jerry_value_t promise) /**< promise object to get the result from */ +jerry_promise_result (const jerry_value_t promise) /**< promise object to get the result from */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT if (!jerry_value_is_promise (promise)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } return ecma_promise_get_result (ecma_get_object_from_value (promise)); #else /* !JERRY_ESNEXT */ JERRY_UNUSED (promise); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_promise_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_promise_not_supported_p)); #endif /* JERRY_ESNEXT */ -} /* jerry_get_promise_result */ +} /* jerry_promise_result */ /** * Get the state of a promise object. @@ -4829,9 +4815,9 @@ jerry_get_promise_result (const jerry_value_t promise) /**< promise object to ge * or the promise support was not enabled. */ jerry_promise_state_t -jerry_get_promise_state (const jerry_value_t promise) /**< promise object to get the state from */ +jerry_promise_state (const jerry_value_t promise) /**< promise object to get the state from */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT if (!jerry_value_is_promise (promise)) @@ -4847,7 +4833,7 @@ jerry_get_promise_state (const jerry_value_t promise) /**< promise object to get JERRY_UNUSED (promise); return JERRY_PROMISE_STATE_NONE; #endif /* JERRY_ESNEXT */ -} /* jerry_get_promise_state */ +} /* jerry_promise_state */ /** * Sets a callback for tracking Promise and async operations. @@ -4856,11 +4842,11 @@ jerry_get_promise_state (const jerry_value_t promise) /**< promise object to get * the previous callback is overwritten */ void -jerry_promise_set_callback (jerry_promise_event_filter_t filters, /**< combination of event filters */ - jerry_promise_callback_t callback, /**< notification callback */ - void *user_p) /**< user pointer passed to the callback */ +jerry_promise_event_cb (jerry_promise_event_filter_t filters, /**< combination of event filters */ + jerry_promise_event_cb_t callback, /**< notification callback */ + void *user_p) /**< user pointer passed to the callback */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT && JERRY_PROMISE_CALLBACK if (filters == JERRY_PROMISE_EVENT_FILTER_DISABLE || callback == NULL) @@ -4877,21 +4863,21 @@ jerry_promise_set_callback (jerry_promise_event_filter_t filters, /**< combinati JERRY_UNUSED (callback); JERRY_UNUSED (user_p); #endif /* JERRY_ESNEXT && JERRY_PROMISE_CALLBACK */ -} /* jerry_promise_set_callback */ +} /* jerry_promise_event_cb */ /** * Get the well-knwon symbol represented by the given `symbol` enum value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return undefined value - if invalid well-known symbol was requested * well-known symbol value - otherwise */ jerry_value_t -jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol) /**< jerry_well_known_symbol_t enum value */ +jerry_symbol (jerry_well_known_symbol_t symbol) /**< jerry_well_known_symbol_t enum value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT lit_magic_string_id_t id = (lit_magic_string_id_t) (LIT_GLOBAL_SYMBOL__FIRST + symbol); @@ -4907,26 +4893,26 @@ jerry_get_well_known_symbol (jerry_well_known_symbol_t symbol) /**< jerry_well_k return ECMA_VALUE_UNDEFINED; #endif /* JERRY_ESNEXT */ -} /* jerry_get_well_known_symbol */ +} /* jerry_symbol */ /** * Returns the description internal property of a symbol. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return string or undefined value containing the symbol's description - if success * thrown error - otherwise */ jerry_value_t -jerry_get_symbol_description (const jerry_value_t symbol) /**< symbol value */ +jerry_symbol_description (const jerry_value_t symbol) /**< symbol value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT if (!ecma_is_value_symbol (symbol)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } /* Note: This operation cannot throw an error */ @@ -4934,28 +4920,28 @@ jerry_get_symbol_description (const jerry_value_t symbol) /**< symbol value */ #else /* !JERRY_ESNEXT */ JERRY_UNUSED (symbol); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_symbol_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_symbol_not_supported_p)); #endif /* JERRY_ESNEXT */ -} /* jerry_get_symbol_description */ +} /* jerry_symbol_description */ /** * Call the SymbolDescriptiveString ecma builtin operation on the symbol value. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return string value containing the symbol's descriptive string - if success * thrown error - otherwise */ jerry_value_t -jerry_get_symbol_descriptive_string (const jerry_value_t symbol) /**< symbol value */ +jerry_symbol_descriptive_string (const jerry_value_t symbol) /**< symbol value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_ESNEXT if (!ecma_is_value_symbol (symbol)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } /* Note: This operation cannot throw an error */ @@ -4963,9 +4949,9 @@ jerry_get_symbol_descriptive_string (const jerry_value_t symbol) /**< symbol val #else /* !JERRY_ESNEXT */ JERRY_UNUSED (symbol); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_symbol_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_symbol_not_supported_p)); #endif /* JERRY_ESNEXT */ -} /* jerry_get_symbol_descriptive_string */ +} /* jerry_symbol_descriptive_string */ /** * Get the number of uint64 digits of a BigInt value @@ -4973,9 +4959,9 @@ jerry_get_symbol_descriptive_string (const jerry_value_t symbol) /**< symbol val * @return number of uint64 digits */ uint32_t -jerry_get_bigint_size_in_digits (jerry_value_t value) /**< BigInt value */ +jerry_bigint_digit_count (const jerry_value_t value) /**< BigInt value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_BIGINT if (!ecma_is_value_bigint (value)) @@ -4988,16 +4974,16 @@ jerry_get_bigint_size_in_digits (jerry_value_t value) /**< BigInt value */ JERRY_UNUSED (value); return 0; #endif /* JERRY_BUILTIN_BIGINT */ -} /* jerry_get_bigint_size_in_digits */ +} /* jerry_bigint_digit_count */ /** * Get the uint64 digits of a BigInt value (lowest digit first) */ void -jerry_get_bigint_digits (jerry_value_t value, /**< BigInt value */ - uint64_t *digits_p, /**< [out] buffer for digits */ - uint32_t size, /**< buffer size in digits */ - bool *sign_p) /**< [out] sign of BigInt */ +jerry_bigint_to_digits (jerry_value_t value, /**< BigInt value */ + uint64_t *digits_p, /**< [out] buffer for digits */ + uint32_t digit_count, /**< buffer size in digits */ + bool *sign_p) /**< [out] sign of BigInt */ { #if JERRY_BUILTIN_BIGINT if (!ecma_is_value_bigint (value)) @@ -5006,10 +4992,10 @@ jerry_get_bigint_digits (jerry_value_t value, /**< BigInt value */ { *sign_p = false; } - memset (digits_p, 0, size * sizeof (uint64_t)); + memset (digits_p, 0, digit_count * sizeof (uint64_t)); } - ecma_bigint_get_digits_and_sign (value, digits_p, size, sign_p); + ecma_bigint_get_digits_and_sign (value, digits_p, digit_count, sign_p); #else /* !JERRY_BUILTIN_BIGINT */ JERRY_UNUSED (value); @@ -5017,9 +5003,9 @@ jerry_get_bigint_digits (jerry_value_t value, /**< BigInt value */ { *sign_p = false; } - memset (digits_p, 0, size * sizeof (uint64_t)); + memset (digits_p, 0, digit_count * sizeof (uint64_t)); #endif /* JERRY_BUILTIN_BIGINT */ -} /* jerry_get_bigint_digits */ +} /* jerry_bigint_to_digits */ /** * Get the target object of a Proxy object @@ -5028,9 +5014,9 @@ jerry_get_bigint_digits (jerry_value_t value, /**< BigInt value */ * target object - otherwise */ jerry_value_t -jerry_get_proxy_target (jerry_value_t proxy_value) /**< proxy value */ +jerry_proxy_target (const jerry_value_t proxy_value) /**< proxy value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_PROXY if (ecma_is_value_object (proxy_value)) @@ -5052,8 +5038,8 @@ jerry_get_proxy_target (jerry_value_t proxy_value) /**< proxy value */ JERRY_UNUSED (proxy_value); #endif /* JERRY_BUILTIN_PROXY */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_argument_is_not_a_proxy))); -} /* jerry_get_proxy_target */ + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_argument_is_not_a_proxy)); +} /* jerry_proxy_target */ /** * Get the handler object of a Proxy object @@ -5062,9 +5048,9 @@ jerry_get_proxy_target (jerry_value_t proxy_value) /**< proxy value */ * handler object - otherwise */ jerry_value_t -jerry_get_proxy_handler (jerry_value_t proxy_value) /**< proxy value */ +jerry_proxy_handler (const jerry_value_t proxy_value) /**< proxy value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_PROXY if (ecma_is_value_object (proxy_value)) @@ -5086,34 +5072,36 @@ jerry_get_proxy_handler (jerry_value_t proxy_value) /**< proxy value */ JERRY_UNUSED (proxy_value); #endif /* JERRY_BUILTIN_PROXY */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_argument_is_not_a_proxy))); -} /* jerry_get_proxy_handler */ + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_argument_is_not_a_proxy)); +} /* jerry_proxy_handler */ /** - * Validate UTF-8 string + * Validate string buffer for the specified encoding * - * @return true - if UTF-8 string is well-formed + * @return true - if string is well-formed * false - otherwise */ bool -jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */ - jerry_size_t buf_size) /**< string size */ +jerry_validate_string (const jerry_char_t *buffer_p, /**< string buffer */ + jerry_size_t buffer_size, /**< buffer size */ + jerry_encoding_t encoding) /**< buffer encoding */ { - return lit_is_valid_utf8_string ((lit_utf8_byte_t *) utf8_buf_p, (lit_utf8_size_t) buf_size, true); -} /* jerry_is_valid_utf8_string */ - -/** - * Validate CESU-8 string - * - * @return true - if CESU-8 string is well-formed - * false - otherwise - */ -bool -jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string */ - jerry_size_t buf_size) /**< string size */ -{ - return lit_is_valid_cesu8_string ((lit_utf8_byte_t *) cesu8_buf_p, (lit_utf8_size_t) buf_size); -} /* jerry_is_valid_cesu8_string */ + switch (encoding) + { + case JERRY_ENCODING_CESU8: + { + return lit_is_valid_cesu8_string (buffer_p, buffer_size); + } + case JERRY_ENCODING_UTF8: + { + return lit_is_valid_utf8_string (buffer_p, buffer_size, true); + } + default: + { + return false; + } + } +} /* jerry_validate_string */ /** * Allocate memory on the engine's heap. @@ -5127,9 +5115,9 @@ jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string * NULL otherwise */ void * -jerry_heap_alloc (size_t size) /**< size of the memory block */ +jerry_heap_alloc (jerry_size_t size) /**< size of the memory block */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return jmem_heap_alloc_block_null_on_error (size); } /* jerry_heap_alloc */ @@ -5139,9 +5127,9 @@ jerry_heap_alloc (size_t size) /**< size of the memory block */ */ void jerry_heap_free (void *mem_p, /**< value returned by jerry_heap_alloc */ - size_t size) /**< same size as passed to jerry_heap_alloc */ + jerry_size_t size) /**< same size as passed to jerry_heap_alloc */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); jmem_heap_free_block (mem_p, size); } /* jerry_heap_free */ @@ -5152,9 +5140,9 @@ jerry_heap_free (void *mem_p, /**< value returned by jerry_heap_alloc */ * @return the pointer to the context. */ jerry_context_t * -jerry_create_context (uint32_t heap_size, /**< the size of heap */ - jerry_context_alloc_t alloc, /**< the alloc function */ - void *cb_data_p) /**< the cb_data for alloc function */ +jerry_context (jerry_size_t heap_size, /**< the size of heap */ + jerry_context_alloc_cb_t alloc, /**< the alloc function */ + void *cb_data_p) /**< the cb_data for alloc function */ { JERRY_UNUSED (heap_size); @@ -5209,7 +5197,7 @@ jerry_create_context (uint32_t heap_size, /**< the size of heap */ return NULL; #endif /* JERRY_EXTERNAL_CONTEXT */ -} /* jerry_create_context */ +} /* jerry_context */ /** * When JERRY_VM_EXEC_STOP is enabled, the callback passed to this function @@ -5217,9 +5205,9 @@ jerry_create_context (uint32_t heap_size, /**< the size of heap */ * than 1, the callback is only called at every frequency ticks. */ void -jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, /**< periodically called user function */ - void *user_p, /**< pointer passed to the function */ - uint32_t frequency) /**< frequency of the function call */ +jerry_halt_cb (jerry_halt_cb_t halt_cb, /**< periodically called user function */ + void *user_p, /**< pointer passed to the function */ + uint32_t frequency) /**< frequency of the function call */ { #if JERRY_VM_EXEC_STOP if (frequency == 0) @@ -5229,14 +5217,14 @@ jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, /**< per JERRY_CONTEXT (vm_exec_stop_frequency) = frequency; JERRY_CONTEXT (vm_exec_stop_counter) = frequency; - JERRY_CONTEXT (vm_exec_stop_cb) = stop_cb; + JERRY_CONTEXT (vm_exec_stop_cb) = halt_cb; JERRY_CONTEXT (vm_exec_stop_user_p) = user_p; #else /* !JERRY_VM_EXEC_STOP */ - JERRY_UNUSED (stop_cb); + JERRY_UNUSED (halt_cb); JERRY_UNUSED (user_p); JERRY_UNUSED (frequency); #endif /* JERRY_VM_EXEC_STOP */ -} /* jerry_set_vm_exec_stop_callback */ +} /* jerry_halt_cb */ /** * Get backtrace. The backtrace is an array of strings where @@ -5246,20 +5234,20 @@ jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, /**< per * @return array value */ jerry_value_t -jerry_get_backtrace (uint32_t max_depth) /**< depth limit of the backtrace */ +jerry_backtrace (uint32_t max_depth) /**< depth limit of the backtrace */ { return vm_get_backtrace (max_depth); -} /* jerry_get_backtrace */ +} /* jerry_backtrace */ /** * Low-level function to capture each backtrace frame. * The captured frame data is passed to a callback function. */ void -jerry_backtrace_capture (jerry_backtrace_callback_t callback, /**< callback function */ +jerry_backtrace_capture (jerry_backtrace_cb_t callback, /**< callback function */ void *user_p) /**< user pointer passed to the callback function */ { - jerry_backtrace_frame_t frame; + jerry_frame_t frame; vm_frame_ctx_t *context_p = JERRY_CONTEXT (vm_top_context_p); while (context_p != NULL) @@ -5274,18 +5262,18 @@ jerry_backtrace_capture (jerry_backtrace_callback_t callback, /**< callback func context_p = context_p->prev_context_p; } -} /* jerry_backtrace_capture */ +} /* jerry_backtrace */ /** * Returns with the type of the backtrace frame. * - * @return frame type listed in jerry_backtrace_frame_types_t + * @return frame type listed in jerry_frame_type_t */ -jerry_backtrace_frame_types_t -jerry_backtrace_get_frame_type (jerry_backtrace_frame_t *frame_p) /**< frame pointer */ +jerry_frame_type_t +jerry_frame_type (const jerry_frame_t *frame_p) /**< frame pointer */ { - return (jerry_backtrace_frame_types_t) frame_p->frame_type; -} /* jerry_backtrace_get_frame_type */ + return (jerry_frame_type_t) frame_p->frame_type; +} /* jerry_frame_type */ /** * Initialize and return with the location private field of a backtrace frame. @@ -5293,8 +5281,8 @@ jerry_backtrace_get_frame_type (jerry_backtrace_frame_t *frame_p) /**< frame poi * @return pointer to the location private field - if the location is available, * NULL - otherwise */ -const jerry_backtrace_location_t * -jerry_backtrace_get_location (jerry_backtrace_frame_t *frame_p) /**< frame pointer */ +const jerry_frame_location_t * +jerry_frame_location (jerry_frame_t *frame_p) /**< frame pointer */ { JERRY_UNUSED (frame_p); @@ -5309,7 +5297,7 @@ jerry_backtrace_get_location (jerry_backtrace_frame_t *frame_p) /**< frame point return NULL; } - frame_p->location.resource_name = ecma_get_resource_name (bytecode_header_p); + frame_p->location.source_name = ecma_get_source_name (bytecode_header_p); ecma_line_info_get (ecma_compiled_code_get_line_info (bytecode_header_p), (uint32_t) (context_p->byte_code_p - context_p->byte_code_start_p), @@ -5320,7 +5308,7 @@ jerry_backtrace_get_location (jerry_backtrace_frame_t *frame_p) /**< frame point #endif /* JERRY_LINE_INFO */ return NULL; -} /* jerry_backtrace_get_location */ +} /* jerry_frame_location */ /** * Initialize and return with the called function private field of a backtrace frame. @@ -5330,7 +5318,7 @@ jerry_backtrace_get_location (jerry_backtrace_frame_t *frame_p) /**< frame point * NULL - otherwise */ const jerry_value_t * -jerry_backtrace_get_function (jerry_backtrace_frame_t *frame_p) /**< frame pointer */ +jerry_frame_callee (jerry_frame_t *frame_p) /**< frame pointer */ { if (frame_p->frame_type == JERRY_BACKTRACE_FRAME_JS) { @@ -5344,7 +5332,7 @@ jerry_backtrace_get_function (jerry_backtrace_frame_t *frame_p) /**< frame point } return NULL; -} /* jerry_backtrace_get_function */ +} /* jerry_frame_callee */ /** * Initialize and return with the 'this' binding private field of a backtrace frame. @@ -5355,7 +5343,7 @@ jerry_backtrace_get_function (jerry_backtrace_frame_t *frame_p) /**< frame point * NULL - otherwise */ const jerry_value_t * -jerry_backtrace_get_this (jerry_backtrace_frame_t *frame_p) /**< frame pointer */ +jerry_frame_this (jerry_frame_t *frame_p) /**< frame pointer */ { if (frame_p->frame_type == JERRY_BACKTRACE_FRAME_JS) { @@ -5364,7 +5352,7 @@ jerry_backtrace_get_this (jerry_backtrace_frame_t *frame_p) /**< frame pointer * } return NULL; -} /* jerry_backtrace_get_this */ +} /* jerry_frame_this */ /** * Returns true, if the code bound to the backtrace frame is strict mode code. @@ -5373,16 +5361,16 @@ jerry_backtrace_get_this (jerry_backtrace_frame_t *frame_p) /**< frame pointer * * false - otherwise */ bool -jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p) /**< frame pointer */ +jerry_frame_is_strict (jerry_frame_t *frame_p) /**< frame pointer */ { return (frame_p->frame_type == JERRY_BACKTRACE_FRAME_JS && (frame_p->context_p->status_flags & VM_FRAME_CTX_IS_STRICT) != 0); -} /* jerry_backtrace_is_strict */ +} /* jerry_frame_is_strict */ /** * Get the resource name (usually a file name) of the currently executed script or the given function object * - * Note: returned value must be freed with jerry_release_value, when it is no longer needed + * Note: returned value must be freed with jerry_value_free, when it is no longer needed * * @return JS string constructed from * - the currently executed function object's resource name, if the given value is undefined @@ -5390,12 +5378,12 @@ jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p) /**< frame pointer * - "", otherwise */ jerry_value_t -jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */ +jerry_source_name (const jerry_value_t value) /**< jerry api value */ { #if JERRY_RESOURCE_NAME if (ecma_is_value_undefined (value) && JERRY_CONTEXT (vm_top_context_p) != NULL) { - return ecma_copy_value (ecma_get_resource_name (JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p)); + return ecma_copy_value (ecma_get_source_name (JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p)); } ecma_value_t script_value = ecma_script_get_from_value (value); @@ -5407,12 +5395,12 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */ const cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); - return ecma_copy_value (script_p->resource_name); + return ecma_copy_value (script_p->source_name); #else /* !JERRY_RESOURCE_NAME */ JERRY_UNUSED (value); return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); #endif /* JERRY_RESOURCE_NAME */ -} /* jerry_get_resource_name */ +} /* jerry_source_name */ /** * Returns the user value assigned to a script / module / function. @@ -5424,7 +5412,7 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */ * @return user value */ jerry_value_t -jerry_get_user_value (const jerry_value_t value) /**< jerry api value */ +jerry_source_user_value (const jerry_value_t value) /**< jerry api value */ { ecma_value_t script_value = ecma_script_get_from_value (value); @@ -5441,7 +5429,7 @@ jerry_get_user_value (const jerry_value_t value) /**< jerry api value */ } return ecma_copy_value (CBC_SCRIPT_GET_USER_VALUE (script_p)); -} /* jerry_get_user_value */ +} /* jerry_source_user_value */ /** * Checks whether an ECMAScript code is compiled by eval @@ -5451,7 +5439,7 @@ jerry_get_user_value (const jerry_value_t value) /**< jerry api value */ * false, otherwise */ bool -jerry_is_eval_code (const jerry_value_t value) /**< jerry api value */ +jerry_function_is_dynamic (const jerry_value_t value) /**< jerry api value */ { ecma_value_t script_value = ecma_script_get_from_value (value); @@ -5463,7 +5451,7 @@ jerry_is_eval_code (const jerry_value_t value) /**< jerry api value */ const cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value); return (script_p->refs_and_type & CBC_SCRIPT_IS_EVAL_CODE) != 0; -} /* jerry_is_eval_code */ +} /* jerry_function_is_dynamic */ /** * Returns a newly created source info structure corresponding to the passed script/module/function. @@ -5471,9 +5459,9 @@ jerry_is_eval_code (const jerry_value_t value) /**< jerry api value */ * @return a newly created source info, if at least one field is available, NULL otherwise */ jerry_source_info_t * -jerry_get_source_info (const jerry_value_t value) /**< jerry api value */ +jerry_source_info (const jerry_value_t value) /**< jerry api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_FUNCTION_TO_STRING if (!ecma_is_value_object (value)) @@ -5623,15 +5611,15 @@ jerry_get_source_info (const jerry_value_t value) /**< jerry api value */ JERRY_UNUSED (value); return NULL; #endif /* JERRY_FUNCTION_TO_STRING */ -} /* jerry_get_source_info */ +} /* jerry_source_info */ /** - * Frees the the source info structure returned by jerry_get_source_info. + * Frees the the source info structure returned by jerry_source_info. */ void -jerry_free_source_info (jerry_source_info_t *source_info_p) /**< source info block */ +jerry_source_info_free (jerry_source_info_t *source_info_p) /**< source info block */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_FUNCTION_TO_STRING if (source_info_p != NULL) @@ -5643,7 +5631,7 @@ jerry_free_source_info (jerry_source_info_t *source_info_p) /**< source info blo #else /* !JERRY_FUNCTION_TO_STRING */ JERRY_UNUSED (source_info_p); #endif /* JERRY_FUNCTION_TO_STRING */ -} /* jerry_free_source_info */ +} /* jerry_source_info_free */ /** * Replaces the currently active realm with another realm. @@ -5660,7 +5648,7 @@ jerry_free_source_info (jerry_source_info_t *source_info_p) /**< source info blo jerry_value_t jerry_set_realm (jerry_value_t realm_value) /**< jerry api value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_REALMS if (ecma_is_value_object (realm_value)) @@ -5675,10 +5663,10 @@ jerry_set_realm (jerry_value_t realm_value) /**< jerry api value */ } } - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Passed argument is not a realm"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Passed argument is not a realm")); #else /* !JERRY_BUILTIN_REALMS */ JERRY_UNUSED (realm_value); - return jerry_throw (ecma_raise_reference_error (ECMA_ERR_MSG ("Realm is not available"))); + return jerry_throw_sz (JERRY_ERROR_REFERENCE, ECMA_ERR_MSG ("Realm is not available")); #endif /* JERRY_BUILTIN_REALMS */ } /* jerry_set_realm */ @@ -5689,9 +5677,9 @@ jerry_set_realm (jerry_value_t realm_value) /**< jerry api value */ * this value - otherwise */ jerry_value_t -jerry_realm_get_this (jerry_value_t realm_value) /**< realm value */ +jerry_realm_this (jerry_value_t realm_value) /**< realm value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_REALMS if (ecma_is_value_object (realm_value)) @@ -5717,8 +5705,8 @@ jerry_realm_get_this (jerry_value_t realm_value) /**< realm value */ } #endif /* JERRY_BUILTIN_REALMS */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Passed argument is not a realm"))); -} /* jerry_realm_get_this */ + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Passed argument is not a realm")); +} /* jerry_realm_this */ /** * Sets the 'this' binding of a realm @@ -5733,12 +5721,12 @@ jerry_value_t jerry_realm_set_this (jerry_value_t realm_value, /**< realm value */ jerry_value_t this_value) /**< this value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_REALMS if (!ecma_is_value_object (this_value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Second argument must be an object"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Second argument must be an object")); } if (ecma_is_value_object (realm_value)) @@ -5761,11 +5749,11 @@ jerry_realm_set_this (jerry_value_t realm_value, /**< realm value */ } } - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("First argument is not a realm"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("First argument is not a realm")); #else /* !JERRY_BUILTIN_REALMS */ JERRY_UNUSED (realm_value); JERRY_UNUSED (this_value); - return jerry_throw (ecma_raise_reference_error (ECMA_ERR_MSG ("Realm is not available"))); + return jerry_throw_sz (JERRY_ERROR_REFERENCE, ECMA_ERR_MSG ("Realm is not available")); #endif /* JERRY_BUILTIN_REALMS */ } /* jerry_realm_set_this */ @@ -5778,7 +5766,7 @@ jerry_realm_set_this (jerry_value_t realm_value, /**< realm value */ bool jerry_value_is_arraybuffer (const jerry_value_t value) /**< value to check if it is an ArrayBuffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY return ecma_is_arraybuffer (value); @@ -5793,24 +5781,24 @@ jerry_value_is_arraybuffer (const jerry_value_t value) /**< value to check if it * * Notes: * * the length is specified in bytes. - * * returned value must be freed with jerry_release_value, when it is no longer needed. + * * returned value must be freed with jerry_value_free, when it is no longer needed. * * if the typed arrays are disabled this will return a TypeError. * * @return value of the constructed ArrayBuffer object */ jerry_value_t -jerry_create_arraybuffer (const jerry_length_t size) /**< size of the backing store allocated - * for the array buffer in bytes */ +jerry_arraybuffer (const jerry_length_t size) /**< size of the backing store allocated + * for the array buffer in bytes */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY return jerry_return (ecma_make_object_value (ecma_arraybuffer_new_object (size))); #else /* !JERRY_BUILTIN_TYPEDARRAY */ JERRY_UNUSED (size); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_create_arraybuffer */ +} /* jerry_arraybuffer */ /** * Creates an ArrayBuffer object with user specified buffer. @@ -5824,11 +5812,11 @@ jerry_create_arraybuffer (const jerry_length_t size) /**< size of the backing st * @return value of the newly constructed array buffer object */ jerry_value_t -jerry_create_arraybuffer_external (const jerry_length_t size, /**< size of the buffer in bytes */ - uint8_t *buffer_p, /**< the backing store used by the array buffer object */ - void *arraybuffer_user_p) /**< user pointer assigned to the array buffer object */ +jerry_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by the array buffer object */ + const jerry_length_t size, /**< size of the buffer in bytes */ + void *arraybuffer_user_p) /**< user pointer assigned to the array buffer object */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY ecma_object_t *arraybuffer_p; @@ -5856,9 +5844,9 @@ jerry_create_arraybuffer_external (const jerry_length_t size, /**< size of the b JERRY_UNUSED (size); JERRY_UNUSED (buffer_p); JERRY_UNUSED (arraybuffer_user_p); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_create_arraybuffer_external */ +} /* jerry_arraybuffer_external */ /** * Check if the given value is a SharedArrayBuffer object. @@ -5869,7 +5857,7 @@ jerry_create_arraybuffer_external (const jerry_length_t size, /**< size of the b bool jerry_value_is_shared_arraybuffer (const jerry_value_t value) /**< value to check if it is a SharedArrayBuffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); return ecma_is_shared_arraybuffer (value); } /* jerry_value_is_shared_arraybuffer */ @@ -5879,24 +5867,24 @@ jerry_value_is_shared_arraybuffer (const jerry_value_t value) /**< value to chec * * Notes: * * the length is specified in bytes. - * * returned value must be freed with jerry_release_value, when it is no longer needed. + * * returned value must be freed with jerry_value_free, when it is no longer needed. * * if the typed arrays are disabled this will return a TypeError. * * @return value of the constructed SharedArrayBuffer object */ jerry_value_t -jerry_create_shared_arraybuffer (const jerry_length_t size) /**< size of the backing store allocated - * for the shared array buffer in bytes */ +jerry_shared_arraybuffer (const jerry_length_t size) /**< size of the backing store allocated + * for the shared array buffer in bytes */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_SHAREDARRAYBUFFER return jerry_return (ecma_make_object_value (ecma_shared_arraybuffer_new_object (size))); #else /* !JERRY_BUILTIN_SHAREDARRAYBUFFER */ JERRY_UNUSED (size); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_shared_arraybuffer_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_shared_arraybuffer_not_supported_p)); #endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ -} /* jerry_create_shared_arraybuffer */ +} /* jerry_shared_arraybuffer */ /** * Creates a SharedArrayBuffer object with user specified buffer. @@ -5910,13 +5898,13 @@ jerry_create_shared_arraybuffer (const jerry_length_t size) /**< size of the bac * @return value of the newly constructed shared array buffer object */ jerry_value_t -jerry_create_shared_arraybuffer_external (const jerry_length_t size, /**< size of the buffer in bytes */ - uint8_t *buffer_p, /**< the backing store used by the +jerry_shared_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by the + * shared array buffer object */ + const jerry_length_t size, /**< size of the buffer in bytes */ + void *arraybuffer_user_p) /**< user pointer assigned to the * shared array buffer object */ - void *arraybuffer_user_p) /**< user pointer assigned to the - * shared array buffer object */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_SHAREDARRAYBUFFER ecma_object_t *shared_arraybuffer_p; @@ -5944,9 +5932,9 @@ jerry_create_shared_arraybuffer_external (const jerry_length_t size, /**< size o JERRY_UNUSED (size); JERRY_UNUSED (buffer_p); JERRY_UNUSED (arraybuffer_user_p); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_shared_arraybuffer_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_shared_arraybuffer_not_supported_p)); #endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */ -} /* jerry_create_shared_arraybuffer_external */ +} /* jerry_shared_arraybuffer_external */ #if JERRY_BUILTIN_TYPEDARRAY @@ -5985,7 +5973,7 @@ jerry_arraybuffer_write (const jerry_value_t value, /**< target ArrayBuffer or S const uint8_t *buf_p, /**< buffer to copy from */ jerry_length_t buf_size) /**< number of bytes to copy from the buffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (!(ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value))) @@ -6041,7 +6029,7 @@ jerry_arraybuffer_read (const jerry_value_t value, /**< ArrayBuffer or SharedArr uint8_t *buf_p, /**< destination buffer to copy to */ jerry_length_t buf_size) /**< number of bytes to copy into the buffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (!(ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value))) @@ -6092,9 +6080,9 @@ jerry_arraybuffer_read (const jerry_value_t value, /**< ArrayBuffer or SharedArr * @return the length of the ArrayBuffer in bytes. */ jerry_length_t -jerry_get_arraybuffer_byte_length (const jerry_value_t value) /**< ArrayBuffer or SharedArrayBuffer */ +jerry_arraybuffer_size (const jerry_value_t value) /**< ArrayBuffer or SharedArrayBuffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value)) @@ -6106,7 +6094,7 @@ jerry_get_arraybuffer_byte_length (const jerry_value_t value) /**< ArrayBuffer o JERRY_UNUSED (value); #endif /* JERRY_BUILTIN_TYPEDARRAY */ return 0; -} /* jerry_get_arraybuffer_byte_length */ +} /* jerry_arraybuffer_size */ /** * Get a pointer for the start of the ArrayBuffer. @@ -6121,9 +6109,9 @@ jerry_get_arraybuffer_byte_length (const jerry_value_t value) /**< ArrayBuffer o * - an external ArrayBuffer has been detached */ uint8_t * -jerry_get_arraybuffer_pointer (const jerry_value_t array_buffer) /**< Array Buffer to use */ +jerry_arraybuffer_data (const jerry_value_t array_buffer) /**< Array Buffer to use */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (!(ecma_is_arraybuffer (array_buffer) || ecma_is_shared_arraybuffer (array_buffer))) @@ -6145,7 +6133,7 @@ jerry_get_arraybuffer_pointer (const jerry_value_t array_buffer) /**< Array Buff #endif /* JERRY_BUILTIN_TYPEDARRAY */ return NULL; -} /* jerry_get_arraybuffer_pointer */ +} /* jerry_arraybuffer_data */ /** * Get if the ArrayBuffer is detachable. @@ -6154,9 +6142,9 @@ jerry_get_arraybuffer_pointer (const jerry_value_t array_buffer) /**< Array Buff * value marked with error flag - otherwise */ jerry_value_t -jerry_is_arraybuffer_detachable (const jerry_value_t value) /**< ArrayBuffer */ +jerry_arraybuffer_is_detachable (const jerry_value_t value) /**< ArrayBuffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (ecma_is_arraybuffer (value)) @@ -6167,8 +6155,8 @@ jerry_is_arraybuffer_detachable (const jerry_value_t value) /**< ArrayBuffer */ #else /* !JERRY_BUILTIN_TYPEDARRAY */ JERRY_UNUSED (value); #endif /* JERRY_BUILTIN_TYPEDARRAY */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Expected an ArrayBuffer"))); -} /* jerry_is_arraybuffer_detachable */ + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Expected an ArrayBuffer")); +} /* jerry_arraybuffer_is_detachable */ /** * Detach the underlying data block from ArrayBuffer and set its bytelength to 0. @@ -6180,9 +6168,9 @@ jerry_is_arraybuffer_detachable (const jerry_value_t value) /**< ArrayBuffer */ * value marked with error flag - otherwise */ jerry_value_t -jerry_detach_arraybuffer (const jerry_value_t value) /**< ArrayBuffer */ +jerry_arraybuffer_detach (const jerry_value_t value) /**< ArrayBuffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (ecma_is_arraybuffer (value)) @@ -6192,13 +6180,13 @@ jerry_detach_arraybuffer (const jerry_value_t value) /**< ArrayBuffer */ { return ECMA_VALUE_NULL; } - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has already been detached"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("ArrayBuffer has already been detached")); } #else /* !JERRY_BUILTIN_TYPEDARRAY */ JERRY_UNUSED (value); #endif /* JERRY_BUILTIN_TYPEDARRAY */ - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Expected an ArrayBuffer"))); -} /* jerry_detach_arraybuffer */ + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Expected an ArrayBuffer")); +} /* jerry_arraybuffer_detach */ /** * Checks whether a buffer is currently allocated for an array buffer or typed array. @@ -6209,7 +6197,7 @@ jerry_detach_arraybuffer (const jerry_value_t value) /**< ArrayBuffer */ bool jerry_arraybuffer_has_buffer (const jerry_value_t value) /**< array buffer or typed array value */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (!ecma_is_value_object (value)) @@ -6242,29 +6230,29 @@ jerry_arraybuffer_has_buffer (const jerry_value_t value) /**< array buffer or ty * are not called for these array buffers. The default limit is 256 bytes. */ void -jerry_arraybuffer_set_compact_allocation_limit (const jerry_length_t allocation_limit) /**< maximum size of - * compact allocation */ +jerry_arraybuffer_heap_allocation_limit (const jerry_length_t allocation_limit) /**< maximum size of + * compact allocation */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY JERRY_CONTEXT (arraybuffer_compact_allocation_limit) = allocation_limit; #else /* !JERRY_BUILTIN_TYPEDARRAY */ JERRY_UNUSED (allocation_limit); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_arraybuffer_set_compact_allocation_limit */ +} /* jerry_arraybuffer_heap_allocation_limit */ /** * Set callbacks for allocating and freeing backing stores for array buffer objects. */ void -jerry_arraybuffer_set_allocator_callbacks (jerry_arraybuffer_allocate_t allocate_callback, /**< callback for allocating - * array buffer memory */ - jerry_arraybuffer_free_t free_callback, /**< callback for freeing +jerry_arraybuffer_allocator_cb (jerry_arraybuffer_allocate_cb_t allocate_callback, /**< callback for allocating * array buffer memory */ - void *user_p) /**< user pointer passed to the callbacks */ + jerry_arraybuffer_free_cb_t free_callback, /**< callback for freeing + * array buffer memory */ + void *user_p) /**< user pointer passed to the callbacks */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY JERRY_CONTEXT (arraybuffer_allocate_callback) = allocate_callback; @@ -6275,7 +6263,7 @@ jerry_arraybuffer_set_allocator_callbacks (jerry_arraybuffer_allocate_t allocate JERRY_UNUSED (free_callback); JERRY_UNUSED (user_p); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_arraybuffer_set_allocator_callbacks */ +} /* jerry_arraybuffer_allocator_cb */ /** * DataView related functions @@ -6285,23 +6273,23 @@ jerry_arraybuffer_set_allocator_callbacks (jerry_arraybuffer_allocate_t allocate * Creates a DataView object with the given ArrayBuffer, ByteOffset and ByteLength arguments. * * Notes: - * * returned value must be freed with jerry_release_value, when it is no longer needed. + * * returned value must be freed with jerry_value_free, when it is no longer needed. * * if the DataView bulitin is disabled this will return a TypeError. * * @return value of the constructed DataView object - if success * created error - otherwise */ jerry_value_t -jerry_create_dataview (const jerry_value_t array_buffer, /**< arraybuffer to create DataView from */ - const jerry_length_t byte_offset, /**< offset in bytes, to the first byte in the buffer */ - const jerry_length_t byte_length) /**< number of elements in the byte array */ +jerry_dataview (const jerry_value_t array_buffer, /**< arraybuffer to create DataView from */ + const jerry_length_t byte_offset, /**< offset in bytes, to the first byte in the buffer */ + const jerry_length_t byte_length) /**< number of elements in the byte array */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_DATAVIEW - if (ecma_is_value_error_reference (array_buffer)) + if (ecma_is_value_exception (array_buffer)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } ecma_value_t arguments_p[3] = { array_buffer, @@ -6320,9 +6308,9 @@ jerry_create_dataview (const jerry_value_t array_buffer, /**< arraybuffer to cre JERRY_UNUSED (array_buffer); JERRY_UNUSED (byte_offset); JERRY_UNUSED (byte_length); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_data_view_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_data_view_not_supported_p)); #endif /* JERRY_BUILTIN_DATAVIEW */ -} /* jerry_create_dataview */ +} /* jerry_dataview */ /** * Check if the given value is a DataView object. @@ -6333,7 +6321,7 @@ jerry_create_dataview (const jerry_value_t array_buffer, /**< arraybuffer to cre bool jerry_value_is_dataview (const jerry_value_t value) /**< value to check if it is a DataView object */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_DATAVIEW return ecma_is_dataview (value); @@ -6350,29 +6338,29 @@ jerry_value_is_dataview (const jerry_value_t value) /**< value to check if it is * which were specified when the DataView was created. * * Note: - * the returned value must be freed with a jerry_release_value call + * the returned value must be freed with a jerry_value_free call * * @return ArrayBuffer of a DataView * TypeError if the object is not a DataView. */ jerry_value_t -jerry_get_dataview_buffer (const jerry_value_t value, /**< DataView to get the arraybuffer from */ - jerry_length_t *byte_offset, /**< [out] byteOffset property */ - jerry_length_t *byte_length) /**< [out] byteLength property */ +jerry_dataview_buffer (const jerry_value_t value, /**< DataView to get the arraybuffer from */ + jerry_length_t *byte_offset, /**< [out] byteOffset property */ + jerry_length_t *byte_length) /**< [out] byteLength property */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_DATAVIEW - if (ecma_is_value_error_reference (value)) + if (ecma_is_value_exception (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } ecma_dataview_object_t *dataview_p = ecma_op_dataview_get_object (value); if (JERRY_UNLIKELY (dataview_p == NULL)) { - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } if (byte_offset != NULL) @@ -6393,9 +6381,9 @@ jerry_get_dataview_buffer (const jerry_value_t value, /**< DataView to get the a JERRY_UNUSED (value); JERRY_UNUSED (byte_offset); JERRY_UNUSED (byte_length); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_data_view_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_data_view_not_supported_p)); #endif /* JERRY_BUILTIN_DATAVIEW */ -} /* jerry_get_dataview_buffer */ +} /* jerry_dataview_buffer */ /** * TypedArray related functions @@ -6410,7 +6398,7 @@ jerry_get_dataview_buffer (const jerry_value_t value, /**< DataView to get the a bool jerry_value_is_typedarray (jerry_value_t value) /**< value to check if it is a TypedArray */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY return ecma_is_typedarray (value); @@ -6498,10 +6486,10 @@ jerry_typedarray_find_by_type (jerry_typedarray_type_t type_name, /**< type of t * @return - new TypedArray object */ jerry_value_t -jerry_create_typedarray (jerry_typedarray_type_t type_name, /**< type of TypedArray to create */ - jerry_length_t length) /**< element count of the new TypedArray */ +jerry_typedarray (jerry_typedarray_type_t type_name, /**< type of TypedArray to create */ + jerry_length_t length) /**< element count of the new TypedArray */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY ecma_builtin_id_t prototype_id = 0; @@ -6510,7 +6498,7 @@ jerry_create_typedarray (jerry_typedarray_type_t type_name, /**< type of TypedAr if (!jerry_typedarray_find_by_type (type_name, &prototype_id, &id, &element_size_shift)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Incorrect type for TypedArray"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Incorrect type for TypedArray")); } ecma_object_t *prototype_obj_p = ecma_builtin_get (prototype_id); @@ -6524,9 +6512,9 @@ jerry_create_typedarray (jerry_typedarray_type_t type_name, /**< type of TypedAr #else /* !JERRY_BUILTIN_TYPEDARRAY */ JERRY_UNUSED (type_name); JERRY_UNUSED (length); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_create_typedarray */ +} /* jerry_typedarray */ /** * Create a TypedArray object using the given arraybuffer and size information. @@ -6538,31 +6526,31 @@ jerry_create_typedarray (jerry_typedarray_type_t type_name, /**< type of TypedAr * @return - new TypedArray object */ jerry_value_t -jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, /**< type of TypedArray to create */ - const jerry_value_t arraybuffer, /**< ArrayBuffer to use */ - jerry_length_t byte_offset, /**< offset for the ArrayBuffer */ - jerry_length_t length) /**< number of elements to use from ArrayBuffer */ +jerry_typedarray_with_buffer_span (jerry_typedarray_type_t type, /**< type of TypedArray to create */ + const jerry_value_t arraybuffer, /**< ArrayBuffer to use */ + jerry_length_t byte_offset, /**< offset for the ArrayBuffer */ + jerry_length_t length) /**< number of elements to use from ArrayBuffer */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY - if (ecma_is_value_error_reference (arraybuffer)) + if (ecma_is_value_exception (arraybuffer)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } ecma_builtin_id_t prototype_id = 0; ecma_typedarray_type_t id = 0; uint8_t element_size_shift = 0; - if (!jerry_typedarray_find_by_type (type_name, &prototype_id, &id, &element_size_shift)) + if (!jerry_typedarray_find_by_type (type, &prototype_id, &id, &element_size_shift)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Incorrect type for TypedArray"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Incorrect type for TypedArray")); } if (!ecma_is_arraybuffer (arraybuffer)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an ArrayBuffer"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Argument is not an ArrayBuffer")); } ecma_object_t *prototype_obj_p = ecma_builtin_get (prototype_id); @@ -6574,13 +6562,13 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, / return jerry_return (array_value); #else /* !JERRY_BUILTIN_TYPEDARRAY */ - JERRY_UNUSED (type_name); + JERRY_UNUSED (type); JERRY_UNUSED (arraybuffer); JERRY_UNUSED (byte_offset); JERRY_UNUSED (length); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_create_typedarray_for_arraybuffer_sz */ +} /* jerry_typedarray_with_buffer_span */ /** * Create a TypedArray object using the given arraybuffer and size information. @@ -6592,25 +6580,25 @@ jerry_create_typedarray_for_arraybuffer_sz (jerry_typedarray_type_t type_name, / * @return - new TypedArray object */ jerry_value_t -jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name, /**< type of TypedArray to create */ - const jerry_value_t arraybuffer) /**< ArrayBuffer to use */ +jerry_typedarray_with_buffer (jerry_typedarray_type_t type, /**< type of TypedArray to create */ + const jerry_value_t arraybuffer) /**< ArrayBuffer to use */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY - if (ecma_is_value_error_reference (arraybuffer)) + if (ecma_is_value_exception (arraybuffer)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } - jerry_length_t byteLength = jerry_get_arraybuffer_byte_length (arraybuffer); - return jerry_create_typedarray_for_arraybuffer_sz (type_name, arraybuffer, 0, byteLength); + jerry_length_t byteLength = jerry_arraybuffer_size (arraybuffer); + return jerry_typedarray_with_buffer_span (type, arraybuffer, 0, byteLength); #else /* !JERRY_BUILTIN_TYPEDARRAY */ - JERRY_UNUSED (type_name); + JERRY_UNUSED (type); JERRY_UNUSED (arraybuffer); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_create_typedarray_for_arraybuffer */ +} /* jerry_typedarray_with_buffer */ /** * Get the type of the TypedArray. @@ -6619,9 +6607,9 @@ jerry_create_typedarray_for_arraybuffer (jerry_typedarray_type_t type_name, /**< * - JERRY_TYPEDARRAY_INVALID if the argument is not a TypedArray */ jerry_typedarray_type_t -jerry_get_typedarray_type (jerry_value_t value) /**< object to get the TypedArray type */ +jerry_typedarray_type (jerry_value_t value) /**< object to get the TypedArray type */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (!ecma_is_typedarray (value)) @@ -6644,7 +6632,7 @@ jerry_get_typedarray_type (jerry_value_t value) /**< object to get the TypedArra #endif /* JERRY_BUILTIN_TYPEDARRAY */ return JERRY_TYPEDARRAY_INVALID; -} /* jerry_get_typedarray_type */ +} /* jerry_typedarray_type */ /** * Get the element count of the TypedArray. @@ -6652,9 +6640,9 @@ jerry_get_typedarray_type (jerry_value_t value) /**< object to get the TypedArra * @return length of the TypedArray. */ jerry_length_t -jerry_get_typedarray_length (jerry_value_t value) /**< TypedArray to query */ +jerry_typedarray_length (jerry_value_t value) /**< TypedArray to query */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (ecma_is_typedarray (value)) @@ -6667,7 +6655,7 @@ jerry_get_typedarray_length (jerry_value_t value) /**< TypedArray to query */ #endif /* JERRY_BUILTIN_TYPEDARRAY */ return 0; -} /* jerry_get_typedarray_length */ +} /* jerry_typedarray_length */ /** * Get the underlying ArrayBuffer from a TypedArray. @@ -6676,22 +6664,22 @@ jerry_get_typedarray_length (jerry_value_t value) /**< TypedArray to query */ * which were specified when the TypedArray was created. * * Note: - * the returned value must be freed with a jerry_release_value call + * the returned value must be freed with a jerry_value_free call * * @return ArrayBuffer of a TypedArray * TypeError if the object is not a TypedArray. */ jerry_value_t -jerry_get_typedarray_buffer (jerry_value_t value, /**< TypedArray to get the arraybuffer from */ - jerry_length_t *byte_offset, /**< [out] byteOffset property */ - jerry_length_t *byte_length) /**< [out] byteLength property */ +jerry_typedarray_buffer (jerry_value_t value, /**< TypedArray to get the arraybuffer from */ + jerry_length_t *byte_offset, /**< [out] byteOffset property */ + jerry_length_t *byte_length) /**< [out] byteLength property */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_TYPEDARRAY if (!ecma_is_typedarray (value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Object is not a TypedArray"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Object is not a TypedArray")); } ecma_object_t *array_p = ecma_get_object_from_value (value); @@ -6714,33 +6702,30 @@ jerry_get_typedarray_buffer (jerry_value_t value, /**< TypedArray to get the arr JERRY_UNUSED (value); JERRY_UNUSED (byte_length); JERRY_UNUSED (byte_offset); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)); #endif /* JERRY_BUILTIN_TYPEDARRAY */ -} /* jerry_get_typedarray_buffer */ +} /* jerry_typedarray_buffer */ /** - * Parse the given JSON string to create a jerry_value_t. + * Parse the given input buffer as a JSON string. The behaviour is equivalent with the "JSON.parse(string)" JS + * call. The input buffer can be encoded as either cesu-8 or utf-8, but it is the callers responsibility to make sure + * the encoding is valid. * - * The behaviour is equivalent with the "JSON.parse(string)" JS call. - * - * Note: - * The returned value must be freed with jerry_release_value. * - * @return - jerry_value_t containing a JavaScript value. - * - Error value if there was problems during the parse. + * @return object value, or exception */ jerry_value_t jerry_json_parse (const jerry_char_t *string_p, /**< json string */ jerry_size_t string_size) /**< json string size */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_JSON ecma_value_t ret_value = ecma_builtin_json_parse_buffer (string_p, string_size); if (ecma_is_value_undefined (ret_value)) { - ret_value = jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG ("JSON string parse error"))); + ret_value = jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG ("JSON string parse error")); } return jerry_return (ret_value); @@ -6748,7 +6733,7 @@ jerry_json_parse (const jerry_char_t *string_p, /**< json string */ JERRY_UNUSED (string_p); JERRY_UNUSED (string_size); - return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (ecma_error_json_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG (ecma_error_json_not_supported_p)); #endif /* JERRY_BUILTIN_JSON */ } /* jerry_json_parse */ @@ -6758,7 +6743,7 @@ jerry_json_parse (const jerry_char_t *string_p, /**< json string */ * The behaviour is equivalent with the "JSON.stringify(input_value)" JS call. * * Note: - * The returned value must be freed with jerry_release_value, + * The returned value must be freed with jerry_value_free, * * @return - jerry_value_t containing a JSON string. * - Error value if there was a problem during the stringification. @@ -6766,25 +6751,25 @@ jerry_json_parse (const jerry_char_t *string_p, /**< json string */ jerry_value_t jerry_json_stringify (const jerry_value_t input_value) /**< a value to stringify */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_JSON - if (ecma_is_value_error_reference (input_value)) + if (ecma_is_value_exception (input_value)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } ecma_value_t ret_value = ecma_builtin_json_stringify_no_opts (input_value); if (ecma_is_value_undefined (ret_value)) { - ret_value = jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG ("JSON stringify error"))); + ret_value = jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG ("JSON stringify error")); } return jerry_return (ret_value); #else /* JERRY_BUILTIN_JSON */ JERRY_UNUSED (input_value); - return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (ecma_error_json_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, ECMA_ERR_MSG (ecma_error_json_not_supported_p)); #endif /* JERRY_BUILTIN_JSON */ } /* jerry_json_stringify */ @@ -6794,22 +6779,22 @@ jerry_json_stringify (const jerry_value_t input_value) /**< a value to stringify * inserted to the container. * * Note: - * The returned value must be freed with jerry_release_value + * The returned value must be freed with jerry_value_free * @return jerry_value_t representing a container with the given type. */ jerry_value_t -jerry_create_container (jerry_container_type_t container_type, /**< Type of the container */ - const jerry_value_t *arguments_list_p, /**< arguments list */ - jerry_length_t arguments_list_len) /**< Length of arguments list */ +jerry_container (jerry_container_type_t container_type, /**< Type of the container */ + const jerry_value_t *arguments_list_p, /**< arguments list */ + jerry_length_t arguments_list_len) /**< Length of arguments list */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_CONTAINER for (jerry_length_t i = 0; i < arguments_list_len; i++) { - if (ecma_is_value_error_reference (arguments_list_p[i])) + if (ecma_is_value_exception (arguments_list_p[i])) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_value_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_value_msg_p)); } } @@ -6849,7 +6834,7 @@ jerry_create_container (jerry_container_type_t container_type, /**< Type of the } default: { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Invalid container type"))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Invalid container type")); } } ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target_p); @@ -6867,9 +6852,9 @@ jerry_create_container (jerry_container_type_t container_type, /**< Type of the JERRY_UNUSED (arguments_list_p); JERRY_UNUSED (arguments_list_len); JERRY_UNUSED (container_type); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_container_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_container_not_supported_p)); #endif /* JERRY_BUILTIN_CONTAINER */ -} /* jerry_create_container */ +} /* jerry_container */ /** * Get the type of the given container object. @@ -6877,9 +6862,9 @@ jerry_create_container (jerry_container_type_t container_type, /**< Type of the * @return Corresponding type to the given container object. */ jerry_container_type_t -jerry_get_container_type (const jerry_value_t value) /**< the container object */ +jerry_container_type (const jerry_value_t value) /**< the container object */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_CONTAINER if (ecma_is_value_object (value)) @@ -6918,36 +6903,36 @@ jerry_get_container_type (const jerry_value_t value) /**< the container object * JERRY_UNUSED (value); #endif /* JERRY_BUILTIN_CONTAINER */ return JERRY_CONTAINER_TYPE_INVALID; -} /* jerry_get_container_type */ +} /* jerry_container_type */ /** * Return a new array containing elements from a Container or a Container Iterator. * Sets the boolean input value to `true` if the container object has key/value pairs. * * Note: - * the returned value must be freed with a jerry_release_value call + * the returned value must be freed with a jerry_value_free call * * @return an array of items for maps/sets or their iterators, error otherwise */ jerry_value_t -jerry_get_array_from_container (jerry_value_t value, /**< the container or iterator object */ - bool *is_key_value_p) /**< [out] is key-value structure */ +jerry_container_to_array (jerry_value_t value, /**< the container or iterator object */ + bool *is_key_value_p) /**< [out] is key-value structure */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_CONTAINER const char *container_needed = ECMA_ERR_MSG ("Value is not a Container or Iterator"); if (!ecma_is_value_object (value)) { - return jerry_throw (ecma_raise_type_error (container_needed)); + return jerry_throw_sz (JERRY_ERROR_TYPE, container_needed); } ecma_object_t *obj_p = ecma_get_object_from_value (value); if (ecma_get_object_type (obj_p) != ECMA_OBJECT_TYPE_CLASS) { - return jerry_throw (ecma_raise_type_error (container_needed)); + return jerry_throw_sz (JERRY_ERROR_TYPE, container_needed); } ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; @@ -6982,7 +6967,7 @@ jerry_get_array_from_container (jerry_value_t value, /**< the container or itera iterator_kind = ext_obj_p->u.cls.u1.iterator_kind; } - else if (jerry_get_container_type (value) != JERRY_CONTAINER_TYPE_INVALID) + else if (jerry_container_type (value) != JERRY_CONTAINER_TYPE_INVALID) { ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.u3.value); entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p); @@ -7000,7 +6985,7 @@ jerry_get_array_from_container (jerry_value_t value, /**< the container or itera } else { - return jerry_throw (ecma_raise_type_error (container_needed)); + return jerry_throw_sz (JERRY_ERROR_TYPE, container_needed); } *is_key_value_p = (iterator_kind == ECMA_ITERATOR_ENTRIES); @@ -7029,9 +7014,9 @@ jerry_get_array_from_container (jerry_value_t value, /**< the container or itera #else /* !JERRY_BUILTIN_CONTAINER */ JERRY_UNUSED (value); JERRY_UNUSED (is_key_value_p); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_container_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_container_not_supported_p)); #endif /* JERRY_BUILTIN_CONTAINER */ -} /* jerry_get_array_from_container */ +} /* jerry_container_to_array */ /** * Perform container operation on the given operands (add, get, set, has, delete, size, clear). @@ -7040,30 +7025,30 @@ jerry_get_array_from_container (jerry_value_t value, /**< the container or itera * result of the container operation - otherwise. */ jerry_value_t -jerry_container_operation (jerry_container_operation_t operation, /**< container operation */ - jerry_value_t container, /**< container */ - jerry_value_t *arguments, /**< list of arguments */ - uint32_t arguments_number) /**< number of arguments */ +jerry_container_op (jerry_container_op_t operation, /**< container operation */ + jerry_value_t container, /**< container */ + const jerry_value_t *arguments, /**< list of arguments */ + uint32_t arguments_number) /**< number of arguments */ { - jerry_assert_api_available (); + jerry_assert_api_enabled (); #if JERRY_BUILTIN_CONTAINER if (!ecma_is_value_object (container)) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Container is not an object."))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Container is not an object.")); } ecma_object_t *obj_p = ecma_get_object_from_value (container); if (ecma_get_object_type (obj_p) != ECMA_OBJECT_TYPE_CLASS) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Container is not a container object."))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Container is not a container object.")); } uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id; ecma_extended_object_t *container_object_p = ecma_op_container_get_object (container, type); if (container_object_p == NULL) { - return ecma_create_error_reference_from_context (); + return ecma_create_exception_from_context (); } switch (operation) @@ -7073,18 +7058,17 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container case JERRY_CONTAINER_OP_GET: case JERRY_CONTAINER_OP_HAS: { - if (arguments_number != 1 || ecma_is_value_error_reference (arguments[0])) + if (arguments_number != 1 || ecma_is_value_exception (arguments[0])) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } break; } case JERRY_CONTAINER_OP_SET: { - if (arguments_number != 2 || ecma_is_value_error_reference (arguments[0]) - || ecma_is_value_error_reference (arguments[1])) + if (arguments_number != 2 || ecma_is_value_exception (arguments[0]) || ecma_is_value_exception (arguments[1])) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } break; } @@ -7093,13 +7077,13 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container { if (arguments_number != 0) { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } break; } default: { - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)); } } @@ -7112,7 +7096,7 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container { if (type == LIT_MAGIC_STRING_MAP_UL || type == LIT_MAGIC_STRING_WEAKMAP_UL) { - return jerry_throw (ecma_raise_type_error (incorrect_type_call)); + return jerry_throw_sz (JERRY_ERROR_TYPE, incorrect_type_call); } result = ecma_op_container_set (container_object_p, arguments[0], arguments[0], type); break; @@ -7121,7 +7105,7 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container { if (type == LIT_MAGIC_STRING_SET_UL || type == LIT_MAGIC_STRING_WEAKSET_UL) { - return jerry_throw (ecma_raise_type_error (incorrect_type_call)); + return jerry_throw_sz (JERRY_ERROR_TYPE, incorrect_type_call); } result = ecma_op_container_get (container_object_p, arguments[0], type); break; @@ -7130,7 +7114,7 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container { if (type == LIT_MAGIC_STRING_SET_UL || type == LIT_MAGIC_STRING_WEAKSET_UL) { - return jerry_throw (ecma_raise_type_error (incorrect_type_call)); + return jerry_throw_sz (JERRY_ERROR_TYPE, incorrect_type_call); } result = ecma_op_container_set (container_object_p, arguments[0], arguments[1], type); break; @@ -7159,14 +7143,14 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container { if (type == LIT_MAGIC_STRING_WEAKSET_UL || type == LIT_MAGIC_STRING_WEAKMAP_UL) { - return jerry_throw (ecma_raise_type_error (incorrect_type_call)); + return jerry_throw_sz (JERRY_ERROR_TYPE, incorrect_type_call); } result = ecma_op_container_clear (container_object_p); break; } default: { - result = jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Unsupported container operation"))); + result = jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG ("Unsupported container operation")); break; } } @@ -7176,9 +7160,9 @@ jerry_container_operation (jerry_container_operation_t operation, /**< container JERRY_UNUSED (container); JERRY_UNUSED (arguments); JERRY_UNUSED (arguments_number); - return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_container_not_supported_p))); + return jerry_throw_sz (JERRY_ERROR_TYPE, ECMA_ERR_MSG (ecma_error_container_not_supported_p)); #endif /* JERRY_BUILTIN_CONTAINER */ -} /* jerry_container_operation */ +} /* jerry_container_op */ /** * @} diff --git a/jerry-core/ecma/base/ecma-gc.c b/jerry-core/ecma/base/ecma-gc.c index 83dc808bae..58dcc94895 100644 --- a/jerry-core/ecma/base/ecma-gc.c +++ b/jerry-core/ecma/base/ecma-gc.c @@ -1275,7 +1275,7 @@ ecma_gc_free_native_pointer (ecma_property_t property, /**< property descriptor if (native_pointer_p->native_info_p != NULL) { - jerry_object_native_free_callback_t free_cb = native_pointer_p->native_info_p->free_cb; + jerry_object_native_free_cb_t free_cb = native_pointer_p->native_info_p->free_cb; if (free_cb != NULL) { @@ -1299,7 +1299,7 @@ ecma_gc_free_native_pointer (ecma_property_t property, /**< property descriptor { if (item_p->data.native_info_p != NULL) { - jerry_object_native_free_callback_t free_cb = item_p->data.native_info_p->free_cb; + jerry_object_native_free_cb_t free_cb = item_p->data.native_info_p->free_cb; if (free_cb != NULL) { diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h index b7a38de576..e802e7daab 100644 --- a/jerry-core/ecma/base/ecma-globals.h +++ b/jerry-core/ecma/base/ecma-globals.h @@ -56,7 +56,7 @@ */ typedef enum { - ECMA_STATUS_API_AVAILABLE = (1u << 0), /**< api available */ + ECMA_STATUS_API_ENABLED = (1u << 0), /**< api available */ ECMA_STATUS_DIRECT_EVAL = (1u << 1), /**< eval is called directly */ #if JERRY_PROPERTY_HASHMAP ECMA_STATUS_HIGH_PRESSURE_GC = (1u << 2), /**< last gc was under high pressure */ @@ -1928,14 +1928,14 @@ typedef struct #endif /* !defined (JERRY_BUILTIN_BIGINT) */ /** - * Abort flag for errors in C API. + * Flags for exception values. */ -#define ECMA_ERROR_API_ABORT (1u << 0) - -/** - * Throw captured flag for errors in C API. - */ -#define ECMA_ERROR_API_THROW_CAPTURED (1u << 1) +typedef enum +{ + ECMA_ERROR_API_FLAG_NONE = 0, + ECMA_ERROR_API_FLAG_ABORT = (1u << 0), /**< abort flag */ + ECMA_ERROR_API_FLAG_THROW_CAPTURED = (1u << 1), /**< throw captured flag */ +} ecma_error_api_flags_t; /** * Representation of a thrown value on API level. diff --git a/jerry-core/ecma/base/ecma-helpers-string.c b/jerry-core/ecma/base/ecma-helpers-string.c index a4d6749b46..e86ae852f9 100644 --- a/jerry-core/ecma/base/ecma-helpers-string.c +++ b/jerry-core/ecma/base/ecma-helpers-string.c @@ -488,7 +488,7 @@ ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, /**< /* Normal strings are created for short strings. */ ecma_string_t *string_desc_p = ecma_new_ecma_string_from_utf8 (string_p, string_size); - jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); + jerry_external_string_free_cb_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); if (free_cb != NULL) { @@ -501,7 +501,7 @@ ecma_new_ecma_external_string_from_cesu8 (const lit_utf8_byte_t *string_p, /**< if (string_desc_p != NULL) { - jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); + jerry_external_string_free_cb_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); if (free_cb != NULL) { @@ -974,7 +974,7 @@ ecma_destroy_ecma_string (ecma_string_t *string_p) /**< ecma-string */ } ecma_external_string_t *external_string_p = (ecma_external_string_t *) string_p; - jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); + jerry_external_string_free_cb_t free_cb = JERRY_CONTEXT (external_string_free_callback_p); if (free_cb != NULL) { @@ -1078,81 +1078,44 @@ ecma_string_get_array_index (const ecma_string_t *str_p) /**< ecma-string */ } /* ecma_string_get_array_index */ /** - * Convert ecma-string's contents to a cesu-8 string and put it to the buffer. - * It is the caller's responsibility to make sure that the string fits in the buffer. + * Copy digits of uint32 number, truncating if buffer is not large enough. * - * @return number of bytes, actually copied to the buffer. + * @return number of digits copied */ -lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT -ecma_string_copy_to_cesu8_buffer (const ecma_string_t *string_p, /**< ecma-string descriptor */ - lit_utf8_byte_t *buffer_p, /**< destination buffer pointer - * (can be NULL if buffer_size == 0) */ - lit_utf8_size_t buffer_size) /**< size of buffer */ +static lit_utf8_size_t +ecma_uint32_to_buffer (uint32_t num, /**< number */ + lit_utf8_byte_t *buffer_p /**< destination buffer */, + lit_utf8_size_t buffer_size /**< buffer size */) { - JERRY_ASSERT (string_p != NULL); - JERRY_ASSERT (buffer_p != NULL || buffer_size == 0); - JERRY_ASSERT (ecma_string_get_size (string_p) <= buffer_size); + lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + lit_utf8_size_t digit_count = ecma_uint32_to_utf8_string (num, digits, ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); - lit_utf8_size_t size; - - if (ECMA_IS_DIRECT_STRING (string_p)) - { - if (ECMA_IS_DIRECT_STRING_WITH_TYPE (string_p, ECMA_DIRECT_STRING_UINT)) - { - uint32_t uint32_number = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); - size = ecma_uint32_to_utf8_string (uint32_number, buffer_p, buffer_size); - JERRY_ASSERT (size <= buffer_size); - return size; - } - } - else - { - JERRY_ASSERT (string_p->refs_and_container >= ECMA_STRING_REF_ONE); - - if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) - { - uint32_t uint32_number = string_p->u.uint32_number; - size = ecma_uint32_to_utf8_string (uint32_number, buffer_p, buffer_size); - JERRY_ASSERT (size <= buffer_size); - return size; - } - } - - const lit_utf8_byte_t *chars_p = ecma_string_get_chars_fast (string_p, &size); - - JERRY_ASSERT (chars_p != NULL); - JERRY_ASSERT (size <= buffer_size); - - memcpy (buffer_p, chars_p, size); - return size; -} /* ecma_string_copy_to_cesu8_buffer */ + digit_count = JERRY_MIN (buffer_size, digit_count); + memcpy (buffer_p, digits, digit_count); + return digit_count; +} /* ecma_uint32_to_buffer */ /** - * Convert ecma-string's contents to an utf-8 string and put it to the buffer. - * It is the caller's responsibility to make sure that the string fits in the buffer. + * Convert ecma-string's contents to the specified encoding and copy it to the buffer. + * String data will be truncated to fit the buffer. * - * @return number of bytes, actually copied to the buffer. + * @return number of bytes copied to the buffer. */ lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT -ecma_string_copy_to_utf8_buffer (const ecma_string_t *string_p, /**< ecma-string descriptor */ - lit_utf8_byte_t *buffer_p, /**< destination buffer pointer - * (can be NULL if buffer_size == 0) */ - lit_utf8_size_t buffer_size) /**< size of buffer */ +ecma_string_copy_to_buffer (const ecma_string_t *string_p, /**< ecma-string descriptor */ + lit_utf8_byte_t *buffer_p, /**< destination buffer pointer + * (can be NULL if buffer_size == 0) */ + lit_utf8_size_t buffer_size, /**< size of buffer */ + jerry_encoding_t encoding) /**< encoding */ { JERRY_ASSERT (string_p != NULL); JERRY_ASSERT (buffer_p != NULL || buffer_size == 0); - JERRY_ASSERT (ecma_string_get_utf8_size (string_p) <= buffer_size); - - lit_utf8_size_t size; if (ECMA_IS_DIRECT_STRING (string_p)) { if (ECMA_IS_DIRECT_STRING_WITH_TYPE (string_p, ECMA_DIRECT_STRING_UINT)) { - uint32_t uint32_number = (uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p); - size = ecma_uint32_to_utf8_string (uint32_number, buffer_p, buffer_size); - JERRY_ASSERT (size <= buffer_size); - return size; + return ecma_uint32_to_buffer ((uint32_t) ECMA_GET_DIRECT_STRING_VALUE (string_p), buffer_p, buffer_size); } } else @@ -1161,245 +1124,55 @@ ecma_string_copy_to_utf8_buffer (const ecma_string_t *string_p, /**< ecma-string if (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC) { - uint32_t uint32_number = string_p->u.uint32_number; - size = ecma_uint32_to_utf8_string (uint32_number, buffer_p, buffer_size); - JERRY_ASSERT (size <= buffer_size); - return size; + return ecma_uint32_to_buffer (string_p->u.uint32_number, buffer_p, buffer_size); } } - uint8_t flags = ECMA_STRING_FLAG_IS_ASCII; - const lit_utf8_byte_t *chars_p = ecma_string_get_chars (string_p, &size, NULL, NULL, &flags); + lit_utf8_size_t string_size; + const lit_utf8_byte_t *chars_p = ecma_string_get_chars_fast (string_p, &string_size); + lit_utf8_size_t copy_size = 0; JERRY_ASSERT (chars_p != NULL); - if (flags & ECMA_STRING_FLAG_IS_ASCII) - { - JERRY_ASSERT (size <= buffer_size); - memcpy (buffer_p, chars_p, size); - return size; - } - - size = lit_convert_cesu8_string_to_utf8_string (chars_p, size, buffer_p, buffer_size); - - if (flags & ECMA_STRING_FLAG_MUST_BE_FREED) - { - jmem_heap_free_block ((void *) chars_p, size); - } - - JERRY_ASSERT (size <= buffer_size); - return size; -} /* ecma_string_copy_to_utf8_buffer */ - -/** - * Convert ecma-string's contents to a cesu-8 string, extract the parts of the converted string between the specified - * start position and the end position (or the end of the string, whichever comes first), and copy these characters - * into the buffer. - * - * @return number of bytes, actually copied to the buffer. - */ -lit_utf8_size_t -ecma_substring_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, /**< ecma-string descriptor */ - lit_utf8_size_t start_pos, /**< position of the first character */ - lit_utf8_size_t end_pos, /**< position of the last character */ - lit_utf8_byte_t *buffer_p, /**< destination buffer pointer - * (can be NULL if buffer_size == 0) */ - lit_utf8_size_t buffer_size) /**< size of buffer */ -{ - JERRY_ASSERT (string_desc_p != NULL); - JERRY_ASSERT (buffer_p != NULL || buffer_size == 0); - - lit_utf8_size_t string_length = ecma_string_get_length (string_desc_p); - lit_utf8_size_t size = 0; - - if (start_pos >= string_length || start_pos >= end_pos) - { - return 0; - } - - if (end_pos > string_length) - { - end_pos = string_length; - } - - ECMA_STRING_TO_UTF8_STRING (string_desc_p, utf8_str_p, utf8_str_size); - - const lit_utf8_byte_t *start_p = utf8_str_p; - - if (string_length == utf8_str_size) - { - start_p += start_pos; - size = end_pos - start_pos; - - if (size > buffer_size) - { - size = buffer_size; - } - - memcpy (buffer_p, start_p, size); - } - else - { - end_pos -= start_pos; - while (start_pos--) - { - start_p += lit_get_unicode_char_size_by_utf8_first_byte (*start_p); - } - - const lit_utf8_byte_t *end_p = start_p; - - while (end_pos--) - { - lit_utf8_size_t code_unit_size = lit_get_unicode_char_size_by_utf8_first_byte (*end_p); - - if ((size + code_unit_size) > buffer_size) - { - break; - } - - end_p += code_unit_size; - size += code_unit_size; - } - - memcpy (buffer_p, start_p, size); - } - - ECMA_FINALIZE_UTF8_STRING (utf8_str_p, utf8_str_size); - - JERRY_ASSERT (size <= buffer_size); - return size; -} /* ecma_substring_copy_to_cesu8_buffer */ - -/** - * Convert ecma-string's contents to an utf-8 string, extract the parts of the converted string between the specified - * start position and the end position (or the end of the string, whichever comes first), and copy these characters - * into the buffer. - * - * @return number of bytes, actually copied to the buffer. - */ -lit_utf8_size_t -ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, /**< ecma-string descriptor */ - lit_utf8_size_t start_pos, /**< position of the first character */ - lit_utf8_size_t end_pos, /**< position of the last character */ - lit_utf8_byte_t *buffer_p, /**< destination buffer pointer - * (can be NULL if buffer_size == 0) */ - lit_utf8_size_t buffer_size) /**< size of buffer */ -{ - JERRY_ASSERT (string_desc_p != NULL); - JERRY_ASSERT (ECMA_IS_DIRECT_STRING (string_desc_p) || string_desc_p->refs_and_container >= ECMA_STRING_REF_ONE); - JERRY_ASSERT (buffer_p != NULL || buffer_size == 0); - - lit_utf8_size_t size = 0; - - lit_utf8_size_t utf8_str_length = ecma_string_get_utf8_length (string_desc_p); - - if (start_pos >= utf8_str_length || start_pos >= end_pos) - { - return 0; - } - - if (end_pos > utf8_str_length) + switch (encoding) { - end_pos = utf8_str_length; - } - - ECMA_STRING_TO_UTF8_STRING (string_desc_p, cesu8_str_p, cesu8_str_size); - lit_utf8_size_t cesu8_str_length = ecma_string_get_length (string_desc_p); - - if (cesu8_str_length == cesu8_str_size) - { - cesu8_str_p += start_pos; - size = end_pos - start_pos; - - if (size > buffer_size) + case JERRY_ENCODING_CESU8: { - size = buffer_size; - } + copy_size = JERRY_MIN (string_size, buffer_size); - memcpy (buffer_p, cesu8_str_p, size); - } - else - { - const lit_utf8_byte_t *cesu8_end_pos = cesu8_str_p + cesu8_str_size; - end_pos -= start_pos; - - while (start_pos--) - { - ecma_char_t ch; - lit_utf8_size_t code_unit_size = lit_read_code_unit_from_cesu8 (cesu8_str_p, &ch); - - cesu8_str_p += code_unit_size; - if ((cesu8_str_p != cesu8_end_pos) && lit_is_code_point_utf16_high_surrogate (ch)) + if (copy_size < string_size) { - ecma_char_t next_ch; - lit_utf8_size_t next_ch_size = lit_read_code_unit_from_cesu8 (cesu8_str_p, &next_ch); - if (lit_is_code_point_utf16_low_surrogate (next_ch)) + /* Do not copy partial characters */ + while ((chars_p[copy_size] & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER) { - JERRY_ASSERT (code_unit_size == next_ch_size); - cesu8_str_p += code_unit_size; + copy_size--; } } - } - const lit_utf8_byte_t *cesu8_pos = cesu8_str_p; - - lit_utf8_byte_t *utf8_pos = buffer_p; - lit_utf8_byte_t *utf8_end_pos = buffer_p + buffer_size; - - while (end_pos--) + memcpy (buffer_p, chars_p, copy_size); + break; + } + case JERRY_ENCODING_UTF8: { - ecma_char_t ch; - lit_utf8_size_t code_unit_size = lit_read_code_unit_from_cesu8 (cesu8_pos, &ch); - - if ((size + code_unit_size) > buffer_size) + if (string_size == ecma_string_get_length (string_p)) { - break; - } - - if (((cesu8_pos + code_unit_size) != cesu8_end_pos) && lit_is_code_point_utf16_high_surrogate (ch)) - { - ecma_char_t next_ch; - lit_utf8_size_t next_ch_size = lit_read_code_unit_from_cesu8 (cesu8_pos + code_unit_size, &next_ch); - - if (lit_is_code_point_utf16_low_surrogate (next_ch)) - { - JERRY_ASSERT (code_unit_size == next_ch_size); - - if ((size + code_unit_size + 1) > buffer_size) - { - break; - } - - cesu8_pos += next_ch_size; + copy_size = JERRY_MIN (string_size, buffer_size); - lit_code_point_t code_point = lit_convert_surrogate_pair_to_code_point (ch, next_ch); - lit_code_point_to_utf8 (code_point, utf8_pos); - size += (code_unit_size + 1); - } - else - { - memcpy (utf8_pos, cesu8_pos, code_unit_size); - size += code_unit_size; - } - } - else - { - memcpy (utf8_pos, cesu8_pos, code_unit_size); - size += code_unit_size; + memcpy (buffer_p, chars_p, copy_size); + break; } - utf8_pos = buffer_p + size; - cesu8_pos += code_unit_size; + copy_size = lit_convert_cesu8_string_to_utf8_string (chars_p, string_size, buffer_p, buffer_size); + break; + } + default: + { + break; } - - JERRY_ASSERT (utf8_pos <= utf8_end_pos); } - ECMA_FINALIZE_UTF8_STRING (cesu8_str_p, cesu8_str_size); - JERRY_ASSERT (size <= buffer_size); - - return size; -} /* ecma_substring_copy_to_utf8_buffer */ + return copy_size; +} /* ecma_string_copy_to_buffer */ /** * Convert ecma-string's contents to a cesu-8 string and put it to the buffer. @@ -1407,14 +1180,14 @@ ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, /**< ecm * Check if the size of the string is equal with the size of the buffer. */ extern inline void JERRY_ATTR_ALWAYS_INLINE -ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, /**< ecma-string descriptor */ - lit_utf8_byte_t *buffer_p, /**< destination buffer pointer - * (can be NULL if buffer_size == 0) */ - lit_utf8_size_t buffer_size) /**< size of buffer */ +ecma_string_to_cesu8_bytes (const ecma_string_t *string_desc_p, /**< ecma-string descriptor */ + lit_utf8_byte_t *buffer_p, /**< destination buffer pointer + * (can be NULL if buffer_size == 0) */ + lit_utf8_size_t buffer_size) /**< size of buffer */ { - const lit_utf8_size_t size = ecma_string_copy_to_cesu8_buffer (string_desc_p, buffer_p, buffer_size); + const lit_utf8_size_t size = ecma_string_copy_to_buffer (string_desc_p, buffer_p, buffer_size, JERRY_ENCODING_CESU8); JERRY_ASSERT (size == buffer_size); -} /* ecma_string_to_utf8_bytes */ +} /* ecma_string_to_cesu8_bytes */ /** * Get size of the uint32 number stored locally in the string's descriptor @@ -2707,9 +2480,7 @@ ecma_stringbuilder_create_from (ecma_string_t *string_p) /**< ecma string */ jmem_stats_allocate_string_bytes (initial_size); #endif /* JERRY_MEM_STATS */ - size_t copied_size = - ecma_string_copy_to_cesu8_buffer (string_p, ECMA_STRINGBUILDER_STRING_PTR (header_p), string_size); - JERRY_ASSERT (copied_size == string_size); + ecma_string_to_cesu8_bytes (string_p, ECMA_STRINGBUILDER_STRING_PTR (header_p), string_size); ecma_stringbuilder_t ret = { .header_p = header_p }; return ret; @@ -2822,8 +2593,7 @@ ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, /**< string builder const lit_utf8_size_t string_size = ecma_string_get_size (string_p); lit_utf8_byte_t *dest_p = ecma_stringbuilder_grow (builder_p, string_size); - size_t copied_size = ecma_string_copy_to_cesu8_buffer (string_p, dest_p, string_size); - JERRY_ASSERT (copied_size == string_size); + ecma_string_to_cesu8_bytes (string_p, dest_p, string_size); } /* ecma_stringbuilder_append */ /** diff --git a/jerry-core/ecma/base/ecma-helpers-value.c b/jerry-core/ecma/base/ecma-helpers-value.c index 8b3598a921..0d4987074b 100644 --- a/jerry-core/ecma/base/ecma-helpers-value.c +++ b/jerry-core/ecma/base/ecma-helpers-value.c @@ -423,10 +423,10 @@ ecma_is_value_object (ecma_value_t value) /**< ecma value */ * false - otherwise */ extern inline bool JERRY_ATTR_CONST JERRY_ATTR_ALWAYS_INLINE -ecma_is_value_error_reference (ecma_value_t value) /**< ecma value */ +ecma_is_value_exception (ecma_value_t value) /**< ecma value */ { return (ecma_get_value_type_field (value) == ECMA_TYPE_ERROR); -} /* ecma_is_value_error_reference */ +} /* ecma_is_value_exception */ /** * Debug assertion that specified value's type is one of ECMA-defined diff --git a/jerry-core/ecma/base/ecma-helpers.c b/jerry-core/ecma/base/ecma-helpers.c index b47e153543..9c811ff946 100644 --- a/jerry-core/ecma/base/ecma-helpers.c +++ b/jerry-core/ecma/base/ecma-helpers.c @@ -1254,7 +1254,7 @@ ecma_ref_extended_primitive (ecma_extended_primitive_t *primitve_p) /**< extende * Decrease ref count of an error reference. */ void -ecma_deref_error_reference (ecma_extended_primitive_t *error_ref_p) /**< error reference */ +ecma_deref_exception (ecma_extended_primitive_t *error_ref_p) /**< error reference */ { JERRY_ASSERT (error_ref_p->refs_and_type >= ECMA_EXTENDED_PRIMITIVE_REF_ONE); @@ -1265,7 +1265,7 @@ ecma_deref_error_reference (ecma_extended_primitive_t *error_ref_p) /**< error r ecma_free_value (error_ref_p->u.value); jmem_pools_free (error_ref_p, sizeof (ecma_extended_primitive_t)); } -} /* ecma_deref_error_reference */ +} /* ecma_deref_exception */ #if JERRY_BUILTIN_BIGINT @@ -1303,8 +1303,8 @@ ecma_deref_bigint (ecma_extended_primitive_t *bigint_p) /**< bigint value */ * @return error reference value */ ecma_value_t -ecma_create_error_reference (ecma_value_t value, /**< referenced value */ - uint32_t options) /**< ECMA_ERROR_API_* options */ +ecma_create_exception (ecma_value_t value, /**< referenced value */ + uint32_t options) /**< ECMA_ERROR_API_* options */ { ecma_extended_primitive_t *error_ref_p; error_ref_p = (ecma_extended_primitive_t *) jmem_pools_alloc (sizeof (ecma_extended_primitive_t)); @@ -1312,7 +1312,7 @@ ecma_create_error_reference (ecma_value_t value, /**< referenced value */ error_ref_p->refs_and_type = ECMA_EXTENDED_PRIMITIVE_REF_ONE | options; error_ref_p->u.value = value; return ecma_make_extended_primitive_value (error_ref_p, ECMA_TYPE_ERROR); -} /* ecma_create_error_reference */ +} /* ecma_create_exception */ /** * Create an error reference from the currently thrown error value. @@ -1320,47 +1320,47 @@ ecma_create_error_reference (ecma_value_t value, /**< referenced value */ * @return error reference value */ ecma_value_t -ecma_create_error_reference_from_context (void) +ecma_create_exception_from_context (void) { uint32_t options = 0; uint32_t status_flags = JERRY_CONTEXT (status_flags); if (status_flags & ECMA_STATUS_ABORT) { - options |= ECMA_ERROR_API_ABORT; + options |= ECMA_ERROR_API_FLAG_ABORT; } #if JERRY_VM_THROW if (status_flags & ECMA_STATUS_ERROR_THROWN) { - options |= ECMA_ERROR_API_THROW_CAPTURED; + options |= ECMA_ERROR_API_FLAG_THROW_CAPTURED; } #endif /* JERRY_VM_THROW */ - return ecma_create_error_reference (jcontext_take_exception (), options); -} /* ecma_create_error_reference_from_context */ + return ecma_create_exception (jcontext_take_exception (), options); +} /* ecma_create_exception_from_context */ /** - * Create an error reference from a given object. + * Create an exception from a given object. * * Note: - * Reference of the value is taken. + * Reference of the object is taken. * - * @return error reference value + * @return exception value */ extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE -ecma_create_error_object_reference (ecma_object_t *object_p) /**< referenced object */ +ecma_create_exception_from_object (ecma_object_t *object_p) /**< referenced object */ { - return ecma_create_error_reference (ecma_make_object_value (object_p), 0); -} /* ecma_create_error_object_reference */ + return ecma_create_exception (ecma_make_object_value (object_p), 0); +} /* ecma_create_exception_from_object */ /** - * Raise error from the given error reference. + * Raise a new exception from the argument exception value. * - * Note: the error reference's ref count is also decreased + * Note: the argument exceptions reference count is decreased */ void -ecma_raise_error_from_error_reference (ecma_value_t value) /**< error reference */ +ecma_throw_exception (ecma_value_t value) /**< error reference */ { JERRY_ASSERT (!jcontext_has_pending_exception () && !jcontext_has_pending_abort ()); ecma_extended_primitive_t *error_ref_p = ecma_get_extended_primitive_from_value (value); @@ -1376,13 +1376,13 @@ ecma_raise_error_from_error_reference (ecma_value_t value) /**< error reference #endif /* JERRY_VM_THROW */ | ECMA_STATUS_ABORT); - if (!(error_ref_p->refs_and_type & ECMA_ERROR_API_ABORT)) + if (!(error_ref_p->refs_and_type & ECMA_ERROR_API_FLAG_ABORT)) { status_flags &= ~(uint32_t) ECMA_STATUS_ABORT; } #if JERRY_VM_THROW - if (!(error_ref_p->refs_and_type & ECMA_ERROR_API_THROW_CAPTURED)) + if (!(error_ref_p->refs_and_type & ECMA_ERROR_API_FLAG_THROW_CAPTURED)) { status_flags &= ~(uint32_t) ECMA_STATUS_ERROR_THROWN; } @@ -1401,7 +1401,7 @@ ecma_raise_error_from_error_reference (ecma_value_t value) /**< error reference } JERRY_CONTEXT (error_value) = referenced_value; -} /* ecma_raise_error_from_error_reference */ +} /* ecma_throw_exception */ /** * Decrease the reference counter of a script value. @@ -1434,7 +1434,7 @@ ecma_script_deref (ecma_value_t script_value) /**< script value */ } #if JERRY_RESOURCE_NAME - ecma_deref_ecma_string (ecma_get_string_from_value (script_p->resource_name)); + ecma_deref_ecma_string (ecma_get_string_from_value (script_p->source_name)); #endif /* JERRY_RESOURCE_NAME */ #if JERRY_MODULE_SYSTEM @@ -1778,7 +1778,7 @@ ecma_compiled_code_get_line_info (const ecma_compiled_code_t *bytecode_header_p) * @return resource name value */ ecma_value_t -ecma_get_resource_name (const ecma_compiled_code_t *bytecode_p) /**< compiled code */ +ecma_get_source_name (const ecma_compiled_code_t *bytecode_p) /**< compiled code */ { #if JERRY_RESOURCE_NAME #if JERRY_SNAPSHOT_EXEC @@ -1789,12 +1789,12 @@ ecma_get_resource_name (const ecma_compiled_code_t *bytecode_p) /**< compiled co #endif /* JERRY_SNAPSHOT_EXEC */ ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value; - return ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value)->resource_name; + return ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value)->source_name; #else /* !JERRY_RESOURCE_NAME */ JERRY_UNUSED (bytecode_p); return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); #endif /* !JERRY_RESOURCE_NAME */ -} /* ecma_get_resource_name */ +} /* ecma_get_source_name */ #if (JERRY_STACK_LIMIT != 0) /** diff --git a/jerry-core/ecma/base/ecma-helpers.h b/jerry-core/ecma/base/ecma-helpers.h index 609cf62e6c..0b03c6ff58 100644 --- a/jerry-core/ecma/base/ecma-helpers.h +++ b/jerry-core/ecma/base/ecma-helpers.h @@ -227,7 +227,7 @@ bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_non_direct_string (ecma_value_t value); bool JERRY_ATTR_CONST ecma_is_value_object (ecma_value_t value); -bool JERRY_ATTR_CONST ecma_is_value_error_reference (ecma_value_t value); +bool JERRY_ATTR_CONST ecma_is_value_exception (ecma_value_t value); ecma_value_t ecma_is_value_array (ecma_value_t arg); void ecma_check_value_type_is_spec_defined (ecma_value_t value); @@ -316,24 +316,12 @@ void ecma_destroy_ecma_string (ecma_string_t *string_p); ecma_number_t ecma_string_to_number (const ecma_string_t *str_p); uint32_t ecma_string_get_array_index (const ecma_string_t *str_p); -lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT ecma_string_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, - lit_utf8_byte_t *buffer_p, - lit_utf8_size_t buffer_size); -lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT ecma_string_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, - lit_utf8_byte_t *buffer_p, - lit_utf8_size_t buffer_size); -lit_utf8_size_t ecma_substring_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, - lit_utf8_size_t start_pos, - lit_utf8_size_t end_pos, - lit_utf8_byte_t *buffer_p, - lit_utf8_size_t buffer_size); -lit_utf8_size_t ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, - lit_utf8_size_t start_pos, - lit_utf8_size_t end_pos, - lit_utf8_byte_t *buffer_p, - lit_utf8_size_t buffer_size); +lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT ecma_string_copy_to_buffer (const ecma_string_t *string_desc_p, + lit_utf8_byte_t *buffer_p, + lit_utf8_size_t buffer_size, + jerry_encoding_t encoding); void -ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); +ecma_string_to_cesu8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, lit_utf8_size_t *size_p, lit_utf8_size_t *length_p, @@ -499,15 +487,15 @@ ecma_property_descriptor_t ecma_make_empty_property_descriptor (void); void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p); void ecma_ref_extended_primitive (ecma_extended_primitive_t *primitve_p); -void ecma_deref_error_reference (ecma_extended_primitive_t *error_ref_p); +void ecma_deref_exception (ecma_extended_primitive_t *exception_p); #if JERRY_BUILTIN_BIGINT void ecma_deref_bigint (ecma_extended_primitive_t *bigint_p); #endif /* JERRY_BUILTIN_BIGINT */ -ecma_value_t ecma_create_error_reference (ecma_value_t value, uint32_t options); -ecma_value_t ecma_create_error_reference_from_context (void); -ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p); -void ecma_raise_error_from_error_reference (ecma_value_t value); +ecma_value_t ecma_create_exception (ecma_value_t value, uint32_t options); +ecma_value_t ecma_create_exception_from_context (void); +ecma_value_t ecma_create_exception_from_object (ecma_object_t *object_p); +void ecma_throw_exception (ecma_value_t value); void ecma_script_deref (ecma_value_t script_value); void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p); @@ -521,7 +509,7 @@ ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma #if JERRY_LINE_INFO uint8_t *ecma_compiled_code_get_line_info (const ecma_compiled_code_t *bytecode_header_p); #endif /* JERRY_LINE_INFO */ -ecma_value_t ecma_get_resource_name (const ecma_compiled_code_t *bytecode_p); +ecma_value_t ecma_get_source_name (const ecma_compiled_code_t *bytecode_p); #if (JERRY_STACK_LIMIT != 0) uintptr_t ecma_get_current_stack_usage (void); #endif /* (JERRY_STACK_LIMIT != 0) */ diff --git a/jerry-core/ecma/base/ecma-line-info.c b/jerry-core/ecma/base/ecma-line-info.c index db561c461e..5288d9310c 100644 --- a/jerry-core/ecma/base/ecma-line-info.c +++ b/jerry-core/ecma/base/ecma-line-info.c @@ -116,7 +116,7 @@ ecma_line_info_free (uint8_t *line_info_p) /**< line info buffer */ void ecma_line_info_get (uint8_t *line_info_p, /**< line info buffer */ uint32_t offset, /**< byte code offset */ - jerry_backtrace_location_t *location_p) /**< [out] location */ + jerry_frame_location_t *location_p) /**< [out] location */ { uint32_t line = 1; uint32_t column = ECMA_LINE_INFO_COLUMN_DEFAULT; diff --git a/jerry-core/ecma/base/ecma-line-info.h b/jerry-core/ecma/base/ecma-line-info.h index f2094018f8..f04aead5f5 100644 --- a/jerry-core/ecma/base/ecma-line-info.h +++ b/jerry-core/ecma/base/ecma-line-info.h @@ -98,7 +98,7 @@ uint32_t ecma_line_info_difference_update (uint32_t current_value, uint32_t diff /* General functions. */ void ecma_line_info_free (uint8_t *line_info_p); -void ecma_line_info_get (uint8_t *line_info_p, uint32_t offset, jerry_backtrace_location_t *location_p); +void ecma_line_info_get (uint8_t *line_info_p, uint32_t offset, jerry_frame_location_t *location_p); #if JERRY_PARSER_DUMP_BYTE_CODE void ecma_line_info_dump (uint8_t *line_info_p); diff --git a/jerry-core/ecma/base/ecma-literal-storage.c b/jerry-core/ecma/base/ecma-literal-storage.c index 5e69b00d07..a6d1b13551 100644 --- a/jerry-core/ecma/base/ecma-literal-storage.c +++ b/jerry-core/ecma/base/ecma-literal-storage.c @@ -633,7 +633,7 @@ ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, /**< list of kno *(uint16_t *) destination_p = (uint16_t) length; - ecma_string_to_utf8_bytes (string_p, destination_p + sizeof (uint16_t), length); + ecma_string_to_cesu8_bytes (string_p, destination_p + sizeof (uint16_t), length); length = JERRY_ALIGNUP (sizeof (uint16_t) + length, JERRY_SNAPSHOT_LITERAL_ALIGNMENT); } diff --git a/jerry-core/ecma/base/ecma-module.c b/jerry-core/ecma/base/ecma-module.c index 3a3624a406..babd8499a3 100644 --- a/jerry-core/ecma/base/ecma-module.c +++ b/jerry-core/ecma/base/ecma-module.c @@ -563,9 +563,9 @@ ecma_module_evaluate (ecma_module_t *module_p) /**< module */ { ret_value = module_p->u.callback (ecma_make_object_value (&module_p->header.object)); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (ret_value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (ret_value))) { - ecma_raise_error_from_error_reference (ret_value); + ecma_throw_exception (ret_value); ret_value = ECMA_VALUE_ERROR; } } @@ -1099,7 +1099,7 @@ typedef struct ecma_module_stack_item_t */ ecma_value_t ecma_module_link (ecma_module_t *module_p, /**< root module */ - jerry_module_resolve_callback_t callback, /**< resolve module callback */ + jerry_module_resolve_cb_t callback, /**< resolve module callback */ void *user_p) /**< pointer passed to the resolve callback */ { if (module_p->header.u.cls.u1.module_state != JERRY_MODULE_STATE_UNLINKED) @@ -1141,9 +1141,9 @@ ecma_module_link (ecma_module_t *module_p, /**< root module */ ecma_value_t resolve_result = callback (node_p->u.path_or_module, module_val, user_p); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (resolve_result))) + if (JERRY_UNLIKELY (ecma_is_value_exception (resolve_result))) { - ecma_raise_error_from_error_reference (resolve_result); + ecma_throw_exception (resolve_result); goto error; } @@ -1373,9 +1373,9 @@ ecma_module_import (ecma_value_t specifier, /**< module specifier */ JERRY_CONTEXT (module_import_callback_user_p)); ecma_deref_ecma_string (specifier_p); - if (JERRY_UNLIKELY (ecma_is_value_error_reference (result))) + if (JERRY_UNLIKELY (ecma_is_value_exception (result))) { - ecma_raise_error_from_error_reference (result); + ecma_throw_exception (result); goto error; } diff --git a/jerry-core/ecma/base/ecma-module.h b/jerry-core/ecma/base/ecma-module.h index dd76f57c19..ceb47ec669 100644 --- a/jerry-core/ecma/base/ecma-module.h +++ b/jerry-core/ecma/base/ecma-module.h @@ -68,7 +68,7 @@ typedef struct ecma_module union { ecma_compiled_code_t *compiled_code_p; /**< compiled code for the module */ - jerry_native_module_evaluate_callback_t callback; /**< callback for evaluating native modules */ + jerry_native_module_evaluate_cb_t callback; /**< callback for evaluating native modules */ } u; } ecma_module_t; @@ -117,7 +117,7 @@ typedef struct ecma_module_resolve_stack ecma_value_t ecma_module_initialize (ecma_module_t *module_p); ecma_module_t *ecma_module_get_resolved_module (ecma_value_t module_val); -ecma_value_t ecma_module_link (ecma_module_t *module_p, jerry_module_resolve_callback_t callback_p, void *user_p); +ecma_value_t ecma_module_link (ecma_module_t *module_p, jerry_module_resolve_cb_t callback_p, void *user_p); ecma_value_t ecma_module_evaluate (ecma_module_t *module_p); ecma_value_t ecma_module_import (ecma_value_t specifier, ecma_value_t user_value); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-global.c b/jerry-core/ecma/builtin-objects/ecma-builtin-global.c index f02303848e..44f64ae47f 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-global.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-global.c @@ -649,7 +649,7 @@ ecma_builtin_global_dispatch_routine (uint8_t builtin_routine_id, /**< built-in JMEM_DEFINE_LOCAL_ARRAY (input_start_p, input_size + 1, lit_utf8_byte_t); - ecma_string_to_utf8_bytes (str_p, input_start_p, input_size); + ecma_string_to_cesu8_bytes (str_p, input_start_p, input_size); input_start_p[input_size] = LIT_BYTE_NULL; diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c index 3edab6f2c4..68195270ef 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c @@ -53,11 +53,12 @@ ecma_builtin_helper_object_to_string_tag_helper (ecma_value_t tag_value) /**< st JERRY_ASSERT (ecma_is_value_string (tag_value)); ecma_string_t *tag_str_p = ecma_get_string_from_value (tag_value); + lit_utf8_size_t tag_str_size = ecma_string_get_size (tag_str_p); ecma_string_t *ret_string_p; /* Building string "[object #@@toStringTag#]" The string size will be size("[object ") + size(#@@toStringTag#) + size ("]"). */ - const lit_utf8_size_t buffer_size = 9 + ecma_string_get_size (tag_str_p); + const lit_utf8_size_t buffer_size = 9 + tag_str_size; JMEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, lit_utf8_byte_t); lit_utf8_byte_t *buffer_ptr = str_buffer; @@ -79,9 +80,8 @@ ecma_builtin_helper_object_to_string_tag_helper (ecma_value_t tag_value) /**< st } /* Copy to buffer the #@@toStringTag# string */ - buffer_ptr += ecma_string_copy_to_cesu8_buffer (tag_str_p, - buffer_ptr, - (lit_utf8_size_t) ((str_buffer + buffer_size) - buffer_ptr)); + ecma_string_to_cesu8_bytes (tag_str_p, buffer_ptr, tag_str_size); + buffer_ptr += tag_str_size; JERRY_ASSERT (buffer_ptr <= str_buffer + buffer_size); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c index ef2a7dbd00..3a02b0f8c0 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c @@ -133,6 +133,22 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument break; } + if (*current_p >= LIT_UTF8_4_BYTE_MARKER) + { + ecma_stringbuilder_append_raw (&result_builder, unappended_p, (lit_utf8_size_t) (current_p - unappended_p)); + JERRY_ASSERT (current_p + 4 <= end_p); + + lit_code_point_t cp; + lit_utf8_size_t read_size = lit_read_code_point_from_utf8 (current_p, 4, &cp); + JERRY_ASSERT (read_size == 4); + + ecma_stringbuilder_append_codepoint (&result_builder, cp); + current_p += 4; + + unappended_p = current_p; + continue; + } + if (*current_p == LIT_CHAR_BACKSLASH) { ecma_stringbuilder_append_raw (&result_builder, unappended_p, (lit_utf8_size_t) (current_p - unappended_p)); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index dafde43ed7..cf6da69974 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -1277,11 +1277,13 @@ ecma_builtin_string_prototype_object_repeat (ecma_string_t *original_string_p, / JMEM_DEFINE_LOCAL_ARRAY (str_buffer, total_size, lit_utf8_byte_t); - lit_utf8_byte_t *buffer_ptr = str_buffer; + ecma_string_to_cesu8_bytes (original_string_p, str_buffer, size); + lit_utf8_byte_t *buffer_ptr = str_buffer + size; - for (int32_t n = 0; n < repeat_count; n++) + for (int32_t n = 1; n < repeat_count; n++) { - buffer_ptr += ecma_string_copy_to_cesu8_buffer (original_string_p, buffer_ptr, (lit_utf8_size_t) (size)); + memcpy (buffer_ptr, str_buffer, size); + buffer_ptr += size; } ret_string_p = ecma_new_ecma_string_from_utf8 (str_buffer, (lit_utf8_size_t) (buffer_ptr - str_buffer)); diff --git a/jerry-core/ecma/operations/ecma-arraybuffer-object.c b/jerry-core/ecma/operations/ecma-arraybuffer-object.c index 3457066ca3..27fffd9532 100644 --- a/jerry-core/ecma/operations/ecma-arraybuffer-object.c +++ b/jerry-core/ecma/operations/ecma-arraybuffer-object.c @@ -140,7 +140,7 @@ ecma_arraybuffer_allocate_buffer (ecma_object_t *arraybuffer_p) /**< ArrayBuffer ecma_extended_object_t *extended_object_p = (ecma_extended_object_t *) arraybuffer_p; uint32_t arraybuffer_length = extended_object_p->u.cls.u3.length; ecma_arraybuffer_pointer_t *arraybuffer_pointer_p = (ecma_arraybuffer_pointer_t *) arraybuffer_p; - jerry_arraybuffer_allocate_t arraybuffer_allocate_callback = JERRY_CONTEXT (arraybuffer_allocate_callback); + jerry_arraybuffer_allocate_cb_t arraybuffer_allocate_callback = JERRY_CONTEXT (arraybuffer_allocate_callback); uint8_t *buffer_p; if (arraybuffer_allocate_callback != NULL) @@ -212,7 +212,7 @@ ecma_arraybuffer_release_buffer (ecma_object_t *arraybuffer_p) /**< ArrayBuffer JERRY_ASSERT (ecma_object_class_is (arraybuffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER) || ecma_object_is_shared_arraybuffer (arraybuffer_p)); - jerry_arraybuffer_free_t free_callback = JERRY_CONTEXT (arraybuffer_free_callback); + jerry_arraybuffer_free_cb_t free_callback = JERRY_CONTEXT (arraybuffer_free_callback); ecma_arraybuffer_pointer_t *arraybuffer_pointer_p = (ecma_arraybuffer_pointer_t *) arraybuffer_p; uint32_t arraybuffer_length = arraybuffer_pointer_p->extended_object.u.cls.u3.length; diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index befad242c3..40098966fb 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -1286,9 +1286,9 @@ ecma_op_function_call_native (ecma_object_t *func_obj_p, /**< Function object */ JERRY_CONTEXT (global_object_p) = saved_global_object_p; #endif /* JERRY_BUILTIN_REALMS */ - if (JERRY_UNLIKELY (ecma_is_value_error_reference (ret_value))) + if (JERRY_UNLIKELY (ecma_is_value_exception (ret_value))) { - ecma_raise_error_from_error_reference (ret_value); + ecma_throw_exception (ret_value); return ECMA_VALUE_ERROR; } diff --git a/jerry-core/include/jerryscript-core.h b/jerry-core/include/jerryscript-core.h index 59bef3a4ef..ccb5632b91 100644 --- a/jerry-core/include/jerryscript-core.h +++ b/jerry-core/include/jerryscript-core.h @@ -13,6 +13,8 @@ * limitations under the License. */ +/* vim:fdm=marker:fmr=@{,@} */ + #ifndef JERRYSCRIPT_CORE_H #define JERRYSCRIPT_CORE_H @@ -20,127 +22,187 @@ JERRY_C_API_BEGIN -/** \addtogroup jerry Jerry engine interface +/** + * \defgroup jerry-api JerryScript public API + * @{ + */ + +/** + * \defgroup jerry-api-general General functions * @{ */ /** - * General engine functions. + * \defgroup jerry-api-general-conext Context management + * @{ */ 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, + +jerry_context_t *jerry_context (jerry_size_t heap_size, jerry_context_alloc_cb_t alloc, void *cb_data_p); +void *jerry_context_data (const jerry_context_data_manager_t *manager_p); + +jerry_value_t jerry_current_realm (void); +jerry_value_t jerry_set_realm (jerry_value_t realm); +/** + * jerry-api-general-conext @} + */ + +/** + * \defgroup jerry-api-general-heap Heap management + * @{ + */ +void *jerry_heap_alloc (jerry_size_t size); +void jerry_heap_free (void *mem_p, jerry_size_t size); + +bool jerry_heap_stats (jerry_heap_stats_t *out_stats_p); +void jerry_heap_gc (jerry_gc_mode_t mode); + +bool jerry_foreach_live_object (jerry_foreach_live_object_cb_t callback, void *user_data); +bool jerry_foreach_live_object_with_info (const jerry_object_native_info_t *native_info_p, + jerry_foreach_live_object_with_info_cb_t callback, + void *user_data_p); +/** + * jerry-api-general-heap @} + */ + +/* Miscellaneous functions. */ +bool jerry_validate_string (const jerry_char_t *buffer_p, jerry_size_t buffer_size, jerry_encoding_t encoding); +bool jerry_feature_enabled (const jerry_feature_t feature); +void jerry_register_magic_strings (const jerry_char_t *const *ext_strings_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); +/** + * jerry-api-general @} + */ -bool jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p); +/** + * \defgroup jerry-api-code Scripts and Executables + * @{ + */ /** - * Parser and executor functions. + * \defgroup jerry-api-code-parse Parsing + * @{ */ -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 *source_p, size_t source_size, const jerry_parse_options_t *options_p); -jerry_value_t jerry_parse_value (const jerry_value_t source_value, const jerry_parse_options_t *options_p); -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); +jerry_value_t jerry_parse_value (const jerry_value_t source, const jerry_parse_options_t *options_p); +/** + * jerry-api-code-parse @} + */ /** - * Get the global context. + * \defgroup jerry-api-code-exec Execution + * @{ + */ +jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, uint32_t flags); +jerry_value_t jerry_run (const jerry_value_t script); +jerry_value_t jerry_run_microtasks (void); +/** + * jerry-api-code-exec @} */ -jerry_value_t jerry_get_global_object (void); /** - * Checker functions of 'jerry_value_t'. + * \defgroup jerry-api-code-sourceinfo Source information + * @{ + */ +jerry_value_t jerry_source_name (const jerry_value_t value); +jerry_value_t jerry_source_user_value (const jerry_value_t value); +jerry_source_info_t *jerry_source_info (const jerry_value_t value); +void jerry_source_info_free (jerry_source_info_t *source_info_p); +/** + * jerry-api-code-sourceinfo @} */ -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); -bool jerry_value_is_true (const jerry_value_t value); -bool jerry_value_is_false (const jerry_value_t value); -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); +/** + * \defgroup jerry-api-code-cb Callbacks + * @{ + */ +void jerry_halt_cb (jerry_halt_cb_t halt_cb, void *user_p, uint32_t frequency); +/** + * jerry-api-code-cb @} + */ /** - * Checker function of whether the specified compile feature is enabled. + * jerry-api-code @} */ -bool jerry_is_feature_enabled (const jerry_feature_t feature); /** - * Binary operations + * \defgroup jerry-api-backtrace Backtraces + * @{ */ -jerry_value_t jerry_binary_operation (jerry_binary_operation_t op, const jerry_value_t lhs, const jerry_value_t rhs); /** - * Error manipulation functions. + * \defgroup jerry-api-backtrace-frame Frames + * @{ + */ +jerry_frame_type_t jerry_frame_type (const jerry_frame_t *frame_p); +const jerry_value_t *jerry_frame_callee (jerry_frame_t *frame_p); +const jerry_value_t *jerry_frame_this (jerry_frame_t *frame_p); +const jerry_frame_location_t *jerry_frame_location (jerry_frame_t *frame_p); +bool jerry_frame_is_strict (jerry_frame_t *frame_p); +/** + * jerry-api-backtrace-frame @} */ -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); -void jerry_set_error_object_created_callback (jerry_error_object_created_callback_t callback, void *user_p); -void jerry_set_vm_throw_callback (jerry_vm_throw_callback_t throw_cb, void *user_p); -bool jerry_error_is_throw_captured (jerry_value_t value); -void jerry_error_set_throw_capture (jerry_value_t value, bool should_capture); + +/* Capturing */ +jerry_value_t jerry_backtrace (uint32_t max_depth); +void jerry_backtrace_capture (jerry_backtrace_cb_t callback, void *user_p); /** - * Error object function(s). + * jerry-api-backtrace @} */ -jerry_error_t jerry_get_error_type (jerry_value_t value); /** - * Getter functions of 'jerry_value_t'. + * \defgroup jerry-api-value Values + * @{ */ -double jerry_get_number_value (const jerry_value_t value); + +/* Reference management */ +jerry_value_t jerry_value_copy (const jerry_value_t value); +void jerry_value_free (jerry_value_t value); /** - * Functions for string values. + * \defgroup jerry-api-value-checks Type inspection + * @{ */ -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); -void jerry_string_set_external_free_callback (jerry_external_string_free_callback_t callback_p); -void *jerry_string_get_external_user_pointer (const jerry_value_t value, bool *is_external); +jerry_type_t jerry_value_type (const jerry_value_t value); +bool jerry_value_is_exception (const jerry_value_t value); +bool jerry_value_is_abort (const jerry_value_t value); + +bool jerry_value_is_undefined (const jerry_value_t value); +bool jerry_value_is_null (const jerry_value_t value); +bool jerry_value_is_boolean (const jerry_value_t value); +bool jerry_value_is_true (const jerry_value_t value); +bool jerry_value_is_false (const jerry_value_t value); + +bool jerry_value_is_number (const jerry_value_t value); +bool jerry_value_is_bigint (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_object (const jerry_value_t value); +bool jerry_value_is_array (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_arraybuffer (const jerry_value_t value); +bool jerry_value_is_shared_arraybuffer (const jerry_value_t value); +bool jerry_value_is_dataview (const jerry_value_t value); +bool jerry_value_is_typedarray (const jerry_value_t value); + +bool jerry_value_is_constructor (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_error (const jerry_value_t value); /** - * Functions for array object values. + * jerry-api-value-checks @} */ -uint32_t jerry_get_array_length (const jerry_value_t value); /** - * Converters of 'jerry_value_t'. + * \defgroup jerry-api-value-coerce Coercion + * @{ */ bool jerry_value_to_boolean (const jerry_value_t value); jerry_value_t jerry_value_to_number (const jerry_value_t value); @@ -148,292 +210,872 @@ 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_number (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); +/** + * jerry-api-value-coerce @} + */ /** - * Acquire types with reference counter (increase the references). + * \defgroup jerry-api-value-op Operations + * @{ */ -jerry_value_t jerry_acquire_value (jerry_value_t value); +jerry_value_t jerry_binary_op (jerry_binary_op_t operation, const jerry_value_t lhs, const jerry_value_t rhs); /** - * Release the referenced values. + * jerry-api-value-op @} */ -void jerry_release_value (jerry_value_t value); /** - * Create functions of API values. + * jerry-api-value @} */ -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_special_proxy (const jerry_value_t target, const jerry_value_t handler, uint32_t options); -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, void *user_p); -jerry_value_t jerry_create_external_string_sz (const jerry_char_t *str_p, jerry_size_t str_size, void *user_p); -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_own_property (const jerry_value_t obj_val, - const jerry_value_t prop_name_val, - const jerry_value_t receiver_val, - bool *found_p); -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); - -jerry_property_descriptor_t jerry_property_descriptor_create (void); -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); - -jerry_value_t 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_property_descriptor_free (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); +/** + * \defgroup jerry-api-exception Exceptions + * @{ + */ -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); -void jerry_native_pointer_init_references (void *native_pointer_p, const jerry_object_native_info_t *native_info_p); -void jerry_native_pointer_release_references (void *native_pointer_p, const jerry_object_native_info_t *native_info_p); -void jerry_native_pointer_set_reference (jerry_value_t *reference_p, jerry_value_t value); +/** + * \defgroup jerry-api-exception-ctor Constructors + * @{ + */ +jerry_value_t jerry_throw (jerry_error_t type, const jerry_value_t message); +jerry_value_t jerry_throw_sz (jerry_error_t type, const char *message_p); +jerry_value_t jerry_throw_value (const jerry_value_t value, bool take_ownership); +jerry_value_t jerry_throw_abort (const jerry_value_t value, bool take_ownership); +/** + * jerry-api-exception-ctor @} + */ -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); +/** + * \defgroup jerry-api-exception-op Operations + * @{ + */ +void jerry_exception_allow_capture (jerry_value_t value, bool allow_capture); +/** + * jerry-api-exception-op @} + */ -bool jerry_foreach_object_property (const jerry_value_t obj_val, - jerry_object_property_foreach_t foreach_p, - void *user_data_p); +/** + * \defgroup jerry-api-exception-get Getters + * @{ + */ +jerry_value_t jerry_exception_value (jerry_value_t value, bool free_exception); +bool jerry_exception_is_captured (const jerry_value_t value); +/** + * jerry-api-exception-get @} + */ -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); +/** + * \defgroup jerry-api-exception-cb Callbacks + * @{ + */ +void jerry_throw_cb (jerry_throw_cb_t throw_cb, void *user_p); +/** + * jerry-api-exception-cb @} + */ /** - * Module functions. + * jerry-api-error @} */ -jerry_value_t -jerry_module_link (const jerry_value_t module_val, jerry_module_resolve_callback_t callback_p, void *user_p); -jerry_value_t jerry_module_evaluate (const jerry_value_t module_val); -jerry_module_state_t jerry_module_get_state (const jerry_value_t module_val); -void jerry_module_set_state_changed_callback (jerry_module_state_changed_callback_t callback, void *user_p); -void jerry_module_set_import_meta_callback (jerry_module_import_meta_callback_t callback, void *user_p); -size_t jerry_module_get_number_of_requests (const jerry_value_t module_val); -jerry_value_t jerry_module_get_request (const jerry_value_t module_val, size_t request_index); -jerry_value_t jerry_module_get_namespace (const jerry_value_t module_val); -void jerry_module_set_import_callback (jerry_module_import_callback_t callback_p, void *user_p); +/** + * \defgroup jerry-api-primitives Primitive types + * @{ + */ + +/** + * \defgroup jerry-api-undefined Undefined + * @{ + */ -jerry_value_t jerry_native_module_create (jerry_native_module_evaluate_callback_t callback, - const jerry_value_t *const exports_p, - size_t number_of_exports); -jerry_value_t jerry_native_module_get_export (const jerry_value_t native_module_val, - const jerry_value_t export_name_val); -jerry_value_t jerry_native_module_set_export (const jerry_value_t native_module_val, - const jerry_value_t export_name_val, - const jerry_value_t value_to_set); +jerry_value_t jerry_undefined (void); /** - * Promise functions. + * jerry-api-undefined @} */ -jerry_value_t jerry_resolve_or_reject_promise (jerry_value_t promise, jerry_value_t argument, bool is_resolve); +/** + * \defgroup jerry-api-null Null + * @{ + */ -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); +jerry_value_t jerry_null (void); -void jerry_promise_set_callback (jerry_promise_event_filter_t filters, jerry_promise_callback_t callback, void *user_p); +/** + * jerry-api-null @} + */ /** - * Symbol functions. + * \defgroup jerry-api-boolean Boolean + * @{ */ -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); +jerry_value_t jerry_boolean (bool value); /** - * Realm functions. + * jerry-api-boolean @} */ -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. + * \defgroup jerry-api-number Number + * @{ */ -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); + +jerry_value_t jerry_number (double value); +jerry_value_t jerry_infinity (bool sign); +jerry_value_t jerry_nan (void); /** - * Proxy functions. + * jerry-api-number @} */ -jerry_value_t jerry_get_proxy_target (jerry_value_t proxy_value); -jerry_value_t jerry_get_proxy_handler (jerry_value_t proxy_value); /** - * Input validator functions. + * \defgroup jerry-api-bigint BigInt + * @{ */ -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. +/** + * \defgroup jerry-api-bigint-ctor Constructors + * @{ + */ +jerry_value_t jerry_bigint (const uint64_t *digits_p, uint32_t digit_count, bool sign); +/** + * jerry-api-bigint-ctor @} */ -void *jerry_heap_alloc (size_t size); -void jerry_heap_free (void *mem_p, size_t size); -/* - * External context functions. +/** + * \defgroup jerry-api-bigint-get Getters + * @{ + */ +uint32_t jerry_bigint_digit_count (const jerry_value_t value); +/** + * jerry-api-bigint-get @} */ -jerry_context_t *jerry_create_context (uint32_t heap_size, jerry_context_alloc_t alloc, void *cb_data_p); /** - * Backtrace functions. + * \defgroup jerry-api-bigint-op Operations + * @{ + */ +void jerry_bigint_to_digits (const jerry_value_t value, uint64_t *digits_p, uint32_t digit_count, bool *sign_p); +/** + * jerry-api-bigint-get @} */ -jerry_value_t jerry_get_backtrace (uint32_t max_depth); -void jerry_backtrace_capture (jerry_backtrace_callback_t callback, void *user_p); -jerry_backtrace_frame_types_t jerry_backtrace_get_frame_type (jerry_backtrace_frame_t *frame_p); -const jerry_backtrace_location_t *jerry_backtrace_get_location (jerry_backtrace_frame_t *frame_p); -const jerry_value_t *jerry_backtrace_get_function (jerry_backtrace_frame_t *frame_p); -const jerry_value_t *jerry_backtrace_get_this (jerry_backtrace_frame_t *frame_p); -bool jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p); /** - * Miscellaneous functions. + * jerry-api-bigint @} */ -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_resource_name (const jerry_value_t value); -jerry_value_t jerry_get_user_value (const jerry_value_t value); -bool jerry_is_eval_code (const jerry_value_t value); -jerry_source_info_t *jerry_get_source_info (const jerry_value_t value); -void jerry_free_source_info (jerry_source_info_t *source_info_p); /** - * Array buffer components. + * \defgroup jerry-api-string String + * @{ */ -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, void *buffer_user_p); -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); -bool jerry_arraybuffer_has_buffer (const jerry_value_t value); -void jerry_arraybuffer_set_compact_allocation_limit (const jerry_length_t allocation_limit); -void jerry_arraybuffer_set_allocator_callbacks (jerry_arraybuffer_allocate_t allocate_callback, - jerry_arraybuffer_free_t free_callback, - void *user_p); /** - * SharedArrayBuffer components. + * \defgroup jerry-api-string-ctor Constructors + * @{ + */ +jerry_value_t jerry_string (const jerry_char_t *buffer_p, jerry_size_t buffer_size, jerry_encoding_t encoding); +jerry_value_t jerry_string_sz (const char *str_p); +jerry_value_t jerry_string_external (const jerry_char_t *buffer_p, jerry_size_t buffer_size, void *user_p); +jerry_value_t jerry_string_external_sz (const char *str_p, void *user_p); +/** + * jerry-api-string-cotr @} */ -bool jerry_value_is_shared_arraybuffer (const jerry_value_t value); -jerry_value_t jerry_create_shared_arraybuffer (const jerry_length_t size); -jerry_value_t -jerry_create_shared_arraybuffer_external (const jerry_length_t size, uint8_t *buffer_p, void *buffer_user_p); +/** + * \defgroup jerry-api-string-get Getters + * @{ + */ +jerry_size_t jerry_string_size (const jerry_value_t value, jerry_encoding_t encoding); +jerry_length_t jerry_string_length (const jerry_value_t value); +void *jerry_string_user_ptr (const jerry_value_t value, bool *is_external); +/** + * jerry-api-string-get @} + */ /** - * DataView functions. + * \defgroup jerry-api-string-op Operations + * @{ + */ +jerry_size_t jerry_string_substr (const jerry_value_t value, jerry_length_t start, jerry_length_t end); +jerry_size_t jerry_string_to_buffer (const jerry_value_t value, + jerry_char_t *buffer_p, + jerry_size_t buffer_size, + jerry_encoding_t encoding); +void jerry_string_iterate (const jerry_value_t value, jerry_string_iterate_cb_t cb, jerry_encoding_t encoding); +void jerry_string_print (const jerry_value_t value); +/** + * jerry-api-string-op @} */ -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); +/** + * \defgroup jerry-api-string-cb Callbacks + * @{ + */ +void jerry_string_external_free_cb (jerry_external_string_free_cb_t callback); +/** + * jerry-api-string-cb @} + */ -jerry_value_t -jerry_get_dataview_buffer (const jerry_value_t dataview, jerry_length_t *byte_offset, jerry_length_t *byte_length); +/** + * jerry-api-string @} + */ /** - * TypedArray functions. + * \defgroup jerry-api-symbol Symbol + * @{ */ -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); -jerry_value_t jerry_get_array_from_container (jerry_value_t value, bool *is_key_value_p); -jerry_value_t jerry_container_operation (jerry_container_operation_t operation, - jerry_value_t container, - jerry_value_t *arguments, - uint32_t arguments_number); - -/** - * @} +/** + * \defgroup jerry-api-symbol-ctor Constructors + * @{ + */ +jerry_value_t jerry_symbol (jerry_well_known_symbol_t symbol); +jerry_value_t jerry_symbol_with_description (const jerry_value_t value); +/** + * jerry-api-symbol-ctor @} + */ + +/** + * \defgroup jerry-api-symbol-get Getters + * @{ + */ +jerry_value_t jerry_symbol_description (const jerry_value_t symbol); +jerry_value_t jerry_symbol_descriptive_string (const jerry_value_t symbol); +/** + * jerry-api-symbol-get @} + */ + +/** + * jerry-api-symbol @} + */ + +/** + * jerry-api-primitives @} + */ + +/** + * \defgroup jerry-api-objects Objects + * @{ + */ + +/* Type checking */ +jerry_object_type_t jerry_object_type (const jerry_value_t object); + +/* Getters */ +jerry_value_t jerry_object_proto (const jerry_value_t object); + +/* Operations */ +jerry_value_t jerry_object_set_proto (jerry_value_t object, const jerry_value_t proto); + +/** + * \defgroup jerry-api-object-props Properties + * @{ + */ + +/** + * \defgroup jerry-api-object-props-set Set + * @{ + */ +jerry_value_t jerry_object_set (jerry_value_t object, const jerry_value_t key, const jerry_value_t value); +jerry_value_t jerry_object_set_index (jerry_value_t object, uint32_t index, const jerry_value_t value); +jerry_value_t jerry_object_define_own_prop (jerry_value_t object, + const jerry_value_t key, + const jerry_property_descriptor_t *prop_desc_p); +bool jerry_object_set_internal (jerry_value_t object, const jerry_value_t key, const jerry_value_t value); +void jerry_object_set_native_ptr (jerry_value_t object, + const jerry_object_native_info_t *native_info_p, + void *native_pointer_p); +/** + * jerry-api-object-prop-set @} + */ + +/** + * \defgroup jerry-api-object-props-has Has + * @{ + */ +jerry_value_t jerry_object_has (const jerry_value_t object, const jerry_value_t key); +jerry_value_t jerry_object_has_own (const jerry_value_t object, const jerry_value_t key); +bool jerry_object_has_internal (const jerry_value_t object, const jerry_value_t key); +bool jerry_object_has_native_ptr (const jerry_value_t object, const jerry_object_native_info_t *native_info_p); +/** + * jerry-api-object-prop-has @} + */ + +/** + * \defgroup jerry-api-object-props-get Get + * @{ + */ +jerry_value_t jerry_object_get (const jerry_value_t object, const jerry_value_t key); +jerry_value_t jerry_object_get_index (const jerry_value_t object, uint32_t index); +jerry_value_t jerry_object_get_own_prop (const jerry_value_t object, + const jerry_value_t key, + jerry_property_descriptor_t *prop_desc_p); +jerry_value_t jerry_object_get_internal (const jerry_value_t object, const jerry_value_t key); +void *jerry_object_get_native_ptr (const jerry_value_t object, const jerry_object_native_info_t *native_info_p); + +jerry_value_t jerry_object_find_own (const jerry_value_t object, + const jerry_value_t key, + const jerry_value_t receiver, + bool *found_p); +/** + * jerry-api-object-props-get @} + */ + +/** + * \defgroup jerry-api-object-props-del Delete + * @{ + */ +bool jerry_object_delete (jerry_value_t object, const jerry_value_t key); +bool jerry_object_delete_index (jerry_value_t object, uint32_t index); +bool jerry_object_delete_internal (jerry_value_t object, const jerry_value_t key); +bool jerry_object_delete_native_ptr (jerry_value_t object, const jerry_object_native_info_t *native_info_p); +/** + * jerry-api-object-props-del @} + */ + +jerry_value_t jerry_object_keys (const jerry_value_t object); +jerry_value_t jerry_object_property_names (const jerry_value_t object, jerry_property_filter_t filter); +bool jerry_object_foreach (const jerry_value_t object, jerry_object_property_foreach_cb_t foreach_p, void *user_data_p); + +/** + * \defgroup jerry-api-object-prop-desc Property descriptors + * @{ + */ + +jerry_property_descriptor_t jerry_property_descriptor (void); +void jerry_property_descriptor_free (jerry_property_descriptor_t *prop_desc_p); + +jerry_value_t jerry_property_descriptor_to_object (const jerry_property_descriptor_t *src_prop_desc_p); +jerry_value_t jerry_property_descriptor_from_object (const jerry_value_t obj_value, + jerry_property_descriptor_t *out_prop_desc_p); +/** + * jerry-api-object-prop-desc @} + */ + +/** + * jerry-api-object-props @} + */ + +/** + * \defgroup jerry-api-object-native-ptr Native pointers + * @{ + */ +void jerry_native_ptr_init (void *native_pointer_p, const jerry_object_native_info_t *native_info_p); +void jerry_native_ptr_free (void *native_pointer_p, const jerry_object_native_info_t *native_info_p); +void jerry_native_ptr_set (jerry_value_t *reference_p, const jerry_value_t value); +/** + * jerry-api-object-native-ptr @} + */ + +/** + * \defgroup jerry-api-object-ctor General Object + * @{ + */ +jerry_value_t jerry_object (void); +/** + * jerry-api-object-ctor @} + */ + +/** + * \defgroup jerry-api-array Array + * @{ + */ + +/** + * \defgroup jerry-api-array-ctor Constructors + * @{ + */ +jerry_value_t jerry_array (jerry_length_t length); +/** + * jerry-api-array-ctor @} + */ + +/** + * \defgroup jerry-api-array-get Getters + * @{ + */ +jerry_length_t jerry_array_length (const jerry_value_t value); +/** + * jerry-api-array-get @} + */ + +/** + * jerry-api-array @} + */ + +/** + * \defgroup jerry-api-arraybuffer ArrayBuffer + * @{ + */ + +/** + * \defgroup jerry-api-arraybuffer-ctor Constructors + * @{ + */ +jerry_value_t jerry_arraybuffer (const jerry_length_t size); +jerry_value_t jerry_arraybuffer_external (uint8_t *buffer_p, jerry_length_t size, void *buffer_user_p); +/** + * jerry-api-arraybuffer-ctor @} + */ + +/** + * \defgroup jerry-api-arraybuffer-get Getters + * @{ + */ +jerry_size_t jerry_arraybuffer_size (const jerry_value_t value); +uint8_t *jerry_arraybuffer_data (const jerry_value_t value); +jerry_value_t jerry_arraybuffer_is_detachable (const jerry_value_t value); +jerry_value_t jerry_arraybuffer_detach (const jerry_value_t value); +bool jerry_arraybuffer_has_buffer (const jerry_value_t value); +/** + * jerry-api-arraybuffer-get @} + */ + +/** + * \defgroup jerry-api-arraybuffer-op Operations + * @{ + */ +jerry_size_t +jerry_arraybuffer_read (const jerry_value_t value, jerry_size_t offset, uint8_t *buffer_p, jerry_size_t buffer_size); +jerry_size_t +jerry_arraybuffer_write (jerry_value_t value, jerry_size_t offset, const uint8_t *buffer_p, jerry_size_t buffer_size); +void jerry_arraybuffer_heap_allocation_limit (jerry_size_t limit); +/** + * jerry-api-arraybuffer-op @} + */ + +/** + * \defgroup jerry-api-arraybuffer-cb Callbacks + * @{ + */ +void jerry_arraybuffer_allocator_cb (jerry_arraybuffer_allocate_cb_t allocate_callback, + jerry_arraybuffer_free_cb_t free_callback, + void *user_p); +/** + * jerry-api-arraybuffer-cb @} + */ + +/** + * jerry-api-arraybuffer @} + */ + +/** + * \defgroup jerry-api-sharedarraybuffer SharedArrayBuffer + * @{ + */ + +/* Constructors */ +jerry_value_t jerry_shared_arraybuffer (jerry_size_t size); +jerry_value_t jerry_shared_arraybuffer_external (uint8_t *buffer_p, jerry_size_t buffer_size, void *buffer_user_p); + +/** + * jerry-api-sharedarraybuffer @} + */ + +/** + * \defgroup jerry-api-dataview DataView + * @{ + */ + +/** + * \defgroup jerry-api-dataview-ctor Constructors + * @{ + */ +jerry_value_t jerry_dataview (const jerry_value_t value, jerry_size_t byte_offset, jerry_size_t byte_length); +/** + * jerry-api-dataview-ctr @} + */ + +/** + * \defgroup jerry-api-dataview-get Getters + * @{ + */ +jerry_value_t +jerry_dataview_buffer (const jerry_value_t dataview, jerry_size_t *byte_offset, jerry_size_t *byte_length); +/** + * jerry-api-dataview-get @} + */ + +/** + * jerry-api-dataview @} + */ + +/** + * \defgroup jerry-api-typedarray TypedArray + * @{ + */ + +/** + * \defgroup jerry-api-typedarray-ctor Constructors + * @{ + */ +jerry_value_t jerry_typedarray (jerry_typedarray_type_t type, jerry_length_t length); +jerry_value_t jerry_typedarray_with_buffer (jerry_typedarray_type_t type, const jerry_value_t arraybuffer); +jerry_value_t jerry_typedarray_with_buffer_span (jerry_typedarray_type_t type, + const jerry_value_t arraybuffer, + jerry_size_t byte_offset, + jerry_size_t byte_length); +/** + * jerry-api-typedarray-ctor @} + */ + +/** + * \defgroup jerry-api-typedarray-get Getters + * @{ + */ +jerry_typedarray_type_t jerry_typedarray_type (const jerry_value_t value); +jerry_length_t jerry_typedarray_length (const jerry_value_t value); +jerry_value_t jerry_typedarray_buffer (const jerry_value_t value, jerry_size_t *byte_offset, jerry_size_t *byte_length); +/** + * jerry-api-typedarray-get @} + */ + +/** + * jerry-api-typedarray @} + */ + +/** + * \defgroup jerry-api-iterator Iterator + * @{ + */ + +jerry_iterator_type_t jerry_iterator_type (const jerry_value_t value); + +/** + * jerry-api-iterator @} + */ + +/** + * \defgroup jerry-api-function Function + * @{ + */ + +/** + * \defgroup jerry-api-function-ctor Constructors + * @{ + */ +jerry_value_t jerry_function_external (jerry_external_handler_t handler); +/** + * jerry-api-function-ctor @} + */ + +/** + * \defgroup jerry-api-function-get Getters + * @{ + */ +jerry_function_type_t jerry_function_type (const jerry_value_t value); +bool jerry_function_is_dynamic (const jerry_value_t value); +/** + * jerry-api-function-get @} + */ + +/** + * \defgroup jerry-api-function-op Operations + * @{ + */ +jerry_value_t jerry_call (const jerry_value_t function, + const jerry_value_t this_value, + const jerry_value_t args_p[], + jerry_size_t args_count); +jerry_value_t jerry_construct (const jerry_value_t function, const jerry_value_t args_p[], jerry_size_t args_count); +/** + * jerry-api-function-op @} + */ + +/** + * jerry-api-function @} + */ + +/** + * \defgroup jerry-api-proxy Proxy + * @{ + */ + +/** + * \defgroup jerry-api-proxy-ctor Constructors + * @{ + */ +jerry_value_t jerry_proxy (const jerry_value_t target, const jerry_value_t handler); +jerry_value_t jerry_proxy_custom (const jerry_value_t target, const jerry_value_t handler, uint32_t flags); +/** + * jerry-api-function-proxy-ctor @} + */ + +/** + * \defgroup jerry-api-proxy-get Getters + * @{ + */ +jerry_value_t jerry_proxy_target (const jerry_value_t value); +jerry_value_t jerry_proxy_handler (const jerry_value_t value); +/** + * jerry-api-function-proxy-get @} + */ + +/** + * jerry-api-proxy @} + */ + +/** + * \defgroup jerry-api-promise Promise + * @{ + */ + +/** + * \defgroup jerry-api-promise-ctor Constructors + * @{ + */ +jerry_value_t jerry_promise (void); +/** + * jerry-api-promise-ctor @} + */ + +/** + * \defgroup jerry-api-promise-get Getters + * @{ + */ +jerry_value_t jerry_promise_result (const jerry_value_t promise); +jerry_promise_state_t jerry_promise_state (const jerry_value_t promise); +/** + * jerry-api-promise-get @} + */ + +/** + * \defgroup jerry-api-promise-op Operations + * @{ + */ +jerry_value_t jerry_promise_resolve (jerry_value_t promise, const jerry_value_t argument); +jerry_value_t jerry_promise_reject (jerry_value_t promise, const jerry_value_t argument); +/** + * jerry-api-promise-op @} + */ + +/** + * \defgroup jerry-api-promise-cb Callbacks + * @{ + */ +void jerry_promise_event_cb (jerry_promise_event_filter_t filters, jerry_promise_event_cb_t callback, void *user_p); +/** + * jerry-api-promise-cb @} + */ + +/** + * jerry-api-promise @} + */ + +/** + * \defgroup jerry-api-container Map, Set, WeakMap, WeakSet + * @{ + */ + +/** + * \defgroup jerry-api-container-ctor Constructors + * @{ + */ +jerry_value_t jerry_container (jerry_container_type_t container_type, + const jerry_value_t *arguments_p, + jerry_length_t argument_count); +/** + * jerry-api-promise-ctor @} + */ + +/** + * \defgroup jerry-api-container-get Getters + * @{ + */ +jerry_container_type_t jerry_container_type (const jerry_value_t value); +/** + * jerry-api-container-get @} + */ + +/** + * \defgroup jerry-api-container-op Operations + * @{ + */ +jerry_value_t jerry_container_to_array (const jerry_value_t value, bool *is_key_value_p); +jerry_value_t jerry_container_op (jerry_container_op_t operation, + jerry_value_t container, + const jerry_value_t *arguments, + uint32_t argument_count); +/** + * jerry-api-container-op @} + */ + +/** + * jerry-api-container @} + */ + +/** + * \defgroup jerry-api-regexp RegExp + * @{ + */ + +/** + * \defgroup jerry-api-regexp-ctor Constructors + * @{ + */ +jerry_value_t jerry_regexp (const jerry_value_t pattern, uint16_t flags); +jerry_value_t jerry_regexp_sz (const char *pattern, uint16_t flags); +/** + * jerry-api-regexp-ctor @} + */ + +/** + * jerry-api-regexp @} + */ + +/** + * \defgroup jerry-api-error Error + * @{ + */ + +/** + * \defgroup jerry-api-error-ctor Constructors + * @{ + */ +jerry_value_t jerry_error (jerry_error_t type, const jerry_value_t message); +jerry_value_t jerry_error_sz (jerry_error_t type, const char *message_p); +/** + * jerry-api-error-ctor @} + */ + +/** + * \defgroup jerry-api-error-get Getters + * @{ + */ +jerry_error_t jerry_error_type (jerry_value_t value); +/** + * jerry-api-error-get @} + */ + +/** + * \defgroup jerry-api-error-cb Callbacks + * @{ + */ +void jerry_error_created_cb (jerry_error_object_created_cb_t callback, void *user_p); +/** + * jerry-api-error-cb @} + */ + +/** + * jerry-api-error @} + */ + +/** + * jerry-api-objects @} + */ + +/** + * \defgroup jerry-api-json JSON + * @{ + */ + +/* Operations */ +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); + +/** + * jerry-api-json @} + */ + +/** + * \defgroup jerry-api-module Modules + * @{ + */ + +/** + * \defgroup jerry-api-module-get Getters + * @{ + */ +jerry_module_state_t jerry_module_state (const jerry_value_t module); +size_t jerry_module_request_count (const jerry_value_t module); +jerry_value_t jerry_module_request (const jerry_value_t module, size_t request_index); +jerry_value_t jerry_module_namespace (const jerry_value_t module); +/** + * jerry-api-module-get @} + */ + +/** + * \defgroup jerry-api-module-op Operations + * @{ + */ +jerry_value_t jerry_module_link (const jerry_value_t module, jerry_module_resolve_cb_t callback, void *user_p); +jerry_value_t jerry_module_evaluate (const jerry_value_t module); +/** + * jerry-api-module-op @} + */ + +/** + * \defgroup jerry-api-module-native Native modules + * @{ + */ +jerry_value_t jerry_native_module (jerry_native_module_evaluate_cb_t callback, + const jerry_value_t *const exports_p, + size_t export_count); +jerry_value_t jerry_native_module_get (const jerry_value_t native_module, const jerry_value_t export_name); +jerry_value_t +jerry_native_module_set (const jerry_value_t native_module, const jerry_value_t export_name, const jerry_value_t value); +/** + * jerry-api-module-native @} + */ + +/** + * \defgroup jerry-api-module-cb Callbacks + * @{ + */ +void jerry_module_state_changed_cb (jerry_module_state_changed_cb_t callback, void *user_p); +void jerry_module_import_meta_cb (jerry_module_import_meta_cb_t callback, void *user_p); +void jerry_module_import_cb (jerry_module_import_cb_t callback, void *user_p); +/** + * jerry-api-module-cb @} + */ + +/** + * jerry-api-module @} + */ + +/** + * \defgroup jerry-api-realm Realms + * @{ + */ + +/** + * \defgroup jerry-api-realm-ctor Constructors + * @{ + */ +jerry_value_t jerry_realm (void); +/** + * jerry-api-realm-ctor @} + */ + +/** + * \defgroup jerry-api-realm-get Getters + * @{ + */ +jerry_value_t jerry_realm_this (jerry_value_t realm); +/** + * jerry-api-realm-ctor @} + */ + +/** + * \defgroup jerry-api-realm-op Operation + * @{ + */ +jerry_value_t jerry_realm_set_this (jerry_value_t realm, jerry_value_t this_value); +/** + * jerry-api-realm-op @} + */ + +/** + * jerry-api-realm @} + */ + +/** + * jerry-api @} */ JERRY_C_API_END diff --git a/jerry-core/include/jerryscript-debugger.h b/jerry-core/include/jerryscript-debugger.h index cf22f4cb46..ea128cf28a 100644 --- a/jerry-core/include/jerryscript-debugger.h +++ b/jerry-core/include/jerryscript-debugger.h @@ -47,8 +47,8 @@ typedef enum * * @return this value is passed back by jerry_debugger_wait_and_run_client_source */ -typedef jerry_value_t (*jerry_debugger_wait_for_source_callback_t) (const jerry_char_t *resource_name_p, - size_t resource_name_size, +typedef jerry_value_t (*jerry_debugger_wait_for_source_callback_t) (const jerry_char_t *source_name_p, + size_t source_name_size, const jerry_char_t *source_p, size_t source_size, void *user_p); diff --git a/jerry-core/include/jerryscript-snapshot.h b/jerry-core/include/jerryscript-snapshot.h index 95e96b7345..93ad9579b8 100644 --- a/jerry-core/include/jerryscript-snapshot.h +++ b/jerry-core/include/jerryscript-snapshot.h @@ -45,7 +45,7 @@ typedef enum JERRY_SNAPSHOT_EXEC_COPY_DATA = (1u << 0), /**< copy snashot data */ JERRY_SNAPSHOT_EXEC_ALLOW_STATIC = (1u << 1), /**< static snapshots allowed */ JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION = (1u << 2), /**< load snapshot as function instead of executing it */ - JERRY_SNAPSHOT_EXEC_HAS_RESOURCE = (1u << 3), /**< resource_name field is valid + JERRY_SNAPSHOT_EXEC_HAS_RESOURCE = (1u << 3), /**< source_name field is valid * in jerry_exec_snapshot_option_values_t */ JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE = (1u << 4), /**< user_value field is valid * in jerry_exec_snapshot_option_values_t */ @@ -56,9 +56,9 @@ typedef enum */ typedef struct { - jerry_value_t resource_name; /**< resource name string (usually a file name) - * if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts - * Note: non-string values are ignored */ + jerry_value_t source_name; /**< resource name string (usually a file name) + * if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts + * Note: non-string values are ignored */ jerry_value_t user_value; /**< user value assigned to all functions created by this script including * eval calls executed by the script if JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE * is set in exec_snapshot_opts */ diff --git a/jerry-core/include/jerryscript-types.h b/jerry-core/include/jerryscript-types.h index 9d131479ce..ec83961f56 100644 --- a/jerry-core/include/jerryscript-types.h +++ b/jerry-core/include/jerryscript-types.h @@ -24,25 +24,10 @@ JERRY_C_API_BEGIN -/** \addtogroup jerry Jerry engine interface +/** \addtogroup jerry-api-types JerryScript public API types * @{ */ -/** - * Major version of JerryScript API. - */ -#define JERRY_API_MAJOR_VERSION 3 - -/** - * Minor version of JerryScript API. - */ -#define JERRY_API_MINOR_VERSION 0 - -/** - * Patch version of JerryScript API. - */ -#define JERRY_API_PATCH_VERSION 0 - /** * JerryScript init flags. */ @@ -81,7 +66,7 @@ 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_HEAP_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 */ @@ -167,7 +152,7 @@ typedef enum JERRY_PARSE_MODULE = (1 << 1), /**< parse source as an ECMAScript module */ JERRY_PARSE_HAS_ARGUMENT_LIST = (1 << 2), /**< argument_list field is valid, * this also means that function parsing will be done */ - JERRY_PARSE_HAS_RESOURCE = (1 << 3), /**< resource_name field is valid */ + JERRY_PARSE_HAS_SOURCE_NAME = (1 << 3), /**< source_name field is valid */ JERRY_PARSE_HAS_START = (1 << 4), /**< start_line and start_column fields are valid */ JERRY_PARSE_HAS_USER_VALUE = (1 << 5), /**< user_value field is valid */ } jerry_parse_option_enable_feature_t; @@ -180,9 +165,9 @@ typedef struct uint32_t options; /**< combination of jerry_parse_option_enable_feature_t values */ jerry_value_t argument_list; /**< function argument list if JERRY_PARSE_HAS_ARGUMENT_LIST is set in options * Note: must be string value */ - jerry_value_t resource_name; /**< resource name string (usually a file name) - * if JERRY_PARSE_HAS_RESOURCE is set in options - * Note: must be string value */ + jerry_value_t source_name; /**< source name string (usually a file name) + * if JERRY_PARSE_HAS_SOURCE_NAME is set in options + * Note: must be string value */ uint32_t start_line; /**< start line of the source code if JERRY_PARSE_HAS_START is set in options */ uint32_t start_column; /**< start column of the source code if JERRY_PARSE_HAS_START is set in options */ jerry_value_t user_value; /**< user value assigned to all functions created by this script including eval @@ -245,6 +230,15 @@ typedef enum * integer index property keys as numbers. */ } jerry_property_filter_t; +/** + * String encoding. + */ +typedef enum +{ + JERRY_ENCODING_CESU8, /**< cesu-8 encoding */ + JERRY_ENCODING_UTF8, /**< utf-8 encoding */ +} jerry_encoding_t; + /** * Description of JerryScript heap memory stats. * It is for memory profiling. @@ -278,7 +272,7 @@ typedef jerry_value_t (*jerry_external_handler_t) (const jerry_call_info_t *call /** * Native free callback of generic value types. */ -typedef void (*jerry_value_free_callback_t) (void *native_p); +typedef void (*jerry_value_free_cb_t) (void *native_p); /** * Forward definition of jerry_object_native_info_t. @@ -288,59 +282,63 @@ struct jerry_object_native_info_t; /** * Native free callback of an object. */ -typedef void (*jerry_object_native_free_callback_t) (void *native_p, struct jerry_object_native_info_t *info_p); +typedef void (*jerry_object_native_free_cb_t) (void *native_p, struct jerry_object_native_info_t *info_p); /** * Free callback for external strings. */ -typedef void (*jerry_external_string_free_callback_t) (jerry_char_t *string_p, jerry_size_t string_size, void *user_p); +typedef void (*jerry_external_string_free_cb_t) (jerry_char_t *string_p, jerry_size_t string_size, void *user_p); /** * Decorator callback for Error objects. The decorator can create * or update any properties of the newly created Error object. */ -typedef void (*jerry_error_object_created_callback_t) (const jerry_value_t error_object, void *user_p); +typedef void (*jerry_error_object_created_cb_t) (const jerry_value_t error_object, void *user_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). + * is thrown by the engine as an exception. * * 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); +typedef jerry_value_t (*jerry_halt_cb_t) (void *user_p); /** - * Callback function which is called when an error is thrown in an ECMAScript code. - * The callback should not change the error_value. The callback is not called again + * Callback function which is called when an exception is thrown in an ECMAScript code. + * The callback should not change the exception_value. The callback is not called again * until the value is caught. * - * Note: the engine considers errors thrown by external functions as never caught. + * Note: the engine considers exceptions thrown by external functions as never caught. + */ +typedef void (*jerry_throw_cb_t) (const jerry_value_t exception_value, void *user_p); + +/** + * Function type applied each byte of a string */ -typedef void (*jerry_vm_throw_callback_t) (const jerry_value_t error_value, void *user_p); +typedef void (*jerry_string_iterate_cb_t) (uint8_t byte); /** * 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); +typedef bool (*jerry_object_property_foreach_cb_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); +typedef bool (*jerry_foreach_live_object_cb_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); +typedef bool (*jerry_foreach_live_object_with_info_cb_t) (const jerry_value_t object, + void *object_data_p, + void *user_data_p); /** * User context item manager @@ -349,7 +347,7 @@ 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. + * first time jerry_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. @@ -382,7 +380,7 @@ typedef struct /** * 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. + * returned from the jerry_context_data () API. */ size_t bytes_needed; } jerry_context_data_manager_t; @@ -390,14 +388,14 @@ typedef struct /** * Function type for allocating buffer for JerryScript context. */ -typedef void *(*jerry_context_alloc_t) (size_t size, void *cb_data_p); +typedef void *(*jerry_context_alloc_cb_t) (size_t size, void *cb_data_p); /** * Type information of a native pointer. */ typedef struct jerry_object_native_info_t { - jerry_object_native_free_callback_t free_cb; /**< the free callback of the native pointer */ + jerry_object_native_free_cb_t free_cb; /**< the free callback of the native pointer */ uint16_t number_of_references; /**< the number of value references which are marked by the garbage collector */ uint16_t offset_of_references; /**< byte offset indicating the start offset of value * references in the user allocated buffer */ @@ -425,44 +423,44 @@ typedef enum JERRY_BIN_OP_MUL, /**< multiplication operator (*) */ JERRY_BIN_OP_DIV, /**< division operator (/) */ JERRY_BIN_OP_REM, /**< remainder operator (%) */ -} jerry_binary_operation_t; +} jerry_binary_op_t; /** * Backtrace related types. */ /** - * List of backtrace frame types returned by jerry_backtrace_get_frame_type. + * List of backtrace frame types returned by jerry_frame_type. */ typedef enum { JERRY_BACKTRACE_FRAME_JS, /**< indicates that the frame is created for a JavaScript function/method */ -} jerry_backtrace_frame_types_t; +} jerry_frame_type_t; /** - * Location info retrieved by jerry_backtrace_get_location. + * Location info retrieved by jerry_frame_location. */ typedef struct { - jerry_value_t resource_name; /**< resource name */ + jerry_value_t source_name; /**< resource name */ jerry_size_t line; /**< line index */ jerry_size_t column; /**< column index */ -} jerry_backtrace_location_t; +} jerry_frame_location_t; /** - * Internal data structure for jerry_backtrace_frame_t definition. + * Internal data structure for jerry_frame_t definition. */ -struct jerry_backtrace_frame_internal_t; +struct jerry_frame_internal_t; /** - * Backtrace frame data passed to the jerry_backtrace_callback_t handler. + * Backtrace frame data passed to the jerry_backtrace_cb_t handler. */ -typedef struct jerry_backtrace_frame_internal_t jerry_backtrace_frame_t; +typedef struct jerry_frame_internal_t jerry_frame_t; /** - * Callback function which is called by jerry_backtrace_capture for each stack frame. + * Callback function which is called by jerry_backtrace for each stack frame. */ -typedef bool (*jerry_backtrace_callback_t) (jerry_backtrace_frame_t *frame_p, void *user_p); +typedef bool (*jerry_backtrace_cb_t) (jerry_frame_t *frame_p, void *user_p); /** * Detailed value type related types. @@ -481,7 +479,7 @@ typedef enum JERRY_TYPE_STRING, /**< string type */ JERRY_TYPE_OBJECT, /**< object type */ JERRY_TYPE_FUNCTION, /**< function type */ - JERRY_TYPE_ERROR, /**< error/abort type */ + JERRY_TYPE_EXCEPTION, /**< exception/abort type */ JERRY_TYPE_SYMBOL, /**< symbol type */ JERRY_TYPE_BIGINT, /**< bigint type */ } jerry_type_t; @@ -500,9 +498,9 @@ typedef enum JERRY_OBJECT_TYPE_MODULE, /**< Module object (see jerry_parse) */ JERRY_OBJECT_TYPE_PROMISE, /**< Promise object */ JERRY_OBJECT_TYPE_DATAVIEW, /**< Dataview 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_FUNCTION, /**< Function object (see jerry_function_type) */ + JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_typedarray_type) */ + JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_type) */ JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */ JERRY_OBJECT_TYPE_ERROR, /**< Error object */ JERRY_OBJECT_TYPE_ARRAYBUFFER, /**< Array buffer object */ @@ -554,7 +552,7 @@ typedef enum */ typedef enum { - JERRY_MODULE_STATE_INVALID = 0, /**< return value for jerry_module_get_state when its argument is not a module */ + JERRY_MODULE_STATE_INVALID = 0, /**< return value for jerry_module_state when its argument is not a module */ JERRY_MODULE_STATE_UNLINKED = 1, /**< module is currently unlinked */ JERRY_MODULE_STATE_LINKING = 2, /**< module is currently being linked */ JERRY_MODULE_STATE_LINKED = 3, /**< module has been linked (its dependencies has been resolved) */ @@ -566,36 +564,36 @@ typedef enum /** * Callback which is called by jerry_module_link to get the referenced module. */ -typedef jerry_value_t (*jerry_module_resolve_callback_t) (const jerry_value_t specifier, - const jerry_value_t referrer, - void *user_p); +typedef jerry_value_t (*jerry_module_resolve_cb_t) (const jerry_value_t specifier, + const jerry_value_t referrer, + void *user_p); /** * Callback which is called when an import is resolved dynamically to get the referenced module. */ -typedef jerry_value_t (*jerry_module_import_callback_t) (const jerry_value_t specifier, - const jerry_value_t user_value, - void *user_p); +typedef jerry_value_t (*jerry_module_import_cb_t) (const jerry_value_t specifier, + const jerry_value_t user_value, + void *user_p); /** * Callback which is called after the module enters into linked, evaluated or error state. */ -typedef void (*jerry_module_state_changed_callback_t) (jerry_module_state_t new_state, - const jerry_value_t module, - const jerry_value_t value, - void *user_p); +typedef void (*jerry_module_state_changed_cb_t) (jerry_module_state_t new_state, + const jerry_value_t module, + const jerry_value_t value, + void *user_p); /** * Callback which is called when an import.meta expression of a module is evaluated the first time. */ -typedef void (*jerry_module_import_meta_callback_t) (const jerry_value_t module, - const jerry_value_t meta_object, - void *user_p); +typedef void (*jerry_module_import_meta_cb_t) (const jerry_value_t module, + const jerry_value_t meta_object, + void *user_p); /** * Callback which is called by jerry_module_evaluate to evaluate the native module. */ -typedef jerry_value_t (*jerry_native_module_evaluate_callback_t) (const jerry_value_t native_module); +typedef jerry_value_t (*jerry_native_module_evaluate_cb_t) (const jerry_value_t native_module); /** * Proxy related types. @@ -611,7 +609,7 @@ typedef enum * [[PreventExtensions]], [[GetOwnProperty]], * [[DefineOwnProperty]], [[HasProperty]], [[Get]], * [[Set]], [[Delete]] and [[OwnPropertyKeys]] */ -} jerry_proxy_object_options_t; +} jerry_proxy_custom_behavior_t; /** * Promise related types. @@ -629,7 +627,7 @@ typedef enum } jerry_promise_state_t; /** - * Event types for jerry_promise_callback_t callback function. + * Event types for jerry_promise_event_cb_t callback function. * The description of the 'object' and 'value' arguments are provided for each type. */ typedef enum @@ -680,7 +678,7 @@ typedef enum } jerry_promise_event_type_t; /** - * Filter types for jerry_promise_set_callback callback function. + * Filter types for jerry_promise_event_cb callback function. * The callback is only called for those events which are enabled by the filters. */ typedef enum @@ -712,7 +710,7 @@ typedef enum /** * Notification callback for tracking Promise and async function operations. */ -typedef void (*jerry_promise_callback_t) (jerry_promise_event_type_t event_type, +typedef void (*jerry_promise_event_cb_t) (jerry_promise_event_type_t event_type, const jerry_value_t object, const jerry_value_t value, void *user_p); @@ -788,7 +786,7 @@ typedef enum JERRY_CONTAINER_OP_DELETE, /**< Set/WeakSet/Map/WeakMap delete operation */ JERRY_CONTAINER_OP_SIZE, /**< Set/WeakSet/Map/WeakMap size operation */ JERRY_CONTAINER_OP_CLEAR, /**< Set/Map clear operation */ -} jerry_container_operation_t; +} jerry_container_op_t; /** * Miscellaneous types. @@ -833,19 +831,19 @@ typedef enum /** * Callback for allocating the backing store of array buffer or shared array buffer objects. */ -typedef uint8_t *(*jerry_arraybuffer_allocate_t) (jerry_arraybuffer_type_t buffer_type, - uint32_t buffer_size, - void **arraybuffer_user_p, - void *user_p); +typedef uint8_t *(*jerry_arraybuffer_allocate_cb_t) (jerry_arraybuffer_type_t buffer_type, + uint32_t buffer_size, + void **arraybuffer_user_p, + void *user_p); /** * Callback for freeing the backing store of array buffer or shared array buffer objects. */ -typedef void (*jerry_arraybuffer_free_t) (jerry_arraybuffer_type_t buffer_type, - uint8_t *buffer_p, - uint32_t buffer_size, - void *arraybuffer_user_p, - void *user_p); +typedef void (*jerry_arraybuffer_free_cb_t) (jerry_arraybuffer_type_t buffer_type, + uint8_t *buffer_p, + uint32_t buffer_size, + void *arraybuffer_user_p, + void *user_p); /** * @} diff --git a/jerry-core/include/jerryscript.h b/jerry-core/include/jerryscript.h index 041ac7ea37..fa6626a99b 100644 --- a/jerry-core/include/jerryscript.h +++ b/jerry-core/include/jerryscript.h @@ -16,6 +16,21 @@ #ifndef JERRYSCRIPT_H #define JERRYSCRIPT_H +/** + * Major version of JerryScript API. + */ +#define JERRY_API_MAJOR_VERSION 3 + +/** + * Minor version of JerryScript API. + */ +#define JERRY_API_MINOR_VERSION 0 + +/** + * Patch version of JerryScript API. + */ +#define JERRY_API_PATCH_VERSION 0 + #include "jerryscript-core.h" #include "jerryscript-debugger.h" #include "jerryscript-snapshot.h" diff --git a/jerry-core/jcontext/jcontext.h b/jerry-core/jcontext/jcontext.h index 4af719ac32..8fe5f80bd4 100644 --- a/jerry-core/jcontext/jcontext.h +++ b/jerry-core/jcontext/jcontext.h @@ -150,22 +150,22 @@ struct jerry_context_t #if JERRY_MODULE_SYSTEM ecma_module_t *module_current_p; /**< current module context */ - jerry_module_state_changed_callback_t module_state_changed_callback_p; /**< callback which is called after the - * state of a module is changed */ + jerry_module_state_changed_cb_t module_state_changed_callback_p; /**< callback which is called after the + * state of a module is changed */ void *module_state_changed_callback_user_p; /**< user pointer for module_state_changed_callback_p */ - jerry_module_import_meta_callback_t module_import_meta_callback_p; /**< callback which is called when an - * import.meta expression of a module - * is evaluated the first time */ + jerry_module_import_meta_cb_t module_import_meta_callback_p; /**< callback which is called when an + * import.meta expression of a module + * is evaluated the first time */ void *module_import_meta_callback_user_p; /**< user pointer for module_import_meta_callback_p */ - jerry_module_import_callback_t module_import_callback_p; /**< callback for dynamic module import */ + jerry_module_import_cb_t module_import_callback_p; /**< callback for dynamic module import */ void *module_import_callback_user_p; /**< user pointer for module_import_callback_p */ #endif /* JERRY_MODULE_SYSTEM */ vm_frame_ctx_t *vm_top_context_p; /**< top (current) interpreter context */ jerry_context_data_header_t *context_data_p; /**< linked list of user-provided context-specific pointers */ - jerry_external_string_free_callback_t external_string_free_callback_p; /**< free callback for external strings */ + jerry_external_string_free_cb_t external_string_free_callback_p; /**< free callback for external strings */ void *error_object_created_callback_user_p; /**< user pointer for error_object_update_callback_p */ - jerry_error_object_created_callback_t error_object_created_callback_p; /**< decorator callback for Error objects */ + jerry_error_object_created_cb_t error_object_created_callback_p; /**< decorator callback for Error objects */ size_t ecma_gc_objects_number; /**< number of currently allocated objects */ size_t ecma_gc_new_objects; /**< number of newly allocated objects since last GC session */ size_t jmem_heap_allocated_size; /**< size of allocated regions */ @@ -194,15 +194,15 @@ struct jerry_context_t #if JERRY_PROMISE_CALLBACK uint32_t promise_callback_filters; /**< reported event types for promise callback */ void *promise_callback_user_p; /**< user pointer for promise callback */ - jerry_promise_callback_t promise_callback; /**< user function for tracking Promise object operations */ + jerry_promise_event_cb_t promise_callback; /**< user function for tracking Promise object operations */ #endif /* JERRY_PROMISE_CALLBACK */ #endif /* JERRY_ESNEXT */ #if JERRY_BUILTIN_TYPEDARRAY uint32_t arraybuffer_compact_allocation_limit; /**< maximum size of compact allocation */ - jerry_arraybuffer_allocate_t arraybuffer_allocate_callback; /**< callback for allocating + jerry_arraybuffer_allocate_cb_t arraybuffer_allocate_callback; /**< callback for allocating * arraybuffer memory */ - jerry_arraybuffer_free_t arraybuffer_free_callback; /**< callback for freeing arraybuffer memory */ + jerry_arraybuffer_free_cb_t arraybuffer_free_callback; /**< callback for freeing arraybuffer memory */ void *arraybuffer_allocate_callback_user_p; /**< user pointer passed to arraybuffer_allocate_callback * and arraybuffer_free_callback functions */ #endif /* JERRY_BUILTIN_TYPEDARRAY */ @@ -217,7 +217,7 @@ struct jerry_context_t #if JERRY_VM_THROW void *vm_throw_callback_user_p; /**< user pointer for vm_throw_callback_p */ - jerry_vm_throw_callback_t vm_throw_callback_p; /**< callback for capturing throws */ + jerry_throw_cb_t vm_throw_callback_p; /**< callback for capturing throws */ #endif /* JERRY_VM_THROW */ #if (JERRY_STACK_LIMIT != 0) diff --git a/jerry-core/jrt/jrt.h b/jerry-core/jrt/jrt.h index ffd4bde382..5dbec73b80 100644 --- a/jerry-core/jrt/jrt.h +++ b/jerry-core/jrt/jrt.h @@ -211,10 +211,10 @@ void JERRY_ATTR_NORETURN jerry_fatal (jerry_fatal_code_t code); #define JERRY_BLOCK_TAIL_CALL_OPTIMIZATION() __asm__ __volatile__("") #else /* !defined(__clang__) && !defined(__GNUC__) */ /* On GCC 10.x this version also works. */ -#define JERRY_BLOCK_TAIL_CALL_OPTIMIZATION() \ - do \ - { \ - JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_AVAILABLE; \ +#define JERRY_BLOCK_TAIL_CALL_OPTIMIZATION() \ + do \ + { \ + JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_ENABLED; \ } while (0) #endif /* defined(__clang__) || defined (__GNUC__) */ diff --git a/jerry-core/lit/lit-strings.c b/jerry-core/lit/lit-strings.c index 2ccb414452..3ac97feca2 100644 --- a/jerry-core/lit/lit-strings.c +++ b/jerry-core/lit/lit-strings.c @@ -587,7 +587,7 @@ lit_utf8_decr (const lit_utf8_byte_t **buf_p) /**< [in,out] buffer with characte do { current_p--; - } while ((*(current_p) &LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER); + } while ((*current_p & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER); *buf_p = current_p; } /* lit_utf8_decr */ @@ -824,57 +824,51 @@ lit_code_point_to_utf8 (lit_code_point_t code_point, /**< code point */ /** * Convert cesu-8 string to an utf-8 string and put it into the buffer. - * It is the caller's responsibility to make sure that the string fits in the buffer. + * String will be truncated to fit the buffer. * * @return number of bytes copied to the buffer. */ lit_utf8_size_t -lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string, /**< cesu-8 string */ +lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string_p, /**< cesu-8 string */ lit_utf8_size_t cesu8_size, /**< size of cesu-8 string */ - lit_utf8_byte_t *utf8_string, /**< destination utf-8 buffer pointer - * (can be NULL if buffer_size == 0) */ + lit_utf8_byte_t *utf8_string_p, /**< destination utf-8 buffer pointer + * (can be NULL if buffer_size == 0) */ lit_utf8_size_t utf8_size) /**< size of utf-8 buffer */ { - const lit_utf8_byte_t *cesu8_pos = cesu8_string; - const lit_utf8_byte_t *cesu8_end_pos = cesu8_string + cesu8_size; + const lit_utf8_byte_t *cesu8_cursor_p = cesu8_string_p; + const lit_utf8_byte_t *cesu8_end_p = cesu8_string_p + cesu8_size; - lit_utf8_byte_t *utf8_pos = utf8_string; - lit_utf8_byte_t *utf8_end_pos = utf8_string + utf8_size; + lit_utf8_byte_t *utf8_cursor_p = utf8_string_p; + lit_utf8_byte_t *utf8_end_p = utf8_string_p + utf8_size; - lit_utf8_size_t size = 0; - - ecma_char_t prev_ch = 0; - lit_utf8_size_t prev_ch_size = 0; - - while (cesu8_pos < cesu8_end_pos) + while (cesu8_cursor_p < cesu8_end_p) { - ecma_char_t ch; - lit_utf8_size_t code_unit_size = lit_read_code_unit_from_cesu8 (cesu8_pos, &ch); + lit_code_point_t cp; + lit_utf8_size_t read_size = lit_read_code_point_from_cesu8 (cesu8_cursor_p, cesu8_end_p, &cp); + lit_utf8_size_t encoded_size = (cp >= LIT_UTF16_FIRST_SURROGATE_CODE_POINT) ? 4 : read_size; - if (lit_is_code_point_utf16_low_surrogate (ch) && lit_is_code_point_utf16_high_surrogate (prev_ch)) + if (utf8_cursor_p + encoded_size > utf8_end_p) { - JERRY_ASSERT (code_unit_size == prev_ch_size); - utf8_pos -= prev_ch_size; - lit_code_point_t code_point = lit_convert_surrogate_pair_to_code_point (prev_ch, ch); - lit_code_point_to_utf8 (code_point, utf8_pos); - size++; + break; + } + + if (cp >= LIT_UTF16_FIRST_SURROGATE_CODE_POINT) + { + lit_code_point_to_utf8 (cp, utf8_cursor_p); } else { - memcpy (utf8_pos, cesu8_pos, code_unit_size); - size += code_unit_size; + memcpy (utf8_cursor_p, cesu8_cursor_p, encoded_size); } - utf8_pos = utf8_string + size; - cesu8_pos += code_unit_size; - prev_ch = ch; - prev_ch_size = code_unit_size; + utf8_cursor_p += encoded_size; + cesu8_cursor_p += read_size; } - JERRY_ASSERT (cesu8_pos == cesu8_end_pos); - JERRY_ASSERT (utf8_pos <= utf8_end_pos); + JERRY_ASSERT (cesu8_cursor_p == cesu8_end_p); + JERRY_ASSERT (utf8_cursor_p <= utf8_end_p); - return size; + return (lit_utf8_byte_t) (utf8_cursor_p - utf8_string_p); } /* lit_convert_cesu8_string_to_utf8_string */ /** diff --git a/jerry-core/lit/lit-strings.h b/jerry-core/lit/lit-strings.h index 2905de5b5c..d00480e641 100644 --- a/jerry-core/lit/lit-strings.h +++ b/jerry-core/lit/lit-strings.h @@ -116,9 +116,9 @@ lit_utf8_size_t lit_get_unicode_char_size_by_utf8_first_byte (const lit_utf8_byt lit_utf8_size_t lit_code_unit_to_utf8 (ecma_char_t code_unit, lit_utf8_byte_t *buf_p); lit_utf8_size_t lit_code_point_to_utf8 (lit_code_point_t code_point, lit_utf8_byte_t *buf); lit_utf8_size_t lit_code_point_to_cesu8 (lit_code_point_t code_point, lit_utf8_byte_t *buf); -lit_utf8_size_t lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string, +lit_utf8_size_t lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string_p, lit_utf8_size_t cesu8_size, - lit_utf8_byte_t *utf8_string, + lit_utf8_byte_t *utf8_string_p, lit_utf8_size_t utf8_size); lit_code_point_t lit_convert_surrogate_pair_to_code_point (ecma_char_t high_surrogate, ecma_char_t low_surrogate); diff --git a/jerry-core/parser/js/byte-code.h b/jerry-core/parser/js/byte-code.h index 09b0a78c44..e8a66c63c3 100644 --- a/jerry-core/parser/js/byte-code.h +++ b/jerry-core/parser/js/byte-code.h @@ -925,7 +925,7 @@ typedef struct #endif /* JERRY_BUILTIN_REALMS */ uint32_t refs_and_type; /**< reference counter and type of the function */ #if JERRY_RESOURCE_NAME - ecma_value_t resource_name; /**< resource name */ + ecma_value_t source_name; /**< resource name */ #endif /* JERRY_RESOURCE_NAME */ #if JERRY_FUNCTION_TO_STRING ecma_value_t source_code; /**< source code */ diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index 2ba45777bc..9d90b19b68 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -1940,18 +1940,18 @@ parser_parse_source (void *source_p, /**< source code */ } #if JERRY_RESOURCE_NAME - ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); + ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON); - if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_RESOURCE)) + if (context.options_p != NULL && (context.options_p->options & JERRY_PARSE_HAS_SOURCE_NAME)) { - JERRY_ASSERT (ecma_is_value_string (context.options_p->resource_name)); + JERRY_ASSERT (ecma_is_value_string (context.options_p->source_name)); - ecma_ref_ecma_string (ecma_get_string_from_value (context.options_p->resource_name)); - resource_name = context.options_p->resource_name; + ecma_ref_ecma_string (ecma_get_string_from_value (context.options_p->source_name)); + source_name = context.options_p->source_name; } else if (context.global_status_flags & ECMA_PARSE_EVAL) { - resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL); + source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL); } #endif /* JERRY_RESOURCE_NAME */ @@ -2093,7 +2093,7 @@ parser_parse_source (void *source_p, /**< source code */ #endif /* JERRY_BUILTIN_REALMS */ #if JERRY_RESOURCE_NAME - context.script_p->resource_name = resource_name; + context.script_p->source_name = source_name; #endif /* JERRY_RESOURCE_NAME */ ECMA_SET_INTERNAL_VALUE_POINTER (context.script_value, context.script_p); @@ -2261,7 +2261,7 @@ parser_parse_source (void *source_p, /**< source code */ parser_cbc_stream_free (&context.byte_code); #if JERRY_RESOURCE_NAME - ecma_deref_ecma_string (ecma_get_string_from_value (context.script_p->resource_name)); + ecma_deref_ecma_string (ecma_get_string_from_value (context.script_p->source_name)); #endif /* JERRY_RESOURCE_NAME */ if (context.script_p != NULL) @@ -2346,7 +2346,7 @@ parser_parse_source (void *source_p, /**< source code */ ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX, "% [%:%:%]", err_str_val, - resource_name, + source_name, line_str_val, col_str_val); @@ -3130,7 +3130,7 @@ parser_parse_script (void *source_p, /**< source code */ JERRY_UNUSED (source_p); JERRY_UNUSED (source_size); JERRY_UNUSED (parse_opts); - JERRY_UNUSED (resource_name); + JERRY_UNUSED (source_name); ecma_raise_syntax_error (ECMA_ERR_MSG ("Source code parsing is disabled")); return NULL; diff --git a/jerry-core/vm/vm-defines.h b/jerry-core/vm/vm-defines.h index f93f485c73..0f93427f33 100644 --- a/jerry-core/vm/vm-defines.h +++ b/jerry-core/vm/vm-defines.h @@ -156,13 +156,13 @@ typedef struct } vm_executable_object_t; /** - * Real backtrace frame data passed to the jerry_backtrace_callback_t handler. + * Real backtrace frame data passed to the jerry_backtrace_cb_t handler. */ -struct jerry_backtrace_frame_internal_t +struct jerry_frame_internal_t { vm_frame_ctx_t *context_p; /**< context pointer */ uint8_t frame_type; /**< frame type */ - jerry_backtrace_location_t location; /**< location information */ + jerry_frame_location_t location; /**< location information */ ecma_value_t function; /**< function reference */ ecma_value_t this_binding; /**< this binding passed to the function */ }; diff --git a/jerry-core/vm/vm-utils.c b/jerry-core/vm/vm-utils.c index e9cbb275ea..1a75b14cf3 100644 --- a/jerry-core/vm/vm-utils.c +++ b/jerry-core/vm/vm-utils.c @@ -78,8 +78,8 @@ vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimite while (context_p != NULL) { const ecma_compiled_code_t *bytecode_header_p = context_p->shared_p->bytecode_header_p; - ecma_value_t resource_name = ecma_get_resource_name (bytecode_header_p); - ecma_string_t *str_p = ecma_get_string_from_value (resource_name); + ecma_value_t source_name = ecma_get_source_name (bytecode_header_p); + ecma_string_t *str_p = ecma_get_string_from_value (source_name); ecma_stringbuilder_t builder = ecma_stringbuilder_create (); if (ecma_string_is_empty (str_p)) @@ -94,7 +94,7 @@ vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimite if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_HAS_LINE_INFO) { - jerry_backtrace_location_t location; + jerry_frame_location_t location; ecma_line_info_get (ecma_compiled_code_get_line_info (bytecode_header_p), (uint32_t) (context_p->byte_code_p - context_p->byte_code_start_p), &location); diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index 409c8e2527..575aecc0fd 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -1124,9 +1124,9 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ { JERRY_CONTEXT (vm_exec_stop_counter) = 1; - if (ecma_is_value_error_reference (result)) + if (ecma_is_value_exception (result)) { - ecma_raise_error_from_error_reference (result); + ecma_throw_exception (result); } else { @@ -4707,7 +4707,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */ { JERRY_CONTEXT (status_flags) |= ECMA_STATUS_ERROR_THROWN; - jerry_vm_throw_callback_t vm_throw_callback_p = JERRY_CONTEXT (vm_throw_callback_p); + jerry_throw_cb_t vm_throw_callback_p = JERRY_CONTEXT (vm_throw_callback_p); if (vm_throw_callback_p != NULL) { diff --git a/jerry-ext/arg/arg-js-iterator-helper.c b/jerry-ext/arg/arg-js-iterator-helper.c index c6ef2a4dc3..07cd168d86 100644 --- a/jerry-ext/arg/arg-js-iterator-helper.c +++ b/jerry-ext/arg/arg-js-iterator-helper.c @@ -27,8 +27,7 @@ jerry_value_t jerryx_arg_js_iterator_pop (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */ { - return (js_arg_iter_p->js_arg_idx++ < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p++ - : jerry_create_undefined ()); + return (js_arg_iter_p->js_arg_idx++ < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p++ : jerry_undefined ()); } /* jerryx_arg_js_iterator_pop */ /** @@ -42,7 +41,7 @@ jerryx_arg_js_iterator_restore (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< th { if (js_arg_iter_p->js_arg_idx == 0) { - return jerry_create_undefined (); + return jerry_undefined (); } --js_arg_iter_p->js_arg_idx; @@ -63,7 +62,7 @@ jerryx_arg_js_iterator_restore (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< th jerry_value_t jerryx_arg_js_iterator_peek (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */ { - return (js_arg_iter_p->js_arg_idx < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p : jerry_create_undefined ()); + return (js_arg_iter_p->js_arg_idx < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p : jerry_undefined ()); } /* jerryx_arg_js_iterator_peek */ /** diff --git a/jerry-ext/arg/arg-transform-functions.c b/jerry-ext/arg/arg-transform-functions.c index 8ca7dd47ad..1a9898497d 100644 --- a/jerry-ext/arg/arg-transform-functions.c +++ b/jerry-ext/arg/arg-transform-functions.c @@ -56,12 +56,12 @@ jerryx_arg_transform_number_strict_common (jerryx_arg_js_iterator_t *js_arg_iter if (!jerry_value_is_number (js_arg)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a number."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It is not a number."); } - *number_p = jerry_get_number_value (js_arg); + *number_p = jerry_value_as_number (js_arg); - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_number_strict_common */ /** @@ -79,17 +79,17 @@ jerryx_arg_transform_number_common (jerryx_arg_js_iterator_t *js_arg_iter_p, /** jerry_value_t to_number = jerry_value_to_number (js_arg); - if (jerry_value_is_error (to_number)) + if (jerry_value_is_exception (to_number)) { - jerry_release_value (to_number); + jerry_value_free (to_number); - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It can not be converted to a number."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It can not be converted to a number."); } - *number_p = jerry_get_number_value (to_number); - jerry_release_value (to_number); + *number_p = jerry_value_as_number (to_number); + jerry_value_free (to_number); - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_number_common */ /** @@ -133,14 +133,14 @@ jerryx_arg_helper_process_double (double *d, /**< [in, out] the number to be pro { if (*d != *d) /* isnan (*d) triggers conversion warning on clang<9 */ { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "The number is NaN."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "The number is NaN."); } if (option.clamp == JERRYX_ARG_NO_CLAMP) { if (*d > max || *d < min) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "The number is out of range."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "The number is out of range."); } } else @@ -162,7 +162,7 @@ jerryx_arg_helper_process_double (double *d, /**< [in, out] the number to be pro *d = ceil (*d); } - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_helper_process_double */ /** @@ -174,18 +174,18 @@ jerryx_arg_helper_process_double (double *d, /**< [in, out] the number to be pro { \ double tmp = 0.0; \ jerry_value_t rv = jerryx_arg_transform_number##suffix##_common (js_arg_iter_p, &tmp); \ - if (jerry_value_is_error (rv)) \ + if (jerry_value_is_exception (rv)) \ { \ return rv; \ } \ - jerry_release_value (rv); \ + jerry_value_free (rv); \ union \ { \ jerryx_arg_int_option_t int_option; \ uintptr_t extra_info; \ } u = { .extra_info = c_arg_p->extra_info }; \ rv = jerryx_arg_helper_process_double (&tmp, min, max, u.int_option); \ - if (jerry_value_is_error (rv)) \ + if (jerry_value_is_exception (rv)) \ { \ return rv; \ } \ @@ -220,13 +220,13 @@ jerryx_arg_transform_boolean_strict (jerryx_arg_js_iterator_t *js_arg_iter_p, /* if (!jerry_value_is_boolean (js_arg)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a boolean."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It is not a boolean."); } bool *dest = c_arg_p->dest; *dest = jerry_value_is_true (js_arg); - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_boolean_strict */ /** @@ -246,7 +246,7 @@ jerryx_arg_transform_boolean (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< avai bool *dest = c_arg_p->dest; *dest = to_boolean; - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_boolean */ /** @@ -259,32 +259,22 @@ jerryx_arg_transform_boolean (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< avai static jerry_value_t jerryx_arg_string_to_buffer_common_routine (jerry_value_t js_arg, /**< JS arg */ const jerryx_arg_t *c_arg_p, /**< native arg */ - bool is_utf8) /**< whether it is UTF-8 string */ + jerry_encoding_t encoding) /**< string encoding */ { jerry_char_t *target_p = (jerry_char_t *) c_arg_p->dest; jerry_size_t target_buf_size = (jerry_size_t) c_arg_p->extra_info; - jerry_size_t size; - jerry_length_t len; - if (!is_utf8) - { - size = jerry_string_to_char_buffer (js_arg, target_p, target_buf_size); - len = jerry_get_string_length (js_arg); - } - else - { - size = jerry_string_to_utf8_char_buffer (js_arg, target_p, target_buf_size); - len = jerry_get_utf8_string_length (js_arg); - } + jerry_size_t size = jerry_string_size (js_arg, encoding); - if ((size == target_buf_size) || (size == 0 && len != 0)) + if (size > target_buf_size - 1) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Buffer size is not large enough."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "Buffer size is not large enough."); } + jerry_string_to_buffer (js_arg, target_p, target_buf_size, encoding); target_p[size] = '\0'; - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_string_to_buffer_common_routine */ /** @@ -296,16 +286,16 @@ jerryx_arg_string_to_buffer_common_routine (jerry_value_t js_arg, /**< JS arg */ static jerry_value_t jerryx_arg_transform_string_strict_common (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ const jerryx_arg_t *c_arg_p, /**< the native arg */ - bool is_utf8) /**< whether it is a UTF-8 string */ + jerry_encoding_t encoding) /**< string encoding */ { jerry_value_t js_arg = jerryx_arg_js_iterator_pop (js_arg_iter_p); if (!jerry_value_is_string (js_arg)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a string."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It is not a string."); } - return jerryx_arg_string_to_buffer_common_routine (js_arg, c_arg_p, is_utf8); + return jerryx_arg_string_to_buffer_common_routine (js_arg, c_arg_p, encoding); } /* jerryx_arg_transform_string_strict_common */ /** @@ -317,21 +307,21 @@ jerryx_arg_transform_string_strict_common (jerryx_arg_js_iterator_t *js_arg_iter static jerry_value_t jerryx_arg_transform_string_common (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ const jerryx_arg_t *c_arg_p, /**< the native arg */ - bool is_utf8) /**< whether it is a UTF-8 string */ + jerry_encoding_t encoding) /**< string encoding */ { jerry_value_t js_arg = jerryx_arg_js_iterator_pop (js_arg_iter_p); jerry_value_t to_string = jerry_value_to_string (js_arg); - if (jerry_value_is_error (to_string)) + if (jerry_value_is_exception (to_string)) { - jerry_release_value (to_string); + jerry_value_free (to_string); - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It can not be converted to a string."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It can not be converted to a string."); } - jerry_value_t ret = jerryx_arg_string_to_buffer_common_routine (to_string, c_arg_p, is_utf8); - jerry_release_value (to_string); + jerry_value_t ret = jerryx_arg_string_to_buffer_common_routine (to_string, c_arg_p, encoding); + jerry_value_free (to_string); return ret; } /* jerryx_arg_transform_string_common */ @@ -340,7 +330,7 @@ jerryx_arg_transform_string_common (jerryx_arg_js_iterator_t *js_arg_iter_p, /** * Transform a JS argument to a cesu8 char array. Type coercion is not allowed. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry undefined: the transformer passes, * jerry error: the transformer fails. @@ -349,14 +339,14 @@ jerry_value_t jerryx_arg_transform_string_strict (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ const jerryx_arg_t *c_arg_p) /**< the native arg */ { - return jerryx_arg_transform_string_strict_common (js_arg_iter_p, c_arg_p, false); + return jerryx_arg_transform_string_strict_common (js_arg_iter_p, c_arg_p, JERRY_ENCODING_CESU8); } /* jerryx_arg_transform_string_strict */ /** * Transform a JS argument to a utf8 char array. Type coercion is not allowed. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry undefined: the transformer passes, * jerry error: the transformer fails. @@ -365,14 +355,14 @@ jerry_value_t jerryx_arg_transform_utf8_string_strict (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ const jerryx_arg_t *c_arg_p) /**< the native arg */ { - return jerryx_arg_transform_string_strict_common (js_arg_iter_p, c_arg_p, true); + return jerryx_arg_transform_string_strict_common (js_arg_iter_p, c_arg_p, JERRY_ENCODING_UTF8); } /* jerryx_arg_transform_utf8_string_strict */ /** * Transform a JS argument to a cesu8 char array. Type coercion is allowed. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry undefined: the transformer passes, * jerry error: the transformer fails. @@ -381,14 +371,14 @@ jerry_value_t jerryx_arg_transform_string (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ const jerryx_arg_t *c_arg_p) /**< the native arg */ { - return jerryx_arg_transform_string_common (js_arg_iter_p, c_arg_p, false); + return jerryx_arg_transform_string_common (js_arg_iter_p, c_arg_p, JERRY_ENCODING_CESU8); } /* jerryx_arg_transform_string */ /** * Transform a JS argument to a utf8 char array. Type coercion is allowed. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry undefined: the transformer passes, * jerry error: the transformer fails. @@ -397,7 +387,7 @@ jerry_value_t jerryx_arg_transform_utf8_string (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS args */ const jerryx_arg_t *c_arg_p) /**< the native arg */ { - return jerryx_arg_transform_string_common (js_arg_iter_p, c_arg_p, true); + return jerryx_arg_transform_string_common (js_arg_iter_p, c_arg_p, JERRY_ENCODING_UTF8); } /* jerryx_arg_transform_utf8_string */ /** @@ -414,13 +404,13 @@ jerryx_arg_transform_function (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< ava if (!jerry_value_is_function (js_arg)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a function."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It is not a function."); } jerry_value_t *func_p = c_arg_p->dest; - *func_p = jerry_acquire_value (js_arg); + *func_p = jerry_value_copy (js_arg); - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_function */ /** @@ -438,21 +428,20 @@ jerryx_arg_transform_native_pointer (jerryx_arg_js_iterator_t *js_arg_iter_p, /* if (!jerry_value_is_object (js_arg)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not an object."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It is not an object."); } const jerry_object_native_info_t *expected_info_p; expected_info_p = (const jerry_object_native_info_t *) c_arg_p->extra_info; void **ptr_p = (void **) c_arg_p->dest; - bool is_ok = jerry_get_object_native_pointer (js_arg, ptr_p, expected_info_p); + *ptr_p = jerry_object_get_native_ptr (js_arg, expected_info_p); - if (!is_ok) + if (*ptr_p == NULL) { - return jerry_create_error (JERRY_ERROR_TYPE, - (jerry_char_t *) "The object has no native pointer or type does not match."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "The object has no native pointer or type does not match."); } - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_native_pointer */ /** @@ -543,5 +532,5 @@ jerryx_arg_transform_ignore (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< avail (void) js_arg_iter_p; /* unused */ (void) c_arg_p; /* unused */ - return jerry_create_undefined (); + return jerry_undefined (); } /* jerryx_arg_transform_ignore */ diff --git a/jerry-ext/arg/arg.c b/jerry-ext/arg/arg.c index 018c335ae6..87638b1d3a 100644 --- a/jerry-ext/arg/arg.c +++ b/jerry-ext/arg/arg.c @@ -35,11 +35,11 @@ jerryx_arg_transform_args (const jerry_value_t *js_arg_p, /**< points to the arr const jerryx_arg_t *c_arg_p, /**< points to the array of validation/transformation steps */ jerry_length_t c_arg_cnt) /**< the count of the `c_arg_p` array */ { - jerry_value_t ret = jerry_create_undefined (); + jerry_value_t ret = jerry_undefined (); jerryx_arg_js_iterator_t iterator = { .js_arg_p = js_arg_p, .js_arg_cnt = js_arg_cnt, .js_arg_idx = 0 }; - for (; c_arg_cnt != 0 && !jerry_value_is_error (ret); c_arg_cnt--, c_arg_p++) + for (; c_arg_cnt != 0 && !jerry_value_is_exception (ret); c_arg_cnt--, c_arg_p++) { ret = c_arg_p->func (&iterator, c_arg_p); } @@ -66,18 +66,18 @@ jerryx_arg_transform_this_and_args (const jerry_value_t this_val, /**< the this_ { if (c_arg_cnt == 0) { - return jerry_create_undefined (); + return jerry_undefined (); } jerryx_arg_js_iterator_t iterator = { .js_arg_p = &this_val, .js_arg_cnt = 1, .js_arg_idx = 0 }; jerry_value_t ret = c_arg_p->func (&iterator, c_arg_p); - if (jerry_value_is_error (ret)) + if (jerry_value_is_exception (ret)) { - jerry_release_value (ret); + jerry_value_free (ret); - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "'this' validation failed."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "'this' validation failed."); } return jerryx_arg_transform_args (js_arg_p, js_arg_cnt, c_arg_p + 1, c_arg_cnt - 1); @@ -99,22 +99,22 @@ jerryx_arg_transform_object_properties (const jerry_value_t obj_val, /**< the JS { if (!jerry_value_is_object (obj_val)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Not an object."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "Not an object."); } JERRY_VLA (jerry_value_t, prop, name_cnt); for (jerry_length_t i = 0; i < name_cnt; i++, name_p++) { - const jerry_value_t name_str = jerry_create_string (*name_p); - prop[i] = jerry_get_property (obj_val, name_str); - jerry_release_value (name_str); + const jerry_value_t name_str = jerry_string_sz ((char *) (*name_p)); + prop[i] = jerry_object_get (obj_val, name_str); + jerry_value_free (name_str); - if (jerry_value_is_error (prop[i])) + if (jerry_value_is_exception (prop[i])) { for (jerry_length_t j = 0; j < i; j++) { - jerry_release_value (prop[j]); + jerry_value_free (prop[j]); } return prop[i]; @@ -125,7 +125,7 @@ jerryx_arg_transform_object_properties (const jerry_value_t obj_val, /**< the JS for (jerry_length_t i = 0; i < name_cnt; i++) { - jerry_release_value (prop[i]); + jerry_value_free (prop[i]); } return ret; @@ -144,20 +144,20 @@ jerryx_arg_transform_array (const jerry_value_t array_val, /**< points to the JS { if (!jerry_value_is_array (array_val)) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Not an array."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "Not an array."); } JERRY_VLA (jerry_value_t, arr, c_arg_cnt); for (jerry_length_t i = 0; i < c_arg_cnt; i++) { - arr[i] = jerry_get_property_by_index (array_val, i); + arr[i] = jerry_object_get_index (array_val, i); - if (jerry_value_is_error (arr[i])) + if (jerry_value_is_exception (arr[i])) { for (jerry_length_t j = 0; j < i; j++) { - jerry_release_value (arr[j]); + jerry_value_free (arr[j]); } return arr[i]; @@ -168,7 +168,7 @@ jerryx_arg_transform_array (const jerry_value_t array_val, /**< points to the JS for (jerry_length_t i = 0; i < c_arg_cnt; i++) { - jerry_release_value (arr[i]); + jerry_value_free (arr[i]); } return ret; diff --git a/jerry-ext/debugger/debugger-rp.c b/jerry-ext/debugger/debugger-rp.c index 1f84a5a578..733b81b93d 100644 --- a/jerry-ext/debugger/debugger-rp.c +++ b/jerry-ext/debugger/debugger-rp.c @@ -140,7 +140,7 @@ jerryx_debugger_rp_receive (jerry_debugger_transport_header_t *header_p, /**< he bool jerryx_debugger_rp_create (void) { - const size_t interface_size = sizeof (jerry_debugger_transport_header_t); + const jerry_size_t interface_size = sizeof (jerry_debugger_transport_header_t); jerry_debugger_transport_header_t *header_p; header_p = (jerry_debugger_transport_header_t *) jerry_heap_alloc (interface_size); diff --git a/jerry-ext/debugger/debugger-serial.c b/jerry-ext/debugger/debugger-serial.c index 06d1fb457c..3a4215f087 100644 --- a/jerry-ext/debugger/debugger-serial.c +++ b/jerry-ext/debugger/debugger-serial.c @@ -367,7 +367,7 @@ jerryx_debugger_serial_create (const char *config) /**< specify the configuratio JERRYX_DEBUG_MSG ("Client connected\n"); - size_t size = sizeof (jerryx_debugger_transport_serial_t); + jerry_size_t size = sizeof (jerryx_debugger_transport_serial_t); jerry_debugger_transport_header_t *header_p; header_p = (jerry_debugger_transport_header_t *) jerry_heap_alloc (size); diff --git a/jerry-ext/debugger/debugger-tcp.c b/jerry-ext/debugger/debugger-tcp.c index 7b8c43791b..8a47daa714 100644 --- a/jerry-ext/debugger/debugger-tcp.c +++ b/jerry-ext/debugger/debugger-tcp.c @@ -364,7 +364,7 @@ jerryx_debugger_tcp_create (uint16_t port) /**< listening port */ JERRYX_DEBUG_MSG ("Connected from: %s\n", inet_ntoa (addr.sin_addr)); - size_t size = sizeof (jerryx_debugger_transport_tcp_t); + jerry_size_t size = sizeof (jerryx_debugger_transport_tcp_t); jerry_debugger_transport_header_t *header_p; header_p = (jerry_debugger_transport_header_t *) jerry_heap_alloc (size); diff --git a/jerry-ext/debugger/debugger-ws.c b/jerry-ext/debugger/debugger-ws.c index e877312cba..88d247d54c 100644 --- a/jerry-ext/debugger/debugger-ws.c +++ b/jerry-ext/debugger/debugger-ws.c @@ -407,7 +407,7 @@ jerryx_debugger_ws_create (void) { bool is_handshake_ok = false; - const size_t buffer_size = 1024; + const jerry_size_t buffer_size = 1024; uint8_t *request_buffer_p = (uint8_t *) jerry_heap_alloc (buffer_size); if (!request_buffer_p) @@ -424,7 +424,7 @@ jerryx_debugger_ws_create (void) return false; } - const size_t interface_size = sizeof (jerry_debugger_transport_header_t); + const jerry_size_t interface_size = sizeof (jerry_debugger_transport_header_t); jerry_debugger_transport_header_t *header_p; header_p = (jerry_debugger_transport_header_t *) jerry_heap_alloc (interface_size); diff --git a/jerry-ext/handle-scope/handle-scope.c b/jerry-ext/handle-scope/handle-scope.c index 941c4593e4..517ceb8c6e 100644 --- a/jerry-ext/handle-scope/handle-scope.c +++ b/jerry-ext/handle-scope/handle-scope.c @@ -47,7 +47,7 @@ jerryx_handle_scope_release_handles (jerryx_handle_scope scope) jerryx_handle_t *a_handle = scope->handle_ptr; while (a_handle != NULL) { - jerry_release_value (a_handle->jval); + jerry_value_free (a_handle->jval); jerryx_handle_t *sibling = a_handle->sibling; jerry_heap_free (a_handle, sizeof (jerryx_handle_t)); a_handle = sibling; @@ -58,7 +58,7 @@ jerryx_handle_scope_release_handles (jerryx_handle_scope scope) for (size_t idx = 0; idx < prelist_handle_count; idx++) { - jerry_release_value (scope->handle_prelist[idx]); + jerry_value_free (scope->handle_prelist[idx]); } scope->prelist_handle_count = 0; } /* jerryx_handle_scope_release_handles */ diff --git a/jerry-ext/handler/handler-assert.c b/jerry-ext/handler/handler-assert.c index 13c6e0c9c8..38f7ffb5d6 100644 --- a/jerry-ext/handler/handler-assert.c +++ b/jerry-ext/handler/handler-assert.c @@ -38,52 +38,41 @@ jerryx_handler_assert_fatal (const jerry_call_info_t *call_info_p, /**< call inf if (args_cnt == 1 && jerry_value_is_true (args_p[0])) { - return jerry_create_boolean (true); + return jerry_boolean (true); } /* Assert failed, print a bit of JS backtrace */ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Script Error: assertion failed\n"); - if (jerry_is_feature_enabled (JERRY_FEATURE_LINE_INFO)) + if (jerry_feature_enabled (JERRY_FEATURE_LINE_INFO)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Script backtrace (top 5):\n"); /* If the line info feature is disabled an empty array will be returned. */ - jerry_value_t backtrace_array = jerry_get_backtrace (5); - uint32_t array_length = jerry_get_array_length (backtrace_array); + jerry_value_t backtrace_array = jerry_backtrace (5); + uint32_t array_length = jerry_array_length (backtrace_array); for (uint32_t idx = 0; idx < array_length; idx++) { - jerry_value_t property = jerry_get_property_by_index (backtrace_array, idx); - - jerry_length_t total_size = jerry_get_utf8_string_size (property); - jerry_length_t current_size = 0; - jerry_char_t string_buffer[64]; - const jerry_length_t copy_size = (jerry_length_t) (sizeof (string_buffer) - 1); + jerry_value_t property = jerry_object_get_index (backtrace_array, idx); /* On some systems the uint32_t values can't be printed with "%u" and * on some systems it can be printed. To avoid differences in the uint32_t typdef * The "PRIu32" macro is used to correctly add the formatter. */ jerry_port_log (JERRY_LOG_LEVEL_ERROR, " %" PRIu32 ": ", idx); - do - { - jerry_size_t copied_bytes = jerry_substring_to_utf8_char_buffer (property, - current_size, - current_size + copy_size, - string_buffer, - copy_size); - string_buffer[copied_bytes] = '\0'; - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%s", string_buffer); - - current_size += copied_bytes; - } while (total_size != current_size); - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "\n"); - - jerry_release_value (property); + + jerry_char_t string_buffer[256]; + const jerry_length_t buffer_size = (jerry_length_t) (sizeof (string_buffer) - 1); + + jerry_size_t copied_bytes = jerry_string_to_buffer (property, string_buffer, buffer_size, JERRY_ENCODING_UTF8); + string_buffer[copied_bytes] = '\0'; + + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%s\n", string_buffer); + jerry_value_free (property); } - jerry_release_value (backtrace_array); + jerry_value_free (backtrace_array); } jerry_port_fatal (ERR_FAILED_INTERNAL_ASSERTION); @@ -104,10 +93,10 @@ jerryx_handler_assert_throw (const jerry_call_info_t *call_info_p, /**< call inf if (args_cnt == 1 && jerry_value_is_true (args_p[0])) { - return jerry_create_boolean (true); + return jerry_boolean (true); } - return jerry_create_error (JERRY_ERROR_COMMON, (jerry_char_t *) "assertion failed"); + return jerry_throw_sz (JERRY_ERROR_COMMON, "assertion failed"); } /* jerryx_handler_assert_throw */ /** diff --git a/jerry-ext/handler/handler-gc.c b/jerry-ext/handler/handler-gc.c index 789d491496..e755ea7381 100644 --- a/jerry-ext/handler/handler-gc.c +++ b/jerry-ext/handler/handler-gc.c @@ -30,6 +30,6 @@ jerryx_handler_gc (const jerry_call_info_t *call_info_p, /**< call information * jerry_gc_mode_t mode = ((args_cnt > 0 && jerry_value_to_boolean (args_p[0])) ? JERRY_GC_PRESSURE_HIGH : JERRY_GC_PRESSURE_LOW); - jerry_gc (mode); - return jerry_create_undefined (); + jerry_heap_gc (mode); + return jerry_undefined (); } /* jerryx_handler_gc */ diff --git a/jerry-ext/handler/handler-print.c b/jerry-ext/handler/handler-print.c index f5f6f6e1fc..c220ba4deb 100644 --- a/jerry-ext/handler/handler-print.c +++ b/jerry-ext/handler/handler-print.c @@ -44,9 +44,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio { (void) call_info_p; /* unused */ - const char *const null_str = "\\u0000"; - - jerry_value_t ret_val = jerry_create_undefined (); + jerry_value_t ret_val = jerry_undefined (); for (jerry_length_t arg_index = 0; arg_index < args_cnt; arg_index++) { @@ -54,69 +52,29 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio if (jerry_value_is_symbol (args_p[arg_index])) { - str_val = jerry_get_symbol_descriptive_string (args_p[arg_index]); + str_val = jerry_symbol_descriptive_string (args_p[arg_index]); } else { str_val = jerry_value_to_string (args_p[arg_index]); } - if (jerry_value_is_error (str_val)) + if (jerry_value_is_exception (str_val)) { /* There is no need to free the undefined value. */ ret_val = str_val; break; } - jerry_length_t length = jerry_get_utf8_string_length (str_val); - jerry_length_t substr_pos = 0; - jerry_char_t substr_buf[256]; - - do + if (arg_index > 0) { - jerry_size_t substr_size = jerry_substring_to_utf8_char_buffer (str_val, substr_pos, length, substr_buf, 256 - 1); - - jerry_char_t *buf_end_p = substr_buf + substr_size; - - /* Update start position by the number of utf-8 characters. */ - for (jerry_char_t *buf_p = substr_buf; buf_p < buf_end_p; buf_p++) - { - /* Skip intermediate utf-8 octets. */ - if ((*buf_p & 0xc0) != 0x80) - { - substr_pos++; - } - } - - if (substr_pos == length) - { - *buf_end_p++ = (arg_index < args_cnt - 1) ? ' ' : '\n'; - } - - for (jerry_char_t *buf_p = substr_buf; buf_p < buf_end_p; buf_p++) - { - char chr = (char) *buf_p; - - if (chr != '\0') - { - jerry_port_print_char (chr); - continue; - } - - for (jerry_size_t null_index = 0; null_str[null_index] != '\0'; null_index++) - { - jerry_port_print_char (null_str[null_index]); - } - } - } while (substr_pos < length); - - jerry_release_value (str_val); - } + jerry_port_print_char (' '); + } - if (args_cnt == 0 || jerry_value_is_error (ret_val)) - { - jerry_port_print_char ('\n'); + jerry_string_print (str_val); + jerry_value_free (str_val); } + jerry_port_print_char ('\n'); return ret_val; } /* jerryx_handler_print */ diff --git a/jerry-ext/handler/handler-register.c b/jerry-ext/handler/handler-register.c index f4229b72e4..687f2547ce 100644 --- a/jerry-ext/handler/handler-register.c +++ b/jerry-ext/handler/handler-register.c @@ -19,24 +19,24 @@ * Register a JavaScript function in the global object. * * Note: - * returned value must be freed with jerry_release_value, when it is no longer needed. + * returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful, * error - otherwise. */ jerry_value_t -jerryx_handler_register_global (const jerry_char_t *name_p, /**< name of the function */ +jerryx_handler_register_global (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t global_obj_val = jerry_get_global_object (); - jerry_value_t function_name_val = jerry_create_string (name_p); - jerry_value_t function_val = jerry_create_external_function (handler_p); + jerry_value_t global_obj_val = jerry_current_realm (); + jerry_value_t function_name_val = jerry_string_sz (name_p); + jerry_value_t function_val = jerry_function_external (handler_p); - jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val); + jerry_value_t result_val = jerry_object_set (global_obj_val, function_name_val, function_val); - jerry_release_value (function_val); - jerry_release_value (function_name_val); - jerry_release_value (global_obj_val); + jerry_value_free (function_val); + jerry_value_free (function_name_val); + jerry_value_free (global_obj_val); return result_val; } /* jerryx_handler_register_global */ @@ -66,20 +66,20 @@ jerryx_set_properties (const jerry_value_t target_object, /**< target object */ if (entries == NULL) { - return JERRYX_SET_PROPERTIES_RESULT (jerry_create_undefined (), 0); + return JERRYX_SET_PROPERTIES_RESULT (jerry_undefined (), 0); } for (; (entries[idx].name != NULL); idx++) { const jerryx_property_entry *entry = &entries[idx]; - jerry_value_t prop_name = jerry_create_string_from_utf8 ((const jerry_char_t *) entry->name); - jerry_value_t result = jerry_set_property (target_object, prop_name, entry->value); + jerry_value_t prop_name = jerry_string_sz (entry->name); + jerry_value_t result = jerry_object_set (target_object, prop_name, entry->value); - jerry_release_value (prop_name); + jerry_value_free (prop_name); // By API definition: - // The jerry_set_property returns TRUE if there is no problem + // The jerry_object_set returns TRUE if there is no problem // and error object if there is any problem. // Thus there is no need to check if the boolean value is false or not. if (!jerry_value_is_boolean (result)) @@ -87,11 +87,11 @@ jerryx_set_properties (const jerry_value_t target_object, /**< target object */ return JERRYX_SET_PROPERTIES_RESULT (result, idx); } - jerry_release_value (entry->value); - jerry_release_value (result); + jerry_value_free (entry->value); + jerry_value_free (result); } - return JERRYX_SET_PROPERTIES_RESULT (jerry_create_undefined (), idx); + return JERRYX_SET_PROPERTIES_RESULT (jerry_undefined (), idx); #undef JERRYX_SET_PROPERTIES_RESULT } /* jerryx_set_properties */ @@ -112,7 +112,7 @@ jerryx_release_property_entry (const jerryx_property_entry entries[], /**< list for (uint32_t idx = register_result.registered; entries[idx].name != NULL; idx++) { - jerry_release_value (entries[idx].value); + jerry_value_free (entries[idx].value); } } /* jerryx_release_property_entry */ @@ -120,10 +120,10 @@ jerryx_release_property_entry (const jerryx_property_entry entries[], /**< list * Set a property to a specified value with a given name. * * Notes: - * - The operation performed is the same as what the `jerry_set_property` method. + * - The operation performed is the same as what the `jerry_object_set` method. * - The property name must be a zero terminated UTF-8 string. * - There should be no '\0' (NULL) character in the name excluding the string terminator. - * - Returned value must be freed with jerry_release_value, when it is no longer needed. + * - Returned value must be freed with jerry_value_free, when it is no longer needed. * * @return true value - if the operation was successful * thrown error - otherwise @@ -133,10 +133,10 @@ jerryx_set_property_str (const jerry_value_t target_object, /**< target object * const char *name, /**< property name */ const jerry_value_t value) /**< value to set */ { - jerry_value_t property_name_val = jerry_create_string_from_utf8 ((const jerry_char_t *) name); - jerry_value_t result_val = jerry_set_property (target_object, property_name_val, value); + jerry_value_t property_name_val = jerry_string_sz (name); + jerry_value_t result_val = jerry_object_set (target_object, property_name_val, value); - jerry_release_value (property_name_val); + jerry_value_free (property_name_val); return result_val; } /* jerryx_set_property_str */ @@ -145,10 +145,10 @@ jerryx_set_property_str (const jerry_value_t target_object, /**< target object * * Get a property value of a specified object. * * Notes: - * - The operation performed is the same as what the `jerry_get_property` method. + * - The operation performed is the same as what the `jerry_object_get` method. * - The property name must be a zero terminated UTF-8 string. * - There should be no '\0' (NULL) character in the name excluding the string terminator. - * - Returned value must be freed with jerry_release_value, when it is no longer needed. + * - Returned value must be freed with jerry_value_free, when it is no longer needed. * * @return jerry_value_t - the property value */ @@ -156,9 +156,9 @@ jerry_value_t jerryx_get_property_str (const jerry_value_t target_object, /**< target object */ const char *name) /**< property name */ { - jerry_value_t prop_name = jerry_create_string_from_utf8 ((const jerry_char_t *) name); - jerry_value_t result_val = jerry_get_property (target_object, prop_name); - jerry_release_value (prop_name); + jerry_value_t prop_name = jerry_string_sz (name); + jerry_value_t result_val = jerry_object_get (target_object, prop_name); + jerry_value_free (prop_name); return result_val; } /* jerryx_get_property_str */ @@ -167,7 +167,7 @@ jerryx_get_property_str (const jerry_value_t target_object, /**< target object * * Check if a property exists on an object. * * Notes: - * - The operation performed is the same as what the `jerry_has_property` method. + * - The operation performed is the same as what the `jerry_object_has` method. * - The property name must be a zero terminated UTF-8 string. * - There should be no '\0' (NULL) character in the name excluding the string terminator. * @@ -180,16 +180,16 @@ jerryx_has_property_str (const jerry_value_t target_object, /**< target object * { bool has_property = false; - jerry_value_t prop_name = jerry_create_string_from_utf8 ((const jerry_char_t *) name); - jerry_value_t has_prop_val = jerry_has_property (target_object, prop_name); + jerry_value_t prop_name = jerry_string_sz (name); + jerry_value_t has_prop_val = jerry_object_has (target_object, prop_name); - if (!jerry_value_is_error (has_prop_val)) + if (!jerry_value_is_exception (has_prop_val)) { has_property = jerry_value_is_true (has_prop_val); } - jerry_release_value (has_prop_val); - jerry_release_value (prop_name); + jerry_value_free (has_prop_val); + jerry_value_free (prop_name); return has_property; } /* jerryx_has_property_str */ diff --git a/jerry-ext/handler/handler-resource-name.c b/jerry-ext/handler/handler-resource-name.c index 244206e6c0..7536de9028 100644 --- a/jerry-ext/handler/handler-resource-name.c +++ b/jerry-ext/handler/handler-resource-name.c @@ -18,7 +18,7 @@ /** * Get the resource name (usually a file name) of the currently executed script or the given function object * - * Note: returned value must be freed with jerry_release_value, when it is no longer needed + * Note: returned value must be freed with jerry_value_free, when it is no longer needed * * @return JS string constructed from * - the currently executed function object's resource name, if the given value is undefined @@ -26,15 +26,15 @@ * - "", otherwise */ jerry_value_t -jerryx_handler_resource_name (const jerry_call_info_t *call_info_p, /**< call information */ - const jerry_value_t args_p[], /**< function arguments */ - const jerry_length_t args_cnt) /**< number of function arguments */ +jerryx_handler_source_name (const jerry_call_info_t *call_info_p, /**< call information */ + const jerry_value_t args_p[], /**< function arguments */ + const jerry_length_t args_cnt) /**< number of function arguments */ { (void) call_info_p; /* unused */ - jerry_value_t undefined_value = jerry_create_undefined (); - jerry_value_t resource_name = jerry_get_resource_name (args_cnt > 0 ? args_p[0] : undefined_value); - jerry_release_value (undefined_value); + jerry_value_t undefined_value = jerry_undefined (); + jerry_value_t source_name = jerry_source_name (args_cnt > 0 ? args_p[0] : undefined_value); + jerry_value_free (undefined_value); - return resource_name; -} /* jerryx_handler_resource_name */ + return source_name; +} /* jerryx_handler_source_name */ diff --git a/jerry-ext/include/jerryscript-ext/autorelease.h b/jerry-ext/include/jerryscript-ext/autorelease.h index be3e49ba52..3a91db23f6 100644 --- a/jerry-ext/include/jerryscript-ext/autorelease.h +++ b/jerry-ext/include/jerryscript-ext/autorelease.h @@ -21,25 +21,25 @@ JERRY_C_API_BEGIN #include "autorelease.impl.h" /* - * Macro for `const jerry_value_t` for which jerry_release_value () is + * Macro for `const jerry_value_t` for which jerry_value_free () is * automatically called when the variable goes out of scope. * * Example usage: * static void foo (bool enable) * { - * JERRYX_AR_VALUE_T bar = jerry_create_string (...); + * JERRYX_AR_VALUE_T bar = jerry_string (...); * * if (enable) { - * JERRYX_AR_VALUE_T baz = jerry_get_global_object (); + * JERRYX_AR_VALUE_T baz = jerry_current_realm (); * * // ... * - * // jerry_release_value (baz) and jerry_release_value (bar) is called automatically before + * // jerry_value_free (baz) and jerry_value_free (bar) is called automatically before * // returning, because `baz` and `bar` go out of scope. * return; * } * - * // jerry_release_value (bar) is called automatically when the function returns, + * // jerry_value_free (bar) is called automatically when the function returns, * // because `bar` goes out of scope. * } */ diff --git a/jerry-ext/include/jerryscript-ext/autorelease.impl.h b/jerry-ext/include/jerryscript-ext/autorelease.impl.h index 0657420618..a32f83b866 100644 --- a/jerry-ext/include/jerryscript-ext/autorelease.impl.h +++ b/jerry-ext/include/jerryscript-ext/autorelease.impl.h @@ -20,7 +20,7 @@ #ifdef __GNUC__ /* - * Calls jerry_release_value (*value). + * Calls jerry_value_free (*value). * The GCC __cleanup__ function must take a pointer to the variable to clean up. * * @return void @@ -28,7 +28,7 @@ static inline void jerryx_autorelease_cleanup (const jerry_value_t *value) /**< jerry value */ { - jerry_release_value (*value); + jerry_value_free (*value); } /* jerryx_autorelease_cleanup */ #define __JERRYX_AR_VALUE_T_IMPL const jerry_value_t __attribute__ ((__cleanup__ (jerryx_autorelease_cleanup))) diff --git a/jerry-ext/include/jerryscript-ext/handler.h b/jerry-ext/include/jerryscript-ext/handler.h index dd926fcda2..3935861097 100644 --- a/jerry-ext/include/jerryscript-ext/handler.h +++ b/jerry-ext/include/jerryscript-ext/handler.h @@ -24,7 +24,7 @@ JERRY_C_API_BEGIN * Handler registration helper */ -jerry_value_t jerryx_handler_register_global (const jerry_char_t *name_p, jerry_external_handler_t handler_p); +jerry_value_t jerryx_handler_register_global (const char *name_p, jerry_external_handler_t handler_p); /* * Common external function handlers @@ -44,9 +44,9 @@ jerryx_handler_gc (const jerry_call_info_t *call_info_p, const jerry_value_t arg jerry_value_t jerryx_handler_print (const jerry_call_info_t *call_info_p, const jerry_value_t args_p[], const jerry_length_t args_cnt); -jerry_value_t jerryx_handler_resource_name (const jerry_call_info_t *call_info_p, - const jerry_value_t args_p[], - const jerry_length_t args_cnt); +jerry_value_t jerryx_handler_source_name (const jerry_call_info_t *call_info_p, + const jerry_value_t args_p[], + const jerry_length_t args_cnt); /** * Struct used by the `jerryx_set_functions` method to @@ -61,32 +61,32 @@ typedef struct #define JERRYX_PROPERTY_NUMBER(NAME, NUMBER) \ (jerryx_property_entry) \ { \ - NAME, jerry_create_number (NUMBER) \ + NAME, jerry_number (NUMBER) \ } -#define JERRYX_PROPERTY_STRING(NAME, STR) \ - (jerryx_property_entry) \ - { \ - NAME, jerry_create_string_from_utf8 ((const jerry_char_t *) STR) \ +#define JERRYX_PROPERTY_STRING(NAME, STR, SIZE) \ + (jerryx_property_entry) \ + { \ + NAME, jerry_string ((const jerry_char_t *) STR, SIZE, JERRY_ENCODING_UTF8) \ } -#define JERRYX_PROPERTY_STRING_SZ(NAME, STR, SIZE) \ - (jerryx_property_entry) \ - { \ - NAME, jerry_create_string_sz_from_utf8 ((const jerry_char_t *) STR, SIZE) \ +#define JERRYX_PROPERTY_STRING_SZ(NAME, STR) \ + (jerryx_property_entry) \ + { \ + NAME, jerry_string_sz (STR) \ } #define JERRYX_PROPERTY_BOOLEAN(NAME, VALUE) \ (jerryx_property_entry) \ { \ - NAME, jerry_create_boolean (VALUE) \ + NAME, jerry_boolean (VALUE) \ } -#define JERRYX_PROPERTY_FUNCTION(NAME, FUNC) \ - (jerryx_property_entry) \ - { \ - NAME, jerry_create_external_function (FUNC) \ +#define JERRYX_PROPERTY_FUNCTION(NAME, FUNC) \ + (jerryx_property_entry) \ + { \ + NAME, jerry_function_external (FUNC) \ } #define JERRYX_PROPERTY_UNDEFINED(NAME) \ (jerryx_property_entry) \ { \ - NAME, jerry_create_undefined () \ + NAME, jerry_undefined () \ } #define JERRYX_PROPERTY_LIST_END() \ (jerryx_property_entry) \ diff --git a/jerry-ext/module/module.c b/jerry-ext/module/module.c index 6ca31c46ee..94a2c7c159 100644 --- a/jerry-ext/module/module.c +++ b/jerry-ext/module/module.c @@ -19,9 +19,9 @@ #include "jerryscript.h" -static const jerry_char_t *module_name_property_name = (jerry_char_t *) "moduleName"; -static const jerry_char_t *module_not_found = (jerry_char_t *) "Module not found"; -static const jerry_char_t *module_name_not_string = (jerry_char_t *) "Module name is not a string"; +static const char *module_name_property_name = "moduleName"; +static const char *module_not_found = "Module not found"; +static const char *module_name_not_string = "Module name is not a string"; /** * Create an error related to modules @@ -33,19 +33,16 @@ static const jerry_char_t *module_name_not_string = (jerry_char_t *) "Module nam */ static jerry_value_t jerryx_module_create_error (jerry_error_t error_type, /**< the type of error to create */ - const jerry_char_t *message, /**< the error message */ + const char *message, /**< the error message */ const jerry_value_t module_name) /**< the module name */ { - jerry_value_t ret = jerry_create_error (error_type, message); + jerry_value_t error_object = jerry_error_sz (error_type, message); + jerry_value_t property_name = jerry_string_sz (module_name_property_name); - jerry_value_t error_object = jerry_get_value_from_error (ret, false); - jerry_value_t property_name = jerry_create_string (module_name_property_name); + jerry_value_free (jerry_object_set (error_object, property_name, module_name)); - jerry_release_value (jerry_set_property (error_object, property_name, module_name)); - - jerry_release_value (property_name); - jerry_release_value (error_object); - return ret; + jerry_value_free (property_name); + return jerry_throw_value (error_object, true); } /* jerryx_module_create_error */ /** @@ -54,7 +51,7 @@ jerryx_module_create_error (jerry_error_t error_type, /**< the type of error to static void jerryx_module_manager_init (void *user_data_p) { - *((jerry_value_t *) user_data_p) = jerry_create_object (); + *((jerry_value_t *) user_data_p) = jerry_object (); } /* jerryx_module_manager_init */ /** @@ -63,7 +60,7 @@ jerryx_module_manager_init (void *user_data_p) static void jerryx_module_manager_deinit (void *user_data_p) /**< context pointer to deinitialize */ { - jerry_release_value (*(jerry_value_t *) user_data_p); + jerry_value_free (*(jerry_value_t *) user_data_p); } /* jerryx_module_manager_deinit */ /** @@ -118,10 +115,10 @@ jerryx_module_check_cache (jerry_value_t cache, /**< cache from which to attempt bool ret = false; /* Check if the cache has the module. */ - jerry_value_t js_has_property = jerry_has_property (cache, module_name); + jerry_value_t js_has_property = jerry_object_has (cache, module_name); /* If we succeed in getting an answer, we examine the answer. */ - if (!jerry_value_is_error (js_has_property)) + if (!jerry_value_is_exception (js_has_property)) { bool has_property = jerry_value_is_true (js_has_property); @@ -130,13 +127,13 @@ jerryx_module_check_cache (jerry_value_t cache, /**< cache from which to attempt { if (result != NULL) { - (*result) = jerry_get_property (cache, module_name); + (*result) = jerry_object_get (cache, module_name); } ret = true; } } - jerry_release_value (js_has_property); + jerry_value_free (js_has_property); return ret; } /* jerryx_module_check_cache */ @@ -152,22 +149,22 @@ jerryx_module_add_to_cache (jerry_value_t cache, /**< cache to which to add the jerry_value_t module_name, /**< key at which to cache the module */ jerry_value_t module) /**< the module to cache */ { - jerry_value_t ret = jerry_set_property (cache, module_name, module); + jerry_value_t ret = jerry_object_set (cache, module_name, module); - if (jerry_value_is_error (ret)) + if (jerry_value_is_exception (ret)) { - jerry_release_value (module); + jerry_value_free (module); } else { - jerry_release_value (ret); + jerry_value_free (ret); ret = module; } return ret; } /* jerryx_module_add_to_cache */ -static const jerry_char_t *on_resolve_absent = (jerry_char_t *) "Module on_resolve () must not be NULL"; +static const char *on_resolve_absent = "Module on_resolve () must not be NULL"; /** * Declare and define the default module resolver - one which examines what modules are defined in the above linker @@ -180,9 +177,9 @@ jerryx_resolve_native_module (const jerry_value_t canonical_name, /**< canonical { const jerryx_native_module_t *module_p = NULL; - jerry_size_t name_size = jerry_get_utf8_string_size (canonical_name); + jerry_size_t name_size = jerry_string_size (canonical_name, JERRY_ENCODING_UTF8); JERRY_VLA (jerry_char_t, name_string, name_size); - jerry_string_to_utf8_char_buffer (canonical_name, name_string, name_size); + jerry_string_to_buffer (canonical_name, name_string, name_size, JERRY_ENCODING_UTF8); /* Look for the module by its name in the list of module definitions. */ for (module_p = first_module_p; module_p != NULL; module_p = module_p->next_p) @@ -226,7 +223,7 @@ jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module t goto done; } - instances = *(jerry_value_t *) jerry_get_context_data (&jerryx_module_manager); + instances = *(jerry_value_t *) jerry_context_data (&jerryx_module_manager); /** * Establish the canonical name for the requested module. Each resolver presents its own canonical name. If one of @@ -235,15 +232,14 @@ jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module t for (index = 0; index < resolver_count; index++) { get_canonical_name_p = (resolvers_p[index] == NULL ? NULL : resolvers_p[index]->get_canonical_name_p); - canonical_names[index] = - ((get_canonical_name_p == NULL) ? jerry_acquire_value (name) : get_canonical_name_p (name)); + canonical_names[index] = ((get_canonical_name_p == NULL) ? jerry_value_copy (name) : get_canonical_name_p (name)); canonical_names_used++; if (jerryx_module_check_cache (instances, canonical_names[index], result)) { /* A NULL for result indicates that we are to delete the module from the cache if found. Let's do that here.*/ if (result == NULL) { - jerry_delete_property (instances, canonical_names[index]); + jerry_object_delete (instances, canonical_names[index]); } goto done; } @@ -263,7 +259,7 @@ jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module t resolve_p = (resolvers_p[index] == NULL ? NULL : resolvers_p[index]->resolve_p); if (resolve_p != NULL && resolve_p (canonical_names[index], result)) { - if (!jerry_value_is_error (*result)) + if (!jerry_value_is_exception (*result)) { *result = jerryx_module_add_to_cache (instances, canonical_names[index], *result); } @@ -278,7 +274,7 @@ jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module t /* Release the canonical names as returned by the various resolvers. */ for (index = 0; index < canonical_names_used; index++) { - jerry_release_value (canonical_names[index]); + jerry_value_free (canonical_names[index]); } } /* jerryx_module_resolve_local */ @@ -311,7 +307,7 @@ jerryx_module_clear_cache (const jerry_value_t name, /**< name of the module to const jerryx_module_resolver_t **resolvers_p, /**< list of resolvers */ size_t resolver_count) /**< number of resolvers in @p resolvers */ { - void *instances_p = jerry_get_context_data (&jerryx_module_manager); + void *instances_p = jerry_context_data (&jerryx_module_manager); if (jerry_value_is_undefined (name)) { diff --git a/jerry-main/libfuzzer.c b/jerry-main/libfuzzer.c index 7f9d8c9e59..831063de76 100644 --- a/jerry-main/libfuzzer.c +++ b/jerry-main/libfuzzer.c @@ -23,20 +23,22 @@ LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) srand (0); jerry_init (JERRY_INIT_EMPTY); - if (jerry_is_valid_utf8_string ((jerry_char_t *) data, (jerry_size_t) size)) + if (jerry_validate_string ((jerry_char_t *) data, (jerry_size_t) size, JERRY_ENCODING_UTF8)) { - jerry_value_t parse_value = jerry_parse (NULL, 0, (jerry_char_t *) data, size, JERRY_PARSE_NO_OPTS); + jerry_parse_options_t parse_options; + parse_options.options = JERRY_PARSE_NO_OPTS; + jerry_value_t parse_value = jerry_parse ((jerry_char_t *) data, size, &parse_options); - if (!jerry_value_is_error (parse_value)) + if (!jerry_value_is_exception (parse_value)) { jerry_value_t run_value = jerry_run (parse_value); - jerry_release_value (run_value); + jerry_value_free (run_value); - jerry_value_t run_queue_value = jerry_run_all_enqueued_jobs (); - jerry_release_value (run_queue_value); + run_value = jerry_run_microtasks (); + jerry_value_free (run_value); } - jerry_release_value (parse_value); + jerry_value_free (parse_value); } jerry_cleanup (); diff --git a/jerry-main/main-jerry-snapshot.c b/jerry-main/main-jerry-snapshot.c index b36ff11eea..beec81feeb 100644 --- a/jerry-main/main-jerry-snapshot.c +++ b/jerry-main/main-jerry-snapshot.c @@ -48,7 +48,7 @@ static const jerry_char_t *magic_string_items[JERRY_LITERAL_LENGTH]; #if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) /** - * The alloc function passed to jerry_create_context + * The alloc function passed to jerry_context_create */ static void * context_alloc (size_t size, void *cb_data_p) @@ -63,7 +63,7 @@ context_alloc (size_t size, void *cb_data_p) static void context_init (void) { - jerry_context_t *context_p = jerry_create_context (JERRY_GLOBAL_HEAP_SIZE * 1024, context_alloc, NULL); + jerry_context_t *context_p = jerry_context (JERRY_GLOBAL_HEAP_SIZE * 1024, context_alloc, NULL); jerry_port_default_set_current_context (context_p); } /* context_init */ @@ -79,7 +79,7 @@ static bool check_feature (jerry_feature_t feature, /**< feature to check */ const char *option) /**< command line option that triggered this check */ { - if (!jerry_is_feature_enabled (feature)) + if (!jerry_feature_enabled (feature)) { jerry_port_default_set_log_level (JERRY_LOG_LEVEL_WARNING); jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Ignoring '%s' option because this feature is disabled!\n", option); @@ -159,34 +159,24 @@ read_file (uint8_t *input_pos_p, /**< next position in the input buffer */ static void print_unhandled_exception (jerry_value_t error_value) /**< error value */ { - assert (!jerry_value_is_error (error_value)); + assert (!jerry_value_is_exception (error_value)); jerry_value_t err_str_val = jerry_value_to_string (error_value); - if (jerry_value_is_error (err_str_val)) + if (jerry_value_is_exception (err_str_val)) { /* Avoid recursive error throws. */ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Snapshot error: [value cannot be converted to string]\n"); - jerry_release_value (err_str_val); - return; - } - - jerry_size_t err_str_size = jerry_get_utf8_string_size (err_str_val); - - if (err_str_size >= 256) - { - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Snapshot error: [value cannot be converted to string]\n"); - jerry_release_value (err_str_val); + jerry_value_free (err_str_val); return; } jerry_char_t err_str_buf[256]; - jerry_size_t string_end = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size); - assert (string_end == err_str_size); - err_str_buf[string_end] = 0; + jerry_size_t bytes = jerry_string_to_buffer (err_str_val, err_str_buf, sizeof (err_str_buf) - 1, JERRY_ENCODING_UTF8); + err_str_buf[bytes] = '\0'; jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Snapshot error: %s\n", (char *) err_str_buf); - jerry_release_value (err_str_val); + jerry_value_free (err_str_val); } /* print_unhandled_exception */ /** @@ -333,7 +323,7 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */ jerry_init (flags); - if (!jerry_is_valid_utf8_string (source_p, (jerry_size_t) source_length)) + if (!jerry_validate_string (source_p, (jerry_size_t) source_length, JERRY_ENCODING_UTF8)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Input must be a valid UTF-8 string.\n"); jerry_cleanup (); @@ -372,50 +362,52 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */ } jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; /* To avoid cppcheck warning. */ parse_options.argument_list = 0; - parse_options.resource_name = - jerry_create_string_sz ((const jerry_char_t *) file_name_p, (jerry_size_t) strlen (file_name_p)); + parse_options.source_name = + jerry_string ((const jerry_char_t *) file_name_p, (jerry_size_t) strlen (file_name_p), JERRY_ENCODING_UTF8); if (function_args_p != NULL) { parse_options.options |= JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string_from_utf8 ((const jerry_char_t *) function_args_p); + parse_options.argument_list = jerry_string ((const jerry_char_t *) function_args_p, + (jerry_size_t) strlen (function_args_p), + JERRY_ENCODING_UTF8); } jerry_value_t snapshot_result = jerry_parse ((jerry_char_t *) source_p, source_length, &parse_options); - if (!jerry_value_is_error (snapshot_result)) + if (!jerry_value_is_exception (snapshot_result)) { jerry_value_t parse_result = snapshot_result; snapshot_result = jerry_generate_snapshot (parse_result, snapshot_flags, output_buffer, sizeof (output_buffer) / sizeof (uint32_t)); - jerry_release_value (parse_result); + jerry_value_free (parse_result); } if (parse_options.options & JERRY_PARSE_HAS_ARGUMENT_LIST) { - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_options.argument_list); } - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (jerry_value_is_error (snapshot_result)) + if (jerry_value_is_exception (snapshot_result)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Generating snapshot failed!\n"); - snapshot_result = jerry_get_value_from_error (snapshot_result, true); + snapshot_result = jerry_exception_value (snapshot_result, true); print_unhandled_exception (snapshot_result); - jerry_release_value (snapshot_result); + jerry_value_free (snapshot_result); jerry_cleanup (); return JERRY_STANDALONE_EXIT_CODE_FAIL; } - size_t snapshot_size = (size_t) jerry_get_number_value (snapshot_result); - jerry_release_value (snapshot_result); + size_t snapshot_size = (size_t) jerry_value_as_number (snapshot_result); + jerry_value_free (snapshot_result); FILE *snapshot_file_p = fopen (output_file_name_p, "wb"); if (snapshot_file_p == NULL) diff --git a/jerry-main/main-jerry-test.c b/jerry-main/main-jerry-test.c index 640049b3fa..bec9b8ba86 100644 --- a/jerry-main/main-jerry-test.c +++ b/jerry-main/main-jerry-test.c @@ -75,7 +75,7 @@ static JERRY_ATTR_NOINLINE int run (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t ret_value = jerry_create_undefined (); + jerry_value_t ret_value = jerry_undefined (); for (int i = 1; i < argc; i++) { @@ -86,33 +86,34 @@ run (void) if (source_p == NULL) { - ret_value = jerry_create_error (JERRY_ERROR_COMMON, (jerry_char_t *) ""); + ret_value = jerry_throw_sz (JERRY_ERROR_COMMON, ""); break; } else { ret_value = jerry_parse (source_p, source_size, NULL); - if (!jerry_value_is_error (ret_value)) + if (!jerry_value_is_exception (ret_value)) { jerry_value_t func_val = ret_value; ret_value = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); } } - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { break; } - jerry_release_value (ret_value); - ret_value = jerry_create_undefined (); + jerry_value_free (ret_value); + ret_value = jerry_undefined (); } - int ret_code = !jerry_value_is_error (ret_value) ? JERRY_STANDALONE_EXIT_CODE_OK : JERRY_STANDALONE_EXIT_CODE_FAIL; + int ret_code = + !jerry_value_is_exception (ret_value) ? JERRY_STANDALONE_EXIT_CODE_OK : JERRY_STANDALONE_EXIT_CODE_FAIL; - jerry_release_value (ret_value); + jerry_value_free (ret_value); jerry_cleanup (); return ret_code; diff --git a/jerry-main/main-jerry.c b/jerry-main/main-jerry.c index f5805325a4..2dbab65266 100644 --- a/jerry-main/main-jerry.c +++ b/jerry-main/main-jerry.c @@ -34,7 +34,7 @@ #if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) /** - * The alloc function passed to jerry_create_context + * The alloc function passed to jerry_context_create */ static void * context_alloc (size_t size, void *cb_data_p) @@ -62,7 +62,7 @@ main (int argc, char **argv) main_parse_args (argc, argv, &arguments); #if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) - jerry_context_t *context_p = jerry_create_context (JERRY_GLOBAL_HEAP_SIZE * 1024, context_alloc, NULL); + jerry_context_t *context_p = jerry_context (JERRY_GLOBAL_HEAP_SIZE * 1024, context_alloc, NULL); jerry_port_default_set_current_context (context_p); #endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */ @@ -78,45 +78,46 @@ main (int argc, char **argv) if (source_file_p->type == SOURCE_MODULE) { - jerry_value_t specifier = jerry_create_string_from_utf8 ((const jerry_char_t *) file_path_p); - jerry_value_t referrer = jerry_create_undefined (); + jerry_value_t specifier = + jerry_string ((const jerry_char_t *) file_path_p, (jerry_size_t) strlen (file_path_p), JERRY_ENCODING_UTF8); + jerry_value_t referrer = jerry_undefined (); ret_value = jerry_port_module_resolve (specifier, referrer, NULL); - jerry_release_value (referrer); - jerry_release_value (specifier); + jerry_value_free (referrer); + jerry_value_free (specifier); - if (!jerry_value_is_error (ret_value)) + if (!jerry_value_is_exception (ret_value)) { - if (jerry_module_get_state (ret_value) != JERRY_MODULE_STATE_UNLINKED) + if (jerry_module_state (ret_value) != JERRY_MODULE_STATE_UNLINKED) { /* A module can be evaluated only once. */ - jerry_release_value (ret_value); + jerry_value_free (ret_value); continue; } jerry_value_t link_val = jerry_module_link (ret_value, NULL, NULL); - if (jerry_value_is_error (link_val)) + if (jerry_value_is_exception (link_val)) { - jerry_release_value (ret_value); + jerry_value_free (ret_value); ret_value = link_val; } else { - jerry_release_value (link_val); + jerry_value_free (link_val); jerry_value_t module_val = ret_value; ret_value = jerry_module_evaluate (module_val); - jerry_release_value (module_val); + jerry_value_free (module_val); } } - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); goto exit; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); continue; } @@ -145,7 +146,7 @@ main (int argc, char **argv) { assert (source_file_p->type == SOURCE_SCRIPT || source_file_p->type == SOURCE_MODULE); - if (!jerry_is_valid_utf8_string ((jerry_char_t *) source_p, (jerry_size_t) source_size)) + if (!jerry_validate_string ((jerry_char_t *) source_p, (jerry_size_t) source_size, JERRY_ENCODING_UTF8)) { jerry_port_release_source (source_p); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Input must be a valid UTF-8 string."); @@ -153,27 +154,27 @@ main (int argc, char **argv) } jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = - jerry_create_string_sz ((const jerry_char_t *) file_path_p, (jerry_size_t) strlen (file_path_p)); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = + jerry_string ((const jerry_char_t *) file_path_p, (jerry_size_t) strlen (file_path_p), JERRY_ENCODING_UTF8); ret_value = jerry_parse (source_p, source_size, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); jerry_port_release_source (source_p); - if (!jerry_value_is_error (ret_value) && !(arguments.option_flags & OPT_FLAG_PARSE_ONLY)) + if (!jerry_value_is_exception (ret_value) && !(arguments.option_flags & OPT_FLAG_PARSE_ONLY)) { jerry_value_t func_val = ret_value; ret_value = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); } break; } } - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { if (main_is_value_reset (ret_value)) { @@ -186,7 +187,7 @@ main (int argc, char **argv) goto exit; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); } if (arguments.option_flags & OPT_FLAG_WAIT_SOURCE) @@ -218,7 +219,7 @@ main (int argc, char **argv) } assert (receive_status == JERRY_DEBUGGER_SOURCE_RECEIVED); - jerry_release_value (ret_value); + jerry_value_free (ret_value); } } else if (arguments.option_flags & OPT_FLAG_USE_STDIN) @@ -241,7 +242,7 @@ main (int argc, char **argv) ret_value = jerry_parse ((jerry_char_t *) source_p, source_size, NULL); free (source_p); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); goto exit; @@ -249,15 +250,15 @@ main (int argc, char **argv) jerry_value_t func_val = ret_value; ret_value = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); goto exit; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); } else if (arguments.source_count == 0) { @@ -282,7 +283,7 @@ main (int argc, char **argv) continue; } - if (!jerry_is_valid_utf8_string ((jerry_char_t *) str_p, (jerry_size_t) len)) + if (!jerry_validate_string ((jerry_char_t *) str_p, (jerry_size_t) len, JERRY_ENCODING_UTF8)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Input must be a valid UTF-8 string.\n"); continue; @@ -290,7 +291,7 @@ main (int argc, char **argv) ret_value = jerry_parse ((jerry_char_t *) str_p, len, NULL); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); continue; @@ -298,9 +299,9 @@ main (int argc, char **argv) jerry_value_t func_val = ret_value; ret_value = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); continue; @@ -308,53 +309,53 @@ main (int argc, char **argv) const jerry_value_t args[] = { ret_value }; jerry_value_t ret_val_print = jerryx_handler_print (NULL, args, 1); - jerry_release_value (ret_val_print); - jerry_release_value (ret_value); - ret_value = jerry_run_all_enqueued_jobs (); + jerry_value_free (ret_val_print); + jerry_value_free (ret_value); + ret_value = jerry_run_microtasks (); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); continue; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); } } - ret_value = jerry_run_all_enqueued_jobs (); + ret_value = jerry_run_microtasks (); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); goto exit; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); if (arguments.exit_cb_name_p != NULL) { - jerry_value_t global = jerry_get_global_object (); - jerry_value_t name_str = jerry_create_string ((jerry_char_t *) arguments.exit_cb_name_p); - jerry_value_t callback_fn = jerry_get_property (global, name_str); + jerry_value_t global = jerry_current_realm (); + jerry_value_t name_str = jerry_string_sz (arguments.exit_cb_name_p); + jerry_value_t callback_fn = jerry_object_get (global, name_str); - jerry_release_value (global); - jerry_release_value (name_str); + jerry_value_free (global); + jerry_value_free (name_str); if (jerry_value_is_function (callback_fn)) { - ret_value = jerry_call_function (callback_fn, jerry_create_undefined (), NULL, 0); + ret_value = jerry_call (callback_fn, jerry_undefined (), NULL, 0); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { main_print_unhandled_exception (ret_value); goto exit; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); } - jerry_release_value (callback_fn); + jerry_value_free (callback_fn); } return_code = JERRY_STANDALONE_EXIT_CODE_OK; diff --git a/jerry-main/main-options.c b/jerry-main/main-options.c index a60ec1fbdb..99cc29d703 100644 --- a/jerry-main/main-options.c +++ b/jerry-main/main-options.c @@ -131,7 +131,7 @@ static bool check_feature (jerry_feature_t feature, /**< feature to check */ const char *option) /**< command line option that triggered this check */ { - if (!jerry_is_feature_enabled (feature)) + if (!jerry_feature_enabled (feature)) { jerry_port_default_set_log_level (JERRY_LOG_LEVEL_WARNING); jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Ignoring '%s' option because this feature is disabled!\n", option); @@ -184,7 +184,7 @@ main_parse_args (int argc, /**< argc */ } case OPT_MEM_STATS: { - if (check_feature (JERRY_FEATURE_MEM_STATS, cli_state.arg)) + if (check_feature (JERRY_FEATURE_HEAP_STATS, cli_state.arg)) { jerry_port_default_set_log_level (JERRY_LOG_LEVEL_DEBUG); arguments_p->init_flags |= JERRY_INIT_MEM_STATS; diff --git a/jerry-main/main-utils.c b/jerry-main/main-utils.c index e66068d4fa..cbe2aa6372 100644 --- a/jerry-main/main-utils.c +++ b/jerry-main/main-utils.c @@ -40,9 +40,9 @@ static void main_register_global_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p); - assert (!jerry_value_is_error (result_val)); - jerry_release_value (result_val); + jerry_value_t result_val = jerryx_handler_register_global (name_p, handler_p); + assert (!jerry_value_is_exception (result_val)); + jerry_value_free (result_val); } /* main_register_global_function */ static jerry_value_t @@ -53,7 +53,7 @@ main_create_realm (const jerry_call_info_t *call_info_p, /**< call information * (void) call_info_p; /* unused */ (void) args_p; /* unused */ (void) args_cnt; /* unused */ - return jerry_create_realm (); + return jerry_realm (); } /* main_create_realm */ /** @@ -64,16 +64,16 @@ test262_register_function (jerry_value_t test262_obj, /** $262 object */ const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t function_val = jerry_create_external_function (handler_p); + jerry_value_t function_name_val = jerry_string_sz (name_p); + jerry_value_t function_val = jerry_function_external (handler_p); - jerry_value_t result_val = jerry_set_property (test262_obj, function_name_val, function_val); + jerry_value_t result_val = jerry_object_set (test262_obj, function_name_val, function_val); - jerry_release_value (function_val); - jerry_release_value (function_name_val); + jerry_value_free (function_val); + jerry_value_free (function_name_val); - assert (!jerry_value_is_error (result_val)); - jerry_release_value (result_val); + assert (!jerry_value_is_exception (result_val)); + jerry_value_free (result_val); } /* test262_register_function */ /** @@ -93,12 +93,12 @@ test262_detach_array_buffer (const jerry_call_info_t *call_info_p, /**< call inf if (args_cnt < 1 || !jerry_value_is_arraybuffer (args_p[0])) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Expected an ArrayBuffer object"); + return jerry_throw_sz (JERRY_ERROR_TYPE, "Expected an ArrayBuffer object"); } /* TODO: support the optional 'key' argument */ - return jerry_detach_arraybuffer (args_p[0]); + return jerry_arraybuffer_detach (args_p[0]); } /* test262_detach_array_buffer */ /** @@ -117,25 +117,26 @@ test262_eval_script (const jerry_call_info_t *call_info_p, /**< call information if (args_cnt < 1 || !jerry_value_is_string (args_p[0])) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Expected a string"); + return jerry_throw_sz (JERRY_ERROR_TYPE, "Expected a string"); } - jerry_size_t str_size = jerry_get_utf8_string_size (args_p[0]); + jerry_size_t str_size = jerry_string_size (args_p[0], JERRY_ENCODING_UTF8); jerry_char_t *str_buf_p = malloc (str_size * sizeof (jerry_char_t)); - if (str_buf_p == NULL || jerry_string_to_utf8_char_buffer (args_p[0], str_buf_p, str_size) != str_size) + if (str_buf_p == NULL) { - free (str_buf_p); - return jerry_create_error (JERRY_ERROR_RANGE, (jerry_char_t *) "Internal error"); + return jerry_throw_sz (JERRY_ERROR_RANGE, "Internal allocation error"); } + jerry_string_to_buffer (args_p[0], str_buf_p, str_size, JERRY_ENCODING_UTF8); + jerry_value_t ret_value = jerry_parse (str_buf_p, str_size, NULL); - if (!jerry_value_is_error (ret_value)) + if (!jerry_value_is_exception (ret_value)) { jerry_value_t func_val = ret_value; ret_value = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); } free (str_buf_p); @@ -161,12 +162,12 @@ test262_create_realm (const jerry_call_info_t *call_info_p, /**< call informatio (void) args_p; /* unused */ (void) args_cnt; /* unused */ - jerry_value_t realm_object = jerry_create_realm (); + jerry_value_t realm_object = jerry_realm (); jerry_value_t previous_realm = jerry_set_realm (realm_object); - assert (!jerry_value_is_error (previous_realm)); + assert (!jerry_value_is_exception (previous_realm)); jerry_value_t test262_object = create_test262 (realm_object); jerry_set_realm (previous_realm); - jerry_release_value (realm_object); + jerry_value_free (realm_object); return test262_object; } /* test262_create_realm */ @@ -179,24 +180,26 @@ test262_create_realm (const jerry_call_info_t *call_info_p, /**< call informatio static jerry_value_t create_test262 (jerry_value_t global_obj) /**< global object */ { - jerry_value_t test262_object = jerry_create_object (); + jerry_value_t test262_object = jerry_object (); test262_register_function (test262_object, "detachArrayBuffer", test262_detach_array_buffer); test262_register_function (test262_object, "evalScript", test262_eval_script); test262_register_function (test262_object, "createRealm", test262_create_realm); test262_register_function (test262_object, "gc", jerryx_handler_gc); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "global"); - jerry_value_t result = jerry_set_property (test262_object, prop_name, global_obj); - assert (!jerry_value_is_error (result)); - jerry_release_value (prop_name); - jerry_release_value (result); - prop_name = jerry_create_string ((const jerry_char_t *) "$262"); - result = jerry_set_property (global_obj, prop_name, test262_object); + jerry_value_t prop_name = jerry_string_sz ("global"); + jerry_value_t result = jerry_object_set (test262_object, prop_name, global_obj); + assert (!jerry_value_is_exception (result)); + + jerry_value_free (prop_name); + jerry_value_free (result); + + prop_name = jerry_string_sz ("$262"); + result = jerry_object_set (global_obj, prop_name, test262_object); + assert (!jerry_value_is_exception (result)); - jerry_release_value (prop_name); - assert (!jerry_value_is_error (result)); - jerry_release_value (result); + jerry_value_free (prop_name); + jerry_value_free (result); return test262_object; } /* create_test262 */ @@ -216,12 +219,12 @@ promise_callback (jerry_promise_event_type_t event_type, /**< event type */ return; } - jerry_value_t reason = jerry_get_promise_result (object); + jerry_value_t reason = jerry_promise_result (object); jerry_value_t reason_to_string = jerry_value_to_string (reason); - if (!jerry_value_is_error (reason_to_string)) + if (!jerry_value_is_exception (reason_to_string)) { - jerry_size_t buffer_size = jerry_get_utf8_string_size (reason_to_string); + jerry_size_t buffer_size = jerry_string_size (reason_to_string, JERRY_ENCODING_UTF8); if (buffer_size > max_allowed_size) { @@ -229,7 +232,7 @@ promise_callback (jerry_promise_event_type_t event_type, /**< event type */ } JERRY_VLA (jerry_char_t, str_buf_p, buffer_size + 1); - jerry_string_to_utf8_char_buffer (reason_to_string, str_buf_p, buffer_size); + jerry_string_to_buffer (reason_to_string, str_buf_p, buffer_size, JERRY_ENCODING_UTF8); str_buf_p[buffer_size] = '\0'; jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught Promise rejection: %s\n", str_buf_p); @@ -239,8 +242,8 @@ promise_callback (jerry_promise_event_type_t event_type, /**< event type */ jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught Promise rejection (reason cannot be converted to string)\n"); } - jerry_release_value (reason_to_string); - jerry_release_value (reason); + jerry_value_free (reason_to_string); + jerry_value_free (reason); } /* promise_callback */ /** @@ -251,7 +254,7 @@ main_init_engine (main_args_t *arguments_p) /**< main arguments */ { jerry_init (arguments_p->init_flags); - jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_ERROR, promise_callback, NULL); + jerry_promise_event_cb (JERRY_PROMISE_EVENT_FILTER_ERROR, promise_callback, NULL); if (arguments_p->option_flags & OPT_FLAG_DEBUG_SERVER) { @@ -279,15 +282,15 @@ main_init_engine (main_args_t *arguments_p) /**< main arguments */ } if (arguments_p->option_flags & OPT_FLAG_TEST262_OBJECT) { - jerry_value_t global_obj = jerry_get_global_object (); + jerry_value_t global_obj = jerry_current_realm (); jerry_value_t test262_object = create_test262 (global_obj); - jerry_release_value (test262_object); - jerry_release_value (global_obj); + jerry_value_free (test262_object); + jerry_value_free (global_obj); } main_register_global_function ("assert", jerryx_handler_assert); main_register_global_function ("gc", jerryx_handler_gc); main_register_global_function ("print", jerryx_handler_print); - main_register_global_function ("resourceName", jerryx_handler_resource_name); + main_register_global_function ("resourceName", jerryx_handler_source_name); main_register_global_function ("createRealm", main_create_realm); } /* main_init_engine */ @@ -299,129 +302,118 @@ main_init_engine (main_args_t *arguments_p) /**< main arguments */ void main_print_unhandled_exception (jerry_value_t error_value) /**< error value */ { - assert (jerry_value_is_error (error_value)); - error_value = jerry_get_value_from_error (error_value, true); + assert (jerry_value_is_exception (error_value)); + error_value = jerry_exception_value (error_value, true); jerry_char_t err_str_buf[256]; jerry_value_t err_str_val = jerry_value_to_string (error_value); - jerry_size_t err_str_size = jerry_get_utf8_string_size (err_str_val); - if (err_str_size >= 256) - { - const char msg[] = "[Error message too long]"; - err_str_size = sizeof (msg) / sizeof (char) - 1; - memcpy (err_str_buf, msg, err_str_size + 1); - } - else - { - jerry_size_t string_end = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size); - assert (string_end == err_str_size); - err_str_buf[string_end] = 0; + jerry_size_t string_end = + jerry_string_to_buffer (err_str_val, err_str_buf, sizeof (err_str_buf) - 1, JERRY_ENCODING_UTF8); + err_str_buf[string_end] = '\0'; - if (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES) - && jerry_get_error_type (error_value) == JERRY_ERROR_SYNTAX) + if (jerry_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES) && jerry_error_type (error_value) == JERRY_ERROR_SYNTAX) + { + jerry_char_t *string_end_p = err_str_buf + string_end; + unsigned int err_line = 0; + unsigned int err_col = 0; + char *path_str_p = NULL; + char *path_str_end_p = NULL; + + /* 1. parse column and line information */ + for (jerry_char_t *current_p = err_str_buf; current_p < string_end_p; current_p++) { - jerry_char_t *string_end_p = err_str_buf + string_end; - unsigned int err_line = 0; - unsigned int err_col = 0; - char *path_str_p = NULL; - char *path_str_end_p = NULL; - - /* 1. parse column and line information */ - for (jerry_char_t *current_p = err_str_buf; current_p < string_end_p; current_p++) + if (*current_p == '[') { - if (*current_p == '[') + current_p++; + + if (*current_p == '<') { - current_p++; + break; + } - if (*current_p == '<') - { - break; - } + path_str_p = (char *) current_p; + while (current_p < string_end_p && *current_p != ':') + { + current_p++; + } - path_str_p = (char *) current_p; - while (current_p < string_end_p && *current_p != ':') - { - current_p++; - } + path_str_end_p = (char *) current_p++; - path_str_end_p = (char *) current_p++; + err_line = (unsigned int) strtol ((char *) current_p, (char **) ¤t_p, 10); - err_line = (unsigned int) strtol ((char *) current_p, (char **) ¤t_p, 10); + current_p++; - current_p++; + err_col = (unsigned int) strtol ((char *) current_p, NULL, 10); + break; + } + } /* for */ - err_col = (unsigned int) strtol ((char *) current_p, NULL, 10); - break; - } - } /* for */ + if (err_line != 0 && err_col > 0 && err_col < SYNTAX_ERROR_MAX_LINE_LENGTH) + { + /* Temporarily modify the error message, so we can use the path. */ + *path_str_end_p = '\0'; - if (err_line != 0 && err_col > 0 && err_col < SYNTAX_ERROR_MAX_LINE_LENGTH) - { - /* Temporarily modify the error message, so we can use the path. */ - *path_str_end_p = '\0'; + size_t source_size; + uint8_t *source_p = jerry_port_read_source (path_str_p, &source_size); - size_t source_size; - uint8_t *source_p = jerry_port_read_source (path_str_p, &source_size); + /* Revert the error message. */ + *path_str_end_p = ':'; - /* Revert the error message. */ - *path_str_end_p = ':'; + if (source_p != NULL) + { + uint32_t curr_line = 1; + uint32_t pos = 0; - if (source_p != NULL) + /* 2. seek and print */ + while (pos < source_size && curr_line < err_line) { - uint32_t curr_line = 1; - uint32_t pos = 0; - - /* 2. seek and print */ - while (pos < source_size && curr_line < err_line) + if (source_p[pos] == '\n') { - if (source_p[pos] == '\n') - { - curr_line++; - } - - pos++; + curr_line++; } - /* Print character if: - * - The max line length is not reached. - * - The current position is valid (it is not the end of the source). - * - The current character is not a newline. - **/ - for (uint32_t char_count = 0; - (char_count < SYNTAX_ERROR_MAX_LINE_LENGTH) && (pos < source_size) && (source_p[pos] != '\n'); - char_count++, pos++) - { - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%c", source_p[pos]); - } - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "\n"); + pos++; + } - jerry_port_release_source (source_p); + /* Print character if: + * - The max line length is not reached. + * - The current position is valid (it is not the end of the source). + * - The current character is not a newline. + **/ + for (uint32_t char_count = 0; + (char_count < SYNTAX_ERROR_MAX_LINE_LENGTH) && (pos < source_size) && (source_p[pos] != '\n'); + char_count++, pos++) + { + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%c", source_p[pos]); + } + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "\n"); - while (--err_col) - { - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "~"); - } + jerry_port_release_source (source_p); - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "^\n\n"); + while (--err_col) + { + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "~"); } + + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "^\n\n"); } } } - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%s\n", err_str_buf); - jerry_release_value (err_str_val); + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Unhandled exception: %s\n", err_str_buf); + jerry_value_free (err_str_val); if (jerry_value_is_object (error_value)) { - jerry_value_t stack_str = jerry_create_string ((const jerry_char_t *) "stack"); - jerry_value_t backtrace_val = jerry_get_property (error_value, stack_str); - jerry_release_value (stack_str); + jerry_value_t stack_str = jerry_string_sz ("stack"); + jerry_value_t backtrace_val = jerry_object_get (error_value, stack_str); + jerry_value_free (stack_str); if (jerry_value_is_array (backtrace_val)) { - uint32_t length = jerry_get_array_length (backtrace_val); + uint32_t length = jerry_array_length (backtrace_val); /* This length should be enough. */ if (length > 32) @@ -431,34 +423,24 @@ main_print_unhandled_exception (jerry_value_t error_value) /**< error value */ for (uint32_t i = 0; i < length; i++) { - jerry_value_t item_val = jerry_get_property_by_index (backtrace_val, i); + jerry_value_t item_val = jerry_object_get_index (backtrace_val, i); if (jerry_value_is_string (item_val)) { - jerry_size_t str_size = jerry_get_utf8_string_size (item_val); + string_end = jerry_string_to_buffer (item_val, err_str_buf, sizeof (err_str_buf) - 1, JERRY_ENCODING_UTF8); + err_str_buf[string_end] = '\0'; - if (str_size >= 256) - { - printf ("%6u: [Backtrace string too long]\n", i); - } - else - { - jerry_size_t string_end = jerry_string_to_utf8_char_buffer (item_val, err_str_buf, str_size); - assert (string_end == str_size); - err_str_buf[string_end] = 0; - - printf ("%6u: %s\n", i, err_str_buf); - } + printf ("%6u: %s\n", i, err_str_buf); } - jerry_release_value (item_val); + jerry_value_free (item_val); } } - jerry_release_value (backtrace_val); + jerry_value_free (backtrace_val); } - jerry_release_value (error_value); + jerry_value_free (error_value); } /* main_print_unhandled_exception */ /** @@ -467,8 +449,8 @@ main_print_unhandled_exception (jerry_value_t error_value) /**< error value */ * @return result fo the source code execution */ jerry_value_t -main_wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource name */ - size_t resource_name_size, /**< size of resource name */ +main_wait_for_source_callback (const jerry_char_t *source_name_p, /**< resource name */ + size_t source_name_size, /**< size of resource name */ const jerry_char_t *source_p, /**< source code */ size_t source_size, /**< source code size */ void *user_p) /**< user pointer */ @@ -476,18 +458,18 @@ main_wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resourc (void) user_p; /* unused */ jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string_sz (resource_name_p, (jerry_size_t) resource_name_size); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string (source_name_p, (jerry_size_t) source_name_size, JERRY_ENCODING_UTF8); jerry_value_t ret_val = jerry_parse (source_p, source_size, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); - if (!jerry_value_is_error (ret_val)) + if (!jerry_value_is_exception (ret_val)) { jerry_value_t func_val = ret_val; ret_val = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); } return ret_val; @@ -509,32 +491,32 @@ main_is_value_reset (jerry_value_t value) /**< jerry value */ return false; } - jerry_value_t abort_value = jerry_get_value_from_error (value, false); + jerry_value_t abort_value = jerry_exception_value (value, false); if (!jerry_value_is_string (abort_value)) { - jerry_release_value (abort_value); + jerry_value_free (abort_value); return false; } static const char restart_str[] = "r353t"; - jerry_size_t str_size = jerry_get_string_size (abort_value); + jerry_size_t str_size = jerry_string_size (abort_value, JERRY_ENCODING_CESU8); bool is_reset = false; if (str_size == sizeof (restart_str) - 1) { JERRY_VLA (jerry_char_t, str_buf, str_size); - jerry_string_to_char_buffer (abort_value, str_buf, str_size); + jerry_string_to_buffer (abort_value, str_buf, str_size, JERRY_ENCODING_CESU8); is_reset = memcmp (restart_str, (char *) (str_buf), str_size) == 0; if (is_reset) { - jerry_release_value (value); + jerry_value_free (value); } } - jerry_release_value (abort_value); + jerry_value_free (abort_value); return is_reset; } /* main_is_value_reset */ diff --git a/jerry-main/main-utils.h b/jerry-main/main-utils.h index 777dd46c1b..9e6958d4ec 100644 --- a/jerry-main/main-utils.h +++ b/jerry-main/main-utils.h @@ -29,8 +29,8 @@ void main_init_engine (main_args_t *arguments_p); void main_print_unhandled_exception (jerry_value_t error_value); -jerry_value_t main_wait_for_source_callback (const jerry_char_t *resource_name_p, - size_t resource_name_size, +jerry_value_t main_wait_for_source_callback (const jerry_char_t *source_name_p, + size_t source_name_size, const jerry_char_t *source_p, size_t source_size, void *user_p); diff --git a/jerry-port/default/default-module.c b/jerry-port/default/default-module.c index 1cc0d55d8e..50649dbe55 100644 --- a/jerry-port/default/default-module.c +++ b/jerry-port/default/default-module.c @@ -250,8 +250,8 @@ jerry_port_module_free (jerry_port_module_manager_t *manager_p, /**< module mana if (release_all || module_p->realm == realm) { free (module_p->path_p); - jerry_release_value (module_p->realm); - jerry_release_value (module_p->module); + jerry_value_free (module_p->realm); + jerry_value_free (module_p->module); free (module_p); @@ -288,9 +288,9 @@ jerry_port_module_manager_init (void *user_data_p) static void jerry_port_module_manager_deinit (void *user_data_p) /**< context pointer to deinitialize */ { - jerry_value_t undef = jerry_create_undefined (); + jerry_value_t undef = jerry_undefined (); jerry_port_module_free ((jerry_port_module_manager_t *) user_data_p, undef); - jerry_release_value (undef); + jerry_value_free (undef); } /* jerry_port_module_manager_deinit */ /** @@ -313,32 +313,32 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { (void) user_p; - jerry_port_module_t *module_p; const jerry_char_t *base_path_p = NULL; size_t base_path_length = 0; + jerry_port_module_t *module_p = jerry_object_get_native_ptr (referrer, &jerry_port_module_native_info); - if (jerry_get_object_native_pointer (referrer, (void **) &module_p, &jerry_port_module_native_info)) + if (module_p != NULL) { base_path_p = module_p->path_p; base_path_length = module_p->base_path_length; } - jerry_size_t in_path_length = jerry_get_utf8_string_size (specifier); + jerry_size_t in_path_length = jerry_string_size (specifier, JERRY_ENCODING_UTF8); jerry_char_t *in_path_p = (jerry_char_t *) malloc (in_path_length + 1); - jerry_string_to_utf8_char_buffer (specifier, in_path_p, in_path_length); + jerry_string_to_buffer (specifier, in_path_p, in_path_length, JERRY_ENCODING_UTF8); in_path_p[in_path_length] = '\0'; jerry_char_t *path_p = jerry_port_normalize_path (in_path_p, in_path_length, base_path_p, base_path_length); if (path_p == NULL) { - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Out of memory"); + return jerry_throw_sz (JERRY_ERROR_COMMON, "Out of memory"); } - jerry_value_t realm = jerry_get_global_object (); + jerry_value_t realm = jerry_current_realm (); jerry_port_module_manager_t *manager_p; - manager_p = (jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager); + manager_p = (jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager); module_p = manager_p->module_head_p; @@ -348,8 +348,8 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { free (path_p); free (in_path_p); - jerry_release_value (realm); - return jerry_acquire_value (module_p->module); + jerry_value_free (realm); + return jerry_value_copy (module_p->module); } module_p = module_p->next_p; @@ -362,26 +362,26 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { free (path_p); free (in_path_p); - jerry_release_value (realm); + jerry_value_free (realm); /* TODO: This is incorrect, but makes test262 module tests pass * (they should throw SyntaxError, but not because the module cannot be found). */ - return jerry_create_error (JERRY_ERROR_SYNTAX, (const jerry_char_t *) "Module file not found"); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, "Module file not found"); } jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string_sz ((const jerry_char_t *) in_path_p, in_path_length); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string (in_path_p, in_path_length, JERRY_ENCODING_UTF8); jerry_value_t ret_value = jerry_parse (source_p, source_size, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); jerry_port_release_source (source_p); free (in_path_p); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { free (path_p); - jerry_release_value (realm); + jerry_value_free (realm); return ret_value; } @@ -391,9 +391,9 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier module_p->path_p = path_p; module_p->base_path_length = jerry_port_get_directory_end (module_p->path_p); module_p->realm = realm; - module_p->module = jerry_acquire_value (ret_value); + module_p->module = jerry_value_copy (ret_value); - jerry_set_object_native_pointer (ret_value, module_p, &jerry_port_module_native_info); + jerry_object_set_native_ptr (ret_value, &jerry_port_module_native_info, module_p); manager_p->module_head_p = module_p; return ret_value; @@ -406,5 +406,5 @@ void jerry_port_module_release (const jerry_value_t realm) /**< if this argument is object, release only those modules, * which realm value is equal to this argument. */ { - jerry_port_module_free ((jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager), realm); + jerry_port_module_free ((jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager), realm); } /* jerry_port_module_release */ diff --git a/targets/curie_bsp/jerry_app/quark/main.c b/targets/curie_bsp/jerry_app/quark/main.c index 2975bbb0bb..d45a2f73c6 100644 --- a/targets/curie_bsp/jerry_app/quark/main.c +++ b/targets/curie_bsp/jerry_app/quark/main.c @@ -13,59 +13,60 @@ * limitations under the License. */ -#include #include +#include #include /* Infra */ +#include "cfw/cfw.h" #include "infra/bsp.h" -#include "infra/reboot.h" #include "infra/log.h" -#include "infra/time.h" +#include "infra/reboot.h" #include "infra/system_events.h" #include "infra/tcmd/handler.h" - -#include "cfw/cfw.h" +#include "infra/time.h" /* Watchdog helper */ -#include "infra/wdt_helper.h" - -#include "jerryscript.h" #include "jerryscript-port.h" -#include "string.h" +#include "jerryscript.h" -#include "zephyr.h" +#include "infra/wdt_helper.h" #include "microkernel/task.h" -#include "os/os.h" #include "misc/printk.h" +#include "os/os.h" +#include "string.h" +#include "zephyr.h" static T_QUEUE queue; jerry_value_t print_function; -void jerry_resolve_error (jerry_value_t ret_value) +void +jerry_resolve_error (jerry_value_t ret_value) { - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { - ret_value = jerry_get_value_from_error (ret_value, true); + ret_value = jerry_exception_value (ret_value, true); jerry_value_t err_str_val = jerry_value_to_string (ret_value); - jerry_size_t err_str_size = jerry_get_utf8_string_size (err_str_val); + jerry_size_t err_str_size = jerry_string_size (err_str_val, JERRY_ENCODING_UTF8); jerry_char_t *err_str_buf = (jerry_char_t *) balloc (err_str_size, NULL); - jerry_size_t sz = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size); + jerry_size_t sz = jerry_string_to_buffer (err_str_val, err_str_buf, err_str_size, JERRY_ENCODING_UTF8); err_str_buf[sz] = 0; printk ("Script Error: unhandled exception: %s\n", err_str_buf); - bfree(err_str_buf); - jerry_release_value (err_str_val); + bfree (err_str_buf); + jerry_value_free (err_str_val); } } -void help () +void +help () { printk ("Usage:\n"); printk ("js e 'JavaScript Command'\n"); printk ("eg. js e print ('Hello World');\n"); } -void eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx) +void +eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx) { if (argc < 3) { @@ -77,7 +78,7 @@ void eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx) { OS_ERR_TYPE err; size_t str_total_length = 0; - size_t *str_lens = (size_t *) balloc ((argc - 2) * sizeof(size_t), &err); + size_t *str_lens = (size_t *) balloc ((argc - 2) * sizeof (size_t), &err); if (str_lens == NULL || err != E_OS_OK) { printk ("%s: allocate memory failed!", __func__); @@ -101,7 +102,7 @@ void eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx) char *p = buffer; for (int i = 2; i < argc; ++i) { - for (int j =0; j < str_lens[i - 2]; ++j) + for (int j = 0; j < str_lens[i - 2]; ++j) { *p = argv[i][j]; ++p; @@ -113,41 +114,44 @@ void eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx) jerry_value_t eval_ret = jerry_eval (buffer, str_total_length - 1, JERRY_PARSE_NO_OPTS); - if (jerry_value_is_error (eval_ret)) + if (jerry_value_is_exception (eval_ret)) { jerry_resolve_error (eval_ret); TCMD_RSP_ERROR (ctx, NULL); } else { - jerry_value_t args[] = {eval_ret}; - jerry_value_t ret_val_print = jerry_call_function (print_function, - jerry_create_undefined (), - args, - 1); - jerry_release_value (ret_val_print); + jerry_value_t args[] = { eval_ret }; + jerry_value_t ret_val_print = jerry_call (print_function, jerry_undefined (), args, 1); + jerry_value_free (ret_val_print); TCMD_RSP_FINAL (ctx, NULL); } - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); bfree (buffer); bfree (str_lens); } } -void jerry_start () +void +jerry_start () { - union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () }; + union + { + double d; + unsigned u; + } now = { .d = jerry_port_get_current_time () }; srand (now.u); jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_obj_val = jerry_get_global_object (); - jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print"); - print_function = jerry_get_property (global_obj_val, print_func_name_val); - jerry_release_value (print_func_name_val); - jerry_release_value (global_obj_val); + jerry_value_t global_obj_val = jerry_current_realm (); + jerry_value_t print_func_name_val = jerry_string_sz ("print"); + print_function = jerry_object_get (global_obj_val, print_func_name_val); + jerry_value_free (print_func_name_val); + jerry_value_free (global_obj_val); } /* Application main entry point */ -void main_task (void *param) +void +main_task (void *param) { /* Init BSP (also init BSP on ARC core) */ queue = bsp_init (); diff --git a/targets/esp-idf/jerry_module.c b/targets/esp-idf/jerry_module.c index 97f92dcfdb..c57b6e6276 100644 --- a/targets/esp-idf/jerry_module.c +++ b/targets/esp-idf/jerry_module.c @@ -14,12 +14,12 @@ */ #include -#include #include +#include #include -#include "jerryscript.h" #include "jerryscript-port.h" +#include "jerryscript.h" /** * Computes the end of the directory part of a path. @@ -102,8 +102,7 @@ typedef struct jerry_port_module_t /** * Native info descriptor for modules. */ -static const jerry_object_native_info_t jerry_port_module_native_info = -{ +static const jerry_object_native_info_t jerry_port_module_native_info = { .free_cb = NULL, }; @@ -136,8 +135,8 @@ jerry_port_module_free (jerry_port_module_manager_t *manager_p, /**< module mana if (release_all || module_p->realm == realm) { free (module_p->path_p); - jerry_release_value (module_p->realm); - jerry_release_value (module_p->module); + jerry_value_free (module_p->realm); + jerry_value_free (module_p->module); free (module_p); @@ -174,20 +173,18 @@ jerry_port_module_manager_init (void *user_data_p) static void jerry_port_module_manager_deinit (void *user_data_p) /**< context pointer to deinitialize */ { - jerry_value_t undef = jerry_create_undefined (); + jerry_value_t undef = jerry_undefined (); jerry_port_module_free ((jerry_port_module_manager_t *) user_data_p, undef); - jerry_release_value (undef); + jerry_value_free (undef); } /* jerry_port_module_manager_deinit */ /** * Declare the context data manager for modules. */ -static const jerry_context_data_manager_t jerry_port_module_manager = -{ - .init_cb = jerry_port_module_manager_init, - .deinit_cb = jerry_port_module_manager_deinit, - .bytes_needed = sizeof (jerry_port_module_manager_t) -}; +static const jerry_context_data_manager_t jerry_port_module_manager = { .init_cb = jerry_port_module_manager_init, + .deinit_cb = jerry_port_module_manager_deinit, + .bytes_needed = + sizeof (jerry_port_module_manager_t) }; /** * Default module resolver. @@ -201,44 +198,43 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { (void) user_p; - jerry_port_module_t *module_p; const jerry_char_t *base_path_p = NULL; size_t base_path_length = 0; + jerry_port_module_t *module_p = jerry_object_get_native_ptr (referrer, &jerry_port_module_native_info); - if (jerry_get_object_native_pointer (referrer, (void **) &module_p, &jerry_port_module_native_info)) + if (module_p != NULL) { base_path_p = module_p->path_p; base_path_length = module_p->base_path_length; } - jerry_size_t in_path_length = jerry_get_utf8_string_size (specifier); + jerry_size_t in_path_length = jerry_string_size (specifier, JERRY_ENCODING_UTF8); jerry_char_t *in_path_p = (jerry_char_t *) malloc (in_path_length + 1); - jerry_string_to_utf8_char_buffer (specifier, in_path_p, in_path_length); + jerry_string_to_buffer (specifier, in_path_p, in_path_length, JERRY_ENCODING_UTF8); in_path_p[in_path_length] = '\0'; jerry_char_t *path_p = jerry_port_normalize_path (in_path_p, in_path_length, base_path_p, base_path_length); if (path_p == NULL) { - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Out of memory"); + return jerry_throw_sz (JERRY_ERROR_COMMON, "Out of memory"); } - jerry_value_t realm = jerry_get_global_object (); + jerry_value_t realm = jerry_current_realm (); jerry_port_module_manager_t *manager_p; - manager_p = (jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager); + manager_p = (jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager); module_p = manager_p->module_head_p; while (module_p != NULL) { - if (module_p->realm == realm - && strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0) + if (module_p->realm == realm && strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0) { free (path_p); free (in_path_p); - jerry_release_value (realm); - return jerry_acquire_value (module_p->module); + jerry_value_free (realm); + return jerry_value_copy (module_p->module); } module_p = module_p->next_p; @@ -251,28 +247,24 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { free (path_p); free (in_path_p); - jerry_release_value (realm); - /* TODO: This is incorrect, but makes test262 module tests pass - * (they should throw SyntaxError, but not because the module cannot be found). */ - return jerry_create_error (JERRY_ERROR_SYNTAX, (const jerry_char_t *) "Module file not found"); + jerry_value_free (realm); + return jerry_throw_sz (JERRY_ERROR_SYNTAX, "Module file not found"); } jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string_sz ((const jerry_char_t *) in_path_p, in_path_length); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string ((const jerry_char_t *) in_path_p, in_path_length, JERRY_ENCODING_UTF8); - jerry_value_t ret_value = jerry_parse (source_p, - source_size, - &parse_options); + jerry_value_t ret_value = jerry_parse (source_p, source_size, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); jerry_port_release_source (source_p); free (in_path_p); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { free (path_p); - jerry_release_value (realm); + jerry_value_free (realm); return ret_value; } @@ -282,9 +274,9 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier module_p->path_p = path_p; module_p->base_path_length = jerry_port_get_directory_end (module_p->path_p); module_p->realm = realm; - module_p->module = jerry_acquire_value (ret_value); + module_p->module = jerry_value_copy (ret_value); - jerry_set_object_native_pointer (ret_value, module_p, &jerry_port_module_native_info); + jerry_object_set_native_ptr (ret_value, &jerry_port_module_native_info, module_p); manager_p->module_head_p = module_p; return ret_value; @@ -297,6 +289,5 @@ void jerry_port_module_release (const jerry_value_t realm) /**< if this argument is object, release only those modules, * which realm value is equal to this argument. */ { - jerry_port_module_free ((jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager), - realm); + jerry_port_module_free ((jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager), realm); } /* jerry_port_module_release */ diff --git a/targets/esp8266/user/jerry_extapi.c b/targets/esp8266/user/jerry_extapi.c index 930319c101..f3a99365a1 100644 --- a/targets/esp8266/user/jerry_extapi.c +++ b/targets/esp8266/user/jerry_extapi.c @@ -13,67 +13,64 @@ * limitations under the License. */ -#include +#include "jerry_extapi.h" + #include +#include + +#include "jerryscript.h" #include "c_types.h" #include "gpio.h" -#include "jerryscript.h" -#include "jerry_extapi.h" - -#define __UNUSED__ __attribute__((unused)) +#define __UNUSED__ __attribute__ ((unused)) -#define DELCARE_HANDLER(NAME) \ -static jerry_value_t \ -NAME ## _handler (const jerry_call_info_t *call_info_p __UNUSED__, \ - const jerry_value_t args_p[], \ - const jerry_length_t args_cnt) +#define DELCARE_HANDLER(NAME) \ + static jerry_value_t NAME##_handler (const jerry_call_info_t *call_info_p __UNUSED__, \ + const jerry_value_t args_p[], \ + const jerry_length_t args_cnt) -#define REGISTER_HANDLER(NAME) \ - register_native_function ( # NAME, NAME ## _handler) +#define REGISTER_HANDLER(NAME) register_native_function (#NAME, NAME##_handler) -DELCARE_HANDLER(assert) { - if (args_cnt == 1 - && jerry_value_is_true (args_p[0])) +DELCARE_HANDLER (assert) +{ + if (args_cnt == 1 && jerry_value_is_true (args_p[0])) { printf (">> Jerry assert true\r\n"); - return jerry_create_boolean (true); + return jerry_boolean (true); } printf ("Script assertion failed\n"); exit (JERRY_STANDALONE_EXIT_CODE_FAIL); - return jerry_create_boolean (false); + return jerry_boolean (false); } /* assert */ - -DELCARE_HANDLER(print) { +DELCARE_HANDLER (print) +{ if (args_cnt) { for (jerry_length_t cc = 0; cc < args_cnt; cc++) { if (jerry_value_is_string (args_p[cc])) { - jerry_size_t size = jerry_get_utf8_string_size (args_p[0]); + jerry_size_t size = jerry_string_size (args_p[0], JERRY_ENCODING_UTF8); char *buffer; - buffer = (char *) malloc(size + 1); + buffer = (char *) malloc (size + 1); - if(!buffer) + if (!buffer) { - // not enough memory for this string. - printf("[]"); - continue; + // not enough memory for this string. + printf ("[]"); + continue; } - jerry_string_to_utf8_char_buffer (args_p[cc], - (jerry_char_t *) buffer, - size); - *(buffer + size) = 0; - printf("%s ", buffer); + jerry_string_to_buffer (args_p[cc], (jerry_char_t *) buffer, size, JERRY_ENCODING_UTF8); + buffer[size] = '\0'; + printf ("%s ", buffer); free (buffer); } else if (jerry_value_is_number (args_p[cc])) { - double number = jerry_get_number_value (args_p[cc]); + double number = jerry_value_as_number (args_p[cc]); if ((int) number == number) { printf ("%d", (int) number); @@ -81,106 +78,105 @@ DELCARE_HANDLER(print) { else { char buff[50]; - sprintf(buff, "%.10f", number); - printf("%s", buff); + sprintf (buff, "%.10f", number); + printf ("%s", buff); } - } } printf ("\r\n"); } - return jerry_create_boolean (true); + return jerry_boolean (true); } /* print */ -DELCARE_HANDLER(gpio_dir) { +DELCARE_HANDLER (gpio_dir) +{ if (args_cnt < 2) { - return jerry_create_boolean (false); + return jerry_boolean (false); } - int port = (int) jerry_get_number_value (args_p[0]); - int value = (int) jerry_get_number_value (args_p[1]); + int port = (int) jerry_value_as_number (args_p[0]); + int value = (int) jerry_value_as_number (args_p[1]); if (value) { - GPIO_AS_OUTPUT(1 << port); + GPIO_AS_OUTPUT (1 << port); } else { - GPIO_AS_INPUT(1 << port); + GPIO_AS_INPUT (1 << port); } - return jerry_create_boolean (true); + return jerry_boolean (true); } /* gpio_dir */ -DELCARE_HANDLER(gpio_set) { +DELCARE_HANDLER (gpio_set) +{ if (args_cnt < 2) { - return jerry_create_boolean (false); + return jerry_boolean (false); } - int port = (int) jerry_get_number_value (args_p[0]); - int value = (int) jerry_get_number_value (args_p[1]); + int port = (int) jerry_value_as_number (args_p[0]); + int value = (int) jerry_value_as_number (args_p[1]); - GPIO_OUTPUT_SET(port, value); + GPIO_OUTPUT_SET (port, value); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* gpio_set */ - -DELCARE_HANDLER(gpio_get) { +DELCARE_HANDLER (gpio_get) +{ if (args_cnt < 1) { - return jerry_create_boolean (false); + return jerry_boolean (false); } - int port = (int) jerry_get_number_value (args_p[0]); - int value = GPIO_INPUT_GET(port) ? 1 : 0; + int port = (int) jerry_value_as_number (args_p[0]); + int value = GPIO_INPUT_GET (port) ? 1 : 0; - return jerry_create_number ((double) value); + return jerry_number ((double) value); } /* gpio_get */ static bool -register_native_function (const char* name, - jerry_external_handler_t handler) +register_native_function (const char *name, jerry_external_handler_t handler) { - jerry_value_t global_obj_val = jerry_get_global_object (); - jerry_value_t reg_func_val = jerry_create_external_function (handler); - bool bok = true; + jerry_value_t global_obj_val = jerry_current_realm (); + jerry_value_t reg_func_val = jerry_function_external (handler); - if (!(jerry_value_is_function (reg_func_val) - && jerry_value_is_constructor (reg_func_val))) + if (!(jerry_value_is_function (reg_func_val) && jerry_value_is_constructor (reg_func_val))) { printf ("!!! create_external_function failed !!!\r\n"); - jerry_release_value (reg_func_val); - jerry_release_value (global_obj_val); + jerry_value_free (reg_func_val); + jerry_value_free (global_obj_val); return false; } - jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) name); - jerry_value_t res = jerry_set_property (global_obj_val, prop_name_val, reg_func_val); + jerry_value_t prop_name_val = jerry_string_sz (name); + jerry_value_t res = jerry_object_set (global_obj_val, prop_name_val, reg_func_val); - jerry_release_value (reg_func_val); - jerry_release_value (global_obj_val); - jerry_release_value (prop_name_val); + jerry_value_free (reg_func_val); + jerry_value_free (global_obj_val); + jerry_value_free (prop_name_val); - if (jerry_value_is_error (res)) + if (jerry_value_is_exception (res)) { printf ("!!! register_native_function failed: [%s]\r\n", name); - jerry_release_value (res); + jerry_value_free (res); return false; } - jerry_release_value (res); + jerry_value_free (res); return true; } /* register_native_function */ -void js_register_functions (void) +void +js_register_functions (void) { - REGISTER_HANDLER(assert); - REGISTER_HANDLER(print); - REGISTER_HANDLER(gpio_dir); - REGISTER_HANDLER(gpio_set); - REGISTER_HANDLER(gpio_get); + REGISTER_HANDLER (assert); + REGISTER_HANDLER (print); + REGISTER_HANDLER (gpio_dir); + REGISTER_HANDLER (gpio_set); + REGISTER_HANDLER (gpio_get); } /* js_register_functions */ diff --git a/targets/esp8266/user/jerry_run.c b/targets/esp8266/user/jerry_run.c index e7fff4c375..b3205bac8d 100644 --- a/targets/esp8266/user/jerry_run.c +++ b/targets/esp8266/user/jerry_run.c @@ -13,88 +13,97 @@ * limitations under the License. */ -#include -#include - -#include "jerry_extapi.h" #include "jerry_run.h" -#include "jerryscript.h" +#include +#include + #include "jerryscript-port.h" +#include "jerryscript.h" + +#include "jerry_extapi.h" -static const char* fn_sys_loop_name = "sysloop"; +static const char *fn_sys_loop_name = "sysloop"; -void js_entry () +void +js_entry () { - union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () }; + union + { + double d; + unsigned u; + } now = { .d = jerry_port_get_current_time () }; srand (now.u); jerry_init (JERRY_INIT_EMPTY); js_register_functions (); } -int js_eval (const char *source_p, const size_t source_size) +int +js_eval (const char *source_p, const size_t source_size) { - jerry_value_t res = jerry_eval ((jerry_char_t *) source_p, - source_size, - JERRY_PARSE_NO_OPTS); - if (jerry_value_is_error (res)) { - jerry_release_value (res); + jerry_value_t res = jerry_eval ((jerry_char_t *) source_p, source_size, JERRY_PARSE_NO_OPTS); + if (jerry_value_is_exception (res)) + { + jerry_value_free (res); return -1; } - jerry_release_value (res); + jerry_value_free (res); return 0; } -int js_loop (uint32_t ticknow) +int +js_loop (uint32_t ticknow) { - jerry_value_t global_obj_val = jerry_get_global_object (); - jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) fn_sys_loop_name); - jerry_value_t sysloop_func = jerry_get_property (global_obj_val, prop_name_val); - jerry_release_value (prop_name_val); + jerry_value_t global_obj_val = jerry_current_realm (); + jerry_value_t prop_name_val = jerry_string_sz (fn_sys_loop_name); + jerry_value_t sysloop_func = jerry_object_get (global_obj_val, prop_name_val); + jerry_value_free (prop_name_val); - if (jerry_value_is_error (sysloop_func)) { + if (jerry_value_is_exception (sysloop_func)) + { printf ("Error: '%s' not defined!!!\r\n", fn_sys_loop_name); - jerry_release_value (sysloop_func); - jerry_release_value (global_obj_val); + jerry_value_free (sysloop_func); + jerry_value_free (global_obj_val); return -1; } - if (!jerry_value_is_function (sysloop_func)) { + if (!jerry_value_is_function (sysloop_func)) + { printf ("Error: '%s' is not a function!!!\r\n", fn_sys_loop_name); - jerry_release_value (sysloop_func); - jerry_release_value (global_obj_val); + jerry_value_free (sysloop_func); + jerry_value_free (global_obj_val); return -2; } - jerry_value_t val_args[] = { jerry_create_number (ticknow) }; + jerry_value_t val_args[] = { jerry_number (ticknow) }; uint16_t val_argv = sizeof (val_args) / sizeof (jerry_value_t); - jerry_value_t res = jerry_call_function (sysloop_func, - global_obj_val, - val_args, - val_argv); + jerry_value_t res = jerry_call (sysloop_func, global_obj_val, val_args, val_argv); - for (uint16_t i = 0; i < val_argv; i++) { - jerry_release_value (val_args[i]); + for (uint16_t i = 0; i < val_argv; i++) + { + jerry_value_free (val_args[i]); } - jerry_release_value (sysloop_func); - jerry_release_value (global_obj_val); + jerry_value_free (sysloop_func); + jerry_value_free (global_obj_val); - if (jerry_value_is_error (res)) { - jerry_release_value (res); + if (jerry_value_is_exception (res)) + { + jerry_value_free (res); return -3; } - jerry_release_value (res); + jerry_value_free (res); return 0; } -void js_exit (void) +void +js_exit (void) { jerry_cleanup (); } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/AnalogIn-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/AnalogIn-js.cpp index d05c19ce05..4c3499b85d 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/AnalogIn-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/AnalogIn-js.cpp @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "jerryscript-mbed-util/logging.h" #include "jerryscript-mbed-library-registry/wrap_tools.h" - +#include "jerryscript-mbed-util/logging.h" #include "mbed.h" /** @@ -22,9 +21,11 @@ * * Called if/when the AnalogIn is GC'ed. */ -void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(AnalogIn)(void* void_ptr, jerry_object_native_info_t *info_p) { - (void) info_p; - delete static_cast(void_ptr); +void +NAME_FOR_CLASS_NATIVE_DESTRUCTOR (AnalogIn) (void* void_ptr, jerry_object_native_info_t* info_p) +{ + (void) info_p; + delete static_cast (void_ptr); } /** @@ -32,9 +33,8 @@ void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(AnalogIn)(void* void_ptr, jerry_object_nat * * Set AnalogIn#destructor as the free callback. */ -static const jerry_object_native_info_t native_obj_type_info = { - .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR(AnalogIn) -}; +static const jerry_object_native_info_t native_obj_type_info = { .free_cb = + NAME_FOR_CLASS_NATIVE_DESTRUCTOR (AnalogIn) }; /** * AnalogIn#read (native JavaScript method) @@ -43,22 +43,22 @@ static const jerry_object_native_info_t native_obj_type_info = { * * @returns A floating-point value representing the current input voltage, measured as a percentage */ -DECLARE_CLASS_FUNCTION(AnalogIn, read) { - CHECK_ARGUMENT_COUNT(AnalogIn, read, (args_count == 0)); +DECLARE_CLASS_FUNCTION (AnalogIn, read) +{ + CHECK_ARGUMENT_COUNT (AnalogIn, read, (args_count == 0)); - // Extract native AnalogIn pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native AnalogIn pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native AnalogIn pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native AnalogIn pointer"); + } - AnalogIn* native_ptr = static_cast(void_ptr); + AnalogIn* native_ptr = static_cast (void_ptr); - float result = native_ptr->read(); - return jerry_create_number(result); + float result = native_ptr->read (); + return jerry_number (result); } /** @@ -68,22 +68,22 @@ DECLARE_CLASS_FUNCTION(AnalogIn, read) { * * @returns 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value */ -DECLARE_CLASS_FUNCTION(AnalogIn, read_u16) { - CHECK_ARGUMENT_COUNT(AnalogIn, read_u16, (args_count == 0)); +DECLARE_CLASS_FUNCTION (AnalogIn, read_u16) +{ + CHECK_ARGUMENT_COUNT (AnalogIn, read_u16, (args_count == 0)); - // Extract native AnalogIn pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native AnalogIn pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native AnalogIn pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native AnalogIn pointer"); + } - AnalogIn* native_ptr = static_cast(void_ptr); + AnalogIn* native_ptr = static_cast (void_ptr); - uint16_t result = native_ptr->read_u16(); - return jerry_create_number(result); + uint16_t result = native_ptr->read_u16 (); + return jerry_number (result); } /** @@ -92,22 +92,23 @@ DECLARE_CLASS_FUNCTION(AnalogIn, read_u16) { * @param pin_name mbed pin to connect the AnalogIn to. * @returns a JavaScript object representing a AnalogIn. */ -DECLARE_CLASS_CONSTRUCTOR(AnalogIn) { - CHECK_ARGUMENT_COUNT(AnalogIn, __constructor, args_count == 1); - CHECK_ARGUMENT_TYPE_ALWAYS(AnalogIn, __constructor, 0, number); +DECLARE_CLASS_CONSTRUCTOR (AnalogIn) +{ + CHECK_ARGUMENT_COUNT (AnalogIn, __constructor, args_count == 1); + CHECK_ARGUMENT_TYPE_ALWAYS (AnalogIn, __constructor, 0, number); - PinName pin_name = PinName(jerry_get_number_value(args[0])); + PinName pin_name = PinName (jerry_value_as_number (args[0])); - // create native object - AnalogIn* native_ptr = new AnalogIn(pin_name); + // create native object + AnalogIn* native_ptr = new AnalogIn (pin_name); - // create the jerryscript object - jerry_value_t js_object = jerry_create_object(); - jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); + // create the jerryscript object + jerry_value_t js_object = jerry_object (); + jerry_object_set_native_ptr (js_object, &native_obj_type_info, native_ptr); - // attach methods - ATTACH_CLASS_FUNCTION(js_object, AnalogIn, read); - ATTACH_CLASS_FUNCTION(js_object, AnalogIn, read_u16); + // attach methods + ATTACH_CLASS_FUNCTION (js_object, AnalogIn, read); + ATTACH_CLASS_FUNCTION (js_object, AnalogIn, read_u16); - return js_object; + return js_object; } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/DigitalOut-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/DigitalOut-js.cpp index a521f00e6d..1ab0370776 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/DigitalOut-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/DigitalOut-js.cpp @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "jerryscript-mbed-util/logging.h" #include "jerryscript-mbed-library-registry/wrap_tools.h" - +#include "jerryscript-mbed-util/logging.h" #include "mbed.h" /** @@ -22,9 +21,11 @@ * * Called if/when the DigitalOut is GC'ed. */ -void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(DigitalOut)(void* void_ptr, jerry_object_native_info_t *info_p) { - (void) info_p; - delete static_cast(void_ptr); +void +NAME_FOR_CLASS_NATIVE_DESTRUCTOR (DigitalOut) (void* void_ptr, jerry_object_native_info_t* info_p) +{ + (void) info_p; + delete static_cast (void_ptr); } /** @@ -32,9 +33,8 @@ void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(DigitalOut)(void* void_ptr, jerry_object_n * * Set DigitalOut#destructor as the free callback. */ -static const jerry_object_native_info_t native_obj_type_info = { - .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR(DigitalOut) -}; +static const jerry_object_native_info_t native_obj_type_info = { .free_cb = + NAME_FOR_CLASS_NATIVE_DESTRUCTOR (DigitalOut) }; /** * DigitalOut#write (native JavaScript method) @@ -45,25 +45,25 @@ static const jerry_object_native_info_t native_obj_type_info = { * respectively * @returns undefined, or an error if invalid arguments are provided. */ -DECLARE_CLASS_FUNCTION(DigitalOut, write) { - CHECK_ARGUMENT_COUNT(DigitalOut, write, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(DigitalOut, write, 0, number); +DECLARE_CLASS_FUNCTION (DigitalOut, write) +{ + CHECK_ARGUMENT_COUNT (DigitalOut, write, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (DigitalOut, write, 0, number); - // Extract native DigitalOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native DigitalOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native DigitalOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native DigitalOut pointer"); + } - DigitalOut* native_ptr = static_cast(void_ptr); + DigitalOut* native_ptr = static_cast (void_ptr); - int arg0 = jerry_get_number_value(args[0]); - native_ptr->write(arg0); + int arg0 = jerry_value_as_number (args[0]); + native_ptr->write (arg0); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -73,22 +73,22 @@ DECLARE_CLASS_FUNCTION(DigitalOut, write) { * * @returns 1 if the pin is currently high, or 0 if the pin is currently low. */ -DECLARE_CLASS_FUNCTION(DigitalOut, read) { - CHECK_ARGUMENT_COUNT(DigitalOut, read, (args_count == 0)); +DECLARE_CLASS_FUNCTION (DigitalOut, read) +{ + CHECK_ARGUMENT_COUNT (DigitalOut, read, (args_count == 0)); - // Extract native DigitalOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native DigitalOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native DigitalOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native DigitalOut pointer"); + } - DigitalOut* native_ptr = static_cast(void_ptr); + DigitalOut* native_ptr = static_cast (void_ptr); - int result = native_ptr->read(); - return jerry_create_number(result); + int result = native_ptr->read (); + return jerry_number (result); } /** @@ -97,22 +97,22 @@ DECLARE_CLASS_FUNCTION(DigitalOut, read) { * @returns 0 if the DigitalOut is set to NC, or 1 if it is connected to an * actual pin */ -DECLARE_CLASS_FUNCTION(DigitalOut, is_connected) { - CHECK_ARGUMENT_COUNT(DigitalOut, is_connected, (args_count == 0)); +DECLARE_CLASS_FUNCTION (DigitalOut, is_connected) +{ + CHECK_ARGUMENT_COUNT (DigitalOut, is_connected, (args_count == 0)); - // Extract native DigitalOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native DigitalOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native DigitalOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native DigitalOut pointer"); + } - DigitalOut* native_ptr = static_cast(void_ptr); + DigitalOut* native_ptr = static_cast (void_ptr); - int result = native_ptr->is_connected(); - return jerry_create_number(result); + int result = native_ptr->is_connected (); + return jerry_number (result); } /** @@ -122,35 +122,37 @@ DECLARE_CLASS_FUNCTION(DigitalOut, is_connected) { * @param value (optional) Initial value of the DigitalOut. * @returns a JavaScript object representing a DigitalOut. */ -DECLARE_CLASS_CONSTRUCTOR(DigitalOut) { - CHECK_ARGUMENT_COUNT(DigitalOut, __constructor, (args_count == 1 || args_count == 2)); - CHECK_ARGUMENT_TYPE_ALWAYS(DigitalOut, __constructor, 0, number); - CHECK_ARGUMENT_TYPE_ON_CONDITION(DigitalOut, __constructor, 1, number, (args_count == 2)); - - DigitalOut* native_ptr; - - // Call correct overload of DigitalOut::DigitalOut depending on the - // arguments passed. - PinName pin_name = PinName(jerry_get_number_value(args[0])); - - switch (args_count) { - case 1: - native_ptr = new DigitalOut(pin_name); - break; - case 2: - int value = static_cast(jerry_get_number_value(args[1])); - native_ptr = new DigitalOut(pin_name, value); - break; - } - - // create the jerryscript object - jerry_value_t js_object = jerry_create_object(); - jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); - - // attach methods - ATTACH_CLASS_FUNCTION(js_object, DigitalOut, write); - ATTACH_CLASS_FUNCTION(js_object, DigitalOut, read); - ATTACH_CLASS_FUNCTION(js_object, DigitalOut, is_connected); - - return js_object; +DECLARE_CLASS_CONSTRUCTOR (DigitalOut) +{ + CHECK_ARGUMENT_COUNT (DigitalOut, __constructor, (args_count == 1 || args_count == 2)); + CHECK_ARGUMENT_TYPE_ALWAYS (DigitalOut, __constructor, 0, number); + CHECK_ARGUMENT_TYPE_ON_CONDITION (DigitalOut, __constructor, 1, number, (args_count == 2)); + + DigitalOut* native_ptr; + + // Call correct overload of DigitalOut::DigitalOut depending on the + // arguments passed. + PinName pin_name = PinName (jerry_value_as_number (args[0])); + + switch (args_count) + { + case 1: + native_ptr = new DigitalOut (pin_name); + break; + case 2: + int value = static_cast (jerry_value_as_number (args[1])); + native_ptr = new DigitalOut (pin_name, value); + break; + } + + // create the jerryscript object + jerry_value_t js_object = jerry_object (); + jerry_object_set_native_ptr (js_object, &native_obj_type_info, native_ptr); + + // attach methods + ATTACH_CLASS_FUNCTION (js_object, DigitalOut, write); + ATTACH_CLASS_FUNCTION (js_object, DigitalOut, read); + ATTACH_CLASS_FUNCTION (js_object, DigitalOut, is_connected); + + return js_object; } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/I2C-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/I2C-js.cpp index f622f0a6fc..90cbc83c16 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/I2C-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/I2C-js.cpp @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "jerryscript-mbed-util/logging.h" #include "jerryscript-mbed-drivers/I2C-js.h" -#include "jerryscript-mbed-library-registry/wrap_tools.h" +#include "jerryscript-mbed-library-registry/wrap_tools.h" +#include "jerryscript-mbed-util/logging.h" #include "mbed.h" /** @@ -23,9 +23,11 @@ * * Called if/when the I2C object is GC'ed. */ -void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(I2C) (void *void_ptr, jerry_object_native_info_t *info_p) { - (void) info_p; - delete static_cast(void_ptr); +void +NAME_FOR_CLASS_NATIVE_DESTRUCTOR (I2C) (void *void_ptr, jerry_object_native_info_t *info_p) +{ + (void) info_p; + delete static_cast (void_ptr); } /** @@ -33,9 +35,7 @@ void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(I2C) (void *void_ptr, jerry_object_native_ * * Set I2C#destructor as the free callback. */ -static const jerry_object_native_info_t native_obj_type_info = { - .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR(I2C) -}; +static const jerry_object_native_info_t native_obj_type_info = { .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR (I2C) }; /** * I2C#frequency (native JavaScript method) @@ -44,25 +44,25 @@ static const jerry_object_native_info_t native_obj_type_info = { * * @param frequency New I2C Frequency */ -DECLARE_CLASS_FUNCTION(I2C, frequency) { - CHECK_ARGUMENT_COUNT(I2C, frequency, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, frequency, 0, number); +DECLARE_CLASS_FUNCTION (I2C, frequency) +{ + CHECK_ARGUMENT_COUNT (I2C, frequency, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, frequency, 0, number); - // Unwrap native I2C object - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Unwrap native I2C object + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - int hz = jerry_get_number_value(args[0]); - native_ptr->frequency(hz); + int hz = jerry_value_as_number (args[0]); + native_ptr->frequency (hz); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -86,77 +86,84 @@ DECLARE_CLASS_FUNCTION(I2C, frequency) { * * @returns array: Data read from the I2C bus */ -DECLARE_CLASS_FUNCTION(I2C, read) { - CHECK_ARGUMENT_COUNT(I2C, read, (args_count == 1 || args_count == 3 || args_count == 4)); - - if (args_count == 1) { - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, read, 0, number); - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); - - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } +DECLARE_CLASS_FUNCTION (I2C, read) +{ + CHECK_ARGUMENT_COUNT (I2C, read, (args_count == 1 || args_count == 3 || args_count == 4)); + + if (args_count == 1) + { + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, read, 0, number); + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); + + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - int data = jerry_get_number_value(args[0]); - int result = native_ptr->read(data); + int data = jerry_value_as_number (args[0]); + int result = native_ptr->read (data); - return jerry_create_number(result); - } else { - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, read, 0, number); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, read, 1, array); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, read, 2, number); + return jerry_number (result); + } + else + { + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, read, 0, number); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, read, 1, array); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, read, 2, number); - CHECK_ARGUMENT_TYPE_ON_CONDITION(I2C, read, 3, boolean, (args_count == 4)); + CHECK_ARGUMENT_TYPE_ON_CONDITION (I2C, read, 3, boolean, (args_count == 4)); - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - const uint32_t data_len = jerry_get_array_length(args[1]); + const uint32_t data_len = jerry_array_length (args[1]); - int address = jerry_get_number_value(args[0]); - int length = jerry_get_number_value(args[2]); + int address = jerry_value_as_number (args[0]); + int length = jerry_value_as_number (args[2]); - char *data = new char[data_len]; + char *data = new char[data_len]; - bool repeated = false; - if (args_count == 4) { - repeated = jerry_value_is_true(args[3]); - } + bool repeated = false; + if (args_count == 4) + { + repeated = jerry_value_is_true (args[3]); + } - int result = native_ptr->read(address, data, length, repeated); + int result = native_ptr->read (address, data, length, repeated); - jerry_value_t out_array = jerry_create_array(data_len); + jerry_value_t out_array = jerry_array (data_len); - for (uint32_t i = 0; i < data_len; i++) { - jerry_value_t val = jerry_create_number(double(data[i])); - jerry_release_value(jerry_set_property_by_index(out_array, i, val)); - jerry_release_value(val); - } + for (uint32_t i = 0; i < data_len; i++) + { + jerry_value_t val = jerry_number (double (data[i])); + jerry_value_free (jerry_object_set_index (out_array, i, val)); + jerry_value_free (val); + } - delete[] data; + delete[] data; - if (result == 0) { - // ACK - return out_array; - } else { - // NACK - const char *error_msg = "NACK received from I2C bus"; + if (result == 0) + { + // ACK + return out_array; + } + else + { + // NACK + const char *error_msg = "NACK received from I2C bus"; - jerry_release_value(out_array); - return jerry_create_error(JERRY_ERROR_COMMON, reinterpret_cast(error_msg)); - } + jerry_value_free (out_array); + return jerry_throw_sz (JERRY_ERROR_COMMON, error_msg); } + } } /** @@ -179,65 +186,68 @@ DECLARE_CLASS_FUNCTION(I2C, read) { * * @returns 0 on success, non-0 on failure */ -DECLARE_CLASS_FUNCTION(I2C, write) { - CHECK_ARGUMENT_COUNT(I2C, write, (args_count == 1 || args_count == 3 || args_count == 4)); +DECLARE_CLASS_FUNCTION (I2C, write) +{ + CHECK_ARGUMENT_COUNT (I2C, write, (args_count == 1 || args_count == 3 || args_count == 4)); - if (args_count == 1) { - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, write, 0, number); + if (args_count == 1) + { + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, write, 0, number); - // Extract native I2C object - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native I2C object + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - // Unwrap arguments - int data = jerry_get_number_value(args[0]); + // Unwrap arguments + int data = jerry_value_as_number (args[0]); - int result = native_ptr->write(data); - return jerry_create_number(result); - } else { - // 3 or 4 - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, write, 0, number); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, write, 1, array); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, write, 2, number); - CHECK_ARGUMENT_TYPE_ON_CONDITION(I2C, write, 3, boolean, (args_count == 4)); + int result = native_ptr->write (data); + return jerry_number (result); + } + else + { + // 3 or 4 + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, write, 0, number); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, write, 1, array); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, write, 2, number); + CHECK_ARGUMENT_TYPE_ON_CONDITION (I2C, write, 3, boolean, (args_count == 4)); - // Extract native I2C object - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native I2C object + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } + if (void_ptr != NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - // Unwrap arguments - int address = jerry_get_number_value(args[0]); - const uint32_t data_len = jerry_get_array_length(args[1]); - int length = jerry_get_number_value(args[2]); - bool repeated = args_count == 4 && jerry_value_is_true(args[3]); + // Unwrap arguments + int address = jerry_value_as_number (args[0]); + const uint32_t data_len = jerry_array_length (args[1]); + int length = jerry_value_as_number (args[2]); + bool repeated = args_count == 4 && jerry_value_is_true (args[3]); - // Construct data byte array - char *data = new char[data_len]; - for (uint32_t i = 0; i < data_len; i++) { - data[i] = jerry_get_number_value(jerry_get_property_by_index(args[1], i)); - } + // Construct data byte array + char *data = new char[data_len]; + for (uint32_t i = 0; i < data_len; i++) + { + data[i] = jerry_value_as_number (jerry_object_get_index (args[1], i)); + } - int result = native_ptr->write(address, data, length, repeated); + int result = native_ptr->write (address, data, length, repeated); - // free dynamically allocated resources - delete[] data; + // free dynamically allocated resources + delete[] data; - return jerry_create_number(result); - } + return jerry_number (result); + } } /** @@ -245,22 +255,22 @@ DECLARE_CLASS_FUNCTION(I2C, write) { * * Creates a start condition on the I2C bus. */ -DECLARE_CLASS_FUNCTION(I2C, start) { - CHECK_ARGUMENT_COUNT(I2C, start, (args_count == 0)); +DECLARE_CLASS_FUNCTION (I2C, start) +{ + CHECK_ARGUMENT_COUNT (I2C, start, (args_count == 0)); - // Extract native I2C object - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native I2C object + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - native_ptr->start(); - return jerry_create_undefined(); + native_ptr->start (); + return jerry_undefined (); } /** @@ -268,22 +278,22 @@ DECLARE_CLASS_FUNCTION(I2C, start) { * * Creates a stop condition on the I2C bus. */ -DECLARE_CLASS_FUNCTION(I2C, stop) { - CHECK_ARGUMENT_COUNT(I2C, stop, (args_count == 0)); +DECLARE_CLASS_FUNCTION (I2C, stop) +{ + CHECK_ARGUMENT_COUNT (I2C, stop, (args_count == 0)); - // Extract native I2C object - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native I2C object + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native I2C pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native I2C pointer"); + } - I2C *native_ptr = static_cast(void_ptr); + I2C *native_ptr = static_cast (void_ptr); - native_ptr->stop(); - return jerry_create_undefined(); + native_ptr->stop (); + return jerry_undefined (); } /** @@ -293,24 +303,25 @@ DECLARE_CLASS_FUNCTION(I2C, stop) { * @param scl mbed pin for I2C clock * @returns a JavaScript object representing the I2C bus. */ -DECLARE_CLASS_CONSTRUCTOR(I2C) { - CHECK_ARGUMENT_COUNT(I2C, __constructor, (args_count == 2)); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, __constructor, 0, number); - CHECK_ARGUMENT_TYPE_ALWAYS(I2C, __constructor, 1, number); +DECLARE_CLASS_CONSTRUCTOR (I2C) +{ + CHECK_ARGUMENT_COUNT (I2C, __constructor, (args_count == 2)); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, __constructor, 0, number); + CHECK_ARGUMENT_TYPE_ALWAYS (I2C, __constructor, 1, number); - int sda = jerry_get_number_value(args[0]); - int scl = jerry_get_number_value(args[1]); + int sda = jerry_value_as_number (args[0]); + int scl = jerry_value_as_number (args[1]); - I2C *native_ptr = new I2C((PinName)sda, (PinName)scl); + I2C *native_ptr = new I2C ((PinName) sda, (PinName) scl); - jerry_value_t js_object = jerry_create_object(); - jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); + jerry_value_t js_object = jerry_object (); + jerry_object_set_native_ptr (js_object, &native_obj_type_info, native_ptr); - ATTACH_CLASS_FUNCTION(js_object, I2C, frequency); - ATTACH_CLASS_FUNCTION(js_object, I2C, read); - ATTACH_CLASS_FUNCTION(js_object, I2C, write); - ATTACH_CLASS_FUNCTION(js_object, I2C, start); - ATTACH_CLASS_FUNCTION(js_object, I2C, stop); + ATTACH_CLASS_FUNCTION (js_object, I2C, frequency); + ATTACH_CLASS_FUNCTION (js_object, I2C, read); + ATTACH_CLASS_FUNCTION (js_object, I2C, write); + ATTACH_CLASS_FUNCTION (js_object, I2C, start); + ATTACH_CLASS_FUNCTION (js_object, I2C, stop); - return js_object; + return js_object; } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp index a1961dfed4..2d7c1b2e4c 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp @@ -12,10 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "jerryscript-mbed-util/logging.h" #include "jerryscript-mbed-event-loop/EventLoop.h" #include "jerryscript-mbed-library-registry/wrap_tools.h" - +#include "jerryscript-mbed-util/logging.h" #include "mbed.h" /** @@ -23,13 +22,15 @@ * * Called if/when the InterruptIn object is GC'ed. */ -void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(InterruptIn) (void *void_ptr, jerry_object_native_info_t *info_p) { - (void) info_p; - InterruptIn *native_ptr = static_cast(void_ptr); - - native_ptr->rise(0); - native_ptr->fall(0); - delete native_ptr; +void +NAME_FOR_CLASS_NATIVE_DESTRUCTOR (InterruptIn) (void *void_ptr, jerry_object_native_info_t *info_p) +{ + (void) info_p; + InterruptIn *native_ptr = static_cast (void_ptr); + + native_ptr->rise (0); + native_ptr->fall (0); + delete native_ptr; } /** @@ -37,9 +38,8 @@ void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(InterruptIn) (void *void_ptr, jerry_object * * Set InterruptIn#destructor as the free callback. */ -static const jerry_object_native_info_t native_obj_type_info = { - .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR(InterruptIn) -}; +static const jerry_object_native_info_t native_obj_type_info = { .free_cb = + NAME_FOR_CLASS_NATIVE_DESTRUCTOR (InterruptIn) }; /** * InterruptIn#rise (native JavaScript method) @@ -48,62 +48,63 @@ static const jerry_object_native_info_t native_obj_type_info = { * * @param cb Callback function, or null to detach previously attached callback. */ -DECLARE_CLASS_FUNCTION(InterruptIn, rise) { - CHECK_ARGUMENT_COUNT(InterruptIn, rise, (args_count == 1)); - - // Detach the rise callback when InterruptIn::rise(null) is called - if (jerry_value_is_null(args[0])) { - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); +DECLARE_CLASS_FUNCTION (InterruptIn, rise) +{ + CHECK_ARGUMENT_COUNT (InterruptIn, rise, (args_count == 1)); + + // Detach the rise callback when InterruptIn::rise(null) is called + if (jerry_value_is_null (args[0])) + { + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); + + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + InterruptIn *native_ptr = static_cast (void_ptr); - InterruptIn *native_ptr = static_cast(void_ptr); + jerry_value_t property_name = jerry_string_sz ("cb_rise"); + jerry_value_t cb_func = jerry_object_get (call_info_p->this_value, property_name); + jerry_value_free (property_name); - jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_rise"); - jerry_value_t cb_func = jerry_get_property(call_info_p->this_value, property_name); - jerry_release_value(property_name); + // Only drop the callback if it exists + if (jerry_value_is_function (cb_func)) + { + // Ensure that the EventLoop frees memory used by the callback. + mbed::js::EventLoop::getInstance ().dropCallback (cb_func); + } + jerry_value_free (cb_func); - // Only drop the callback if it exists - if (jerry_value_is_function(cb_func)) { - // Ensure that the EventLoop frees memory used by the callback. - mbed::js::EventLoop::getInstance().dropCallback(cb_func); - } - jerry_release_value(cb_func); + native_ptr->rise (0); - native_ptr->rise(0); + return jerry_undefined (); + } - return jerry_create_undefined(); - } + // Assuming we actually have a callback now... + CHECK_ARGUMENT_TYPE_ALWAYS (InterruptIn, rise, 0, function); - // Assuming we actually have a callback now... - CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, rise, 0, function); + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); - - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - InterruptIn *native_ptr = static_cast(void_ptr); + InterruptIn *native_ptr = static_cast (void_ptr); - jerry_value_t f = args[0]; + jerry_value_t f = args[0]; - // Pass the function to EventLoop. - mbed::Callback cb = mbed::js::EventLoop::getInstance().wrapFunction(f); - native_ptr->rise(cb); + // Pass the function to EventLoop. + mbed::Callback cb = mbed::js::EventLoop::getInstance ().wrapFunction (f); + native_ptr->rise (cb); - // Keep track of our callback internally. - jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_rise"); - jerry_release_value(jerry_set_property(call_info_p->this_value, property_name, f)); - jerry_release_value(property_name); + // Keep track of our callback internally. + jerry_value_t property_name = jerry_string_sz ("cb_rise"); + jerry_value_free (jerry_object_set (call_info_p->this_value, property_name, f)); + jerry_value_free (property_name); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -113,62 +114,63 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) { * * @param cb Callback function, or null to detach previously attached callback. */ -DECLARE_CLASS_FUNCTION(InterruptIn, fall) { - CHECK_ARGUMENT_COUNT(InterruptIn, fall, (args_count == 1)); +DECLARE_CLASS_FUNCTION (InterruptIn, fall) +{ + CHECK_ARGUMENT_COUNT (InterruptIn, fall, (args_count == 1)); + + // Detach the fall callback when InterruptIn::fall(null) is called + if (jerry_value_is_null (args[0])) + { + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); + + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - // Detach the fall callback when InterruptIn::fall(null) is called - if (jerry_value_is_null(args[0])) { - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + InterruptIn *native_ptr = static_cast (void_ptr); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + jerry_value_t property_name = jerry_string_sz ("cb_fall"); + jerry_value_t cb_func = jerry_object_get (call_info_p->this_value, property_name); + jerry_value_free (property_name); - InterruptIn *native_ptr = static_cast(void_ptr); + // Only drop the callback if it exists + if (jerry_value_is_function (cb_func)) + { + // Ensure that the EventLoop frees memory used by the callback. + mbed::js::EventLoop::getInstance ().dropCallback (cb_func); + } + jerry_value_free (cb_func); - jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_fall"); - jerry_value_t cb_func = jerry_get_property(call_info_p->this_value, property_name); - jerry_release_value(property_name); + native_ptr->fall (0); - // Only drop the callback if it exists - if (jerry_value_is_function(cb_func)) { - // Ensure that the EventLoop frees memory used by the callback. - mbed::js::EventLoop::getInstance().dropCallback(cb_func); - } - jerry_release_value(cb_func); + return jerry_undefined (); + } - native_ptr->fall(0); + // Assuming we actually have a callback now... + CHECK_ARGUMENT_TYPE_ALWAYS (InterruptIn, fall, 0, function); - return jerry_create_undefined(); - } + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - // Assuming we actually have a callback now... - CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, fall, 0, function); + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); - - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + InterruptIn *native_ptr = static_cast (void_ptr); - InterruptIn *native_ptr = static_cast(void_ptr); + jerry_value_t f = args[0]; - jerry_value_t f = args[0]; + // Pass the function to EventLoop. + mbed::Callback cb = mbed::js::EventLoop::getInstance ().wrapFunction (f); + native_ptr->fall (cb); - // Pass the function to EventLoop. - mbed::Callback cb = mbed::js::EventLoop::getInstance().wrapFunction(f); - native_ptr->fall(cb); + // Keep track of our callback internally. + jerry_value_t property_name = jerry_string_sz ("cb_fall"); + jerry_value_free (jerry_object_set (call_info_p->this_value, property_name, f)); + jerry_value_free (property_name); - // Keep track of our callback internally. - jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_fall"); - jerry_release_value(jerry_set_property(call_info_p->this_value, property_name, f)); - jerry_release_value(property_name); - - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -178,24 +180,24 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) { * * @param mode PullUp, PullDown, PullNone */ -DECLARE_CLASS_FUNCTION(InterruptIn, mode) { - CHECK_ARGUMENT_COUNT(InterruptIn, mode, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, mode, 0, number); +DECLARE_CLASS_FUNCTION (InterruptIn, mode) +{ + CHECK_ARGUMENT_COUNT (InterruptIn, mode, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (InterruptIn, mode, 0, number); - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - InterruptIn *native_ptr = static_cast(void_ptr); + InterruptIn *native_ptr = static_cast (void_ptr); - int pull = jerry_get_number_value(args[0]); - native_ptr->mode((PinMode)pull); + int pull = jerry_value_as_number (args[0]); + native_ptr->mode ((PinMode) pull); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -203,21 +205,21 @@ DECLARE_CLASS_FUNCTION(InterruptIn, mode) { * * Disable IRQ. See InterruptIn.h in mbed-os sources for more details. */ -DECLARE_CLASS_FUNCTION(InterruptIn, disable_irq) { - CHECK_ARGUMENT_COUNT(InterruptIn, disable_irq, (args_count == 0)); +DECLARE_CLASS_FUNCTION (InterruptIn, disable_irq) +{ + CHECK_ARGUMENT_COUNT (InterruptIn, disable_irq, (args_count == 0)); - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - InterruptIn *native_ptr = static_cast(void_ptr); + InterruptIn *native_ptr = static_cast (void_ptr); - native_ptr->disable_irq(); - return jerry_create_undefined(); + native_ptr->disable_irq (); + return jerry_undefined (); } /** @@ -225,21 +227,21 @@ DECLARE_CLASS_FUNCTION(InterruptIn, disable_irq) { * * Enable IRQ. See InterruptIn.h in mbed-os sources for more details. */ -DECLARE_CLASS_FUNCTION(InterruptIn, enable_irq) { - CHECK_ARGUMENT_COUNT(InterruptIn, enable_irq, (args_count == 0)); +DECLARE_CLASS_FUNCTION (InterruptIn, enable_irq) +{ + CHECK_ARGUMENT_COUNT (InterruptIn, enable_irq, (args_count == 0)); - void *void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + void *void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native InterruptIn pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native InterruptIn pointer"); + } - InterruptIn *native_ptr = static_cast(void_ptr); + InterruptIn *native_ptr = static_cast (void_ptr); - native_ptr->enable_irq(); - return jerry_create_undefined(); + native_ptr->enable_irq (); + return jerry_undefined (); } /** @@ -249,21 +251,22 @@ DECLARE_CLASS_FUNCTION(InterruptIn, enable_irq) { * * @returns JavaScript object wrapping InterruptIn native object */ -DECLARE_CLASS_CONSTRUCTOR(InterruptIn) { - CHECK_ARGUMENT_COUNT(InterruptIn, __constructor, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, __constructor, 0, number); - int pin = jerry_get_number_value(args[0]); +DECLARE_CLASS_CONSTRUCTOR (InterruptIn) +{ + CHECK_ARGUMENT_COUNT (InterruptIn, __constructor, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (InterruptIn, __constructor, 0, number); + int pin = jerry_value_as_number (args[0]); - InterruptIn *native_ptr = new InterruptIn((PinName)pin); - jerry_value_t js_object = jerry_create_object(); + InterruptIn *native_ptr = new InterruptIn ((PinName) pin); + jerry_value_t js_object = jerry_object (); - jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); + jerry_object_set_native_ptr (js_object, &native_obj_type_info, native_ptr); - ATTACH_CLASS_FUNCTION(js_object, InterruptIn, rise); - ATTACH_CLASS_FUNCTION(js_object, InterruptIn, fall); - ATTACH_CLASS_FUNCTION(js_object, InterruptIn, mode); - ATTACH_CLASS_FUNCTION(js_object, InterruptIn, enable_irq); - ATTACH_CLASS_FUNCTION(js_object, InterruptIn, disable_irq); + ATTACH_CLASS_FUNCTION (js_object, InterruptIn, rise); + ATTACH_CLASS_FUNCTION (js_object, InterruptIn, fall); + ATTACH_CLASS_FUNCTION (js_object, InterruptIn, mode); + ATTACH_CLASS_FUNCTION (js_object, InterruptIn, enable_irq); + ATTACH_CLASS_FUNCTION (js_object, InterruptIn, disable_irq); - return js_object; + return js_object; } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/PwmOut-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/PwmOut-js.cpp index fab24157f5..de332c5b8a 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/PwmOut-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/PwmOut-js.cpp @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "jerryscript-mbed-util/logging.h" #include "jerryscript-mbed-library-registry/wrap_tools.h" - +#include "jerryscript-mbed-util/logging.h" #include "mbed.h" /** @@ -22,9 +21,11 @@ * * Called if/when the PwmOut is GC'ed. */ -void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(PwmOut)(void* void_ptr, jerry_object_native_info_t *info_p) { - (void) info_p; - delete static_cast(void_ptr); +void +NAME_FOR_CLASS_NATIVE_DESTRUCTOR (PwmOut) (void* void_ptr, jerry_object_native_info_t* info_p) +{ + (void) info_p; + delete static_cast (void_ptr); } /** @@ -32,9 +33,7 @@ void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(PwmOut)(void* void_ptr, jerry_object_nativ * * Set PwmOut#destructor as the free callback. */ -static const jerry_object_native_info_t native_obj_type_info = { - .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR(PwmOut) -}; +static const jerry_object_native_info_t native_obj_type_info = { .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR (PwmOut) }; /** * PwmOut#write (native JavaScript method) @@ -47,25 +46,25 @@ static const jerry_object_native_info_t native_obj_type_info = { * Values outside this range will be saturated to 0.0f or 1.0f * @returns undefined */ -DECLARE_CLASS_FUNCTION(PwmOut, write) { - CHECK_ARGUMENT_COUNT(PwmOut, write, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, write, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, write) +{ + CHECK_ARGUMENT_COUNT (PwmOut, write, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, write, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->write(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->write (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -81,22 +80,22 @@ DECLARE_CLASS_FUNCTION(PwmOut, write) { * @note * This value may not match exactly the value set by a previous . */ -DECLARE_CLASS_FUNCTION(PwmOut, read) { - CHECK_ARGUMENT_COUNT(PwmOut, read, (args_count == 0)); +DECLARE_CLASS_FUNCTION (PwmOut, read) +{ + CHECK_ARGUMENT_COUNT (PwmOut, read, (args_count == 0)); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - float result = native_ptr->read(); - return jerry_create_number(result); + float result = native_ptr->read (); + return jerry_number (result); } /** @@ -108,25 +107,25 @@ DECLARE_CLASS_FUNCTION(PwmOut, read) { * The resolution is currently in microseconds; periods smaller than this * will be set to zero. */ -DECLARE_CLASS_FUNCTION(PwmOut, period) { - CHECK_ARGUMENT_COUNT(PwmOut, period, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, period, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, period) +{ + CHECK_ARGUMENT_COUNT (PwmOut, period, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, period, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->period(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->period (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -134,25 +133,25 @@ DECLARE_CLASS_FUNCTION(PwmOut, period) { * * Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. */ -DECLARE_CLASS_FUNCTION(PwmOut, period_ms) { - CHECK_ARGUMENT_COUNT(PwmOut, period_ms, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, period_ms, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, period_ms) +{ + CHECK_ARGUMENT_COUNT (PwmOut, period_ms, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, period_ms, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->period_ms(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->period_ms (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -160,25 +159,25 @@ DECLARE_CLASS_FUNCTION(PwmOut, period_ms) { * * Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. */ -DECLARE_CLASS_FUNCTION(PwmOut, period_us) { - CHECK_ARGUMENT_COUNT(PwmOut, period_us, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, period_us, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, period_us) +{ + CHECK_ARGUMENT_COUNT (PwmOut, period_us, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, period_us, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->period_us(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->period_us (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -186,25 +185,25 @@ DECLARE_CLASS_FUNCTION(PwmOut, period_us) { * * Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. */ -DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth) { - CHECK_ARGUMENT_COUNT(PwmOut, pulsewidth, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, pulsewidth, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, pulsewidth) +{ + CHECK_ARGUMENT_COUNT (PwmOut, pulsewidth, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, pulsewidth, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->pulsewidth(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->pulsewidth (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -212,25 +211,25 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth) { * * Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. */ -DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_ms) { - CHECK_ARGUMENT_COUNT(PwmOut, pulsewidth_ms, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, pulsewidth_ms, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, pulsewidth_ms) +{ + CHECK_ARGUMENT_COUNT (PwmOut, pulsewidth_ms, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, pulsewidth_ms, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->pulsewidth_ms(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->pulsewidth_ms (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -238,25 +237,25 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_ms) { * * Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. */ -DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_us) { - CHECK_ARGUMENT_COUNT(PwmOut, pulsewidth_us, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, pulsewidth_us, 0, number); +DECLARE_CLASS_FUNCTION (PwmOut, pulsewidth_us) +{ + CHECK_ARGUMENT_COUNT (PwmOut, pulsewidth_us, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, pulsewidth_us, 0, number); - // Extract native PwmOut pointer - void* void_ptr; - bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info); + // Extract native PwmOut pointer + void* void_ptr = jerry_object_get_native_ptr (call_info_p->this_value, &native_obj_type_info); - if (!has_ptr) { - return jerry_create_error(JERRY_ERROR_TYPE, - (const jerry_char_t *) "Failed to get native PwmOut pointer"); - } + if (void_ptr == NULL) + { + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to get native PwmOut pointer"); + } - PwmOut* native_ptr = static_cast(void_ptr); + PwmOut* native_ptr = static_cast (void_ptr); - double arg0 = jerry_get_number_value(args[0]); - native_ptr->pulsewidth_us(static_cast(arg0)); + double arg0 = jerry_value_as_number (args[0]); + native_ptr->pulsewidth_us (static_cast (arg0)); - return jerry_create_undefined(); + return jerry_undefined (); } /** @@ -265,28 +264,29 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_us) { * @param pin_name mbed pin to connect the PwmOut to. * @returns a JavaScript object representing a PwmOut. */ -DECLARE_CLASS_CONSTRUCTOR(PwmOut) { - CHECK_ARGUMENT_COUNT(PwmOut, __constructor, args_count == 1); - CHECK_ARGUMENT_TYPE_ALWAYS(PwmOut, __constructor, 0, number); - - PinName pin_name = PinName(jerry_get_number_value(args[0])); - - // Create the native object - PwmOut* native_ptr = new PwmOut(pin_name); - - // create the jerryscript object - jerry_value_t js_object = jerry_create_object(); - jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); - - // attach methods - ATTACH_CLASS_FUNCTION(js_object, PwmOut, write); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, read); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, period); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, period_ms); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, period_us); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, pulsewidth); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, pulsewidth_ms); - ATTACH_CLASS_FUNCTION(js_object, PwmOut, pulsewidth_us); - - return js_object; +DECLARE_CLASS_CONSTRUCTOR (PwmOut) +{ + CHECK_ARGUMENT_COUNT (PwmOut, __constructor, args_count == 1); + CHECK_ARGUMENT_TYPE_ALWAYS (PwmOut, __constructor, 0, number); + + PinName pin_name = PinName (jerry_value_as_number (args[0])); + + // Create the native object + PwmOut* native_ptr = new PwmOut (pin_name); + + // create the jerryscript object + jerry_value_t js_object = jerry_object (); + jerry_object_set_native_ptr (js_object, &native_obj_type_info, native_ptr); + + // attach methods + ATTACH_CLASS_FUNCTION (js_object, PwmOut, write); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, read); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, period); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, period_ms); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, period_us); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, pulsewidth); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, pulsewidth_ms); + ATTACH_CLASS_FUNCTION (js_object, PwmOut, pulsewidth_us); + + return js_object; } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setInterval-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setInterval-js.cpp index b79063df19..c8d9a5c327 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setInterval-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setInterval-js.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include "jerryscript-mbed-drivers/setInterval-js.h" + #include "jerryscript-mbed-event-loop/EventLoop.h" /** @@ -23,26 +24,33 @@ * @param function Function to call * @param interval Time between function calls, in ms. */ -DECLARE_GLOBAL_FUNCTION(setInterval) { - CHECK_ARGUMENT_COUNT(global, setInterval, (args_count == 2)); - CHECK_ARGUMENT_TYPE_ALWAYS(global, setInterval, 0, function); - CHECK_ARGUMENT_TYPE_ALWAYS(global, setInterval, 1, number); +DECLARE_GLOBAL_FUNCTION (setInterval) +{ + CHECK_ARGUMENT_COUNT (global, setInterval, (args_count == 2)); + CHECK_ARGUMENT_TYPE_ALWAYS (global, setInterval, 0, function); + CHECK_ARGUMENT_TYPE_ALWAYS (global, setInterval, 1, number); - int interval = int(jerry_get_number_value(args[1])); + int interval = int (jerry_value_as_number (args[1])); - int id = mbed::js::EventLoop::getInstance().getQueue().call_every(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0); + int id = mbed::js::EventLoop::getInstance ().getQueue ().call_every (interval, + jerry_call, + args[0], + jerry_null (), + (jerry_value_t*) NULL, + 0); - jerry_value_t result = jerry_set_property_by_index(call_info_p->function, id, args[0]); + jerry_value_t result = jerry_object_set_index (call_info_p->function, id, args[0]); - if (jerry_value_is_error(result)) { - jerry_release_value(result); - mbed::js::EventLoop::getInstance().getQueue().cancel(id); + if (jerry_value_is_exception (result)) + { + jerry_value_free (result); + mbed::js::EventLoop::getInstance ().getQueue ().cancel (id); - return jerry_create_error(JERRY_ERROR_TYPE, (const jerry_char_t *) "Failed to run setInterval"); - } + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to run setInterval"); + } - jerry_release_value(result); - return jerry_create_number(id); + jerry_value_free (result); + return jerry_number (id); } /** @@ -52,22 +60,23 @@ DECLARE_GLOBAL_FUNCTION(setInterval) { * * @param id ID of the timeout event, returned by setInterval. */ -DECLARE_GLOBAL_FUNCTION(clearInterval) { - CHECK_ARGUMENT_COUNT(global, clearInterval, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(global, clearInterval, 0, number); +DECLARE_GLOBAL_FUNCTION (clearInterval) +{ + CHECK_ARGUMENT_COUNT (global, clearInterval, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (global, clearInterval, 0, number); - int id = int(jerry_get_number_value(args[0])); + int id = int (jerry_value_as_number (args[0])); - mbed::js::EventLoop::getInstance().getQueue().cancel(id); + mbed::js::EventLoop::getInstance ().getQueue ().cancel (id); - jerry_value_t global_obj = jerry_get_global_object(); - jerry_value_t prop_name = jerry_create_string((const jerry_char_t*)"setInterval"); - jerry_value_t func_obj = jerry_get_property(global_obj, prop_name); - jerry_release_value(prop_name); + jerry_value_t global_obj = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("setInterval"); + jerry_value_t func_obj = jerry_object_get (global_obj, prop_name); + jerry_value_free (prop_name); - jerry_delete_property_by_index(func_obj, id); - jerry_release_value(func_obj); - jerry_release_value(global_obj); + jerry_object_delete_index (func_obj, id); + jerry_value_free (func_obj); + jerry_value_free (global_obj); - return jerry_create_undefined(); + return jerry_undefined (); } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setTimeout-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setTimeout-js.cpp index a9bf1096ec..a7eb32bb35 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setTimeout-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/setTimeout-js.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include "jerryscript-mbed-drivers/setTimeout-js.h" + #include "jerryscript-mbed-event-loop/EventLoop.h" /** @@ -23,26 +24,33 @@ * @param function Function to call * @param wait_time Time before function is called, in ms. */ -DECLARE_GLOBAL_FUNCTION(setTimeout) { - CHECK_ARGUMENT_COUNT(global, setTimeout, (args_count == 2)); - CHECK_ARGUMENT_TYPE_ALWAYS(global, setTimeout, 0, function); - CHECK_ARGUMENT_TYPE_ALWAYS(global, setTimeout, 1, number); +DECLARE_GLOBAL_FUNCTION (setTimeout) +{ + CHECK_ARGUMENT_COUNT (global, setTimeout, (args_count == 2)); + CHECK_ARGUMENT_TYPE_ALWAYS (global, setTimeout, 0, function); + CHECK_ARGUMENT_TYPE_ALWAYS (global, setTimeout, 1, number); - int interval = int(jerry_get_number_value(args[1])); + int interval = int (jerry_value_as_number (args[1])); - int id = mbed::js::EventLoop::getInstance().getQueue().call_in(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0); + int id = mbed::js::EventLoop::getInstance ().getQueue ().call_in (interval, + jerry_call, + args[0], + jerry_null (), + (jerry_value_t*) NULL, + 0); - jerry_value_t result = jerry_set_property_by_index(call_info_p->function, id, args[0]); + jerry_value_t result = jerry_object_set_index (call_info_p->function, id, args[0]); - if (jerry_value_is_error(result)) { - jerry_release_value(result); - mbed::js::EventLoop::getInstance().getQueue().cancel(id); + if (jerry_value_is_exception (result)) + { + jerry_value_free (result); + mbed::js::EventLoop::getInstance ().getQueue ().cancel (id); - return jerry_create_error(JERRY_ERROR_TYPE, (const jerry_char_t *) "Failed to run setTimeout"); - } + return jerry_throw_sz (JERRY_ERROR_TYPE, "Failed to run setTimeout"); + } - jerry_release_value(result); - return jerry_create_number(id); + jerry_value_free (result); + return jerry_number (id); } /** @@ -52,22 +60,23 @@ DECLARE_GLOBAL_FUNCTION(setTimeout) { * * @param id ID of the timeout event, returned by setTimeout. */ -DECLARE_GLOBAL_FUNCTION(clearTimeout) { - CHECK_ARGUMENT_COUNT(global, clearTimeout, (args_count == 1)); - CHECK_ARGUMENT_TYPE_ALWAYS(global, clearTimeout, 0, number); +DECLARE_GLOBAL_FUNCTION (clearTimeout) +{ + CHECK_ARGUMENT_COUNT (global, clearTimeout, (args_count == 1)); + CHECK_ARGUMENT_TYPE_ALWAYS (global, clearTimeout, 0, number); - int id = int(jerry_get_number_value(args[0])); + int id = int (jerry_value_as_number (args[0])); - mbed::js::EventLoop::getInstance().getQueue().cancel(id); + mbed::js::EventLoop::getInstance ().getQueue ().cancel (id); - jerry_value_t global_obj = jerry_get_global_object(); - jerry_value_t prop_name = jerry_create_string((const jerry_char_t*)"setTimeout"); - jerry_value_t func_obj = jerry_get_property(global_obj, prop_name); - jerry_release_value(prop_name); + jerry_value_t global_obj = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("setTimeout"); + jerry_value_t func_obj = jerry_object_get (global_obj, prop_name); + jerry_value_free (prop_name); - jerry_delete_property_by_index(func_obj, id); - jerry_release_value(func_obj); - jerry_release_value(global_obj); + jerry_object_delete_index (func_obj, id); + jerry_value_free (func_obj); + jerry_value_free (global_obj); - return jerry_create_undefined(); + return jerry_undefined (); } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h index 99d8552269..db7c985e56 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h @@ -73,7 +73,7 @@ class EventLoop { } void callback(jerry_value_t f) { - queue.call(jerry_call_function, f, jerry_create_null(), (const jerry_value_t*)NULL, 0); + queue.call(jerry_call, f, jerry_null(), (const jerry_value_t*)NULL, 0); } void nativeCallback(Callback cb) { diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/launcher.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/launcher.cpp index 6e3b1c87ae..e8623795d0 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/launcher.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/launcher.cpp @@ -44,24 +44,24 @@ static int load_javascript() { jerry_value_t parsed_code = jerry_parse(code, length, NULL); - if (jerry_value_is_error(parsed_code)) { + if (jerry_value_is_exception(parsed_code)) { LOG_PRINT_ALWAYS("jerry_parse failed [%s]\r\n", js_codes[src].name); - jerry_release_value(parsed_code); + jerry_value_free(parsed_code); jsmbed_js_exit(); return -1; } jerry_value_t returned_value = jerry_run(parsed_code); - jerry_release_value(parsed_code); + jerry_value_free(parsed_code); - if (jerry_value_is_error(returned_value)) { + if (jerry_value_is_exception(returned_value)) { LOG_PRINT_ALWAYS("jerry_run failed [%s]\r\n", js_codes[src].name); - jerry_release_value(returned_value); + jerry_value_free(returned_value); jsmbed_js_exit(); return -1; } - jerry_release_value(returned_value); + jerry_value_free(returned_value); } return 0; diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/setup.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/setup.cpp index fb6bb27b18..fd19b713f7 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/setup.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-launcher/source/setup.cpp @@ -12,38 +12,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include "jerryscript-mbed-launcher/setup.h" + #include +#include -#include "jerryscript-mbed-launcher/setup.h" #include "jerryscript-mbed-util/logging.h" extern uint32_t jsmbed_js_magic_string_count; extern uint32_t jsmbed_js_magic_string_values[]; -extern const jerry_char_t *jsmbed_js_magic_strings[]; +extern const char *jsmbed_js_magic_strings[]; extern const jerry_length_t jsmbed_js_magic_string_lengths[]; -void jsmbed_js_load_magic_strings() { - if (jsmbed_js_magic_string_count == 0) { - return; - } +void +jsmbed_js_load_magic_strings () +{ + if (jsmbed_js_magic_string_count == 0) + { + return; + } - jerry_register_magic_strings(jsmbed_js_magic_strings, - jsmbed_js_magic_string_count, - jsmbed_js_magic_string_lengths); + jerry_register_magic_strings ((const jerry_char_t **) jsmbed_js_magic_strings, + jsmbed_js_magic_string_count, + jsmbed_js_magic_string_lengths); - jerry_value_t global = jerry_get_global_object(); + jerry_value_t global = jerry_current_realm (); - for (unsigned int idx = 0; idx < jsmbed_js_magic_string_count; idx++) { - jerry_value_t constant_value = jerry_create_number(jsmbed_js_magic_string_values[idx]); - jerry_value_t magic_string = jerry_create_string(jsmbed_js_magic_strings[idx]); + for (unsigned int idx = 0; idx < jsmbed_js_magic_string_count; idx++) + { + jerry_value_t constant_value = jerry_number (jsmbed_js_magic_string_values[idx]); + jerry_value_t magic_string = jerry_string_sz (jsmbed_js_magic_strings[idx]); - jerry_release_value(jerry_set_property(global, magic_string, constant_value)); + jerry_value_free (jerry_object_set (global, magic_string, constant_value)); - jerry_release_value(constant_value); - jerry_release_value(magic_string); - } + jerry_value_free (constant_value); + jerry_value_free (magic_string); + } - jerry_release_value(global); + jerry_value_free (global); } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-library-registry/source/wrap_tools.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-library-registry/source/wrap_tools.cpp index 21607657d1..15c1eb6bf2 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-library-registry/source/wrap_tools.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-library-registry/source/wrap_tools.cpp @@ -12,66 +12,73 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include - #include "jerryscript-mbed-library-registry/wrap_tools.h" -bool jsmbed_wrap_register_global_function(const char* name, jerry_external_handler_t handler) { - jerry_value_t global_object_val = jerry_get_global_object(); - jerry_value_t reg_function = jerry_create_external_function(handler); - - bool is_ok = true; +#include +#include - if (!(jerry_value_is_function(reg_function) - && jerry_value_is_constructor(reg_function))) { - is_ok = false; - LOG_PRINT_ALWAYS("Error: jerry_create_external_function failed!\r\n"); - jerry_release_value(global_object_val); - jerry_release_value(reg_function); - return is_ok; - } +bool +jsmbed_wrap_register_global_function (const char* name, jerry_external_handler_t handler) +{ + jerry_value_t global_object_val = jerry_current_realm (); + jerry_value_t reg_function = jerry_function_external (handler); - if (jerry_value_is_error(reg_function)) { - is_ok = false; - LOG_PRINT_ALWAYS("Error: jerry_create_external_function has error flag! \r\n"); - jerry_release_value(global_object_val); - jerry_release_value(reg_function); - return is_ok; - } + bool is_ok = true; - jerry_value_t jerry_name = jerry_create_string((jerry_char_t *) name); + if (!(jerry_value_is_function (reg_function) && jerry_value_is_constructor (reg_function))) + { + is_ok = false; + LOG_PRINT_ALWAYS ("Error: jerry_function_external failed!\r\n"); + jerry_value_free (global_object_val); + jerry_value_free (reg_function); + return is_ok; + } + + if (jerry_value_is_exception (reg_function)) + { + is_ok = false; + LOG_PRINT_ALWAYS ("Error: jerry_function_external has error flag! \r\n"); + jerry_value_free (global_object_val); + jerry_value_free (reg_function); + return is_ok; + } - jerry_value_t set_result = jerry_set_property(global_object_val, jerry_name, reg_function); + jerry_value_t jerry_name = jerry_string_sz (name); + jerry_value_t set_result = jerry_object_set (global_object_val, jerry_name, reg_function); - if (jerry_value_is_error(set_result)) { - is_ok = false; - LOG_PRINT_ALWAYS("Error: jerry_create_external_function failed: [%s]\r\n", name); - } + if (jerry_value_is_exception (set_result)) + { + is_ok = false; + LOG_PRINT_ALWAYS ("Error: jerry_function_external failed: [%s]\r\n", name); + } - jerry_release_value(jerry_name); - jerry_release_value(global_object_val); - jerry_release_value(reg_function); - jerry_release_value(set_result); + jerry_value_free (jerry_name); + jerry_value_free (global_object_val); + jerry_value_free (reg_function); + jerry_value_free (set_result); - return is_ok; + return is_ok; } -bool jsmbed_wrap_register_class_constructor(const char* name, jerry_external_handler_t handler) { - // Register class constructor as a global function - return jsmbed_wrap_register_global_function(name, handler); +bool +jsmbed_wrap_register_class_constructor (const char* name, jerry_external_handler_t handler) +{ + // Register class constructor as a global function + return jsmbed_wrap_register_global_function (name, handler); } -bool jsmbed_wrap_register_class_function(jerry_value_t this_obj, const char* name, jerry_external_handler_t handler) { - jerry_value_t property_name = jerry_create_string(reinterpret_cast(name)); - jerry_value_t handler_obj = jerry_create_external_function(handler); +bool +jsmbed_wrap_register_class_function (jerry_value_t this_obj, const char* name, jerry_external_handler_t handler) +{ + jerry_value_t property_name = jerry_string_sz (name); + jerry_value_t handler_obj = jerry_function_external (handler); - jerry_release_value(jerry_set_property(this_obj, property_name, handler_obj)); + jerry_value_free (jerry_object_set (this_obj, property_name, handler_obj)); - jerry_release_value(handler_obj); - jerry_release_value(property_name); + jerry_value_free (handler_obj); + jerry_value_free (property_name); - // TODO: check for errors, and return false in the case of errors - return true; + // TODO: check for errors, and return false in the case of errors + return true; } diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h index 892ad4a2c2..8043a66b0b 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-util/wrappers.h @@ -19,75 +19,73 @@ * Used in header/source files for wrappers, to declare the signature of the * registration function. */ -#define DECLARE_JS_WRAPPER_REGISTRATION(NAME) \ - void jsmbed_wrap_registry_entry__ ## NAME (void) +#define DECLARE_JS_WRAPPER_REGISTRATION(NAME) void jsmbed_wrap_registry_entry__##NAME (void) // // 2. Wrapper function declaration/use macros // // Global functions -#define DECLARE_GLOBAL_FUNCTION(NAME) \ -jerry_value_t \ -NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_call_info_t *call_info_p, \ - const jerry_value_t args[], \ - const jerry_length_t args_count) +#define DECLARE_GLOBAL_FUNCTION(NAME) \ + jerry_value_t NAME_FOR_GLOBAL_FUNCTION ( \ + NAME) (const jerry_call_info_t* call_info_p, const jerry_value_t args[], const jerry_length_t args_count) -#define REGISTER_GLOBAL_FUNCTION(NAME) \ - jsmbed_wrap_register_global_function ( # NAME, NAME_FOR_GLOBAL_FUNCTION(NAME) ) +#define REGISTER_GLOBAL_FUNCTION(NAME) jsmbed_wrap_register_global_function (#NAME, NAME_FOR_GLOBAL_FUNCTION (NAME)) -#define REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(NAME, HANDLER) \ - jsmbed_wrap_register_global_function ( # NAME, HANDLER ) +#define REGISTER_GLOBAL_FUNCTION_WITH_HANDLER(NAME, HANDLER) jsmbed_wrap_register_global_function (#NAME, HANDLER) // Class constructors -#define DECLARE_CLASS_CONSTRUCTOR(CLASS) \ -jerry_value_t \ -NAME_FOR_CLASS_CONSTRUCTOR(CLASS) (const jerry_call_info_t *call_info_p, \ - const jerry_value_t args[], \ - const jerry_length_t args_count) +#define DECLARE_CLASS_CONSTRUCTOR(CLASS) \ + jerry_value_t NAME_FOR_CLASS_CONSTRUCTOR ( \ + CLASS) (const jerry_call_info_t* call_info_p, const jerry_value_t args[], const jerry_length_t args_count) #define REGISTER_CLASS_CONSTRUCTOR(CLASS) \ - jsmbed_wrap_register_class_constructor ( # CLASS, NAME_FOR_CLASS_CONSTRUCTOR(CLASS) ) + jsmbed_wrap_register_class_constructor (#CLASS, NAME_FOR_CLASS_CONSTRUCTOR (CLASS)) // Class functions -#define DECLARE_CLASS_FUNCTION(CLASS, NAME) \ -jerry_value_t \ -NAME_FOR_CLASS_FUNCTION(CLASS, NAME) (const jerry_call_info_t *call_info_p, \ - const jerry_value_t args[], \ - const jerry_length_t args_count) +#define DECLARE_CLASS_FUNCTION(CLASS, NAME) \ + jerry_value_t NAME_FOR_CLASS_FUNCTION (CLASS, NAME) (const jerry_call_info_t* call_info_p, \ + const jerry_value_t args[], \ + const jerry_length_t args_count) #define ATTACH_CLASS_FUNCTION(OBJECT, CLASS, NAME) \ - jsmbed_wrap_register_class_function (OBJECT, # NAME, NAME_FOR_CLASS_FUNCTION(CLASS, NAME) ) + jsmbed_wrap_register_class_function (OBJECT, #NAME, NAME_FOR_CLASS_FUNCTION (CLASS, NAME)) // // 3. Argument checking macros // -#define CHECK_ARGUMENT_COUNT(CLASS, NAME, EXPR) \ - if (!(EXPR)) { \ - const char* error_msg = "ERROR: wrong argument count for " # CLASS "." # NAME ", expected " # EXPR "."; \ - return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast(error_msg)); \ - } +#define CHECK_ARGUMENT_COUNT(CLASS, NAME, EXPR) \ + if (!(EXPR)) \ + { \ + const char* error_msg = "ERROR: wrong argument count for " #CLASS "." #NAME ", expected " #EXPR "."; \ + return jerry_throw_sz (JERRY_ERROR_TYPE, error_msg); \ + } -#define CHECK_ARGUMENT_TYPE_ALWAYS(CLASS, NAME, INDEX, TYPE) \ - if (!jerry_value_is_ ## TYPE (args[INDEX])) { \ - const char* error_msg = "ERROR: wrong argument type for " # CLASS "." # NAME ", expected argument " # INDEX " to be a " # TYPE ".\n"; \ - return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast(error_msg)); \ - } +#define CHECK_ARGUMENT_TYPE_ALWAYS(CLASS, NAME, INDEX, TYPE) \ + if (!jerry_value_is_##TYPE (args[INDEX])) \ + { \ + const char* error_msg = \ + "ERROR: wrong argument type for " #CLASS "." #NAME ", expected argument " #INDEX " to be a " #TYPE ".\n"; \ + return jerry_throw_sz (JERRY_ERROR_TYPE, error_msg); \ + } -#define CHECK_ARGUMENT_TYPE_ON_CONDITION(CLASS, NAME, INDEX, TYPE, EXPR) \ - if ((EXPR)) { \ - if (!jerry_value_is_ ## TYPE (args[INDEX])) { \ - const char* error_msg = "ERROR: wrong argument type for " # CLASS "." # NAME ", expected argument " # INDEX " to be a " # TYPE ".\n"; \ - return jerry_create_error(JERRY_ERROR_TYPE, reinterpret_cast(error_msg)); \ - } \ - } +#define CHECK_ARGUMENT_TYPE_ON_CONDITION(CLASS, NAME, INDEX, TYPE, EXPR) \ + if ((EXPR)) \ + { \ + if (!jerry_value_is_##TYPE (args[INDEX])) \ + { \ + const char* error_msg = \ + "ERROR: wrong argument type for " #CLASS "." #NAME ", expected argument " #INDEX " to be a " #TYPE ".\n"; \ + return jerry_throw_sz (JERRY_ERROR_TYPE, error_msg); \ + } \ + } -#define NAME_FOR_GLOBAL_FUNCTION(NAME) __gen_jsmbed_global_func_ ## NAME -#define NAME_FOR_CLASS_CONSTRUCTOR(CLASS) __gen_jsmbed_class_constructor_ ## CLASS -#define NAME_FOR_CLASS_FUNCTION(CLASS, NAME) __gen_jsmbed_func_c_ ## CLASS ## _f_ ## NAME +#define NAME_FOR_GLOBAL_FUNCTION(NAME) __gen_jsmbed_global_func_##NAME +#define NAME_FOR_CLASS_CONSTRUCTOR(CLASS) __gen_jsmbed_class_constructor_##CLASS +#define NAME_FOR_CLASS_FUNCTION(CLASS, NAME) __gen_jsmbed_func_c_##CLASS##_f_##NAME -#define NAME_FOR_CLASS_NATIVE_CONSTRUCTOR(CLASS, TYPELIST) __gen_native_jsmbed_ ## CLASS ## __Special_create_ ## TYPELIST -#define NAME_FOR_CLASS_NATIVE_DESTRUCTOR(CLASS) __gen_native_jsmbed_ ## CLASS ## __Special_destroy -#define NAME_FOR_CLASS_NATIVE_FUNCTION(CLASS, NAME) __gen_native_jsmbed_ ## CLASS ## _ ## NAME +#define NAME_FOR_CLASS_NATIVE_CONSTRUCTOR(CLASS, TYPELIST) __gen_native_jsmbed_##CLASS##__Special_create_##TYPELIST +#define NAME_FOR_CLASS_NATIVE_DESTRUCTOR(CLASS) __gen_native_jsmbed_##CLASS##__Special_destroy +#define NAME_FOR_CLASS_NATIVE_FUNCTION(CLASS, NAME) __gen_native_jsmbed_##CLASS##_##NAME -#endif // _JERRYSCRIPT_MBED_UTIL_WRAPPERS_H +#endif // _JERRYSCRIPT_MBED_UTIL_WRAPPERS_H diff --git a/targets/nuttx-stm32f4/jerry_main.c b/targets/nuttx-stm32f4/jerry_main.c index 3840b2cb30..c7ff6b2653 100644 --- a/targets/nuttx-stm32f4/jerry_main.c +++ b/targets/nuttx-stm32f4/jerry_main.c @@ -15,13 +15,14 @@ #include #include -#include #include +#include +#include "jerryscript-port.h" #include "jerryscript.h" + #include "jerryscript-ext/debugger.h" #include "jerryscript-ext/handler.h" -#include "jerryscript-port.h" #include "setjmp.h" /** @@ -111,7 +112,7 @@ read_file (const char *file_name, /**< source code */ if (!bytes_read || bytes_read != script_len) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to read file: %s\n", file_name); - free ((void*) buffer); + free ((void *) buffer); fclose (file); return NULL; @@ -132,7 +133,7 @@ static uint32_t str_to_uint (const char *num_str_p, /**< string to convert */ char **out_p) /**< [out] end of the number */ { - assert (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES)); + assert (jerry_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES)); uint32_t result = 0; @@ -157,124 +158,111 @@ str_to_uint (const char *num_str_p, /**< string to convert */ static void print_unhandled_exception (jerry_value_t error_value) /**< error value */ { - assert (jerry_value_is_error (error_value)); + assert (jerry_value_is_exception (error_value)); - error_value = jerry_get_value_from_error (error_value, false); + error_value = jerry_exception_value (error_value, false); jerry_value_t err_str_val = jerry_value_to_string (error_value); - jerry_size_t err_str_size = jerry_get_utf8_string_size (err_str_val); jerry_char_t err_str_buf[256]; - jerry_release_value (error_value); + jerry_value_free (error_value); - if (err_str_size >= 256) - { - const char msg[] = "[Error message too long]"; - err_str_size = sizeof (msg) / sizeof (char) - 1; - memcpy (err_str_buf, msg, err_str_size); - } - else - { - jerry_size_t sz = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size); - assert (sz == err_str_size); - err_str_buf[err_str_size] = 0; + jerry_size_t sz = jerry_string_to_buffer (err_str_val, err_str_buf, sizeof (err_str_buf) - 1, JERRY_ENCODING_UTF8); + err_str_buf[sz] = '\0'; - if (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES) - && jerry_get_error_type (error_value) == JERRY_ERROR_SYNTAX) + if (jerry_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES) && jerry_error_type (error_value) == JERRY_ERROR_SYNTAX) + { + jerry_char_t *string_end_p = err_str_buf + sz; + uint32_t err_line = 0; + uint32_t err_col = 0; + char *path_str_p = NULL; + char *path_str_end_p = NULL; + + /* 1. parse column and line information */ + for (jerry_char_t *current_p = err_str_buf; current_p < string_end_p; current_p++) { - jerry_char_t *string_end_p = err_str_buf + sz; - uint32_t err_line = 0; - uint32_t err_col = 0; - char *path_str_p = NULL; - char *path_str_end_p = NULL; - - /* 1. parse column and line information */ - for (jerry_char_t *current_p = err_str_buf; current_p < string_end_p; current_p++) + if (*current_p == '[') { - if (*current_p == '[') + current_p++; + + if (*current_p == '<') { - current_p++; + break; + } - if (*current_p == '<') - { - break; - } + path_str_p = (char *) current_p; + while (current_p < string_end_p && *current_p != ':') + { + current_p++; + } - path_str_p = (char *) current_p; - while (current_p < string_end_p && *current_p != ':') - { - current_p++; - } + path_str_end_p = (char *) current_p++; - path_str_end_p = (char *) current_p++; + err_line = str_to_uint ((char *) current_p, (char **) ¤t_p); - err_line = str_to_uint ((char *) current_p, (char **) ¤t_p); + current_p++; - current_p++; + err_col = str_to_uint ((char *) current_p, NULL); + break; + } + } /* for */ - err_col = str_to_uint ((char *) current_p, NULL); - break; - } - } /* for */ + if (err_line != 0 && err_col != 0) + { + uint32_t curr_line = 1; - if (err_line != 0 && err_col != 0) - { - uint32_t curr_line = 1; + bool is_printing_context = false; + uint32_t pos = 0; - bool is_printing_context = false; - uint32_t pos = 0; + /* Temporarily modify the error message, so we can use the path. */ + *path_str_end_p = '\0'; - /* Temporarily modify the error message, so we can use the path. */ - *path_str_end_p = '\0'; + size_t source_size; + const jerry_char_t *source_p = read_file (path_str_p, &source_size); - size_t source_size; - const jerry_char_t *source_p = read_file (path_str_p, &source_size); + /* Revert the error message. */ + *path_str_end_p = ':'; - /* Revert the error message. */ - *path_str_end_p = ':'; + /* 2. seek and print */ + while (source_p[pos] != '\0') + { + if (source_p[pos] == '\n') + { + curr_line++; + } - /* 2. seek and print */ - while (source_p[pos] != '\0') + if (err_line < SYNTAX_ERROR_CONTEXT_SIZE + || (err_line >= curr_line && (err_line - curr_line) <= SYNTAX_ERROR_CONTEXT_SIZE)) { - if (source_p[pos] == '\n') - { - curr_line++; - } - - if (err_line < SYNTAX_ERROR_CONTEXT_SIZE - || (err_line >= curr_line - && (err_line - curr_line) <= SYNTAX_ERROR_CONTEXT_SIZE)) - { - /* context must be printed */ - is_printing_context = true; - } - - if (curr_line > err_line) - { - break; - } - - if (is_printing_context) - { - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%c", source_p[pos]); - } - - pos++; + /* context must be printed */ + is_printing_context = true; } - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "\n"); + if (curr_line > err_line) + { + break; + } - while (--err_col) + if (is_printing_context) { - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "~"); + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%c", source_p[pos]); } - jerry_port_log (JERRY_LOG_LEVEL_ERROR, "^\n"); + pos++; } + + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "\n"); + + while (--err_col) + { + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "~"); + } + + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "^\n"); } } jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Script Error: %s\n", err_str_buf); - jerry_release_value (err_str_val); + jerry_value_free (err_str_val); } /* print_unhandled_exception */ /** @@ -284,26 +272,27 @@ static void register_js_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p); + jerry_value_t result_val = jerryx_handler_register_global (name_p, handler_p); - if (jerry_value_is_error (result_val)) + if (jerry_value_is_exception (result_val)) { jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p); } - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_function */ - /** * Main program. * * @return 0 if success, error code otherwise */ #ifdef CONFIG_BUILD_KERNEL -int main (int argc, FAR char *argv[]) +int +main (int argc, FAR char *argv[]) #else /* !defined(CONFIG_BUILD_KERNEL) */ -int jerry_main (int argc, char *argv[]) +int +jerry_main (int argc, char *argv[]) #endif /* defined(CONFIG_BUILD_KERNEL) */ { if (argc > JERRY_MAX_COMMAND_LINE_ARGS) @@ -347,7 +336,7 @@ int jerry_main (int argc, char *argv[]) } else if (!strcmp ("--log-level", argv[i])) { - if (++i < argc && strlen (argv[i]) == 1 && argv[i][0] >='0' && argv[i][0] <= '3') + if (++i < argc && strlen (argv[i]) == 1 && argv[i][0] >= '0' && argv[i][0] <= '3') { set_log_level (argv[i][0] - '0'); } @@ -383,15 +372,14 @@ int jerry_main (int argc, char *argv[]) if (start_debug_server) { - jerryx_debugger_after_connect (jerryx_debugger_tcp_create (debug_port) - && jerryx_debugger_ws_create ()); + jerryx_debugger_after_connect (jerryx_debugger_tcp_create (debug_port) && jerryx_debugger_ws_create ()); } register_js_function ("assert", jerryx_handler_assert); register_js_function ("gc", jerryx_handler_gc); register_js_function ("print", jerryx_handler_print); - jerry_value_t ret_value = jerry_create_undefined (); + jerry_value_t ret_value = jerry_undefined (); if (files_counter == 0) { @@ -400,7 +388,7 @@ int jerry_main (int argc, char *argv[]) ret_value = jerry_parse (script, sizeof (script) - 1, NULL); - if (!jerry_value_is_error (ret_value)) + if (!jerry_value_is_exception (ret_value)) { ret_value = jerry_run (ret_value); } @@ -419,50 +407,48 @@ int jerry_main (int argc, char *argv[]) } jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) file_names[i]); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz (file_names[i]); - ret_value = jerry_parse (source_p, - source_size, - &parse_options); - jerry_release_value (parse_options.resource_name); - free ((void*) source_p); + ret_value = jerry_parse (source_p, source_size, &parse_options); + jerry_value_free (parse_options.source_name); + free ((void *) source_p); - if (!jerry_value_is_error (ret_value)) + if (!jerry_value_is_exception (ret_value)) { jerry_value_t func_val = ret_value; ret_value = jerry_run (func_val); - jerry_release_value (func_val); + jerry_value_free (func_val); } - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { print_unhandled_exception (ret_value); break; } - jerry_release_value (ret_value); - ret_value = jerry_create_undefined (); + jerry_value_free (ret_value); + ret_value = jerry_undefined (); } } int ret_code = JERRY_STANDALONE_EXIT_CODE_OK; - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); - ret_value = jerry_run_all_enqueued_jobs (); + ret_value = jerry_run_microtasks (); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); jerry_cleanup (); return ret_code; diff --git a/targets/nuttx-stm32f4/jerry_module.c b/targets/nuttx-stm32f4/jerry_module.c index 97f92dcfdb..c8738df04b 100644 --- a/targets/nuttx-stm32f4/jerry_module.c +++ b/targets/nuttx-stm32f4/jerry_module.c @@ -14,12 +14,12 @@ */ #include -#include #include +#include #include -#include "jerryscript.h" #include "jerryscript-port.h" +#include "jerryscript.h" /** * Computes the end of the directory part of a path. @@ -102,8 +102,7 @@ typedef struct jerry_port_module_t /** * Native info descriptor for modules. */ -static const jerry_object_native_info_t jerry_port_module_native_info = -{ +static const jerry_object_native_info_t jerry_port_module_native_info = { .free_cb = NULL, }; @@ -136,8 +135,8 @@ jerry_port_module_free (jerry_port_module_manager_t *manager_p, /**< module mana if (release_all || module_p->realm == realm) { free (module_p->path_p); - jerry_release_value (module_p->realm); - jerry_release_value (module_p->module); + jerry_value_free (module_p->realm); + jerry_value_free (module_p->module); free (module_p); @@ -174,20 +173,18 @@ jerry_port_module_manager_init (void *user_data_p) static void jerry_port_module_manager_deinit (void *user_data_p) /**< context pointer to deinitialize */ { - jerry_value_t undef = jerry_create_undefined (); + jerry_value_t undef = jerry_undefined (); jerry_port_module_free ((jerry_port_module_manager_t *) user_data_p, undef); - jerry_release_value (undef); + jerry_value_free (undef); } /* jerry_port_module_manager_deinit */ /** * Declare the context data manager for modules. */ -static const jerry_context_data_manager_t jerry_port_module_manager = -{ - .init_cb = jerry_port_module_manager_init, - .deinit_cb = jerry_port_module_manager_deinit, - .bytes_needed = sizeof (jerry_port_module_manager_t) -}; +static const jerry_context_data_manager_t jerry_port_module_manager = { .init_cb = jerry_port_module_manager_init, + .deinit_cb = jerry_port_module_manager_deinit, + .bytes_needed = + sizeof (jerry_port_module_manager_t) }; /** * Default module resolver. @@ -201,44 +198,43 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { (void) user_p; - jerry_port_module_t *module_p; const jerry_char_t *base_path_p = NULL; size_t base_path_length = 0; + jerry_port_module_t *module_p = jerry_object_get_native_ptr (referrer, &jerry_port_module_native_info); - if (jerry_get_object_native_pointer (referrer, (void **) &module_p, &jerry_port_module_native_info)) + if (module_p != NULL) { base_path_p = module_p->path_p; base_path_length = module_p->base_path_length; } - jerry_size_t in_path_length = jerry_get_utf8_string_size (specifier); + jerry_size_t in_path_length = jerry_string_size (specifier, JERRY_ENCODING_UTF8); jerry_char_t *in_path_p = (jerry_char_t *) malloc (in_path_length + 1); - jerry_string_to_utf8_char_buffer (specifier, in_path_p, in_path_length); + jerry_string_to_buffer (specifier, in_path_p, in_path_length, JERRY_ENCODING_UTF8); in_path_p[in_path_length] = '\0'; jerry_char_t *path_p = jerry_port_normalize_path (in_path_p, in_path_length, base_path_p, base_path_length); if (path_p == NULL) { - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Out of memory"); + return jerry_throw_sz (JERRY_ERROR_COMMON, "Out of memory"); } - jerry_value_t realm = jerry_get_global_object (); + jerry_value_t realm = jerry_current_realm (); jerry_port_module_manager_t *manager_p; - manager_p = (jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager); + manager_p = (jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager); module_p = manager_p->module_head_p; while (module_p != NULL) { - if (module_p->realm == realm - && strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0) + if (module_p->realm == realm && strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0) { free (path_p); free (in_path_p); - jerry_release_value (realm); - return jerry_acquire_value (module_p->module); + jerry_value_free (realm); + return jerry_value_copy (module_p->module); } module_p = module_p->next_p; @@ -251,28 +247,25 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier { free (path_p); free (in_path_p); - jerry_release_value (realm); - /* TODO: This is incorrect, but makes test262 module tests pass - * (they should throw SyntaxError, but not because the module cannot be found). */ - return jerry_create_error (JERRY_ERROR_SYNTAX, (const jerry_char_t *) "Module file not found"); + jerry_value_free (realm); + + return jerry_throw_sz (JERRY_ERROR_SYNTAX, "Module file not found"); } jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string_sz ((const jerry_char_t *) in_path_p, in_path_length); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string (in_path_p, in_path_length, JERRY_ENCODING_UTF8); - jerry_value_t ret_value = jerry_parse (source_p, - source_size, - &parse_options); + jerry_value_t ret_value = jerry_parse (source_p, source_size, &parse_options); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); jerry_port_release_source (source_p); free (in_path_p); - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { free (path_p); - jerry_release_value (realm); + jerry_value_free (realm); return ret_value; } @@ -282,9 +275,9 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier module_p->path_p = path_p; module_p->base_path_length = jerry_port_get_directory_end (module_p->path_p); module_p->realm = realm; - module_p->module = jerry_acquire_value (ret_value); + module_p->module = jerry_value_copy (ret_value); - jerry_set_object_native_pointer (ret_value, module_p, &jerry_port_module_native_info); + jerry_object_set_native_ptr (ret_value, &jerry_port_module_native_info, module_p); manager_p->module_head_p = module_p; return ret_value; @@ -297,6 +290,5 @@ void jerry_port_module_release (const jerry_value_t realm) /**< if this argument is object, release only those modules, * which realm value is equal to this argument. */ { - jerry_port_module_free ((jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager), - realm); + jerry_port_module_free ((jerry_port_module_manager_t *) jerry_context_data (&jerry_port_module_manager), realm); } /* jerry_port_module_release */ diff --git a/targets/particle/source/main.cpp b/targets/particle/source/main.cpp index 97d56781ba..b5cd6cebac 100644 --- a/targets/particle/source/main.cpp +++ b/targets/particle/source/main.cpp @@ -30,16 +30,16 @@ set_led (const jerry_value_t func_value, /**< function object */ if (args_cnt != 2) { Serial.println ("Wrong arguments count in 'test.setLed' function."); - return jerry_create_boolean (false); + return jerry_boolean (false); } - int ledPin = jerry_get_number_value (args_p[0]); + int ledPin = jerry_value_as_number (args_p[0]); bool value = jerry_value_is_true (args_p[1]); pinMode (ledPin, OUTPUT); digitalWrite (ledPin, value); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* set_led */ /** @@ -54,14 +54,14 @@ js_delay (const jerry_value_t func_value, /**< function object */ if (args_cnt != 1) { Serial.println ("Wrong arguments count in 'test.delay' function."); - return jerry_create_boolean (false); + return jerry_boolean (false); } - int millisec = jerry_get_number_value (args_p[0]); + int millisec = jerry_value_as_number (args_p[0]); delay (millisec); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* js_delay */ /* @@ -73,32 +73,32 @@ init_jerry () jerry_init (JERRY_INIT_EMPTY); /* Create an empty JS object */ - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); jerry_value_t func_obj; jerry_value_t prop_name; - func_obj = jerry_create_external_function (set_led); - prop_name = jerry_create_string ((const jerry_char_t *) "setLed"); - jerry_release_value (jerry_set_property (object, prop_name, func_obj)); - jerry_release_value (prop_name); - jerry_release_value (func_obj); + func_obj = jerry_function_external (set_led); + prop_name = jerry_string_sz ("setLed"); + jerry_value_free (jerry_object_set (object, prop_name, func_obj)); + jerry_value_free (prop_name); + jerry_value_free (func_obj); - func_obj = jerry_create_external_function (js_delay); - prop_name = jerry_create_string ((const jerry_char_t *) "delay"); - jerry_release_value (jerry_set_property (object, prop_name, func_obj)); - jerry_release_value (prop_name); - jerry_release_value (func_obj); + func_obj = jerry_function_external (js_delay); + prop_name = jerry_string_sz ("delay"); + jerry_value_free (jerry_object_set (object, prop_name, func_obj)); + jerry_value_free (prop_name); + jerry_value_free (func_obj); /* Wrap the JS object (not empty anymore) into a jerry api value */ - jerry_value_t global_object = jerry_get_global_object (); + jerry_value_t global_object = jerry_current_realm (); /* Add the JS object to the global context */ - prop_name = jerry_create_string ((const jerry_char_t *) "test"); - jerry_release_value (jerry_set_property (global_object, prop_name, object)); - jerry_release_value (prop_name); - jerry_release_value (object); - jerry_release_value (global_object); + prop_name = jerry_string_sz ("test"); + jerry_value_free (jerry_object_set (global_object, prop_name, object)); + jerry_value_free (prop_name); + jerry_value_free (object); + jerry_value_free (global_object); } /* init_jerry */ /** @@ -117,7 +117,7 @@ test_jerry () jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS); /* Free JavaScript value, returned by eval */ - jerry_release_value (eval_ret); + jerry_value_free (eval_ret); } /* test_jerry */ /** diff --git a/targets/riot-stm32f4/source/main-riotos.c b/targets/riot-stm32f4/source/main-riotos.c index d17be877e8..9ffd355e81 100644 --- a/targets/riot-stm32f4/source/main-riotos.c +++ b/targets/riot-stm32f4/source/main-riotos.c @@ -16,10 +16,12 @@ #include #include #include -#include "shell.h" + +#include "jerryscript-port.h" #include "jerryscript.h" + #include "jerryscript-ext/handler.h" -#include "jerryscript-port.h" +#include "shell.h" /** * Standalone Jerry exit codes @@ -34,26 +36,27 @@ static void register_js_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p); + jerry_value_t result_val = jerryx_handler_register_global (name_p, handler_p); - if (jerry_value_is_error (result_val)) + if (jerry_value_is_exception (result_val)) { printf ("Warning: failed to register '%s' method.", name_p); } - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_function */ /** * Jerryscript simple test */ -int test_jerry (int argc, char **argv) +int +test_jerry (int argc, char **argv) { /* Suppress compiler errors */ (void) argc; (void) argv; - jerry_value_t ret_value = jerry_create_undefined (); + jerry_value_t ret_value = jerry_undefined (); const jerry_char_t script[] = "print ('Hello, World!');"; printf ("This test run the following script code: [%s]\n\n", script); @@ -67,7 +70,7 @@ int test_jerry (int argc, char **argv) /* Setup Global scope code */ ret_value = jerry_parse (script, sizeof (script) - 1, NULL); - if (!jerry_value_is_error (ret_value)) + if (!jerry_value_is_exception (ret_value)) { /* Execute the parsed source code in the Global scope */ ret_value = jerry_run (ret_value); @@ -75,14 +78,14 @@ int test_jerry (int argc, char **argv) int ret_code = JERRY_STANDALONE_EXIT_CODE_OK; - if (jerry_value_is_error (ret_value)) + if (jerry_value_is_exception (ret_value)) { printf ("Script Error!"); ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL; } - jerry_release_value (ret_value); + jerry_value_free (ret_value); /* Cleanup engine */ jerry_cleanup (); @@ -91,14 +94,17 @@ int test_jerry (int argc, char **argv) } /* test_jerry */ -const shell_command_t shell_commands[] = { - { "test", "Jerryscript Hello World test", test_jerry }, - { NULL, NULL, NULL } -}; +const shell_command_t shell_commands[] = { { "test", "Jerryscript Hello World test", test_jerry }, + { NULL, NULL, NULL } }; -int main (void) +int +main (void) { - union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () }; + union + { + double d; + unsigned u; + } now = { .d = jerry_port_get_current_time () }; srand (now.u); printf ("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); printf ("This board features a(n) %s MCU.\n", RIOT_MCU); diff --git a/targets/zephyr/src/main-zephyr.c b/targets/zephyr/src/main-zephyr.c index c0d02cff12..db81a3c2a5 100644 --- a/targets/zephyr/src/main-zephyr.c +++ b/targets/zephyr/src/main-zephyr.c @@ -14,16 +14,16 @@ */ #include -#include #include - +#include #include -#include -#include "getline-zephyr.h" -#include "jerryscript.h" #include "jerryscript-port.h" +#include "jerryscript.h" + +#include "getline-zephyr.h" #include "jerryscript-ext/handler.h" +#include static jerry_value_t print_function; @@ -34,25 +34,24 @@ static void register_js_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p); + jerry_value_t result_val = jerryx_handler_register_global (name_p, handler_p); - if (jerry_value_is_error (result_val)) + if (jerry_value_is_exception (result_val)) { jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p); } - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_function */ -static int shell_cmd_handler (char *source_buffer) +static int +shell_cmd_handler (char *source_buffer) { jerry_value_t ret_val; - ret_val = jerry_eval ((jerry_char_t *) source_buffer, - strlen (source_buffer), - JERRY_PARSE_NO_OPTS); + ret_val = jerry_eval ((jerry_char_t *) source_buffer, strlen (source_buffer), JERRY_PARSE_NO_OPTS); - if (jerry_value_is_error (ret_val)) + if (jerry_value_is_exception (ret_val)) { /* User-friendly error messages require at least "cp" JerryScript profile. Include a message prefix in case "cp_minimal" profile @@ -60,44 +59,47 @@ static int shell_cmd_handler (char *source_buffer) printf ("Error executing statement: "); /* Clear error flag, otherwise print call below won't produce any output. */ - ret_val = jerry_get_value_from_error (ret_val, true); + ret_val = jerry_exception_value (ret_val, true); } - if (!jerry_value_is_error (print_function)) + if (!jerry_value_is_exception (print_function)) { - jerry_value_t ret_val_print = jerry_call_function (print_function, - jerry_create_undefined (), - &ret_val, - 1); - jerry_release_value (ret_val_print); + jerry_value_t ret_val_print = jerry_call (print_function, jerry_undefined (), &ret_val, 1); + jerry_value_free (ret_val_print); } - jerry_release_value (ret_val); + jerry_value_free (ret_val); return 0; } /* shell_cmd_handler */ -void main (void) +void +main (void) { - union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () }; + union + { + double d; + unsigned u; + } now = { .d = jerry_port_get_current_time () }; srand (now.u); uint32_t zephyr_ver = sys_kernel_version_get (); printf ("JerryScript build: " __DATE__ " " __TIME__ "\n"); printf ("JerryScript API %d.%d.%d\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION, JERRY_API_PATCH_VERSION); - printf ("Zephyr version %d.%d.%d\n", (int)SYS_KERNEL_VER_MAJOR (zephyr_ver), - (int)SYS_KERNEL_VER_MINOR (zephyr_ver), - (int)SYS_KERNEL_VER_PATCHLEVEL (zephyr_ver)); + printf ("Zephyr version %d.%d.%d\n", + (int) SYS_KERNEL_VER_MAJOR (zephyr_ver), + (int) SYS_KERNEL_VER_MINOR (zephyr_ver), + (int) SYS_KERNEL_VER_PATCHLEVEL (zephyr_ver)); zephyr_getline_init (); jerry_init (JERRY_INIT_EMPTY); register_js_function ("print", jerryx_handler_print); - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print"); - print_function = jerry_get_property (global_obj_val, print_func_name_val); - jerry_release_value (print_func_name_val); - jerry_release_value (global_obj_val); - if (jerry_value_is_error (print_function)) + jerry_value_t print_func_name_val = jerry_string_sz ("print"); + print_function = jerry_object_get (global_obj_val, print_func_name_val); + jerry_value_free (print_func_name_val); + jerry_value_free (global_obj_val); + if (jerry_value_is_exception (print_function)) { printf ("Error: could not look up print function, expression results won't be printed\n"); } @@ -105,8 +107,8 @@ void main (void) while (1) { char *s; - printf("js> "); - fflush(stdout); + printf ("js> "); + fflush (stdout); s = zephyr_getline (); if (*s) { diff --git a/tests/debugger/do_abort.expected b/tests/debugger/do_abort.expected index 7656e41ae5..b659d0358a 100644 --- a/tests/debugger/do_abort.expected +++ b/tests/debugger/do_abort.expected @@ -9,4 +9,4 @@ Stopped at tests/debugger/do_abort.js:20 (in g() at line:19, col:1) (jerry-debugger) s Stopped at tests/debugger/do_abort.js:16 (in f() at line:15, col:1) (jerry-debugger) abort new Error('Fatal error :)') -err: Error: Fatal error :) +err: Unhandled exception: Error: Fatal error :) diff --git a/tests/debugger/do_throw.expected b/tests/debugger/do_throw.expected index d191be816b..39a8b86a1c 100644 --- a/tests/debugger/do_throw.expected +++ b/tests/debugger/do_throw.expected @@ -17,4 +17,4 @@ Stopped at tests/debugger/do_throw.js:34 (jerry-debugger) eval e.message.length 538 (jerry-debugger) throw new Error('Exit') -err: Error: Exit +err: Unhandled exception: Error: Exit diff --git a/tests/debugger/do_throw_adv.expected b/tests/debugger/do_throw_adv.expected index aef65829d6..d6176bf52a 100644 --- a/tests/debugger/do_throw_adv.expected +++ b/tests/debugger/do_throw_adv.expected @@ -39,4 +39,4 @@ Exception throw detected (to disable automatic stop type exception 0) Exception hint: 16 Stopped at tests/debugger/do_throw_adv.js:18 (in f() at line:17, col:1) (jerry-debugger) c -err: 16 +err: Unhandled exception: 16 diff --git a/tests/unit-core/test-abort.c b/tests/unit-core/test-abort.c index 6d50b21353..e8d3329418 100644 --- a/tests/unit-core/test-abort.c +++ b/tests/unit-core/test-abort.c @@ -25,8 +25,8 @@ callback_func (const jerry_call_info_t *call_info_p, const jerry_value_t args_p[ JERRY_UNUSED (args_p); JERRY_UNUSED (args_count); - jerry_value_t value = jerry_create_string ((jerry_char_t *) "Abort run!"); - value = jerry_create_abort_from_value (value, true); + jerry_value_t value = jerry_string_sz ("Abort run!"); + value = jerry_throw_abort (value, true); return value; } /* callback_func */ @@ -37,16 +37,16 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); - jerry_value_t callback_name = jerry_create_string ((jerry_char_t *) "callback"); - jerry_value_t func = jerry_create_external_function (callback_func); - jerry_value_t res = jerry_set_property (global, callback_name, func); - TEST_ASSERT (!jerry_value_is_error (res)); + jerry_value_t global = jerry_current_realm (); + jerry_value_t callback_name = jerry_string_sz ("callback"); + jerry_value_t func = jerry_function_external (callback_func); + jerry_value_t res = jerry_object_set (global, callback_name, func); + TEST_ASSERT (!jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (func); - jerry_release_value (callback_name); - jerry_release_value (global); + jerry_value_free (res); + jerry_value_free (func); + jerry_value_free (callback_name); + jerry_value_free (global); const jerry_char_t inf_loop_code_src1[] = TEST_STRING_LITERAL ("while(true) {\n" " with ({}) {\n" @@ -60,13 +60,13 @@ main (void) jerry_value_t parsed_code_val = jerry_parse (inf_loop_code_src1, sizeof (inf_loop_code_src1) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); res = jerry_run (parsed_code_val); TEST_ASSERT (jerry_value_is_abort (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); const jerry_char_t inf_loop_code_src2[] = TEST_STRING_LITERAL ("function f() {" " while(true) {\n" @@ -89,32 +89,32 @@ main (void) parsed_code_val = jerry_parse (inf_loop_code_src2, sizeof (inf_loop_code_src2) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); res = jerry_run (parsed_code_val); TEST_ASSERT (jerry_value_is_abort (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); /* Test flag overwrites. */ - jerry_value_t value = jerry_create_string ((jerry_char_t *) "Error description"); + jerry_value_t value = jerry_string_sz ("Error description"); TEST_ASSERT (!jerry_value_is_abort (value)); - TEST_ASSERT (!jerry_value_is_error (value)); + TEST_ASSERT (!jerry_value_is_exception (value)); - value = jerry_create_abort_from_value (value, true); + value = jerry_throw_abort (value, true); TEST_ASSERT (jerry_value_is_abort (value)); - TEST_ASSERT (jerry_value_is_error (value)); + TEST_ASSERT (jerry_value_is_exception (value)); - value = jerry_create_error_from_value (value, true); + value = jerry_throw_value (value, true); TEST_ASSERT (!jerry_value_is_abort (value)); - TEST_ASSERT (jerry_value_is_error (value)); + TEST_ASSERT (jerry_value_is_exception (value)); - value = jerry_create_abort_from_value (value, true); + value = jerry_throw_abort (value, true); TEST_ASSERT (jerry_value_is_abort (value)); - TEST_ASSERT (jerry_value_is_error (value)); + TEST_ASSERT (jerry_value_is_exception (value)); - jerry_release_value (value); + jerry_value_free (value); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-api-binary-operations-arithmetics.c b/tests/unit-core/test-api-binary-operations-arithmetics.c index cd695aaa0c..185dc12c01 100644 --- a/tests/unit-core/test-api-binary-operations-arithmetics.c +++ b/tests/unit-core/test-api-binary-operations-arithmetics.c @@ -35,7 +35,7 @@ typedef struct { - jerry_binary_operation_t op; + jerry_binary_op_t op; jerry_value_t lhs; jerry_value_t rhs; jerry_value_t expected; @@ -43,7 +43,7 @@ typedef struct typedef struct { - jerry_binary_operation_t op; + jerry_binary_op_t op; jerry_value_t lhs; jerry_value_t rhs; } test_nan_entry_t; @@ -57,230 +57,194 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t obj1 = jerry_eval ((const jerry_char_t *) "o={x:1};o", 9, JERRY_PARSE_NO_OPTS); - jerry_value_t obj2 = jerry_eval ((const jerry_char_t *) "o={x:1};o", 9, JERRY_PARSE_NO_OPTS); - jerry_value_t err1 = jerry_create_error (JERRY_ERROR_SYNTAX, (const jerry_char_t *) "error"); + jerry_value_t obj1 = jerry_eval ((jerry_char_t *) "o={x:1};o", 9, JERRY_PARSE_NO_OPTS); + jerry_value_t obj2 = jerry_eval ((jerry_char_t *) "o={x:1};o", 9, JERRY_PARSE_NO_OPTS); + jerry_value_t err1 = jerry_throw_sz (JERRY_ERROR_SYNTAX, "error"); test_nan_entry_t test_nans[] = { /* Testing addition (+) */ - T_NAN (JERRY_BIN_OP_ADD, jerry_create_number (3.1), jerry_create_undefined ()), - T_NAN (JERRY_BIN_OP_ADD, jerry_create_undefined (), jerry_create_undefined ()), - T_NAN (JERRY_BIN_OP_ADD, jerry_create_undefined (), jerry_create_null ()), + T_NAN (JERRY_BIN_OP_ADD, jerry_number (3.1), jerry_undefined ()), + T_NAN (JERRY_BIN_OP_ADD, jerry_undefined (), jerry_undefined ()), + T_NAN (JERRY_BIN_OP_ADD, jerry_undefined (), jerry_null ()), /* Testing subtraction (-), multiplication (*), division (/), remainder (%) */ - T_ARI (jerry_create_number (3.1), jerry_create_undefined ()), - T_ARI (jerry_create_string ((const jerry_char_t *) "foo"), jerry_create_string ((const jerry_char_t *) "bar")), - T_ARI (jerry_create_string ((const jerry_char_t *) "foo"), jerry_create_undefined ()), - T_ARI (jerry_create_string ((const jerry_char_t *) "foo"), jerry_create_null ()), - T_ARI (jerry_create_string ((const jerry_char_t *) "foo"), jerry_create_number (5.0)), - T_ARI (jerry_create_undefined (), jerry_create_string ((const jerry_char_t *) "foo")), - T_ARI (jerry_create_null (), jerry_create_string ((const jerry_char_t *) "foo")), - T_ARI (jerry_create_number (5.0), jerry_create_string ((const jerry_char_t *) "foo")), - T_ARI (jerry_create_undefined (), jerry_create_undefined ()), - T_ARI (jerry_create_undefined (), jerry_create_null ()), - T_ARI (jerry_create_null (), jerry_create_undefined ()), - T_ARI (jerry_acquire_value (obj1), jerry_acquire_value (obj1)), - T_ARI (jerry_acquire_value (obj1), jerry_acquire_value (obj2)), - T_ARI (jerry_acquire_value (obj2), jerry_acquire_value (obj1)), - T_ARI (jerry_acquire_value (obj2), jerry_create_undefined ()), - T_ARI (jerry_acquire_value (obj1), jerry_create_string ((const jerry_char_t *) "foo")), - T_ARI (jerry_acquire_value (obj1), jerry_create_null ()), - T_ARI (jerry_acquire_value (obj1), jerry_create_boolean (true)), - T_ARI (jerry_acquire_value (obj1), jerry_create_boolean (false)), - T_ARI (jerry_acquire_value (obj1), jerry_create_number (5.0)), + T_ARI (jerry_number (3.1), jerry_undefined ()), + T_ARI (jerry_string_sz ("foo"), jerry_string_sz ("bar")), + T_ARI (jerry_string_sz ("foo"), jerry_undefined ()), + T_ARI (jerry_string_sz ("foo"), jerry_null ()), + T_ARI (jerry_string_sz ("foo"), jerry_number (5.0)), + T_ARI (jerry_undefined (), jerry_string_sz ("foo")), + T_ARI (jerry_null (), jerry_string_sz ("foo")), + T_ARI (jerry_number (5.0), jerry_string_sz ("foo")), + T_ARI (jerry_undefined (), jerry_undefined ()), + T_ARI (jerry_undefined (), jerry_null ()), + T_ARI (jerry_null (), jerry_undefined ()), + T_ARI (jerry_value_copy (obj1), jerry_value_copy (obj1)), + T_ARI (jerry_value_copy (obj1), jerry_value_copy (obj2)), + T_ARI (jerry_value_copy (obj2), jerry_value_copy (obj1)), + T_ARI (jerry_value_copy (obj2), jerry_undefined ()), + T_ARI (jerry_value_copy (obj1), jerry_string_sz ("foo")), + T_ARI (jerry_value_copy (obj1), jerry_null ()), + T_ARI (jerry_value_copy (obj1), jerry_boolean (true)), + T_ARI (jerry_value_copy (obj1), jerry_boolean (false)), + T_ARI (jerry_value_copy (obj1), jerry_number (5.0)), /* Testing division (/) */ - T_NAN (JERRY_BIN_OP_DIV, jerry_create_boolean (false), jerry_create_boolean (false)), - T_NAN (JERRY_BIN_OP_DIV, jerry_create_number (0.0), jerry_create_number (0.0)), - T_NAN (JERRY_BIN_OP_DIV, jerry_create_null (), jerry_create_null ()), + T_NAN (JERRY_BIN_OP_DIV, jerry_boolean (false), jerry_boolean (false)), + T_NAN (JERRY_BIN_OP_DIV, jerry_number (0.0), jerry_number (0.0)), + T_NAN (JERRY_BIN_OP_DIV, jerry_null (), jerry_null ()), /* Testing remainder (%) */ - T_NAN (JERRY_BIN_OP_REM, jerry_create_boolean (true), jerry_create_boolean (false)), - T_NAN (JERRY_BIN_OP_REM, jerry_create_boolean (false), jerry_create_boolean (false)), - T_NAN (JERRY_BIN_OP_REM, jerry_create_number (0.0), jerry_create_number (0.0)), - T_NAN (JERRY_BIN_OP_REM, jerry_create_null (), jerry_create_null ()), + T_NAN (JERRY_BIN_OP_REM, jerry_boolean (true), jerry_boolean (false)), + T_NAN (JERRY_BIN_OP_REM, jerry_boolean (false), jerry_boolean (false)), + T_NAN (JERRY_BIN_OP_REM, jerry_number (0.0), jerry_number (0.0)), + T_NAN (JERRY_BIN_OP_REM, jerry_null (), jerry_null ()), }; for (uint32_t idx = 0; idx < sizeof (test_nans) / sizeof (test_nan_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (test_nans[idx].op, test_nans[idx].lhs, test_nans[idx].rhs); + jerry_value_t result = jerry_binary_op (test_nans[idx].op, test_nans[idx].lhs, test_nans[idx].rhs); TEST_ASSERT (jerry_value_is_number (result)); - double num = jerry_get_number_value (result); + double num = jerry_value_as_number (result); TEST_ASSERT (num != num); - jerry_release_value (test_nans[idx].lhs); - jerry_release_value (test_nans[idx].rhs); - jerry_release_value (result); + jerry_value_free (test_nans[idx].lhs); + jerry_value_free (test_nans[idx].rhs); + jerry_value_free (result); } test_entry_t tests[] = { /* Testing addition (+) */ - T (JERRY_BIN_OP_ADD, jerry_create_number (5.0), jerry_create_number (5.0), jerry_create_number (10.0)), - T (JERRY_BIN_OP_ADD, jerry_create_number (3.1), jerry_create_number (10), jerry_create_number (13.1)), - T (JERRY_BIN_OP_ADD, jerry_create_number (3.1), jerry_create_boolean (true), jerry_create_number (4.1)), + T (JERRY_BIN_OP_ADD, jerry_number (5.0), jerry_number (5.0), jerry_number (10.0)), + T (JERRY_BIN_OP_ADD, jerry_number (3.1), jerry_number (10), jerry_number (13.1)), + T (JERRY_BIN_OP_ADD, jerry_number (3.1), jerry_boolean (true), jerry_number (4.1)), + T (JERRY_BIN_OP_ADD, jerry_string_sz ("foo"), jerry_string_sz ("bar"), jerry_string_sz ("foobar")), + T (JERRY_BIN_OP_ADD, jerry_string_sz ("foo"), jerry_undefined (), jerry_string_sz ("fooundefined")), + T (JERRY_BIN_OP_ADD, jerry_string_sz ("foo"), jerry_null (), jerry_string_sz ("foonull")), + T (JERRY_BIN_OP_ADD, jerry_string_sz ("foo"), jerry_number (5.0), jerry_string_sz ("foo5")), + + T (JERRY_BIN_OP_ADD, jerry_null (), jerry_null (), jerry_number (0.0)), + T (JERRY_BIN_OP_ADD, jerry_boolean (true), jerry_boolean (true), jerry_number (2.0)), + T (JERRY_BIN_OP_ADD, jerry_boolean (true), jerry_boolean (false), jerry_number (1.0)), + T (JERRY_BIN_OP_ADD, jerry_boolean (false), jerry_boolean (true), jerry_number (1.0)), + T (JERRY_BIN_OP_ADD, jerry_boolean (false), jerry_boolean (false), jerry_number (0.0)), T (JERRY_BIN_OP_ADD, - jerry_create_string ((const jerry_char_t *) "foo"), - jerry_create_string ((const jerry_char_t *) "bar"), - jerry_create_string ((const jerry_char_t *) "foobar")), + jerry_value_copy (obj1), + jerry_value_copy (obj1), + jerry_string_sz ("[object Object][object Object]")), T (JERRY_BIN_OP_ADD, - jerry_create_string ((const jerry_char_t *) "foo"), - jerry_create_undefined (), - jerry_create_string ((const jerry_char_t *) "fooundefined")), + jerry_value_copy (obj1), + jerry_value_copy (obj2), + jerry_string_sz ("[object Object][object Object]")), T (JERRY_BIN_OP_ADD, - jerry_create_string ((const jerry_char_t *) "foo"), - jerry_create_null (), - jerry_create_string ((const jerry_char_t *) "foonull")), - T (JERRY_BIN_OP_ADD, - jerry_create_string ((const jerry_char_t *) "foo"), - jerry_create_number (5.0), - jerry_create_string ((const jerry_char_t *) "foo5")), - - T (JERRY_BIN_OP_ADD, jerry_create_null (), jerry_create_null (), jerry_create_number (0.0)), - T (JERRY_BIN_OP_ADD, jerry_create_boolean (true), jerry_create_boolean (true), jerry_create_number (2.0)), - T (JERRY_BIN_OP_ADD, jerry_create_boolean (true), jerry_create_boolean (false), jerry_create_number (1.0)), - T (JERRY_BIN_OP_ADD, jerry_create_boolean (false), jerry_create_boolean (true), jerry_create_number (1.0)), - T (JERRY_BIN_OP_ADD, jerry_create_boolean (false), jerry_create_boolean (false), jerry_create_number (0.0)), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_acquire_value (obj1), - jerry_create_string ((const jerry_char_t *) "[object Object][object Object]")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_acquire_value (obj2), - jerry_create_string ((const jerry_char_t *) "[object Object][object Object]")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj2), - jerry_acquire_value (obj1), - jerry_create_string ((const jerry_char_t *) "[object Object][object Object]")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_create_null (), - jerry_create_string ((const jerry_char_t *) "[object Object]null")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_create_undefined (), - jerry_create_string ((const jerry_char_t *) "[object Object]undefined")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_create_boolean (true), - jerry_create_string ((const jerry_char_t *) "[object Object]true")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_create_boolean (false), - jerry_create_string ((const jerry_char_t *) "[object Object]false")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_create_number (5.0), - jerry_create_string ((const jerry_char_t *) "[object Object]5")), - T (JERRY_BIN_OP_ADD, - jerry_acquire_value (obj1), - jerry_create_string ((const jerry_char_t *) "foo"), - jerry_create_string ((const jerry_char_t *) "[object Object]foo")), + jerry_value_copy (obj2), + jerry_value_copy (obj1), + jerry_string_sz ("[object Object][object Object]")), + T (JERRY_BIN_OP_ADD, jerry_value_copy (obj1), jerry_null (), jerry_string_sz ("[object Object]null")), + T (JERRY_BIN_OP_ADD, jerry_value_copy (obj1), jerry_undefined (), jerry_string_sz ("[object Object]undefined")), + T (JERRY_BIN_OP_ADD, jerry_value_copy (obj1), jerry_boolean (true), jerry_string_sz ("[object Object]true")), + T (JERRY_BIN_OP_ADD, jerry_value_copy (obj1), jerry_boolean (false), jerry_string_sz ("[object Object]false")), + T (JERRY_BIN_OP_ADD, jerry_value_copy (obj1), jerry_number (5.0), jerry_string_sz ("[object Object]5")), + T (JERRY_BIN_OP_ADD, jerry_value_copy (obj1), jerry_string_sz ("foo"), jerry_string_sz ("[object Object]foo")), /* Testing subtraction (-) */ - T (JERRY_BIN_OP_SUB, jerry_create_number (5.0), jerry_create_number (5.0), jerry_create_number (0.0)), - T (JERRY_BIN_OP_SUB, jerry_create_number (3.1), jerry_create_number (10), jerry_create_number (-6.9)), - T (JERRY_BIN_OP_SUB, jerry_create_number (3.1), jerry_create_boolean (true), jerry_create_number (2.1)), - T (JERRY_BIN_OP_SUB, jerry_create_boolean (true), jerry_create_boolean (true), jerry_create_number (0.0)), - T (JERRY_BIN_OP_SUB, jerry_create_boolean (true), jerry_create_boolean (false), jerry_create_number (1.0)), - T (JERRY_BIN_OP_SUB, jerry_create_boolean (false), jerry_create_boolean (true), jerry_create_number (-1.0)), - T (JERRY_BIN_OP_SUB, jerry_create_boolean (false), jerry_create_boolean (false), jerry_create_number (0.0)), - T (JERRY_BIN_OP_SUB, jerry_create_null (), jerry_create_null (), jerry_create_number (-0.0)), + T (JERRY_BIN_OP_SUB, jerry_number (5.0), jerry_number (5.0), jerry_number (0.0)), + T (JERRY_BIN_OP_SUB, jerry_number (3.1), jerry_number (10), jerry_number (-6.9)), + T (JERRY_BIN_OP_SUB, jerry_number (3.1), jerry_boolean (true), jerry_number (2.1)), + T (JERRY_BIN_OP_SUB, jerry_boolean (true), jerry_boolean (true), jerry_number (0.0)), + T (JERRY_BIN_OP_SUB, jerry_boolean (true), jerry_boolean (false), jerry_number (1.0)), + T (JERRY_BIN_OP_SUB, jerry_boolean (false), jerry_boolean (true), jerry_number (-1.0)), + T (JERRY_BIN_OP_SUB, jerry_boolean (false), jerry_boolean (false), jerry_number (0.0)), + T (JERRY_BIN_OP_SUB, jerry_null (), jerry_null (), jerry_number (-0.0)), /* Testing multiplication (*) */ - T (JERRY_BIN_OP_MUL, jerry_create_number (5.0), jerry_create_number (5.0), jerry_create_number (25.0)), - T (JERRY_BIN_OP_MUL, jerry_create_number (3.1), jerry_create_number (10), jerry_create_number (31)), - T (JERRY_BIN_OP_MUL, jerry_create_number (3.1), jerry_create_boolean (true), jerry_create_number (3.1)), - T (JERRY_BIN_OP_MUL, jerry_create_boolean (true), jerry_create_boolean (true), jerry_create_number (1.0)), - T (JERRY_BIN_OP_MUL, jerry_create_boolean (true), jerry_create_boolean (false), jerry_create_number (0.0)), - T (JERRY_BIN_OP_MUL, jerry_create_boolean (false), jerry_create_boolean (true), jerry_create_number (0.0)), - T (JERRY_BIN_OP_MUL, jerry_create_boolean (false), jerry_create_boolean (false), jerry_create_number (0.0)), - T (JERRY_BIN_OP_MUL, jerry_create_null (), jerry_create_null (), jerry_create_number (0.0)), + T (JERRY_BIN_OP_MUL, jerry_number (5.0), jerry_number (5.0), jerry_number (25.0)), + T (JERRY_BIN_OP_MUL, jerry_number (3.1), jerry_number (10), jerry_number (31)), + T (JERRY_BIN_OP_MUL, jerry_number (3.1), jerry_boolean (true), jerry_number (3.1)), + T (JERRY_BIN_OP_MUL, jerry_boolean (true), jerry_boolean (true), jerry_number (1.0)), + T (JERRY_BIN_OP_MUL, jerry_boolean (true), jerry_boolean (false), jerry_number (0.0)), + T (JERRY_BIN_OP_MUL, jerry_boolean (false), jerry_boolean (true), jerry_number (0.0)), + T (JERRY_BIN_OP_MUL, jerry_boolean (false), jerry_boolean (false), jerry_number (0.0)), + T (JERRY_BIN_OP_MUL, jerry_null (), jerry_null (), jerry_number (0.0)), /* Testing division (/) */ - T (JERRY_BIN_OP_DIV, jerry_create_number (5.0), jerry_create_number (5.0), jerry_create_number (1.0)), - T (JERRY_BIN_OP_DIV, jerry_create_number (3.1), jerry_create_number (10), jerry_create_number (0.31)), - T (JERRY_BIN_OP_DIV, jerry_create_number (3.1), jerry_create_boolean (true), jerry_create_number (3.1)), - T (JERRY_BIN_OP_DIV, jerry_create_boolean (true), jerry_create_boolean (true), jerry_create_number (1.0)), - T (JERRY_BIN_OP_DIV, - jerry_create_boolean (true), - jerry_create_boolean (false), - jerry_create_number_infinity (false)), - T (JERRY_BIN_OP_DIV, jerry_create_boolean (false), jerry_create_boolean (true), jerry_create_number (0.0)), + T (JERRY_BIN_OP_DIV, jerry_number (5.0), jerry_number (5.0), jerry_number (1.0)), + T (JERRY_BIN_OP_DIV, jerry_number (3.1), jerry_number (10), jerry_number (0.31)), + T (JERRY_BIN_OP_DIV, jerry_number (3.1), jerry_boolean (true), jerry_number (3.1)), + T (JERRY_BIN_OP_DIV, jerry_boolean (true), jerry_boolean (true), jerry_number (1.0)), + T (JERRY_BIN_OP_DIV, jerry_boolean (true), jerry_boolean (false), jerry_infinity (false)), + T (JERRY_BIN_OP_DIV, jerry_boolean (false), jerry_boolean (true), jerry_number (0.0)), /* Testing remainder (%) */ - T (JERRY_BIN_OP_REM, jerry_create_number (5.0), jerry_create_number (5.0), jerry_create_number (0.0)), - T (JERRY_BIN_OP_REM, jerry_create_number (5.0), jerry_create_number (2.0), jerry_create_number (1.0)), - T (JERRY_BIN_OP_REM, jerry_create_number (3.1), jerry_create_number (10), jerry_create_number (3.1)), - T (JERRY_BIN_OP_REM, - jerry_create_number (3.1), - jerry_create_boolean (true), - jerry_create_number (0.10000000000000009)), - T (JERRY_BIN_OP_REM, jerry_create_boolean (true), jerry_create_boolean (true), jerry_create_number (0.0)), - T (JERRY_BIN_OP_REM, jerry_create_boolean (false), jerry_create_boolean (true), jerry_create_number (0.0)), + T (JERRY_BIN_OP_REM, jerry_number (5.0), jerry_number (5.0), jerry_number (0.0)), + T (JERRY_BIN_OP_REM, jerry_number (5.0), jerry_number (2.0), jerry_number (1.0)), + T (JERRY_BIN_OP_REM, jerry_number (3.1), jerry_number (10), jerry_number (3.1)), + T (JERRY_BIN_OP_REM, jerry_number (3.1), jerry_boolean (true), jerry_number (0.10000000000000009)), + T (JERRY_BIN_OP_REM, jerry_boolean (true), jerry_boolean (true), jerry_number (0.0)), + T (JERRY_BIN_OP_REM, jerry_boolean (false), jerry_boolean (true), jerry_number (0.0)), }; for (uint32_t idx = 0; idx < sizeof (tests) / sizeof (test_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (tests[idx].op, tests[idx].lhs, tests[idx].rhs); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_t result = jerry_binary_op (tests[idx].op, tests[idx].lhs, tests[idx].rhs); + TEST_ASSERT (!jerry_value_is_exception (result)); - jerry_value_t equals = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, result, tests[idx].expected); + jerry_value_t equals = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, result, tests[idx].expected); TEST_ASSERT (jerry_value_is_boolean (equals) && jerry_value_is_true (equals)); - jerry_release_value (equals); + jerry_value_free (equals); - jerry_release_value (tests[idx].lhs); - jerry_release_value (tests[idx].rhs); - jerry_release_value (tests[idx].expected); - jerry_release_value (result); + jerry_value_free (tests[idx].lhs); + jerry_value_free (tests[idx].rhs); + jerry_value_free (tests[idx].expected); + jerry_value_free (result); } - jerry_value_t obj3 = jerry_eval ((const jerry_char_t *) "o={valueOf:function(){throw 5}};o", 33, JERRY_PARSE_NO_OPTS); + jerry_value_t obj3 = jerry_eval ((jerry_char_t *) "o={valueOf:function(){throw 5}};o", 33, JERRY_PARSE_NO_OPTS); test_error_entry_t error_tests[] = { /* Testing addition (+) */ - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (err1), jerry_acquire_value (err1)), - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (err1), jerry_create_undefined ()), - T_ERR (JERRY_BIN_OP_ADD, jerry_create_undefined (), jerry_acquire_value (err1)), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (err1), jerry_value_copy (err1)), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (err1), jerry_undefined ()), + T_ERR (JERRY_BIN_OP_ADD, jerry_undefined (), jerry_value_copy (err1)), /* Testing subtraction (-), multiplication (*), division (/), remainder (%) */ - T_ARI (jerry_acquire_value (err1), jerry_acquire_value (err1)), - T_ARI (jerry_acquire_value (err1), jerry_create_undefined ()), - T_ARI (jerry_create_undefined (), jerry_acquire_value (err1)), + T_ARI (jerry_value_copy (err1), jerry_value_copy (err1)), + T_ARI (jerry_value_copy (err1), jerry_undefined ()), + T_ARI (jerry_undefined (), jerry_value_copy (err1)), /* Testing addition (+) */ - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (obj3), jerry_create_undefined ()), - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (obj3), jerry_create_null ()), - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (obj3), jerry_create_boolean (true)), - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (obj3), jerry_create_boolean (false)), - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (obj3), jerry_acquire_value (obj2)), - T_ERR (JERRY_BIN_OP_ADD, jerry_acquire_value (obj3), jerry_create_string ((const jerry_char_t *) "foo")), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (obj3), jerry_undefined ()), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (obj3), jerry_null ()), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (obj3), jerry_boolean (true)), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (obj3), jerry_boolean (false)), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (obj3), jerry_value_copy (obj2)), + T_ERR (JERRY_BIN_OP_ADD, jerry_value_copy (obj3), jerry_string_sz ("foo")), /* Testing subtraction (-), multiplication (*), division (/), remainder (%) */ - T_ARI (jerry_acquire_value (obj3), jerry_create_undefined ()), - T_ARI (jerry_acquire_value (obj3), jerry_create_null ()), - T_ARI (jerry_acquire_value (obj3), jerry_create_boolean (true)), - T_ARI (jerry_acquire_value (obj3), jerry_create_boolean (false)), - T_ARI (jerry_acquire_value (obj3), jerry_acquire_value (obj2)), - T_ARI (jerry_acquire_value (obj3), jerry_create_string ((const jerry_char_t *) "foo")), + T_ARI (jerry_value_copy (obj3), jerry_undefined ()), + T_ARI (jerry_value_copy (obj3), jerry_null ()), + T_ARI (jerry_value_copy (obj3), jerry_boolean (true)), + T_ARI (jerry_value_copy (obj3), jerry_boolean (false)), + T_ARI (jerry_value_copy (obj3), jerry_value_copy (obj2)), + T_ARI (jerry_value_copy (obj3), jerry_string_sz ("foo")), }; for (uint32_t idx = 0; idx < sizeof (error_tests) / sizeof (test_error_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (tests[idx].op, error_tests[idx].lhs, error_tests[idx].rhs); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (error_tests[idx].lhs); - jerry_release_value (error_tests[idx].rhs); - jerry_release_value (result); + jerry_value_t result = jerry_binary_op (tests[idx].op, error_tests[idx].lhs, error_tests[idx].rhs); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (error_tests[idx].lhs); + jerry_value_free (error_tests[idx].rhs); + jerry_value_free (result); } - jerry_release_value (obj1); - jerry_release_value (obj2); - jerry_release_value (obj3); - jerry_release_value (err1); + jerry_value_free (obj1); + jerry_value_free (obj2); + jerry_value_free (obj3); + jerry_value_free (err1); jerry_cleanup (); diff --git a/tests/unit-core/test-api-binary-operations-comparisons.c b/tests/unit-core/test-api-binary-operations-comparisons.c index 0a2698c1e4..7feb322e1e 100644 --- a/tests/unit-core/test-api-binary-operations-comparisons.c +++ b/tests/unit-core/test-api-binary-operations-comparisons.c @@ -24,7 +24,7 @@ typedef struct { - jerry_binary_operation_t op; + jerry_binary_op_t op; jerry_value_t lhs; jerry_value_t rhs; bool expected; @@ -39,213 +39,165 @@ main (void) jerry_value_t obj1 = jerry_eval ((const jerry_char_t *) "o={x:1};o", 9, JERRY_PARSE_NO_OPTS); jerry_value_t obj2 = jerry_eval ((const jerry_char_t *) "o={x:1};o", 9, JERRY_PARSE_NO_OPTS); - jerry_value_t err1 = jerry_create_error (JERRY_ERROR_SYNTAX, (const jerry_char_t *) "error"); + jerry_value_t err1 = jerry_throw_sz (JERRY_ERROR_SYNTAX, "error"); test_entry_t tests[] = { /* Testing strict equal comparison */ - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_number (5.0), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_number (3.1), jerry_create_number (10), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_number (3.1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_number (3.1), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_STRICT_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_string ((const jerry_char_t *) "example string"), - true), - T (JERRY_BIN_OP_STRICT_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_undefined (), - false), - T (JERRY_BIN_OP_STRICT_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_null (), - false), - T (JERRY_BIN_OP_STRICT_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_number (5.0), - false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_undefined (), jerry_create_undefined (), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_undefined (), jerry_create_null (), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_null (), jerry_create_null (), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_boolean (true), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_boolean (true), jerry_create_boolean (false), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_boolean (false), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_boolean (false), jerry_create_boolean (false), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_acquire_value (obj1), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_acquire_value (obj2), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj2), jerry_acquire_value (obj1), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_create_null (), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_create_boolean (false), false), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (obj1), jerry_create_number (5.0), false), - T (JERRY_BIN_OP_STRICT_EQUAL, - jerry_acquire_value (obj1), - jerry_create_string ((const jerry_char_t *) "example string"), - false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_number (5.0), jerry_number (5.0), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_number (3.1), jerry_number (10), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_number (3.1), jerry_undefined (), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_number (3.1), jerry_boolean (true), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_string_sz ("example string"), jerry_string_sz ("example string"), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_string_sz ("example string"), jerry_undefined (), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_string_sz ("example string"), jerry_null (), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_string_sz ("example string"), jerry_number (5.0), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_undefined (), jerry_undefined (), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_undefined (), jerry_null (), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_null (), jerry_null (), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_boolean (true), jerry_boolean (true), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_boolean (true), jerry_boolean (false), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_boolean (false), jerry_boolean (true), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_boolean (false), jerry_boolean (false), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_value_copy (obj1), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_value_copy (obj2), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj2), jerry_value_copy (obj1), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_null (), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_undefined (), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_boolean (true), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_boolean (false), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_number (5.0), false), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (obj1), jerry_string_sz ("example string"), false), /* Testing equal comparison */ - T (JERRY_BIN_OP_EQUAL, jerry_create_number (5.0), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_EQUAL, jerry_create_number (3.1), jerry_create_number (10), false), - T (JERRY_BIN_OP_EQUAL, jerry_create_number (3.1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_EQUAL, jerry_create_number (3.1), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_string ((const jerry_char_t *) "example string"), - true), - T (JERRY_BIN_OP_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_undefined (), - false), - T (JERRY_BIN_OP_EQUAL, jerry_create_string ((const jerry_char_t *) "example string"), jerry_create_null (), false), - T (JERRY_BIN_OP_EQUAL, - jerry_create_string ((const jerry_char_t *) "example string"), - jerry_create_number (5.0), - false), - T (JERRY_BIN_OP_EQUAL, jerry_create_undefined (), jerry_create_undefined (), true), - T (JERRY_BIN_OP_EQUAL, jerry_create_undefined (), jerry_create_null (), true), - T (JERRY_BIN_OP_EQUAL, jerry_create_null (), jerry_create_null (), true), - T (JERRY_BIN_OP_EQUAL, jerry_create_boolean (true), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_EQUAL, jerry_create_boolean (true), jerry_create_boolean (false), false), - T (JERRY_BIN_OP_EQUAL, jerry_create_boolean (false), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_EQUAL, jerry_create_boolean (false), jerry_create_boolean (false), true), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_acquire_value (obj1), true), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_acquire_value (obj2), false), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj2), jerry_acquire_value (obj1), false), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_create_null (), false), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_create_boolean (false), false), - T (JERRY_BIN_OP_EQUAL, jerry_acquire_value (obj1), jerry_create_number (5.0), false), - T (JERRY_BIN_OP_EQUAL, - jerry_acquire_value (obj1), - jerry_create_string ((const jerry_char_t *) "example string"), - false), + T (JERRY_BIN_OP_EQUAL, jerry_number (5.0), jerry_number (5.0), true), + T (JERRY_BIN_OP_EQUAL, jerry_number (3.1), jerry_number (10), false), + T (JERRY_BIN_OP_EQUAL, jerry_number (3.1), jerry_undefined (), false), + T (JERRY_BIN_OP_EQUAL, jerry_number (3.1), jerry_boolean (true), false), + T (JERRY_BIN_OP_EQUAL, jerry_string_sz ("example string"), jerry_string_sz ("example string"), true), + T (JERRY_BIN_OP_EQUAL, jerry_string_sz ("example string"), jerry_undefined (), false), + T (JERRY_BIN_OP_EQUAL, jerry_string_sz ("example string"), jerry_null (), false), + T (JERRY_BIN_OP_EQUAL, jerry_string_sz ("example string"), jerry_number (5.0), false), + T (JERRY_BIN_OP_EQUAL, jerry_undefined (), jerry_undefined (), true), + T (JERRY_BIN_OP_EQUAL, jerry_undefined (), jerry_null (), true), + T (JERRY_BIN_OP_EQUAL, jerry_null (), jerry_null (), true), + T (JERRY_BIN_OP_EQUAL, jerry_boolean (true), jerry_boolean (true), true), + T (JERRY_BIN_OP_EQUAL, jerry_boolean (true), jerry_boolean (false), false), + T (JERRY_BIN_OP_EQUAL, jerry_boolean (false), jerry_boolean (true), false), + T (JERRY_BIN_OP_EQUAL, jerry_boolean (false), jerry_boolean (false), true), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_value_copy (obj1), true), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_value_copy (obj2), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj2), jerry_value_copy (obj1), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_null (), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_undefined (), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_boolean (true), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_boolean (false), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_number (5.0), false), + T (JERRY_BIN_OP_EQUAL, jerry_value_copy (obj1), jerry_string_sz ("example string"), false), /* Testing less comparison */ - T (JERRY_BIN_OP_LESS, jerry_create_number (5.0), jerry_create_number (5.0), false), - T (JERRY_BIN_OP_LESS, jerry_create_number (3.1), jerry_create_number (10), true), - T (JERRY_BIN_OP_LESS, jerry_create_number (3.1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_LESS, jerry_create_number (3.1), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_LESS, - jerry_create_string ((const jerry_char_t *) "1"), - jerry_create_string ((const jerry_char_t *) "2"), - true), - T (JERRY_BIN_OP_LESS, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_undefined (), false), - T (JERRY_BIN_OP_LESS, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_null (), false), - T (JERRY_BIN_OP_LESS, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_LESS, jerry_create_undefined (), jerry_create_undefined (), false), - T (JERRY_BIN_OP_LESS, jerry_create_undefined (), jerry_create_null (), false), - T (JERRY_BIN_OP_LESS, jerry_create_null (), jerry_create_null (), false), - T (JERRY_BIN_OP_LESS, jerry_create_boolean (true), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_LESS, jerry_create_boolean (true), jerry_create_boolean (false), false), - T (JERRY_BIN_OP_LESS, jerry_create_boolean (false), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_LESS, jerry_create_boolean (false), jerry_create_boolean (false), false), + T (JERRY_BIN_OP_LESS, jerry_number (5.0), jerry_number (5.0), false), + T (JERRY_BIN_OP_LESS, jerry_number (3.1), jerry_number (10), true), + T (JERRY_BIN_OP_LESS, jerry_number (3.1), jerry_undefined (), false), + T (JERRY_BIN_OP_LESS, jerry_number (3.1), jerry_boolean (true), false), + T (JERRY_BIN_OP_LESS, jerry_string_sz ("1"), jerry_string_sz ("2"), true), + T (JERRY_BIN_OP_LESS, jerry_string_sz ("1"), jerry_undefined (), false), + T (JERRY_BIN_OP_LESS, jerry_string_sz ("1"), jerry_null (), false), + T (JERRY_BIN_OP_LESS, jerry_string_sz ("1"), jerry_number (5.0), true), + T (JERRY_BIN_OP_LESS, jerry_undefined (), jerry_undefined (), false), + T (JERRY_BIN_OP_LESS, jerry_undefined (), jerry_null (), false), + T (JERRY_BIN_OP_LESS, jerry_null (), jerry_null (), false), + T (JERRY_BIN_OP_LESS, jerry_boolean (true), jerry_boolean (true), false), + T (JERRY_BIN_OP_LESS, jerry_boolean (true), jerry_boolean (false), false), + T (JERRY_BIN_OP_LESS, jerry_boolean (false), jerry_boolean (true), true), + T (JERRY_BIN_OP_LESS, jerry_boolean (false), jerry_boolean (false), false), /* Testing less or equal comparison */ - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_number (5.0), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_number (5.1), jerry_create_number (5.0), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_number (3.1), jerry_create_number (10), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_number (3.1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_number (3.1), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_LESS_EQUAL, - jerry_create_string ((const jerry_char_t *) "1"), - jerry_create_string ((const jerry_char_t *) "2"), - true), - T (JERRY_BIN_OP_LESS_EQUAL, - jerry_create_string ((const jerry_char_t *) "1"), - jerry_create_string ((const jerry_char_t *) "1"), - true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_undefined (), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_null (), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_string ((const jerry_char_t *) "5.0"), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_undefined (), jerry_create_undefined (), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_undefined (), jerry_create_null (), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_null (), jerry_create_null (), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_boolean (true), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_boolean (true), jerry_create_boolean (false), false), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_boolean (false), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_LESS_EQUAL, jerry_create_boolean (false), jerry_create_boolean (false), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_number (5.0), jerry_number (5.0), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_number (5.1), jerry_number (5.0), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_number (3.1), jerry_number (10), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_number (3.1), jerry_undefined (), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_number (3.1), jerry_boolean (true), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_string_sz ("1"), jerry_string_sz ("2"), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_string_sz ("1"), jerry_string_sz ("1"), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_string_sz ("1"), jerry_undefined (), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_string_sz ("1"), jerry_null (), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_string_sz ("1"), jerry_number (5.0), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_string_sz ("5.0"), jerry_number (5.0), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_undefined (), jerry_undefined (), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_undefined (), jerry_null (), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_null (), jerry_null (), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_boolean (true), jerry_boolean (true), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_boolean (true), jerry_boolean (false), false), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_boolean (false), jerry_boolean (true), true), + T (JERRY_BIN_OP_LESS_EQUAL, jerry_boolean (false), jerry_boolean (false), true), /* Testing greater comparison */ - T (JERRY_BIN_OP_GREATER, jerry_create_number (5.0), jerry_create_number (5.0), false), - T (JERRY_BIN_OP_GREATER, jerry_create_number (10), jerry_create_number (3.1), true), - T (JERRY_BIN_OP_GREATER, jerry_create_number (3.1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_GREATER, jerry_create_number (3.1), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_GREATER, - jerry_create_string ((const jerry_char_t *) "2"), - jerry_create_string ((const jerry_char_t *) "1"), - true), - T (JERRY_BIN_OP_GREATER, - jerry_create_string ((const jerry_char_t *) "1"), - jerry_create_string ((const jerry_char_t *) "2"), - false), - T (JERRY_BIN_OP_GREATER, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_undefined (), false), - T (JERRY_BIN_OP_GREATER, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_null (), true), - T (JERRY_BIN_OP_GREATER, jerry_create_number (5.0), jerry_create_string ((const jerry_char_t *) "1"), true), - T (JERRY_BIN_OP_GREATER, jerry_create_undefined (), jerry_create_undefined (), false), - T (JERRY_BIN_OP_GREATER, jerry_create_undefined (), jerry_create_null (), false), - T (JERRY_BIN_OP_GREATER, jerry_create_null (), jerry_create_null (), false), - T (JERRY_BIN_OP_GREATER, jerry_create_boolean (true), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_GREATER, jerry_create_boolean (true), jerry_create_boolean (false), true), - T (JERRY_BIN_OP_GREATER, jerry_create_boolean (false), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_GREATER, jerry_create_boolean (false), jerry_create_boolean (false), false), + T (JERRY_BIN_OP_GREATER, jerry_number (5.0), jerry_number (5.0), false), + T (JERRY_BIN_OP_GREATER, jerry_number (10), jerry_number (3.1), true), + T (JERRY_BIN_OP_GREATER, jerry_number (3.1), jerry_undefined (), false), + T (JERRY_BIN_OP_GREATER, jerry_number (3.1), jerry_boolean (true), true), + T (JERRY_BIN_OP_GREATER, jerry_string_sz ("2"), jerry_string_sz ("1"), true), + T (JERRY_BIN_OP_GREATER, jerry_string_sz ("1"), jerry_string_sz ("2"), false), + T (JERRY_BIN_OP_GREATER, jerry_string_sz ("1"), jerry_undefined (), false), + T (JERRY_BIN_OP_GREATER, jerry_string_sz ("1"), jerry_null (), true), + T (JERRY_BIN_OP_GREATER, jerry_number (5.0), jerry_string_sz ("1"), true), + T (JERRY_BIN_OP_GREATER, jerry_undefined (), jerry_undefined (), false), + T (JERRY_BIN_OP_GREATER, jerry_undefined (), jerry_null (), false), + T (JERRY_BIN_OP_GREATER, jerry_null (), jerry_null (), false), + T (JERRY_BIN_OP_GREATER, jerry_boolean (true), jerry_boolean (true), false), + T (JERRY_BIN_OP_GREATER, jerry_boolean (true), jerry_boolean (false), true), + T (JERRY_BIN_OP_GREATER, jerry_boolean (false), jerry_boolean (true), false), + T (JERRY_BIN_OP_GREATER, jerry_boolean (false), jerry_boolean (false), false), /* Testing greater or equal comparison */ - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_number (5.0), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_number (5.0), jerry_create_number (5.1), false), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_number (10), jerry_create_number (3.1), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_number (3.1), jerry_create_undefined (), false), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_number (3.1), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_GREATER_EQUAL, - jerry_create_string ((const jerry_char_t *) "2"), - jerry_create_string ((const jerry_char_t *) "1"), - true), - T (JERRY_BIN_OP_GREATER_EQUAL, - jerry_create_string ((const jerry_char_t *) "1"), - jerry_create_string ((const jerry_char_t *) "1"), - true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_undefined (), false), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_string ((const jerry_char_t *) "1"), jerry_create_null (), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_number (5.0), jerry_create_string ((const jerry_char_t *) "1"), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_string ((const jerry_char_t *) "5.0"), jerry_create_number (5.0), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_undefined (), jerry_create_undefined (), false), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_undefined (), jerry_create_null (), false), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_null (), jerry_create_null (), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_boolean (true), jerry_create_boolean (true), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_boolean (true), jerry_create_boolean (false), true), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_boolean (false), jerry_create_boolean (true), false), - T (JERRY_BIN_OP_GREATER_EQUAL, jerry_create_boolean (false), jerry_create_boolean (false), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_number (5.0), jerry_number (5.0), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_number (5.0), jerry_number (5.1), false), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_number (10), jerry_number (3.1), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_number (3.1), jerry_undefined (), false), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_number (3.1), jerry_boolean (true), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_string_sz ("2"), jerry_string_sz ("1"), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_string_sz ("1"), jerry_string_sz ("1"), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_string_sz ("1"), jerry_undefined (), false), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_string_sz ("1"), jerry_null (), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_number (5.0), jerry_string_sz ("1"), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_string_sz ("5.0"), jerry_number (5.0), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_undefined (), jerry_undefined (), false), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_undefined (), jerry_null (), false), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_null (), jerry_null (), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_boolean (true), jerry_boolean (true), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_boolean (true), jerry_boolean (false), true), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_boolean (false), jerry_boolean (true), false), + T (JERRY_BIN_OP_GREATER_EQUAL, jerry_boolean (false), jerry_boolean (false), true), }; for (uint32_t idx = 0; idx < sizeof (tests) / sizeof (test_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (tests[idx].op, tests[idx].lhs, tests[idx].rhs); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_t result = jerry_binary_op (tests[idx].op, tests[idx].lhs, tests[idx].rhs); + TEST_ASSERT (!jerry_value_is_exception (result)); TEST_ASSERT (jerry_value_is_true (result) == tests[idx].expected); - jerry_release_value (tests[idx].lhs); - jerry_release_value (tests[idx].rhs); - jerry_release_value (result); + jerry_value_free (tests[idx].lhs); + jerry_value_free (tests[idx].rhs); + jerry_value_free (result); } test_entry_t error_tests[] = { - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (err1), jerry_acquire_value (err1), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_acquire_value (err1), jerry_create_undefined (), true), - T (JERRY_BIN_OP_STRICT_EQUAL, jerry_create_undefined (), jerry_acquire_value (err1), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (err1), jerry_value_copy (err1), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_value_copy (err1), jerry_undefined (), true), + T (JERRY_BIN_OP_STRICT_EQUAL, jerry_undefined (), jerry_value_copy (err1), true), }; for (uint32_t idx = 0; idx < sizeof (error_tests) / sizeof (test_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (tests[idx].op, error_tests[idx].lhs, error_tests[idx].rhs); - TEST_ASSERT (jerry_value_is_error (result) == error_tests[idx].expected); - jerry_release_value (error_tests[idx].lhs); - jerry_release_value (error_tests[idx].rhs); - jerry_release_value (result); + jerry_value_t result = jerry_binary_op (tests[idx].op, error_tests[idx].lhs, error_tests[idx].rhs); + TEST_ASSERT (jerry_value_is_exception (result) == error_tests[idx].expected); + jerry_value_free (error_tests[idx].lhs); + jerry_value_free (error_tests[idx].rhs); + jerry_value_free (result); } - jerry_release_value (obj1); - jerry_release_value (obj2); - jerry_release_value (err1); + jerry_value_free (obj1); + jerry_value_free (obj2); + jerry_value_free (err1); jerry_cleanup (); diff --git a/tests/unit-core/test-api-binary-operations-instanceof.c b/tests/unit-core/test-api-binary-operations-instanceof.c index 5c268cfaa1..2a2043961d 100644 --- a/tests/unit-core/test-api-binary-operations-instanceof.c +++ b/tests/unit-core/test-api-binary-operations-instanceof.c @@ -37,7 +37,7 @@ my_constructor (const jerry_call_info_t *call_info_p, /**< call information */ (void) call_info_p; (void) argv; (void) argc; - return jerry_create_undefined (); + return jerry_undefined (); } /* my_constructor */ int @@ -47,68 +47,64 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t base_obj = jerry_create_object (); - jerry_value_t constructor = jerry_create_external_function (my_constructor); + jerry_value_t base_obj = jerry_object (); + jerry_value_t constructor = jerry_function_external (my_constructor); - jerry_value_t no_proto_instance_val = jerry_construct_object (constructor, NULL, 0); + jerry_value_t no_proto_instance_val = jerry_construct (constructor, NULL, 0); - jerry_value_t prototype_str = jerry_create_string ((const jerry_char_t *) "prototype"); - jerry_value_t res = jerry_set_property (constructor, prototype_str, base_obj); - jerry_release_value (prototype_str); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (res); + jerry_value_t prototype_str = jerry_string_sz ("prototype"); + jerry_value_t res = jerry_object_set (constructor, prototype_str, base_obj); + jerry_value_free (prototype_str); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (res); - jerry_value_t instance_val = jerry_construct_object (constructor, NULL, 0); + jerry_value_t instance_val = jerry_construct (constructor, NULL, 0); - jerry_value_t error = jerry_create_error_from_value (base_obj, false); + jerry_value_t error = jerry_throw_value (base_obj, false); - test_entry_t bool_tests[] = { - T (jerry_acquire_value (instance_val), jerry_acquire_value (constructor), true), - T (jerry_acquire_value (no_proto_instance_val), jerry_acquire_value (constructor), false), - T (jerry_acquire_value (base_obj), jerry_acquire_value (constructor), false) - }; + test_entry_t bool_tests[] = { T (jerry_value_copy (instance_val), jerry_value_copy (constructor), true), + T (jerry_value_copy (no_proto_instance_val), jerry_value_copy (constructor), false), + T (jerry_value_copy (base_obj), jerry_value_copy (constructor), false) }; for (uint32_t idx = 0; idx < sizeof (bool_tests) / sizeof (test_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, bool_tests[idx].lhs, bool_tests[idx].rhs); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_t result = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, bool_tests[idx].lhs, bool_tests[idx].rhs); + TEST_ASSERT (!jerry_value_is_exception (result)); TEST_ASSERT (jerry_value_is_true (result) == bool_tests[idx].expected); - jerry_release_value (bool_tests[idx].lhs); - jerry_release_value (bool_tests[idx].rhs); - jerry_release_value (result); + jerry_value_free (bool_tests[idx].lhs); + jerry_value_free (bool_tests[idx].rhs); + jerry_value_free (result); } - test_entry_t error_tests[] = { - T (jerry_acquire_value (constructor), jerry_acquire_value (instance_val), true), - T (jerry_create_undefined (), jerry_acquire_value (constructor), true), - T (jerry_acquire_value (instance_val), jerry_create_undefined (), true), - T (jerry_acquire_value (instance_val), jerry_acquire_value (base_obj), true), - T (jerry_acquire_value (error), jerry_acquire_value (constructor), true), - T (jerry_acquire_value (instance_val), jerry_acquire_value (error), true), - T (jerry_create_string ((const jerry_char_t *) ""), jerry_create_string ((const jerry_char_t *) ""), true), - T (jerry_create_string ((const jerry_char_t *) ""), jerry_create_number (5.0), true), - T (jerry_create_number (5.0), jerry_create_string ((const jerry_char_t *) ""), true), - T (jerry_create_array (1), jerry_create_array (1), true), - T (jerry_create_array (1), jerry_create_object (), true), - T (jerry_create_object (), jerry_create_array (1), true), - T (jerry_create_null (), jerry_create_object (), true), - T (jerry_create_object (), jerry_create_string ((const jerry_char_t *) ""), true) - }; + test_entry_t error_tests[] = { T (jerry_value_copy (constructor), jerry_value_copy (instance_val), true), + T (jerry_undefined (), jerry_value_copy (constructor), true), + T (jerry_value_copy (instance_val), jerry_undefined (), true), + T (jerry_value_copy (instance_val), jerry_value_copy (base_obj), true), + T (jerry_value_copy (error), jerry_value_copy (constructor), true), + T (jerry_value_copy (instance_val), jerry_value_copy (error), true), + T (jerry_string_sz (""), jerry_string_sz (""), true), + T (jerry_string_sz (""), jerry_number (5.0), true), + T (jerry_number (5.0), jerry_string_sz (""), true), + T (jerry_array (1), jerry_array (1), true), + T (jerry_array (1), jerry_object (), true), + T (jerry_object (), jerry_array (1), true), + T (jerry_null (), jerry_object (), true), + T (jerry_object (), jerry_string_sz (""), true) }; for (uint32_t idx = 0; idx < sizeof (error_tests) / sizeof (test_entry_t); idx++) { - jerry_value_t result = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, error_tests[idx].lhs, error_tests[idx].rhs); - TEST_ASSERT (jerry_value_is_error (result) == error_tests[idx].expected); - jerry_release_value (error_tests[idx].lhs); - jerry_release_value (error_tests[idx].rhs); - jerry_release_value (result); + jerry_value_t result = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, error_tests[idx].lhs, error_tests[idx].rhs); + TEST_ASSERT (jerry_value_is_exception (result) == error_tests[idx].expected); + jerry_value_free (error_tests[idx].lhs); + jerry_value_free (error_tests[idx].rhs); + jerry_value_free (result); } - jerry_release_value (base_obj); - jerry_release_value (constructor); - jerry_release_value (error); - jerry_release_value (instance_val); - jerry_release_value (no_proto_instance_val); + jerry_value_free (base_obj); + jerry_value_free (constructor); + jerry_value_free (error); + jerry_value_free (instance_val); + jerry_value_free (no_proto_instance_val); jerry_cleanup (); diff --git a/tests/unit-core/test-api-errortype.c b/tests/unit-core/test-api-errortype.c index 645f1806eb..43327e8f2b 100644 --- a/tests/unit-core/test-api-errortype.c +++ b/tests/unit-core/test-api-errortype.c @@ -29,45 +29,45 @@ main (void) for (size_t idx = 0; idx < sizeof (errors) / sizeof (errors[0]); idx++) { - jerry_value_t error_obj = jerry_create_error (errors[idx], (const jerry_char_t *) "test"); - TEST_ASSERT (jerry_value_is_error (error_obj)); - TEST_ASSERT (jerry_get_error_type (error_obj) == errors[idx]); + jerry_value_t error_obj = jerry_throw_sz (errors[idx], "test"); + TEST_ASSERT (jerry_value_is_exception (error_obj)); + TEST_ASSERT (jerry_error_type (error_obj) == errors[idx]); - error_obj = jerry_get_value_from_error (error_obj, true); + error_obj = jerry_exception_value (error_obj, true); - TEST_ASSERT (jerry_get_error_type (error_obj) == errors[idx]); + TEST_ASSERT (jerry_error_type (error_obj) == errors[idx]); - jerry_release_value (error_obj); + jerry_value_free (error_obj); } jerry_value_t test_values[] = { - jerry_create_number (11), - jerry_create_string ((const jerry_char_t *) "message"), - jerry_create_boolean (true), - jerry_create_object (), + jerry_number (11), + jerry_string_sz ("message"), + jerry_boolean (true), + jerry_object (), }; for (size_t idx = 0; idx < sizeof (test_values) / sizeof (test_values[0]); idx++) { - jerry_error_t error_type = jerry_get_error_type (test_values[idx]); + jerry_error_t error_type = jerry_error_type (test_values[idx]); TEST_ASSERT (error_type == JERRY_ERROR_NONE); - jerry_release_value (test_values[idx]); + jerry_value_free (test_values[idx]); } char test_source[] = "\xF0\x9D\x84\x9E"; jerry_value_t result = jerry_parse ((const jerry_char_t *) test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (jerry_value_is_error (result)); - TEST_ASSERT (jerry_get_error_type (result) == JERRY_ERROR_SYNTAX); + TEST_ASSERT (jerry_value_is_exception (result)); + TEST_ASSERT (jerry_error_type (result) == JERRY_ERROR_SYNTAX); - jerry_release_value (result); + jerry_value_free (result); char test_invalid_error[] = "Object.create(Error.prototype)"; result = jerry_eval ((const jerry_char_t *) test_invalid_error, sizeof (test_invalid_error) - 1, JERRY_PARSE_NO_OPTS); - TEST_ASSERT (!jerry_value_is_error (result) && jerry_value_is_object (result)); - TEST_ASSERT (jerry_get_error_type (result) == JERRY_ERROR_NONE); + TEST_ASSERT (!jerry_value_is_exception (result) && jerry_value_is_object (result)); + TEST_ASSERT (jerry_error_type (result) == JERRY_ERROR_NONE); - jerry_release_value (result); + jerry_value_free (result); jerry_cleanup (); } /* main */ diff --git a/tests/unit-core/test-api-functiontype.c b/tests/unit-core/test-api-functiontype.c index 0437a5662f..2c22b79bc0 100644 --- a/tests/unit-core/test-api-functiontype.c +++ b/tests/unit-core/test-api-functiontype.c @@ -31,9 +31,9 @@ typedef struct { \ TYPE, VALUE, true, false \ } -#define ENTRY_IF(TYPE, VALUE, FEATURE, ASYNC) \ - { \ - TYPE, VALUE, jerry_is_feature_enabled (FEATURE), ASYNC \ +#define ENTRY_IF(TYPE, VALUE, FEATURE, ASYNC) \ + { \ + TYPE, VALUE, jerry_feature_enabled (FEATURE), ASYNC \ } #define EVALUATE(BUFF) (jerry_eval ((BUFF), sizeof ((BUFF)) - 1, JERRY_PARSE_NO_OPTS)) static jerry_value_t @@ -44,7 +44,7 @@ test_ext_function (const jerry_call_info_t *call_info_p, /**< call information * (void) call_info_p; (void) args_p; (void) args_cnt; - return jerry_create_boolean (true); + return jerry_boolean (true); } /* test_ext_function */ int @@ -67,15 +67,15 @@ main (void) const jerry_char_t bound_function[] = "function f() {}; f.bind(1,2)"; test_entry_t entries[] = { - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_number (-33.0)), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_boolean (true)), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_undefined ()), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_null ()), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_string ((const jerry_char_t *) "foo")), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_number (-33.0)), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_boolean (true)), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_undefined ()), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_null ()), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_string_sz ("foo")), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_throw_sz (JERRY_ERROR_TYPE, "error")), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_object ()), - ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_create_array (10)), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_object ()), + ENTRY (JERRY_FUNCTION_TYPE_NONE, jerry_array (10)), ENTRY_IF (JERRY_FUNCTION_TYPE_ARROW, EVALUATE (arrow_function), JERRY_FEATURE_SYMBOL, false), ENTRY_IF (JERRY_FUNCTION_TYPE_ARROW, EVALUATE (async_arrow_function), JERRY_FEATURE_SYMBOL, true), @@ -85,18 +85,18 @@ main (void) ENTRY (JERRY_FUNCTION_TYPE_GENERIC, EVALUATE (builtin_function)), ENTRY (JERRY_FUNCTION_TYPE_GENERIC, EVALUATE (simple_function)), ENTRY (JERRY_FUNCTION_TYPE_BOUND, EVALUATE (bound_function)), - ENTRY (JERRY_FUNCTION_TYPE_GENERIC, jerry_create_external_function (test_ext_function)), + ENTRY (JERRY_FUNCTION_TYPE_GENERIC, jerry_function_external (test_ext_function)), ENTRY (JERRY_FUNCTION_TYPE_ACCESSOR, EVALUATE (getter_function)), ENTRY (JERRY_FUNCTION_TYPE_ACCESSOR, EVALUATE (setter_function)), }; for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++) { - jerry_function_type_t type_info = jerry_function_get_type (entries[idx].value); + jerry_function_type_t type_info = jerry_function_type (entries[idx].value); TEST_ASSERT (!entries[idx].active || (type_info == entries[idx].type_info && jerry_value_is_async_function (entries[idx].value) == entries[idx].is_async)); - jerry_release_value (entries[idx].value); + jerry_value_free (entries[idx].value); } jerry_cleanup (); diff --git a/tests/unit-core/test-api-iteratortype.c b/tests/unit-core/test-api-iteratortype.c index 7f0d9a4007..5d0bdfc962 100644 --- a/tests/unit-core/test-api-iteratortype.c +++ b/tests/unit-core/test-api-iteratortype.c @@ -30,9 +30,9 @@ typedef struct { \ TYPE, VALUE, true \ } -#define ENTRY_IF(TYPE, VALUE, FEATURE) \ - { \ - TYPE, VALUE, jerry_is_feature_enabled (FEATURE) \ +#define ENTRY_IF(TYPE, VALUE, FEATURE) \ + { \ + TYPE, VALUE, jerry_feature_enabled (FEATURE) \ } #define EVALUATE(BUFF) (jerry_eval ((BUFF), sizeof ((BUFF)) - 1, JERRY_PARSE_NO_OPTS)) @@ -66,15 +66,15 @@ main (void) const jerry_char_t set_iterator_symbol_iterator[] = "new Set([1, 2, 3])[Symbol.iterator]()"; test_entry_t entries[] = { - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_number (-33.0)), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_boolean (true)), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_undefined ()), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_null ()), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_string ((const jerry_char_t *) "foo")), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_number (-33.0)), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_boolean (true)), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_undefined ()), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_null ()), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_string_sz ("foo")), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_throw_sz (JERRY_ERROR_TYPE, "error")), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_object ()), - ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_create_array (10)), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_object ()), + ENTRY (JERRY_ITERATOR_TYPE_NONE, jerry_array (10)), ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (array_iterator_keys), JERRY_FEATURE_SYMBOL), ENTRY_IF (JERRY_ITERATOR_TYPE_ARRAY, EVALUATE (array_iterator_values), JERRY_FEATURE_SYMBOL), @@ -101,9 +101,9 @@ main (void) for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++) { - jerry_iterator_type_t type_info = jerry_iterator_get_type (entries[idx].value); + jerry_iterator_type_t type_info = jerry_iterator_type (entries[idx].value); TEST_ASSERT (!entries[idx].active || type_info == entries[idx].type_info); - jerry_release_value (entries[idx].value); + jerry_value_free (entries[idx].value); } jerry_cleanup (); diff --git a/tests/unit-core/test-api-object-property-names.c b/tests/unit-core/test-api-object-property-names.c index 9934801f7f..f51056b95f 100644 --- a/tests/unit-core/test-api-object-property-names.c +++ b/tests/unit-core/test-api-object-property-names.c @@ -26,33 +26,33 @@ static jerry_char_t buffer[256] = { 0 }; static void create_and_set_property (const jerry_value_t object, const char *prop_name) { - jerry_value_t jprop_name = jerry_create_string ((const jerry_char_t *) prop_name); - jerry_value_t ret_val = jerry_set_property (object, jprop_name, jerry_create_undefined ()); + jerry_value_t jprop_name = jerry_string_sz (prop_name); + jerry_value_t ret_val = jerry_object_set (object, jprop_name, jerry_undefined ()); - jerry_release_value (jprop_name); - jerry_release_value (ret_val); + jerry_value_free (jprop_name); + jerry_value_free (ret_val); } /* create_and_set_property */ static void compare_prop_name (const jerry_value_t object, const char *prop_name, uint32_t idx) { - jerry_value_t name = jerry_get_property_by_index (object, idx); + jerry_value_t name = jerry_object_get_index (object, idx); TEST_ASSERT (jerry_value_is_string (name) || jerry_value_is_number (name)); if (jerry_value_is_string (name)) { - jerry_size_t name_size = jerry_get_string_size (name); + jerry_size_t name_size = jerry_string_size (name, JERRY_ENCODING_CESU8); TEST_ASSERT (name_size < sizeof (buffer)); - jerry_size_t ret_size = jerry_string_to_char_buffer (name, buffer, sizeof (buffer)); + jerry_size_t ret_size = jerry_string_to_buffer (name, buffer, sizeof (buffer), JERRY_ENCODING_CESU8); TEST_ASSERT (name_size == ret_size); buffer[name_size] = '\0'; TEST_ASSERT (strcmp ((const char *) buffer, prop_name) == 0); } else { - TEST_ASSERT ((int) jerry_get_number_value (name) == atoi (prop_name)); + TEST_ASSERT ((int) jerry_value_as_number (name) == atoi (prop_name)); } - jerry_release_value (name); + jerry_value_free (name); } /* compare_prop_name */ static void @@ -61,27 +61,27 @@ define_property (const jerry_value_t object, jerry_property_descriptor_t *prop_desc_p, bool is_symbol) { - jerry_value_t jname = jerry_create_string ((const jerry_char_t *) prop_name); + jerry_value_t jname = jerry_string_sz (prop_name); jerry_value_t ret_val; if (is_symbol) { - jerry_value_t symbol = jerry_create_symbol (jname); - ret_val = jerry_define_own_property (object, symbol, prop_desc_p); - jerry_release_value (symbol); + jerry_value_t symbol = jerry_symbol_with_description (jname); + ret_val = jerry_object_define_own_prop (object, symbol, prop_desc_p); + jerry_value_free (symbol); } else { - ret_val = jerry_define_own_property (object, jname, prop_desc_p); + ret_val = jerry_object_define_own_prop (object, jname, prop_desc_p); } - jerry_release_value (jname); - jerry_release_value (ret_val); + jerry_value_free (jname); + jerry_value_free (ret_val); } /* define_property */ int main (void) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (!jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { return 0; } @@ -89,61 +89,61 @@ main (void) TEST_INIT (); jerry_init (JERRY_INIT_EMPTY); - jerry_value_t error_value = jerry_object_get_property_names (jerry_create_undefined (), JERRY_PROPERTY_FILTER_ALL); - TEST_ASSERT (jerry_value_is_error (error_value) && jerry_get_error_type (error_value) == JERRY_ERROR_TYPE); - jerry_release_value (error_value); + jerry_value_t error_value = jerry_object_property_names (jerry_undefined (), JERRY_PROPERTY_FILTER_ALL); + TEST_ASSERT (jerry_value_is_exception (error_value) && jerry_error_type (error_value) == JERRY_ERROR_TYPE); + jerry_value_free (error_value); - jerry_value_t test_object = jerry_create_object (); + jerry_value_t test_object = jerry_object (); create_and_set_property (test_object, prop_names[0]); create_and_set_property (test_object, prop_names[1]); jerry_value_t names; - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); prop_desc.flags |= (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_WRITABLE | JERRY_PROP_IS_ENUMERABLE_DEFINED); // Test enumerable - non-enumerable filter define_property (test_object, prop_names[2], &prop_desc, false); - names = jerry_object_get_property_names (test_object, - JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_NON_ENUMERABLE); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 2); - jerry_release_value (names); - names = jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 3); + names = + jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_NON_ENUMERABLE); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 2); + jerry_value_free (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 3); compare_prop_name (names, prop_names[2], 2); - jerry_release_value (names); + jerry_value_free (names); prop_desc.flags |= JERRY_PROP_IS_ENUMERABLE; // Test configurable - non-configurable filter prop_desc.flags &= (uint16_t) ~JERRY_PROP_IS_CONFIGURABLE; define_property (test_object, prop_names[3], &prop_desc, false); - names = jerry_object_get_property_names (test_object, - JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_NON_CONFIGURABLE); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 3); - jerry_release_value (names); - names = jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 4); + names = jerry_object_property_names (test_object, + JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_NON_CONFIGURABLE); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 3); + jerry_value_free (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 4); compare_prop_name (names, prop_names[3], 3); - jerry_release_value (names); + jerry_value_free (names); prop_desc.flags |= JERRY_PROP_IS_CONFIGURABLE; // Test writable - non-writable filter prop_desc.flags &= (uint16_t) ~JERRY_PROP_IS_WRITABLE; define_property (test_object, prop_names[4], &prop_desc, false); - names = jerry_object_get_property_names (test_object, - JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_NON_WRITABLE); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 4); - jerry_release_value (names); - names = jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 5); + names = + jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_NON_WRITABLE); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 4); + jerry_value_free (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 5); compare_prop_name (names, prop_names[4], 4); - jerry_release_value (names); + jerry_value_free (names); prop_desc.flags |= JERRY_PROP_IS_WRITABLE; // Test all property filter - names = jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); - jerry_length_t array_len = jerry_get_array_length (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); + jerry_length_t array_len = jerry_array_length (names); TEST_ASSERT (array_len == (uint32_t) 5); for (uint32_t i = 0; i < array_len; i++) @@ -151,42 +151,41 @@ main (void) compare_prop_name (names, prop_names[i], i); } - jerry_release_value (names); + jerry_value_free (names); // Test number and string index exclusion define_property (test_object, prop_names[5], &prop_desc, false); - names = jerry_object_get_property_names (test_object, - JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS - | JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 1); + names = jerry_object_property_names (test_object, + JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_STRINGS + | JERRY_PROPERTY_FILTER_INTEGER_INDICES_AS_NUMBER); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 1); compare_prop_name (names, prop_names[5], 0); - jerry_release_value (names); - names = jerry_object_get_property_names (test_object, - JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 5); - jerry_release_value (names); + jerry_value_free (names); + names = jerry_object_property_names (test_object, + JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_INTEGER_INDICES); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 5); + jerry_value_free (names); // Test prototype chain traversion - names = jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 6); - jerry_release_value (names); - names = jerry_object_get_property_names (test_object, - JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 18); - jerry_release_value (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 6); + jerry_value_free (names); + names = jerry_object_property_names (test_object, + JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_TRAVERSE_PROTOTYPE_CHAIN); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 18); + jerry_value_free (names); // Test symbol exclusion define_property (test_object, prop_names[6], &prop_desc, true); - names = - jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 6); - jerry_release_value (names); - names = jerry_object_get_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); - TEST_ASSERT (jerry_get_array_length (names) == (uint32_t) 7); - jerry_release_value (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL | JERRY_PROPERTY_FILTER_EXCLUDE_SYMBOLS); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 6); + jerry_value_free (names); + names = jerry_object_property_names (test_object, JERRY_PROPERTY_FILTER_ALL); + TEST_ASSERT (jerry_array_length (names) == (uint32_t) 7); + jerry_value_free (names); jerry_property_descriptor_free (&prop_desc); - jerry_release_value (test_object); + jerry_value_free (test_object); jerry_cleanup (); return 0; } /* main */ diff --git a/tests/unit-core/test-api-objecttype.c b/tests/unit-core/test-api-objecttype.c index abd66f58d8..000179b093 100644 --- a/tests/unit-core/test-api-objecttype.c +++ b/tests/unit-core/test-api-objecttype.c @@ -30,9 +30,9 @@ typedef struct { \ TYPE, VALUE, true \ } -#define ENTRY_IF(TYPE, VALUE, FEATURE) \ - { \ - TYPE, VALUE, jerry_is_feature_enabled (FEATURE) \ +#define ENTRY_IF(TYPE, VALUE, FEATURE) \ + { \ + TYPE, VALUE, jerry_feature_enabled (FEATURE) \ } #define EVALUATE(BUFF) (jerry_eval ((BUFF), sizeof ((BUFF)) - 1, JERRY_PARSE_NO_OPTS)) #define PARSE(OPTS) (jerry_parse ((const jerry_char_t *) "", 0, (OPTS))) @@ -44,7 +44,7 @@ test_ext_function (const jerry_call_info_t *call_info_p, /**< call information * (void) call_info_p; (void) args_p; (void) args_cnt; - return jerry_create_boolean (true); + return jerry_boolean (true); } /* test_ext_function */ static jerry_object_type_t @@ -52,19 +52,19 @@ test_namespace (const jerry_parse_options_t module_parse_options) /** module opt { jerry_value_t module = jerry_parse ((const jerry_char_t *) "", 0, &module_parse_options); jerry_value_t module_linked = jerry_module_link (module, NULL, NULL); - jerry_object_type_t namespace = jerry_module_get_namespace (module); - jerry_release_value (module_linked); - jerry_release_value (module); + jerry_object_type_t namespace = jerry_module_namespace (module); + jerry_value_free (module_linked); + jerry_value_free (module); return namespace; } /* test_namespace */ static jerry_value_t test_dataview (void) { - jerry_value_t arraybuffer = jerry_create_arraybuffer (10); - jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 4); + jerry_value_t arraybuffer = jerry_arraybuffer (10); + jerry_value_t dataview = jerry_dataview (arraybuffer, 0, 4); - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); return dataview; } /* test_dataview */ @@ -109,16 +109,16 @@ main (void) module_parse_options.options = JERRY_PARSE_MODULE; test_entry_t entries[] = { - ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_number (-33.0)), - ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_boolean (true)), - ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_undefined ()), - ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_null ()), - ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_string ((const jerry_char_t *) "foo")), - ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")), - - ENTRY (JERRY_OBJECT_TYPE_GENERIC, jerry_create_object ()), + ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_number (-33.0)), + ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_boolean (true)), + ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_undefined ()), + ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_null ()), + ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_string_sz ("foo")), + ENTRY (JERRY_OBJECT_TYPE_NONE, jerry_throw_sz (JERRY_ERROR_TYPE, "error")), + + ENTRY (JERRY_OBJECT_TYPE_GENERIC, jerry_object ()), ENTRY_IF (JERRY_OBJECT_TYPE_MODULE_NAMESPACE, test_namespace (module_parse_options), JERRY_FEATURE_MODULE), - ENTRY (JERRY_OBJECT_TYPE_ARRAY, jerry_create_array (10)), + ENTRY (JERRY_OBJECT_TYPE_ARRAY, jerry_array (10)), ENTRY_IF (JERRY_OBJECT_TYPE_PROXY, EVALUATE (proxy_object), JERRY_FEATURE_PROXY), ENTRY_IF (JERRY_OBJECT_TYPE_TYPEDARRAY, EVALUATE (typedarray_object), JERRY_FEATURE_TYPEDARRAY), @@ -127,7 +127,7 @@ main (void) ENTRY (JERRY_OBJECT_TYPE_SCRIPT, PARSE (NULL)), ENTRY_IF (JERRY_OBJECT_TYPE_MODULE, PARSE (&module_parse_options), JERRY_FEATURE_MODULE), - ENTRY_IF (JERRY_OBJECT_TYPE_PROMISE, jerry_create_promise (), JERRY_FEATURE_PROMISE), + ENTRY_IF (JERRY_OBJECT_TYPE_PROMISE, jerry_promise (), JERRY_FEATURE_PROMISE), ENTRY_IF (JERRY_OBJECT_TYPE_DATAVIEW, test_dataview (), JERRY_FEATURE_DATAVIEW), ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (arrow_function), JERRY_FEATURE_SYMBOL), ENTRY_IF (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (async_arrow_function), JERRY_FEATURE_SYMBOL), @@ -137,11 +137,11 @@ main (void) ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (builtin_function)), ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (simple_function)), ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (bound_function)), - ENTRY (JERRY_OBJECT_TYPE_FUNCTION, jerry_create_external_function (test_ext_function)), + ENTRY (JERRY_OBJECT_TYPE_FUNCTION, jerry_function_external (test_ext_function)), ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (getter_function)), ENTRY (JERRY_OBJECT_TYPE_FUNCTION, EVALUATE (setter_function)), ENTRY_IF (JERRY_OBJECT_TYPE_ERROR, EVALUATE (error_object), JERRY_FEATURE_ERROR_MESSAGES), - ENTRY_IF (JERRY_OBJECT_TYPE_ARRAYBUFFER, jerry_create_arraybuffer (10), JERRY_FEATURE_TYPEDARRAY), + ENTRY_IF (JERRY_OBJECT_TYPE_ARRAYBUFFER, jerry_arraybuffer (10), JERRY_FEATURE_TYPEDARRAY), ENTRY (JERRY_OBJECT_TYPE_ARGUMENTS, EVALUATE (mapped_arguments)), ENTRY (JERRY_OBJECT_TYPE_ARGUMENTS, EVALUATE (unmapped_arguments)), @@ -158,25 +158,25 @@ main (void) for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++) { - jerry_object_type_t type_info = jerry_object_get_type (entries[idx].value); + jerry_object_type_t type_info = jerry_object_type (entries[idx].value); TEST_ASSERT (!entries[idx].active || type_info == entries[idx].type_info); - jerry_release_value (entries[idx].value); + jerry_value_free (entries[idx].value); } - if (jerry_is_feature_enabled (JERRY_FEATURE_REALM)) + if (jerry_feature_enabled (JERRY_FEATURE_REALM)) { - jerry_value_t new_realm = jerry_create_realm (); - jerry_object_type_t new_realm_object_type = jerry_object_get_type (new_realm); + jerry_value_t new_realm = jerry_realm (); + jerry_object_type_t new_realm_object_type = jerry_object_type (new_realm); TEST_ASSERT (new_realm_object_type == JERRY_OBJECT_TYPE_GENERIC); jerry_value_t old_realm = jerry_set_realm (new_realm); - jerry_object_type_t old_realm_object_type = jerry_object_get_type (old_realm); + jerry_object_type_t old_realm_object_type = jerry_object_type (old_realm); TEST_ASSERT (old_realm_object_type == JERRY_OBJECT_TYPE_GENERIC); jerry_set_realm (old_realm); - jerry_release_value (new_realm); + jerry_value_free (new_realm); } jerry_cleanup (); diff --git a/tests/unit-core/test-api-promise.c b/tests/unit-core/test-api-promise.c index 94e5e6ee20..7bfed77947 100644 --- a/tests/unit-core/test-api-promise.c +++ b/tests/unit-core/test-api-promise.c @@ -22,135 +22,134 @@ static void test_promise_resolve_success (void) { - jerry_value_t my_promise = jerry_create_promise (); + jerry_value_t my_promise = jerry_promise (); // A created promise has an undefined promise result by default and a pending state { - jerry_value_t promise_result = jerry_get_promise_result (my_promise); + jerry_value_t promise_result = jerry_promise_result (my_promise); TEST_ASSERT (jerry_value_is_undefined (promise_result)); - jerry_promise_state_t promise_state = jerry_get_promise_state (my_promise); + jerry_promise_state_t promise_state = jerry_promise_state (my_promise); TEST_ASSERT (promise_state == JERRY_PROMISE_STATE_PENDING); - jerry_release_value (promise_result); + jerry_value_free (promise_result); } - jerry_value_t resolve_value = jerry_create_object (); + jerry_value_t resolve_value = jerry_object (); { - jerry_value_t obj_key = jerry_create_string ((const jerry_char_t *) "key_one"); - jerry_value_t set_result = jerry_set_property (resolve_value, obj_key, jerry_create_number (3)); + jerry_value_t obj_key = jerry_string_sz ("key_one"); + jerry_value_t set_result = jerry_object_set (resolve_value, obj_key, jerry_number (3)); TEST_ASSERT (jerry_value_is_boolean (set_result) && (jerry_value_is_true (set_result))); - jerry_release_value (set_result); - jerry_release_value (obj_key); + jerry_value_free (set_result); + jerry_value_free (obj_key); } // A resolved promise should have the result of from the resolve call and a fulfilled state { - jerry_value_t resolve_result = jerry_resolve_or_reject_promise (my_promise, resolve_value, true); + jerry_value_t resolve_result = jerry_promise_resolve (my_promise, resolve_value); // Release "old" value of resolve. - jerry_release_value (resolve_value); + jerry_value_free (resolve_value); - jerry_value_t promise_result = jerry_get_promise_result (my_promise); + jerry_value_t promise_result = jerry_promise_result (my_promise); { TEST_ASSERT (jerry_value_is_object (promise_result)); - jerry_value_t obj_key = jerry_create_string ((const jerry_char_t *) "key_one"); - jerry_value_t get_result = jerry_get_property (promise_result, obj_key); + jerry_value_t obj_key = jerry_string_sz ("key_one"); + jerry_value_t get_result = jerry_object_get (promise_result, obj_key); TEST_ASSERT (jerry_value_is_number (get_result)); - TEST_ASSERT (jerry_get_number_value (get_result) == 3.0); + TEST_ASSERT (jerry_value_as_number (get_result) == 3.0); - jerry_release_value (get_result); - jerry_release_value (obj_key); + jerry_value_free (get_result); + jerry_value_free (obj_key); } - jerry_promise_state_t promise_state = jerry_get_promise_state (my_promise); + jerry_promise_state_t promise_state = jerry_promise_state (my_promise); TEST_ASSERT (promise_state == JERRY_PROMISE_STATE_FULFILLED); - jerry_release_value (promise_result); + jerry_value_free (promise_result); - jerry_release_value (resolve_result); + jerry_value_free (resolve_result); } // Resolvind a promise again does not change the result/state { - jerry_value_t resolve_result = jerry_resolve_or_reject_promise (my_promise, jerry_create_number (50), false); + jerry_value_t resolve_result = jerry_promise_reject (my_promise, jerry_number (50)); - jerry_value_t promise_result = jerry_get_promise_result (my_promise); + jerry_value_t promise_result = jerry_promise_result (my_promise); { TEST_ASSERT (jerry_value_is_object (promise_result)); - jerry_value_t obj_key = jerry_create_string ((const jerry_char_t *) "key_one"); - jerry_value_t get_result = jerry_get_property (promise_result, obj_key); + jerry_value_t obj_key = jerry_string_sz ("key_one"); + jerry_value_t get_result = jerry_object_get (promise_result, obj_key); TEST_ASSERT (jerry_value_is_number (get_result)); - TEST_ASSERT (jerry_get_number_value (get_result) == 3.0); + TEST_ASSERT (jerry_value_as_number (get_result) == 3.0); - jerry_release_value (get_result); - jerry_release_value (obj_key); + jerry_value_free (get_result); + jerry_value_free (obj_key); } - jerry_promise_state_t promise_state = jerry_get_promise_state (my_promise); + jerry_promise_state_t promise_state = jerry_promise_state (my_promise); TEST_ASSERT (promise_state == JERRY_PROMISE_STATE_FULFILLED); - jerry_release_value (promise_result); + jerry_value_free (promise_result); - jerry_release_value (resolve_result); + jerry_value_free (resolve_result); } - jerry_release_value (my_promise); + jerry_value_free (my_promise); } /* test_promise_resolve_success */ static void test_promise_resolve_fail (void) { - jerry_value_t my_promise = jerry_create_promise (); + jerry_value_t my_promise = jerry_promise (); // A created promise has an undefined promise result by default and a pending state { - jerry_value_t promise_result = jerry_get_promise_result (my_promise); + jerry_value_t promise_result = jerry_promise_result (my_promise); TEST_ASSERT (jerry_value_is_undefined (promise_result)); - jerry_promise_state_t promise_state = jerry_get_promise_state (my_promise); + jerry_promise_state_t promise_state = jerry_promise_state (my_promise); TEST_ASSERT (promise_state == JERRY_PROMISE_STATE_PENDING); - jerry_release_value (promise_result); + jerry_value_free (promise_result); } // A resolved promise should have the result of from the resolve call and a fulfilled state { - jerry_value_t error_value = jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "resolve_fail"); - jerry_value_t error_obj = jerry_get_value_from_error (error_value, true); - jerry_value_t resolve_result = jerry_resolve_or_reject_promise (my_promise, error_obj, false); - jerry_release_value (error_obj); + jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, "resolve_fail"); + jerry_value_t resolve_result = jerry_promise_reject (my_promise, error_obj); + jerry_value_free (error_obj); - jerry_value_t promise_result = jerry_get_promise_result (my_promise); + jerry_value_t promise_result = jerry_promise_result (my_promise); // The error is not throw that's why it is only an error object. TEST_ASSERT (jerry_value_is_object (promise_result)); - TEST_ASSERT (jerry_get_error_type (promise_result) == JERRY_ERROR_TYPE); + TEST_ASSERT (jerry_error_type (promise_result) == JERRY_ERROR_TYPE); - jerry_promise_state_t promise_state = jerry_get_promise_state (my_promise); + jerry_promise_state_t promise_state = jerry_promise_state (my_promise); TEST_ASSERT (promise_state == JERRY_PROMISE_STATE_REJECTED); - jerry_release_value (promise_result); + jerry_value_free (promise_result); - jerry_release_value (resolve_result); + jerry_value_free (resolve_result); } // Resolvind a promise again does not change the result/state { - jerry_value_t resolve_result = jerry_resolve_or_reject_promise (my_promise, jerry_create_number (50), true); + jerry_value_t resolve_result = jerry_promise_resolve (my_promise, jerry_number (50)); - jerry_value_t promise_result = jerry_get_promise_result (my_promise); + jerry_value_t promise_result = jerry_promise_result (my_promise); TEST_ASSERT (jerry_value_is_object (promise_result)); - TEST_ASSERT (jerry_get_error_type (promise_result) == JERRY_ERROR_TYPE); + TEST_ASSERT (jerry_error_type (promise_result) == JERRY_ERROR_TYPE); - jerry_promise_state_t promise_state = jerry_get_promise_state (my_promise); + jerry_promise_state_t promise_state = jerry_promise_state (my_promise); TEST_ASSERT (promise_state == JERRY_PROMISE_STATE_REJECTED); - jerry_release_value (promise_result); + jerry_value_free (promise_result); - jerry_release_value (resolve_result); + jerry_value_free (resolve_result); } - jerry_release_value (my_promise); + jerry_value_free (my_promise); } /* test_promise_resolve_fail */ static void @@ -159,31 +158,31 @@ test_promise_from_js (void) const jerry_char_t test_source[] = "(new Promise(function(rs, rj) { rs(30); })).then(function(v) { return v + 1; })"; jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); TEST_ASSERT (jerry_value_is_promise (res)); - TEST_ASSERT (jerry_get_promise_state (res) == JERRY_PROMISE_STATE_PENDING); + TEST_ASSERT (jerry_promise_state (res) == JERRY_PROMISE_STATE_PENDING); - jerry_value_t run_result = jerry_run_all_enqueued_jobs (); + jerry_value_t run_result = jerry_run_microtasks (); TEST_ASSERT (jerry_value_is_undefined (run_result)); - jerry_release_value (run_result); + jerry_value_free (run_result); - TEST_ASSERT (jerry_get_promise_state (res) == JERRY_PROMISE_STATE_FULFILLED); - jerry_value_t promise_result = jerry_get_promise_result (res); + TEST_ASSERT (jerry_promise_state (res) == JERRY_PROMISE_STATE_FULFILLED); + jerry_value_t promise_result = jerry_promise_result (res); TEST_ASSERT (jerry_value_is_number (promise_result)); - TEST_ASSERT (jerry_get_number_value (promise_result) == 31.0); + TEST_ASSERT (jerry_value_as_number (promise_result) == 31.0); - jerry_release_value (promise_result); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (promise_result); + jerry_value_free (res); + jerry_value_free (parsed_code_val); } /* test_promise_from_js */ int main (void) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_PROMISE)) + if (!jerry_feature_enabled (JERRY_FEATURE_PROMISE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Promise is disabled!\n"); return 0; diff --git a/tests/unit-core/test-api-property.c b/tests/unit-core/test-api-property.c index a1d14e5be7..2315003bb9 100644 --- a/tests/unit-core/test-api-property.c +++ b/tests/unit-core/test-api-property.c @@ -25,47 +25,47 @@ main (void) jerry_init (JERRY_INIT_EMPTY); /* Test: init property descriptor */ - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); TEST_ASSERT (prop_desc.flags == JERRY_PROP_NO_OPTS); TEST_ASSERT (jerry_value_is_undefined (prop_desc.value)); TEST_ASSERT (jerry_value_is_undefined (prop_desc.getter)); TEST_ASSERT (jerry_value_is_undefined (prop_desc.setter)); /* Test: define own properties */ - jerry_value_t global_obj_val = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_defined_property"); + jerry_value_t global_obj_val = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("my_defined_property"); prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED; - prop_desc.value = jerry_acquire_value (prop_name); - jerry_value_t res = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); + prop_desc.value = jerry_value_copy (prop_name); + jerry_value_t res = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (res) && jerry_value_is_true (res)); - jerry_release_value (res); + jerry_value_free (res); jerry_property_descriptor_free (&prop_desc); /* Test: define own property with error */ - prop_desc = jerry_property_descriptor_create (); + prop_desc = jerry_property_descriptor (); prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_SHOULD_THROW; - prop_desc.value = jerry_create_number (3.14); - res = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); - TEST_ASSERT (jerry_value_is_error (res)); - jerry_release_value (res); + prop_desc.value = jerry_number (3.14); + res = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); + TEST_ASSERT (jerry_value_is_exception (res)); + jerry_value_free (res); jerry_property_descriptor_free (&prop_desc); /* Test: test define own property failure without throw twice */ - prop_desc = jerry_property_descriptor_create (); + prop_desc = jerry_property_descriptor (); prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_GET_DEFINED; - res = jerry_define_own_property (prop_name, prop_name, &prop_desc); + res = jerry_object_define_own_prop (prop_name, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (res) && !jerry_value_is_true (res)); - jerry_release_value (res); - res = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); + jerry_value_free (res); + res = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (res) && !jerry_value_is_true (res)); - jerry_release_value (res); + jerry_value_free (res); jerry_property_descriptor_free (&prop_desc); /* Test: get own property descriptor */ - prop_desc = jerry_property_descriptor_create (); - jerry_value_t is_ok = jerry_get_own_property_descriptor (global_obj_val, prop_name, &prop_desc); + prop_desc = jerry_property_descriptor (); + jerry_value_t is_ok = jerry_object_get_own_prop (global_obj_val, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (is_ok) && jerry_value_is_true (is_ok)); - jerry_release_value (is_ok); + jerry_value_free (is_ok); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_VALUE_DEFINED); TEST_ASSERT (jerry_value_is_string (prop_desc.value)); TEST_ASSERT (!(prop_desc.flags & JERRY_PROP_IS_WRITABLE)); @@ -77,61 +77,61 @@ main (void) TEST_ASSERT (jerry_value_is_undefined (prop_desc.setter)); jerry_property_descriptor_free (&prop_desc); - if (jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (jerry_feature_enabled (JERRY_FEATURE_PROXY)) { /* Note: update this test when the internal method is implemented */ - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); - jerry_release_value (target); - jerry_release_value (handler); - is_ok = jerry_get_own_property_descriptor (proxy, prop_name, &prop_desc); + jerry_value_free (target); + jerry_value_free (handler); + is_ok = jerry_object_get_own_prop (proxy, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (is_ok) && !jerry_value_is_true (is_ok)); - jerry_release_value (is_ok); - jerry_release_value (proxy); + jerry_value_free (is_ok); + jerry_value_free (proxy); } - jerry_release_value (prop_name); + jerry_value_free (prop_name); /* Test: define and get own property descriptor */ prop_desc.flags |= JERRY_PROP_IS_ENUMERABLE; - prop_name = jerry_create_string ((const jerry_char_t *) "enumerable-property"); - res = jerry_define_own_property (global_obj_val, prop_name, &prop_desc); - TEST_ASSERT (!jerry_value_is_error (res)); + prop_name = jerry_string_sz ("enumerable-property"); + res = jerry_object_define_own_prop (global_obj_val, prop_name, &prop_desc); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); + jerry_value_free (res); jerry_property_descriptor_free (&prop_desc); - is_ok = jerry_get_own_property_descriptor (global_obj_val, prop_name, &prop_desc); + is_ok = jerry_object_get_own_prop (global_obj_val, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (is_ok) && jerry_value_is_true (is_ok)); - jerry_release_value (is_ok); + jerry_value_free (is_ok); TEST_ASSERT (!(prop_desc.flags & JERRY_PROP_IS_WRITABLE)); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE); TEST_ASSERT (!(prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE)); - jerry_release_value (prop_name); - jerry_release_value (global_obj_val); + jerry_value_free (prop_name); + jerry_value_free (global_obj_val); /* Test: define own property descriptor error */ - prop_desc = jerry_property_descriptor_create (); + prop_desc = jerry_property_descriptor (); prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED; - prop_desc.value = jerry_create_number (11); - - jerry_value_t obj_val = jerry_create_object (); - prop_name = jerry_create_string ((const jerry_char_t *) "property_key"); - res = jerry_define_own_property (obj_val, prop_name, &prop_desc); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (res); - - jerry_release_value (prop_desc.value); - prop_desc.value = jerry_create_number (22); - res = jerry_define_own_property (obj_val, prop_name, &prop_desc); - TEST_ASSERT (jerry_value_is_error (res)); - jerry_release_value (res); - - jerry_release_value (prop_name); - jerry_release_value (obj_val); + prop_desc.value = jerry_number (11); + + jerry_value_t obj_val = jerry_object (); + prop_name = jerry_string_sz ("property_key"); + res = jerry_object_define_own_prop (obj_val, prop_name, &prop_desc); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (res); + + jerry_value_free (prop_desc.value); + prop_desc.value = jerry_number (22); + res = jerry_object_define_own_prop (obj_val, prop_name, &prop_desc); + TEST_ASSERT (jerry_value_is_exception (res)); + jerry_value_free (res); + + jerry_value_free (prop_name); + jerry_value_free (obj_val); jerry_cleanup (); diff --git a/tests/unit-core/test-api-set-and-clear-error-flag.c b/tests/unit-core/test-api-set-and-clear-error-flag.c index eba6b89720..dea5cfe5c6 100644 --- a/tests/unit-core/test-api-set-and-clear-error-flag.c +++ b/tests/unit-core/test-api-set-and-clear-error-flag.c @@ -18,12 +18,12 @@ #include "test-common.h" static void -compare_str (jerry_value_t value, const jerry_char_t *str_p, size_t str_len) +compare_str (jerry_value_t value, const char *str_p, size_t str_len) { - jerry_size_t size = jerry_get_string_size (value); + jerry_size_t size = jerry_string_size (value, JERRY_ENCODING_CESU8); TEST_ASSERT (str_len == size); JERRY_VLA (jerry_char_t, str_buff, size); - jerry_string_to_utf8_char_buffer (value, str_buff, size); + jerry_string_to_buffer (value, str_buff, size, JERRY_ENCODING_CESU8); TEST_ASSERT (!memcmp (str_p, str_buff, str_len)); } /* compare_str */ @@ -34,174 +34,174 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t obj_val = jerry_create_object (); - obj_val = jerry_create_error_from_value (obj_val, true); - jerry_value_t err_val = jerry_acquire_value (obj_val); + jerry_value_t obj_val = jerry_object (); + obj_val = jerry_throw_value (obj_val, true); + jerry_value_t err_val = jerry_value_copy (obj_val); - obj_val = jerry_get_value_from_error (err_val, true); + obj_val = jerry_exception_value (err_val, true); TEST_ASSERT (obj_val != err_val); - jerry_release_value (err_val); - jerry_release_value (obj_val); + jerry_value_free (err_val); + jerry_value_free (obj_val); - const jerry_char_t pterodactylus[] = "Pterodactylus"; + const char pterodactylus[] = "Pterodactylus"; const size_t pterodactylus_size = sizeof (pterodactylus) - 1; - jerry_value_t str = jerry_create_string (pterodactylus); - jerry_value_t error = jerry_create_error_from_value (str, true); - str = jerry_get_value_from_error (error, true); + jerry_value_t str = jerry_string_sz (pterodactylus); + jerry_value_t error = jerry_throw_value (str, true); + str = jerry_exception_value (error, true); compare_str (str, pterodactylus, pterodactylus_size); - jerry_release_value (str); + jerry_value_free (str); - str = jerry_create_string (pterodactylus); - error = jerry_create_error_from_value (str, false); - jerry_release_value (str); - str = jerry_get_value_from_error (error, true); + str = jerry_string_sz (pterodactylus); + error = jerry_throw_value (str, false); + jerry_value_free (str); + str = jerry_exception_value (error, true); compare_str (str, pterodactylus, pterodactylus_size); - jerry_release_value (str); + jerry_value_free (str); - str = jerry_create_string (pterodactylus); - error = jerry_create_abort_from_value (str, true); - str = jerry_get_value_from_error (error, true); + str = jerry_string_sz (pterodactylus); + error = jerry_throw_abort (str, true); + str = jerry_exception_value (error, true); compare_str (str, pterodactylus, pterodactylus_size); - jerry_release_value (str); + jerry_value_free (str); - str = jerry_create_string (pterodactylus); - error = jerry_create_abort_from_value (str, false); - jerry_release_value (str); - str = jerry_get_value_from_error (error, true); + str = jerry_string_sz (pterodactylus); + error = jerry_throw_abort (str, false); + jerry_value_free (str); + str = jerry_exception_value (error, true); compare_str (str, pterodactylus, pterodactylus_size); - jerry_release_value (str); + jerry_value_free (str); - str = jerry_create_string (pterodactylus); - error = jerry_create_error_from_value (str, true); - error = jerry_create_abort_from_value (error, true); + str = jerry_string_sz (pterodactylus); + error = jerry_throw_value (str, true); + error = jerry_throw_abort (error, true); TEST_ASSERT (jerry_value_is_abort (error)); - str = jerry_get_value_from_error (error, true); + str = jerry_exception_value (error, true); compare_str (str, pterodactylus, pterodactylus_size); - jerry_release_value (str); + jerry_value_free (str); - str = jerry_create_string (pterodactylus); - error = jerry_create_error_from_value (str, true); - jerry_value_t error2 = jerry_create_abort_from_value (error, false); + str = jerry_string_sz (pterodactylus); + error = jerry_throw_value (str, true); + jerry_value_t error2 = jerry_throw_abort (error, false); TEST_ASSERT (jerry_value_is_abort (error2)); - jerry_release_value (error); - str = jerry_get_value_from_error (error2, true); + jerry_value_free (error); + str = jerry_exception_value (error2, true); compare_str (str, pterodactylus, pterodactylus_size); - jerry_release_value (str); + jerry_value_free (str); double test_num = 3.1415926; - jerry_value_t num = jerry_create_number (test_num); - jerry_value_t num2 = jerry_create_error_from_value (num, false); - TEST_ASSERT (jerry_value_is_error (num2)); - jerry_release_value (num); - num2 = jerry_get_value_from_error (num2, true); - TEST_ASSERT (jerry_get_number_value (num2) == test_num); - jerry_release_value (num2); - - num = jerry_create_number (test_num); - num2 = jerry_create_error_from_value (num, true); - TEST_ASSERT (jerry_value_is_error (num2)); - num2 = jerry_get_value_from_error (num2, true); - TEST_ASSERT (jerry_get_number_value (num2) == test_num); - jerry_release_value (num2); - - num = jerry_create_number (test_num); - num2 = jerry_create_error_from_value (num, false); - TEST_ASSERT (jerry_value_is_error (num2)); - jerry_release_value (num); - jerry_value_t num3 = jerry_create_error_from_value (num2, false); - TEST_ASSERT (jerry_value_is_error (num3)); - jerry_release_value (num2); - num2 = jerry_get_value_from_error (num3, true); - TEST_ASSERT (jerry_get_number_value (num2) == test_num); - jerry_release_value (num2); - - num = jerry_create_number (test_num); - num2 = jerry_create_error_from_value (num, true); - TEST_ASSERT (jerry_value_is_error (num2)); - num3 = jerry_create_error_from_value (num2, true); - TEST_ASSERT (jerry_value_is_error (num3)); - num2 = jerry_get_value_from_error (num3, true); - TEST_ASSERT (jerry_get_number_value (num2) == test_num); - jerry_release_value (num2); - - num = jerry_create_number (test_num); - error = jerry_create_abort_from_value (num, true); + jerry_value_t num = jerry_number (test_num); + jerry_value_t num2 = jerry_throw_value (num, false); + TEST_ASSERT (jerry_value_is_exception (num2)); + jerry_value_free (num); + num2 = jerry_exception_value (num2, true); + TEST_ASSERT (jerry_value_as_number (num2) == test_num); + jerry_value_free (num2); + + num = jerry_number (test_num); + num2 = jerry_throw_value (num, true); + TEST_ASSERT (jerry_value_is_exception (num2)); + num2 = jerry_exception_value (num2, true); + TEST_ASSERT (jerry_value_as_number (num2) == test_num); + jerry_value_free (num2); + + num = jerry_number (test_num); + num2 = jerry_throw_value (num, false); + TEST_ASSERT (jerry_value_is_exception (num2)); + jerry_value_free (num); + jerry_value_t num3 = jerry_throw_value (num2, false); + TEST_ASSERT (jerry_value_is_exception (num3)); + jerry_value_free (num2); + num2 = jerry_exception_value (num3, true); + TEST_ASSERT (jerry_value_as_number (num2) == test_num); + jerry_value_free (num2); + + num = jerry_number (test_num); + num2 = jerry_throw_value (num, true); + TEST_ASSERT (jerry_value_is_exception (num2)); + num3 = jerry_throw_value (num2, true); + TEST_ASSERT (jerry_value_is_exception (num3)); + num2 = jerry_exception_value (num3, true); + TEST_ASSERT (jerry_value_as_number (num2) == test_num); + jerry_value_free (num2); + + num = jerry_number (test_num); + error = jerry_throw_abort (num, true); TEST_ASSERT (jerry_value_is_abort (error)); - num2 = jerry_create_error_from_value (error, true); - TEST_ASSERT (jerry_value_is_error (num2)); - num = jerry_get_value_from_error (num2, true); - TEST_ASSERT (jerry_get_number_value (num) == test_num); - jerry_release_value (num); - - num = jerry_create_number (test_num); - error = jerry_create_abort_from_value (num, false); - jerry_release_value (num); + num2 = jerry_throw_value (error, true); + TEST_ASSERT (jerry_value_is_exception (num2)); + num = jerry_exception_value (num2, true); + TEST_ASSERT (jerry_value_as_number (num) == test_num); + jerry_value_free (num); + + num = jerry_number (test_num); + error = jerry_throw_abort (num, false); + jerry_value_free (num); TEST_ASSERT (jerry_value_is_abort (error)); - num2 = jerry_create_error_from_value (error, true); - TEST_ASSERT (jerry_value_is_error (num2)); - num = jerry_get_value_from_error (num2, true); - TEST_ASSERT (jerry_get_number_value (num) == test_num); - jerry_release_value (num); - - num = jerry_create_number (test_num); - error = jerry_create_abort_from_value (num, true); + num2 = jerry_throw_value (error, true); + TEST_ASSERT (jerry_value_is_exception (num2)); + num = jerry_exception_value (num2, true); + TEST_ASSERT (jerry_value_as_number (num) == test_num); + jerry_value_free (num); + + num = jerry_number (test_num); + error = jerry_throw_abort (num, true); TEST_ASSERT (jerry_value_is_abort (error)); - num2 = jerry_create_error_from_value (error, false); - jerry_release_value (error); - TEST_ASSERT (jerry_value_is_error (num2)); - num = jerry_get_value_from_error (num2, true); - TEST_ASSERT (jerry_get_number_value (num) == test_num); - jerry_release_value (num); - - num = jerry_create_number (test_num); - error = jerry_create_abort_from_value (num, false); - jerry_release_value (num); + num2 = jerry_throw_value (error, false); + jerry_value_free (error); + TEST_ASSERT (jerry_value_is_exception (num2)); + num = jerry_exception_value (num2, true); + TEST_ASSERT (jerry_value_as_number (num) == test_num); + jerry_value_free (num); + + num = jerry_number (test_num); + error = jerry_throw_abort (num, false); + jerry_value_free (num); TEST_ASSERT (jerry_value_is_abort (error)); - num2 = jerry_create_error_from_value (error, false); - jerry_release_value (error); - TEST_ASSERT (jerry_value_is_error (num2)); - num = jerry_get_value_from_error (num2, true); - TEST_ASSERT (jerry_get_number_value (num) == test_num); - jerry_release_value (num); - - jerry_value_t value = jerry_create_number (42); - value = jerry_get_value_from_error (value, true); - jerry_release_value (value); - - value = jerry_create_number (42); - jerry_value_t value2 = jerry_get_value_from_error (value, false); - jerry_release_value (value); - jerry_release_value (value2); - - value = jerry_create_number (42); - error = jerry_create_error_from_value (value, true); - error = jerry_create_error_from_value (error, true); - jerry_release_value (error); - - value = jerry_create_number (42); - error = jerry_create_abort_from_value (value, true); - error = jerry_create_abort_from_value (error, true); - jerry_release_value (error); - - value = jerry_create_number (42); - error = jerry_create_error_from_value (value, true); - error2 = jerry_create_error_from_value (error, false); - jerry_release_value (error); - jerry_release_value (error2); - - value = jerry_create_number (42); - error = jerry_create_abort_from_value (value, true); - error2 = jerry_create_abort_from_value (error, false); - jerry_release_value (error); - jerry_release_value (error2); + num2 = jerry_throw_value (error, false); + jerry_value_free (error); + TEST_ASSERT (jerry_value_is_exception (num2)); + num = jerry_exception_value (num2, true); + TEST_ASSERT (jerry_value_as_number (num) == test_num); + jerry_value_free (num); + + jerry_value_t value = jerry_number (42); + value = jerry_exception_value (value, true); + jerry_value_free (value); + + value = jerry_number (42); + jerry_value_t value2 = jerry_exception_value (value, false); + jerry_value_free (value); + jerry_value_free (value2); + + value = jerry_number (42); + error = jerry_throw_value (value, true); + error = jerry_throw_value (error, true); + jerry_value_free (error); + + value = jerry_number (42); + error = jerry_throw_abort (value, true); + error = jerry_throw_abort (error, true); + jerry_value_free (error); + + value = jerry_number (42); + error = jerry_throw_value (value, true); + error2 = jerry_throw_value (error, false); + jerry_value_free (error); + jerry_value_free (error2); + + value = jerry_number (42); + error = jerry_throw_abort (value, true); + error2 = jerry_throw_abort (error, false); + jerry_value_free (error); + jerry_value_free (error2); jerry_cleanup (); } /* main */ diff --git a/tests/unit-core/test-api-strings.c b/tests/unit-core/test-api-strings.c index a3b2496a2a..ac7d5ea408 100644 --- a/tests/unit-core/test-api-strings.c +++ b/tests/unit-core/test-api-strings.c @@ -23,14 +23,14 @@ strict_equals (jerry_value_t a, /**< the first string to compare */ { const jerry_char_t is_equal_src[] = "var isEqual = function(a, b) { return (a === b); }; isEqual"; jerry_value_t is_equal_fn_val = jerry_eval (is_equal_src, sizeof (is_equal_src) - 1, JERRY_PARSE_NO_OPTS); - TEST_ASSERT (!jerry_value_is_error (is_equal_fn_val)); + TEST_ASSERT (!jerry_value_is_exception (is_equal_fn_val)); jerry_value_t args[2] = { a, b }; - jerry_value_t res = jerry_call_function (is_equal_fn_val, jerry_create_undefined (), args, 2); - TEST_ASSERT (!jerry_value_is_error (res)); + jerry_value_t res = jerry_call (is_equal_fn_val, jerry_undefined (), args, 2); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res)); bool is_strict_equal = jerry_value_is_true (res); - jerry_release_value (res); - jerry_release_value (is_equal_fn_val); + jerry_value_free (res); + jerry_value_free (is_equal_fn_val); return is_strict_equal; } /* strict_equals */ @@ -38,253 +38,127 @@ int main (void) { jerry_size_t sz, utf8_sz, cesu8_sz; - jerry_length_t cesu8_length, utf8_length; jerry_value_t args[2]; TEST_INIT (); jerry_init (JERRY_INIT_EMPTY); /* Test corner case for jerry_string_to_char_buffer */ - args[0] = jerry_create_string ((jerry_char_t *) ""); - sz = jerry_get_string_size (args[0]); + args[0] = jerry_string_sz (""); + sz = jerry_string_size (args[0], JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 0); - jerry_release_value (args[0]); + jerry_value_free (args[0]); /* Test create_jerry_string_from_utf8 with 4-byte long unicode sequences, * test string: 'str: {DESERET CAPITAL LETTER LONG I}' */ - args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "\x73\x74\x72\x3a \xf0\x90\x90\x80"); - args[1] = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"); + char *utf8_bytes_p = "\x73\x74\x72\x3a \xf0\x90\x90\x80"; + char *cesu8_bytes_p = "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"; + args[0] = jerry_string ((jerry_char_t *) utf8_bytes_p, (jerry_size_t) strlen (utf8_bytes_p), JERRY_ENCODING_UTF8); + args[1] = jerry_string ((jerry_char_t *) cesu8_bytes_p, (jerry_size_t) strlen (cesu8_bytes_p), JERRY_ENCODING_CESU8); /* These sizes must be equal */ - utf8_sz = jerry_get_string_size (args[0]); - cesu8_sz = jerry_get_string_size (args[1]); + utf8_sz = jerry_string_size (args[0], JERRY_ENCODING_CESU8); + cesu8_sz = jerry_string_size (args[1], JERRY_ENCODING_CESU8); - JERRY_VLA (char, string_from_utf8, utf8_sz); - JERRY_VLA (char, string_from_cesu8, cesu8_sz); + JERRY_VLA (jerry_char_t, string_from_utf8, utf8_sz); + JERRY_VLA (jerry_char_t, string_from_cesu8, cesu8_sz); - jerry_string_to_char_buffer (args[0], (jerry_char_t *) string_from_utf8, utf8_sz); - jerry_string_to_char_buffer (args[1], (jerry_char_t *) string_from_cesu8, cesu8_sz); + jerry_string_to_buffer (args[0], string_from_utf8, utf8_sz, JERRY_ENCODING_CESU8); + jerry_string_to_buffer (args[1], string_from_cesu8, cesu8_sz, JERRY_ENCODING_CESU8); TEST_ASSERT (utf8_sz == cesu8_sz); - TEST_ASSERT (!strncmp (string_from_utf8, string_from_cesu8, utf8_sz)); - jerry_release_value (args[0]); - jerry_release_value (args[1]); + TEST_ASSERT (!memcmp (string_from_utf8, string_from_cesu8, utf8_sz)); + jerry_value_free (args[0]); + jerry_value_free (args[1]); - /* Test jerry_string_to_utf8_char_buffer, test string: 'str: {DESERET CAPITAL LETTER LONG I}' */ - args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "\x73\x74\x72\x3a \xf0\x90\x90\x80"); - args[1] = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"); + /* Test jerry_string_to_buffer, test string: 'str: {DESERET CAPITAL LETTER LONG I}' */ + utf8_bytes_p = "\x73\x74\x72\x3a \xf0\x90\x90\x80"; + cesu8_bytes_p = "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"; + args[0] = jerry_string ((jerry_char_t *) utf8_bytes_p, (jerry_size_t) strlen (utf8_bytes_p), JERRY_ENCODING_UTF8); + args[1] = jerry_string ((jerry_char_t *) cesu8_bytes_p, (jerry_size_t) strlen (cesu8_bytes_p), JERRY_ENCODING_CESU8); /* Test that the strings are equal / ensure hashes are equal */ TEST_ASSERT (strict_equals (args[0], args[1])); /* These sizes must be equal */ - utf8_sz = jerry_get_utf8_string_size (args[0]); - cesu8_sz = jerry_get_utf8_string_size (args[1]); + utf8_sz = jerry_string_size (args[0], JERRY_ENCODING_UTF8); + cesu8_sz = jerry_string_size (args[1], JERRY_ENCODING_UTF8); TEST_ASSERT (utf8_sz == cesu8_sz && utf8_sz > 0); - JERRY_VLA (char, string_from_utf8_string, utf8_sz); - JERRY_VLA (char, string_from_cesu8_string, cesu8_sz); + JERRY_VLA (jerry_char_t, string_from_utf8_string, utf8_sz); + JERRY_VLA (jerry_char_t, string_from_cesu8_string, cesu8_sz); - jerry_string_to_utf8_char_buffer (args[0], (jerry_char_t *) string_from_utf8_string, utf8_sz); - jerry_string_to_utf8_char_buffer (args[1], (jerry_char_t *) string_from_cesu8_string, cesu8_sz); + jerry_string_to_buffer (args[0], string_from_utf8_string, utf8_sz, JERRY_ENCODING_UTF8); + jerry_string_to_buffer (args[1], string_from_cesu8_string, cesu8_sz, JERRY_ENCODING_UTF8); - TEST_ASSERT (!strncmp (string_from_utf8_string, string_from_cesu8_string, utf8_sz)); - jerry_release_value (args[0]); - jerry_release_value (args[1]); + TEST_ASSERT (!memcmp (string_from_utf8_string, string_from_cesu8_string, utf8_sz)); + jerry_value_free (args[0]); + jerry_value_free (args[1]); /* Test string: 'str: {MATHEMATICAL FRAKTUR SMALL F}{MATHEMATICAL FRAKTUR SMALL G}' */ - args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4"); + utf8_bytes_p = "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4"; + args[0] = jerry_string ((jerry_char_t *) utf8_bytes_p, (jerry_size_t) strlen (utf8_bytes_p), JERRY_ENCODING_UTF8); - cesu8_length = jerry_get_string_length (args[0]); - utf8_length = jerry_get_utf8_string_length (args[0]); + cesu8_sz = jerry_string_size (args[0], JERRY_ENCODING_CESU8); + utf8_sz = jerry_string_size (args[0], JERRY_ENCODING_UTF8); - cesu8_sz = jerry_get_string_size (args[0]); - utf8_sz = jerry_get_utf8_string_size (args[0]); - - TEST_ASSERT (cesu8_length == 10 && utf8_length == 8); + TEST_ASSERT (jerry_string_length (args[0]) == 10); TEST_ASSERT (cesu8_sz != utf8_sz); TEST_ASSERT (utf8_sz == 14 && cesu8_sz == 18); JERRY_VLA (char, test_string, utf8_sz); - TEST_ASSERT (jerry_string_to_utf8_char_buffer (args[0], (jerry_char_t *) test_string, utf8_sz) == 14); - TEST_ASSERT (!strncmp (test_string, "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4", utf8_sz)); - - sz = jerry_substring_to_utf8_char_buffer (args[0], 0, utf8_length, (jerry_char_t *) test_string, utf8_sz); - TEST_ASSERT (sz == 14); - TEST_ASSERT (!strncmp (test_string, "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4", sz)); - - sz = jerry_substring_to_utf8_char_buffer (args[0], 0, utf8_length + 1, (jerry_char_t *) test_string, utf8_sz); - TEST_ASSERT (sz == 14); - TEST_ASSERT (!strncmp (test_string, "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 \xf0\x9d\x94\xa4", sz)); - - sz = jerry_substring_to_utf8_char_buffer (args[0], utf8_length, 0, (jerry_char_t *) test_string, utf8_sz); - TEST_ASSERT (sz == 0); - - sz = jerry_substring_to_utf8_char_buffer (args[0], 0, utf8_length, (jerry_char_t *) test_string, utf8_sz - 1); - TEST_ASSERT (sz == 10); - TEST_ASSERT (!strncmp (test_string, "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 ", sz)); - - sz = jerry_substring_to_utf8_char_buffer (args[0], 0, utf8_length - 1, (jerry_char_t *) test_string, utf8_sz); - TEST_ASSERT (sz == 10); - TEST_ASSERT (!strncmp (test_string, "\x73\x74\x72\x3a \xf0\x9d\x94\xa3 ", sz)); - - sz = jerry_substring_to_utf8_char_buffer (args[0], - utf8_length - 2, - utf8_length - 1, - (jerry_char_t *) test_string, - utf8_sz); - TEST_ASSERT (sz == 1); - TEST_ASSERT (!strncmp (test_string, " ", sz)); - - sz = jerry_substring_to_utf8_char_buffer (args[0], - utf8_length - 3, - utf8_length - 2, - (jerry_char_t *) test_string, - utf8_sz); - TEST_ASSERT (sz == 4); - TEST_ASSERT (!strncmp (test_string, "\xf0\x9d\x94\xa3", sz)); + TEST_ASSERT (jerry_string_to_buffer (args[0], (jerry_char_t *) test_string, utf8_sz, JERRY_ENCODING_UTF8) == 14); + TEST_ASSERT (!strncmp (test_string, utf8_bytes_p, utf8_sz)); - jerry_release_value (args[0]); + jerry_value_free (args[0]); /* Test string: 'str: {DESERET CAPITAL LETTER LONG I}' */ - args[0] = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"); + cesu8_bytes_p = "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"; + args[0] = jerry_string ((jerry_char_t *) cesu8_bytes_p, (jerry_size_t) strlen (cesu8_bytes_p), JERRY_ENCODING_CESU8); - cesu8_length = jerry_get_string_length (args[0]); - utf8_length = jerry_get_utf8_string_length (args[0]); + cesu8_sz = jerry_string_size (args[0], JERRY_ENCODING_CESU8); + utf8_sz = jerry_string_size (args[0], JERRY_ENCODING_UTF8); - cesu8_sz = jerry_get_string_size (args[0]); - utf8_sz = jerry_get_utf8_string_size (args[0]); - - TEST_ASSERT (cesu8_length == 7 && utf8_length == 6); + TEST_ASSERT (jerry_string_length (args[0]) == 7); TEST_ASSERT (cesu8_sz != utf8_sz); TEST_ASSERT (utf8_sz == 9 && cesu8_sz == 11); - jerry_release_value (args[0]); + jerry_value_free (args[0]); /* Test string: 'price: 10{EURO SIGN}' */ - args[0] = jerry_create_string_from_utf8 ((jerry_char_t *) "\x70\x72\x69\x63\x65\x3a \x31\x30\xe2\x82\xac"); - - cesu8_length = jerry_get_string_length (args[0]); - utf8_length = jerry_get_utf8_string_length (args[0]); + utf8_bytes_p = "\x70\x72\x69\x63\x65\x3a \x31\x30\xe2\x82\xac"; + args[0] = jerry_string ((jerry_char_t *) utf8_bytes_p, (jerry_size_t) strlen (utf8_bytes_p), JERRY_ENCODING_UTF8); - cesu8_sz = jerry_get_string_size (args[0]); - utf8_sz = jerry_get_utf8_string_size (args[0]); + cesu8_sz = jerry_string_size (args[0], JERRY_ENCODING_CESU8); + utf8_sz = jerry_string_size (args[0], JERRY_ENCODING_UTF8); - TEST_ASSERT (cesu8_length == utf8_length); - TEST_ASSERT (cesu8_length == 10); + TEST_ASSERT (jerry_string_length (args[0]) == 10); TEST_ASSERT (cesu8_sz == utf8_sz); TEST_ASSERT (utf8_sz == 12); - jerry_release_value (args[0]); + jerry_value_free (args[0]); /* Test string: '3' */ { - jerry_value_t test_str = jerry_create_string ((const jerry_char_t *) "3"); + jerry_value_t test_str = jerry_string_sz ("3"); char result_string[1] = { 'E' }; jerry_size_t copied_utf8 = - jerry_substring_to_utf8_char_buffer (test_str, 0, 1, (jerry_char_t *) result_string, sizeof (result_string)); + jerry_string_to_buffer (test_str, (jerry_char_t *) result_string, sizeof (result_string), JERRY_ENCODING_UTF8); TEST_ASSERT (copied_utf8 == 1); TEST_ASSERT (result_string[0] == '3'); result_string[0] = 'E'; jerry_size_t copied = - jerry_substring_to_char_buffer (test_str, 0, 1, (jerry_char_t *) result_string, sizeof (result_string)); + jerry_string_to_buffer (test_str, (jerry_char_t *) result_string, sizeof (result_string), JERRY_ENCODING_CESU8); TEST_ASSERT (copied == 1); TEST_ASSERT (result_string[0] == '3'); - jerry_release_value (test_str); + jerry_value_free (test_str); } - /* Test jerry_substring_to_char_buffer */ - args[0] = jerry_create_string ((jerry_char_t *) "an ascii string"); - - /* Buffer size */ - cesu8_sz = 5; - - JERRY_VLA (char, substring, cesu8_sz); - sz = jerry_substring_to_char_buffer (args[0], 3, 8, (jerry_char_t *) substring, cesu8_sz); - TEST_ASSERT (sz == 5); - TEST_ASSERT (!strncmp (substring, "ascii", sz)); - - /* Buffer size is 5, substring length is 11 => copied only the first 5 char */ - sz = jerry_substring_to_char_buffer (args[0], 0, 11, (jerry_char_t *) substring, cesu8_sz); - - TEST_ASSERT (sz == 5); - TEST_ASSERT (!strncmp (substring, "an as", sz)); - - /* Position of the first character is greater than the string length */ - sz = jerry_substring_to_char_buffer (args[0], 16, 21, (jerry_char_t *) substring, cesu8_sz); - TEST_ASSERT (sz == 0); - - sz = jerry_substring_to_char_buffer (args[0], 14, 15, (jerry_char_t *) substring, cesu8_sz); - TEST_ASSERT (sz == 1); - TEST_ASSERT (!strncmp (substring, "g", sz)); - - sz = jerry_substring_to_char_buffer (args[0], 0, 1, (jerry_char_t *) substring, cesu8_sz); - TEST_ASSERT (sz == 1); - TEST_ASSERT (!strncmp (substring, "a", sz)); - - cesu8_length = jerry_get_string_length (args[0]); - cesu8_sz = jerry_get_string_size (args[0]); - TEST_ASSERT (cesu8_length == 15); - TEST_ASSERT (cesu8_length == cesu8_sz); - - JERRY_VLA (char, fullstring, cesu8_sz); - sz = jerry_substring_to_char_buffer (args[0], 0, cesu8_length, (jerry_char_t *) fullstring, cesu8_sz); - TEST_ASSERT (sz == 15); - TEST_ASSERT (!strncmp (fullstring, "an ascii string", sz)); - - jerry_release_value (args[0]); - - /* Test jerry_substring_to_char_buffer: '0101' */ - args[0] = jerry_create_string ((jerry_char_t *) "0101"); - cesu8_sz = jerry_get_string_size (args[0]); - - JERRY_VLA (char, number_substring, cesu8_sz); - - sz = jerry_substring_to_char_buffer (args[0], 1, 3, (jerry_char_t *) number_substring, cesu8_sz); - TEST_ASSERT (sz == 2); - TEST_ASSERT (!strncmp (number_substring, "10", sz)); - - jerry_release_value (args[0]); - - /* Test jerry_substring_to_char_buffer: 'str: {greek zero sign}' */ - args[0] = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x80\xed\xb6\x8a"); - cesu8_sz = jerry_get_string_size (args[0]); - cesu8_length = jerry_get_string_length (args[0]); - TEST_ASSERT (cesu8_sz == 11); - TEST_ASSERT (cesu8_length = 7); - - JERRY_VLA (char, supl_substring, cesu8_sz); - - sz = jerry_substring_to_char_buffer (args[0], 0, cesu8_length, (jerry_char_t *) supl_substring, cesu8_sz); - TEST_ASSERT (sz == 11); - TEST_ASSERT (!strncmp (supl_substring, "\x73\x74\x72\x3a \xed\xa0\x80\xed\xb6\x8a", sz)); - - /* Decrease the buffer size => the low surrogate char will not fit into the buffer */ - cesu8_sz -= 1; - sz = jerry_substring_to_char_buffer (args[0], 0, cesu8_length, (jerry_char_t *) supl_substring, cesu8_sz); - TEST_ASSERT (sz == 8); - TEST_ASSERT (!strncmp (supl_substring, "\x73\x74\x72\x3a \xed\xa0\x80", sz)); - - sz = - jerry_substring_to_char_buffer (args[0], cesu8_length - 1, cesu8_length, (jerry_char_t *) supl_substring, cesu8_sz); - TEST_ASSERT (sz == 3); - TEST_ASSERT (!strncmp (supl_substring, "\xed\xb6\x8a", sz)); - - sz = jerry_substring_to_char_buffer (args[0], - cesu8_length - 2, - cesu8_length - 1, - (jerry_char_t *) supl_substring, - cesu8_sz); - TEST_ASSERT (sz == 3); - TEST_ASSERT (!strncmp (supl_substring, "\xed\xa0\x80", sz)); - - jerry_release_value (args[0]); - jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-api-value-type.c b/tests/unit-core/test-api-value-type.c index 208cc888d7..9b2ec7f38a 100644 --- a/tests/unit-core/test-api-value-type.c +++ b/tests/unit-core/test-api-value-type.c @@ -38,7 +38,7 @@ test_ext_function (const jerry_call_info_t *call_info_p, /**< call information * (void) call_info_p; (void) args_p; (void) args_cnt; - return jerry_create_boolean (true); + return jerry_boolean (true); } /* test_ext_function */ int @@ -48,103 +48,104 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - const jerry_char_t test_eval_function[] = "function demo(a) { return a + 1; }; demo"; + const char test_eval_function[] = "function demo(a) { return a + 1; }; demo"; test_entry_t entries[] = { - ENTRY (JERRY_TYPE_NUMBER, jerry_create_number (-33.0)), - ENTRY (JERRY_TYPE_NUMBER, jerry_create_number (3)), - ENTRY (JERRY_TYPE_NUMBER, jerry_create_number_nan ()), - ENTRY (JERRY_TYPE_NUMBER, jerry_create_number_infinity (false)), - ENTRY (JERRY_TYPE_NUMBER, jerry_create_number_infinity (true)), + ENTRY (JERRY_TYPE_NUMBER, jerry_number (-33.0)), + ENTRY (JERRY_TYPE_NUMBER, jerry_number (3)), + ENTRY (JERRY_TYPE_NUMBER, jerry_nan ()), + ENTRY (JERRY_TYPE_NUMBER, jerry_infinity (false)), + ENTRY (JERRY_TYPE_NUMBER, jerry_infinity (true)), - ENTRY (JERRY_TYPE_BOOLEAN, jerry_create_boolean (true)), - ENTRY (JERRY_TYPE_BOOLEAN, jerry_create_boolean (false)), + ENTRY (JERRY_TYPE_BOOLEAN, jerry_boolean (true)), + ENTRY (JERRY_TYPE_BOOLEAN, jerry_boolean (false)), - ENTRY (JERRY_TYPE_UNDEFINED, jerry_create_undefined ()), + ENTRY (JERRY_TYPE_UNDEFINED, jerry_undefined ()), - ENTRY (JERRY_TYPE_OBJECT, jerry_create_object ()), - ENTRY (JERRY_TYPE_OBJECT, jerry_create_array (10)), - ENTRY (JERRY_TYPE_ERROR, jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error")), + ENTRY (JERRY_TYPE_OBJECT, jerry_object ()), + ENTRY (JERRY_TYPE_OBJECT, jerry_array (10)), + ENTRY (JERRY_TYPE_EXCEPTION, jerry_throw_sz (JERRY_ERROR_TYPE, "error")), - ENTRY (JERRY_TYPE_NULL, jerry_create_null ()), + ENTRY (JERRY_TYPE_NULL, jerry_null ()), - ENTRY (JERRY_TYPE_FUNCTION, jerry_eval (test_eval_function, sizeof (test_eval_function) - 1, JERRY_PARSE_NO_OPTS)), - ENTRY (JERRY_TYPE_FUNCTION, jerry_create_external_function (test_ext_function)), + ENTRY (JERRY_TYPE_FUNCTION, + jerry_eval ((jerry_char_t *) test_eval_function, sizeof (test_eval_function) - 1, JERRY_PARSE_NO_OPTS)), + ENTRY (JERRY_TYPE_FUNCTION, jerry_function_external (test_ext_function)), - ENTRY (JERRY_TYPE_STRING, jerry_create_string (test_eval_function)), - ENTRY (JERRY_TYPE_STRING, jerry_create_string ((jerry_char_t *) "")), + ENTRY (JERRY_TYPE_STRING, jerry_string_sz (test_eval_function)), + ENTRY (JERRY_TYPE_STRING, jerry_string_sz ("")), }; for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++) { - jerry_type_t type_info = jerry_value_get_type (entries[idx].value); + jerry_type_t type_info = jerry_value_type (entries[idx].value); TEST_ASSERT (type_info != JERRY_TYPE_NONE); TEST_ASSERT (type_info == entries[idx].type_info); - jerry_release_value (entries[idx].value); + jerry_value_free (entries[idx].value); } - if (jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { - jerry_value_t symbol_desc_value = jerry_create_string ((jerry_char_t *) "foo"); - jerry_value_t symbol_value = jerry_create_symbol (symbol_desc_value); - jerry_type_t type_info = jerry_value_get_type (symbol_value); + jerry_value_t symbol_desc_value = jerry_string_sz ("foo"); + jerry_value_t symbol_value = jerry_symbol_with_description (symbol_desc_value); + jerry_type_t type_info = jerry_value_type (symbol_value); TEST_ASSERT (type_info != JERRY_TYPE_NONE); TEST_ASSERT (type_info == JERRY_TYPE_SYMBOL); - jerry_release_value (symbol_value); - jerry_release_value (symbol_desc_value); + jerry_value_free (symbol_value); + jerry_value_free (symbol_desc_value); } - if (jerry_is_feature_enabled (JERRY_FEATURE_BIGINT)) + if (jerry_feature_enabled (JERRY_FEATURE_BIGINT)) { /* Check simple bigint value type */ uint64_t digits_buffer[2] = { 1, 0 }; - jerry_value_t value_bigint = jerry_create_bigint (digits_buffer, 2, false); - jerry_type_t value_type_info = jerry_value_get_type (value_bigint); + jerry_value_t value_bigint = jerry_bigint (digits_buffer, 2, false); + jerry_type_t value_type_info = jerry_value_type (value_bigint); TEST_ASSERT (value_type_info != JERRY_TYPE_NONE); TEST_ASSERT (value_type_info == JERRY_TYPE_BIGINT); - jerry_release_value (value_bigint); + jerry_value_free (value_bigint); /* Check bigint wrapped in object type */ jerry_char_t object_bigint_src[] = "Object(5n)"; jerry_value_t object_bigint = jerry_eval (object_bigint_src, sizeof (object_bigint_src) - 1, JERRY_PARSE_NO_OPTS); - TEST_ASSERT (!jerry_value_is_error (object_bigint)); + TEST_ASSERT (!jerry_value_is_exception (object_bigint)); - jerry_type_t object_type_info = jerry_value_get_type (object_bigint); + jerry_type_t object_type_info = jerry_value_type (object_bigint); TEST_ASSERT (object_type_info != JERRY_TYPE_NONE); TEST_ASSERT (object_type_info == JERRY_TYPE_OBJECT); - jerry_release_value (object_bigint); + jerry_value_free (object_bigint); } - if (jerry_is_feature_enabled (JERRY_FEATURE_REALM)) + if (jerry_feature_enabled (JERRY_FEATURE_REALM)) { - jerry_value_t new_realm = jerry_create_realm (); + jerry_value_t new_realm = jerry_realm (); jerry_value_t old_realm = jerry_set_realm (new_realm); - jerry_type_t new_realm_type = jerry_value_get_type (new_realm); + jerry_type_t new_realm_type = jerry_value_type (new_realm); TEST_ASSERT (new_realm_type == JERRY_TYPE_OBJECT); - jerry_value_t new_realm_this = jerry_realm_get_this (new_realm); - jerry_type_t new_realm_this_type = jerry_value_get_type (new_realm_this); + jerry_value_t new_realm_this = jerry_realm_this (new_realm); + jerry_type_t new_realm_this_type = jerry_value_type (new_realm_this); TEST_ASSERT (new_realm_this_type == JERRY_TYPE_OBJECT); - jerry_release_value (new_realm_this); + jerry_value_free (new_realm_this); - jerry_type_t old_realm_type = jerry_value_get_type (old_realm); + jerry_type_t old_realm_type = jerry_value_type (old_realm); TEST_ASSERT (old_realm_type == JERRY_TYPE_OBJECT); - jerry_release_value (new_realm); + jerry_value_free (new_realm); - jerry_value_t old_realm_this = jerry_realm_get_this (old_realm); - jerry_type_t old_realm_this_type = jerry_value_get_type (old_realm_this); + jerry_value_t old_realm_this = jerry_realm_this (old_realm); + jerry_type_t old_realm_this_type = jerry_value_type (old_realm_this); TEST_ASSERT (old_realm_this_type == JERRY_TYPE_OBJECT); - jerry_release_value (old_realm_this); + jerry_value_free (old_realm_this); /* Restore the old realm as per docs */ jerry_set_realm (old_realm); diff --git a/tests/unit-core/test-api.c b/tests/unit-core/test-api.c index 077a75b32a..ca85ecc9b6 100644 --- a/tests/unit-core/test-api.c +++ b/tests/unit-core/test-api.c @@ -77,15 +77,15 @@ handler (const jerry_call_info_t *call_info_p, /**< call information */ TEST_ASSERT (args_cnt == 2); TEST_ASSERT (jerry_value_is_string (args_p[0])); - sz = jerry_get_string_size (args_p[0]); + sz = jerry_string_size (args_p[0], JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 1); - sz = jerry_string_to_char_buffer (args_p[0], (jerry_char_t *) buffer, sz); + sz = jerry_string_to_buffer (args_p[0], (jerry_char_t *) buffer, sz, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 1); TEST_ASSERT (!strncmp (buffer, "1", (size_t) sz)); TEST_ASSERT (jerry_value_is_boolean (args_p[1])); - return jerry_create_string ((jerry_char_t *) "string from handler"); + return jerry_string_sz ("string from handler"); } /* handler */ static jerry_value_t @@ -99,7 +99,7 @@ handler_throw_test (const jerry_call_info_t *call_info_p, /**< call information (void *) args_p, (unsigned int) args_cnt); - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "error"); + return jerry_throw_sz (JERRY_ERROR_TYPE, "error"); } /* handler_throw_test */ static void @@ -134,7 +134,7 @@ handler_construct_2_freecb (void *native_p, /**< native pointer */ */ #define JERRY_DEFINE_NATIVE_HANDLE_INFO(c_type, native_free_cb) \ static const jerry_object_native_info_t JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (c_type) = { \ - .free_cb = (jerry_object_native_free_callback_t) native_free_cb, \ + .free_cb = (jerry_object_native_free_cb_t) native_free_cb, \ .number_of_references = 0, \ .offset_of_references = 0, \ } @@ -161,36 +161,34 @@ handler_construct (const jerry_call_info_t *call_info_p, /**< call information * TEST_ASSERT (jerry_value_is_true (args_p[0])); jerry_value_t this_value = call_info_p->this_value; - jerry_value_t field_name = jerry_create_string ((jerry_char_t *) "value_field"); - jerry_value_t res = jerry_set_property (this_value, field_name, args_p[0]); - TEST_ASSERT (!jerry_value_is_error (res)); + jerry_value_t field_name = jerry_string_sz ("value_field"); + jerry_value_t res = jerry_object_set (this_value, field_name, args_p[0]); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); - jerry_release_value (field_name); + jerry_value_free (res); + jerry_value_free (field_name); /* Set a native pointer. */ - jerry_set_object_native_pointer (this_value, - (void *) 0x0000000000000000ull, - &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1)); + jerry_object_set_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1), NULL); /* Check that the native pointer was set. */ - void *ptr = NULL; - bool is_ok = jerry_get_object_native_pointer (this_value, &ptr, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1)); - TEST_ASSERT (is_ok && (uintptr_t) ptr == (uintptr_t) 0x0000000000000000ull); + TEST_ASSERT (jerry_object_has_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1))); + void *ptr = jerry_object_get_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1)); + TEST_ASSERT (ptr == NULL); /* Set a second native pointer. */ - jerry_set_object_native_pointer (this_value, - (void *) 0x0012345678abcdefull, - &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2)); + jerry_object_set_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2), (void *) 0x0012345678abcdefull); /* Check that a second native pointer was set. */ - is_ok = jerry_get_object_native_pointer (this_value, &ptr, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2)); - TEST_ASSERT (is_ok && (uintptr_t) ptr == (uintptr_t) 0x0012345678abcdefull); + TEST_ASSERT (jerry_object_has_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2))); + ptr = jerry_object_get_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2)); + TEST_ASSERT ((uintptr_t) ptr == (uintptr_t) 0x0012345678abcdefull); /* Check that the first native pointer is still set. */ - is_ok = jerry_get_object_native_pointer (this_value, &ptr, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1)); - TEST_ASSERT (is_ok && (uintptr_t) ptr == (uintptr_t) 0x0000000000000000ull); - return jerry_create_boolean (true); + TEST_ASSERT (jerry_object_has_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1))); + ptr = jerry_object_get_native_ptr (this_value, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1)); + TEST_ASSERT (ptr == NULL); + return jerry_boolean (true); } /* handler_construct */ /** @@ -228,7 +226,8 @@ static bool foreach (const jerry_value_t name, /**< field name */ void *user_data) /**< user data */ { char str_buf_p[128]; - jerry_size_t sz = jerry_string_to_char_buffer (name, (jerry_char_t *) str_buf_p, 128); + jerry_size_t sz = + jerry_string_to_buffer (name, (jerry_char_t *) str_buf_p, sizeof (str_buf_p) - 1, JERRY_ENCODING_CESU8); str_buf_p[sz] = '\0'; TEST_ASSERT (!strncmp ((const char *) user_data, "user_data", 9)); @@ -237,7 +236,7 @@ static bool foreach (const jerry_value_t name, /**< field name */ if (!strncmp (str_buf_p, "alpha", (size_t) sz)) { TEST_ASSERT (jerry_value_is_number (value)); - TEST_ASSERT (jerry_get_number_value (value) == 32.0); + TEST_ASSERT (jerry_value_as_number (value) == 32.0); return true; } else if (!strncmp (str_buf_p, "bravo", (size_t) sz)) @@ -255,13 +254,14 @@ static bool foreach (const jerry_value_t name, /**< field name */ else if (!strncmp (str_buf_p, "delta", (size_t) sz)) { TEST_ASSERT (jerry_value_is_number (value)); - TEST_ASSERT (jerry_get_number_value (value) == 123.45); + TEST_ASSERT (jerry_value_as_number (value) == 123.45); return true; } else if (!strncmp (str_buf_p, "echo", (size_t) sz)) { TEST_ASSERT (jerry_value_is_string (value)); - jerry_size_t echo_sz = jerry_string_to_char_buffer (value, (jerry_char_t *) str_buf_p, 128); + jerry_size_t echo_sz = + jerry_string_to_buffer (value, (jerry_char_t *) str_buf_p, sizeof (str_buf_p) - 1, JERRY_ENCODING_CESU8); str_buf_p[echo_sz] = '\0'; TEST_ASSERT (!strncmp (str_buf_p, "foobar", (size_t) echo_sz)); return true; @@ -279,7 +279,8 @@ foreach_exception (const jerry_value_t name, /**< field name */ JERRY_UNUSED (value); JERRY_UNUSED (user_data); char str_buf_p[128]; - jerry_size_t sz = jerry_string_to_char_buffer (name, (jerry_char_t *) str_buf_p, 128); + jerry_size_t sz = + jerry_string_to_buffer (name, (jerry_char_t *) str_buf_p, sizeof (str_buf_p) - 1, JERRY_ENCODING_CESU8); str_buf_p[sz] = '\0'; if (!strncmp (str_buf_p, "foxtrot", (size_t) sz)) @@ -311,9 +312,9 @@ static jerry_value_t get_property (const jerry_value_t obj_val, /**< object value */ const char *str_p) /**< property name */ { - jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) str_p); - jerry_value_t ret_val = jerry_get_property (obj_val, prop_name_val); - jerry_release_value (prop_name_val); + jerry_value_t prop_name_val = jerry_string_sz (str_p); + jerry_value_t ret_val = jerry_object_get (obj_val, prop_name_val); + jerry_value_free (prop_name_val); return ret_val; } /* get_property */ @@ -322,20 +323,12 @@ set_property (const jerry_value_t obj_val, /**< object value */ const char *str_p, /**< property name */ const jerry_value_t val) /**< value to set */ { - jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) str_p); - jerry_value_t ret_val = jerry_set_property (obj_val, prop_name_val, val); - jerry_release_value (prop_name_val); + jerry_value_t prop_name_val = jerry_string_sz (str_p); + jerry_value_t ret_val = jerry_object_set (obj_val, prop_name_val, val); + jerry_value_free (prop_name_val); return ret_val; } /* set_property */ -static bool -test_run_simple (const char *script_p) /**< source code to run */ -{ - size_t script_size = strlen (script_p); - - return jerry_run_simple ((const jerry_char_t *) script_p, script_size, JERRY_INIT_EMPTY); -} /* test_run_simple */ - static void test_syntax_error (const char *script_p, /**< source code to run */ const jerry_parse_options_t *options_p, /**< additional parsing options */ @@ -346,27 +339,27 @@ test_syntax_error (const char *script_p, /**< source code to run */ if (run_script) { - TEST_ASSERT (!jerry_value_is_error (result_val)); + TEST_ASSERT (!jerry_value_is_exception (result_val)); jerry_value_t script_val = result_val; result_val = jerry_run (script_val); - jerry_release_value (script_val); + jerry_value_free (script_val); } - TEST_ASSERT (jerry_value_is_error (result_val)); - result_val = jerry_get_value_from_error (result_val, true); + TEST_ASSERT (jerry_value_is_exception (result_val)); + result_val = jerry_exception_value (result_val, true); jerry_value_t err_str_val = jerry_value_to_string (result_val); - jerry_size_t err_str_size = jerry_get_string_size (err_str_val); + jerry_size_t err_str_size = jerry_string_size (err_str_val, JERRY_ENCODING_CESU8); jerry_char_t err_str_buf[256]; TEST_ASSERT (err_str_size <= sizeof (err_str_buf)); TEST_ASSERT (err_str_size == strlen (error_message_p)); - TEST_ASSERT (jerry_string_to_char_buffer (err_str_val, err_str_buf, err_str_size) == err_str_size); + TEST_ASSERT (jerry_string_to_buffer (err_str_val, err_str_buf, err_str_size, JERRY_ENCODING_CESU8) == err_str_size); - jerry_release_value (err_str_val); - jerry_release_value (result_val); + jerry_value_free (err_str_val); + jerry_value_free (result_val); TEST_ASSERT (memcmp ((char *) err_str_buf, error_message_p, err_str_size) == 0); } /* test_syntax_error */ @@ -388,622 +381,623 @@ main (void) double number_val; char buffer[32]; - is_ok = test_run_simple ("throw 'Hello World';"); - TEST_ASSERT (!is_ok); - jerry_init (JERRY_INIT_EMPTY); parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (res); + jerry_value_free (parsed_code_val); - global_obj_val = jerry_get_global_object (); + global_obj_val = jerry_current_realm (); /* Get global.boo (non-existing field) */ val_t = get_property (global_obj_val, "boo"); - TEST_ASSERT (!jerry_value_is_error (val_t)); + TEST_ASSERT (!jerry_value_is_exception (val_t)); TEST_ASSERT (jerry_value_is_undefined (val_t)); /* Get global.t */ val_t = get_property (global_obj_val, "t"); - TEST_ASSERT (!jerry_value_is_error (val_t)); - TEST_ASSERT (jerry_value_is_number (val_t) && jerry_get_number_value (val_t) == 1.0); - jerry_release_value (val_t); + TEST_ASSERT (!jerry_value_is_exception (val_t)); + TEST_ASSERT (jerry_value_is_number (val_t) && jerry_value_as_number (val_t) == 1.0); + jerry_value_free (val_t); /* Get global.foo */ val_foo = get_property (global_obj_val, "foo"); - TEST_ASSERT (!jerry_value_is_error (val_foo)); + TEST_ASSERT (!jerry_value_is_exception (val_foo)); TEST_ASSERT (jerry_value_is_object (val_foo)); /* Call foo (4, 2) */ - args[0] = jerry_create_number (4); - args[1] = jerry_create_number (2); - res = jerry_call_function (val_foo, jerry_create_undefined (), args, 2); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_value_is_number (res) && jerry_get_number_value (res) == 1.0); - jerry_release_value (res); + args[0] = jerry_number (4); + args[1] = jerry_number (2); + res = jerry_call (val_foo, jerry_undefined (), args, 2); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_is_number (res) && jerry_value_as_number (res) == 1.0); + jerry_value_free (res); /* Get global.bar */ val_bar = get_property (global_obj_val, "bar"); - TEST_ASSERT (!jerry_value_is_error (val_bar)); + TEST_ASSERT (!jerry_value_is_exception (val_bar)); TEST_ASSERT (jerry_value_is_object (val_bar)); /* Call bar (4, 2) */ - res = jerry_call_function (val_bar, jerry_create_undefined (), args, 2); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_value_is_number (res) && jerry_get_number_value (res) == 5.0); - jerry_release_value (res); - jerry_release_value (val_bar); + res = jerry_call (val_bar, jerry_undefined (), args, 2); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_is_number (res) && jerry_value_as_number (res) == 5.0); + jerry_value_free (res); + jerry_value_free (val_bar); /* Set global.t = "abcd" */ - jerry_release_value (args[0]); - args[0] = jerry_create_string ((jerry_char_t *) "abcd"); + jerry_value_free (args[0]); + args[0] = jerry_string_sz ("abcd"); res = set_property (global_obj_val, "t", args[0]); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); + jerry_value_free (res); /* Call foo (4, 2) */ - res = jerry_call_function (val_foo, jerry_create_undefined (), args, 2); - TEST_ASSERT (!jerry_value_is_error (res)); + res = jerry_call (val_foo, jerry_undefined (), args, 2); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_string (res)); - sz = jerry_get_string_size (res); + sz = jerry_string_size (res, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 4); - sz = jerry_string_to_char_buffer (res, (jerry_char_t *) buffer, sz); + sz = jerry_string_to_buffer (res, (jerry_char_t *) buffer, sz, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 4); - jerry_release_value (res); + jerry_value_free (res); TEST_ASSERT (!strncmp (buffer, "abcd", (size_t) sz)); - jerry_release_value (args[0]); - jerry_release_value (args[1]); + jerry_value_free (args[0]); + jerry_value_free (args[1]); /* Get global.A */ val_A = get_property (global_obj_val, "A"); - TEST_ASSERT (!jerry_value_is_error (val_A)); + TEST_ASSERT (!jerry_value_is_exception (val_A)); TEST_ASSERT (jerry_value_is_object (val_A)); /* Get A.prototype */ is_ok = jerry_value_is_constructor (val_A); TEST_ASSERT (is_ok); val_A_prototype = get_property (val_A, "prototype"); - TEST_ASSERT (!jerry_value_is_error (val_A_prototype)); + TEST_ASSERT (!jerry_value_is_exception (val_A_prototype)); TEST_ASSERT (jerry_value_is_object (val_A_prototype)); - jerry_release_value (val_A); + jerry_value_free (val_A); /* Set A.prototype.foo = global.foo */ res = set_property (val_A_prototype, "foo", val_foo); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); - jerry_release_value (val_A_prototype); - jerry_release_value (val_foo); + jerry_value_free (res); + jerry_value_free (val_A_prototype); + jerry_value_free (val_foo); /* Get global.a */ val_a = get_property (global_obj_val, "a"); - TEST_ASSERT (!jerry_value_is_error (val_a)); + TEST_ASSERT (!jerry_value_is_exception (val_a)); TEST_ASSERT (jerry_value_is_object (val_a)); /* Get a.t */ res = get_property (val_a, "t"); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_value_is_number (res) && jerry_get_number_value (res) == 12.0); - jerry_release_value (res); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_is_number (res) && jerry_value_as_number (res) == 12.0); + jerry_value_free (res); /* foreach properties */ val_p = get_property (global_obj_val, "p"); - is_ok = jerry_foreach_object_property (val_p, foreach, (void *) "user_data"); + is_ok = jerry_object_foreach (val_p, foreach, (void *) "user_data"); TEST_ASSERT (is_ok); /* break foreach at third element */ int count = 0; - is_ok = jerry_foreach_object_property (val_p, foreach_subset, &count); + is_ok = jerry_object_foreach (val_p, foreach_subset, &count); TEST_ASSERT (is_ok); TEST_ASSERT (count == 3); - jerry_release_value (val_p); + jerry_value_free (val_p); /* foreach with throw test */ val_np = get_property (global_obj_val, "np"); - is_ok = !jerry_foreach_object_property (val_np, foreach_exception, NULL); + is_ok = !jerry_object_foreach (val_np, foreach_exception, NULL); TEST_ASSERT (is_ok); - jerry_release_value (val_np); + jerry_value_free (val_np); /* Get a.foo */ val_a_foo = get_property (val_a, "foo"); - TEST_ASSERT (!jerry_value_is_error (val_a_foo)); + TEST_ASSERT (!jerry_value_is_exception (val_a_foo)); TEST_ASSERT (jerry_value_is_object (val_a_foo)); /* Call a.foo () */ - res = jerry_call_function (val_a_foo, val_a, NULL, 0); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_value_is_number (res) && jerry_get_number_value (res) == 12.0); - jerry_release_value (res); - jerry_release_value (val_a_foo); + res = jerry_call (val_a_foo, val_a, NULL, 0); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_is_number (res) && jerry_value_as_number (res) == 12.0); + jerry_value_free (res); + jerry_value_free (val_a_foo); - jerry_release_value (val_a); + jerry_value_free (val_a); /* Create native handler bound function object and set it to 'external' variable */ - external_func_val = jerry_create_external_function (handler); + external_func_val = jerry_function_external (handler); TEST_ASSERT (jerry_value_is_function (external_func_val) && jerry_value_is_constructor (external_func_val)); res = set_property (global_obj_val, "external", external_func_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (external_func_val); + jerry_value_free (external_func_val); /* Call 'call_external' function that should call external function created above */ val_call_external = get_property (global_obj_val, "call_external"); - TEST_ASSERT (!jerry_value_is_error (val_call_external)); + TEST_ASSERT (!jerry_value_is_exception (val_call_external)); TEST_ASSERT (jerry_value_is_object (val_call_external)); - res = jerry_call_function (val_call_external, global_obj_val, NULL, 0); - jerry_release_value (val_call_external); - TEST_ASSERT (!jerry_value_is_error (res)); + res = jerry_call (val_call_external, global_obj_val, NULL, 0); + jerry_value_free (val_call_external); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_string (res)); - sz = jerry_get_string_size (res); + sz = jerry_string_size (res, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 19); - sz = jerry_string_to_char_buffer (res, (jerry_char_t *) buffer, sz); + sz = jerry_string_to_buffer (res, (jerry_char_t *) buffer, sz, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 19); - jerry_release_value (res); + jerry_value_free (res); TEST_ASSERT (!strncmp (buffer, "string from handler", (size_t) sz)); /* Create native handler bound function object and set it to 'external_construct' variable */ - external_construct_val = jerry_create_external_function (handler_construct); + external_construct_val = jerry_function_external (handler_construct); TEST_ASSERT (jerry_value_is_function (external_construct_val) && jerry_value_is_constructor (external_construct_val)); res = set_property (global_obj_val, "external_construct", external_construct_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); + jerry_value_free (res); /* Call external function created above, as constructor */ - args[0] = jerry_create_boolean (true); - res = jerry_construct_object (external_construct_val, args, 1); - TEST_ASSERT (!jerry_value_is_error (res)); + args[0] = jerry_boolean (true); + res = jerry_construct (external_construct_val, args, 1); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_object (res)); val_value_field = get_property (res, "value_field"); /* Get 'value_field' of constructed object */ - TEST_ASSERT (!jerry_value_is_error (val_value_field)); + TEST_ASSERT (!jerry_value_is_exception (val_value_field)); TEST_ASSERT (jerry_value_is_boolean (val_value_field) && jerry_value_is_true (val_value_field)); - jerry_release_value (val_value_field); - jerry_release_value (external_construct_val); + jerry_value_free (val_value_field); + jerry_value_free (external_construct_val); - void *ptr = NULL; - is_ok = jerry_get_object_native_pointer (res, &ptr, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2)); - TEST_ASSERT (is_ok && (uintptr_t) ptr == (uintptr_t) 0x0012345678abcdefull); + TEST_ASSERT (jerry_object_has_native_ptr (res, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2))); + void *ptr = jerry_object_get_native_ptr (res, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2)); + TEST_ASSERT ((uintptr_t) ptr == (uintptr_t) 0x0012345678abcdefull); /* Passing NULL for info_p is allowed. */ - is_ok = jerry_get_object_native_pointer (res, &ptr, NULL); - TEST_ASSERT (!is_ok); + TEST_ASSERT (!jerry_object_has_native_ptr (res, NULL)); + jerry_object_set_native_ptr (res, NULL, (void *) 0x0012345678abcdefull); + + TEST_ASSERT (jerry_object_has_native_ptr (res, NULL)); + ptr = jerry_object_get_native_ptr (res, NULL); + TEST_ASSERT ((uintptr_t) ptr == (uintptr_t) 0x0012345678abcdefull); - jerry_release_value (res); + jerry_value_free (res); /* Test: It is ok to set native pointer's free callback as NULL. */ - jerry_value_t obj_freecb = jerry_create_object (); - jerry_set_object_native_pointer (obj_freecb, (void *) 0x1234, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind3)); + jerry_value_t obj_freecb = jerry_object (); + jerry_object_set_native_ptr (obj_freecb, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind3), (void *) 0x1234); - jerry_release_value (obj_freecb); + jerry_value_free (obj_freecb); /* Test: Throwing exception from native handler. */ - throw_test_handler_val = jerry_create_external_function (handler_throw_test); + throw_test_handler_val = jerry_function_external (handler_throw_test); TEST_ASSERT (jerry_value_is_function (throw_test_handler_val)); res = set_property (global_obj_val, "throw_test", throw_test_handler_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); - jerry_release_value (throw_test_handler_val); + jerry_value_free (res); + jerry_value_free (throw_test_handler_val); val_t = get_property (global_obj_val, "call_throw_test"); - TEST_ASSERT (!jerry_value_is_error (val_t)); + TEST_ASSERT (!jerry_value_is_exception (val_t)); TEST_ASSERT (jerry_value_is_object (val_t)); - res = jerry_call_function (val_t, global_obj_val, NULL, 0); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (val_t); - jerry_release_value (res); + res = jerry_call (val_t, global_obj_val, NULL, 0); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (val_t); + jerry_value_free (res); /* Test: Unhandled exception in called function */ val_t = get_property (global_obj_val, "throw_reference_error"); - TEST_ASSERT (!jerry_value_is_error (val_t)); + TEST_ASSERT (!jerry_value_is_exception (val_t)); TEST_ASSERT (jerry_value_is_object (val_t)); - res = jerry_call_function (val_t, global_obj_val, NULL, 0); + res = jerry_call (val_t, global_obj_val, NULL, 0); - TEST_ASSERT (jerry_value_is_error (res)); - jerry_release_value (val_t); + TEST_ASSERT (jerry_value_is_exception (res)); + jerry_value_free (val_t); /* 'res' should contain exception object */ - res = jerry_get_value_from_error (res, true); + res = jerry_exception_value (res, true); TEST_ASSERT (jerry_value_is_object (res)); - jerry_release_value (res); + jerry_value_free (res); /* Test: Call of non-function */ - obj_val = jerry_create_object (); - res = jerry_call_function (obj_val, global_obj_val, NULL, 0); - TEST_ASSERT (jerry_value_is_error (res)); + obj_val = jerry_object (); + res = jerry_call (obj_val, global_obj_val, NULL, 0); + TEST_ASSERT (jerry_value_is_exception (res)); /* 'res' should contain exception object */ - res = jerry_get_value_from_error (res, true); + res = jerry_exception_value (res, true); TEST_ASSERT (jerry_value_is_object (res)); - jerry_release_value (res); + jerry_value_free (res); - jerry_release_value (obj_val); + jerry_value_free (obj_val); /* Test: Unhandled exception in function called, as constructor */ val_t = get_property (global_obj_val, "throw_reference_error"); - TEST_ASSERT (!jerry_value_is_error (val_t)); + TEST_ASSERT (!jerry_value_is_exception (val_t)); TEST_ASSERT (jerry_value_is_object (val_t)); - res = jerry_construct_object (val_t, NULL, 0); - TEST_ASSERT (jerry_value_is_error (res)); - jerry_release_value (val_t); + res = jerry_construct (val_t, NULL, 0); + TEST_ASSERT (jerry_value_is_exception (res)); + jerry_value_free (val_t); /* 'res' should contain exception object */ - res = jerry_get_value_from_error (res, true); + res = jerry_exception_value (res, true); TEST_ASSERT (jerry_value_is_object (res)); - jerry_release_value (res); + jerry_value_free (res); /* Test: Call of non-function as constructor */ - obj_val = jerry_create_object (); - res = jerry_construct_object (obj_val, NULL, 0); - TEST_ASSERT (jerry_value_is_error (res)); + obj_val = jerry_object (); + res = jerry_construct (obj_val, NULL, 0); + TEST_ASSERT (jerry_value_is_exception (res)); /* 'res' should contain exception object */ - res = jerry_get_value_from_error (res, true); + res = jerry_exception_value (res, true); TEST_ASSERT (jerry_value_is_object (res)); - jerry_release_value (res); + jerry_value_free (res); - jerry_release_value (obj_val); + jerry_value_free (obj_val); /* Test: Array Object API */ - jerry_value_t array_obj_val = jerry_create_array (10); + jerry_value_t array_obj_val = jerry_array (10); TEST_ASSERT (jerry_value_is_array (array_obj_val)); - TEST_ASSERT (jerry_get_array_length (array_obj_val) == 10); + TEST_ASSERT (jerry_array_length (array_obj_val) == 10); - jerry_value_t v_in = jerry_create_number (10.5); - res = jerry_set_property_by_index (array_obj_val, 5, v_in); - TEST_ASSERT (!jerry_value_is_error (res)); + jerry_value_t v_in = jerry_number (10.5); + res = jerry_object_set_index (array_obj_val, 5, v_in); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res) && jerry_value_is_true (res)); - jerry_release_value (res); - jerry_value_t v_out = jerry_get_property_by_index (array_obj_val, 5); + jerry_value_free (res); + jerry_value_t v_out = jerry_object_get_index (array_obj_val, 5); - TEST_ASSERT (jerry_value_is_number (v_out) && jerry_get_number_value (v_out) == 10.5); + TEST_ASSERT (jerry_value_is_number (v_out) && jerry_value_as_number (v_out) == 10.5); - jerry_delete_property_by_index (array_obj_val, 5); - jerry_value_t v_und = jerry_get_property_by_index (array_obj_val, 5); + jerry_object_delete_index (array_obj_val, 5); + jerry_value_t v_und = jerry_object_get_index (array_obj_val, 5); TEST_ASSERT (jerry_value_is_undefined (v_und)); - jerry_release_value (v_in); - jerry_release_value (v_out); - jerry_release_value (v_und); - jerry_release_value (array_obj_val); + jerry_value_free (v_in); + jerry_value_free (v_out); + jerry_value_free (v_und); + jerry_value_free (array_obj_val); /* Test: object keys */ - res = jerry_get_object_keys (global_obj_val); - TEST_ASSERT (!jerry_value_is_error (res)); + res = jerry_object_keys (global_obj_val); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_array (res)); - TEST_ASSERT (jerry_get_array_length (res) == 15); - jerry_release_value (res); + TEST_ASSERT (jerry_array_length (res) == 15); + jerry_value_free (res); /* Test: jerry_value_to_primitive */ obj_val = jerry_eval ((jerry_char_t *) "new String ('hello')", 20, JERRY_PARSE_NO_OPTS); - TEST_ASSERT (!jerry_value_is_error (obj_val)); + TEST_ASSERT (!jerry_value_is_exception (obj_val)); TEST_ASSERT (jerry_value_is_object (obj_val)); TEST_ASSERT (!jerry_value_is_string (obj_val)); prim_val = jerry_value_to_primitive (obj_val); - TEST_ASSERT (!jerry_value_is_error (prim_val)); + TEST_ASSERT (!jerry_value_is_exception (prim_val)); TEST_ASSERT (jerry_value_is_string (prim_val)); - jerry_release_value (prim_val); + jerry_value_free (prim_val); - /* Test: jerry_get_prototype */ - proto_val = jerry_get_prototype (jerry_create_undefined ()); - TEST_ASSERT (jerry_value_is_error (proto_val)); - jerry_value_t error = jerry_get_value_from_error (proto_val, true); - TEST_ASSERT (jerry_get_error_type (error) == JERRY_ERROR_TYPE); - jerry_release_value (error); + /* Test: jerry_object_proto */ + proto_val = jerry_object_proto (jerry_undefined ()); + TEST_ASSERT (jerry_value_is_exception (proto_val)); + jerry_value_t error = jerry_exception_value (proto_val, true); + TEST_ASSERT (jerry_error_type (error) == JERRY_ERROR_TYPE); + jerry_value_free (error); - proto_val = jerry_get_prototype (obj_val); - TEST_ASSERT (!jerry_value_is_error (proto_val)); + proto_val = jerry_object_proto (obj_val); + TEST_ASSERT (!jerry_value_is_exception (proto_val)); TEST_ASSERT (jerry_value_is_object (proto_val)); - jerry_release_value (proto_val); - jerry_release_value (obj_val); + jerry_value_free (proto_val); + jerry_value_free (obj_val); - if (jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (jerry_feature_enabled (JERRY_FEATURE_PROXY)) { - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); jerry_value_t obj_proto = jerry_eval ((jerry_char_t *) "Object.prototype", 16, JERRY_PARSE_NO_OPTS); - jerry_release_value (target); - jerry_release_value (handler); - proto_val = jerry_get_prototype (proxy); - TEST_ASSERT (!jerry_value_is_error (proto_val)); + jerry_value_free (target); + jerry_value_free (handler); + proto_val = jerry_object_proto (proxy); + TEST_ASSERT (!jerry_value_is_exception (proto_val)); TEST_ASSERT (proto_val == obj_proto); - jerry_release_value (proto_val); - jerry_release_value (obj_proto); - jerry_release_value (proxy); + jerry_value_free (proto_val); + jerry_value_free (obj_proto); + jerry_value_free (proxy); } - /* Test: jerry_set_prototype */ - obj_val = jerry_create_object (); - res = jerry_set_prototype (obj_val, jerry_create_null ()); - TEST_ASSERT (!jerry_value_is_error (res)); + /* Test: jerry_object_set_proto */ + obj_val = jerry_object (); + res = jerry_object_set_proto (obj_val, jerry_null ()); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_value_t new_proto = jerry_create_object (); - res = jerry_set_prototype (obj_val, new_proto); - jerry_release_value (new_proto); - TEST_ASSERT (!jerry_value_is_error (res)); + jerry_value_t new_proto = jerry_object (); + res = jerry_object_set_proto (obj_val, new_proto); + jerry_value_free (new_proto); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res)); TEST_ASSERT (jerry_value_is_true (res)); - proto_val = jerry_get_prototype (obj_val); - TEST_ASSERT (!jerry_value_is_error (proto_val)); + proto_val = jerry_object_proto (obj_val); + TEST_ASSERT (!jerry_value_is_exception (proto_val)); TEST_ASSERT (jerry_value_is_object (proto_val)); - jerry_release_value (proto_val); - jerry_release_value (obj_val); + jerry_value_free (proto_val); + jerry_value_free (obj_val); - if (jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (jerry_feature_enabled (JERRY_FEATURE_PROXY)) { - jerry_value_t target = jerry_create_object (); - jerry_value_t handler = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t handler = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); new_proto = jerry_eval ((jerry_char_t *) "Function.prototype", 18, JERRY_PARSE_NO_OPTS); - res = jerry_set_prototype (proxy, new_proto); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_value_t target_proto = jerry_get_prototype (target); + res = jerry_object_set_proto (proxy, new_proto); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_t target_proto = jerry_object_proto (target); TEST_ASSERT (target_proto == new_proto); - jerry_release_value (target); - jerry_release_value (handler); - jerry_release_value (proxy); - jerry_release_value (new_proto); - jerry_release_value (target_proto); + jerry_value_free (target); + jerry_value_free (handler); + jerry_value_free (proxy); + jerry_value_free (new_proto); + jerry_value_free (target_proto); } /* Test: eval */ const jerry_char_t eval_code_src1[] = "(function () { return 123; })"; val_t = jerry_eval (eval_code_src1, sizeof (eval_code_src1) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (val_t)); + TEST_ASSERT (!jerry_value_is_exception (val_t)); TEST_ASSERT (jerry_value_is_object (val_t)); TEST_ASSERT (jerry_value_is_function (val_t)); - res = jerry_call_function (val_t, jerry_create_undefined (), NULL, 0); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_value_is_number (res) && jerry_get_number_value (res) == 123.0); - jerry_release_value (res); + res = jerry_call (val_t, jerry_undefined (), NULL, 0); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_is_number (res) && jerry_value_as_number (res) == 123.0); + jerry_value_free (res); - jerry_release_value (val_t); + jerry_value_free (val_t); /* cleanup. */ - jerry_release_value (global_obj_val); + jerry_value_free (global_obj_val); /* Test: run gc. */ - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); /* Test: spaces */ const jerry_char_t eval_code_src2[] = "\x0a \x0b \x0c \xc2\xa0 \xe2\x80\xa8 \xe2\x80\xa9 \xef\xbb\xbf 4321"; val_t = jerry_eval (eval_code_src2, sizeof (eval_code_src2) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (val_t)); - TEST_ASSERT (jerry_value_is_number (val_t) && jerry_get_number_value (val_t) == 4321.0); - jerry_release_value (val_t); + TEST_ASSERT (!jerry_value_is_exception (val_t)); + TEST_ASSERT (jerry_value_is_number (val_t) && jerry_value_as_number (val_t) == 4321.0); + jerry_value_free (val_t); /* Test: number */ - val_t = jerry_create_number (6.25); - number_val = jerry_get_number_value (val_t); + val_t = jerry_number (6.25); + number_val = jerry_value_as_number (val_t); TEST_ASSERT (number_val * 3 == 18.75); - jerry_release_value (val_t); + jerry_value_free (val_t); - val_t = jerry_create_number_infinity (true); - number_val = jerry_get_number_value (val_t); + val_t = jerry_infinity (true); + number_val = jerry_value_as_number (val_t); TEST_ASSERT (number_val * 3 == number_val && number_val != 0.0); - jerry_release_value (val_t); + jerry_value_free (val_t); - val_t = jerry_create_number_nan (); - number_val = jerry_get_number_value (val_t); + val_t = jerry_nan (); + number_val = jerry_value_as_number (val_t); TEST_ASSERT (number_val != number_val); - jerry_release_value (val_t); + jerry_value_free (val_t); /* Test: create function */ - jerry_value_t script_source = jerry_create_string ((const jerry_char_t *) " return 5 + a+\nb+c"); + jerry_value_t script_source = jerry_string_sz (" return 5 + a+\nb+c"); jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "a , b,c"); + parse_options.argument_list = jerry_string_sz ("a , b,c"); jerry_value_t func_val = jerry_parse_value (script_source, &parse_options); - TEST_ASSERT (!jerry_value_is_error (func_val)); + TEST_ASSERT (!jerry_value_is_exception (func_val)); - jerry_release_value (parse_options.argument_list); - jerry_release_value (script_source); + jerry_value_free (parse_options.argument_list); + jerry_value_free (script_source); - jerry_value_t func_args[3] = { jerry_create_number (4), jerry_create_number (6), jerry_create_number (-2) }; + jerry_value_t func_args[3] = { jerry_number (4), jerry_number (6), jerry_number (-2) }; - val_t = jerry_call_function (func_val, func_args[0], func_args, 3); - number_val = jerry_get_number_value (val_t); + val_t = jerry_call (func_val, func_args[0], func_args, 3); + number_val = jerry_value_as_number (val_t); TEST_ASSERT (number_val == 13.0); - jerry_release_value (val_t); - jerry_release_value (func_val); + jerry_value_free (val_t); + jerry_value_free (func_val); parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_null (); + parse_options.argument_list = jerry_null (); func_val = jerry_parse ((const jerry_char_t *) "", 0, &parse_options); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_options.argument_list); - TEST_ASSERT (jerry_value_is_error (func_val) && jerry_get_error_type (func_val) == JERRY_ERROR_TYPE); - jerry_release_value (func_val); + TEST_ASSERT (jerry_value_is_exception (func_val) && jerry_error_type (func_val) == JERRY_ERROR_TYPE); + jerry_value_free (func_val); - script_source = jerry_create_number (4.5); + script_source = jerry_number (4.5); func_val = jerry_parse_value (script_source, NULL); - jerry_release_value (script_source); + jerry_value_free (script_source); - TEST_ASSERT (jerry_value_is_error (func_val) && jerry_get_error_type (func_val) == JERRY_ERROR_TYPE); - jerry_release_value (func_val); + TEST_ASSERT (jerry_value_is_exception (func_val) && jerry_error_type (func_val) == JERRY_ERROR_TYPE); + jerry_value_free (func_val); jerry_cleanup (); TEST_ASSERT (test_api_is_free_callback_was_called); - /* Test: jerry_get_value_from_error */ + /* Test: jerry_exception_value */ { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t num_val = jerry_create_number (123); - num_val = jerry_create_error_from_value (num_val, true); - TEST_ASSERT (jerry_value_is_error (num_val)); - jerry_value_t num2_val = jerry_get_value_from_error (num_val, false); - TEST_ASSERT (jerry_value_is_error (num_val)); - TEST_ASSERT (!jerry_value_is_error (num2_val)); - double num = jerry_get_number_value (num2_val); + jerry_value_t num_val = jerry_number (123); + num_val = jerry_throw_value (num_val, true); + TEST_ASSERT (jerry_value_is_exception (num_val)); + jerry_value_t num2_val = jerry_exception_value (num_val, false); + TEST_ASSERT (jerry_value_is_exception (num_val)); + TEST_ASSERT (!jerry_value_is_exception (num2_val)); + double num = jerry_value_as_number (num2_val); TEST_ASSERT (num == 123); - num2_val = jerry_get_value_from_error (num_val, true); - TEST_ASSERT (!jerry_value_is_error (num2_val)); - num = jerry_get_number_value (num2_val); + num2_val = jerry_exception_value (num_val, true); + TEST_ASSERT (!jerry_value_is_exception (num2_val)); + num = jerry_value_as_number (num2_val); TEST_ASSERT (num == 123); - jerry_release_value (num2_val); + jerry_value_free (num2_val); jerry_cleanup (); } /* Test parsing/executing scripts with lexically scoped global variables multiple times. */ - if (jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { jerry_init (JERRY_INIT_EMPTY); const jerry_char_t scoped_src_p[] = "let a; this.b = 5"; jerry_value_t parse_result = jerry_parse (scoped_src_p, sizeof (scoped_src_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); - jerry_release_value (parse_result); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); + jerry_value_free (parse_result); parse_result = jerry_parse (scoped_src_p, sizeof (scoped_src_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t run_result = jerry_run (parse_result); - TEST_ASSERT (!jerry_value_is_error (run_result)); - jerry_release_value (run_result); + TEST_ASSERT (!jerry_value_is_exception (run_result)); + jerry_value_free (run_result); /* Should be a syntax error due to redeclaration. */ run_result = jerry_run (parse_result); - TEST_ASSERT (jerry_value_is_error (run_result)); - jerry_release_value (run_result); - jerry_release_value (parse_result); + TEST_ASSERT (jerry_value_is_exception (run_result)); + jerry_value_free (run_result); + jerry_value_free (parse_result); /* The variable should have no effect on parsing. */ parse_result = jerry_parse (scoped_src_p, sizeof (scoped_src_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); - jerry_release_value (parse_result); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); + jerry_value_free (parse_result); /* The already existing global binding should not affect a new lexical binding */ const jerry_char_t scoped_src2_p[] = "let b = 6; this.b + b"; parse_result = jerry_parse (scoped_src2_p, sizeof (scoped_src2_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); run_result = jerry_run (parse_result); TEST_ASSERT (jerry_value_is_number (run_result)); - TEST_ASSERT (jerry_get_number_value (run_result) == 11); - jerry_release_value (run_result); - jerry_release_value (parse_result); + TEST_ASSERT (jerry_value_as_number (run_result) == 11); + jerry_value_free (run_result); + jerry_value_free (parse_result); /* Check restricted global property */ const jerry_char_t scoped_src3_p[] = "let undefined;"; parse_result = jerry_parse (scoped_src3_p, sizeof (scoped_src3_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); run_result = jerry_run (parse_result); - TEST_ASSERT (jerry_value_is_error (run_result)); - TEST_ASSERT (jerry_get_error_type (run_result) == JERRY_ERROR_SYNTAX); - jerry_release_value (run_result); - jerry_release_value (parse_result); + TEST_ASSERT (jerry_value_is_exception (run_result)); + TEST_ASSERT (jerry_error_type (run_result) == JERRY_ERROR_SYNTAX); + jerry_value_free (run_result); + jerry_value_free (parse_result); - jerry_value_t global_obj = jerry_get_global_object (); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "foo"); + jerry_value_t global_obj = jerry_current_realm (); + jerry_value_t prop_name = jerry_string_sz ("foo"); - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED; - prop_desc.value = jerry_create_number (5.2); + prop_desc.value = jerry_number (5.2); - jerry_value_t define_result = jerry_define_own_property (global_obj, prop_name, &prop_desc); + jerry_value_t define_result = jerry_object_define_own_prop (global_obj, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (define_result) && jerry_value_is_true (define_result)); - jerry_release_value (define_result); + jerry_value_free (define_result); jerry_property_descriptor_free (&prop_desc); - jerry_release_value (prop_name); - jerry_release_value (global_obj); + jerry_value_free (prop_name); + jerry_value_free (global_obj); const jerry_char_t scoped_src4_p[] = "let foo;"; parse_result = jerry_parse (scoped_src4_p, sizeof (scoped_src4_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); run_result = jerry_run (parse_result); - TEST_ASSERT (jerry_value_is_error (run_result)); - TEST_ASSERT (jerry_get_error_type (run_result) == JERRY_ERROR_SYNTAX); - jerry_release_value (run_result); - jerry_release_value (parse_result); + TEST_ASSERT (jerry_value_is_exception (run_result)); + TEST_ASSERT (jerry_error_type (run_result) == JERRY_ERROR_SYNTAX); + jerry_value_free (run_result); + jerry_value_free (parse_result); - if (jerry_is_feature_enabled (JERRY_FEATURE_REALM)) + if (jerry_feature_enabled (JERRY_FEATURE_REALM)) { const jerry_char_t proxy_src_p[] = "new Proxy({}, { getOwnPropertyDescriptor() { throw 42.1 }})"; jerry_value_t proxy = jerry_eval (proxy_src_p, sizeof (proxy_src_p) - 1, JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_object (proxy)); - jerry_value_t new_realm_value = jerry_create_realm (); + jerry_value_t new_realm_value = jerry_realm (); jerry_value_t set_realm_this_result = jerry_realm_set_this (new_realm_value, proxy); TEST_ASSERT (jerry_value_is_boolean (set_realm_this_result) && jerry_value_is_true (set_realm_this_result)); - jerry_release_value (set_realm_this_result); + jerry_value_free (set_realm_this_result); jerry_value_t old_realm = jerry_set_realm (new_realm_value); const jerry_char_t scoped_src5_p[] = "let a;"; parse_result = jerry_parse (scoped_src5_p, sizeof (scoped_src5_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); run_result = jerry_run (parse_result); - TEST_ASSERT (jerry_value_is_error (run_result)); - jerry_value_t error_value = jerry_get_value_from_error (run_result, false); - TEST_ASSERT (jerry_value_is_number (error_value) && jerry_get_number_value (error_value) == 42.1); - jerry_release_value (error_value); - jerry_release_value (run_result); - jerry_release_value (parse_result); + TEST_ASSERT (jerry_value_is_exception (run_result)); + jerry_value_t error_value = jerry_exception_value (run_result, false); + TEST_ASSERT (jerry_value_is_number (error_value) && jerry_value_as_number (error_value) == 42.1); + jerry_value_free (error_value); + jerry_value_free (run_result); + jerry_value_free (parse_result); jerry_set_realm (old_realm); - jerry_release_value (new_realm_value); - jerry_release_value (proxy); + jerry_value_free (new_realm_value); + jerry_value_free (proxy); const jerry_char_t proxy_src2_p[] = "new Proxy(Object.defineProperty({}, 'b', {value: 5.2}), {})"; proxy = jerry_eval (proxy_src2_p, sizeof (proxy_src2_p) - 1, JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_object (proxy)); - new_realm_value = jerry_create_realm (); + new_realm_value = jerry_realm (); set_realm_this_result = jerry_realm_set_this (new_realm_value, proxy); TEST_ASSERT (jerry_value_is_boolean (set_realm_this_result) && jerry_value_is_true (set_realm_this_result)); - jerry_release_value (set_realm_this_result); + jerry_value_free (set_realm_this_result); old_realm = jerry_set_realm (new_realm_value); const jerry_char_t scoped_src6_p[] = "let b;"; parse_result = jerry_parse (scoped_src6_p, sizeof (scoped_src6_p) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); run_result = jerry_run (parse_result); - TEST_ASSERT (jerry_value_is_error (run_result)); - TEST_ASSERT (jerry_value_is_error (run_result)); - TEST_ASSERT (jerry_get_error_type (run_result) == JERRY_ERROR_SYNTAX); - jerry_release_value (run_result); - jerry_release_value (parse_result); + TEST_ASSERT (jerry_value_is_exception (run_result)); + TEST_ASSERT (jerry_value_is_exception (run_result)); + TEST_ASSERT (jerry_error_type (run_result) == JERRY_ERROR_SYNTAX); + jerry_value_free (run_result); + jerry_value_free (parse_result); jerry_set_realm (old_realm); - jerry_release_value (new_realm_value); - jerry_release_value (proxy); + jerry_value_free (new_realm_value); + jerry_value_free (proxy); } jerry_cleanup (); } /* Test: parser error location */ - if (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES)) + if (jerry_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES)) { jerry_init (JERRY_INIT_SHOW_OPCODES); @@ -1012,8 +1006,8 @@ main (void) "SyntaxError: Unexpected end of input [:2:10]", false); - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "filename.js"); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("filename.js"); test_syntax_error ("b = 'hello';\nvar a = (;", &parse_options, @@ -1034,7 +1028,7 @@ main (void) "SyntaxError: Expected ')' token [filename.js:10:36]", false); - jerry_release_value (parse_options.resource_name); + jerry_value_free (parse_options.source_name); jerry_cleanup (); } @@ -1046,47 +1040,47 @@ main (void) const jerry_char_t ms_code_src[] = "var global = {}; var console = [1]; var process = 1;"; parsed_code_val = jerry_parse (ms_code_src, sizeof (ms_code_src) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (res); + jerry_value_free (parsed_code_val); - /* call jerry_create_string functions which will returns with the registered external magic strings */ - args[0] = jerry_create_string ((jerry_char_t *) "console"); - args[1] = jerry_create_string ((jerry_char_t *) "\xed\xa0\x80\xed\xb6\x8a"); /**< greek zero sign */ + /* call jerry_string_sz functions which will returns with the registered external magic strings */ + args[0] = jerry_string_sz ("console"); + args[1] = jerry_string_sz ("\xed\xa0\x80\xed\xb6\x8a"); /**< greek zero sign */ - cesu8_length = jerry_get_string_length (args[0]); - cesu8_sz = jerry_get_string_size (args[0]); + cesu8_length = jerry_string_length (args[0]); + cesu8_sz = jerry_string_size (args[0], JERRY_ENCODING_CESU8); JERRY_VLA (char, string_console, cesu8_sz); - jerry_string_to_char_buffer (args[0], (jerry_char_t *) string_console, cesu8_sz); + jerry_string_to_buffer (args[0], (jerry_char_t *) string_console, cesu8_sz, JERRY_ENCODING_CESU8); TEST_ASSERT (!strncmp (string_console, "console", cesu8_sz)); TEST_ASSERT (cesu8_length == 7); TEST_ASSERT (cesu8_length == cesu8_sz); - jerry_release_value (args[0]); + jerry_value_free (args[0]); const jerry_char_t test_magic_str_access_src[] = "'console'.charAt(6) == 'e'"; res = jerry_eval (test_magic_str_access_src, sizeof (test_magic_str_access_src) - 1, JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_boolean (res)); TEST_ASSERT (jerry_value_is_true (res)); - jerry_release_value (res); + jerry_value_free (res); - cesu8_length = jerry_get_string_length (args[1]); - cesu8_sz = jerry_get_string_size (args[1]); + cesu8_length = jerry_string_length (args[1]); + cesu8_sz = jerry_string_size (args[1], JERRY_ENCODING_CESU8); JERRY_VLA (char, string_greek_zero_sign, cesu8_sz); - jerry_string_to_char_buffer (args[1], (jerry_char_t *) string_greek_zero_sign, cesu8_sz); + jerry_string_to_buffer (args[1], (jerry_char_t *) string_greek_zero_sign, cesu8_sz, JERRY_ENCODING_CESU8); TEST_ASSERT (!strncmp (string_greek_zero_sign, "\xed\xa0\x80\xed\xb6\x8a", cesu8_sz)); TEST_ASSERT (cesu8_length == 2); TEST_ASSERT (cesu8_sz == 6); - jerry_release_value (args[1]); + jerry_value_free (args[1]); jerry_cleanup (); diff --git a/tests/unit-core/test-arraybuffer.c b/tests/unit-core/test-arraybuffer.c index 8677746353..aaa9ef24bb 100644 --- a/tests/unit-core/test-arraybuffer.c +++ b/tests/unit-core/test-arraybuffer.c @@ -26,16 +26,16 @@ static void register_js_value (const char *name_p, /**< name of the function */ jerry_value_t value) /**< JS value */ { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_set_property (global_obj_val, name_val, value); + jerry_value_t name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_set (global_obj_val, name_val, value); TEST_ASSERT (jerry_value_is_boolean (result_val)); - jerry_release_value (name_val); - jerry_release_value (global_obj_val); + jerry_value_free (name_val); + jerry_value_free (global_obj_val); - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_value */ static jerry_value_t @@ -47,17 +47,17 @@ assert_handler (const jerry_call_info_t *call_info_p, /**< call information */ if (args_cnt > 0 && jerry_value_is_true (args_p[0])) { - return jerry_create_boolean (true); + return jerry_boolean (true); } if (args_cnt > 1 && jerry_value_is_string (args_p[1])) { - jerry_length_t utf8_sz = jerry_get_string_size (args_p[1]); + jerry_length_t utf8_sz = jerry_string_size (args_p[1], JERRY_ENCODING_CESU8); TEST_ASSERT (utf8_sz <= 127); /* 127 is the expected max assert fail message size. */ JERRY_VLA (char, string_from_utf8, utf8_sz + 1); string_from_utf8[utf8_sz] = 0; - jerry_string_to_char_buffer (args_p[1], (jerry_char_t *) string_from_utf8, utf8_sz); + jerry_string_to_buffer (args_p[1], (jerry_char_t *) string_from_utf8, utf8_sz, JERRY_ENCODING_CESU8); printf ("JS assert: %s\n", string_from_utf8); } @@ -78,9 +78,9 @@ test_read_with_offset (uint8_t offset) /**< offset for buffer read. */ jerry_value_t arraybuffer = jerry_eval (eval_arraybuffer_src, sizeof (eval_arraybuffer_src) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 15); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == 15); uint8_t buffer[20]; memset (buffer, 120, 20); @@ -95,7 +95,7 @@ test_read_with_offset (uint8_t offset) /**< offset for buffer read. */ } TEST_ASSERT (buffer[15 - offset] == 120); - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } /* test_read_with_offset */ /** @@ -105,18 +105,18 @@ static void test_write_with_offset (uint8_t offset) /**< offset for buffer write. */ { { - jerry_value_t offset_val = jerry_create_number (offset); + jerry_value_t offset_val = jerry_number (offset); register_js_value ("offset", offset_val); - jerry_release_value (offset_val); + jerry_value_free (offset_val); } const jerry_char_t eval_arraybuffer_src[] = "var array = new Uint8Array (15); array.buffer"; jerry_value_t arraybuffer = jerry_eval (eval_arraybuffer_src, sizeof (eval_arraybuffer_src) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 15); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == 15); uint8_t buffer[20]; @@ -141,8 +141,8 @@ test_write_with_offset (uint8_t offset) /**< offset for buffer write. */ "};" "assert (array[15] === undefined, 'ArrayBuffer out of bounds index should return undefined value');"); jerry_value_t res = jerry_eval (eval_test_arraybuffer, sizeof (eval_test_arraybuffer) - 1, JERRY_PARSE_STRICT_MODE); - jerry_release_value (res); - jerry_release_value (arraybuffer); + jerry_value_free (res); + jerry_value_free (arraybuffer); } /* test_write_with_offset */ static int allocate_mode = 0; @@ -205,39 +205,39 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY)) + if (!jerry_feature_enabled (JERRY_FEATURE_TYPEDARRAY)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ArrayBuffer is disabled!\n"); jerry_cleanup (); return 0; } - jerry_arraybuffer_set_compact_allocation_limit (4); - jerry_arraybuffer_set_allocator_callbacks (test_allocate_cb, test_free_cb, (void *) &allocate_mode); + jerry_arraybuffer_heap_allocation_limit (4); + jerry_arraybuffer_allocator_cb (test_allocate_cb, test_free_cb, (void *) &allocate_mode); - jerry_value_t function_val = jerry_create_external_function (assert_handler); + jerry_value_t function_val = jerry_function_external (assert_handler); register_js_value ("assert", function_val); - jerry_release_value (function_val); + jerry_value_free (function_val); /* Test array buffer queries */ { const jerry_char_t eval_arraybuffer_src[] = "new ArrayBuffer (10)"; jerry_value_t eval_arraybuffer = jerry_eval (eval_arraybuffer_src, sizeof (eval_arraybuffer_src) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (eval_arraybuffer)); + TEST_ASSERT (!jerry_value_is_exception (eval_arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (eval_arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (eval_arraybuffer) == 10); - jerry_release_value (eval_arraybuffer); + TEST_ASSERT (jerry_arraybuffer_size (eval_arraybuffer) == 10); + jerry_value_free (eval_arraybuffer); } /* Test array buffer creation */ { const uint32_t length = 15; - jerry_value_t arraybuffer = jerry_create_arraybuffer (length); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer (length); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); - jerry_release_value (arraybuffer); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); + jerry_value_free (arraybuffer); } /* Test array buffer read operations */ @@ -249,10 +249,10 @@ main (void) /* Test zero length ArrayBuffer read */ { const uint32_t length = 0; - jerry_value_t arraybuffer = jerry_create_arraybuffer (length); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer (length); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); uint8_t data[20]; memset (data, 11, 20); @@ -265,7 +265,7 @@ main (void) TEST_ASSERT (data[i] == 11); } - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } /* Test array buffer write operations */ @@ -277,10 +277,10 @@ main (void) /* Test zero length ArrayBuffer write */ { const uint32_t length = 0; - jerry_value_t arraybuffer = jerry_create_arraybuffer (length); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer (length); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); uint8_t data[20]; memset (data, 11, 20); @@ -288,17 +288,17 @@ main (void) jerry_length_t bytes_written = jerry_arraybuffer_write (arraybuffer, 0, data, 20); TEST_ASSERT (bytes_written == 0); - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } /* Test zero length external ArrayBuffer */ { const uint32_t length = 0; - jerry_value_t arraybuffer = jerry_create_arraybuffer_external (length, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer_external (NULL, length, NULL); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_is_arraybuffer_detachable (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_is_detachable (arraybuffer)); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); uint8_t data[20]; memset (data, 11, 20); @@ -306,7 +306,7 @@ main (void) jerry_length_t bytes_written = jerry_arraybuffer_write (arraybuffer, 0, data, 20); TEST_ASSERT (bytes_written == 0); - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } /* Test ArrayBuffer with buffer allocated externally */ @@ -317,12 +317,12 @@ main (void) uint8_t *buffer_p = (uint8_t *) malloc (buffer_size); memset (buffer_p, base_value, buffer_size); - jerry_value_t arrayb = jerry_create_arraybuffer_external (buffer_size, buffer_p, NULL); + jerry_value_t arrayb = jerry_arraybuffer_external (buffer_p, buffer_size, NULL); uint8_t new_value = 123; jerry_length_t copied = jerry_arraybuffer_write (arrayb, 0, &new_value, 1); TEST_ASSERT (copied == 1); TEST_ASSERT (buffer_p[0] == new_value); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arrayb) == buffer_size); + TEST_ASSERT (jerry_arraybuffer_size (arrayb) == buffer_size); for (uint32_t i = 1; i < buffer_size; i++) { @@ -340,16 +340,16 @@ main (void) } TEST_ASSERT (jerry_value_is_arraybuffer (arrayb)); - jerry_release_value (arrayb); + jerry_value_free (arrayb); } /* Test ArrayBuffer external memory map/unmap */ { const uint32_t buffer_size = 20; - jerry_value_t input_buffer = jerry_create_arraybuffer_external (buffer_size, NULL, (void *) &allocate_count); + jerry_value_t input_buffer = jerry_arraybuffer_external (NULL, buffer_size, (void *) &allocate_count); register_js_value ("input_buffer", input_buffer); - jerry_release_value (input_buffer); + jerry_value_free (input_buffer); const jerry_char_t eval_arraybuffer_src[] = TEST_STRING_LITERAL ("var array = new Uint8Array(input_buffer);" "for (var i = 0; i < array.length; i++)" @@ -360,11 +360,11 @@ main (void) jerry_value_t buffer = jerry_eval (eval_arraybuffer_src, sizeof (eval_arraybuffer_src) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (buffer)); + TEST_ASSERT (!jerry_value_is_exception (buffer)); TEST_ASSERT (jerry_value_is_arraybuffer (buffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (buffer) == 20); + TEST_ASSERT (jerry_arraybuffer_size (buffer) == 20); - uint8_t *const data = jerry_get_arraybuffer_pointer (buffer); + uint8_t *const data = jerry_arraybuffer_data (buffer); TEST_ASSERT (data != NULL); @@ -393,71 +393,71 @@ main (void) "sum"); jerry_value_t res = jerry_eval (eval_test_arraybuffer, sizeof (eval_test_arraybuffer) - 1, JERRY_PARSE_STRICT_MODE); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == sum); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == sum); + jerry_value_free (res); - jerry_release_value (buffer); + jerry_value_free (buffer); } /* Test internal ArrayBuffer detach */ { const uint32_t length = 4; - jerry_value_t arraybuffer = jerry_create_arraybuffer (length); + jerry_value_t arraybuffer = jerry_arraybuffer (length); TEST_ASSERT (jerry_arraybuffer_has_buffer (arraybuffer)); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); - jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer); + jerry_value_t is_detachable = jerry_arraybuffer_is_detachable (arraybuffer); TEST_ASSERT (jerry_value_is_true (is_detachable)); - jerry_release_value (is_detachable); + jerry_value_free (is_detachable); - jerry_value_t res = jerry_detach_arraybuffer (arraybuffer); + jerry_value_t res = jerry_arraybuffer_detach (arraybuffer); TEST_ASSERT (!jerry_arraybuffer_has_buffer (arraybuffer)); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_get_arraybuffer_pointer (arraybuffer) == NULL); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 0); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_arraybuffer_data (arraybuffer) == NULL); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == 0); - is_detachable = jerry_is_arraybuffer_detachable (arraybuffer); + is_detachable = jerry_arraybuffer_is_detachable (arraybuffer); TEST_ASSERT (jerry_value_is_false (is_detachable)); - jerry_release_value (is_detachable); + jerry_value_free (is_detachable); - jerry_release_value (res); - jerry_release_value (arraybuffer); + jerry_value_free (res); + jerry_value_free (arraybuffer); } /* Test external ArrayBuffer detach */ { const uint32_t length = 64; - jerry_value_t arraybuffer = jerry_create_arraybuffer_external (length, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer_external (NULL, length, NULL); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); TEST_ASSERT (!jerry_arraybuffer_has_buffer (arraybuffer)); uint8_t buf[1] = { 1 }; TEST_ASSERT (jerry_arraybuffer_write (arraybuffer, 0, buf, 1) == 1); TEST_ASSERT (jerry_arraybuffer_has_buffer (arraybuffer)); - jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (is_detachable)); + jerry_value_t is_detachable = jerry_arraybuffer_is_detachable (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (is_detachable)); TEST_ASSERT (jerry_value_is_true (is_detachable)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); - jerry_release_value (is_detachable); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); + jerry_value_free (is_detachable); - jerry_value_t res = jerry_detach_arraybuffer (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_get_arraybuffer_pointer (arraybuffer) == NULL); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 0); + jerry_value_t res = jerry_arraybuffer_detach (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_arraybuffer_data (arraybuffer) == NULL); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == 0); - is_detachable = jerry_is_arraybuffer_detachable (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (is_detachable)); + is_detachable = jerry_arraybuffer_is_detachable (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (is_detachable)); TEST_ASSERT (!jerry_value_is_true (is_detachable)); TEST_ASSERT (!jerry_arraybuffer_has_buffer (arraybuffer)); - jerry_release_value (is_detachable); + jerry_value_free (is_detachable); - jerry_release_value (res); - jerry_release_value (arraybuffer); + jerry_value_free (res); + jerry_value_free (arraybuffer); } /* Test ArrayBuffer created in ECMAScript */ @@ -465,7 +465,7 @@ main (void) { const jerry_char_t source[] = TEST_STRING_LITERAL ("new ArrayBuffer(64)"); jerry_value_t arraybuffer = jerry_eval (source, sizeof (source) - 1, JERRY_PARSE_NO_OPTS); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); TEST_ASSERT (!jerry_arraybuffer_has_buffer (arraybuffer)); @@ -482,13 +482,13 @@ main (void) } else { - uint8_t *buffer_p = jerry_get_arraybuffer_pointer (arraybuffer); + uint8_t *buffer_p = jerry_arraybuffer_data (arraybuffer); TEST_ASSERT (buffer_p != NULL); } TEST_ASSERT (jerry_arraybuffer_has_buffer (arraybuffer)); - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } jerry_cleanup (); diff --git a/tests/unit-core/test-backtrace.c b/tests/unit-core/test-backtrace.c index 1201ab805f..69c1aecbca 100644 --- a/tests/unit-core/test-backtrace.c +++ b/tests/unit-core/test-backtrace.c @@ -29,10 +29,10 @@ backtrace_handler (const jerry_call_info_t *call_info_p, /**< call information * if (args_count >= 1 && jerry_value_is_number (args_p[0])) { - max_depth = (uint32_t) jerry_get_number_value (args_p[0]); + max_depth = (uint32_t) jerry_value_as_number (args_p[0]); } - return jerry_get_backtrace (max_depth); + return jerry_backtrace (max_depth); } /* backtrace_handler */ static void @@ -44,9 +44,9 @@ compare_string (jerry_value_t left_value, /* string value */ TEST_ASSERT (length <= sizeof (buffer)); TEST_ASSERT (jerry_value_is_string (left_value)); - TEST_ASSERT (jerry_get_string_size (left_value) == length); + TEST_ASSERT (jerry_string_size (left_value, JERRY_ENCODING_CESU8) == length); - TEST_ASSERT (jerry_string_to_char_buffer (left_value, buffer, sizeof (buffer)) == length); + TEST_ASSERT (jerry_string_to_buffer (left_value, buffer, sizeof (buffer), JERRY_ENCODING_CESU8) == length); TEST_ASSERT (memcmp (buffer, right_p, length) == 0); } /* compare_string */ @@ -54,27 +54,27 @@ static const jerry_value_t *handler_args_p; static int frame_index; static bool -backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information */ +backtrace_callback (jerry_frame_t *frame_p, /* frame information */ void *user_p) /* user data */ { TEST_ASSERT ((void *) handler_args_p == user_p); - TEST_ASSERT (jerry_backtrace_get_frame_type (frame_p) == JERRY_BACKTRACE_FRAME_JS); + TEST_ASSERT (jerry_frame_type (frame_p) == JERRY_BACKTRACE_FRAME_JS); - const jerry_backtrace_location_t *location_p = jerry_backtrace_get_location (frame_p); - const jerry_value_t *function_p = jerry_backtrace_get_function (frame_p); - const jerry_value_t *this_p = jerry_backtrace_get_this (frame_p); + const jerry_frame_location_t *location_p = jerry_frame_location (frame_p); + const jerry_value_t *function_p = jerry_frame_callee (frame_p); + const jerry_value_t *this_p = jerry_frame_this (frame_p); TEST_ASSERT (location_p != NULL); TEST_ASSERT (function_p != NULL); TEST_ASSERT (this_p != NULL); - compare_string (location_p->resource_name, "capture_test.js"); + compare_string (location_p->source_name, "capture_test.js"); ++frame_index; if (frame_index == 1) { - TEST_ASSERT (!jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (!jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 2); TEST_ASSERT (location_p->column == 3); TEST_ASSERT (handler_args_p[0] == *function_p); @@ -84,7 +84,7 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information */ if (frame_index == 2) { - TEST_ASSERT (jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 7); TEST_ASSERT (location_p->column == 6); TEST_ASSERT (handler_args_p[2] == *function_p); @@ -92,39 +92,39 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information */ return true; } - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); TEST_ASSERT (frame_index == 3); - TEST_ASSERT (!jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (!jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 11); TEST_ASSERT (location_p->column == 3); TEST_ASSERT (handler_args_p[3] == *function_p); TEST_ASSERT (global == *this_p); - jerry_release_value (global); + jerry_value_free (global); return false; } /* backtrace_callback */ static bool -async_backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information */ +async_backtrace_callback (jerry_frame_t *frame_p, /* frame information */ void *user_p) /* user data */ { TEST_ASSERT ((void *) handler_args_p == user_p); - TEST_ASSERT (jerry_backtrace_get_frame_type (frame_p) == JERRY_BACKTRACE_FRAME_JS); + TEST_ASSERT (jerry_frame_type (frame_p) == JERRY_BACKTRACE_FRAME_JS); - const jerry_backtrace_location_t *location_p = jerry_backtrace_get_location (frame_p); - const jerry_value_t *function_p = jerry_backtrace_get_function (frame_p); + const jerry_frame_location_t *location_p = jerry_frame_location (frame_p); + const jerry_value_t *function_p = jerry_frame_callee (frame_p); TEST_ASSERT (location_p != NULL); TEST_ASSERT (function_p != NULL); - compare_string (location_p->resource_name, "async_capture_test.js"); + compare_string (location_p->source_name, "async_capture_test.js"); ++frame_index; if (frame_index == 1) { - TEST_ASSERT (jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 3); TEST_ASSERT (location_p->column == 3); TEST_ASSERT (handler_args_p[0] == *function_p); @@ -132,7 +132,7 @@ async_backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information } TEST_ASSERT (frame_index == 2); - TEST_ASSERT (!jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (!jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 8); TEST_ASSERT (location_p->column == 3); TEST_ASSERT (handler_args_p[1] == *function_p); @@ -140,32 +140,32 @@ async_backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information } /* async_backtrace_callback */ static bool -class_backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information */ +class_backtrace_callback (jerry_frame_t *frame_p, /* frame information */ void *user_p) /* user data */ { TEST_ASSERT ((void *) handler_args_p == user_p); - TEST_ASSERT (jerry_backtrace_get_frame_type (frame_p) == JERRY_BACKTRACE_FRAME_JS); + TEST_ASSERT (jerry_frame_type (frame_p) == JERRY_BACKTRACE_FRAME_JS); - const jerry_backtrace_location_t *location_p = jerry_backtrace_get_location (frame_p); - const jerry_value_t *function_p = jerry_backtrace_get_function (frame_p); + const jerry_frame_location_t *location_p = jerry_frame_location (frame_p); + const jerry_value_t *function_p = jerry_frame_callee (frame_p); TEST_ASSERT (location_p != NULL); TEST_ASSERT (function_p != NULL); - compare_string (location_p->resource_name, "class_capture_test.js"); + compare_string (location_p->source_name, "class_capture_test.js"); ++frame_index; if (frame_index == 1) { - TEST_ASSERT (jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 3); TEST_ASSERT (location_p->column == 14); return false; } TEST_ASSERT (frame_index == 2); - TEST_ASSERT (jerry_backtrace_is_strict (frame_p)); + TEST_ASSERT (jerry_frame_is_strict (frame_p)); TEST_ASSERT (location_p->line == 2); TEST_ASSERT (location_p->column == 7); return false; @@ -181,7 +181,7 @@ capture_handler (const jerry_call_info_t *call_info_p, /**< call information */ TEST_ASSERT (args_count == 0 || args_count == 2 || args_count == 4); TEST_ASSERT (args_count == 0 || frame_index == 0); - jerry_backtrace_callback_t callback = backtrace_callback; + jerry_backtrace_cb_t callback = backtrace_callback; if (args_count == 0) { @@ -197,22 +197,22 @@ capture_handler (const jerry_call_info_t *call_info_p, /**< call information */ TEST_ASSERT (args_count == 0 || frame_index == (args_count == 4 ? 3 : 2)); - return jerry_create_undefined (); + return jerry_undefined (); } /* capture_handler */ static bool -global_backtrace_callback (jerry_backtrace_frame_t *frame_p, /* frame information */ +global_backtrace_callback (jerry_frame_t *frame_p, /* frame information */ void *user_p) /* user data */ { TEST_ASSERT (user_p != NULL && frame_index == 0); frame_index++; - const jerry_value_t *function_p = jerry_backtrace_get_function (frame_p); + const jerry_value_t *function_p = jerry_frame_callee (frame_p); jerry_value_t *result_p = ((jerry_value_t *) user_p); TEST_ASSERT (function_p != NULL); - jerry_release_value (*result_p); - *result_p = jerry_acquire_value (*function_p); + jerry_value_free (*result_p); + *result_p = jerry_value_copy (*function_p); return true; } /* global_backtrace_callback */ @@ -225,7 +225,7 @@ global_capture_handler (const jerry_call_info_t *call_info_p, /**< call informat JERRY_UNUSED (args_p); JERRY_UNUSED (args_count); - jerry_value_t result = jerry_create_undefined (); + jerry_value_t result = jerry_undefined (); jerry_backtrace_capture (global_backtrace_callback, &result); TEST_ASSERT (jerry_value_is_object (result)); @@ -236,34 +236,34 @@ static void register_callback (jerry_external_handler_t handler_p, /**< callback function */ char *name_p) /**< name of the function */ { - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); - jerry_value_t func = jerry_create_external_function (handler_p); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result = jerry_set_property (global, name, func); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_t func = jerry_function_external (handler_p); + jerry_value_t name = jerry_string_sz (name_p); + jerry_value_t result = jerry_object_set (global, name, func); + TEST_ASSERT (!jerry_value_is_exception (result)); - jerry_release_value (result); - jerry_release_value (name); - jerry_release_value (func); + jerry_value_free (result); + jerry_value_free (name); + jerry_value_free (func); - jerry_release_value (global); + jerry_value_free (global); } /* register_callback */ static jerry_value_t -run (const char *resource_name_p, /**< resource name */ +run (const char *source_name_p, /**< resource name */ const char *source_p) /**< source code */ { jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) resource_name_p); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz (source_name_p); jerry_value_t code = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), &parse_options); - jerry_release_value (parse_options.resource_name); - TEST_ASSERT (!jerry_value_is_error (code)); + jerry_value_free (parse_options.source_name); + TEST_ASSERT (!jerry_value_is_exception (code)); jerry_value_t result = jerry_run (code); - jerry_release_value (code); + jerry_value_free (code); return result; } /* run */ @@ -279,16 +279,16 @@ compare (jerry_value_t array, /**< array */ TEST_ASSERT (len < sizeof (buf)); - jerry_value_t value = jerry_get_property_by_index (array, index); + jerry_value_t value = jerry_object_get_index (array, index); - TEST_ASSERT (!jerry_value_is_error (value) && jerry_value_is_string (value)); + TEST_ASSERT (!jerry_value_is_exception (value) && jerry_value_is_string (value)); - TEST_ASSERT (jerry_get_string_size (value) == len); + TEST_ASSERT (jerry_string_size (value, JERRY_ENCODING_CESU8) == len); - jerry_size_t str_len = jerry_string_to_char_buffer (value, buf, (jerry_size_t) len); + jerry_size_t str_len = jerry_string_to_buffer (value, buf, (jerry_size_t) len, JERRY_ENCODING_CESU8); TEST_ASSERT (str_len == len); - jerry_release_value (value); + jerry_value_free (value); TEST_ASSERT (memcmp (buf, str, len) == 0); } /* compare */ @@ -317,16 +317,16 @@ test_get_backtrace_api_call (void) jerry_value_t backtrace = run ("something.js", source_p); - TEST_ASSERT (!jerry_value_is_error (backtrace) && jerry_value_is_array (backtrace)); + TEST_ASSERT (!jerry_value_is_exception (backtrace) && jerry_value_is_array (backtrace)); - TEST_ASSERT (jerry_get_array_length (backtrace) == 4); + TEST_ASSERT (jerry_array_length (backtrace) == 4); compare (backtrace, 0, "something.js:2:3"); compare (backtrace, 1, "something.js:6:3"); compare (backtrace, 2, "something.js:10:3"); compare (backtrace, 3, "something.js:13:1"); - jerry_release_value (backtrace); + jerry_value_free (backtrace); /* Depth set to 2 this time. */ @@ -346,14 +346,14 @@ test_get_backtrace_api_call (void) backtrace = run ("something_else.js", source_p); - TEST_ASSERT (!jerry_value_is_error (backtrace) && jerry_value_is_array (backtrace)); + TEST_ASSERT (!jerry_value_is_exception (backtrace) && jerry_value_is_array (backtrace)); - TEST_ASSERT (jerry_get_array_length (backtrace) == 2); + TEST_ASSERT (jerry_array_length (backtrace) == 2); compare (backtrace, 0, "something_else.js:2:6"); compare (backtrace, 1, "something_else.js:6:3"); - jerry_release_value (backtrace); + jerry_value_free (backtrace); /* Test frame capturing. */ @@ -376,7 +376,7 @@ test_get_backtrace_api_call (void) jerry_value_t result = run ("capture_test.js", source_p); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); TEST_ASSERT (frame_index == 3); @@ -384,9 +384,9 @@ test_get_backtrace_api_call (void) source_p = "async function f() {}"; result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), JERRY_PARSE_NO_OPTS); - if (!jerry_value_is_error (result)) + if (!jerry_value_is_exception (result)) { - jerry_release_value (result); + jerry_value_free (result); frame_index = 0; source_p = ("function f() {\n" @@ -404,29 +404,29 @@ test_get_backtrace_api_call (void) result = run ("async_capture_test.js", source_p); TEST_ASSERT (jerry_value_is_promise (result)); - jerry_release_value (result); + jerry_value_free (result); TEST_ASSERT (frame_index == 0); - result = jerry_run_all_enqueued_jobs (); - TEST_ASSERT (!jerry_value_is_error (result)); + result = jerry_run_microtasks (); + TEST_ASSERT (!jerry_value_is_exception (result)); TEST_ASSERT (frame_index == 2); } else { - TEST_ASSERT (jerry_get_error_type (result) == JERRY_ERROR_SYNTAX); + TEST_ASSERT (jerry_error_type (result) == JERRY_ERROR_SYNTAX); } - jerry_release_value (result); + jerry_value_free (result); /* Test class initializer frame capturing. */ source_p = "class C {}"; result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), JERRY_PARSE_NO_OPTS); - if (!jerry_value_is_error (result)) + if (!jerry_value_is_exception (result)) { - jerry_release_value (result); + jerry_value_free (result); frame_index = 0; source_p = ("class C {\n" @@ -437,15 +437,15 @@ test_get_backtrace_api_call (void) result = run ("class_capture_test.js", source_p); - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); TEST_ASSERT (frame_index == 2); } else { - TEST_ASSERT (jerry_get_error_type (result) == JERRY_ERROR_SYNTAX); + TEST_ASSERT (jerry_error_type (result) == JERRY_ERROR_SYNTAX); } - jerry_release_value (result); + jerry_value_free (result); register_callback (global_capture_handler, "global_capture"); @@ -454,16 +454,16 @@ test_get_backtrace_api_call (void) source_p = "global_capture()"; jerry_value_t code = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), NULL); - TEST_ASSERT (!jerry_value_is_error (code)); + TEST_ASSERT (!jerry_value_is_exception (code)); result = jerry_run (code); - jerry_value_t compare_value = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, result, code); + jerry_value_t compare_value = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, result, code); TEST_ASSERT (jerry_value_is_true (compare_value)); - jerry_release_value (compare_value); - jerry_release_value (result); - jerry_release_value (code); + jerry_value_free (compare_value); + jerry_value_free (result); + jerry_value_free (code); jerry_cleanup (); } /* test_get_backtrace_api_call */ @@ -485,27 +485,27 @@ test_exception_backtrace (void) jerry_value_t error = run ("bad.js", source); - TEST_ASSERT (jerry_value_is_error (error)); + TEST_ASSERT (jerry_value_is_exception (error)); - error = jerry_get_value_from_error (error, true); + error = jerry_exception_value (error, true); TEST_ASSERT (jerry_value_is_object (error)); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "stack"); - jerry_value_t backtrace = jerry_get_property (error, name); + jerry_value_t name = jerry_string_sz ("stack"); + jerry_value_t backtrace = jerry_object_get (error, name); - jerry_release_value (name); - jerry_release_value (error); + jerry_value_free (name); + jerry_value_free (error); - TEST_ASSERT (!jerry_value_is_error (backtrace) && jerry_value_is_array (backtrace)); + TEST_ASSERT (!jerry_value_is_exception (backtrace) && jerry_value_is_array (backtrace)); - TEST_ASSERT (jerry_get_array_length (backtrace) == 3); + TEST_ASSERT (jerry_array_length (backtrace) == 3); compare (backtrace, 0, "bad.js:2:3"); compare (backtrace, 1, "bad.js:6:3"); compare (backtrace, 2, "bad.js:9:1"); - jerry_release_value (backtrace); + jerry_value_free (backtrace); jerry_cleanup (); } /* test_exception_backtrace */ @@ -531,25 +531,25 @@ test_large_line_count (void) jerry_value_t error = run ("bad.js", source); - TEST_ASSERT (jerry_value_is_error (error)); + TEST_ASSERT (jerry_value_is_exception (error)); - error = jerry_get_value_from_error (error, true); + error = jerry_exception_value (error, true); TEST_ASSERT (jerry_value_is_object (error)); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "stack"); - jerry_value_t backtrace = jerry_get_property (error, name); + jerry_value_t name = jerry_string_sz ("stack"); + jerry_value_t backtrace = jerry_object_get (error, name); - jerry_release_value (name); - jerry_release_value (error); + jerry_value_free (name); + jerry_value_free (error); - TEST_ASSERT (!jerry_value_is_error (backtrace) && jerry_value_is_array (backtrace)); + TEST_ASSERT (!jerry_value_is_exception (backtrace) && jerry_value_is_array (backtrace)); - TEST_ASSERT (jerry_get_array_length (backtrace) == 1); + TEST_ASSERT (jerry_array_length (backtrace) == 1); compare (backtrace, 0, "bad.js:385:1"); - jerry_release_value (backtrace); + jerry_value_free (backtrace); jerry_cleanup (); } /* test_large_line_count */ @@ -559,7 +559,7 @@ main (void) { TEST_INIT (); - TEST_ASSERT (jerry_is_feature_enabled (JERRY_FEATURE_LINE_INFO)); + TEST_ASSERT (jerry_feature_enabled (JERRY_FEATURE_LINE_INFO)); test_get_backtrace_api_call (); test_exception_backtrace (); diff --git a/tests/unit-core/test-bigint.c b/tests/unit-core/test-bigint.c index b4f0f329c8..57b73c4144 100644 --- a/tests/unit-core/test-bigint.c +++ b/tests/unit-core/test-bigint.c @@ -20,7 +20,7 @@ int main (void) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_BIGINT)) + if (!jerry_feature_enabled (JERRY_FEATURE_BIGINT)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Bigint support is disabled!\n"); return 0; @@ -28,34 +28,34 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t string = jerry_create_string ((const jerry_char_t *) "0xfffffff1fffffff2fffffff3"); - TEST_ASSERT (!jerry_value_is_error (string)); + jerry_value_t string = jerry_string_sz ("0xfffffff1fffffff2fffffff3"); + TEST_ASSERT (!jerry_value_is_exception (string)); jerry_value_t bigint = jerry_value_to_bigint (string); - jerry_release_value (string); + jerry_value_free (string); - TEST_ASSERT (!jerry_value_is_error (bigint)); + TEST_ASSERT (!jerry_value_is_exception (bigint)); TEST_ASSERT (jerry_value_is_bigint (bigint)); string = jerry_value_to_string (bigint); - TEST_ASSERT (!jerry_value_is_error (string)); + TEST_ASSERT (!jerry_value_is_exception (string)); static jerry_char_t str_buffer[64]; const char *expected_string_p = "79228162256009920505775652851"; - jerry_size_t size = jerry_string_to_char_buffer (string, str_buffer, sizeof (str_buffer)); + jerry_size_t size = jerry_string_to_buffer (string, str_buffer, sizeof (str_buffer), JERRY_ENCODING_CESU8); TEST_ASSERT (size == strlen (expected_string_p)); TEST_ASSERT (memcmp (str_buffer, expected_string_p, size) == 0); - jerry_release_value (string); + jerry_value_free (string); - TEST_ASSERT (jerry_get_bigint_size_in_digits (bigint) == 2); + TEST_ASSERT (jerry_bigint_digit_count (bigint) == 2); uint64_t digits_buffer[4]; bool sign; memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = true; - jerry_get_bigint_digits (bigint, digits_buffer, 0, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 0, &sign); TEST_ASSERT (sign == false); TEST_ASSERT (digits_buffer[0] == ~((uint64_t) 0)); TEST_ASSERT (digits_buffer[1] == ~((uint64_t) 0)); @@ -64,7 +64,7 @@ main (void) memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = true; - jerry_get_bigint_digits (bigint, digits_buffer, 1, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 1, &sign); TEST_ASSERT (sign == false); TEST_ASSERT (digits_buffer[0] == 0xfffffff2fffffff3ull); TEST_ASSERT (digits_buffer[1] == ~((uint64_t) 0)); @@ -73,7 +73,7 @@ main (void) memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = true; - jerry_get_bigint_digits (bigint, digits_buffer, 2, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 2, &sign); TEST_ASSERT (sign == false); TEST_ASSERT (digits_buffer[0] == 0xfffffff2fffffff3ull); TEST_ASSERT (digits_buffer[1] == 0xfffffff1ull); @@ -82,7 +82,7 @@ main (void) memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = true; - jerry_get_bigint_digits (bigint, digits_buffer, 3, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 3, &sign); TEST_ASSERT (sign == false); TEST_ASSERT (digits_buffer[0] == 0xfffffff2fffffff3ull); TEST_ASSERT (digits_buffer[1] == 0xfffffff1ull); @@ -90,44 +90,44 @@ main (void) TEST_ASSERT (digits_buffer[3] == ~((uint64_t) 0)); memset (digits_buffer, 0xff, sizeof (digits_buffer)); - jerry_get_bigint_digits (bigint, digits_buffer, 4, NULL); + jerry_bigint_to_digits (bigint, digits_buffer, 4, NULL); TEST_ASSERT (digits_buffer[0] == 0xfffffff2fffffff3ull); TEST_ASSERT (digits_buffer[1] == 0xfffffff1ull); TEST_ASSERT (digits_buffer[2] == 0); TEST_ASSERT (digits_buffer[3] == 0); - jerry_release_value (bigint); + jerry_value_free (bigint); digits_buffer[0] = 0; digits_buffer[1] = 0; digits_buffer[2] = 0; /* Sign of zero value is always positive, even if we set negative. */ - bigint = jerry_create_bigint (digits_buffer, 3, true); + bigint = jerry_bigint (digits_buffer, 3, true); TEST_ASSERT (jerry_value_is_bigint (bigint)); - TEST_ASSERT (jerry_get_bigint_size_in_digits (bigint) == 0); + TEST_ASSERT (jerry_bigint_digit_count (bigint) == 0); memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = true; - jerry_get_bigint_digits (bigint, digits_buffer, 2, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 2, &sign); TEST_ASSERT (sign == false); TEST_ASSERT (digits_buffer[0] == 0); TEST_ASSERT (digits_buffer[1] == 0); TEST_ASSERT (digits_buffer[2] == ~((uint64_t) 0)); TEST_ASSERT (digits_buffer[3] == ~((uint64_t) 0)); - jerry_release_value (bigint); + jerry_value_free (bigint); digits_buffer[0] = 1; digits_buffer[1] = 0; digits_buffer[2] = 0; digits_buffer[3] = 0; - bigint = jerry_create_bigint (digits_buffer, 4, true); + bigint = jerry_bigint (digits_buffer, 4, true); TEST_ASSERT (jerry_value_is_bigint (bigint)); - TEST_ASSERT (jerry_get_bigint_size_in_digits (bigint) == 1); + TEST_ASSERT (jerry_bigint_digit_count (bigint) == 1); memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = false; - jerry_get_bigint_digits (bigint, digits_buffer, 1, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 1, &sign); TEST_ASSERT (sign == true); TEST_ASSERT (digits_buffer[0] == 1); TEST_ASSERT (digits_buffer[1] == ~((uint64_t) 0)); @@ -136,26 +136,26 @@ main (void) memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = false; - jerry_get_bigint_digits (bigint, digits_buffer, 2, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 2, &sign); TEST_ASSERT (sign == true); TEST_ASSERT (digits_buffer[0] == 1); TEST_ASSERT (digits_buffer[1] == 0); TEST_ASSERT (digits_buffer[2] == ~((uint64_t) 0)); TEST_ASSERT (digits_buffer[3] == ~((uint64_t) 0)); - jerry_release_value (bigint); + jerry_value_free (bigint); digits_buffer[0] = 0; digits_buffer[1] = 1; digits_buffer[2] = 0; digits_buffer[3] = 0; - bigint = jerry_create_bigint (digits_buffer, 4, true); + bigint = jerry_bigint (digits_buffer, 4, true); TEST_ASSERT (jerry_value_is_bigint (bigint)); - TEST_ASSERT (jerry_get_bigint_size_in_digits (bigint) == 2); + TEST_ASSERT (jerry_bigint_digit_count (bigint) == 2); memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = false; - jerry_get_bigint_digits (bigint, digits_buffer, 1, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 1, &sign); TEST_ASSERT (sign == true); TEST_ASSERT (digits_buffer[0] == 0); TEST_ASSERT (digits_buffer[1] == ~((uint64_t) 0)); @@ -164,7 +164,7 @@ main (void) memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = false; - jerry_get_bigint_digits (bigint, digits_buffer, 2, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 2, &sign); TEST_ASSERT (sign == true); TEST_ASSERT (digits_buffer[0] == 0); TEST_ASSERT (digits_buffer[1] == 1); @@ -173,14 +173,14 @@ main (void) memset (digits_buffer, 0xff, sizeof (digits_buffer)); sign = false; - jerry_get_bigint_digits (bigint, digits_buffer, 3, &sign); + jerry_bigint_to_digits (bigint, digits_buffer, 3, &sign); TEST_ASSERT (sign == true); TEST_ASSERT (digits_buffer[0] == 0); TEST_ASSERT (digits_buffer[1] == 1); TEST_ASSERT (digits_buffer[2] == 0); TEST_ASSERT (digits_buffer[3] == ~((uint64_t) 0)); - jerry_release_value (bigint); + jerry_value_free (bigint); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-container-operation.c b/tests/unit-core/test-container-operation.c index a0aca68a67..fd29ec61d7 100644 --- a/tests/unit-core/test-container-operation.c +++ b/tests/unit-core/test-container-operation.c @@ -22,8 +22,8 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_MAP) || !jerry_is_feature_enabled (JERRY_FEATURE_SET) - || !jerry_is_feature_enabled (JERRY_FEATURE_WEAKMAP) || !jerry_is_feature_enabled (JERRY_FEATURE_WEAKSET)) + if (!jerry_feature_enabled (JERRY_FEATURE_MAP) || !jerry_feature_enabled (JERRY_FEATURE_SET) + || !jerry_feature_enabled (JERRY_FEATURE_WEAKMAP) || !jerry_feature_enabled (JERRY_FEATURE_WEAKSET)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Containers are disabled!\n"); jerry_cleanup (); @@ -31,151 +31,151 @@ main (void) } // Map container tests - jerry_value_t map = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); - TEST_ASSERT (jerry_get_container_type (map) == JERRY_CONTAINER_TYPE_MAP); + jerry_value_t map = jerry_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); + TEST_ASSERT (jerry_container_type (map) == JERRY_CONTAINER_TYPE_MAP); - jerry_value_t key_str = jerry_create_string ((jerry_char_t *) "number"); - jerry_value_t number = jerry_create_number (10); + jerry_value_t key_str = jerry_string_sz ("number"); + jerry_value_t number = jerry_number (10); jerry_value_t args[2] = { key_str, number }; - jerry_value_t result = jerry_container_operation (JERRY_CONTAINER_OP_SET, map, args, 2); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + jerry_value_t result = jerry_container_op (JERRY_CONTAINER_OP_SET, map, args, 2); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_GET, map, &key_str, 1); - TEST_ASSERT (jerry_get_number_value (result) == 10); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_GET, map, &key_str, 1); + TEST_ASSERT (jerry_value_as_number (result) == 10); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_HAS, map, &key_str, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_HAS, map, &key_str, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 1); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 1); + jerry_value_free (result); - key_str = jerry_create_string ((jerry_char_t *) "number2"); - number = jerry_create_number (11); + key_str = jerry_string_sz ("number2"); + number = jerry_number (11); jerry_value_t args2[2] = { key_str, number }; - result = jerry_container_operation (JERRY_CONTAINER_OP_SET, map, args2, 2); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SET, map, args2, 2); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 2); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 2); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_DELETE, map, &key_str, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_DELETE, map, &key_str, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 1); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 1); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_CLEAR, map, NULL, 0); + result = jerry_container_op (JERRY_CONTAINER_OP_CLEAR, map, NULL, 0); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 0); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, map, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 0); + jerry_value_free (result); // Set container tests - number = jerry_create_number (10); - jerry_value_t set = jerry_create_container (JERRY_CONTAINER_TYPE_SET, NULL, 0); - TEST_ASSERT (jerry_get_container_type (set) == JERRY_CONTAINER_TYPE_SET); - result = jerry_container_operation (JERRY_CONTAINER_OP_ADD, set, &number, 1); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); - - result = jerry_container_operation (JERRY_CONTAINER_OP_HAS, set, &number, 1); + number = jerry_number (10); + jerry_value_t set = jerry_container (JERRY_CONTAINER_TYPE_SET, NULL, 0); + TEST_ASSERT (jerry_container_type (set) == JERRY_CONTAINER_TYPE_SET); + result = jerry_container_op (JERRY_CONTAINER_OP_ADD, set, &number, 1); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); + + result = jerry_container_op (JERRY_CONTAINER_OP_HAS, set, &number, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 1); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 1); + jerry_value_free (result); - number = jerry_create_number (11); - result = jerry_container_operation (JERRY_CONTAINER_OP_ADD, set, &number, 1); - jerry_release_value (result); + number = jerry_number (11); + result = jerry_container_op (JERRY_CONTAINER_OP_ADD, set, &number, 1); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 2); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 2); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_DELETE, set, &number, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_DELETE, set, &number, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 1); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 1); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_CLEAR, set, NULL, 0); + result = jerry_container_op (JERRY_CONTAINER_OP_CLEAR, set, NULL, 0); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); - TEST_ASSERT (jerry_get_number_value (result) == 0); - jerry_release_value (result); - jerry_release_value (set); + result = jerry_container_op (JERRY_CONTAINER_OP_SIZE, set, NULL, 0); + TEST_ASSERT (jerry_value_as_number (result) == 0); + jerry_value_free (result); + jerry_value_free (set); // WeakMap contanier tests - number = jerry_create_number (10); - jerry_value_t weak_map = jerry_create_container (JERRY_CONTAINER_TYPE_WEAKMAP, NULL, 0); - TEST_ASSERT (jerry_get_container_type (weak_map) == JERRY_CONTAINER_TYPE_WEAKMAP); + number = jerry_number (10); + jerry_value_t weak_map = jerry_container (JERRY_CONTAINER_TYPE_WEAKMAP, NULL, 0); + TEST_ASSERT (jerry_container_type (weak_map) == JERRY_CONTAINER_TYPE_WEAKMAP); - jerry_value_t obj = jerry_create_object (); - number = jerry_create_number (10); + jerry_value_t obj = jerry_object (); + number = jerry_number (10); jerry_value_t args4[2] = { obj, number }; - result = jerry_container_operation (JERRY_CONTAINER_OP_SET, weak_map, args4, 2); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_SET, weak_map, args4, 2); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_HAS, weak_map, &obj, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_HAS, weak_map, &obj, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_DELETE, weak_map, &obj, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_DELETE, weak_map, &obj, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); - jerry_release_value (weak_map); + jerry_value_free (result); + jerry_value_free (weak_map); // WeakSet contanier tests, - jerry_value_t weak_set = jerry_create_container (JERRY_CONTAINER_TYPE_WEAKSET, NULL, 0); - TEST_ASSERT (jerry_get_container_type (weak_set) == JERRY_CONTAINER_TYPE_WEAKSET); + jerry_value_t weak_set = jerry_container (JERRY_CONTAINER_TYPE_WEAKSET, NULL, 0); + TEST_ASSERT (jerry_container_type (weak_set) == JERRY_CONTAINER_TYPE_WEAKSET); - result = jerry_container_operation (JERRY_CONTAINER_OP_ADD, weak_set, &obj, 1); - jerry_release_value (result); + result = jerry_container_op (JERRY_CONTAINER_OP_ADD, weak_set, &obj, 1); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_HAS, weak_set, &obj, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_HAS, weak_set, &obj, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_container_operation (JERRY_CONTAINER_OP_DELETE, weak_set, &obj, 1); + result = jerry_container_op (JERRY_CONTAINER_OP_DELETE, weak_set, &obj, 1); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); - jerry_release_value (weak_set); + jerry_value_free (result); + jerry_value_free (weak_set); // container is not a object - jerry_value_t empty_val = jerry_create_undefined (); - result = jerry_container_operation (JERRY_CONTAINER_OP_SET, empty_val, args, 2); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + jerry_value_t empty_val = jerry_undefined (); + result = jerry_container_op (JERRY_CONTAINER_OP_SET, empty_val, args, 2); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); // arguments is a error const char *const error_message_p = "Random error."; - jerry_value_t error_val = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p); + jerry_value_t error_val = jerry_throw_sz (JERRY_ERROR_RANGE, error_message_p); jerry_value_t args3[2] = { error_val, error_val }; - result = jerry_container_operation (JERRY_CONTAINER_OP_SET, map, args3, 2); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); - jerry_release_value (error_val); - jerry_release_value (map); - - jerry_release_value (key_str); - jerry_release_value (number); - jerry_release_value (obj); + result = jerry_container_op (JERRY_CONTAINER_OP_SET, map, args3, 2); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); + jerry_value_free (error_val); + jerry_value_free (map); + + jerry_value_free (key_str); + jerry_value_free (number); + jerry_value_free (obj); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-container.c b/tests/unit-core/test-container.c index b3c5b032f2..dffcb1d7c0 100644 --- a/tests/unit-core/test-container.c +++ b/tests/unit-core/test-container.c @@ -43,11 +43,11 @@ create_array_from_container_handler (const jerry_call_info_t *call_info_p, if (args_count < 2) { - return jerry_create_undefined (); + return jerry_undefined (); } bool is_key_value_pairs = false; - jerry_value_t result = jerry_get_array_from_container (args_p[0], &is_key_value_pairs); + jerry_value_t result = jerry_container_to_array (args_p[0], &is_key_value_pairs); TEST_ASSERT (is_key_value_pairs == jerry_value_is_true (args_p[1])); return result; @@ -58,15 +58,15 @@ run_eval (const char *source_p) { jerry_value_t result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); } /* run_eval */ static void run_eval_error (const char *source_p) { jerry_value_t result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - jerry_release_value (result); + jerry_value_free (result); } /* run_eval_error */ int @@ -74,8 +74,8 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_MAP) || !jerry_is_feature_enabled (JERRY_FEATURE_SET) - || !jerry_is_feature_enabled (JERRY_FEATURE_WEAKMAP) || !jerry_is_feature_enabled (JERRY_FEATURE_WEAKSET)) + if (!jerry_feature_enabled (JERRY_FEATURE_MAP) || !jerry_feature_enabled (JERRY_FEATURE_SET) + || !jerry_feature_enabled (JERRY_FEATURE_WEAKMAP) || !jerry_feature_enabled (JERRY_FEATURE_WEAKSET)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Containers are disabled!\n"); jerry_cleanup (); @@ -83,63 +83,63 @@ main (void) } jerry_value_t instance_check; - jerry_value_t global = jerry_get_global_object (); - jerry_value_t map_str = jerry_create_string ((jerry_char_t *) "Map"); - jerry_value_t set_str = jerry_create_string ((jerry_char_t *) "Set"); - jerry_value_t weakmap_str = jerry_create_string ((jerry_char_t *) "WeakMap"); - jerry_value_t weakset_str = jerry_create_string ((jerry_char_t *) "WeakSet"); - jerry_value_t global_map = jerry_get_property (global, map_str); - jerry_value_t global_set = jerry_get_property (global, set_str); - jerry_value_t global_weakmap = jerry_get_property (global, weakmap_str); - jerry_value_t global_weakset = jerry_get_property (global, weakset_str); - - jerry_value_t function = jerry_create_external_function (create_array_from_container_handler); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "create_array_from_container"); - jerry_value_t res = jerry_set_property (global, name, function); - TEST_ASSERT (!jerry_value_is_error (res)); - - jerry_release_value (res); - jerry_release_value (name); - jerry_release_value (function); - - jerry_release_value (global); - - jerry_release_value (map_str); - jerry_release_value (set_str); - jerry_release_value (weakmap_str); - jerry_release_value (weakset_str); - - jerry_value_t empty_map = jerry_create_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); - TEST_ASSERT (jerry_get_container_type (empty_map) == JERRY_CONTAINER_TYPE_MAP); - instance_check = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, empty_map, global_map); + jerry_value_t global = jerry_current_realm (); + jerry_value_t map_str = jerry_string_sz ("Map"); + jerry_value_t set_str = jerry_string_sz ("Set"); + jerry_value_t weakmap_str = jerry_string_sz ("WeakMap"); + jerry_value_t weakset_str = jerry_string_sz ("WeakSet"); + jerry_value_t global_map = jerry_object_get (global, map_str); + jerry_value_t global_set = jerry_object_get (global, set_str); + jerry_value_t global_weakmap = jerry_object_get (global, weakmap_str); + jerry_value_t global_weakset = jerry_object_get (global, weakset_str); + + jerry_value_t function = jerry_function_external (create_array_from_container_handler); + jerry_value_t name = jerry_string_sz ("create_array_from_container"); + jerry_value_t res = jerry_object_set (global, name, function); + TEST_ASSERT (!jerry_value_is_exception (res)); + + jerry_value_free (res); + jerry_value_free (name); + jerry_value_free (function); + + jerry_value_free (global); + + jerry_value_free (map_str); + jerry_value_free (set_str); + jerry_value_free (weakmap_str); + jerry_value_free (weakset_str); + + jerry_value_t empty_map = jerry_container (JERRY_CONTAINER_TYPE_MAP, NULL, 0); + TEST_ASSERT (jerry_container_type (empty_map) == JERRY_CONTAINER_TYPE_MAP); + instance_check = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, empty_map, global_map); TEST_ASSERT (jerry_value_is_true (instance_check)); - jerry_release_value (instance_check); - jerry_release_value (global_map); - jerry_release_value (empty_map); + jerry_value_free (instance_check); + jerry_value_free (global_map); + jerry_value_free (empty_map); - jerry_value_t empty_set = jerry_create_container (JERRY_CONTAINER_TYPE_SET, NULL, 0); - TEST_ASSERT (jerry_get_container_type (empty_set) == JERRY_CONTAINER_TYPE_SET); - instance_check = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, empty_set, global_set); + jerry_value_t empty_set = jerry_container (JERRY_CONTAINER_TYPE_SET, NULL, 0); + TEST_ASSERT (jerry_container_type (empty_set) == JERRY_CONTAINER_TYPE_SET); + instance_check = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, empty_set, global_set); TEST_ASSERT (jerry_value_is_true (instance_check)); - jerry_release_value (instance_check); - jerry_release_value (global_set); - jerry_release_value (empty_set); + jerry_value_free (instance_check); + jerry_value_free (global_set); + jerry_value_free (empty_set); - jerry_value_t empty_weakmap = jerry_create_container (JERRY_CONTAINER_TYPE_WEAKMAP, NULL, 0); - TEST_ASSERT (jerry_get_container_type (empty_weakmap) == JERRY_CONTAINER_TYPE_WEAKMAP); - instance_check = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, empty_weakmap, global_weakmap); + jerry_value_t empty_weakmap = jerry_container (JERRY_CONTAINER_TYPE_WEAKMAP, NULL, 0); + TEST_ASSERT (jerry_container_type (empty_weakmap) == JERRY_CONTAINER_TYPE_WEAKMAP); + instance_check = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, empty_weakmap, global_weakmap); TEST_ASSERT (jerry_value_is_true (instance_check)); - jerry_release_value (instance_check); - jerry_release_value (global_weakmap); - jerry_release_value (empty_weakmap); + jerry_value_free (instance_check); + jerry_value_free (global_weakmap); + jerry_value_free (empty_weakmap); - jerry_value_t empty_weakset = jerry_create_container (JERRY_CONTAINER_TYPE_WEAKSET, NULL, 0); - TEST_ASSERT (jerry_get_container_type (empty_weakset) == JERRY_CONTAINER_TYPE_WEAKSET); - instance_check = jerry_binary_operation (JERRY_BIN_OP_INSTANCEOF, empty_weakset, global_weakset); + jerry_value_t empty_weakset = jerry_container (JERRY_CONTAINER_TYPE_WEAKSET, NULL, 0); + TEST_ASSERT (jerry_container_type (empty_weakset) == JERRY_CONTAINER_TYPE_WEAKSET); + instance_check = jerry_binary_op (JERRY_BIN_OP_INSTANCEOF, empty_weakset, global_weakset); TEST_ASSERT (jerry_value_is_true (instance_check)); - jerry_release_value (instance_check); - jerry_release_value (global_weakset); - jerry_release_value (empty_weakset); + jerry_value_free (instance_check); + jerry_value_free (global_weakset); + jerry_value_free (empty_weakset); const jerry_char_t source[] = TEST_STRING_LITERAL ("(function () {\n" " var o1 = {}\n" @@ -153,11 +153,11 @@ main (void) jerry_value_t result = jerry_eval (source, sizeof (source) - 1, JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_object (result)); - jerry_set_object_native_pointer (result, (void *) &global_counter, &native_info); - jerry_release_value (result); + jerry_object_set_native_ptr (result, &native_info, (void *) &global_counter); + jerry_value_free (result); global_counter = 0; - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (global_counter == 1); run_eval ("function assert(v) {\n" diff --git a/tests/unit-core/test-context-data.c b/tests/unit-core/test-context-data.c index d01f713355..6af81db2c3 100644 --- a/tests/unit-core/test-context-data.c +++ b/tests/unit-core/test-context-data.c @@ -135,10 +135,10 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - TEST_ASSERT (!strcmp (*((const char **) jerry_get_context_data (&manager1)), "item1")); - TEST_ASSERT (!strcmp (*((const char **) jerry_get_context_data (&manager2)), "item2")); - TEST_ASSERT (jerry_get_context_data (&manager3) == NULL); - TEST_ASSERT (jerry_get_context_data (&manager4) == NULL); + TEST_ASSERT (!strcmp (*((const char **) jerry_context_data (&manager1)), "item1")); + TEST_ASSERT (!strcmp (*((const char **) jerry_context_data (&manager2)), "item2")); + TEST_ASSERT (jerry_context_data (&manager3) == NULL); + TEST_ASSERT (jerry_context_data (&manager4) == NULL); TEST_ASSERT (test_context_data1_new_called); TEST_ASSERT (test_context_data2_new_called); diff --git a/tests/unit-core/test-dataview.c b/tests/unit-core/test-dataview.c index b377de69c8..089bbb9a60 100644 --- a/tests/unit-core/test-dataview.c +++ b/tests/unit-core/test-dataview.c @@ -22,82 +22,82 @@ int main (void) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_DATAVIEW)) + if (!jerry_feature_enabled (JERRY_FEATURE_DATAVIEW)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "DataView support is disabled!\n"); return 0; } /* DataView builtin requires the TypedArray builtin */ - TEST_ASSERT (jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY)); + TEST_ASSERT (jerry_feature_enabled (JERRY_FEATURE_TYPEDARRAY)); jerry_init (JERRY_INIT_EMPTY); /* Test accessors */ - jerry_value_t arraybuffer = jerry_create_arraybuffer (16); - jerry_value_t view1 = jerry_create_dataview (arraybuffer, 0, 16); - TEST_ASSERT (!jerry_value_is_error (view1)); + jerry_value_t arraybuffer = jerry_arraybuffer (16); + jerry_value_t view1 = jerry_dataview (arraybuffer, 0, 16); + TEST_ASSERT (!jerry_value_is_exception (view1)); TEST_ASSERT (jerry_value_is_dataview (view1)); jerry_length_t byteOffset = 0; jerry_length_t byteLength = 0; ; - jerry_value_t internal_buffer = jerry_get_dataview_buffer (view1, &byteOffset, &byteLength); - TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, internal_buffer, arraybuffer)); + jerry_value_t internal_buffer = jerry_dataview_buffer (view1, &byteOffset, &byteLength); + TEST_ASSERT (jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, internal_buffer, arraybuffer)); TEST_ASSERT (byteOffset == 0); TEST_ASSERT (byteLength == 16); - jerry_release_value (internal_buffer); + jerry_value_free (internal_buffer); - jerry_value_t view2 = jerry_create_dataview (arraybuffer, 12, 4); - TEST_ASSERT (!jerry_value_is_error (view1)); + jerry_value_t view2 = jerry_dataview (arraybuffer, 12, 4); + TEST_ASSERT (!jerry_value_is_exception (view1)); TEST_ASSERT (jerry_value_is_dataview (view2)); - internal_buffer = jerry_get_dataview_buffer (view2, &byteOffset, &byteLength); - TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, internal_buffer, arraybuffer)); + internal_buffer = jerry_dataview_buffer (view2, &byteOffset, &byteLength); + TEST_ASSERT (jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, internal_buffer, arraybuffer)); TEST_ASSERT (byteOffset == 12); TEST_ASSERT (byteLength == 4); - jerry_release_value (internal_buffer); + jerry_value_free (internal_buffer); /* Test invalid construction */ - jerry_value_t empty_object = jerry_create_object (); - jerry_value_t view3 = jerry_create_dataview (empty_object, 20, 10); - TEST_ASSERT (jerry_value_is_error (view3)); - jerry_value_t error_obj = jerry_get_value_from_error (view3, true); - TEST_ASSERT (jerry_get_error_type (error_obj) == JERRY_ERROR_TYPE); - jerry_release_value (error_obj); - jerry_release_value (empty_object); - - jerry_value_t view4 = jerry_create_dataview (arraybuffer, 20, 10); - TEST_ASSERT (jerry_value_is_error (view3)); - error_obj = jerry_get_value_from_error (view4, true); - TEST_ASSERT (jerry_get_error_type (error_obj) == JERRY_ERROR_RANGE); - jerry_release_value (error_obj); + jerry_value_t empty_object = jerry_object (); + jerry_value_t view3 = jerry_dataview (empty_object, 20, 10); + TEST_ASSERT (jerry_value_is_exception (view3)); + jerry_value_t error_obj = jerry_exception_value (view3, true); + TEST_ASSERT (jerry_error_type (error_obj) == JERRY_ERROR_TYPE); + jerry_value_free (error_obj); + jerry_value_free (empty_object); + + jerry_value_t view4 = jerry_dataview (arraybuffer, 20, 10); + TEST_ASSERT (jerry_value_is_exception (view3)); + error_obj = jerry_exception_value (view4, true); + TEST_ASSERT (jerry_error_type (error_obj) == JERRY_ERROR_RANGE); + jerry_value_free (error_obj); /* Test getting/setting values */ - jerry_value_t global_obj = jerry_get_global_object (); - jerry_value_t view1_str = jerry_create_string ((const jerry_char_t *) "view1"); - jerry_value_t view2_str = jerry_create_string ((const jerry_char_t *) "view2"); - TEST_ASSERT (jerry_set_property (global_obj, view1_str, view1)); - TEST_ASSERT (jerry_set_property (global_obj, view2_str, view2)); + jerry_value_t global_obj = jerry_current_realm (); + jerry_value_t view1_str = jerry_string_sz ("view1"); + jerry_value_t view2_str = jerry_string_sz ("view2"); + TEST_ASSERT (jerry_object_set (global_obj, view1_str, view1)); + TEST_ASSERT (jerry_object_set (global_obj, view2_str, view2)); - jerry_release_value (view1_str); - jerry_release_value (view2_str); - jerry_release_value (global_obj); + jerry_value_free (view1_str); + jerry_value_free (view2_str); + jerry_value_free (global_obj); const jerry_char_t set_src[] = "view1.setInt16 (12, 255)"; TEST_ASSERT (jerry_value_is_undefined (jerry_eval (set_src, sizeof (set_src) - 1, JERRY_PARSE_NO_OPTS))); const jerry_char_t get_src[] = "view2.getInt16 (0)"; - TEST_ASSERT (jerry_get_number_value (jerry_eval (get_src, sizeof (get_src) - 1, JERRY_PARSE_NO_OPTS)) == 255); + TEST_ASSERT (jerry_value_as_number (jerry_eval (get_src, sizeof (get_src) - 1, JERRY_PARSE_NO_OPTS)) == 255); const jerry_char_t get_src_little_endian[] = "view2.getInt16 (0, true)"; TEST_ASSERT ( - jerry_get_number_value (jerry_eval (get_src_little_endian, sizeof (get_src_little_endian) - 1, JERRY_PARSE_NO_OPTS)) + jerry_value_as_number (jerry_eval (get_src_little_endian, sizeof (get_src_little_endian) - 1, JERRY_PARSE_NO_OPTS)) == -256); /* Cleanup */ - jerry_release_value (view2); - jerry_release_value (view1); - jerry_release_value (arraybuffer); + jerry_value_free (view2); + jerry_value_free (view1); + jerry_value_free (arraybuffer); jerry_cleanup (); diff --git a/tests/unit-core/test-error-callback.c b/tests/unit-core/test-error-callback.c index 7f551a70cc..e9bdc62a5e 100644 --- a/tests/unit-core/test-error-callback.c +++ b/tests/unit-core/test-error-callback.c @@ -30,21 +30,21 @@ error_object_created_callback (const jerry_value_t error_object_t, /**< new erro error_object_created_callback_is_running = true; error_object_created_callback_count++; - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "message"); - jerry_value_t message = jerry_create_string ((const jerry_char_t *) "Replaced message!"); + jerry_value_t name = jerry_string_sz ("message"); + jerry_value_t message = jerry_string_sz ("Replaced message!"); - jerry_value_t result = jerry_set_property (error_object_t, name, message); + jerry_value_t result = jerry_object_set (error_object_t, name, message); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); /* This SyntaxError must not trigger a recusrsive call of the this callback. */ const char *source_p = "Syntax Error in JS!"; result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - TEST_ASSERT (jerry_value_is_error (result)); + TEST_ASSERT (jerry_value_is_exception (result)); - jerry_release_value (result); - jerry_release_value (message); - jerry_release_value (name); + jerry_value_free (result); + jerry_value_free (message); + jerry_value_free (name); error_object_created_callback_is_running = false; } /* error_object_created_callback */ @@ -57,7 +57,7 @@ run_test (const char *source_p) { jerry_value_t result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); } } /* run_test */ @@ -71,8 +71,7 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_set_error_object_created_callback (error_object_created_callback, - (void *) &error_object_created_callback_count); + jerry_error_created_cb (error_object_created_callback, (void *) &error_object_created_callback_count); run_test ("var result = false\n" "try {\n" @@ -85,7 +84,7 @@ main (void) run_test ("var error = new Error()\n" "error.message === 'Replaced message!'\n"); - jerry_release_value (jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Message")); + jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, "Message")); TEST_ASSERT (error_object_created_callback_count == 11); diff --git a/tests/unit-core/test-external-string.c b/tests/unit-core/test-external-string.c index 5821c3da7e..e6f51ae636 100644 --- a/tests/unit-core/test-external-string.c +++ b/tests/unit-core/test-external-string.c @@ -67,140 +67,140 @@ main (void) bool is_external; /* Test external callback calls. */ - jerry_string_set_external_free_callback (external_string_free_callback_1); - jerry_value_t external_string = jerry_create_external_string ((jerry_char_t *) external_1, NULL); + jerry_string_external_free_cb (external_string_free_callback_1); + jerry_value_t external_string = jerry_string_external_sz (external_1, NULL); TEST_ASSERT (free_count == 0); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (is_external); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, NULL) == NULL); - jerry_release_value (external_string); + TEST_ASSERT (jerry_string_user_ptr (external_string, NULL) == NULL); + jerry_value_free (external_string); TEST_ASSERT (free_count == 1); - jerry_string_set_external_free_callback (NULL); - external_string = jerry_create_external_string ((jerry_char_t *) external_1, (void *) &free_count); + jerry_string_external_free_cb (NULL); + external_string = jerry_string_external_sz (external_1, (void *) &free_count); TEST_ASSERT (free_count == 1); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == (void *) &free_count); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == (void *) &free_count); TEST_ASSERT (is_external); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, NULL) == (void *) &free_count); - jerry_release_value (external_string); + TEST_ASSERT (jerry_string_user_ptr (external_string, NULL) == (void *) &free_count); + jerry_value_free (external_string); TEST_ASSERT (free_count == 1); - jerry_string_set_external_free_callback (external_string_free_callback_2); - external_string = jerry_create_external_string ((jerry_char_t *) external_2, (void *) &free_count); + jerry_string_external_free_cb (external_string_free_callback_2); + external_string = jerry_string_external_sz (external_2, (void *) &free_count); TEST_ASSERT (free_count == 2); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (!is_external); - jerry_release_value (external_string); + jerry_value_free (external_string); TEST_ASSERT (free_count == 2); - jerry_string_set_external_free_callback (NULL); - external_string = jerry_create_external_string ((jerry_char_t *) external_2, (void *) &free_count); + jerry_string_external_free_cb (NULL); + external_string = jerry_string_external_sz (external_2, (void *) &free_count); TEST_ASSERT (free_count == 2); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (!is_external); - jerry_release_value (external_string); + jerry_value_free (external_string); TEST_ASSERT (free_count == 2); - jerry_string_set_external_free_callback (external_string_free_callback_3); - external_string = jerry_create_external_string ((jerry_char_t *) external_3, (void *) external_3); + jerry_string_external_free_cb (external_string_free_callback_3); + external_string = jerry_string_external_sz (external_3, (void *) external_3); TEST_ASSERT (free_count == 3); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (!is_external); - jerry_release_value (external_string); + jerry_value_free (external_string); TEST_ASSERT (free_count == 3); - jerry_string_set_external_free_callback (NULL); - external_string = jerry_create_external_string ((jerry_char_t *) external_3, (void *) external_3); + jerry_string_external_free_cb (NULL); + external_string = jerry_string_external_sz (external_3, (void *) external_3); TEST_ASSERT (free_count == 3); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (!is_external); - jerry_release_value (external_string); + jerry_value_free (external_string); TEST_ASSERT (free_count == 3); /* Test string comparison. */ - jerry_string_set_external_free_callback (external_string_free_callback_1); - external_string = jerry_create_external_string ((jerry_char_t *) external_1, NULL); - jerry_value_t other_string = jerry_create_string ((jerry_char_t *) external_1); + jerry_string_external_free_cb (external_string_free_callback_1); + external_string = jerry_string_external_sz (external_1, NULL); + jerry_value_t other_string = jerry_string_sz (external_1); - jerry_value_t result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, external_string, other_string); + jerry_value_t result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, external_string, other_string); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, external_string, external_string); + result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, external_string, external_string); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); TEST_ASSERT (free_count == 3); - jerry_release_value (external_string); + jerry_value_free (external_string); TEST_ASSERT (free_count == 4); - jerry_release_value (other_string); + jerry_value_free (other_string); /* Test getting string. */ - jerry_string_set_external_free_callback (external_string_free_callback_1); - external_string = jerry_create_external_string ((jerry_char_t *) external_1, NULL); + jerry_string_external_free_cb (external_string_free_callback_1); + external_string = jerry_string_external_sz (external_1, NULL); size_t length = strlen (external_1); TEST_ASSERT (jerry_value_is_string (external_string)); - TEST_ASSERT (jerry_get_string_size (external_string) == length); - TEST_ASSERT (jerry_get_string_length (external_string) == length); + TEST_ASSERT (jerry_string_size (external_string, JERRY_ENCODING_CESU8) == length); + TEST_ASSERT (jerry_string_length (external_string) == length); jerry_char_t buf[128]; - jerry_string_to_char_buffer (external_string, buf, sizeof (buf)); + jerry_string_to_buffer (external_string, buf, sizeof (buf), JERRY_ENCODING_CESU8); TEST_ASSERT (memcmp (buf, external_1, length) == 0); TEST_ASSERT (free_count == 4); - jerry_release_value (external_string); + jerry_value_free (external_string); TEST_ASSERT (free_count == 5); /* Test property access. */ - jerry_string_set_external_free_callback (NULL); - external_string = jerry_create_external_string ((jerry_char_t *) external_4, NULL); - other_string = jerry_create_string ((jerry_char_t *) external_4); + jerry_string_external_free_cb (NULL); + external_string = jerry_string_external_sz (external_4, NULL); + other_string = jerry_string_sz (external_4); - jerry_value_t obj = jerry_create_object (); - result = jerry_set_property (obj, external_string, other_string); + jerry_value_t obj = jerry_object (); + result = jerry_object_set (obj, external_string, other_string); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - jerry_value_t get_result = jerry_get_property (obj, other_string); + jerry_value_t get_result = jerry_object_get (obj, other_string); TEST_ASSERT (jerry_value_is_string (get_result)); - result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, get_result, external_string); - jerry_release_value (get_result); + result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, get_result, external_string); + jerry_value_free (get_result); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_set_property (obj, other_string, external_string); + result = jerry_object_set (obj, other_string, external_string); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - get_result = jerry_get_property (obj, external_string); + get_result = jerry_object_get (obj, external_string); TEST_ASSERT (jerry_value_is_string (get_result)); - result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, get_result, other_string); - jerry_release_value (get_result); + result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, get_result, other_string); + jerry_value_free (get_result); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (obj); - jerry_release_value (external_string); - jerry_release_value (other_string); + jerry_value_free (obj); + jerry_value_free (external_string); + jerry_value_free (other_string); - external_string = jerry_create_boolean (true); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + external_string = jerry_boolean (true); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (!is_external); - jerry_release_value (external_string); + jerry_value_free (external_string); - external_string = jerry_create_object (); - TEST_ASSERT (jerry_string_get_external_user_pointer (external_string, &is_external) == NULL); + external_string = jerry_object (); + TEST_ASSERT (jerry_string_user_ptr (external_string, &is_external) == NULL); TEST_ASSERT (!is_external); - jerry_release_value (external_string); + jerry_value_free (external_string); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-from-property-descriptor.c b/tests/unit-core/test-from-property-descriptor.c index 8b9c646b1d..6134c0c7b4 100644 --- a/tests/unit-core/test-from-property-descriptor.c +++ b/tests/unit-core/test-from-property-descriptor.c @@ -25,55 +25,55 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object = jerry_create_object (); - jerry_value_t prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "length"); - jerry_value_t value = jerry_create_boolean (true); + jerry_value_t object = jerry_object (); + jerry_value_t prop_name = jerry_string_sz ("length"); + jerry_value_t value = jerry_boolean (true); - TEST_ASSERT (jerry_set_property (object, prop_name, prop_name)); - TEST_ASSERT (jerry_has_property (object, prop_name)); - TEST_ASSERT (jerry_has_own_property (object, prop_name)); + TEST_ASSERT (jerry_object_set (object, prop_name, prop_name)); + TEST_ASSERT (jerry_object_has (object, prop_name)); + TEST_ASSERT (jerry_object_has_own (object, prop_name)); jerry_property_descriptor_t prop_desc; - TEST_ASSERT (jerry_get_own_property_descriptor (object, prop_name, &prop_desc)); + TEST_ASSERT (jerry_object_get_own_prop (object, prop_name, &prop_desc)); - jerry_value_t from_object = jerry_from_property_descriptor (&prop_desc); + jerry_value_t from_object = jerry_property_descriptor_to_object (&prop_desc); - prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "value"); - value = jerry_get_property (from_object, prop_name); + prop_name = jerry_string_sz ("value"); + value = jerry_object_get (from_object, prop_name); TEST_ASSERT (value == prop_desc.value); - prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "writable"); - value = jerry_get_property (from_object, prop_name); + prop_name = jerry_string_sz ("writable"); + value = jerry_object_get (from_object, prop_name); TEST_ASSERT (jerry_value_is_true (value) == ((prop_desc.flags & JERRY_PROP_IS_WRITABLE) != 0)); - prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "enumerable"); - value = jerry_get_property (from_object, prop_name); + prop_name = jerry_string_sz ("enumerable"); + value = jerry_object_get (from_object, prop_name); TEST_ASSERT (jerry_value_is_true (value) == ((prop_desc.flags & JERRY_PROP_IS_ENUMERABLE) != 0)); - prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "configurable"); - value = jerry_get_property (from_object, prop_name); + prop_name = jerry_string_sz ("configurable"); + value = jerry_object_get (from_object, prop_name); TEST_ASSERT (jerry_value_is_true (value) == ((prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE) != 0)); - jerry_release_value (object); - jerry_release_value (prop_name); - jerry_release_value (value); - jerry_release_value (from_object); + jerry_value_free (object); + jerry_value_free (prop_name); + jerry_value_free (value); + jerry_value_free (from_object); jerry_property_descriptor_free (&prop_desc); prop_desc.flags = JERRY_PROP_IS_CONFIGURABLE; - from_object = jerry_from_property_descriptor (&prop_desc); - TEST_ASSERT (jerry_value_is_error (from_object)); - jerry_release_value (from_object); + from_object = jerry_property_descriptor_to_object (&prop_desc); + TEST_ASSERT (jerry_value_is_exception (from_object)); + jerry_value_free (from_object); prop_desc.flags = JERRY_PROP_IS_ENUMERABLE; - from_object = jerry_from_property_descriptor (&prop_desc); - TEST_ASSERT (jerry_value_is_error (from_object)); - jerry_release_value (from_object); + from_object = jerry_property_descriptor_to_object (&prop_desc); + TEST_ASSERT (jerry_value_is_exception (from_object)); + jerry_value_free (from_object); prop_desc.flags = JERRY_PROP_IS_WRITABLE; - from_object = jerry_from_property_descriptor (&prop_desc); - TEST_ASSERT (jerry_value_is_error (from_object)); - jerry_release_value (from_object); + from_object = jerry_property_descriptor_to_object (&prop_desc); + TEST_ASSERT (jerry_value_is_exception (from_object)); + jerry_value_free (from_object); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-get-own-property.c b/tests/unit-core/test-get-own-property.c index 433d2dc507..43c653288d 100644 --- a/tests/unit-core/test-get-own-property.c +++ b/tests/unit-core/test-get-own-property.c @@ -35,9 +35,9 @@ compare_string (jerry_value_t value, /**< value to compare */ size_t size = strlen (string_p); TEST_ASSERT (size <= sizeof (string_buffer)); - TEST_ASSERT (size == jerry_get_string_size (value)); + TEST_ASSERT (size == jerry_string_size (value, JERRY_ENCODING_CESU8)); - jerry_string_to_char_buffer (value, string_buffer, (jerry_size_t) size); + jerry_string_to_buffer (value, string_buffer, (jerry_size_t) size, JERRY_ENCODING_CESU8); TEST_ASSERT (memcmp (string_p, string_buffer, size) == 0); } /* compare_string */ @@ -47,97 +47,97 @@ main (void) TEST_INIT (); jerry_init (JERRY_INIT_EMPTY); - jerry_value_t pp_string = jerry_create_string ((const jerry_char_t *) "pp"); - jerry_value_t qq_string = jerry_create_string ((const jerry_char_t *) "qq"); - jerry_value_t rr_string = jerry_create_string ((const jerry_char_t *) "rr"); + jerry_value_t pp_string = jerry_string_sz ("pp"); + jerry_value_t qq_string = jerry_string_sz ("qq"); + jerry_value_t rr_string = jerry_string_sz ("rr"); jerry_value_t object = create_object ("'use strict';\n" "({ pp:'A', get qq() { return 'B' } })"); - jerry_value_t result = jerry_get_own_property (object, pp_string, object, NULL); + jerry_value_t result = jerry_object_find_own (object, pp_string, object, NULL); compare_string (result, "A"); - jerry_release_value (result); + jerry_value_free (result); bool found = false; - result = jerry_get_own_property (object, pp_string, object, &found); + result = jerry_object_find_own (object, pp_string, object, &found); compare_string (result, "A"); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_get_own_property (object, qq_string, object, NULL); + result = jerry_object_find_own (object, qq_string, object, NULL); compare_string (result, "B"); - jerry_release_value (result); + jerry_value_free (result); found = false; - result = jerry_get_own_property (object, qq_string, object, &found); + result = jerry_object_find_own (object, qq_string, object, &found); compare_string (result, "B"); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_get_own_property (object, rr_string, object, NULL); + result = jerry_object_find_own (object, rr_string, object, NULL); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); found = true; - result = jerry_get_own_property (object, rr_string, object, &found); + result = jerry_object_find_own (object, rr_string, object, &found); TEST_ASSERT (jerry_value_is_undefined (result)); TEST_ASSERT (!found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (object); + jerry_value_free (object); object = create_object ("'use strict';\n" "Object.create({ pp:'Found!' })\n"); found = true; /* Does not check prototype. */ - result = jerry_get_own_property (object, pp_string, object, &found); + result = jerry_object_find_own (object, pp_string, object, &found); TEST_ASSERT (jerry_value_is_undefined (result)); TEST_ASSERT (!found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (object); + jerry_value_free (object); object = create_object ("'use strict';\n" "var obj = Object.create({ get pp() { return this.qq } })\n" "Object.defineProperty(obj, 'qq', { value: 'Prop' })\n" "obj"); - jerry_value_t prototype = jerry_get_prototype (object); + jerry_value_t prototype = jerry_object_proto (object); TEST_ASSERT (jerry_value_is_object (prototype)); found = false; - result = jerry_get_own_property (prototype, pp_string, object, &found); + result = jerry_object_find_own (prototype, pp_string, object, &found); compare_string (result, "Prop"); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (prototype); - jerry_release_value (object); + jerry_value_free (prototype); + jerry_value_free (object); /* Error cases. */ - jerry_value_t invalid_arg = jerry_create_null (); - object = jerry_create_object (); + jerry_value_t invalid_arg = jerry_null (); + object = jerry_object (); found = true; - result = jerry_get_own_property (invalid_arg, pp_string, object, &found); - TEST_ASSERT (jerry_value_is_error (result)); + result = jerry_object_find_own (invalid_arg, pp_string, object, &found); + TEST_ASSERT (jerry_value_is_exception (result)); TEST_ASSERT (!found); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_get_own_property (object, pp_string, invalid_arg, NULL); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_object_find_own (object, pp_string, invalid_arg, NULL); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); found = true; - result = jerry_get_own_property (object, invalid_arg, object, &found); - TEST_ASSERT (jerry_value_is_error (result)); + result = jerry_object_find_own (object, invalid_arg, object, &found); + TEST_ASSERT (jerry_value_is_exception (result)); TEST_ASSERT (!found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (object); - jerry_release_value (invalid_arg); + jerry_value_free (object); + jerry_value_free (invalid_arg); - if (jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (jerry_feature_enabled (JERRY_FEATURE_PROXY)) { object = create_object ("'use strict';\n" "var proxy = new Proxy({}, {\n" @@ -150,21 +150,21 @@ main (void) "Object.defineProperty(obj, 'pp', { value: 'Prop' })\n" "obj"); - prototype = jerry_get_prototype (object); + prototype = jerry_object_proto (object); found = false; - result = jerry_get_own_property (prototype, pp_string, object, &found); + result = jerry_object_find_own (prototype, pp_string, object, &found); compare_string (result, "Prop"); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); found = false; - result = jerry_get_own_property (prototype, qq_string, object, &found); + result = jerry_object_find_own (prototype, qq_string, object, &found); TEST_ASSERT (jerry_value_is_undefined (result)); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (prototype); - jerry_release_value (object); + jerry_value_free (prototype); + jerry_value_free (object); object = create_object ("'use strict';\n" "(new Proxy({}, {\n" @@ -174,38 +174,38 @@ main (void) "}))\n"); found = false; - result = jerry_get_own_property (object, qq_string, object, &found); - TEST_ASSERT (jerry_value_is_error (result)); + result = jerry_object_find_own (object, qq_string, object, &found); + TEST_ASSERT (jerry_value_is_exception (result)); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (object); + jerry_value_free (object); } - if (jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { object = create_object ("'use strict'\n" "var sym = Symbol();\n" "({ pp:sym, [sym]:'Prop' })"); found = false; - jerry_value_t symbol = jerry_get_own_property (object, pp_string, object, &found); + jerry_value_t symbol = jerry_object_find_own (object, pp_string, object, &found); TEST_ASSERT (jerry_value_is_symbol (symbol)); TEST_ASSERT (found); found = false; - result = jerry_get_own_property (object, symbol, object, &found); + result = jerry_object_find_own (object, symbol, object, &found); compare_string (result, "Prop"); TEST_ASSERT (found); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (symbol); - jerry_release_value (object); + jerry_value_free (symbol); + jerry_value_free (object); } - jerry_release_value (pp_string); - jerry_release_value (qq_string); - jerry_release_value (rr_string); + jerry_value_free (pp_string); + jerry_value_free (qq_string); + jerry_value_free (rr_string); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-has-property.c b/tests/unit-core/test-has-property.c index af3094299f..e2ea659075 100644 --- a/tests/unit-core/test-has-property.c +++ b/tests/unit-core/test-has-property.c @@ -23,7 +23,7 @@ assert_boolean_and_release (jerry_value_t result, bool expected) { TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result) == expected); - jerry_release_value (result); + jerry_value_free (result); } /* assert_boolean_and_release */ int @@ -33,38 +33,38 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object = jerry_create_object (); - jerry_value_t prop_name = jerry_create_string_from_utf8 ((jerry_char_t *) "something"); - jerry_value_t prop_value = jerry_create_boolean (true); - jerry_value_t proto_object = jerry_create_object (); + jerry_value_t object = jerry_object (); + jerry_value_t prop_name = jerry_string_sz ("something"); + jerry_value_t prop_value = jerry_boolean (true); + jerry_value_t proto_object = jerry_object (); /* Assert that an empty object does not have the property in question */ - assert_boolean_and_release (jerry_has_property (object, prop_name), false); - assert_boolean_and_release (jerry_has_own_property (object, prop_name), false); + assert_boolean_and_release (jerry_object_has (object, prop_name), false); + assert_boolean_and_release (jerry_object_has_own (object, prop_name), false); - assert_boolean_and_release (jerry_set_prototype (object, proto_object), true); + assert_boolean_and_release (jerry_object_set_proto (object, proto_object), true); /* If the object has a prototype, that still means it doesn't have the property */ - assert_boolean_and_release (jerry_has_property (object, prop_name), false); - assert_boolean_and_release (jerry_has_own_property (object, prop_name), false); + assert_boolean_and_release (jerry_object_has (object, prop_name), false); + assert_boolean_and_release (jerry_object_has_own (object, prop_name), false); - assert_boolean_and_release (jerry_set_property (proto_object, prop_name, prop_value), true); + assert_boolean_and_release (jerry_object_set (proto_object, prop_name, prop_value), true); /* After setting the property on the prototype, it must be there, but not on the object */ - assert_boolean_and_release (jerry_has_property (object, prop_name), true); - assert_boolean_and_release (jerry_has_own_property (object, prop_name), false); + assert_boolean_and_release (jerry_object_has (object, prop_name), true); + assert_boolean_and_release (jerry_object_has_own (object, prop_name), false); - TEST_ASSERT (jerry_delete_property (proto_object, prop_name)); - assert_boolean_and_release (jerry_set_property (object, prop_name, prop_value), true); + TEST_ASSERT (jerry_object_delete (proto_object, prop_name)); + assert_boolean_and_release (jerry_object_set (object, prop_name, prop_value), true); /* After relocating the property onto the object, it must be there */ - assert_boolean_and_release (jerry_has_property (object, prop_name), true); - assert_boolean_and_release (jerry_has_own_property (object, prop_name), true); + assert_boolean_and_release (jerry_object_has (object, prop_name), true); + assert_boolean_and_release (jerry_object_has_own (object, prop_name), true); - jerry_release_value (object); - jerry_release_value (prop_name); - jerry_release_value (prop_value); - jerry_release_value (proto_object); + jerry_value_free (object); + jerry_value_free (prop_name); + jerry_value_free (prop_value); + jerry_value_free (proto_object); jerry_cleanup (); diff --git a/tests/unit-core/test-internal-properties.c b/tests/unit-core/test-internal-properties.c index 01afd25625..3297ed1942 100644 --- a/tests/unit-core/test-internal-properties.c +++ b/tests/unit-core/test-internal-properties.c @@ -24,71 +24,71 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); - jerry_value_t prop_name_1 = jerry_create_string ((const jerry_char_t *) "foo"); - jerry_value_t prop_name_2 = jerry_create_string ((const jerry_char_t *) "non_hidden_prop"); + jerry_value_t prop_name_1 = jerry_string_sz ("foo"); + jerry_value_t prop_name_2 = jerry_string_sz ("non_hidden_prop"); jerry_value_t prop_name_3; - if (jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { - jerry_value_t prop_name_3_desc = jerry_create_string ((const jerry_char_t *) "bar"); - prop_name_3 = jerry_create_symbol (prop_name_3_desc); - jerry_release_value (prop_name_3_desc); + jerry_value_t prop_name_3_desc = jerry_string_sz ("bar"); + prop_name_3 = jerry_symbol_with_description (prop_name_3_desc); + jerry_value_free (prop_name_3_desc); } else { - prop_name_3 = jerry_create_string ((const jerry_char_t *) "non_hidden_string_prop"); + prop_name_3 = jerry_string_sz ("non_hidden_string_prop"); } - jerry_value_t internal_prop_name_1 = jerry_create_string ((const jerry_char_t *) "hidden_foo"); - jerry_value_t internal_prop_name_2 = jerry_create_string ((const jerry_char_t *) "hidden_prop"); + jerry_value_t internal_prop_name_1 = jerry_string_sz ("hidden_foo"); + jerry_value_t internal_prop_name_2 = jerry_string_sz ("hidden_prop"); jerry_value_t internal_prop_name_3; - if (jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { - jerry_value_t internal_prop_name_3_desc = jerry_create_string ((const jerry_char_t *) "bar"); - internal_prop_name_3 = jerry_create_symbol (internal_prop_name_3_desc); - jerry_release_value (internal_prop_name_3_desc); + jerry_value_t internal_prop_name_3_desc = jerry_string_sz ("bar"); + internal_prop_name_3 = jerry_symbol_with_description (internal_prop_name_3_desc); + jerry_value_free (internal_prop_name_3_desc); } else { - internal_prop_name_3 = jerry_create_string ((const jerry_char_t *) "hidden_string_prop"); + internal_prop_name_3 = jerry_string_sz ("hidden_string_prop"); } - jerry_value_t prop_value_1 = jerry_create_number (5.5); - jerry_value_t prop_value_2 = jerry_create_number (6.5); - jerry_value_t prop_value_3 = jerry_create_number (7.5); + jerry_value_t prop_value_1 = jerry_number (5.5); + jerry_value_t prop_value_2 = jerry_number (6.5); + jerry_value_t prop_value_3 = jerry_number (7.5); - jerry_value_t internal_prop_value_1 = jerry_create_number (8.5); - jerry_value_t internal_prop_value_2 = jerry_create_number (9.5); - jerry_value_t internal_prop_value_3 = jerry_create_number (10.5); + jerry_value_t internal_prop_value_1 = jerry_number (8.5); + jerry_value_t internal_prop_value_2 = jerry_number (9.5); + jerry_value_t internal_prop_value_3 = jerry_number (10.5); /* Test the normal [[Set]] method */ - bool set_result_1 = jerry_set_property (object, prop_name_1, prop_value_1); - bool set_result_2 = jerry_set_property (object, prop_name_2, prop_value_2); - bool set_result_3 = jerry_set_property (object, prop_name_3, prop_value_3); + bool set_result_1 = jerry_object_set (object, prop_name_1, prop_value_1); + bool set_result_2 = jerry_object_set (object, prop_name_2, prop_value_2); + bool set_result_3 = jerry_object_set (object, prop_name_3, prop_value_3); TEST_ASSERT (set_result_1); TEST_ASSERT (set_result_2); TEST_ASSERT (set_result_3); /* Test the internal [[Set]] method */ - bool set_internal_result_1 = jerry_set_internal_property (object, internal_prop_name_1, internal_prop_value_1); - bool set_internal_result_2 = jerry_set_internal_property (object, internal_prop_name_2, internal_prop_value_2); - bool set_internal_result_3 = jerry_set_internal_property (object, internal_prop_name_3, internal_prop_value_3); + bool set_internal_result_1 = jerry_object_set_internal (object, internal_prop_name_1, internal_prop_value_1); + bool set_internal_result_2 = jerry_object_set_internal (object, internal_prop_name_2, internal_prop_value_2); + bool set_internal_result_3 = jerry_object_set_internal (object, internal_prop_name_3, internal_prop_value_3); TEST_ASSERT (set_internal_result_1); TEST_ASSERT (set_internal_result_2); TEST_ASSERT (set_internal_result_3); /* Test the normal [[Has]] method. */ - jerry_value_t has_result_1 = jerry_has_property (object, prop_name_1); - jerry_value_t has_result_2 = jerry_has_property (object, prop_name_2); - jerry_value_t has_result_3 = jerry_has_property (object, prop_name_3); - jerry_value_t has_result_4 = jerry_has_property (object, internal_prop_name_1); - jerry_value_t has_result_5 = jerry_has_property (object, internal_prop_name_2); - jerry_value_t has_result_6 = jerry_has_property (object, internal_prop_name_3); + jerry_value_t has_result_1 = jerry_object_has (object, prop_name_1); + jerry_value_t has_result_2 = jerry_object_has (object, prop_name_2); + jerry_value_t has_result_3 = jerry_object_has (object, prop_name_3); + jerry_value_t has_result_4 = jerry_object_has (object, internal_prop_name_1); + jerry_value_t has_result_5 = jerry_object_has (object, internal_prop_name_2); + jerry_value_t has_result_6 = jerry_object_has (object, internal_prop_name_3); TEST_ASSERT (jerry_value_is_boolean (has_result_1) && jerry_value_is_true (has_result_1)); TEST_ASSERT (jerry_value_is_boolean (has_result_2) && jerry_value_is_true (has_result_2)); @@ -97,20 +97,20 @@ main (void) TEST_ASSERT (jerry_value_is_boolean (has_result_5) && !jerry_value_is_true (has_result_5)); TEST_ASSERT (jerry_value_is_boolean (has_result_6) && !jerry_value_is_true (has_result_6)); - jerry_release_value (has_result_1); - jerry_release_value (has_result_2); - jerry_release_value (has_result_3); - jerry_release_value (has_result_4); - jerry_release_value (has_result_5); - jerry_release_value (has_result_6); + jerry_value_free (has_result_1); + jerry_value_free (has_result_2); + jerry_value_free (has_result_3); + jerry_value_free (has_result_4); + jerry_value_free (has_result_5); + jerry_value_free (has_result_6); /* Test the internal [[Has]] method. */ - bool has_internal_result_1 = jerry_has_internal_property (object, prop_name_1); - bool has_internal_result_2 = jerry_has_internal_property (object, prop_name_2); - bool has_internal_result_3 = jerry_has_internal_property (object, prop_name_3); - bool has_internal_result_4 = jerry_has_internal_property (object, internal_prop_name_1); - bool has_internal_result_5 = jerry_has_internal_property (object, internal_prop_name_2); - bool has_internal_result_6 = jerry_has_internal_property (object, internal_prop_name_3); + bool has_internal_result_1 = jerry_object_has_internal (object, prop_name_1); + bool has_internal_result_2 = jerry_object_has_internal (object, prop_name_2); + bool has_internal_result_3 = jerry_object_has_internal (object, prop_name_3); + bool has_internal_result_4 = jerry_object_has_internal (object, internal_prop_name_1); + bool has_internal_result_5 = jerry_object_has_internal (object, internal_prop_name_2); + bool has_internal_result_6 = jerry_object_has_internal (object, internal_prop_name_3); TEST_ASSERT (!has_internal_result_1); TEST_ASSERT (!has_internal_result_2); @@ -120,56 +120,56 @@ main (void) TEST_ASSERT (has_internal_result_6); /* Test the normal [[Get]] method. */ - jerry_value_t get_result_1 = jerry_get_property (object, prop_name_1); - jerry_value_t get_result_2 = jerry_get_property (object, prop_name_2); - jerry_value_t get_result_3 = jerry_get_property (object, prop_name_3); - jerry_value_t get_result_4 = jerry_get_property (object, internal_prop_name_1); - jerry_value_t get_result_5 = jerry_get_property (object, internal_prop_name_2); - jerry_value_t get_result_6 = jerry_get_property (object, internal_prop_name_3); - - TEST_ASSERT (jerry_value_is_number (get_result_1) && jerry_get_number_value (get_result_1) == 5.5); - TEST_ASSERT (jerry_value_is_number (get_result_2) && jerry_get_number_value (get_result_2) == 6.5); - TEST_ASSERT (jerry_value_is_number (get_result_3) && jerry_get_number_value (get_result_3) == 7.5); + jerry_value_t get_result_1 = jerry_object_get (object, prop_name_1); + jerry_value_t get_result_2 = jerry_object_get (object, prop_name_2); + jerry_value_t get_result_3 = jerry_object_get (object, prop_name_3); + jerry_value_t get_result_4 = jerry_object_get (object, internal_prop_name_1); + jerry_value_t get_result_5 = jerry_object_get (object, internal_prop_name_2); + jerry_value_t get_result_6 = jerry_object_get (object, internal_prop_name_3); + + TEST_ASSERT (jerry_value_is_number (get_result_1) && jerry_value_as_number (get_result_1) == 5.5); + TEST_ASSERT (jerry_value_is_number (get_result_2) && jerry_value_as_number (get_result_2) == 6.5); + TEST_ASSERT (jerry_value_is_number (get_result_3) && jerry_value_as_number (get_result_3) == 7.5); TEST_ASSERT (jerry_value_is_undefined (get_result_4)); TEST_ASSERT (jerry_value_is_undefined (get_result_5)); TEST_ASSERT (jerry_value_is_undefined (get_result_6)); - jerry_release_value (get_result_1); - jerry_release_value (get_result_2); - jerry_release_value (get_result_3); - jerry_release_value (get_result_4); - jerry_release_value (get_result_5); - jerry_release_value (get_result_6); + jerry_value_free (get_result_1); + jerry_value_free (get_result_2); + jerry_value_free (get_result_3); + jerry_value_free (get_result_4); + jerry_value_free (get_result_5); + jerry_value_free (get_result_6); /* Test the internal [[Get]] method. */ - jerry_value_t get_internal_result_1 = jerry_get_internal_property (object, prop_name_1); - jerry_value_t get_internal_result_2 = jerry_get_internal_property (object, prop_name_2); - jerry_value_t get_internal_result_3 = jerry_get_internal_property (object, prop_name_3); - jerry_value_t get_internal_result_4 = jerry_get_internal_property (object, internal_prop_name_1); - jerry_value_t get_internal_result_5 = jerry_get_internal_property (object, internal_prop_name_2); - jerry_value_t get_internal_result_6 = jerry_get_internal_property (object, internal_prop_name_3); + jerry_value_t get_internal_result_1 = jerry_object_get_internal (object, prop_name_1); + jerry_value_t get_internal_result_2 = jerry_object_get_internal (object, prop_name_2); + jerry_value_t get_internal_result_3 = jerry_object_get_internal (object, prop_name_3); + jerry_value_t get_internal_result_4 = jerry_object_get_internal (object, internal_prop_name_1); + jerry_value_t get_internal_result_5 = jerry_object_get_internal (object, internal_prop_name_2); + jerry_value_t get_internal_result_6 = jerry_object_get_internal (object, internal_prop_name_3); TEST_ASSERT (jerry_value_is_undefined (get_internal_result_1)); TEST_ASSERT (jerry_value_is_undefined (get_internal_result_2)); TEST_ASSERT (jerry_value_is_undefined (get_internal_result_3)); - TEST_ASSERT (jerry_value_is_number (get_internal_result_4) && jerry_get_number_value (get_internal_result_4) == 8.5); - TEST_ASSERT (jerry_value_is_number (get_internal_result_5) && jerry_get_number_value (get_internal_result_5) == 9.5); - TEST_ASSERT (jerry_value_is_number (get_internal_result_6) && jerry_get_number_value (get_internal_result_6) == 10.5); + TEST_ASSERT (jerry_value_is_number (get_internal_result_4) && jerry_value_as_number (get_internal_result_4) == 8.5); + TEST_ASSERT (jerry_value_is_number (get_internal_result_5) && jerry_value_as_number (get_internal_result_5) == 9.5); + TEST_ASSERT (jerry_value_is_number (get_internal_result_6) && jerry_value_as_number (get_internal_result_6) == 10.5); - jerry_release_value (get_internal_result_1); - jerry_release_value (get_internal_result_2); - jerry_release_value (get_internal_result_3); - jerry_release_value (get_internal_result_4); - jerry_release_value (get_internal_result_5); - jerry_release_value (get_internal_result_6); + jerry_value_free (get_internal_result_1); + jerry_value_free (get_internal_result_2); + jerry_value_free (get_internal_result_3); + jerry_value_free (get_internal_result_4); + jerry_value_free (get_internal_result_5); + jerry_value_free (get_internal_result_6); /* Test the normal [[Delete]] method. */ - bool delete_result_1 = jerry_delete_property (object, prop_name_1); - bool delete_result_2 = jerry_delete_property (object, prop_name_2); - bool delete_result_3 = jerry_delete_property (object, prop_name_3); - bool delete_result_4 = jerry_delete_property (object, internal_prop_name_1); - bool delete_result_5 = jerry_delete_property (object, internal_prop_name_2); - bool delete_result_6 = jerry_delete_property (object, internal_prop_name_3); + bool delete_result_1 = jerry_object_delete (object, prop_name_1); + bool delete_result_2 = jerry_object_delete (object, prop_name_2); + bool delete_result_3 = jerry_object_delete (object, prop_name_3); + bool delete_result_4 = jerry_object_delete (object, internal_prop_name_1); + bool delete_result_5 = jerry_object_delete (object, internal_prop_name_2); + bool delete_result_6 = jerry_object_delete (object, internal_prop_name_3); TEST_ASSERT (delete_result_1); TEST_ASSERT (delete_result_2); @@ -178,12 +178,12 @@ main (void) TEST_ASSERT (delete_result_5); TEST_ASSERT (delete_result_6); - jerry_value_t has_after_delete_result_1 = jerry_has_property (object, prop_name_1); - jerry_value_t has_after_delete_result_2 = jerry_has_property (object, prop_name_2); - jerry_value_t has_after_delete_result_3 = jerry_has_property (object, prop_name_3); - bool has_after_delete_result_4 = jerry_has_internal_property (object, internal_prop_name_1); - bool has_after_delete_result_5 = jerry_has_internal_property (object, internal_prop_name_2); - bool has_after_delete_result_6 = jerry_has_internal_property (object, internal_prop_name_3); + jerry_value_t has_after_delete_result_1 = jerry_object_has (object, prop_name_1); + jerry_value_t has_after_delete_result_2 = jerry_object_has (object, prop_name_2); + jerry_value_t has_after_delete_result_3 = jerry_object_has (object, prop_name_3); + bool has_after_delete_result_4 = jerry_object_has_internal (object, internal_prop_name_1); + bool has_after_delete_result_5 = jerry_object_has_internal (object, internal_prop_name_2); + bool has_after_delete_result_6 = jerry_object_has_internal (object, internal_prop_name_3); TEST_ASSERT (jerry_value_is_boolean (has_after_delete_result_1) && !jerry_value_is_true (has_after_delete_result_1)); TEST_ASSERT (jerry_value_is_boolean (has_after_delete_result_2) && !jerry_value_is_true (has_after_delete_result_2)); @@ -192,45 +192,45 @@ main (void) TEST_ASSERT (has_after_delete_result_5); TEST_ASSERT (has_after_delete_result_6); - jerry_release_value (has_after_delete_result_1); - jerry_release_value (has_after_delete_result_2); - jerry_release_value (has_after_delete_result_3); + jerry_value_free (has_after_delete_result_1); + jerry_value_free (has_after_delete_result_2); + jerry_value_free (has_after_delete_result_3); /* Test the internal [[Delete]] method. */ - bool delete_internal_result_4 = jerry_delete_internal_property (object, internal_prop_name_1); - bool delete_internal_result_5 = jerry_delete_internal_property (object, internal_prop_name_2); - bool delete_internal_result_6 = jerry_delete_internal_property (object, internal_prop_name_3); + bool delete_internal_result_4 = jerry_object_delete_internal (object, internal_prop_name_1); + bool delete_internal_result_5 = jerry_object_delete_internal (object, internal_prop_name_2); + bool delete_internal_result_6 = jerry_object_delete_internal (object, internal_prop_name_3); TEST_ASSERT (delete_internal_result_4); TEST_ASSERT (delete_internal_result_5); TEST_ASSERT (delete_internal_result_6); - bool has_after_internal_delete_result_1 = jerry_has_internal_property (object, internal_prop_name_1); - bool has_after_internal_delete_result_2 = jerry_has_internal_property (object, internal_prop_name_2); - bool has_after_internal_delete_result_3 = jerry_has_internal_property (object, internal_prop_name_3); + bool has_after_internal_delete_result_1 = jerry_object_has_internal (object, internal_prop_name_1); + bool has_after_internal_delete_result_2 = jerry_object_has_internal (object, internal_prop_name_2); + bool has_after_internal_delete_result_3 = jerry_object_has_internal (object, internal_prop_name_3); TEST_ASSERT (!has_after_internal_delete_result_1); TEST_ASSERT (!has_after_internal_delete_result_2); TEST_ASSERT (!has_after_internal_delete_result_3); /* Cleanup */ - jerry_release_value (prop_value_3); - jerry_release_value (prop_value_2); - jerry_release_value (prop_value_1); + jerry_value_free (prop_value_3); + jerry_value_free (prop_value_2); + jerry_value_free (prop_value_1); - jerry_release_value (prop_name_3); - jerry_release_value (prop_name_2); - jerry_release_value (prop_name_1); + jerry_value_free (prop_name_3); + jerry_value_free (prop_name_2); + jerry_value_free (prop_name_1); - jerry_release_value (internal_prop_value_3); - jerry_release_value (internal_prop_value_2); - jerry_release_value (internal_prop_value_1); + jerry_value_free (internal_prop_value_3); + jerry_value_free (internal_prop_value_2); + jerry_value_free (internal_prop_value_1); - jerry_release_value (internal_prop_name_3); - jerry_release_value (internal_prop_name_2); - jerry_release_value (internal_prop_name_1); + jerry_value_free (internal_prop_name_3); + jerry_value_free (internal_prop_name_2); + jerry_value_free (internal_prop_name_1); - jerry_release_value (object); + jerry_value_free (object); jerry_cleanup (); diff --git a/tests/unit-core/test-is-eval-code.c b/tests/unit-core/test-is-eval-code.c index 0c07838df1..13daa21623 100644 --- a/tests/unit-core/test-is-eval-code.c +++ b/tests/unit-core/test-is-eval-code.c @@ -25,8 +25,8 @@ check_eval (const jerry_call_info_t *call_info_p, /**< call information */ { JERRY_UNUSED (call_info_p); - TEST_ASSERT (args_cnt == 2 && jerry_is_eval_code (args_p[0]) == jerry_value_is_true (args_p[1])); - return jerry_create_boolean (true); + TEST_ASSERT (args_cnt == 2 && jerry_function_is_dynamic (args_p[0]) == jerry_value_is_true (args_p[1])); + return jerry_boolean (true); } /* check_eval */ static void @@ -34,22 +34,22 @@ test_parse (const char *source_p, /**< source code */ jerry_parse_options_t *options_p) /**< options passed to jerry_parse */ { jerry_value_t parse_result = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), options_p); - TEST_ASSERT (!jerry_value_is_error (parse_result)); - TEST_ASSERT (!jerry_is_eval_code (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); + TEST_ASSERT (!jerry_function_is_dynamic (parse_result)); jerry_value_t result; if (options_p->options & JERRY_PARSE_HAS_ARGUMENT_LIST) { - jerry_value_t this_value = jerry_create_undefined (); - result = jerry_call_function (parse_result, this_value, NULL, 0); - jerry_release_value (this_value); + jerry_value_t this_value = jerry_undefined (); + result = jerry_call (parse_result, this_value, NULL, 0); + jerry_value_free (this_value); } else if (options_p->options & JERRY_PARSE_MODULE) { result = jerry_module_link (parse_result, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); result = jerry_module_evaluate (parse_result); } else @@ -57,10 +57,10 @@ test_parse (const char *source_p, /**< source code */ result = jerry_run (parse_result); } - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); - jerry_release_value (parse_result); - jerry_release_value (result); + jerry_value_free (parse_result); + jerry_value_free (result); } /* test_parse */ int @@ -70,15 +70,15 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_object_value = jerry_get_global_object (); + jerry_value_t global_object_value = jerry_current_realm (); - jerry_value_t function_value = jerry_create_external_function (check_eval); - jerry_value_t function_name_value = jerry_create_string ((const jerry_char_t *) "check_eval"); - jerry_release_value (jerry_set_property (global_object_value, function_name_value, function_value)); + jerry_value_t function_value = jerry_function_external (check_eval); + jerry_value_t function_name_value = jerry_string_sz ("check_eval"); + jerry_value_free (jerry_object_set (global_object_value, function_name_value, function_value)); - jerry_release_value (function_name_value); - jerry_release_value (function_value); - jerry_release_value (global_object_value); + jerry_value_free (function_name_value); + jerry_value_free (function_value); + jerry_value_free (global_object_value); jerry_parse_options_t parse_options; const char *source_p = TEST_STRING_LITERAL ("eval('check_eval(function() {}, true)')\n" @@ -87,23 +87,23 @@ main (void) parse_options.options = JERRY_PARSE_NO_OPTS; test_parse (source_p, &parse_options); - if (jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + if (jerry_feature_enabled (JERRY_FEATURE_MODULE)) { parse_options.options = JERRY_PARSE_MODULE; test_parse (source_p, &parse_options); } parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) ""); + parse_options.argument_list = jerry_string_sz (""); test_parse (source_p, &parse_options); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_options.argument_list); parse_options.options = JERRY_PARSE_NO_OPTS; source_p = TEST_STRING_LITERAL ("check_eval(new Function('a', 'return a'), true)"); test_parse (source_p, &parse_options); source_p = TEST_STRING_LITERAL ("check_eval(function() {}, true)"); - jerry_release_value (jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), JERRY_PARSE_NO_OPTS)); + jerry_value_free (jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), JERRY_PARSE_NO_OPTS)); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-json.c b/tests/unit-core/test-json.c index 3f22784dd5..b316c14833 100644 --- a/tests/unit-core/test-json.c +++ b/tests/unit-core/test-json.c @@ -27,7 +27,7 @@ custom_to_json (const jerry_call_info_t *call_info_p, /**< call information */ JERRY_UNUSED (args_p); JERRY_UNUSED (args_cnt); - return jerry_create_error (JERRY_ERROR_URI, (const jerry_char_t *) "Error"); + return jerry_throw_sz (JERRY_ERROR_URI, "Error"); } /* custom_to_json */ int @@ -43,125 +43,145 @@ main (void) jerry_value_t parsed_json = jerry_json_parse (data, sizeof (data) - 1); /* Check "name" property values */ - jerry_value_t name_key = jerry_create_string ((const jerry_char_t *) "name"); + jerry_value_t name_key = jerry_string_sz ("name"); - jerry_value_t has_name = jerry_has_property (parsed_json, name_key); + jerry_value_t has_name = jerry_object_has (parsed_json, name_key); TEST_ASSERT (jerry_value_is_true (has_name)); - jerry_release_value (has_name); + jerry_value_free (has_name); - jerry_value_t name_value = jerry_get_property (parsed_json, name_key); + jerry_value_t name_value = jerry_object_get (parsed_json, name_key); TEST_ASSERT (jerry_value_is_string (name_value) == true); - jerry_size_t name_size = jerry_get_string_size (name_value); + jerry_size_t name_size = jerry_string_size (name_value, JERRY_ENCODING_CESU8); TEST_ASSERT (name_size == 4); JERRY_VLA (jerry_char_t, name_data, name_size + 1); - jerry_size_t copied = jerry_string_to_char_buffer (name_value, name_data, name_size); + jerry_size_t copied = jerry_string_to_buffer (name_value, name_data, name_size, JERRY_ENCODING_CESU8); name_data[name_size] = '\0'; - jerry_release_value (name_value); + jerry_value_free (name_value); TEST_ASSERT (copied == name_size); TEST_ASSERT_STR ("John", name_data); - jerry_release_value (name_key); + jerry_value_free (name_key); /* Check "age" property values */ - jerry_value_t age_key = jerry_create_string ((const jerry_char_t *) "age"); + jerry_value_t age_key = jerry_string_sz ("age"); - jerry_value_t has_age = jerry_has_property (parsed_json, age_key); + jerry_value_t has_age = jerry_object_has (parsed_json, age_key); TEST_ASSERT (jerry_value_is_true (has_age)); - jerry_release_value (has_age); + jerry_value_free (has_age); - jerry_value_t age_value = jerry_get_property (parsed_json, age_key); + jerry_value_t age_value = jerry_object_get (parsed_json, age_key); TEST_ASSERT (jerry_value_is_number (age_value) == true); - TEST_ASSERT (jerry_get_number_value (age_value) == 5.0); + TEST_ASSERT (jerry_value_as_number (age_value) == 5.0); - jerry_release_value (age_value); - jerry_release_value (age_key); + jerry_value_free (age_value); + jerry_value_free (age_key); - jerry_release_value (parsed_json); + jerry_value_free (parsed_json); + } + + /* JSON.parse cesu-8 / utf-8 encoded string */ + { + jerry_char_t cesu8[] = "{\"ch\": \"\xED\xA0\x83\xED\xB2\x9F\"}"; + jerry_char_t utf8[] = "{\"ch\": \"\xF0\x90\xB2\x9F\"}"; + + jerry_value_t parsed_cesu8 = jerry_json_parse (cesu8, sizeof (cesu8) - 1); + jerry_value_t parsed_utf8 = jerry_json_parse (utf8, sizeof (utf8) - 1); + + jerry_value_t key = jerry_string_sz ("ch"); + jerry_value_t char_cesu8 = jerry_object_get (parsed_cesu8, key); + jerry_value_t char_utf8 = jerry_object_get (parsed_utf8, key); + jerry_value_free (key); + + TEST_ASSERT (jerry_value_to_boolean (jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, char_cesu8, char_utf8))); + jerry_value_free (char_cesu8); + jerry_value_free (char_utf8); + jerry_value_free (parsed_cesu8); + jerry_value_free (parsed_utf8); } /* JSON.parse error checks */ { jerry_value_t parsed_json = jerry_json_parse ((const jerry_char_t *) "", 0); - TEST_ASSERT (jerry_value_is_error (parsed_json)); - TEST_ASSERT (jerry_get_error_type (parsed_json) == JERRY_ERROR_SYNTAX); - jerry_release_value (parsed_json); + TEST_ASSERT (jerry_value_is_exception (parsed_json)); + TEST_ASSERT (jerry_error_type (parsed_json) == JERRY_ERROR_SYNTAX); + jerry_value_free (parsed_json); } { jerry_value_t parsed_json = jerry_json_parse ((const jerry_char_t *) "-", 1); - TEST_ASSERT (jerry_value_is_error (parsed_json)); - TEST_ASSERT (jerry_get_error_type (parsed_json) == JERRY_ERROR_SYNTAX); - jerry_release_value (parsed_json); + TEST_ASSERT (jerry_value_is_exception (parsed_json)); + TEST_ASSERT (jerry_error_type (parsed_json) == JERRY_ERROR_SYNTAX); + jerry_value_free (parsed_json); } /* JSON.stringify check */ { - jerry_value_t obj = jerry_create_object (); + jerry_value_t obj = jerry_object (); /* Fill "obj" with data */ { - jerry_value_t name_key = jerry_create_string ((const jerry_char_t *) "name"); - jerry_value_t name_value = jerry_create_string ((const jerry_char_t *) "John"); - jerry_value_t name_set = jerry_set_property (obj, name_key, name_value); - TEST_ASSERT (!jerry_value_is_error (name_set)); + jerry_value_t name_key = jerry_string_sz ("name"); + jerry_value_t name_value = jerry_string_sz ("John"); + jerry_value_t name_set = jerry_object_set (obj, name_key, name_value); + TEST_ASSERT (!jerry_value_is_exception (name_set)); TEST_ASSERT (jerry_value_is_boolean (name_set)); TEST_ASSERT (jerry_value_is_true (name_set)); - jerry_release_value (name_key); - jerry_release_value (name_value); - jerry_release_value (name_set); + jerry_value_free (name_key); + jerry_value_free (name_value); + jerry_value_free (name_set); } { - jerry_value_t age_key = jerry_create_string ((const jerry_char_t *) "age"); - jerry_value_t age_value = jerry_create_number (32); - jerry_value_t age_set = jerry_set_property (obj, age_key, age_value); - TEST_ASSERT (!jerry_value_is_error (age_set)); + jerry_value_t age_key = jerry_string_sz ("age"); + jerry_value_t age_value = jerry_number (32); + jerry_value_t age_set = jerry_object_set (obj, age_key, age_value); + TEST_ASSERT (!jerry_value_is_exception (age_set)); TEST_ASSERT (jerry_value_is_boolean (age_set)); TEST_ASSERT (jerry_value_is_true (age_set)); - jerry_release_value (age_key); - jerry_release_value (age_value); - jerry_release_value (age_set); + jerry_value_free (age_key); + jerry_value_free (age_value); + jerry_value_free (age_set); } jerry_value_t json_string = jerry_json_stringify (obj); TEST_ASSERT (jerry_value_is_string (json_string)); - jerry_release_value (obj); + jerry_value_free (obj); const char check_value[] = "{\"name\":\"John\",\"age\":32}"; - jerry_size_t json_size = jerry_get_string_size (json_string); + jerry_size_t json_size = jerry_string_size (json_string, JERRY_ENCODING_CESU8); TEST_ASSERT (json_size == strlen (check_value)); JERRY_VLA (jerry_char_t, json_data, json_size + 1); - jerry_string_to_char_buffer (json_string, json_data, json_size); + jerry_string_to_buffer (json_string, json_data, json_size, JERRY_ENCODING_CESU8); json_data[json_size] = '\0'; TEST_ASSERT_STR (check_value, json_data); - jerry_release_value (json_string); + jerry_value_free (json_string); } /* Custom "toJSON" invocation test */ { - jerry_value_t obj = jerry_create_object (); + jerry_value_t obj = jerry_object (); /* Fill "obj" with data */ { - jerry_value_t name_key = jerry_create_string ((const jerry_char_t *) "toJSON"); - jerry_value_t name_value = jerry_create_external_function (custom_to_json); - jerry_value_t name_set = jerry_set_property (obj, name_key, name_value); - TEST_ASSERT (!jerry_value_is_error (name_set)); + jerry_value_t name_key = jerry_string_sz ("toJSON"); + jerry_value_t name_value = jerry_function_external (custom_to_json); + jerry_value_t name_set = jerry_object_set (obj, name_key, name_value); + TEST_ASSERT (!jerry_value_is_exception (name_set)); TEST_ASSERT (jerry_value_is_boolean (name_set)); TEST_ASSERT (jerry_value_is_true (name_set)); - jerry_release_value (name_key); - jerry_release_value (name_value); - jerry_release_value (name_set); + jerry_value_free (name_key); + jerry_value_free (name_value); + jerry_value_free (name_set); } jerry_value_t json_string = jerry_json_stringify (obj); - TEST_ASSERT (jerry_value_is_error (json_string)); - TEST_ASSERT (jerry_get_error_type (json_string) == JERRY_ERROR_URI); + TEST_ASSERT (jerry_value_is_exception (json_string)); + TEST_ASSERT (jerry_error_type (json_string) == JERRY_ERROR_URI); - jerry_release_value (json_string); - jerry_release_value (obj); + jerry_value_free (json_string); + jerry_value_free (obj); } jerry_cleanup (); diff --git a/tests/unit-core/test-mem-stats.c b/tests/unit-core/test-mem-stats.c index cfa1caebbf..f440ba18c9 100644 --- a/tests/unit-core/test-mem-stats.c +++ b/tests/unit-core/test-mem-stats.c @@ -20,7 +20,7 @@ int main (void) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_MEM_STATS)) + if (!jerry_feature_enabled (JERRY_FEATURE_HEAP_STATS)) { return 0; } @@ -30,22 +30,22 @@ main (void) jerry_init (JERRY_INIT_EMPTY); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); jerry_heap_stats_t stats; memset (&stats, 0, sizeof (stats)); - bool get_stats_ret = jerry_get_memory_stats (&stats); + bool get_stats_ret = jerry_heap_stats (&stats); TEST_ASSERT (get_stats_ret); TEST_ASSERT (stats.version == 1); TEST_ASSERT (stats.size == 524280); - TEST_ASSERT (!jerry_get_memory_stats (NULL)); + TEST_ASSERT (!jerry_heap_stats (NULL)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); jerry_cleanup (); diff --git a/tests/unit-core/test-module-dynamic.c b/tests/unit-core/test-module-dynamic.c index 1c62e22682..f83aaa914f 100644 --- a/tests/unit-core/test-module-dynamic.c +++ b/tests/unit-core/test-module-dynamic.c @@ -30,24 +30,24 @@ global_assert (const jerry_call_info_t *call_info_p, /**< call information */ JERRY_UNUSED (call_info_p); TEST_ASSERT (args_cnt == 1 && jerry_value_is_true (args_p[0])); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* global_assert */ static void register_assert (void) { - jerry_value_t global_object_value = jerry_get_global_object (); + jerry_value_t global_object_value = jerry_current_realm (); - jerry_value_t function_value = jerry_create_external_function (global_assert); - jerry_value_t function_name_value = jerry_create_string ((const jerry_char_t *) "assert"); - jerry_value_t result_value = jerry_set_property (global_object_value, function_name_value, function_value); + jerry_value_t function_value = jerry_function_external (global_assert); + jerry_value_t function_name_value = jerry_string_sz ("assert"); + jerry_value_t result_value = jerry_object_set (global_object_value, function_name_value, function_value); - jerry_release_value (function_name_value); - jerry_release_value (function_value); - jerry_release_value (global_object_value); + jerry_value_free (function_name_value); + jerry_value_free (function_value); + jerry_value_free (global_object_value); TEST_ASSERT (jerry_value_is_true (result_value)); - jerry_release_value (result_value); + jerry_value_free (result_value); } /* register_assert */ static void @@ -65,9 +65,9 @@ compare_specifier (jerry_value_t specifier, /* string value */ jerry_char_t buffer[sizeof (string) - 1]; TEST_ASSERT (jerry_value_is_string (specifier)); - TEST_ASSERT (jerry_get_string_size (specifier) == length); + TEST_ASSERT (jerry_string_size (specifier, JERRY_ENCODING_CESU8) == length); - TEST_ASSERT (jerry_string_to_char_buffer (specifier, buffer, length) == length); + TEST_ASSERT (jerry_string_to_buffer (specifier, buffer, length, JERRY_ENCODING_CESU8) == length); TEST_ASSERT (memcmp (buffer, string, length) == 0); } /* compare_specifier */ @@ -80,10 +80,10 @@ module_import_callback (const jerry_value_t specifier, /* string value */ if (mode != 3) { - jerry_value_t compare_value = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, user_value, global_user_value); + jerry_value_t compare_value = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, user_value, global_user_value); TEST_ASSERT (jerry_value_is_true (compare_value)); - jerry_release_value (compare_value); + jerry_value_free (compare_value); } switch (mode) @@ -91,22 +91,22 @@ module_import_callback (const jerry_value_t specifier, /* string value */ case 0: { compare_specifier (specifier, 1); - return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) "Err01"); + return jerry_throw_sz (JERRY_ERROR_RANGE, "Err01"); } case 1: { compare_specifier (specifier, 2); - return jerry_create_null (); + return jerry_null (); } case 2: { compare_specifier (specifier, 3); - jerry_value_t promise_value = jerry_create_promise (); + jerry_value_t promise_value = jerry_promise (); /* Normally this should be a namespace object. */ - jerry_value_t object_value = jerry_create_object (); - jerry_resolve_or_reject_promise (promise_value, object_value, true); - jerry_release_value (object_value); + jerry_value_t object_value = jerry_object (); + jerry_promise_resolve (promise_value, object_value); + jerry_value_free (object_value); return promise_value; } case 3: @@ -114,12 +114,12 @@ module_import_callback (const jerry_value_t specifier, /* string value */ compare_specifier (specifier, 28); TEST_ASSERT (jerry_value_is_object (user_value)); - jerry_value_t property_name = jerry_create_string ((const jerry_char_t *) "MyProp1"); - jerry_value_t result = jerry_get_property (user_value, property_name); - TEST_ASSERT (jerry_value_is_number (result) && jerry_get_number_value (result) == 3.5); - jerry_release_value (result); - jerry_release_value (property_name); - return jerry_create_undefined (); + jerry_value_t property_name = jerry_string_sz ("MyProp1"); + jerry_value_t result = jerry_object_get (user_value, property_name); + TEST_ASSERT (jerry_value_is_number (result) && jerry_value_as_number (result) == 3.5); + jerry_value_free (result); + jerry_value_free (property_name); + return jerry_undefined (); } } @@ -129,17 +129,17 @@ module_import_callback (const jerry_value_t specifier, /* string value */ parse_options.options = JERRY_PARSE_MODULE; jerry_value_t parse_result_value = jerry_parse ((const jerry_char_t *) "", 0, &parse_options); - TEST_ASSERT (!jerry_value_is_error (parse_result_value)); + TEST_ASSERT (!jerry_value_is_exception (parse_result_value)); jerry_value_t result_value = jerry_module_link (parse_result_value, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); if (mode == 4) { result_value = jerry_module_evaluate (parse_result_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); } return parse_result_value; @@ -153,20 +153,20 @@ run_script (const char *source_p, /* source code */ jerry_value_t parse_result_value; parse_result_value = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), parse_options_p); - TEST_ASSERT (!jerry_value_is_error (parse_result_value)); + TEST_ASSERT (!jerry_value_is_exception (parse_result_value)); if (release_user_value) { - jerry_release_value (parse_options_p->user_value); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_value_free (parse_options_p->user_value); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); } jerry_value_t result_value; if (parse_options_p->options & JERRY_PARSE_MODULE) { result_value = jerry_module_link (parse_result_value, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); result_value = jerry_module_evaluate (parse_result_value); } @@ -175,14 +175,14 @@ run_script (const char *source_p, /* source code */ result_value = jerry_run (parse_result_value); } - jerry_release_value (parse_result_value); + jerry_value_free (parse_result_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); - result_value = jerry_run_all_enqueued_jobs (); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + result_value = jerry_run_microtasks (); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); } /* run_script */ int @@ -190,7 +190,7 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + if (!jerry_feature_enabled (JERRY_FEATURE_MODULE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Module is disabled!\n"); jerry_cleanup (); @@ -198,12 +198,12 @@ main (void) } register_assert (); - jerry_module_set_import_callback (module_import_callback, (void *) &mode); + jerry_module_import_cb (module_import_callback, (void *) &mode); jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_NO_OPTS; - if (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES)) + if (jerry_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES)) { run_script ("var expected_message = 'Module cannot be instantiated'", &parse_options, false); } @@ -212,7 +212,7 @@ main (void) run_script ("var expected_message = ''", &parse_options, false); } - global_user_value = jerry_create_object (); + global_user_value = jerry_object (); const char *source_p = TEST_STRING_LITERAL ("import('01_module.mjs').then(\n" " function(resolve) { assert(false) },\n" " function(reject) {\n" @@ -225,9 +225,9 @@ main (void) parse_options.options = JERRY_PARSE_HAS_USER_VALUE; parse_options.user_value = global_user_value; run_script (source_p, &parse_options, false); - jerry_release_value (global_user_value); + jerry_value_free (global_user_value); - global_user_value = jerry_create_null (); + global_user_value = jerry_null (); source_p = TEST_STRING_LITERAL ("var src = \"import('02_module.mjs').then(\\\n" " function(resolve) { assert(false) },\\\n" " function(reject) {\\\n" @@ -241,9 +241,9 @@ main (void) parse_options.options = JERRY_PARSE_HAS_USER_VALUE; parse_options.user_value = global_user_value; run_script (source_p, &parse_options, false); - jerry_release_value (global_user_value); + jerry_value_free (global_user_value); - global_user_value = jerry_create_number (5.6); + global_user_value = jerry_number (5.6); source_p = TEST_STRING_LITERAL ("function f() {\n" " return function () {\n" " return import('03_module.mjs')\n" @@ -258,9 +258,9 @@ main (void) parse_options.options = JERRY_PARSE_HAS_USER_VALUE | JERRY_PARSE_MODULE; parse_options.user_value = global_user_value; run_script (source_p, &parse_options, false); - jerry_release_value (global_user_value); + jerry_value_free (global_user_value); - global_user_value = jerry_create_string ((const jerry_char_t *) "Any string..."); + global_user_value = jerry_string_sz ("Any string..."); source_p = TEST_STRING_LITERAL ("var src = \"import('02_module.mjs').then(\\\n" " function(resolve) { assert(typeof resolve == 'object') },\\\n" " function(reject) { assert(false) }\\\n" @@ -274,14 +274,14 @@ main (void) { mode = 3; parse_options.options = JERRY_PARSE_HAS_USER_VALUE | (i == 1 ? JERRY_PARSE_MODULE : 0); - parse_options.user_value = jerry_create_object (); - jerry_value_t property_name = jerry_create_string ((const jerry_char_t *) "MyProp1"); - jerry_value_t property_value = jerry_create_number (3.5); - jerry_value_t result = jerry_set_property (parse_options.user_value, property_name, property_value); + parse_options.user_value = jerry_object (); + jerry_value_t property_name = jerry_string_sz ("MyProp1"); + jerry_value_t property_value = jerry_number (3.5); + jerry_value_t result = jerry_object_set (parse_options.user_value, property_name, property_value); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); - jerry_release_value (property_value); - jerry_release_value (property_name); + jerry_value_free (result); + jerry_value_free (property_value); + jerry_value_free (property_name); source_p = TEST_STRING_LITERAL ("import('28_module.mjs')"); run_script (source_p, &parse_options, true); @@ -291,9 +291,9 @@ main (void) parse_options.options = JERRY_PARSE_HAS_USER_VALUE; parse_options.user_value = global_user_value; run_script (source_p, &parse_options, false); - jerry_release_value (global_user_value); + jerry_value_free (global_user_value); - global_user_value = jerry_create_external_function (global_assert); + global_user_value = jerry_function_external (global_assert); source_p = TEST_STRING_LITERAL ("var src = \"import('02_module.mjs').then(\\\n" " function(resolve) { assert(false) },\\\n" " function(reject) {\\\n" @@ -310,7 +310,7 @@ main (void) parse_options.options = JERRY_PARSE_HAS_USER_VALUE | JERRY_PARSE_MODULE; parse_options.user_value = global_user_value; run_script (source_p, &parse_options, false); - jerry_release_value (global_user_value); + jerry_value_free (global_user_value); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-module-import-meta.c b/tests/unit-core/test-module-import-meta.c index 9d5ded9977..37a5403b00 100644 --- a/tests/unit-core/test-module-import-meta.c +++ b/tests/unit-core/test-module-import-meta.c @@ -29,24 +29,24 @@ global_assert (const jerry_call_info_t *call_info_p, /**< call information */ JERRY_UNUSED (call_info_p); TEST_ASSERT (args_cnt == 1 && jerry_value_is_true (args_p[0])); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* global_assert */ static void register_assert (void) { - jerry_value_t global_object_value = jerry_get_global_object (); + jerry_value_t global_object_value = jerry_current_realm (); - jerry_value_t function_value = jerry_create_external_function (global_assert); - jerry_value_t function_name_value = jerry_create_string ((const jerry_char_t *) "assert"); - jerry_value_t result_value = jerry_set_property (global_object_value, function_name_value, function_value); + jerry_value_t function_value = jerry_function_external (global_assert); + jerry_value_t function_name_value = jerry_string_sz ("assert"); + jerry_value_t result_value = jerry_object_set (global_object_value, function_name_value, function_value); - jerry_release_value (function_name_value); - jerry_release_value (function_value); - jerry_release_value (global_object_value); + jerry_value_free (function_name_value); + jerry_value_free (function_value); + jerry_value_free (global_object_value); TEST_ASSERT (jerry_value_is_true (result_value)); - jerry_release_value (result_value); + jerry_value_free (result_value); } /* register_assert */ static void @@ -57,10 +57,10 @@ module_import_meta_callback (const jerry_value_t module, /**< module */ TEST_ASSERT (user_p == (void *) &counter); TEST_ASSERT (module == global_module_value); - jerry_value_t property_name_value = jerry_create_string ((const jerry_char_t *) "prop"); - jerry_value_t result_value = jerry_set_property (meta_object, property_name_value, property_name_value); - jerry_release_value (result_value); - jerry_release_value (property_name_value); + jerry_value_t property_name_value = jerry_string_sz ("prop"); + jerry_value_t result_value = jerry_object_set (meta_object, property_name_value, property_name_value); + jerry_value_free (result_value); + jerry_value_free (property_name_value); counter++; } /* module_import_meta_callback */ @@ -70,8 +70,8 @@ test_syntax_error (const char *source_p, /**< source code */ const jerry_parse_options_t *options_p) /**< parse options */ { jerry_value_t result_value = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), options_p); - TEST_ASSERT (jerry_value_is_error (result_value) && jerry_get_error_type (result_value) == JERRY_ERROR_SYNTAX); - jerry_release_value (result_value); + TEST_ASSERT (jerry_value_is_exception (result_value) && jerry_error_type (result_value) == JERRY_ERROR_SYNTAX); + jerry_value_free (result_value); } /* test_syntax_error */ static void @@ -79,18 +79,18 @@ run_module (const char *source_p, /* source code */ jerry_parse_options_t *parse_options_p) /* parse options */ { global_module_value = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), parse_options_p); - TEST_ASSERT (!jerry_value_is_error (global_module_value)); + TEST_ASSERT (!jerry_value_is_exception (global_module_value)); jerry_value_t result_value = jerry_module_link (global_module_value, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); result_value = jerry_module_evaluate (global_module_value); - jerry_release_value (global_module_value); + jerry_value_free (global_module_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); - jerry_release_value (result_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + jerry_value_free (result_value); } /* run_module */ int @@ -98,7 +98,7 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + if (!jerry_feature_enabled (JERRY_FEATURE_MODULE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Module is disabled!\n"); jerry_cleanup (); @@ -106,7 +106,7 @@ main (void) } register_assert (); - jerry_module_set_import_meta_callback (module_import_meta_callback, (void *) &counter); + jerry_module_import_meta_cb (module_import_meta_callback, (void *) &counter); /* Syntax errors. */ test_syntax_error ("import.meta", NULL); diff --git a/tests/unit-core/test-module.c b/tests/unit-core/test-module.c index 186bd6b805..6d1b6fd912 100644 --- a/tests/unit-core/test-module.c +++ b/tests/unit-core/test-module.c @@ -34,9 +34,9 @@ compare_specifier (jerry_value_t specifier, /* string value */ jerry_char_t buffer[sizeof (string) - 1]; TEST_ASSERT (jerry_value_is_string (specifier)); - TEST_ASSERT (jerry_get_string_size (specifier) == length); + TEST_ASSERT (jerry_string_size (specifier, JERRY_ENCODING_CESU8) == length); - TEST_ASSERT (jerry_string_to_char_buffer (specifier, buffer, length) == length); + TEST_ASSERT (jerry_string_to_buffer (specifier, buffer, length, JERRY_ENCODING_CESU8) == length); TEST_ASSERT (memcmp (buffer, string, length) == 0); } /* compare_specifier */ @@ -45,14 +45,14 @@ compare_property (jerry_value_t namespace_object, /**< namespace object */ const char *name_p, /**< property name */ double expected_value) /**< property value (number for simplicity) */ { - jerry_value_t name = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result = jerry_get_property (namespace_object, name); + jerry_value_t name = jerry_string_sz (name_p); + jerry_value_t result = jerry_object_get (namespace_object, name); TEST_ASSERT (jerry_value_is_number (result)); - TEST_ASSERT (jerry_get_number_value (result) == expected_value); + TEST_ASSERT (jerry_value_as_number (result) == expected_value); - jerry_release_value (result); - jerry_release_value (name); + jerry_value_free (result); + jerry_value_free (name); } /* compare_property */ static jerry_value_t @@ -81,7 +81,7 @@ create_module (int id) /**< module id */ result = jerry_parse (source, sizeof (source) - 1, &module_parse_options); } - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); return result; } /* create_module */ @@ -98,7 +98,7 @@ resolve_callback1 (const jerry_value_t specifier, /**< module specifier */ compare_specifier (specifier, 1); counter++; - return counter == 1 ? jerry_create_number (7) : jerry_create_object (); + return counter == 1 ? jerry_number (7) : jerry_object (); } /* resolve_callback1 */ static jerry_value_t prev_module; @@ -118,7 +118,7 @@ resolve_callback2 (const jerry_value_t specifier, /**< module specifier */ { if (terminate_with_error) { - return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) "Module not found"); + return jerry_throw_sz (JERRY_ERROR_RANGE, "Module not found"); } return create_module (0); @@ -145,62 +145,62 @@ native_module_evaluate (const jerry_value_t native_module) /**< native module */ { ++counter; - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_EVALUATING); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_EVALUATING); - jerry_value_t exp_val = jerry_create_string ((const jerry_char_t *) "exp"); - jerry_value_t other_exp_val = jerry_create_string ((const jerry_char_t *) "other_exp"); + jerry_value_t exp_val = jerry_string_sz ("exp"); + jerry_value_t other_exp_val = jerry_string_sz ("other_exp"); /* The native module has no such export. */ - jerry_value_t no_exp_val = jerry_create_string ((const jerry_char_t *) "no_exp"); + jerry_value_t no_exp_val = jerry_string_sz ("no_exp"); - jerry_value_t result = jerry_native_module_get_export (native_module, exp_val); + jerry_value_t result = jerry_native_module_get (native_module, exp_val); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_native_module_get_export (native_module, other_exp_val); + result = jerry_native_module_get (native_module, other_exp_val); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_native_module_get_export (native_module, no_exp_val); - TEST_ASSERT (jerry_value_is_error (result)); - TEST_ASSERT (jerry_get_error_type (result) == JERRY_ERROR_REFERENCE); - jerry_release_value (result); + result = jerry_native_module_get (native_module, no_exp_val); + TEST_ASSERT (jerry_value_is_exception (result)); + TEST_ASSERT (jerry_error_type (result) == JERRY_ERROR_REFERENCE); + jerry_value_free (result); - jerry_value_t export = jerry_create_number (3.5); - result = jerry_native_module_set_export (native_module, exp_val, export); + jerry_value_t export = jerry_number (3.5); + result = jerry_native_module_set (native_module, exp_val, export); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); - jerry_release_value (result); - jerry_release_value (export); + jerry_value_free (result); + jerry_value_free (export); - export = jerry_create_string ((const jerry_char_t *) "str"); - result = jerry_native_module_set_export (native_module, other_exp_val, export); + export = jerry_string_sz ("str"); + result = jerry_native_module_set (native_module, other_exp_val, export); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); - jerry_release_value (result); - jerry_release_value (export); + jerry_value_free (result); + jerry_value_free (export); - result = jerry_native_module_set_export (native_module, no_exp_val, no_exp_val); - TEST_ASSERT (jerry_value_is_error (result)); - TEST_ASSERT (jerry_get_error_type (result) == JERRY_ERROR_REFERENCE); - jerry_release_value (result); + result = jerry_native_module_set (native_module, no_exp_val, no_exp_val); + TEST_ASSERT (jerry_value_is_exception (result)); + TEST_ASSERT (jerry_error_type (result) == JERRY_ERROR_REFERENCE); + jerry_value_free (result); - result = jerry_native_module_get_export (native_module, exp_val); - TEST_ASSERT (jerry_value_is_number (result) && jerry_get_number_value (result) == 3.5); - jerry_release_value (result); + result = jerry_native_module_get (native_module, exp_val); + TEST_ASSERT (jerry_value_is_number (result) && jerry_value_as_number (result) == 3.5); + jerry_value_free (result); - result = jerry_native_module_get_export (native_module, other_exp_val); + result = jerry_native_module_get (native_module, other_exp_val); TEST_ASSERT (jerry_value_is_string (result)); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (exp_val); - jerry_release_value (other_exp_val); - jerry_release_value (no_exp_val); + jerry_value_free (exp_val); + jerry_value_free (other_exp_val); + jerry_value_free (no_exp_val); if (counter == 4) { ++counter; - return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Ooops!"); + return jerry_throw_sz (JERRY_ERROR_COMMON, "Ooops!"); } - return jerry_create_undefined (); + return jerry_undefined (); } /* native_module_evaluate */ static jerry_value_t @@ -213,16 +213,15 @@ resolve_callback4 (const jerry_value_t specifier, /**< module specifier */ ++counter; - jerry_value_t exports[2] = { jerry_create_string ((const jerry_char_t *) "exp"), - jerry_create_string ((const jerry_char_t *) "other_exp") }; + jerry_value_t exports[2] = { jerry_string_sz ("exp"), jerry_string_sz ("other_exp") }; - jerry_value_t native_module = jerry_native_module_create (native_module_evaluate, exports, 2); - TEST_ASSERT (!jerry_value_is_error (native_module)); + jerry_value_t native_module = jerry_native_module (native_module_evaluate, exports, 2); + TEST_ASSERT (!jerry_value_is_exception (native_module)); - jerry_release_value (exports[0]); - jerry_release_value (exports[1]); + jerry_value_free (exports[0]); + jerry_value_free (exports[1]); - *((jerry_value_t *) user_p) = jerry_acquire_value (native_module); + *((jerry_value_t *) user_p) = jerry_value_copy (native_module); return native_module; } /* resolve_callback4 */ @@ -232,7 +231,7 @@ module_state_changed (jerry_module_state_t new_state, /**< new state of the modu const jerry_value_t value, /**< value argument */ void *user_p) /**< user pointer */ { - TEST_ASSERT (jerry_module_get_state (module_val) == new_state); + TEST_ASSERT (jerry_module_state (module_val) == new_state); TEST_ASSERT (module_val == module); TEST_ASSERT (user_p == (void *) &counter); @@ -250,14 +249,14 @@ module_state_changed (jerry_module_state_t new_state, /**< new state of the modu case 2: { TEST_ASSERT (new_state == JERRY_MODULE_STATE_EVALUATED); - TEST_ASSERT (jerry_value_is_number (value) && jerry_get_number_value (value) == 33.5); + TEST_ASSERT (jerry_value_is_number (value) && jerry_value_as_number (value) == 33.5); break; } default: { TEST_ASSERT (counter == 4); TEST_ASSERT (new_state == JERRY_MODULE_STATE_ERROR); - TEST_ASSERT (jerry_value_is_number (value) && jerry_get_number_value (value) == -5.5); + TEST_ASSERT (jerry_value_is_number (value) && jerry_value_as_number (value) == -5.5); break; } } @@ -281,62 +280,62 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + if (!jerry_feature_enabled (JERRY_FEATURE_MODULE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Module is disabled!\n"); jerry_cleanup (); return 0; } - jerry_value_t number = jerry_create_number (5); - jerry_value_t object = jerry_create_object (); + jerry_value_t number = jerry_number (5); + jerry_value_t object = jerry_object (); jerry_value_t result = jerry_module_link (number, resolve_callback1, NULL); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); result = jerry_module_link (object, resolve_callback1, NULL); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); module = create_module (1); /* After an error, module must remain in unlinked mode. */ result = jerry_module_link (module, resolve_callback1, (void *) &module); - TEST_ASSERT (jerry_value_is_error (result)); + TEST_ASSERT (jerry_value_is_exception (result)); TEST_ASSERT (counter == 1); - jerry_release_value (result); + jerry_value_free (result); result = jerry_module_link (module, resolve_callback1, (void *) &module); - TEST_ASSERT (jerry_value_is_error (result)); + TEST_ASSERT (jerry_value_is_exception (result)); TEST_ASSERT (counter == 2); - jerry_release_value (result); + jerry_value_free (result); prev_module = module; counter = 0; terminate_with_error = true; result = jerry_module_link (module, resolve_callback2, NULL); - TEST_ASSERT (jerry_value_is_error (result)); + TEST_ASSERT (jerry_value_is_exception (result)); TEST_ASSERT (counter == 32); - jerry_release_value (result); + jerry_value_free (result); /* The successfully resolved modules is kept around in unlinked state. */ - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); counter = 31; terminate_with_error = false; result = jerry_module_link (module, resolve_callback2, NULL); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); TEST_ASSERT (counter == 32); - jerry_release_value (result); + jerry_value_free (result); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_LINKED); - TEST_ASSERT (jerry_module_get_number_of_requests (module) == 1); - result = jerry_module_get_request (module, 0); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_LINKED); - jerry_release_value (result); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_LINKED); + TEST_ASSERT (jerry_module_request_count (module) == 1); + result = jerry_module_request (module, 0); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_LINKED); + jerry_value_free (result); - jerry_release_value (module); + jerry_value_free (module); module = create_module (1); @@ -346,10 +345,10 @@ main (void) result = jerry_module_link (module, resolve_callback2, NULL); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); TEST_ASSERT (counter == 32); - jerry_release_value (result); - jerry_release_value (module); + jerry_value_free (result); + jerry_value_free (module); - TEST_ASSERT (jerry_module_get_state (number) == JERRY_MODULE_STATE_INVALID); + TEST_ASSERT (jerry_module_state (number) == JERRY_MODULE_STATE_INVALID); jerry_parse_options_t module_parse_options; module_parse_options.options = JERRY_PARSE_MODULE; @@ -359,116 +358,116 @@ main (void) "export * from '44_module.mjs'\n" "import * as b from '36_module.mjs'\n"); module = jerry_parse (source1, sizeof (source1) - 1, &module_parse_options); - TEST_ASSERT (!jerry_value_is_error (module)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_UNLINKED); + TEST_ASSERT (!jerry_value_is_exception (module)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_UNLINKED); - TEST_ASSERT (jerry_module_get_number_of_requests (number) == 0); - TEST_ASSERT (jerry_module_get_number_of_requests (module) == 4); + TEST_ASSERT (jerry_module_request_count (number) == 0); + TEST_ASSERT (jerry_module_request_count (module) == 4); - result = jerry_module_get_request (object, 0); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_module_request (object, 0); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); - result = jerry_module_get_request (module, 0); + result = jerry_module_request (module, 0); compare_specifier (result, 16); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_module_get_request (module, 1); + result = jerry_module_request (module, 1); compare_specifier (result, 7); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_module_get_request (module, 2); + result = jerry_module_request (module, 2); compare_specifier (result, 44); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_module_get_request (module, 3); + result = jerry_module_request (module, 3); compare_specifier (result, 36); - jerry_release_value (result); + jerry_value_free (result); - result = jerry_module_get_request (module, 4); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_module_request (module, 4); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); - jerry_release_value (module); + jerry_value_free (module); - result = jerry_module_get_namespace (number); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_module_namespace (number); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); jerry_char_t source2[] = TEST_STRING_LITERAL ("export let a = 6\n" "export let b = 8.5\n"); module = jerry_parse (source2, sizeof (source2) - 1, &module_parse_options); - TEST_ASSERT (!jerry_value_is_error (module)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_UNLINKED); + TEST_ASSERT (!jerry_value_is_exception (module)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_UNLINKED); result = jerry_module_link (module, resolve_callback3, NULL); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_LINKED); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_LINKED); result = jerry_module_evaluate (module); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_EVALUATED); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_EVALUATED); - result = jerry_module_get_namespace (module); + result = jerry_module_namespace (module); TEST_ASSERT (jerry_value_is_object (result)); compare_property (result, "a", 6); compare_property (result, "b", 8.5); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (module); + jerry_value_free (module); - module = jerry_native_module_create (NULL, &object, 1); - TEST_ASSERT (jerry_value_is_error (module)); - jerry_release_value (module); + module = jerry_native_module (NULL, &object, 1); + TEST_ASSERT (jerry_value_is_exception (module)); + jerry_value_free (module); - module = jerry_native_module_create (NULL, NULL, 0); - TEST_ASSERT (!jerry_value_is_error (module)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_UNLINKED); + module = jerry_native_module (NULL, NULL, 0); + TEST_ASSERT (!jerry_value_is_exception (module)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_UNLINKED); - result = jerry_native_module_get_export (object, number); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_native_module_get (object, number); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); - result = jerry_native_module_set_export (module, number, number); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_native_module_set (module, number, number); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); - jerry_release_value (module); + jerry_value_free (module); /* Valid identifier. */ - jerry_value_t export = jerry_create_string ((const jerry_char_t *) "\xed\xa0\x83\xed\xb2\x80"); + jerry_value_t export = jerry_string_sz ("\xed\xa0\x83\xed\xb2\x80"); - module = jerry_native_module_create (NULL, &export, 1); - TEST_ASSERT (!jerry_value_is_error (module)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_UNLINKED); + module = jerry_native_module (NULL, &export, 1); + TEST_ASSERT (!jerry_value_is_exception (module)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_UNLINKED); result = jerry_module_link (module, NULL, NULL); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); result = jerry_module_evaluate (module); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); - jerry_release_value (module); - jerry_release_value (export); + jerry_value_free (module); + jerry_value_free (export); /* Invalid identifiers. */ - export = jerry_create_string ((const jerry_char_t *) "a+"); - module = jerry_native_module_create (NULL, &export, 1); - TEST_ASSERT (jerry_value_is_error (module)); - jerry_release_value (module); - jerry_release_value (export); - - export = jerry_create_string ((const jerry_char_t *) "\xed\xa0\x80"); - module = jerry_native_module_create (NULL, &export, 1); - TEST_ASSERT (jerry_value_is_error (module)); - jerry_release_value (module); - jerry_release_value (export); + export = jerry_string_sz ("a+"); + module = jerry_native_module (NULL, &export, 1); + TEST_ASSERT (jerry_value_is_exception (module)); + jerry_value_free (module); + jerry_value_free (export); + + export = jerry_string_sz ("\xed\xa0\x80"); + module = jerry_native_module (NULL, &export, 1); + TEST_ASSERT (jerry_value_is_exception (module)); + jerry_value_free (module); + jerry_value_free (export); counter = 0; @@ -480,74 +479,74 @@ main (void) "if (exp !== 3.5 || other !== 'str') { throw 'Assertion failed!' }\n" "if (namespace.exp !== 3.5 || namespace.other_exp !== 'str') { throw 'Assertion failed!' }\n"); module = jerry_parse (source3, sizeof (source3) - 1, &module_parse_options); - TEST_ASSERT (!jerry_value_is_error (module)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_UNLINKED); + TEST_ASSERT (!jerry_value_is_exception (module)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_UNLINKED); jerry_value_t native_module; result = jerry_module_link (module, resolve_callback4, (void *) &native_module); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); TEST_ASSERT (counter == i * 2 + 1); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_LINKED); - TEST_ASSERT (jerry_module_get_state (native_module) == JERRY_MODULE_STATE_LINKED); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_LINKED); + TEST_ASSERT (jerry_module_state (native_module) == JERRY_MODULE_STATE_LINKED); result = jerry_module_evaluate (module); if (i == 0) { - TEST_ASSERT (!jerry_value_is_error (result)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_EVALUATED); - TEST_ASSERT (jerry_module_get_state (native_module) == JERRY_MODULE_STATE_EVALUATED); + TEST_ASSERT (!jerry_value_is_exception (result)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_EVALUATED); + TEST_ASSERT (jerry_module_state (native_module) == JERRY_MODULE_STATE_EVALUATED); TEST_ASSERT (counter == 2); } else { - TEST_ASSERT (jerry_value_is_error (result)); - TEST_ASSERT (jerry_module_get_state (module) == JERRY_MODULE_STATE_ERROR); - TEST_ASSERT (jerry_module_get_state (native_module) == JERRY_MODULE_STATE_ERROR); + TEST_ASSERT (jerry_value_is_exception (result)); + TEST_ASSERT (jerry_module_state (module) == JERRY_MODULE_STATE_ERROR); + TEST_ASSERT (jerry_module_state (native_module) == JERRY_MODULE_STATE_ERROR); TEST_ASSERT (counter == 5); } - jerry_release_value (result); - jerry_release_value (module); - jerry_release_value (native_module); + jerry_value_free (result); + jerry_value_free (module); + jerry_value_free (native_module); } - jerry_release_value (object); - jerry_release_value (number); + jerry_value_free (object); + jerry_value_free (number); counter = 0; - jerry_module_set_state_changed_callback (module_state_changed, (void *) &counter); + jerry_module_state_changed_cb (module_state_changed, (void *) &counter); jerry_char_t source4[] = TEST_STRING_LITERAL ("33.5\n"); module = jerry_parse (source4, sizeof (source4) - 1, &module_parse_options); result = jerry_module_link (module, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); result = jerry_module_evaluate (module); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - jerry_release_value (module); + jerry_value_free (module); jerry_char_t source5[] = TEST_STRING_LITERAL ("throw -5.5\n"); module = jerry_parse (source5, sizeof (source5) - 1, &module_parse_options); result = jerry_module_link (module, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); result = jerry_module_evaluate (module); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); - jerry_release_value (module); + jerry_value_free (module); - jerry_module_set_state_changed_callback (NULL, NULL); + jerry_module_state_changed_cb (NULL, NULL); TEST_ASSERT (counter == 4); @@ -555,8 +554,8 @@ main (void) module = jerry_parse (source6, sizeof (source6) - 1, &module_parse_options); result = jerry_module_link (module, resolve_callback5, NULL); - TEST_ASSERT (jerry_value_is_error (result) && jerry_get_error_type (result) == JERRY_ERROR_SYNTAX); - jerry_release_value (result); + TEST_ASSERT (jerry_value_is_exception (result) && jerry_error_type (result) == JERRY_ERROR_SYNTAX); + jerry_value_free (result); jerry_cleanup (); diff --git a/tests/unit-core/test-native-callback-nested.c b/tests/unit-core/test-native-callback-nested.c index 66220b2ee0..2aef0f736f 100644 --- a/tests/unit-core/test-native-callback-nested.c +++ b/tests/unit-core/test-native-callback-nested.c @@ -22,12 +22,12 @@ static void native_cb2 (void) { - jerry_value_t array = jerry_create_array (100); - jerry_release_value (array); + jerry_value_t array = jerry_array (100); + jerry_value_free (array); } /* native_cb2 */ static const jerry_object_native_info_t native_info2 = { - .free_cb = (jerry_object_native_free_callback_t) native_cb2, + .free_cb = (jerry_object_native_free_cb_t) native_cb2, .number_of_references = 0, .offset_of_references = 0, }; @@ -35,15 +35,15 @@ static const jerry_object_native_info_t native_info2 = { static void native_cb (void) { - jerry_value_t array = jerry_create_array (100); + jerry_value_t array = jerry_array (100); - jerry_set_object_native_pointer (array, NULL, &native_info2); + jerry_object_set_native_ptr (array, &native_info2, NULL); - jerry_release_value (array); + jerry_value_free (array); } /* native_cb */ static const jerry_object_native_info_t native_info = { - .free_cb = (jerry_object_native_free_callback_t) native_cb, + .free_cb = (jerry_object_native_free_cb_t) native_cb, .number_of_references = 0, .offset_of_references = 0, }; @@ -58,14 +58,14 @@ context_alloc_fn (size_t size, void *cb_data) int main (void) { - jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL); + jerry_context_t *ctx_p = jerry_context (1024, context_alloc_fn, NULL); jerry_port_default_set_current_context (ctx_p); jerry_init (JERRY_INIT_EMPTY); - jerry_value_t obj = jerry_create_object (); + jerry_value_t obj = jerry_object (); - jerry_set_object_native_pointer (obj, NULL, &native_info); - jerry_release_value (obj); + jerry_object_set_native_ptr (obj, &native_info, NULL); + jerry_value_free (obj); jerry_cleanup (); free (ctx_p); diff --git a/tests/unit-core/test-native-instanceof.c b/tests/unit-core/test-native-instanceof.c index 5e899cee93..e5fcad0655 100644 --- a/tests/unit-core/test-native-instanceof.c +++ b/tests/unit-core/test-native-instanceof.c @@ -26,26 +26,26 @@ external_function (const jerry_call_info_t *call_info_p, const jerry_value_t arg (void) args_p; (void) args_count; - return jerry_create_undefined (); + return jerry_undefined (); } /* external_function */ static void test_instanceof (jerry_value_t instanceof, jerry_value_t constructor) { - jerry_value_t instance = jerry_construct_object (constructor, NULL, 0); + jerry_value_t instance = jerry_construct (constructor, NULL, 0); jerry_value_t args[2] = { instance, constructor }; - jerry_value_t undefined = jerry_create_undefined (); - jerry_value_t result = jerry_call_function (instanceof, undefined, args, 2); - jerry_release_value (undefined); + jerry_value_t undefined = jerry_undefined (); + jerry_value_t result = jerry_call (instanceof, undefined, args, 2); + jerry_value_free (undefined); - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (instance); - jerry_release_value (result); + jerry_value_free (instance); + jerry_value_free (result); } /* test_instanceof */ int @@ -56,22 +56,22 @@ main (void) jerry_value_t instanceof = jerry_eval ((jerry_char_t *) instanceof_source, sizeof (instanceof_source) - 1, true); /* Test for a native-backed function. */ - jerry_value_t constructor = jerry_create_external_function (external_function); + jerry_value_t constructor = jerry_function_external (external_function); test_instanceof (instanceof, constructor); - jerry_release_value (constructor); + jerry_value_free (constructor); /* Test for a JS constructor. */ - jerry_value_t global = jerry_get_global_object (); - jerry_value_t object_name = jerry_create_string ((jerry_char_t *) "Object"); - constructor = jerry_get_property (global, object_name); - jerry_release_value (object_name); - jerry_release_value (global); + jerry_value_t global = jerry_current_realm (); + jerry_value_t object_name = jerry_string_sz ("Object"); + constructor = jerry_object_get (global, object_name); + jerry_value_free (object_name); + jerry_value_free (global); test_instanceof (instanceof, constructor); - jerry_release_value (constructor); + jerry_value_free (constructor); - jerry_release_value (instanceof); + jerry_value_free (instanceof); jerry_cleanup (); diff --git a/tests/unit-core/test-native-pointer.c b/tests/unit-core/test-native-pointer.c index d769004a1e..664aba4616 100644 --- a/tests/unit-core/test-native-pointer.c +++ b/tests/unit-core/test-native-pointer.c @@ -76,7 +76,7 @@ native_references_free_callback (void *native_p, /**< native pointer */ uint32_t check = refs_p->check_before; - jerry_native_pointer_release_references (native_p, info_p); + jerry_native_ptr_free (native_p, info_p); TEST_ASSERT (jerry_value_is_undefined (refs_p->a)); TEST_ASSERT (jerry_value_is_undefined (refs_p->b)); @@ -104,7 +104,7 @@ init_references (test_references_t *refs_p, /**< native pointer */ refs_p->c = 3; refs_p->check_after = check; - jerry_native_pointer_init_references ((void *) refs_p, &native_info_4); + jerry_native_ptr_init ((void *) refs_p, &native_info_4); TEST_ASSERT (jerry_value_is_undefined (refs_p->a)); TEST_ASSERT (jerry_value_is_undefined (refs_p->b)); @@ -119,9 +119,9 @@ set_references (test_references_t *refs_p, /**< native pointer */ jerry_value_t value2, /**< second value to be set */ jerry_value_t value3) /**< third value to be set */ { - jerry_native_pointer_set_reference (&refs_p->a, value1); - jerry_native_pointer_set_reference (&refs_p->b, value2); - jerry_native_pointer_set_reference (&refs_p->c, value3); + jerry_native_ptr_set (&refs_p->a, value1); + jerry_native_ptr_set (&refs_p->b, value2); + jerry_native_ptr_set (&refs_p->c, value3); TEST_ASSERT (jerry_value_is_object (value1) ? jerry_value_is_object (refs_p->a) : jerry_value_is_string (refs_p->a)); TEST_ASSERT (jerry_value_is_object (value2) ? jerry_value_is_object (refs_p->b) : jerry_value_is_string (refs_p->b)); @@ -133,8 +133,8 @@ check_native_info (jerry_value_t object_value, /**< object value */ const jerry_object_native_info_t *native_info_p, /**< native info */ void *expected_pointer_p) /**< expected pointer */ { - void *native_pointer_p; - TEST_ASSERT (jerry_get_object_native_pointer (object_value, &native_pointer_p, native_info_p)); + TEST_ASSERT (jerry_object_has_native_ptr (object_value, native_info_p)); + void *native_pointer_p = jerry_object_get_native_ptr (object_value, native_info_p); TEST_ASSERT (native_pointer_p == expected_pointer_p); } /* check_native_info */ @@ -144,189 +144,189 @@ main (void) TEST_INIT (); jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object_value = jerry_create_object (); + jerry_value_t object_value = jerry_object (); - jerry_set_object_native_pointer (object_value, global_p, &native_info_1); - jerry_set_object_native_pointer (object_value, NULL, &native_info_2); + jerry_object_set_native_ptr (object_value, &native_info_1, global_p); + jerry_object_set_native_ptr (object_value, &native_info_2, NULL); check_native_info (object_value, &native_info_1, global_p); check_native_info (object_value, &native_info_2, NULL); - jerry_release_value (object_value); + jerry_value_free (object_value); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); TEST_ASSERT (global_counter == 1); global_counter = 0; - object_value = jerry_create_object (); + object_value = jerry_object (); - jerry_set_object_native_pointer (object_value, global_p, &native_info_1); - jerry_set_object_native_pointer (object_value, NULL, &native_info_2); + jerry_object_set_native_ptr (object_value, &native_info_1, global_p); + jerry_object_set_native_ptr (object_value, &native_info_2, NULL); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_1)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_1)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_1)); check_native_info (object_value, &native_info_2, NULL); - TEST_ASSERT (!jerry_delete_object_native_pointer (object_value, &native_info_1)); + TEST_ASSERT (!jerry_object_delete_native_ptr (object_value, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_1)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_1)); check_native_info (object_value, &native_info_2, NULL); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_2)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_2)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_2)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_1)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_2)); - jerry_set_object_native_pointer (object_value, NULL, &native_info_1); + jerry_object_set_native_ptr (object_value, &native_info_1, NULL); check_native_info (object_value, &native_info_1, NULL); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_2)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_2)); - jerry_set_object_native_pointer (object_value, global_p, &native_info_2); + jerry_object_set_native_ptr (object_value, &native_info_2, global_p); check_native_info (object_value, &native_info_1, NULL); check_native_info (object_value, &native_info_2, global_p); - jerry_set_object_native_pointer (object_value, global_p, &native_info_1); + jerry_object_set_native_ptr (object_value, &native_info_1, global_p); check_native_info (object_value, &native_info_1, global_p); check_native_info (object_value, &native_info_2, global_p); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_1)); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_2)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_1)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_2)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_2)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_1)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_2)); - jerry_set_object_native_pointer (object_value, global_p, &native_info_1); - jerry_set_object_native_pointer (object_value, NULL, &native_info_2); - jerry_set_object_native_pointer (object_value, global_p, &native_info_3); + jerry_object_set_native_ptr (object_value, &native_info_1, global_p); + jerry_object_set_native_ptr (object_value, &native_info_2, NULL); + jerry_object_set_native_ptr (object_value, &native_info_3, global_p); check_native_info (object_value, &native_info_1, global_p); check_native_info (object_value, &native_info_2, NULL); check_native_info (object_value, &native_info_3, global_p); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_1)); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_2)); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_3)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_1)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_2)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_3)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_2)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_3)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_1)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_2)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_3)); - jerry_set_object_native_pointer (object_value, NULL, &native_info_1); - jerry_set_object_native_pointer (object_value, global_p, &native_info_2); - jerry_set_object_native_pointer (object_value, NULL, &native_info_3); + jerry_object_set_native_ptr (object_value, &native_info_1, NULL); + jerry_object_set_native_ptr (object_value, &native_info_2, global_p); + jerry_object_set_native_ptr (object_value, &native_info_3, NULL); check_native_info (object_value, &native_info_1, NULL); check_native_info (object_value, &native_info_2, global_p); check_native_info (object_value, &native_info_3, NULL); /* Reversed delete order. */ - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_3)); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_2)); - TEST_ASSERT (jerry_delete_object_native_pointer (object_value, &native_info_1)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_3)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_2)); + TEST_ASSERT (jerry_object_delete_native_ptr (object_value, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_1)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_2)); - TEST_ASSERT (!jerry_get_object_native_pointer (object_value, NULL, &native_info_3)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_1)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_2)); + TEST_ASSERT (!jerry_object_has_native_ptr (object_value, &native_info_3)); /* Test value references */ - jerry_value_t string1_value = jerry_create_string ((const jerry_char_t *) "String1"); - jerry_value_t string2_value = jerry_create_string ((const jerry_char_t *) "String2"); + jerry_value_t string1_value = jerry_string_sz ("String1"); + jerry_value_t string2_value = jerry_string_sz ("String2"); - jerry_value_t object1_value = jerry_create_object (); - jerry_value_t object2_value = jerry_create_object (); + jerry_value_t object1_value = jerry_object (); + jerry_value_t object2_value = jerry_object (); init_references (&test_references1, 0x12345678); init_references (&test_references2, 0x87654321); - jerry_set_object_native_pointer (object1_value, (void *) &test_references1, &native_info_4); - jerry_set_object_native_pointer (object2_value, (void *) &test_references2, &native_info_4); + jerry_object_set_native_ptr (object1_value, &native_info_4, (void *) &test_references1); + jerry_object_set_native_ptr (object2_value, &native_info_4, (void *) &test_references2); /* Assign values (cross reference between object1 and object2). */ set_references (&test_references1, string1_value, object2_value, string2_value); set_references (&test_references2, string2_value, object1_value, string1_value); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); /* Reassign values. */ set_references (&test_references1, object2_value, string2_value, string1_value); set_references (&test_references2, object1_value, string1_value, string2_value); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); - jerry_release_value (object1_value); - jerry_release_value (object2_value); + jerry_value_free (object1_value); + jerry_value_free (object2_value); - object1_value = jerry_create_object (); - object2_value = jerry_create_object (); + object1_value = jerry_object (); + object2_value = jerry_object (); init_references (&test_references3, 0x12344321); /* Assign the same native pointer to multiple objects. */ - jerry_set_object_native_pointer (object1_value, (void *) &test_references3, &native_info_4); - jerry_set_object_native_pointer (object2_value, (void *) &test_references3, &native_info_4); + jerry_object_set_native_ptr (object1_value, &native_info_4, (void *) &test_references3); + jerry_object_set_native_ptr (object2_value, &native_info_4, (void *) &test_references3); set_references (&test_references3, object1_value, object2_value, string1_value); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); init_references (&test_references4, 0x87655678); /* Re-assign reference */ - jerry_set_object_native_pointer (object1_value, (void *) &test_references4, &native_info_4); + jerry_object_set_native_ptr (object1_value, &native_info_4, (void *) &test_references4); set_references (&test_references4, string1_value, string2_value, string1_value); - jerry_set_object_native_pointer (object1_value, NULL, &native_info_4); + jerry_object_set_native_ptr (object1_value, &native_info_4, NULL); - jerry_native_pointer_release_references ((void *) &test_references4, &native_info_4); + jerry_native_ptr_free ((void *) &test_references4, &native_info_4); - /* Calling jerry_native_pointer_init_references with test_references4 is optional here. */ + /* Calling jerry_native_ptr_init with test_references4 is optional here. */ - jerry_set_object_native_pointer (object1_value, (void *) &test_references4, &native_info_4); + jerry_object_set_native_ptr (object1_value, &native_info_4, (void *) &test_references4); set_references (&test_references4, string2_value, string1_value, string2_value); - TEST_ASSERT (jerry_delete_object_native_pointer (object1_value, &native_info_4)); + TEST_ASSERT (jerry_object_delete_native_ptr (object1_value, &native_info_4)); - jerry_native_pointer_release_references ((void *) &test_references4, &native_info_4); + jerry_native_ptr_free ((void *) &test_references4, &native_info_4); - jerry_release_value (object1_value); - jerry_release_value (object2_value); + jerry_value_free (object1_value); + jerry_value_free (object2_value); /* Delete references */ for (int i = 0; i < 3; i++) { - object1_value = jerry_create_object (); + object1_value = jerry_object (); - jerry_set_object_native_pointer (object1_value, global_p, NULL); - jerry_set_object_native_pointer (object1_value, (void *) &test_references4, &native_info_4); - jerry_set_object_native_pointer (object1_value, global_p, &native_info_2); + jerry_object_set_native_ptr (object1_value, NULL, global_p); + jerry_object_set_native_ptr (object1_value, &native_info_4, (void *) &test_references4); + jerry_object_set_native_ptr (object1_value, &native_info_2, global_p); set_references (&test_references4, string1_value, string2_value, object1_value); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); if (i == 1) { - TEST_ASSERT (jerry_delete_object_native_pointer (object1_value, NULL)); + TEST_ASSERT (jerry_object_delete_native_ptr (object1_value, NULL)); } else if (i == 2) { - TEST_ASSERT (jerry_delete_object_native_pointer (object1_value, &native_info_2)); + TEST_ASSERT (jerry_object_delete_native_ptr (object1_value, &native_info_2)); } - TEST_ASSERT (jerry_delete_object_native_pointer (object1_value, &native_info_4)); - jerry_native_pointer_release_references ((void *) &test_references4, &native_info_4); - jerry_release_value (object1_value); + TEST_ASSERT (jerry_object_delete_native_ptr (object1_value, &native_info_4)); + jerry_native_ptr_free ((void *) &test_references4, &native_info_4); + jerry_value_free (object1_value); } - jerry_release_value (string1_value); - jerry_release_value (string2_value); + jerry_value_free (string1_value); + jerry_value_free (string2_value); - jerry_release_value (object_value); + jerry_value_free (object_value); jerry_cleanup (); diff --git a/tests/unit-core/test-newtarget.c b/tests/unit-core/test-newtarget.c index 861083fe9b..e03e02424b 100644 --- a/tests/unit-core/test-newtarget.c +++ b/tests/unit-core/test-newtarget.c @@ -26,16 +26,16 @@ static jerry_value_t register_js_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t function_val = jerry_create_external_function (handler_p); - jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val); + jerry_value_t function_val = jerry_function_external (handler_p); + jerry_value_t function_name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_set (global_obj_val, function_name_val, function_val); - jerry_release_value (function_name_val); - jerry_release_value (global_obj_val); + jerry_value_free (function_name_val); + jerry_value_free (global_obj_val); - jerry_release_value (result_val); + jerry_value_free (result_val); return function_val; } /* register_js_function */ @@ -59,7 +59,7 @@ construct_handler (const jerry_call_info_t *call_info_p, /**< call information * TEST_ASSERT (0 && "Invalid arguments for demo method"); } - int test_id = (int) jerry_get_number_value (args_p[0]); + int test_id = (int) jerry_value_as_number (args_p[0]); switch (test_id) { @@ -87,11 +87,11 @@ construct_handler (const jerry_call_info_t *call_info_p, /**< call information * TEST_ASSERT (target == call_info_p->function); /* Calling a function should hide the old "new.target". */ - jerry_value_t sub_arg = jerry_create_number (TEST_ID_SIMPLE_CALL); + jerry_value_t sub_arg = jerry_number (TEST_ID_SIMPLE_CALL); jerry_value_t func_call_result; - func_call_result = jerry_call_function (call_info_p->function, call_info_p->this_value, &sub_arg, 1); - TEST_ASSERT (!jerry_value_is_error (func_call_result)); + func_call_result = jerry_call (call_info_p->function, call_info_p->this_value, &sub_arg, 1); + TEST_ASSERT (!jerry_value_is_exception (func_call_result)); TEST_ASSERT (jerry_value_is_undefined (func_call_result)); break; } @@ -103,14 +103,14 @@ construct_handler (const jerry_call_info_t *call_info_p, /**< call information * } } - return jerry_create_undefined (); + return jerry_undefined (); } /* construct_handler */ int main (void) { /* Test JERRY_FEATURE_SYMBOL feature as it is a must-have in ES.next */ - if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (!jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Skipping test, ES.next support is disabled.\n"); return 0; @@ -121,57 +121,57 @@ main (void) jerry_value_t demo_func = register_js_function ("Demo", construct_handler); { - jerry_value_t test_arg = jerry_create_number (TEST_ID_SIMPLE_CONSTRUCT); - jerry_value_t constructed = jerry_construct_object (demo_func, &test_arg, 1); - TEST_ASSERT (!jerry_value_is_error (constructed)); + jerry_value_t test_arg = jerry_number (TEST_ID_SIMPLE_CONSTRUCT); + jerry_value_t constructed = jerry_construct (demo_func, &test_arg, 1); + TEST_ASSERT (!jerry_value_is_exception (constructed)); TEST_ASSERT (jerry_value_is_object (constructed)); - jerry_release_value (test_arg); - jerry_release_value (constructed); + jerry_value_free (test_arg); + jerry_value_free (constructed); } { - jerry_value_t test_arg = jerry_create_number (TEST_ID_SIMPLE_CALL); - jerry_value_t this_arg = jerry_create_undefined (); - jerry_value_t constructed = jerry_call_function (demo_func, this_arg, &test_arg, 1); + jerry_value_t test_arg = jerry_number (TEST_ID_SIMPLE_CALL); + jerry_value_t this_arg = jerry_undefined (); + jerry_value_t constructed = jerry_call (demo_func, this_arg, &test_arg, 1); TEST_ASSERT (jerry_value_is_undefined (constructed)); - jerry_release_value (constructed); - jerry_release_value (constructed); - jerry_release_value (test_arg); + jerry_value_free (constructed); + jerry_value_free (constructed); + jerry_value_free (test_arg); } { - jerry_value_t test_arg = jerry_create_number (TEST_ID_CONSTRUCT_AND_CALL_SUB); - jerry_value_t constructed = jerry_construct_object (demo_func, &test_arg, 1); - TEST_ASSERT (!jerry_value_is_error (constructed)); + jerry_value_t test_arg = jerry_number (TEST_ID_CONSTRUCT_AND_CALL_SUB); + jerry_value_t constructed = jerry_construct (demo_func, &test_arg, 1); + TEST_ASSERT (!jerry_value_is_exception (constructed)); TEST_ASSERT (jerry_value_is_object (constructed)); - jerry_release_value (test_arg); - jerry_release_value (constructed); + jerry_value_free (test_arg); + jerry_value_free (constructed); } { static const jerry_char_t test_source[] = TEST_STRING_LITERAL ("new Demo (1)"); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); } { static const jerry_char_t test_source[] = TEST_STRING_LITERAL ("Demo (2)"); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); } { @@ -181,16 +181,16 @@ main (void) "new base(3);"); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); } - jerry_release_value (demo_func); + jerry_value_free (demo_func); jerry_cleanup (); return 0; } /* main */ diff --git a/tests/unit-core/test-number-converter.c b/tests/unit-core/test-number-converter.c index 71e5e71261..9b7116cb27 100644 --- a/tests/unit-core/test-number-converter.c +++ b/tests/unit-core/test-number-converter.c @@ -21,30 +21,30 @@ static void test_to_uint32 (double input, uint32_t test_number) { - jerry_value_t number_val = jerry_create_number (input); + jerry_value_t number_val = jerry_number (input); uint32_t uint_number = jerry_value_as_uint32 (number_val); TEST_ASSERT (uint_number == test_number); - jerry_release_value (number_val); + jerry_value_free (number_val); } /* test_to_uint32 */ // basic toInt32 tester method static void test_to_int32 (double input, int32_t test_number) { - jerry_value_t number_val = jerry_create_number (input); + jerry_value_t number_val = jerry_number (input); int32_t int_number = jerry_value_as_int32 (number_val); TEST_ASSERT (int_number == test_number); - jerry_release_value (number_val); + jerry_value_free (number_val); } /* test_to_int32 */ // basic toInteger tester method static void test_to_interger (double input, double test_number) { - jerry_value_t number_val = jerry_create_number (input); + jerry_value_t number_val = jerry_number (input); double double_number = jerry_value_as_integer (number_val); TEST_ASSERT (double_number == test_number); - jerry_release_value (number_val); + jerry_value_free (number_val); } /* test_to_interger */ int @@ -115,21 +115,21 @@ main (void) test_to_interger (-4294967297, -4294967297); // few test-cases which return with error - jerry_value_t error_val = jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error"); + jerry_value_t error_val = jerry_throw_sz (JERRY_ERROR_TYPE, "error"); double number = jerry_value_as_integer (error_val); - jerry_release_value (error_val); + jerry_value_free (error_val); TEST_ASSERT (number == 0); - error_val = jerry_create_symbol (error_val); + error_val = jerry_symbol_with_description (error_val); number = jerry_value_as_integer (error_val); TEST_ASSERT (number == 0); - jerry_release_value (error_val); + jerry_value_free (error_val); error_val = jerry_eval ((const jerry_char_t *) "({ valueOf() { throw new TypeError('foo')}})", 44, JERRY_PARSE_NO_OPTS); number = jerry_value_as_integer (error_val); TEST_ASSERT (number == 0); - jerry_release_value (error_val); + jerry_value_free (error_val); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-objects-foreach.c b/tests/unit-core/test-objects-foreach.c index 1cf6f48782..6ad0783d10 100644 --- a/tests/unit-core/test-objects-foreach.c +++ b/tests/unit-core/test-objects-foreach.c @@ -32,14 +32,14 @@ count_objects (jerry_value_t object, void *user_arg) static void test_container (void) { - jerry_value_t global = jerry_get_global_object (); - jerry_value_t map_str = jerry_create_string ((const jerry_char_t *) "Map"); - jerry_value_t map_result = jerry_get_property (global, map_str); - jerry_type_t type = jerry_value_get_type (map_result); + jerry_value_t global = jerry_current_realm (); + jerry_value_t map_str = jerry_string_sz ("Map"); + jerry_value_t map_result = jerry_object_get (global, map_str); + jerry_type_t type = jerry_value_type (map_result); - jerry_release_value (map_result); - jerry_release_value (map_str); - jerry_release_value (global); + jerry_value_free (map_result); + jerry_value_free (map_str); + jerry_value_free (global); /* If there is no Map function this is not an es.next profile build, skip this test case. */ if (type != JERRY_TYPE_FUNCTION) @@ -53,8 +53,8 @@ test_container (void) const char array_str[] = "var DEMO = [[1, 2], [3, 4]]; DEMO"; jerry_value_t array = jerry_eval ((const jerry_char_t *) array_str, sizeof (array_str) - 1, 0); TEST_ASSERT (jerry_value_is_object (array)); - TEST_ASSERT (!jerry_value_is_error (array)); - jerry_release_value (array); + TEST_ASSERT (!jerry_value_is_exception (array)); + jerry_value_free (array); } const char eval_str[] = "new Map (DEMO)"; @@ -62,73 +62,73 @@ test_container (void) /* Make sure that the Map and it's prototype object/function is initialized. */ jerry_value_t result = jerry_eval ((const jerry_char_t *) eval_str, sizeof (eval_str) - 1, 0); TEST_ASSERT (jerry_value_is_object (result)); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); } /* Do a bit of cleaning to clear up old objects. */ - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); /* Get the number of iterable objects. */ int start_count = 0; - jerry_objects_foreach (count_objects, &start_count); + jerry_foreach_live_object (count_objects, &start_count); /* Create another map. */ jerry_value_t result = jerry_eval ((const jerry_char_t *) eval_str, sizeof (eval_str) - 1, 0); /* Remove any old/unused objects. */ - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); /* Get the current number of objects. */ int end_count = 0; - jerry_objects_foreach (count_objects, &end_count); + jerry_foreach_live_object (count_objects, &end_count); /* As only one Map was created the number of available iterable objects should be incremented only by one. */ TEST_ASSERT (end_count > start_count); TEST_ASSERT ((end_count - start_count) == 1); - jerry_release_value (result); + jerry_value_free (result); } /* test_container */ static void test_internal_prop (void) { /* Make sure that the object is initialized in the engine. */ - jerry_value_t object_dummy = jerry_create_object (); + jerry_value_t object_dummy = jerry_object (); /* Get the number of iterable objects. */ int before_object_count = 0; - jerry_objects_foreach (count_objects, &before_object_count); + jerry_foreach_live_object (count_objects, &before_object_count); - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); /* After creating the object, the number of objects is incremented by one. */ int after_object_count = 0; { - jerry_objects_foreach (count_objects, &after_object_count); + jerry_foreach_live_object (count_objects, &after_object_count); TEST_ASSERT (after_object_count > before_object_count); TEST_ASSERT ((after_object_count - before_object_count) == 1); } - jerry_value_t internal_prop_name = jerry_create_string ((const jerry_char_t *) "hidden_foo"); - jerry_value_t internal_prop_object = jerry_create_object (); - bool internal_result = jerry_set_internal_property (object, internal_prop_name, internal_prop_object); + jerry_value_t internal_prop_name = jerry_string_sz ("hidden_foo"); + jerry_value_t internal_prop_object = jerry_object (); + bool internal_result = jerry_object_set_internal (object, internal_prop_name, internal_prop_object); TEST_ASSERT (internal_result == true); - jerry_release_value (internal_prop_name); - jerry_release_value (internal_prop_object); + jerry_value_free (internal_prop_name); + jerry_value_free (internal_prop_object); /* After adding an internal property object, the number of object is incremented by one. */ { int after_internal_count = 0; - jerry_objects_foreach (count_objects, &after_internal_count); + jerry_foreach_live_object (count_objects, &after_internal_count); TEST_ASSERT (after_internal_count > after_object_count); TEST_ASSERT ((after_internal_count - after_object_count) == 1); } - jerry_release_value (object); - jerry_release_value (object_dummy); + jerry_value_free (object); + jerry_value_free (object_dummy); } /* test_internal_prop */ static int test_data = 1; @@ -154,7 +154,7 @@ find_test_object_by_data (const jerry_value_t candidate, void *object_data_p, vo { if (object_data_p == &test_data) { - *((jerry_value_t *) context_p) = jerry_acquire_value (candidate); + *((jerry_value_t *) context_p) = jerry_value_copy (candidate); return false; } return true; @@ -164,17 +164,17 @@ static bool find_test_object_by_property (const jerry_value_t candidate, void *context_p) { jerry_value_t *args_p = (jerry_value_t *) context_p; - jerry_value_t result = jerry_has_property (candidate, args_p[0]); + jerry_value_t result = jerry_object_has (candidate, args_p[0]); - bool has_property = (!jerry_value_is_error (result) && jerry_value_is_true (result)); + bool has_property = (!jerry_value_is_exception (result) && jerry_value_is_true (result)); /* If the object has the desired property, store a new reference to it in args_p[1]. */ if (has_property) { - args_p[1] = jerry_acquire_value (candidate); + args_p[1] = jerry_value_copy (candidate); } - jerry_release_value (result); + jerry_value_free (result); /* Stop iterating if we've found our object. */ return !has_property; @@ -190,64 +190,64 @@ main (void) /* Render strict-equal as a function. */ jerry_value_t parse_result = jerry_parse (strict_equal_source, sizeof (strict_equal_source) - 1, &parse_options); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t strict_equal = jerry_run (parse_result); - TEST_ASSERT (!jerry_value_is_error (strict_equal)); - jerry_release_value (parse_result); + TEST_ASSERT (!jerry_value_is_exception (strict_equal)); + jerry_value_free (parse_result); /* Create an object and associate some native data with it. */ - jerry_value_t object = jerry_create_object (); - jerry_set_object_native_pointer (object, &test_data, &test_info); + jerry_value_t object = jerry_object (); + jerry_object_set_native_ptr (object, &test_info, &test_data); /* Retrieve the object by its native pointer. */ jerry_value_t found_object; - TEST_ASSERT (jerry_objects_foreach_by_native_info (&test_info, find_test_object_by_data, &found_object)); + TEST_ASSERT (jerry_foreach_live_object_with_info (&test_info, find_test_object_by_data, &found_object)); jerry_value_t args[2] = { object, found_object }; /* Assert that the correct object was retrieved. */ - jerry_value_t undefined = jerry_create_undefined (); - jerry_value_t strict_equal_result = jerry_call_function (strict_equal, undefined, args, 2); + jerry_value_t undefined = jerry_undefined (); + jerry_value_t strict_equal_result = jerry_call (strict_equal, undefined, args, 2); TEST_ASSERT (jerry_value_is_boolean (strict_equal_result) && jerry_value_is_true (strict_equal_result)); - jerry_release_value (strict_equal_result); - jerry_release_value (found_object); - jerry_release_value (object); + jerry_value_free (strict_equal_result); + jerry_value_free (found_object); + jerry_value_free (object); /* Collect garbage. */ - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); /* Attempt to retrieve the object by its native pointer again. */ - TEST_ASSERT (!jerry_objects_foreach_by_native_info (&test_info, find_test_object_by_data, &found_object)); + TEST_ASSERT (!jerry_foreach_live_object_with_info (&test_info, find_test_object_by_data, &found_object)); /* Create an object and set a property on it. */ - object = jerry_create_object (); - jerry_value_t property_name = jerry_create_string ((jerry_char_t *) "xyzzy"); - jerry_value_t property_value = jerry_create_number (42); - jerry_release_value (jerry_set_property (object, property_name, property_value)); - jerry_release_value (property_value); + object = jerry_object (); + jerry_value_t property_name = jerry_string_sz ("xyzzy"); + jerry_value_t property_value = jerry_number (42); + jerry_value_free (jerry_object_set (object, property_name, property_value)); + jerry_value_free (property_value); /* Retrieve the object by the presence of its property, placing it at args[1]. */ args[0] = property_name; - TEST_ASSERT (jerry_objects_foreach (find_test_object_by_property, args)); + TEST_ASSERT (jerry_foreach_live_object (find_test_object_by_property, args)); /* Assert that the right object was retrieved and release both the original reference to it and the retrieved one. */ args[0] = object; - strict_equal_result = jerry_call_function (strict_equal, undefined, args, 2); + strict_equal_result = jerry_call (strict_equal, undefined, args, 2); TEST_ASSERT (jerry_value_is_boolean (strict_equal_result) && jerry_value_is_true (strict_equal_result)); - jerry_release_value (strict_equal_result); - jerry_release_value (args[0]); - jerry_release_value (args[1]); + jerry_value_free (strict_equal_result); + jerry_value_free (args[0]); + jerry_value_free (args[1]); /* Collect garbage. */ - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); /* Attempt to retrieve the object by the presence of its property again. */ args[0] = property_name; - TEST_ASSERT (!jerry_objects_foreach (find_test_object_by_property, args)); + TEST_ASSERT (!jerry_foreach_live_object (find_test_object_by_property, args)); - jerry_release_value (property_name); - jerry_release_value (undefined); - jerry_release_value (strict_equal); + jerry_value_free (property_name); + jerry_value_free (undefined); + jerry_value_free (strict_equal); test_container (); test_internal_prop (); diff --git a/tests/unit-core/test-promise-callback.c b/tests/unit-core/test-promise-callback.c index 5c7bfda079..e6d0e60bbb 100644 --- a/tests/unit-core/test-promise-callback.c +++ b/tests/unit-core/test-promise-callback.c @@ -108,12 +108,12 @@ run_eval (const uint8_t *event_list_p, /**< event list */ jerry_value_t result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - result = jerry_run_all_enqueued_jobs (); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + result = jerry_run_microtasks (); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); TEST_ASSERT (*next_event_p == UINT8_MAX); } /* run_eval */ @@ -123,14 +123,14 @@ main (void) { TEST_INIT (); - if (!jerry_is_feature_enabled (JERRY_FEATURE_PROMISE)) + if (!jerry_feature_enabled (JERRY_FEATURE_PROMISE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Promise is disabled!\n"); return 0; } /* The test system enables this feature when Promises are enabled. */ - TEST_ASSERT (jerry_is_feature_enabled (JERRY_FEATURE_PROMISE_CALLBACK)); + TEST_ASSERT (jerry_feature_enabled (JERRY_FEATURE_PROMISE_CALLBACK)); jerry_init (JERRY_INIT_EMPTY); @@ -139,7 +139,7 @@ main (void) | JERRY_PROMISE_EVENT_FILTER_ERROR | JERRY_PROMISE_EVENT_FILTER_REACTION_JOB | JERRY_PROMISE_EVENT_FILTER_ASYNC_MAIN | JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB); - jerry_promise_set_callback (filters, promise_callback, (void *) &user); + jerry_promise_event_cb (filters, promise_callback, (void *) &user); /* Test promise creation. */ static uint8_t events1[] = { C, C, C, E }; @@ -341,7 +341,7 @@ main (void) "p.then(() => {}).catch(() => {})\n"); /* Test disabled filters. */ - jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_DISABLE, promise_callback, (void *) &user); + jerry_promise_event_cb (JERRY_PROMISE_EVENT_FILTER_DISABLE, promise_callback, (void *) &user); static uint8_t events24[] = { E }; @@ -352,7 +352,7 @@ main (void) /* Test filtered events. */ filters = JERRY_PROMISE_EVENT_FILTER_REACTION_JOB | JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB; - jerry_promise_set_callback (filters, promise_callback, (void *) &user); + jerry_promise_event_cb (filters, promise_callback, (void *) &user); static uint8_t events25[] = { BR, AR, BRS, ARS, E }; diff --git a/tests/unit-core/test-promise.c b/tests/unit-core/test-promise.c index bf2fe3909f..7335355841 100644 --- a/tests/unit-core/test-promise.c +++ b/tests/unit-core/test-promise.c @@ -31,8 +31,8 @@ static const jerry_char_t test_source[] = TEST_STRING_LITERAL ("var p1 = create_ static int count_in_assert = 0; static jerry_value_t my_promise1; static jerry_value_t my_promise2; -static const jerry_char_t s1[] = "resolved"; -static const jerry_char_t s2[] = "rejected"; +static const char s1[] = "resolved"; +static const char s2[] = "rejected"; static jerry_value_t create_promise1_handler (const jerry_call_info_t *call_info_p, /**< call information */ @@ -43,8 +43,8 @@ create_promise1_handler (const jerry_call_info_t *call_info_p, /**< call informa JERRY_UNUSED (args_p); JERRY_UNUSED (args_cnt); - jerry_value_t ret = jerry_create_promise (); - my_promise1 = jerry_acquire_value (ret); + jerry_value_t ret = jerry_promise (); + my_promise1 = jerry_value_copy (ret); return ret; } /* create_promise1_handler */ @@ -58,8 +58,8 @@ create_promise2_handler (const jerry_call_info_t *call_info_p, /**< call informa JERRY_UNUSED (args_p); JERRY_UNUSED (args_cnt); - jerry_value_t ret = jerry_create_promise (); - my_promise2 = jerry_acquire_value (ret); + jerry_value_t ret = jerry_promise (); + my_promise2 = jerry_value_copy (ret); return ret; } /* create_promise2_handler */ @@ -75,7 +75,7 @@ assert_handler (const jerry_call_info_t *call_info_p, /**< call information */ if (args_cnt == 1 && jerry_value_is_true (args_p[0])) { - return jerry_create_boolean (true); + return jerry_boolean (true); } else { @@ -90,17 +90,17 @@ static void register_js_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t function_val = jerry_create_external_function (handler_p); - jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val); + jerry_value_t function_val = jerry_function_external (handler_p); + jerry_value_t function_name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_set (global_obj_val, function_name_val, function_val); - jerry_release_value (function_name_val); - jerry_release_value (function_val); - jerry_release_value (global_obj_val); + jerry_value_free (function_name_val); + jerry_value_free (function_val); + jerry_value_free (global_obj_val); - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_function */ int @@ -108,7 +108,7 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_PROMISE)) + if (!jerry_feature_enabled (JERRY_FEATURE_PROMISE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Promise is disabled!\n"); jerry_cleanup (); @@ -120,41 +120,41 @@ main (void) register_js_function ("assert", assert_handler); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); - /* Test jerry_create_promise and jerry_value_is_promise. */ + /* Test jerry_promise and jerry_value_is_promise. */ TEST_ASSERT (jerry_value_is_promise (my_promise1)); TEST_ASSERT (jerry_value_is_promise (my_promise2)); TEST_ASSERT (count_in_assert == 0); /* Test jerry_resolve_or_reject_promise. */ - jerry_value_t str_resolve = jerry_create_string (s1); - jerry_value_t str_reject = jerry_create_string (s2); + jerry_value_t str_resolve = jerry_string_sz (s1); + jerry_value_t str_reject = jerry_string_sz (s2); - jerry_resolve_or_reject_promise (my_promise1, str_resolve, true); - jerry_resolve_or_reject_promise (my_promise2, str_reject, false); + jerry_promise_resolve (my_promise1, str_resolve); + jerry_promise_reject (my_promise2, str_reject); /* The resolve/reject function should be invalid after the promise has the result. */ - jerry_resolve_or_reject_promise (my_promise2, str_resolve, true); - jerry_resolve_or_reject_promise (my_promise1, str_reject, false); + jerry_promise_resolve (my_promise2, str_resolve); + jerry_promise_reject (my_promise1, str_reject); /* Run the jobqueue. */ - res = jerry_run_all_enqueued_jobs (); + res = jerry_run_microtasks (); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (count_in_assert == 2); - jerry_release_value (my_promise1); - jerry_release_value (my_promise2); - jerry_release_value (str_resolve); - jerry_release_value (str_reject); + jerry_value_free (my_promise1); + jerry_value_free (my_promise2); + jerry_value_free (str_resolve); + jerry_value_free (str_reject); jerry_cleanup (); diff --git a/tests/unit-core/test-proxy.c b/tests/unit-core/test-proxy.c index c72ceda1db..56b23b9d2c 100644 --- a/tests/unit-core/test-proxy.c +++ b/tests/unit-core/test-proxy.c @@ -71,14 +71,14 @@ handler_get (const jerry_call_info_t *call_info_p, /**< call information */ const char expected[] = "value"; char buffer[10]; - jerry_size_t copied = jerry_string_to_char_buffer (args_p[1], (jerry_char_t *) buffer, 10); + jerry_size_t copied = jerry_string_to_buffer (args_p[1], (jerry_char_t *) buffer, 10, JERRY_ENCODING_CESU8); TEST_ASSERT (copied == 5); TEST_ASSERT (strncmp (expected, buffer, 5) == 0); demo_value++; - return jerry_create_number (demo_value); + return jerry_number (demo_value); } /* handler_get */ static jerry_value_t @@ -98,15 +98,15 @@ handler_set (const jerry_call_info_t *call_info_p, /**< call information */ const char expected[] = "value"; char buffer[10]; - jerry_size_t copied = jerry_string_to_char_buffer (args_p[1], (jerry_char_t *) buffer, 10); + jerry_size_t copied = jerry_string_to_buffer (args_p[1], (jerry_char_t *) buffer, 10, JERRY_ENCODING_CESU8); TEST_ASSERT (copied == 5); TEST_ASSERT (strncmp (expected, buffer, 5) == 0); TEST_ASSERT (jerry_value_is_number (args_p[2])); - demo_value = (int) jerry_get_number_value (args_p[2]); + demo_value = (int) jerry_value_as_number (args_p[2]); - return jerry_create_number (demo_value); + return jerry_number (demo_value); } /* handler_set */ static void @@ -114,23 +114,23 @@ set_property (jerry_value_t target, /**< target object */ const char *name_p, /**< name of the property */ jerry_value_t value) /**< value of the property */ { - jerry_value_t name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_set_property (target, name_val, value); + jerry_value_t name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_set (target, name_val, value); TEST_ASSERT (jerry_value_is_boolean (result_val)); TEST_ASSERT (jerry_value_is_true (result_val)); - jerry_release_value (name_val); + jerry_value_free (name_val); } /* set_property */ static jerry_value_t get_property (jerry_value_t target, /**< target object */ const char *name_p) /**< name of the property */ { - jerry_value_t name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_get_property (target, name_val); + jerry_value_t name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_get (target, name_val); - TEST_ASSERT (!jerry_value_is_error (result_val)); - jerry_release_value (name_val); + TEST_ASSERT (!jerry_value_is_exception (result_val)); + jerry_value_free (name_val); return result_val; } /* get_property */ @@ -139,9 +139,9 @@ set_function (jerry_value_t target, /**< target object */ const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t function_val = jerry_create_external_function (handler_p); + jerry_value_t function_val = jerry_function_external (handler_p); set_property (target, name_p, function_val); - jerry_release_value (function_val); + jerry_value_free (function_val); } /* set_function */ struct test_data @@ -178,12 +178,12 @@ proxy_native_handler_get (const jerry_call_info_t *call_info_p, /**< call inform TEST_ASSERT (jerry_value_is_proxy (receiver)); /* Check if proxy has the native ptr. */ - struct test_data *native_p; - bool has_p = jerry_get_object_native_pointer (receiver, (void *) &native_p, &proxy_native_info); - TEST_ASSERT (has_p == true); + TEST_ASSERT (jerry_object_has_native_ptr (receiver, &proxy_native_info)); + struct test_data *native_p = jerry_object_get_native_ptr (receiver, &proxy_native_info); + TEST_ASSERT (native_p != NULL); native_p->value <<= 1; - return jerry_create_number (native_p->value); + return jerry_number (native_p->value); } /* proxy_native_handler_get */ /** @@ -192,30 +192,30 @@ proxy_native_handler_get (const jerry_call_info_t *call_info_p, /**< call inform static void test_proxy_native (void) { - jerry_value_t handler = jerry_create_object (); + jerry_value_t handler = jerry_object (); set_function (handler, "get", proxy_native_handler_get); - jerry_value_t target = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); struct test_data *data = (struct test_data *) malloc (sizeof (struct test_data)); data->value = 2; - jerry_set_object_native_pointer (proxy, data, &proxy_native_info); + jerry_object_set_native_ptr (proxy, &proxy_native_info, data); /* Call: proxy[10] */ - jerry_value_t result_for_10 = jerry_get_property_by_index (proxy, 10); + jerry_value_t result_for_10 = jerry_object_get_index (proxy, 10); TEST_ASSERT (jerry_value_is_number (result_for_10)); - TEST_ASSERT (jerry_get_number_value (result_for_10) == 4.0); + TEST_ASSERT (jerry_value_as_number (result_for_10) == 4.0); /* Call: proxy[5] */ data->value = 8; - jerry_value_t result_for_5 = jerry_get_property_by_index (proxy, 5); + jerry_value_t result_for_5 = jerry_object_get_index (proxy, 5); TEST_ASSERT (jerry_value_is_number (result_for_5)); - TEST_ASSERT (jerry_get_number_value (result_for_5) == 16.0); + TEST_ASSERT (jerry_value_as_number (result_for_5) == 16.0); - jerry_release_value (handler); - jerry_release_value (target); - jerry_release_value (proxy); + jerry_value_free (handler); + jerry_value_free (target); + jerry_value_free (proxy); } /* test_proxy_native */ int @@ -223,7 +223,7 @@ main (void) { TEST_INIT (); - if (!jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (!jerry_feature_enabled (JERRY_FEATURE_PROXY)) { printf ("Skipping test, Proxy not enabled\n"); return 0; @@ -231,134 +231,134 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t handler = jerry_create_object (); + jerry_value_t handler = jerry_object (); { set_function (handler, "get", handler_get); set_function (handler, "set", handler_set); } - jerry_value_t target = jerry_create_object (); - jerry_value_t proxy = jerry_create_proxy (target, handler); + jerry_value_t target = jerry_object (); + jerry_value_t proxy = jerry_proxy (target, handler); { - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); set_property (global, "pdemo", proxy); - jerry_release_value (global); + jerry_value_free (global); } const jerry_char_t get_value_src[] = TEST_STRING_LITERAL ("pdemo.value"); jerry_value_t parsed_get_code_val = jerry_parse (get_value_src, sizeof (get_value_src) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_get_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_get_code_val)); { jerry_value_t res = jerry_run (parsed_get_code_val); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == 1.0); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == 1.0); + jerry_value_free (res); } { jerry_value_t res = get_property (proxy, "value"); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == 2.0); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == 2.0); + jerry_value_free (res); } { jerry_value_t res = jerry_run (parsed_get_code_val); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == 3.0); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == 3.0); + jerry_value_free (res); } const jerry_char_t set_value_src[] = TEST_STRING_LITERAL ("pdemo.value = 55"); jerry_value_t parsed_set_code_val = jerry_parse (set_value_src, sizeof (set_value_src) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_set_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_set_code_val)); { jerry_value_t res = jerry_run (parsed_set_code_val); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == 55); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == 55); + jerry_value_free (res); } { jerry_value_t res = jerry_run (parsed_get_code_val); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == 56); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == 56); + jerry_value_free (res); } { - jerry_value_t new_value = jerry_create_number (12); + jerry_value_t new_value = jerry_number (12); set_property (proxy, "value", new_value); - jerry_release_value (new_value); + jerry_value_free (new_value); } { jerry_value_t res = get_property (proxy, "value"); TEST_ASSERT (jerry_value_is_number (res)); - TEST_ASSERT (jerry_get_number_value (res) == 13.0); - jerry_release_value (res); + TEST_ASSERT (jerry_value_as_number (res) == 13.0); + jerry_value_free (res); } - jerry_release_value (parsed_set_code_val); - jerry_release_value (parsed_get_code_val); - jerry_release_value (proxy); - jerry_release_value (target); - jerry_release_value (handler); + jerry_value_free (parsed_set_code_val); + jerry_value_free (parsed_get_code_val); + jerry_value_free (proxy); + jerry_value_free (target); + jerry_value_free (handler); { const jerry_char_t has_value_src[] = TEST_STRING_LITERAL ("new Proxy({}, {\n" " has: function(target, key) { throw 33 }\n" "})"); jerry_value_t parsed_has_code_val = jerry_parse (has_value_src, sizeof (has_value_src) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_has_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_has_code_val)); jerry_value_t res = jerry_run (parsed_has_code_val); - jerry_release_value (parsed_has_code_val); + jerry_value_free (parsed_has_code_val); TEST_ASSERT (jerry_value_is_proxy (res)); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "key"); + jerry_value_t name = jerry_string_sz ("key"); TEST_ASSERT (jerry_value_is_string (name)); - jerry_value_t property = jerry_has_property (res, name); - jerry_release_value (name); - jerry_release_value (res); - - TEST_ASSERT (jerry_value_is_error (property)); - property = jerry_get_value_from_error (property, true); - TEST_ASSERT (jerry_get_number_value (property) == 33); - jerry_release_value (property); + jerry_value_t property = jerry_object_has (res, name); + jerry_value_free (name); + jerry_value_free (res); + + TEST_ASSERT (jerry_value_is_exception (property)); + property = jerry_exception_value (property, true); + TEST_ASSERT (jerry_value_as_number (property) == 33); + jerry_value_free (property); } - target = jerry_create_object (); - handler = jerry_create_object (); - proxy = jerry_create_proxy (target, handler); + target = jerry_object (); + handler = jerry_object (); + proxy = jerry_proxy (target, handler); { - jerry_value_t res = jerry_get_proxy_target (proxy); + jerry_value_t res = jerry_proxy_target (proxy); TEST_ASSERT (res == target); - jerry_release_value (res); + jerry_value_free (res); - res = jerry_get_proxy_handler (proxy); + res = jerry_proxy_handler (proxy); TEST_ASSERT (res == handler); - jerry_release_value (res); - - res = jerry_get_proxy_target (target); - TEST_ASSERT (jerry_value_is_error (res)); - res = jerry_get_value_from_error (res, true); - TEST_ASSERT (jerry_get_error_type (res) == JERRY_ERROR_TYPE); - jerry_release_value (res); - - res = jerry_get_proxy_handler (handler); - TEST_ASSERT (jerry_value_is_error (res)); - res = jerry_get_value_from_error (res, true); - TEST_ASSERT (jerry_get_error_type (res) == JERRY_ERROR_TYPE); - jerry_release_value (res); + jerry_value_free (res); + + res = jerry_proxy_target (target); + TEST_ASSERT (jerry_value_is_exception (res)); + res = jerry_exception_value (res, true); + TEST_ASSERT (jerry_error_type (res) == JERRY_ERROR_TYPE); + jerry_value_free (res); + + res = jerry_proxy_handler (handler); + TEST_ASSERT (jerry_value_is_exception (res)); + res = jerry_exception_value (res, true); + TEST_ASSERT (jerry_error_type (res) == JERRY_ERROR_TYPE); + jerry_value_free (res); } - jerry_release_value (proxy); - jerry_release_value (handler); - jerry_release_value (target); + jerry_value_free (proxy); + jerry_value_free (handler); + jerry_value_free (target); test_proxy_native (); diff --git a/tests/unit-core/test-realm.c b/tests/unit-core/test-realm.c index 2d4f7a49d4..db088fd5b0 100644 --- a/tests/unit-core/test-realm.c +++ b/tests/unit-core/test-realm.c @@ -22,29 +22,29 @@ create_number_property (jerry_value_t object_value, /**< object value */ char *name_p, /**< name */ double number) /**< value */ { - jerry_value_t name_value = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t number_value = jerry_create_number (number); - jerry_value_t result_value = jerry_set_property (object_value, name_value, number_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); - - jerry_release_value (result_value); - jerry_release_value (number_value); - jerry_release_value (name_value); + jerry_value_t name_value = jerry_string_sz (name_p); + jerry_value_t number_value = jerry_number (number); + jerry_value_t result_value = jerry_object_set (object_value, name_value, number_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + + jerry_value_free (result_value); + jerry_value_free (number_value); + jerry_value_free (name_value); } /* create_number_property */ static double get_number_property (jerry_value_t object_value, /**< object value */ char *name_p) /**< name */ { - jerry_value_t name_value = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_value = jerry_get_property (object_value, name_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); + jerry_value_t name_value = jerry_string_sz (name_p); + jerry_value_t result_value = jerry_object_get (object_value, name_value); + TEST_ASSERT (!jerry_value_is_exception (result_value)); TEST_ASSERT (jerry_value_is_number (result_value)); - double result = jerry_get_number_value (result_value); + double result = jerry_value_as_number (result_value); - jerry_release_value (result_value); - jerry_release_value (name_value); + jerry_value_free (result_value); + jerry_value_free (name_value); return result; } /* get_number_property */ @@ -55,39 +55,39 @@ eval_and_get_number (char *script_p) /**< script source */ result_value = jerry_eval ((const jerry_char_t *) script_p, strlen (script_p), JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_number (result_value)); - double result = jerry_get_number_value (result_value); - jerry_release_value (result_value); + double result = jerry_value_as_number (result_value); + jerry_value_free (result_value); return result; } /* eval_and_get_number */ static void check_type_error (jerry_value_t result_value) /**< result value */ { - TEST_ASSERT (jerry_value_is_error (result_value)); - result_value = jerry_get_value_from_error (result_value, true); - TEST_ASSERT (jerry_get_error_type (result_value) == JERRY_ERROR_TYPE); - jerry_release_value (result_value); + TEST_ASSERT (jerry_value_is_exception (result_value)); + result_value = jerry_exception_value (result_value, true); + TEST_ASSERT (jerry_error_type (result_value) == JERRY_ERROR_TYPE); + jerry_value_free (result_value); } /* check_type_error */ static void check_array_prototype (jerry_value_t realm_value, jerry_value_t result_value) { - jerry_value_t name_value = jerry_create_string ((const jerry_char_t *) "Array"); - jerry_value_t array_value = jerry_get_property (realm_value, name_value); + jerry_value_t name_value = jerry_string_sz ("Array"); + jerry_value_t array_value = jerry_object_get (realm_value, name_value); TEST_ASSERT (jerry_value_is_object (array_value)); - jerry_release_value (name_value); + jerry_value_free (name_value); - name_value = jerry_create_string ((const jerry_char_t *) "prototype"); - jerry_value_t prototype_value = jerry_get_property (array_value, name_value); + name_value = jerry_string_sz ("prototype"); + jerry_value_t prototype_value = jerry_object_get (array_value, name_value); TEST_ASSERT (jerry_value_is_object (prototype_value)); - jerry_release_value (name_value); - jerry_release_value (array_value); + jerry_value_free (name_value); + jerry_value_free (array_value); - jerry_value_t compare_value = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, result_value, prototype_value); - jerry_release_value (prototype_value); + jerry_value_t compare_value = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, result_value, prototype_value); + jerry_value_free (prototype_value); TEST_ASSERT (jerry_value_is_boolean (compare_value) && jerry_value_is_true (compare_value)); - jerry_release_value (compare_value); + jerry_value_free (compare_value); } /* check_array_prototype */ /** @@ -100,22 +100,22 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_value = jerry_get_global_object (); - jerry_value_t result_value = jerry_realm_get_this (global_value); + jerry_value_t global_value = jerry_current_realm (); + jerry_value_t result_value = jerry_realm_this (global_value); TEST_ASSERT (global_value == result_value); - jerry_release_value (global_value); + jerry_value_free (global_value); - jerry_value_t number_value = jerry_create_number (3); - check_type_error (jerry_realm_get_this (number_value)); - jerry_release_value (number_value); + jerry_value_t number_value = jerry_number (3); + check_type_error (jerry_realm_this (number_value)); + jerry_value_free (number_value); - if (!jerry_is_feature_enabled (JERRY_FEATURE_REALM)) + if (!jerry_feature_enabled (JERRY_FEATURE_REALM)) { printf ("Skipping test, Realms not enabled\n"); return 0; } - jerry_value_t realm_value = jerry_create_realm (); + jerry_value_t realm_value = jerry_realm (); create_number_property (global_value, "a", 3.5); create_number_property (global_value, "b", 7.25); @@ -139,120 +139,120 @@ main (void) result_value = jerry_set_realm (global_value); TEST_ASSERT (result_value == realm_value); - jerry_value_t object_value = jerry_create_object (); + jerry_value_t object_value = jerry_object (); check_type_error (jerry_set_realm (object_value)); - jerry_release_value (object_value); + jerry_value_free (object_value); - number_value = jerry_create_number (5); + number_value = jerry_number (5); check_type_error (jerry_set_realm (number_value)); - jerry_release_value (number_value); + jerry_value_free (number_value); - jerry_release_value (global_value); - jerry_release_value (realm_value); + jerry_value_free (global_value); + jerry_value_free (realm_value); - realm_value = jerry_create_realm (); + realm_value = jerry_realm (); - result_value = jerry_realm_get_this (realm_value); + result_value = jerry_realm_this (realm_value); TEST_ASSERT (result_value == realm_value); - jerry_release_value (result_value); + jerry_value_free (result_value); result_value = jerry_set_realm (realm_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); - object_value = jerry_create_object (); + TEST_ASSERT (!jerry_value_is_exception (result_value)); + object_value = jerry_object (); jerry_set_realm (result_value); - number_value = jerry_create_number (7); + number_value = jerry_number (7); check_type_error (jerry_realm_set_this (realm_value, number_value)); check_type_error (jerry_realm_set_this (number_value, object_value)); - jerry_release_value (number_value); + jerry_value_free (number_value); result_value = jerry_realm_set_this (realm_value, object_value); TEST_ASSERT (jerry_value_is_boolean (result_value) && jerry_value_is_true (result_value)); - jerry_release_value (result_value); + jerry_value_free (result_value); create_number_property (object_value, "x", 7.25); create_number_property (object_value, "y", 1.25); result_value = jerry_set_realm (realm_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); + TEST_ASSERT (!jerry_value_is_exception (result_value)); TEST_ASSERT (eval_and_get_number ("var z = -5.5; x + this.y") == 8.5); jerry_set_realm (result_value); TEST_ASSERT (get_number_property (object_value, "z") == -5.5); - result_value = jerry_realm_get_this (realm_value); + result_value = jerry_realm_this (realm_value); TEST_ASSERT (result_value == object_value); - jerry_release_value (result_value); + jerry_value_free (result_value); - jerry_release_value (object_value); - jerry_release_value (realm_value); + jerry_value_free (object_value); + jerry_value_free (realm_value); - if (jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (jerry_feature_enabled (JERRY_FEATURE_PROXY)) { /* Check property creation. */ - jerry_value_t handler_value = jerry_create_object (); - jerry_value_t target_value = jerry_create_realm (); - jerry_value_t proxy_value = jerry_create_proxy (target_value, handler_value); + jerry_value_t handler_value = jerry_object (); + jerry_value_t target_value = jerry_realm (); + jerry_value_t proxy_value = jerry_proxy (target_value, handler_value); jerry_realm_set_this (target_value, proxy_value); - jerry_release_value (proxy_value); - jerry_release_value (handler_value); + jerry_value_free (proxy_value); + jerry_value_free (handler_value); jerry_value_t old_realm_value = jerry_set_realm (target_value); - TEST_ASSERT (!jerry_value_is_error (old_realm_value)); + TEST_ASSERT (!jerry_value_is_exception (old_realm_value)); TEST_ASSERT (eval_and_get_number ("var z = 1.5; z") == 1.5); jerry_set_realm (old_realm_value); TEST_ASSERT (get_number_property (target_value, "z") == 1.5); - jerry_release_value (target_value); + jerry_value_free (target_value); /* Check isExtensible error. */ const char *script_p = "new Proxy({}, { isExtensible: function() { throw 42.5 } })"; proxy_value = jerry_eval ((const jerry_char_t *) script_p, strlen (script_p), JERRY_PARSE_NO_OPTS); - TEST_ASSERT (!jerry_value_is_error (proxy_value) && jerry_value_is_object (proxy_value)); + TEST_ASSERT (!jerry_value_is_exception (proxy_value) && jerry_value_is_object (proxy_value)); - target_value = jerry_create_realm (); + target_value = jerry_realm (); jerry_realm_set_this (target_value, proxy_value); - jerry_release_value (proxy_value); + jerry_value_free (proxy_value); old_realm_value = jerry_set_realm (target_value); - TEST_ASSERT (!jerry_value_is_error (old_realm_value)); + TEST_ASSERT (!jerry_value_is_exception (old_realm_value)); script_p = "var z = 1.5"; result_value = jerry_eval ((const jerry_char_t *) script_p, strlen (script_p), JERRY_PARSE_NO_OPTS); jerry_set_realm (old_realm_value); - jerry_release_value (target_value); + jerry_value_free (target_value); - TEST_ASSERT (jerry_value_is_error (result_value)); - result_value = jerry_get_value_from_error (result_value, true); - TEST_ASSERT (jerry_value_is_number (result_value) && jerry_get_number_value (result_value) == 42.5); - jerry_release_value (result_value); + TEST_ASSERT (jerry_value_is_exception (result_value)); + result_value = jerry_exception_value (result_value, true); + TEST_ASSERT (jerry_value_is_number (result_value) && jerry_value_as_number (result_value) == 42.5); + jerry_value_free (result_value); } - realm_value = jerry_create_realm (); + realm_value = jerry_realm (); result_value = jerry_set_realm (realm_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); + TEST_ASSERT (!jerry_value_is_exception (result_value)); const char *script_p = "global2 = global1 - 1; Object.getPrototypeOf([])"; jerry_value_t script_value = jerry_parse ((const jerry_char_t *) script_p, strlen (script_p), NULL); - TEST_ASSERT (!jerry_value_is_error (script_value)); + TEST_ASSERT (!jerry_value_is_exception (script_value)); jerry_set_realm (result_value); /* Script is compiled in another realm. */ create_number_property (realm_value, "global1", 7.5); result_value = jerry_run (script_value); - TEST_ASSERT (!jerry_value_is_error (result_value)); + TEST_ASSERT (!jerry_value_is_exception (result_value)); check_array_prototype (realm_value, result_value); - jerry_release_value (result_value); - jerry_release_value (script_value); + jerry_value_free (result_value); + jerry_value_free (script_value); TEST_ASSERT (get_number_property (realm_value, "global2") == 6.5); - jerry_release_value (realm_value); + jerry_value_free (realm_value); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-regexp-dotall-unicode.c b/tests/unit-core/test-regexp-dotall-unicode.c index 516de1c8f1..b701680620 100644 --- a/tests/unit-core/test-regexp-dotall-unicode.c +++ b/tests/unit-core/test-regexp-dotall-unicode.c @@ -23,38 +23,38 @@ main (void) TEST_INIT (); jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (!jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ES.next support is disabled\n"); jerry_cleanup (); return 0; } - jerry_value_t undefined_this_arg = jerry_create_undefined (); - jerry_char_t pattern2[] = "\\u{61}.\\u{62}"; + jerry_value_t undefined_this_arg = jerry_undefined (); + char pattern2[] = "\\u{61}.\\u{62}"; uint16_t flags = JERRY_REGEXP_FLAG_DOTALL | JERRY_REGEXP_FLAG_UNICODE | JERRY_REGEXP_FLAG_STICKY; - jerry_value_t regex_obj = jerry_create_regexp (pattern2, flags); + jerry_value_t regex_obj = jerry_regexp_sz (pattern2, flags); TEST_ASSERT (jerry_value_is_object (regex_obj)); const jerry_char_t func_src2[] = "return [regex.exec('a\\nb'), regex.dotAll, regex.sticky, regex.unicode ];"; jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "regex"); + parse_options.argument_list = jerry_string_sz ("regex"); jerry_value_t func_val = jerry_parse (func_src2, sizeof (func_src2) - 1, &parse_options); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_options.argument_list); - jerry_value_t res = jerry_call_function (func_val, undefined_this_arg, ®ex_obj, 1); - jerry_value_t regex_res = jerry_get_property_by_index (res, 0); - jerry_value_t regex_res_str = jerry_get_property_by_index (regex_res, 0); - jerry_value_t is_dotall = jerry_get_property_by_index (res, 1); - jerry_value_t is_sticky = jerry_get_property_by_index (res, 2); - jerry_value_t is_unicode = jerry_get_property_by_index (res, 3); + jerry_value_t res = jerry_call (func_val, undefined_this_arg, ®ex_obj, 1); + jerry_value_t regex_res = jerry_object_get_index (res, 0); + jerry_value_t regex_res_str = jerry_object_get_index (regex_res, 0); + jerry_value_t is_dotall = jerry_object_get_index (res, 1); + jerry_value_t is_sticky = jerry_object_get_index (res, 2); + jerry_value_t is_unicode = jerry_object_get_index (res, 3); - jerry_size_t str_size = jerry_get_string_size (regex_res_str); + jerry_size_t str_size = jerry_string_size (regex_res_str, JERRY_ENCODING_CESU8); JERRY_VLA (jerry_char_t, res_buff, str_size); - jerry_size_t res_size = jerry_string_to_char_buffer (regex_res_str, res_buff, str_size); + jerry_size_t res_size = jerry_string_to_buffer (regex_res_str, res_buff, str_size, JERRY_ENCODING_CESU8); const char expected_result[] = "a\nb"; TEST_ASSERT (res_size == (sizeof (expected_result) - 1)); @@ -63,14 +63,14 @@ main (void) TEST_ASSERT (jerry_value_is_true (is_sticky)); TEST_ASSERT (jerry_value_is_true (is_unicode)); - jerry_release_value (regex_obj); - jerry_release_value (res); - jerry_release_value (func_val); - jerry_release_value (regex_res); - jerry_release_value (regex_res_str); - jerry_release_value (is_dotall); - jerry_release_value (is_sticky); - jerry_release_value (is_unicode); + jerry_value_free (regex_obj); + jerry_value_free (res); + jerry_value_free (func_val); + jerry_value_free (regex_res); + jerry_value_free (regex_res_str); + jerry_value_free (is_dotall); + jerry_value_free (is_sticky); + jerry_value_free (is_unicode); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-regexp.c b/tests/unit-core/test-regexp.c index 70cf8e177e..d35de5860d 100644 --- a/tests/unit-core/test-regexp.c +++ b/tests/unit-core/test-regexp.c @@ -23,48 +23,48 @@ main (void) TEST_INIT (); jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_char_t pattern[] = "[^.]+"; + char pattern[] = "[^.]+"; uint16_t flags = JERRY_REGEXP_FLAG_GLOBAL | JERRY_REGEXP_FLAG_MULTILINE; - jerry_value_t regex_obj = jerry_create_regexp (pattern, flags); + jerry_value_t regex_obj = jerry_regexp_sz (pattern, flags); TEST_ASSERT (jerry_value_is_object (regex_obj)); const jerry_char_t func_src[] = "return [regex.exec('something.domain.com'), regex.multiline, regex.global];"; jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "regex"); + parse_options.argument_list = jerry_string_sz ("regex"); jerry_value_t func_val = jerry_parse (func_src, sizeof (func_src) - 1, &parse_options); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_options.argument_list); - jerry_value_t res = jerry_call_function (func_val, global_obj_val, ®ex_obj, 1); - jerry_value_t regex_res = jerry_get_property_by_index (res, 0); - jerry_value_t regex_res_str = jerry_get_property_by_index (regex_res, 0); - jerry_value_t is_multiline = jerry_get_property_by_index (res, 1); - jerry_value_t is_global = jerry_get_property_by_index (res, 2); + jerry_value_t res = jerry_call (func_val, global_obj_val, ®ex_obj, 1); + jerry_value_t regex_res = jerry_object_get_index (res, 0); + jerry_value_t regex_res_str = jerry_object_get_index (regex_res, 0); + jerry_value_t is_multiline = jerry_object_get_index (res, 1); + jerry_value_t is_global = jerry_object_get_index (res, 2); const char expected_result[] = "something"; - jerry_size_t str_size = jerry_get_string_size (regex_res_str); + jerry_size_t str_size = jerry_string_size (regex_res_str, JERRY_ENCODING_CESU8); TEST_ASSERT (str_size == (sizeof (expected_result) - 1)); JERRY_VLA (jerry_char_t, res_buff, str_size); - jerry_size_t res_size = jerry_string_to_char_buffer (regex_res_str, res_buff, str_size); + jerry_size_t res_size = jerry_string_to_buffer (regex_res_str, res_buff, str_size, JERRY_ENCODING_CESU8); TEST_ASSERT (res_size == str_size); TEST_ASSERT (strncmp (expected_result, (const char *) res_buff, res_size) == 0); TEST_ASSERT (jerry_value_is_true (is_multiline)); TEST_ASSERT (jerry_value_is_true (is_global)); - jerry_release_value (regex_obj); - jerry_release_value (res); - jerry_release_value (func_val); - jerry_release_value (regex_res); - jerry_release_value (regex_res_str); - jerry_release_value (is_multiline); - jerry_release_value (is_global); - jerry_release_value (global_obj_val); + jerry_value_free (regex_obj); + jerry_value_free (res); + jerry_value_free (func_val); + jerry_value_free (regex_res); + jerry_value_free (regex_res_str); + jerry_value_free (is_multiline); + jerry_value_free (is_global); + jerry_value_free (global_obj_val); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-regression-3588.c b/tests/unit-core/test-regression-3588.c index 9effe6a36a..a69a0d8ee4 100644 --- a/tests/unit-core/test-regression-3588.c +++ b/tests/unit-core/test-regression-3588.c @@ -30,16 +30,16 @@ construct_handler (const jerry_call_info_t *call_info_p, /**< call information * JERRY_UNUSED (call_info_p); TEST_ASSERT (args_cnt == 1); - TEST_ASSERT (jerry_get_number_value (args_p[0]) == 1.0); + TEST_ASSERT (jerry_value_as_number (args_p[0]) == 1.0); - return jerry_create_undefined (); + return jerry_undefined (); } /* construct_handler */ int main (void) { /* Test JERRY_FEATURE_SYMBOL feature as it is a must-have in ES.next */ - if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (!jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Skipping test, ES.next support is disabled.\n"); return 0; @@ -48,17 +48,17 @@ main (void) jerry_init (JERRY_INIT_EMPTY); { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t function_val = jerry_create_external_function (construct_handler); - jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) "Demo"); - jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val); - TEST_ASSERT (!jerry_value_is_error (result_val)); + jerry_value_t function_val = jerry_function_external (construct_handler); + jerry_value_t function_name_val = jerry_string_sz ("Demo"); + jerry_value_t result_val = jerry_object_set (global_obj_val, function_name_val, function_val); + TEST_ASSERT (!jerry_value_is_exception (result_val)); TEST_ASSERT (jerry_value_is_true (result_val)); - jerry_release_value (result_val); - jerry_release_value (function_name_val); - jerry_release_value (global_obj_val); - jerry_release_value (function_val); + jerry_value_free (result_val); + jerry_value_free (function_name_val); + jerry_value_free (global_obj_val); + jerry_value_free (function_val); } { @@ -67,13 +67,13 @@ main (void) "new Sub1 ()"); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t result = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); - jerry_release_value (result); - jerry_release_value (parsed_code_val); + jerry_value_free (result); + jerry_value_free (parsed_code_val); } { @@ -81,13 +81,13 @@ main (void) "new Sub2 (1)"); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t result = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); - jerry_release_value (result); - jerry_release_value (parsed_code_val); + jerry_value_free (result); + jerry_value_free (parsed_code_val); } jerry_cleanup (); diff --git a/tests/unit-core/test-resource-name.c b/tests/unit-core/test-resource-name.c index 1ac1e99d6d..ce8b60cd68 100644 --- a/tests/unit-core/test-resource-name.c +++ b/tests/unit-core/test-resource-name.c @@ -19,25 +19,25 @@ #include "test-common.h" static jerry_value_t -resource_name_handler (const jerry_call_info_t *call_info_p, /**< call information */ - const jerry_value_t args_p[], /**< argument list */ - const jerry_length_t args_count) /**< argument count */ +source_name_handler (const jerry_call_info_t *call_info_p, /**< call information */ + const jerry_value_t args_p[], /**< argument list */ + const jerry_length_t args_count) /**< argument count */ { (void) call_info_p; - jerry_value_t undefined_value = jerry_create_undefined (); - jerry_value_t resource_name = jerry_get_resource_name (args_count > 0 ? args_p[0] : undefined_value); - jerry_release_value (undefined_value); + jerry_value_t undefined_value = jerry_undefined (); + jerry_value_t source_name = jerry_source_name (args_count > 0 ? args_p[0] : undefined_value); + jerry_value_free (undefined_value); - return resource_name; -} /* resource_name_handler */ + return source_name; +} /* source_name_handler */ int main (void) { TEST_INIT (); - if (!jerry_is_feature_enabled (JERRY_FEATURE_LINE_INFO)) + if (!jerry_feature_enabled (JERRY_FEATURE_LINE_INFO)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Line info support is disabled!\n"); return 0; @@ -45,22 +45,22 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); /* Register the "resourceName" method. */ { - jerry_value_t func = jerry_create_external_function (resource_name_handler); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "resourceName"); - jerry_value_t result = jerry_set_property (global, name, func); - jerry_release_value (result); - jerry_release_value (name); - jerry_release_value (func); + jerry_value_t func = jerry_function_external (source_name_handler); + jerry_value_t name = jerry_string_sz ("resourceName"); + jerry_value_t result = jerry_object_set (global, name, func); + jerry_value_free (result); + jerry_value_free (name); + jerry_value_free (func); } - jerry_release_value (global); + jerry_value_free (global); jerry_parse_options_t parse_options; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; const char *source_1 = ("function f1 () {\n" " if (resourceName() !== 'demo1.js') return false; \n" @@ -70,26 +70,25 @@ main (void) "} \n" "f1();"); - parse_options.resource_name = jerry_create_string ((jerry_char_t *) "demo1.js"); + parse_options.source_name = jerry_string_sz ("demo1.js"); jerry_value_t program = jerry_parse ((const jerry_char_t *) source_1, strlen (source_1), &parse_options); - TEST_ASSERT (!jerry_value_is_error (program)); + TEST_ASSERT (!jerry_value_is_exception (program)); jerry_value_t run_result = jerry_run (program); - TEST_ASSERT (!jerry_value_is_error (run_result)); + TEST_ASSERT (!jerry_value_is_exception (run_result)); TEST_ASSERT (jerry_value_is_object (run_result)); - jerry_value_t resource_value = jerry_get_resource_name (run_result); - jerry_value_t compare_result = - jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name); + jerry_value_t resource_value = jerry_source_name (run_result); + jerry_value_t compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (compare_result); - jerry_release_value (resource_value); - jerry_release_value (parse_options.resource_name); + jerry_value_free (compare_result); + jerry_value_free (resource_value); + jerry_value_free (parse_options.source_name); - jerry_release_value (run_result); - jerry_release_value (program); + jerry_value_free (run_result); + jerry_value_free (program); const char *source_2 = ("function f2 () { \n" " if (resourceName() !== 'demo2.js') return false; \n" @@ -101,127 +100,127 @@ main (void) "} \n" "f2(); \n"); - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "demo2.js"); + parse_options.source_name = jerry_string_sz ("demo2.js"); program = jerry_parse ((const jerry_char_t *) source_2, strlen (source_2), &parse_options); - TEST_ASSERT (!jerry_value_is_error (program)); + TEST_ASSERT (!jerry_value_is_exception (program)); run_result = jerry_run (program); - TEST_ASSERT (!jerry_value_is_error (run_result)); + TEST_ASSERT (!jerry_value_is_exception (run_result)); TEST_ASSERT (jerry_value_is_object (run_result)); - resource_value = jerry_get_resource_name (run_result); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name); + resource_value = jerry_source_name (run_result); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (compare_result); - jerry_release_value (resource_value); - jerry_release_value (parse_options.resource_name); + jerry_value_free (compare_result); + jerry_value_free (resource_value); + jerry_value_free (parse_options.source_name); - jerry_release_value (run_result); - jerry_release_value (program); - if (jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + jerry_value_free (run_result); + jerry_value_free (program); + if (jerry_feature_enabled (JERRY_FEATURE_MODULE)) { - jerry_value_t anon = jerry_create_string ((const jerry_char_t *) ""); + jerry_value_t anon = jerry_string_sz (""); const char *source_3 = ""; - parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((const jerry_char_t *) "demo3.js"); + parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("demo3.js"); program = jerry_parse ((const jerry_char_t *) source_3, strlen (source_3), &parse_options); - TEST_ASSERT (!jerry_value_is_error (program)); + TEST_ASSERT (!jerry_value_is_exception (program)); - resource_value = jerry_get_resource_name (program); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name); + resource_value = jerry_source_name (program); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (compare_result); - jerry_release_value (resource_value); + jerry_value_free (compare_result); + jerry_value_free (resource_value); run_result = jerry_module_link (program, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (run_result)); + TEST_ASSERT (!jerry_value_is_exception (run_result)); - resource_value = jerry_get_resource_name (run_result); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, anon); + resource_value = jerry_source_name (run_result); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, anon); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (compare_result); - jerry_release_value (resource_value); - jerry_release_value (run_result); + jerry_value_free (compare_result); + jerry_value_free (resource_value); + jerry_value_free (run_result); run_result = jerry_module_evaluate (program); - TEST_ASSERT (!jerry_value_is_error (run_result)); + TEST_ASSERT (!jerry_value_is_exception (run_result)); - resource_value = jerry_get_resource_name (run_result); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, anon); + resource_value = jerry_source_name (run_result); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, anon); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (compare_result); - jerry_release_value (resource_value); - jerry_release_value (run_result); - jerry_release_value (program); - jerry_release_value (parse_options.resource_name); + jerry_value_free (compare_result); + jerry_value_free (resource_value); + jerry_value_free (run_result); + jerry_value_free (program); + jerry_value_free (parse_options.source_name); } const char *source_4 = ("function f(){} \n" "f.bind().bind();"); - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((jerry_char_t *) "demo4.js"); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("demo4.js"); program = jerry_parse ((const jerry_char_t *) source_4, strlen (source_4), &parse_options); - TEST_ASSERT (!jerry_value_is_error (program)); + TEST_ASSERT (!jerry_value_is_exception (program)); run_result = jerry_run (program); - TEST_ASSERT (!jerry_value_is_error (run_result)); + TEST_ASSERT (!jerry_value_is_exception (run_result)); TEST_ASSERT (jerry_value_is_object (run_result)); - resource_value = jerry_get_resource_name (run_result); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name); + resource_value = jerry_source_name (run_result); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (compare_result); + jerry_value_free (compare_result); - jerry_release_value (resource_value); - jerry_release_value (parse_options.resource_name); - jerry_release_value (run_result); - jerry_release_value (program); + jerry_value_free (resource_value); + jerry_value_free (parse_options.source_name); + jerry_value_free (run_result); + jerry_value_free (program); const char *source_5 = ""; - parse_options.options = JERRY_PARSE_HAS_USER_VALUE | JERRY_PARSE_HAS_RESOURCE; - parse_options.user_value = jerry_create_object (); - parse_options.resource_name = jerry_create_string ((jerry_char_t *) "demo5.js"); + parse_options.options = JERRY_PARSE_HAS_USER_VALUE | JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.user_value = jerry_object (); + parse_options.source_name = jerry_string_sz ("demo5.js"); program = jerry_parse ((const jerry_char_t *) source_5, strlen (source_5), &parse_options); - TEST_ASSERT (!jerry_value_is_error (program)); + TEST_ASSERT (!jerry_value_is_exception (program)); - resource_value = jerry_get_resource_name (program); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name); + resource_value = jerry_source_name (program); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (resource_value); - jerry_release_value (compare_result); - jerry_release_value (parse_options.user_value); - jerry_release_value (parse_options.resource_name); - jerry_release_value (program); + jerry_value_free (resource_value); + jerry_value_free (compare_result); + jerry_value_free (parse_options.user_value); + jerry_value_free (parse_options.source_name); + jerry_value_free (program); const char *source_6 = "(class {})"; - parse_options.options = JERRY_PARSE_HAS_RESOURCE; - parse_options.resource_name = jerry_create_string ((jerry_char_t *) "demo6.js"); + parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; + parse_options.source_name = jerry_string_sz ("demo6.js"); program = jerry_parse ((const jerry_char_t *) source_6, strlen (source_6), &parse_options); - if (!jerry_value_is_error (program)) + if (!jerry_value_is_exception (program)) { - resource_value = jerry_get_resource_name (program); - compare_result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name); + resource_value = jerry_source_name (program); + compare_result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.source_name); TEST_ASSERT (jerry_value_is_true (compare_result)); - jerry_release_value (resource_value); - jerry_release_value (compare_result); + jerry_value_free (resource_value); + jerry_value_free (compare_result); } - jerry_release_value (parse_options.resource_name); - jerry_release_value (program); + jerry_value_free (parse_options.source_name); + jerry_value_free (program); jerry_cleanup (); diff --git a/tests/unit-core/test-script-user-value.c b/tests/unit-core/test-script-user-value.c index 7c473babac..9538f5ebc5 100644 --- a/tests/unit-core/test-script-user-value.c +++ b/tests/unit-core/test-script-user-value.c @@ -32,24 +32,24 @@ test_parse (const char *source_p, /**< source code */ options_p->user_value = user_values[i]; jerry_value_t result = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), options_p); - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); if (run_code) { jerry_value_t parse_result = result; result = jerry_run (result); - jerry_release_value (parse_result); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_free (parse_result); + TEST_ASSERT (!jerry_value_is_exception (result)); } - jerry_value_t user_value = jerry_get_user_value (result); - jerry_value_t compare_value = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, user_value, user_values[i]); + jerry_value_t user_value = jerry_source_user_value (result); + jerry_value_t compare_value = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, user_value, user_values[i]); TEST_ASSERT (jerry_value_is_true (compare_value)); - jerry_release_value (compare_value); - jerry_release_value (user_value); - jerry_release_value (result); + jerry_value_free (compare_value); + jerry_value_free (user_value); + jerry_value_free (result); } } /* test_parse */ @@ -59,36 +59,36 @@ test_parse_function (const char *source_p, /**< source code */ bool run_code) /**< run the code after parsing */ { options_p->options |= JERRY_PARSE_HAS_ARGUMENT_LIST; - options_p->argument_list = jerry_create_string ((const jerry_char_t *) ""); + options_p->argument_list = jerry_string_sz (""); for (size_t i = 0; i < USER_VALUES_SIZE; i++) { options_p->user_value = user_values[i]; jerry_value_t result = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), options_p); - TEST_ASSERT (!jerry_value_is_error (result)); + TEST_ASSERT (!jerry_value_is_exception (result)); if (run_code) { jerry_value_t parse_result = result; - jerry_value_t this_value = jerry_create_undefined (); - result = jerry_call_function (result, this_value, NULL, 0); - jerry_release_value (parse_result); - jerry_release_value (this_value); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_t this_value = jerry_undefined (); + result = jerry_call (result, this_value, NULL, 0); + jerry_value_free (parse_result); + jerry_value_free (this_value); + TEST_ASSERT (!jerry_value_is_exception (result)); } - jerry_value_t user_value = jerry_get_user_value (result); - jerry_value_t compare_value = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, user_value, user_values[i]); + jerry_value_t user_value = jerry_source_user_value (result); + jerry_value_t compare_value = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, user_value, user_values[i]); TEST_ASSERT (jerry_value_is_true (compare_value)); - jerry_release_value (compare_value); - jerry_release_value (user_value); - jerry_release_value (result); + jerry_value_free (compare_value); + jerry_value_free (user_value); + jerry_value_free (result); } - jerry_release_value (options_p->argument_list); + jerry_value_free (options_p->argument_list); } /* test_parse_function */ int @@ -98,10 +98,10 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - user_values[0] = jerry_create_object (); - user_values[1] = jerry_create_null (); - user_values[2] = jerry_create_number (5.5); - user_values[3] = jerry_create_string ((const jerry_char_t *) "AnyString..."); + user_values[0] = jerry_object (); + user_values[1] = jerry_null (); + user_values[2] = jerry_number (5.5); + user_values[3] = jerry_string_sz ("AnyString..."); jerry_parse_options_t parse_options; const char *source_p = TEST_STRING_LITERAL (""); @@ -110,7 +110,7 @@ main (void) test_parse (source_p, &parse_options, false); test_parse_function (source_p, &parse_options, false); - if (jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + if (jerry_feature_enabled (JERRY_FEATURE_MODULE)) { parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_USER_VALUE; test_parse (source_p, &parse_options, false); @@ -131,7 +131,7 @@ main (void) test_parse_function (source_p, &parse_options, true); /* There is no test for ESNEXT, using SYMBOL instead. */ - if (jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { source_p = TEST_STRING_LITERAL ("(class {})"); parse_options.options = JERRY_PARSE_HAS_USER_VALUE; @@ -180,14 +180,14 @@ main (void) for (size_t i = 0; i < USER_VALUES_SIZE; i++) { - jerry_value_t result = jerry_get_user_value (user_values[i]); + jerry_value_t result = jerry_source_user_value (user_values[i]); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); } for (size_t i = 0; i < USER_VALUES_SIZE; i++) { - jerry_release_value (user_values[i]); + jerry_value_free (user_values[i]); } jerry_cleanup (); diff --git a/tests/unit-core/test-snapshot.c b/tests/unit-core/test-snapshot.c index d4e4cc5991..8322f1e043 100644 --- a/tests/unit-core/test-snapshot.c +++ b/tests/unit-core/test-snapshot.c @@ -45,8 +45,7 @@ static void test_function_snapshot (void) { /* function to snapshot */ - if (!jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) - || !jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) + if (!jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) || !jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) { return; } @@ -60,20 +59,20 @@ test_function_snapshot (void) jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST; - parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "a, b"); + parse_options.argument_list = jerry_string_sz ("a, b"); jerry_value_t parse_result = jerry_parse (code_to_snapshot, sizeof (code_to_snapshot) - 1, &parse_options); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t generate_result = jerry_generate_snapshot (parse_result, 0, function_snapshot_buffer, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); - jerry_release_value (parse_options.argument_list); + jerry_value_free (parse_result); + jerry_value_free (parse_options.argument_list); - TEST_ASSERT (!jerry_value_is_error (generate_result) && jerry_value_is_number (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result)); - size_t function_snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t function_snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); @@ -85,25 +84,25 @@ test_function_snapshot (void) JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION, NULL); - TEST_ASSERT (!jerry_value_is_error (function_obj)); + TEST_ASSERT (!jerry_value_is_exception (function_obj)); TEST_ASSERT (jerry_value_is_function (function_obj)); - jerry_value_t this_val = jerry_create_undefined (); + jerry_value_t this_val = jerry_undefined (); jerry_value_t args[2]; - args[0] = jerry_create_number (1.0); - args[1] = jerry_create_number (2.0); + args[0] = jerry_number (1.0); + args[1] = jerry_number (2.0); - jerry_value_t res = jerry_call_function (function_obj, this_val, args, 2); + jerry_value_t res = jerry_call (function_obj, this_val, args, 2); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_number (res)); - double num = jerry_get_number_value (res); + double num = jerry_value_as_number (res); TEST_ASSERT (num == 3); - jerry_release_value (args[0]); - jerry_release_value (args[1]); - jerry_release_value (res); - jerry_release_value (function_obj); + jerry_value_free (args[0]); + jerry_value_free (args[1]); + jerry_value_free (res); + jerry_value_free (function_obj); jerry_cleanup (); } /* test_function_snapshot */ @@ -113,11 +112,11 @@ arguments_test_exec_snapshot (uint32_t *snapshot_p, size_t snapshot_size, uint32 { jerry_init (JERRY_INIT_EMPTY); jerry_value_t res = jerry_exec_snapshot (snapshot_p, snapshot_size, 0, exec_snapshot_flags, NULL); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_number (res)); - double raw_value = jerry_get_number_value (res); + double raw_value = jerry_value_as_number (res); TEST_ASSERT (raw_value == 15); - jerry_release_value (res); + jerry_value_free (res); jerry_cleanup (); } /* arguments_test_exec_snapshot */ @@ -125,7 +124,7 @@ arguments_test_exec_snapshot (uint32_t *snapshot_p, size_t snapshot_size, uint32 static void test_function_arguments_snapshot (void) { - if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) + if (jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) { static uint32_t arguments_snapshot_buffer[SNAPSHOT_BUFFER_SIZE]; @@ -139,16 +138,16 @@ test_function_arguments_snapshot (void) jerry_init (JERRY_INIT_EMPTY); jerry_value_t parse_result = jerry_parse (code_to_snapshot, sizeof (code_to_snapshot) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t generate_result = jerry_generate_snapshot (parse_result, 0, arguments_snapshot_buffer, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - TEST_ASSERT (!jerry_value_is_error (generate_result) && jerry_value_is_number (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result)); - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); @@ -170,13 +169,13 @@ test_exec_snapshot (uint32_t *snapshot_p, size_t snapshot_size, uint32_t exec_sn jerry_value_t res = jerry_exec_snapshot (snapshot_p, snapshot_size, 0, exec_snapshot_flags, NULL); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_string (res)); - jerry_size_t sz = jerry_get_string_size (res); + jerry_size_t sz = jerry_string_size (res, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 20); - sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz); + sz = jerry_string_to_buffer (res, (jerry_char_t *) string_data, sz, JERRY_ENCODING_CESU8); TEST_ASSERT (sz == 20); - jerry_release_value (res); + jerry_value_free (res); TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz)); jerry_cleanup (); @@ -185,7 +184,7 @@ test_exec_snapshot (uint32_t *snapshot_p, size_t snapshot_size, uint32_t exec_sn static void test_snapshot_with_user (void) { - if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) + if (jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) { static uint32_t snapshot_buffer[SNAPSHOT_BUFFER_SIZE]; @@ -194,15 +193,15 @@ test_snapshot_with_user (void) jerry_init (JERRY_INIT_EMPTY); jerry_value_t parse_result = jerry_parse (code_to_snapshot, sizeof (code_to_snapshot) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t generate_result = jerry_generate_snapshot (parse_result, 0, snapshot_buffer, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - TEST_ASSERT (!jerry_value_is_error (generate_result) && jerry_value_is_number (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result)); - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); for (int i = 0; i < 3; i++) { @@ -210,15 +209,15 @@ test_snapshot_with_user (void) if (i == 0) { - snapshot_exec_options.user_value = jerry_create_object (); + snapshot_exec_options.user_value = jerry_object (); } else if (i == 1) { - snapshot_exec_options.user_value = jerry_create_number (-3.5); + snapshot_exec_options.user_value = jerry_number (-3.5); } else { - snapshot_exec_options.user_value = jerry_create_string ((const jerry_char_t *) "AnyString..."); + snapshot_exec_options.user_value = jerry_string_sz ("AnyString..."); } jerry_value_t result = jerry_exec_snapshot (snapshot_buffer, @@ -227,18 +226,18 @@ test_snapshot_with_user (void) JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE, &snapshot_exec_options); - TEST_ASSERT (!jerry_value_is_error (result) && jerry_value_is_function (result)); + TEST_ASSERT (!jerry_value_is_exception (result) && jerry_value_is_function (result)); - jerry_value_t user_value = jerry_get_user_value (result); - jerry_release_value (result); + jerry_value_t user_value = jerry_source_user_value (result); + jerry_value_free (result); - result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, user_value, snapshot_exec_options.user_value); + result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, user_value, snapshot_exec_options.user_value); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); - jerry_release_value (user_value); - jerry_release_value (snapshot_exec_options.user_value); + jerry_value_free (result); + jerry_value_free (user_value); + jerry_value_free (snapshot_exec_options.user_value); } jerry_cleanup (); @@ -251,7 +250,7 @@ main (void) TEST_INIT (); /* Static snapshot */ - if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) + if (jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) { static uint32_t snapshot_buffer[SNAPSHOT_BUFFER_SIZE]; const jerry_char_t code_to_snapshot[] = TEST_STRING_LITERAL ("function func(a, b, c) {" @@ -266,21 +265,21 @@ main (void) magic_string_lengths); jerry_value_t parse_result = jerry_parse (code_to_snapshot, sizeof (code_to_snapshot) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t generate_result = jerry_generate_snapshot (parse_result, JERRY_SNAPSHOT_SAVE_STATIC, snapshot_buffer, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - TEST_ASSERT (!jerry_value_is_error (generate_result) && jerry_value_is_number (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result)); - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); /* Static snapshots are not supported by default. */ jerry_value_t exec_result = jerry_exec_snapshot (snapshot_buffer, snapshot_size, 0, 0, NULL); - TEST_ASSERT (jerry_value_is_error (exec_result)); - jerry_release_value (exec_result); + TEST_ASSERT (jerry_value_is_exception (exec_result)); + jerry_value_free (exec_result); jerry_cleanup (); @@ -288,7 +287,7 @@ main (void) } /* Merge snapshot */ - if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) + if (jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC)) { static uint32_t snapshot_buffer_0[SNAPSHOT_BUFFER_SIZE]; static uint32_t snapshot_buffer_1[SNAPSHOT_BUFFER_SIZE]; @@ -300,15 +299,15 @@ main (void) jerry_init (JERRY_INIT_EMPTY); jerry_value_t parse_result = jerry_parse (code_to_snapshot1, sizeof (code_to_snapshot1) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t generate_result = jerry_generate_snapshot (parse_result, 0, snapshot_buffer_0, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - TEST_ASSERT (!jerry_value_is_error (generate_result) && jerry_value_is_number (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result)); - snapshot_sizes[0] = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + snapshot_sizes[0] = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); @@ -317,15 +316,15 @@ main (void) jerry_init (JERRY_INIT_EMPTY); parse_result = jerry_parse (code_to_snapshot2, sizeof (code_to_snapshot2) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); generate_result = jerry_generate_snapshot (parse_result, 0, snapshot_buffer_1, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - TEST_ASSERT (!jerry_value_is_error (generate_result) && jerry_value_is_number (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result)); - snapshot_sizes[1] = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + snapshot_sizes[1] = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); jerry_cleanup (); @@ -358,20 +357,20 @@ main (void) jerry_init (JERRY_INIT_EMPTY); jerry_value_t res = jerry_exec_snapshot (merged_snapshot_buffer, merged_size, 0, 0, NULL); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_get_number_value (res) == 123); - jerry_release_value (res); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_as_number (res) == 123); + jerry_value_free (res); res = jerry_exec_snapshot (merged_snapshot_buffer, merged_size, 1, 0, NULL); - TEST_ASSERT (!jerry_value_is_error (res)); - TEST_ASSERT (jerry_get_number_value (res) == 456); - jerry_release_value (res); + TEST_ASSERT (!jerry_value_is_exception (res)); + TEST_ASSERT (jerry_value_as_number (res) == 456); + jerry_value_free (res); jerry_cleanup (); } /* Save literals */ - if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE)) + if (jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE)) { /* C format generation */ jerry_init (JERRY_INIT_EMPTY); @@ -381,17 +380,17 @@ main (void) static const jerry_char_t code_for_c_format[] = "var object = { aa:'fo\" o\\n \\\\', Bb:'max', aaa:'xzy0' };"; jerry_value_t parse_result = jerry_parse (code_for_c_format, sizeof (code_for_c_format) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parse_result)); + TEST_ASSERT (!jerry_value_is_exception (parse_result)); jerry_value_t generate_result = jerry_generate_snapshot (parse_result, 0, literal_snapshot_buffer, SNAPSHOT_BUFFER_SIZE); - jerry_release_value (parse_result); + jerry_value_free (parse_result); - TEST_ASSERT (!jerry_value_is_error (generate_result)); + TEST_ASSERT (!jerry_value_is_exception (generate_result)); TEST_ASSERT (jerry_value_is_number (generate_result)); - size_t snapshot_size = (size_t) jerry_get_number_value (generate_result); - jerry_release_value (generate_result); + size_t snapshot_size = (size_t) jerry_value_as_number (generate_result); + jerry_value_free (generate_result); const size_t lit_c_buf_sz = jerry_get_literals_from_snapshot (literal_snapshot_buffer, snapshot_size, diff --git a/tests/unit-core/test-source-info.c b/tests/unit-core/test-source-info.c index 0401eccd5b..c5a5950f4f 100644 --- a/tests/unit-core/test-source-info.c +++ b/tests/unit-core/test-source-info.c @@ -25,9 +25,9 @@ compare_string (jerry_value_t left_string, /**< left string */ size_t size = strlen (right_string_p); uint8_t buffer[64]; - TEST_ASSERT (size == jerry_get_string_size (left_string)); + TEST_ASSERT (size == jerry_string_size (left_string, JERRY_ENCODING_CESU8)); TEST_ASSERT (size < sizeof (buffer)); - TEST_ASSERT (jerry_string_to_char_buffer (left_string, buffer, (jerry_size_t) size) == size); + TEST_ASSERT (jerry_string_to_buffer (left_string, buffer, (jerry_size_t) size, JERRY_ENCODING_CESU8) == size); TEST_ASSERT (memcmp (buffer, right_string_p, size) == 0); } /* compare_string */ @@ -38,73 +38,73 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_FUNCTION_TO_STRING)) + if (!jerry_feature_enabled (JERRY_FEATURE_FUNCTION_TO_STRING)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Source code is not stored!\n"); jerry_cleanup (); return 0; } - jerry_value_t value = jerry_create_null (); - jerry_source_info_t *source_info_p = jerry_get_source_info (value); + jerry_value_t value = jerry_null (); + jerry_source_info_t *source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p == NULL); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); - value = jerry_create_object (); - source_info_p = jerry_get_source_info (value); + value = jerry_object (); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p == NULL); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); jerry_parse_options_t parse_options; const char *source_p = TEST_STRING_LITERAL ("var a = 6"); value = jerry_parse ((jerry_char_t *) source_p, strlen (source_p), NULL); - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p != NULL); TEST_ASSERT (source_info_p->enabled_fields == JERRY_SOURCE_INFO_HAS_SOURCE_CODE); compare_string (source_info_p->source_code, source_p); TEST_ASSERT (jerry_value_is_undefined (source_info_p->function_arguments)); TEST_ASSERT (source_info_p->source_range_start == 0); TEST_ASSERT (source_info_p->source_range_length == 0); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); - if (jerry_is_feature_enabled (JERRY_FEATURE_MODULE)) + if (jerry_feature_enabled (JERRY_FEATURE_MODULE)) { parse_options.options = JERRY_PARSE_MODULE; value = jerry_parse ((jerry_char_t *) source_p, strlen (source_p), &parse_options); jerry_value_t result = jerry_module_link (value, NULL, NULL); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p != NULL); TEST_ASSERT (source_info_p->enabled_fields == JERRY_SOURCE_INFO_HAS_SOURCE_CODE); compare_string (source_info_p->source_code, source_p); TEST_ASSERT (jerry_value_is_undefined (source_info_p->function_arguments)); TEST_ASSERT (source_info_p->source_range_start == 0); TEST_ASSERT (source_info_p->source_range_length == 0); - jerry_free_source_info (source_info_p); + jerry_source_info_free (source_info_p); result = jerry_module_evaluate (value); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); /* Byte code is released after a successful evaluation. */ - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p == NULL); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); } source_p = TEST_STRING_LITERAL ("( function f() {} )"); value = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p != NULL); TEST_ASSERT (source_info_p->enabled_fields == (JERRY_SOURCE_INFO_HAS_SOURCE_CODE | JERRY_SOURCE_INFO_HAS_SOURCE_RANGE)); @@ -112,13 +112,13 @@ main (void) TEST_ASSERT (jerry_value_is_undefined (source_info_p->function_arguments)); TEST_ASSERT (source_info_p->source_range_start == 2); TEST_ASSERT (source_info_p->source_range_length == 15); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); source_p = TEST_STRING_LITERAL ("new Function('a', 'b', 'return 0;')"); value = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p != NULL); TEST_ASSERT (source_info_p->enabled_fields == (JERRY_SOURCE_INFO_HAS_SOURCE_CODE | JERRY_SOURCE_INFO_HAS_FUNCTION_ARGUMENTS)); @@ -126,13 +126,13 @@ main (void) compare_string (source_info_p->function_arguments, "a,b"); TEST_ASSERT (source_info_p->source_range_start == 0); TEST_ASSERT (source_info_p->source_range_length == 0); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); source_p = TEST_STRING_LITERAL ("(new Function('a = ( function() { } )', 'return a;'))()"); value = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p != NULL); TEST_ASSERT (source_info_p->enabled_fields == (JERRY_SOURCE_INFO_HAS_SOURCE_CODE | JERRY_SOURCE_INFO_HAS_SOURCE_RANGE)); @@ -140,13 +140,13 @@ main (void) TEST_ASSERT (jerry_value_is_undefined (source_info_p->function_arguments)); TEST_ASSERT (source_info_p->source_range_start == 6); TEST_ASSERT (source_info_p->source_range_length == 14); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); source_p = TEST_STRING_LITERAL ("(function f(a) { return 7 }).bind({})"); value = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - source_info_p = jerry_get_source_info (value); + source_info_p = jerry_source_info (value); TEST_ASSERT (source_info_p != NULL); TEST_ASSERT (source_info_p->enabled_fields == (JERRY_SOURCE_INFO_HAS_SOURCE_CODE | JERRY_SOURCE_INFO_HAS_SOURCE_RANGE)); @@ -154,8 +154,8 @@ main (void) TEST_ASSERT (jerry_value_is_undefined (source_info_p->function_arguments)); TEST_ASSERT (source_info_p->source_range_start == 1); TEST_ASSERT (source_info_p->source_range_length == 26); - jerry_free_source_info (source_info_p); - jerry_release_value (value); + jerry_source_info_free (source_info_p); + jerry_value_free (value); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-special-proxy.c b/tests/unit-core/test-special-proxy.c index 6ef7f29e8b..e7e6e2cd06 100644 --- a/tests/unit-core/test-special-proxy.c +++ b/tests/unit-core/test-special-proxy.c @@ -26,10 +26,10 @@ create_special_proxy_handler (const jerry_call_info_t *call_info_p, /**< call in if (args_count < 2) { - return jerry_create_undefined (); + return jerry_undefined (); } - return jerry_create_special_proxy (args_p[0], args_p[1], JERRY_PROXY_SKIP_RESULT_VALIDATION); + return jerry_proxy_custom (args_p[0], args_p[1], JERRY_PROXY_SKIP_RESULT_VALIDATION); } /* create_special_proxy_handler */ static void @@ -37,8 +37,8 @@ run_eval (const char *source_p) { jerry_value_t result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); } /* run_eval */ /** @@ -49,7 +49,7 @@ main (void) { TEST_INIT (); - if (!jerry_is_feature_enabled (JERRY_FEATURE_PROXY)) + if (!jerry_feature_enabled (JERRY_FEATURE_PROXY)) { printf ("Skipping test, Proxy not enabled\n"); return 0; @@ -57,18 +57,18 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t global = jerry_get_global_object (); + jerry_value_t global = jerry_current_realm (); - jerry_value_t function = jerry_create_external_function (create_special_proxy_handler); - jerry_value_t name = jerry_create_string ((const jerry_char_t *) "create_special_proxy"); - jerry_value_t result = jerry_set_property (global, name, function); - TEST_ASSERT (!jerry_value_is_error (result)); + jerry_value_t function = jerry_function_external (create_special_proxy_handler); + jerry_value_t name = jerry_string_sz ("create_special_proxy"); + jerry_value_t result = jerry_object_set (global, name, function); + TEST_ASSERT (!jerry_value_is_exception (result)); - jerry_release_value (result); - jerry_release_value (name); - jerry_release_value (function); + jerry_value_free (result); + jerry_value_free (name); + jerry_value_free (function); - jerry_release_value (global); + jerry_value_free (global); run_eval ("function assert (v) {\n" " if (v !== true)\n" diff --git a/tests/unit-core/test-symbol.c b/tests/unit-core/test-symbol.c index b6eae332d2..61a2660f38 100644 --- a/tests/unit-core/test-symbol.c +++ b/tests/unit-core/test-symbol.c @@ -20,10 +20,10 @@ #include "test-common.h" /* foo string */ -#define STRING_FOO ((const jerry_char_t *) "foo") +#define STRING_FOO ("foo") /* bar string */ -#define STRING_BAR ((const jerry_char_t *) "bar") +#define STRING_BAR ("bar") /* Symbol(bar) desciptive string */ #define SYMBOL_DESCIPTIVE_STRING_BAR "Symbol(bar)" @@ -34,7 +34,7 @@ int main (void) { - if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL)) + if (!jerry_feature_enabled (JERRY_FEATURE_SYMBOL)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Symbol support is disabled!\n"); return 0; @@ -42,59 +42,59 @@ main (void) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t object = jerry_create_object (); + jerry_value_t object = jerry_object (); /* Test for that each symbol is unique independently from their descriptor strings */ - jerry_value_t symbol_desc_1 = jerry_create_string (STRING_FOO); - jerry_value_t symbol_desc_2 = jerry_create_string (STRING_FOO); + jerry_value_t symbol_desc_1 = jerry_string_sz (STRING_FOO); + jerry_value_t symbol_desc_2 = jerry_string_sz (STRING_FOO); - jerry_value_t symbol_1 = jerry_create_symbol (symbol_desc_1); - TEST_ASSERT (!jerry_value_is_error (symbol_1)); + jerry_value_t symbol_1 = jerry_symbol_with_description (symbol_desc_1); + TEST_ASSERT (!jerry_value_is_exception (symbol_1)); TEST_ASSERT (jerry_value_is_symbol (symbol_1)); - jerry_value_t symbol_2 = jerry_create_symbol (symbol_desc_2); - TEST_ASSERT (!jerry_value_is_error (symbol_2)); + jerry_value_t symbol_2 = jerry_symbol_with_description (symbol_desc_2); + TEST_ASSERT (!jerry_value_is_exception (symbol_2)); TEST_ASSERT (jerry_value_is_symbol (symbol_2)); /* The descriptor strings are no longer needed */ - jerry_release_value (symbol_desc_1); - jerry_release_value (symbol_desc_2); + jerry_value_free (symbol_desc_1); + jerry_value_free (symbol_desc_2); - jerry_value_t value_1 = jerry_create_number (1); - jerry_value_t value_2 = jerry_create_number (2); + jerry_value_t value_1 = jerry_number (1); + jerry_value_t value_2 = jerry_number (2); - jerry_value_t result_val = jerry_set_property (object, symbol_1, value_1); + jerry_value_t result_val = jerry_object_set (object, symbol_1, value_1); TEST_ASSERT (jerry_value_is_boolean (result_val)); - TEST_ASSERT (jerry_value_is_true (jerry_has_property (object, symbol_1))); - TEST_ASSERT (jerry_value_is_true (jerry_has_own_property (object, symbol_1))); + TEST_ASSERT (jerry_value_is_true (jerry_object_has (object, symbol_1))); + TEST_ASSERT (jerry_value_is_true (jerry_object_has_own (object, symbol_1))); - result_val = jerry_set_property (object, symbol_2, value_2); + result_val = jerry_object_set (object, symbol_2, value_2); TEST_ASSERT (jerry_value_is_boolean (result_val)); - TEST_ASSERT (jerry_value_is_true (jerry_has_property (object, symbol_2))); - TEST_ASSERT (jerry_value_is_true (jerry_has_own_property (object, symbol_2))); + TEST_ASSERT (jerry_value_is_true (jerry_object_has (object, symbol_2))); + TEST_ASSERT (jerry_value_is_true (jerry_object_has_own (object, symbol_2))); - jerry_value_t get_value_1 = jerry_get_property (object, symbol_1); - TEST_ASSERT (jerry_get_number_value (get_value_1) == jerry_get_number_value (value_1)); - jerry_release_value (get_value_1); + jerry_value_t get_value_1 = jerry_object_get (object, symbol_1); + TEST_ASSERT (jerry_value_as_number (get_value_1) == jerry_value_as_number (value_1)); + jerry_value_free (get_value_1); - jerry_value_t get_value_2 = jerry_get_property (object, symbol_2); - TEST_ASSERT (jerry_get_number_value (get_value_2) == jerry_get_number_value (value_2)); - jerry_release_value (get_value_2); + jerry_value_t get_value_2 = jerry_object_get (object, symbol_2); + TEST_ASSERT (jerry_value_as_number (get_value_2) == jerry_value_as_number (value_2)); + jerry_value_free (get_value_2); /* Test delete / has_{own}_property */ - TEST_ASSERT (jerry_delete_property (object, symbol_1)); - TEST_ASSERT (!jerry_value_is_true (jerry_has_property (object, symbol_1))); - TEST_ASSERT (!jerry_value_is_true (jerry_has_own_property (object, symbol_1))); + TEST_ASSERT (jerry_object_delete (object, symbol_1)); + TEST_ASSERT (!jerry_value_is_true (jerry_object_has (object, symbol_1))); + TEST_ASSERT (!jerry_value_is_true (jerry_object_has_own (object, symbol_1))); - jerry_release_value (value_1); - jerry_release_value (symbol_1); + jerry_value_free (value_1); + jerry_value_free (symbol_1); /* Test {get, define}_own_property_descriptor */ jerry_property_descriptor_t prop_desc; - TEST_ASSERT (jerry_get_own_property_descriptor (object, symbol_2, &prop_desc)); + TEST_ASSERT (jerry_object_get_own_prop (object, symbol_2, &prop_desc)); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_VALUE_DEFINED); TEST_ASSERT (value_2 == prop_desc.value); - TEST_ASSERT (jerry_get_number_value (value_2) == jerry_get_number_value (prop_desc.value)); + TEST_ASSERT (jerry_value_as_number (value_2) == jerry_value_as_number (prop_desc.value)); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_WRITABLE); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_ENUMERABLE); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE); @@ -105,17 +105,17 @@ main (void) jerry_property_descriptor_free (&prop_desc); /* Modify the descriptor fields */ - prop_desc = jerry_property_descriptor_create (); - jerry_value_t value_3 = jerry_create_string (STRING_BAR); + prop_desc = jerry_property_descriptor (); + jerry_value_t value_3 = jerry_string_sz (STRING_BAR); prop_desc.flags |= JERRY_PROP_IS_VALUE_DEFINED | JERRY_PROP_IS_WRITABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE_DEFINED; - prop_desc.value = jerry_acquire_value (value_3); - TEST_ASSERT (jerry_value_is_true (jerry_define_own_property (object, symbol_2, &prop_desc))); + prop_desc.value = jerry_value_copy (value_3); + TEST_ASSERT (jerry_value_is_true (jerry_object_define_own_prop (object, symbol_2, &prop_desc))); jerry_property_descriptor_free (&prop_desc); /* Check the modified fields */ - TEST_ASSERT (jerry_get_own_property_descriptor (object, symbol_2, &prop_desc)); + TEST_ASSERT (jerry_object_get_own_prop (object, symbol_2, &prop_desc)); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_VALUE_DEFINED); TEST_ASSERT (value_3 == prop_desc.value); TEST_ASSERT (jerry_value_is_string (prop_desc.value)); @@ -131,88 +131,88 @@ main (void) TEST_ASSERT (jerry_value_is_undefined (prop_desc.setter)); jerry_property_descriptor_free (&prop_desc); - jerry_release_value (value_3); - jerry_release_value (value_2); - jerry_release_value (symbol_2); - jerry_release_value (object); + jerry_value_free (value_3); + jerry_value_free (value_2); + jerry_value_free (symbol_2); + jerry_value_free (object); /* Test creating symbol with a symbol description */ - jerry_value_t empty_symbol_desc = jerry_create_string ((const jerry_char_t *) ""); + jerry_value_t empty_symbol_desc = jerry_string_sz (""); - jerry_value_t empty_symbol = jerry_create_symbol (empty_symbol_desc); - TEST_ASSERT (!jerry_value_is_error (empty_symbol)); + jerry_value_t empty_symbol = jerry_symbol_with_description (empty_symbol_desc); + TEST_ASSERT (!jerry_value_is_exception (empty_symbol)); TEST_ASSERT (jerry_value_is_symbol (empty_symbol)); - jerry_release_value (empty_symbol_desc); + jerry_value_free (empty_symbol_desc); - jerry_value_t symbol_symbol = jerry_create_symbol (empty_symbol); + jerry_value_t symbol_symbol = jerry_symbol_with_description (empty_symbol); TEST_ASSERT (!jerry_value_is_symbol (symbol_symbol)); - TEST_ASSERT (jerry_value_is_error (symbol_symbol)); + TEST_ASSERT (jerry_value_is_exception (symbol_symbol)); - jerry_value_t error_obj = jerry_get_value_from_error (symbol_symbol, true); + jerry_value_t error_obj = jerry_exception_value (symbol_symbol, true); - TEST_ASSERT (jerry_get_error_type (error_obj) == JERRY_ERROR_TYPE); + TEST_ASSERT (jerry_error_type (error_obj) == JERRY_ERROR_TYPE); - jerry_release_value (error_obj); - jerry_release_value (empty_symbol); + jerry_value_free (error_obj); + jerry_value_free (empty_symbol); /* Test symbol to string operation with symbol argument */ - jerry_value_t bar_symbol_desc = jerry_create_string (STRING_BAR); + jerry_value_t bar_symbol_desc = jerry_string_sz (STRING_BAR); - jerry_value_t bar_symbol = jerry_create_symbol (bar_symbol_desc); - TEST_ASSERT (!jerry_value_is_error (bar_symbol)); + jerry_value_t bar_symbol = jerry_symbol_with_description (bar_symbol_desc); + TEST_ASSERT (!jerry_value_is_exception (bar_symbol)); TEST_ASSERT (jerry_value_is_symbol (bar_symbol)); - jerry_release_value (bar_symbol_desc); + jerry_value_free (bar_symbol_desc); - jerry_value_t bar_symbol_string = jerry_get_symbol_descriptive_string (bar_symbol); + jerry_value_t bar_symbol_string = jerry_symbol_descriptive_string (bar_symbol); TEST_ASSERT (jerry_value_is_string (bar_symbol_string)); - jerry_size_t bar_symbol_string_size = jerry_get_string_size (bar_symbol_string); + jerry_size_t bar_symbol_string_size = jerry_string_size (bar_symbol_string, JERRY_ENCODING_CESU8); TEST_ASSERT (bar_symbol_string_size == (sizeof (SYMBOL_DESCIPTIVE_STRING_BAR) - 1)); JERRY_VLA (jerry_char_t, str_buff, bar_symbol_string_size); - jerry_string_to_char_buffer (bar_symbol_string, str_buff, bar_symbol_string_size); + jerry_string_to_buffer (bar_symbol_string, str_buff, bar_symbol_string_size, JERRY_ENCODING_CESU8); TEST_ASSERT (memcmp (str_buff, SYMBOL_DESCIPTIVE_STRING_BAR, sizeof (SYMBOL_DESCIPTIVE_STRING_BAR) - 1) == 0); - jerry_release_value (bar_symbol_string); + jerry_value_free (bar_symbol_string); /* Test symbol get description operation with string description */ - bar_symbol_string = jerry_get_symbol_description (bar_symbol); + bar_symbol_string = jerry_symbol_description (bar_symbol); TEST_ASSERT (jerry_value_is_string (bar_symbol_string)); - bar_symbol_string_size = jerry_get_string_size (bar_symbol_string); + bar_symbol_string_size = jerry_string_size (bar_symbol_string, JERRY_ENCODING_CESU8); TEST_ASSERT (bar_symbol_string_size == (sizeof (SYMBOL_DESCIPTION_BAR) - 1)); - jerry_string_to_char_buffer (bar_symbol_string, str_buff, bar_symbol_string_size); + jerry_string_to_buffer (bar_symbol_string, str_buff, bar_symbol_string_size, JERRY_ENCODING_CESU8); TEST_ASSERT (memcmp (str_buff, STRING_BAR, sizeof (SYMBOL_DESCIPTION_BAR) - 1) == 0); - jerry_release_value (bar_symbol_string); - jerry_release_value (bar_symbol); + jerry_value_free (bar_symbol_string); + jerry_value_free (bar_symbol); /* Test symbol get description operation with undefined description */ - jerry_value_t undefined_value = jerry_create_undefined (); - jerry_value_t undefined_symbol = jerry_create_symbol (undefined_value); - jerry_release_value (undefined_value); - TEST_ASSERT (!jerry_value_is_error (bar_symbol)); + jerry_value_t undefined_value = jerry_undefined (); + jerry_value_t undefined_symbol = jerry_symbol_with_description (undefined_value); + jerry_value_free (undefined_value); + TEST_ASSERT (!jerry_value_is_exception (bar_symbol)); TEST_ASSERT (jerry_value_is_symbol (bar_symbol)); - undefined_value = jerry_get_symbol_description (undefined_symbol); + undefined_value = jerry_symbol_description (undefined_symbol); TEST_ASSERT (jerry_value_is_undefined (undefined_value)); - jerry_release_value (undefined_value); - jerry_release_value (undefined_symbol); + jerry_value_free (undefined_value); + jerry_value_free (undefined_symbol); /* Test symbol to string operation with non-symbol argument */ - jerry_value_t null_value = jerry_create_null (); - jerry_value_t to_string_value = jerry_get_symbol_descriptive_string (null_value); - TEST_ASSERT (jerry_value_is_error (to_string_value)); + jerry_value_t null_value = jerry_null (); + jerry_value_t to_string_value = jerry_symbol_descriptive_string (null_value); + TEST_ASSERT (jerry_value_is_exception (to_string_value)); - error_obj = jerry_get_value_from_error (to_string_value, true); + error_obj = jerry_exception_value (to_string_value, true); - TEST_ASSERT (jerry_get_error_type (error_obj) == JERRY_ERROR_TYPE); + TEST_ASSERT (jerry_error_type (error_obj) == JERRY_ERROR_TYPE); - jerry_release_value (error_obj); - jerry_release_value (null_value); + jerry_value_free (error_obj); + jerry_value_free (null_value); const jerry_char_t obj_src[] = "" "({" @@ -239,9 +239,9 @@ main (void) jerry_value_t obj = jerry_eval (obj_src, sizeof (obj_src) - 1, JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_object (obj)); - jerry_value_t global_obj = jerry_get_global_object (); - jerry_value_t symbol_str = jerry_create_string ((const jerry_char_t *) "Symbol"); - jerry_value_t builtin_symbol = jerry_get_property (global_obj, symbol_str); + jerry_value_t global_obj = jerry_current_realm (); + jerry_value_t symbol_str = jerry_string_sz ("Symbol"); + jerry_value_t builtin_symbol = jerry_object_get (global_obj, symbol_str); TEST_ASSERT (jerry_value_is_object (builtin_symbol)); double expected = 1.0; @@ -250,49 +250,48 @@ main (void) for (jerry_well_known_symbol_t id = JERRY_SYMBOL_ASYNC_ITERATOR; id <= JERRY_SYMBOL_MATCH_ALL; id++, expected++, prop_index++) { - jerry_value_t well_known_symbol = jerry_get_well_known_symbol (id); + jerry_value_t well_known_symbol = jerry_symbol (id); - jerry_value_t prop_str = jerry_create_string ((const jerry_char_t *) symbols[prop_index]); - jerry_value_t current_global_symbol = jerry_get_property (builtin_symbol, prop_str); - jerry_release_value (prop_str); + jerry_value_t prop_str = jerry_string_sz (symbols[prop_index]); + jerry_value_t current_global_symbol = jerry_object_get (builtin_symbol, prop_str); + jerry_value_free (prop_str); - jerry_value_t relation = - jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, well_known_symbol, current_global_symbol); + jerry_value_t relation = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, well_known_symbol, current_global_symbol); TEST_ASSERT (jerry_value_is_boolean (relation) && jerry_value_is_true (relation)); - jerry_release_value (relation); + jerry_value_free (relation); - jerry_value_t prop_result_wn = jerry_get_property (obj, well_known_symbol); - jerry_value_t prop_result_global = jerry_get_property (obj, current_global_symbol); + jerry_value_t prop_result_wn = jerry_object_get (obj, well_known_symbol); + jerry_value_t prop_result_global = jerry_object_get (obj, current_global_symbol); TEST_ASSERT (jerry_value_is_number (prop_result_wn)); - double number_wn = jerry_get_number_value (prop_result_wn); + double number_wn = jerry_value_as_number (prop_result_wn); TEST_ASSERT (number_wn == expected); TEST_ASSERT (jerry_value_is_number (prop_result_global)); - double number_global = jerry_get_number_value (prop_result_global); + double number_global = jerry_value_as_number (prop_result_global); TEST_ASSERT (number_global == expected); - jerry_release_value (prop_result_global); - jerry_release_value (prop_result_wn); - jerry_release_value (current_global_symbol); - jerry_release_value (well_known_symbol); + jerry_value_free (prop_result_global); + jerry_value_free (prop_result_wn); + jerry_value_free (current_global_symbol); + jerry_value_free (well_known_symbol); } - jerry_release_value (builtin_symbol); + jerry_value_free (builtin_symbol); /* Deletion of the 'Symbol' builtin makes the well-known symbols unaccessible from JS context - but the symbols still can be obtained via 'jerry_get_well_known_symbol' */ + but the symbols still can be obtained via 'jerry_symbol' */ const jerry_char_t deleter_src[] = "delete Symbol"; jerry_value_t deleter = jerry_eval (deleter_src, sizeof (deleter_src) - 1, JERRY_PARSE_NO_OPTS); TEST_ASSERT (jerry_value_is_boolean (deleter) && jerry_value_is_true (deleter)); - jerry_release_value (deleter); + jerry_value_free (deleter); - builtin_symbol = jerry_get_property (global_obj, symbol_str); + builtin_symbol = jerry_object_get (global_obj, symbol_str); TEST_ASSERT (jerry_value_is_undefined (builtin_symbol)); - jerry_release_value (builtin_symbol); + jerry_value_free (builtin_symbol); expected = 1.0; prop_index = 0; @@ -300,30 +299,30 @@ main (void) for (jerry_well_known_symbol_t id = JERRY_SYMBOL_ASYNC_ITERATOR; id <= JERRY_SYMBOL_MATCH_ALL; id++, expected++, prop_index++) { - jerry_value_t well_known_symbol = jerry_get_well_known_symbol (id); - jerry_value_t prop_result_wn = jerry_get_property (obj, well_known_symbol); + jerry_value_t well_known_symbol = jerry_symbol (id); + jerry_value_t prop_result_wn = jerry_object_get (obj, well_known_symbol); TEST_ASSERT (jerry_value_is_number (prop_result_wn)); - double number_wn = jerry_get_number_value (prop_result_wn); + double number_wn = jerry_value_as_number (prop_result_wn); TEST_ASSERT (number_wn == expected); - jerry_release_value (prop_result_wn); - jerry_release_value (well_known_symbol); + jerry_value_free (prop_result_wn); + jerry_value_free (well_known_symbol); } jerry_well_known_symbol_t invalid_symbol = (jerry_well_known_symbol_t) (JERRY_SYMBOL_MATCH_ALL + 1); - jerry_value_t invalid_well_known_symbol = jerry_get_well_known_symbol (invalid_symbol); + jerry_value_t invalid_well_known_symbol = jerry_symbol (invalid_symbol); TEST_ASSERT (jerry_value_is_undefined (invalid_well_known_symbol)); - jerry_release_value (invalid_well_known_symbol); + jerry_value_free (invalid_well_known_symbol); invalid_symbol = (jerry_well_known_symbol_t) (JERRY_SYMBOL_ASYNC_ITERATOR - 1); - invalid_well_known_symbol = jerry_get_well_known_symbol (invalid_symbol); + invalid_well_known_symbol = jerry_symbol (invalid_symbol); TEST_ASSERT (jerry_value_is_undefined (invalid_well_known_symbol)); - jerry_release_value (invalid_well_known_symbol); + jerry_value_free (invalid_well_known_symbol); - jerry_release_value (symbol_str); - jerry_release_value (global_obj); - jerry_release_value (obj); + jerry_value_free (symbol_str); + jerry_value_free (global_obj); + jerry_value_free (obj); jerry_cleanup (); diff --git a/tests/unit-core/test-to-property-descriptor.c b/tests/unit-core/test-to-property-descriptor.c index e7c4048161..53821c27c1 100644 --- a/tests/unit-core/test-to-property-descriptor.c +++ b/tests/unit-core/test-to-property-descriptor.c @@ -31,8 +31,8 @@ check_attribute (jerry_value_t attribute, /**< attribute to be checked */ jerry_value_t object, /**< original object */ const char *name_p) /**< name of the attribute */ { - jerry_value_t prop_name = jerry_create_string_from_utf8 ((const jerry_char_t *) name_p); - jerry_value_t value = jerry_get_property (object, prop_name); + jerry_value_t prop_name = jerry_string_sz (name_p); + jerry_value_t value = jerry_object_get (object, prop_name); if (jerry_value_is_undefined (value)) { @@ -40,23 +40,23 @@ check_attribute (jerry_value_t attribute, /**< attribute to be checked */ } else { - jerry_value_t result = jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, attribute, value); + jerry_value_t result = jerry_binary_op (JERRY_BIN_OP_STRICT_EQUAL, attribute, value); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); } - jerry_release_value (value); - jerry_release_value (prop_name); + jerry_value_free (value); + jerry_value_free (prop_name); } /* check_attribute */ static jerry_property_descriptor_t to_property_descriptor (jerry_value_t object /**< object */) { - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); - jerry_value_t result = jerry_to_property_descriptor (object, &prop_desc); + jerry_value_t result = jerry_property_descriptor_from_object (object, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); return prop_desc; } /* to_property_descriptor */ @@ -86,7 +86,7 @@ main (void) TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE); - jerry_release_value (object); + jerry_value_free (object); jerry_property_descriptor_free (&prop_desc); /* Next test. */ @@ -104,7 +104,7 @@ main (void) TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE); - jerry_release_value (object); + jerry_value_free (object); jerry_property_descriptor_free (&prop_desc); /* Next test. */ @@ -126,7 +126,7 @@ main (void) TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED); TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE); - jerry_release_value (object); + jerry_value_free (object); jerry_property_descriptor_free (&prop_desc); /* Next test. */ @@ -145,7 +145,7 @@ main (void) TEST_ASSERT (!(prop_desc.flags & JERRY_PROP_IS_ENUMERABLE)); TEST_ASSERT (!(prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED)); - jerry_release_value (object); + jerry_value_free (object); jerry_property_descriptor_free (&prop_desc); /* Next test. */ @@ -165,23 +165,23 @@ main (void) TEST_ASSERT (prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE_DEFINED); TEST_ASSERT (!(prop_desc.flags & JERRY_PROP_IS_CONFIGURABLE)); - jerry_release_value (object); + jerry_value_free (object); jerry_property_descriptor_free (&prop_desc); /* Next test. */ source_p = "({ get: function(v) {}, writable:true })"; object = create_property_descriptor (source_p); - jerry_value_t result = jerry_to_property_descriptor (object, &prop_desc); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); - jerry_release_value (object); + jerry_value_t result = jerry_property_descriptor_from_object (object, &prop_desc); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); + jerry_value_free (object); /* Next test. */ - object = jerry_create_null (); - result = jerry_to_property_descriptor (object, &prop_desc); - TEST_ASSERT (jerry_value_is_error (result)); - jerry_release_value (result); - jerry_release_value (object); + object = jerry_null (); + result = jerry_property_descriptor_from_object (object, &prop_desc); + TEST_ASSERT (jerry_value_is_exception (result)); + jerry_value_free (result); + jerry_value_free (object); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-typedarray.c b/tests/unit-core/test-typedarray.c index 4f19856f34..df81852347 100644 --- a/tests/unit-core/test-typedarray.c +++ b/tests/unit-core/test-typedarray.c @@ -39,15 +39,15 @@ static void register_js_value (const char *name_p, /**< name of the function */ jerry_value_t value) /**< function callback */ { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_set_property (global_obj_val, name_val, value); + jerry_value_t name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_set (global_obj_val, name_val, value); - jerry_release_value (name_val); - jerry_release_value (global_obj_val); + jerry_value_free (name_val); + jerry_value_free (global_obj_val); - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_value */ static jerry_value_t @@ -59,20 +59,18 @@ assert_handler (const jerry_call_info_t *call_info_p, /**< call information */ if (jerry_value_is_true (args_p[0])) { - return jerry_create_boolean (true); + return jerry_boolean (true); } else { if (args_cnt > 1 && jerry_value_is_string (args_p[1])) { - jerry_length_t utf8_sz = jerry_get_string_size (args_p[1]); - TEST_ASSERT (utf8_sz <= 127); /* 127 is the expected max assert fail message size. */ - JERRY_VLA (char, string_from_utf8, utf8_sz + 1); - string_from_utf8[utf8_sz] = 0; + jerry_char_t utf8_string[128]; + jerry_size_t copied = + jerry_string_to_buffer (args_p[1], utf8_string, sizeof (utf8_string) - 1, JERRY_ENCODING_UTF8); + utf8_string[copied] = '\0'; - jerry_string_to_char_buffer (args_p[1], (jerry_char_t *) string_from_utf8, utf8_sz); - - printf ("JS assert: %s\n", string_from_utf8); + printf ("JS assert: %s\n", utf8_string); } TEST_ASSERT (false); } @@ -87,20 +85,20 @@ test_typedarray_info (jerry_value_t typedarray, /**< target TypedArray to query jerry_length_t element_count, /**< expected element count */ jerry_length_t bytes_per_element) /**< bytes per element for the given type */ { - TEST_ASSERT (!jerry_value_is_error (typedarray)); + TEST_ASSERT (!jerry_value_is_exception (typedarray)); TEST_ASSERT (jerry_value_is_typedarray (typedarray)); - TEST_ASSERT (jerry_get_typedarray_type (typedarray) == typedarray_type); - TEST_ASSERT (jerry_get_typedarray_length (typedarray) == element_count); + TEST_ASSERT (jerry_typedarray_type (typedarray) == typedarray_type); + TEST_ASSERT (jerry_typedarray_length (typedarray) == element_count); jerry_length_t byte_length = (uint32_t) -1; jerry_length_t byte_offset = (uint32_t) -1; - jerry_value_t arraybuffer = jerry_get_typedarray_buffer (typedarray, &byte_offset, &byte_length); + jerry_value_t arraybuffer = jerry_typedarray_buffer (typedarray, &byte_offset, &byte_length); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); TEST_ASSERT (byte_length == element_count * bytes_per_element); TEST_ASSERT (byte_offset == 0); - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } /* test_typedarray_info */ /** @@ -109,43 +107,42 @@ test_typedarray_info (jerry_value_t typedarray, /**< target TypedArray to query static void test_typedarray_queries (test_entry_t test_entries[]) /**< test cases */ { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); for (uint32_t i = 0; test_entries[i].constructor_name != NULL; i++) { /* Create TypedArray via construct call */ { - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) test_entries[i].constructor_name); - jerry_value_t prop_value = jerry_get_property (global_obj_val, prop_name); - TEST_ASSERT (!jerry_value_is_error (prop_value)); - jerry_value_t length_arg = jerry_create_number (test_entries[i].element_count); + jerry_value_t prop_name = jerry_string_sz (test_entries[i].constructor_name); + jerry_value_t prop_value = jerry_object_get (global_obj_val, prop_name); + TEST_ASSERT (!jerry_value_is_exception (prop_value)); + jerry_value_t length_arg = jerry_number (test_entries[i].element_count); - jerry_value_t typedarray = jerry_construct_object (prop_value, &length_arg, 1); + jerry_value_t typedarray = jerry_construct (prop_value, &length_arg, 1); - jerry_release_value (prop_name); - jerry_release_value (prop_value); - jerry_release_value (length_arg); + jerry_value_free (prop_name); + jerry_value_free (prop_value); + jerry_value_free (length_arg); test_typedarray_info (typedarray, test_entries[i].typedarray_type, test_entries[i].element_count, test_entries[i].bytes_per_element); - jerry_release_value (typedarray); + jerry_value_free (typedarray); } /* Create TypedArray via api call */ { - jerry_value_t typedarray = - jerry_create_typedarray (test_entries[i].typedarray_type, test_entries[i].element_count); + jerry_value_t typedarray = jerry_typedarray (test_entries[i].typedarray_type, test_entries[i].element_count); test_typedarray_info (typedarray, test_entries[i].typedarray_type, test_entries[i].element_count, test_entries[i].bytes_per_element); - jerry_release_value (typedarray); + jerry_value_free (typedarray); } } - jerry_release_value (global_obj_val); + jerry_value_free (global_obj_val); } /* test_typedarray_queries */ /** @@ -242,28 +239,26 @@ test_typedarray_complex_creation (test_entry_t test_entries[], /**< test cases * if (use_external_buffer) { buffer_p = (uint8_t *) jerry_heap_alloc (arraybuffer_size); - arraybuffer = jerry_create_arraybuffer_external (arraybuffer_size, buffer_p, NULL); + arraybuffer = jerry_arraybuffer_external (buffer_p, arraybuffer_size, NULL); } else { - arraybuffer = jerry_create_arraybuffer (arraybuffer_size); + arraybuffer = jerry_arraybuffer (arraybuffer_size); } - jerry_value_t js_offset = jerry_create_number (offset); - jerry_value_t js_element_count = jerry_create_number (element_count); + jerry_value_t js_offset = jerry_number (offset); + jerry_value_t js_element_count = jerry_number (element_count); register_js_value ("expected_offset", js_offset); register_js_value ("expected_length", js_element_count); - typedarray = jerry_create_typedarray_for_arraybuffer_sz (test_entries[i].typedarray_type, - arraybuffer, - offset, - element_count); - TEST_ASSERT (!jerry_value_is_error (typedarray)); + typedarray = + jerry_typedarray_with_buffer_span (test_entries[i].typedarray_type, arraybuffer, offset, element_count); + TEST_ASSERT (!jerry_value_is_exception (typedarray)); - jerry_release_value (js_offset); - jerry_release_value (js_element_count); - jerry_release_value (arraybuffer); + jerry_value_free (js_offset); + jerry_value_free (js_element_count); + jerry_value_free (arraybuffer); } register_js_value ("array", typedarray); @@ -273,8 +268,8 @@ test_typedarray_complex_creation (test_entry_t test_entries[], /**< test cases * " 'expected length: ' + expected_length + ' got: ' + array.length);" "assert (array.byteOffset == expected_offset);"); jerry_value_t result = jerry_eval (test_exptected_src, sizeof (test_exptected_src) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); const jerry_char_t set_element_src[] = TEST_STRING_LITERAL ("array[0] = 0x11223344n"); @@ -288,19 +283,19 @@ test_typedarray_complex_creation (test_entry_t test_entries[], /**< test cases * } result = jerry_eval (set_element_src, src_length, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); { jerry_length_t byte_length = 0; jerry_length_t byte_offset = 0; - jerry_value_t buffer = jerry_get_typedarray_buffer (typedarray, &byte_offset, &byte_length); + jerry_value_t buffer = jerry_typedarray_buffer (typedarray, &byte_offset, &byte_length); TEST_ASSERT (byte_length == element_count * bytes_per_element); TEST_ASSERT (byte_offset == offset); JERRY_VLA (uint8_t, test_buffer, arraybuffer_size); - jerry_typedarray_type_t type = jerry_get_typedarray_type (typedarray); + jerry_typedarray_type_t type = jerry_typedarray_type (typedarray); jerry_value_t read_count = jerry_arraybuffer_read (buffer, 0, test_buffer, offset + byte_length); TEST_ASSERT (read_count == offset + byte_length); test_buffer_value (0x11223344, test_buffer, offset, type, bytes_per_element); @@ -311,10 +306,10 @@ test_typedarray_complex_creation (test_entry_t test_entries[], /**< test cases * TEST_ASSERT (memcmp (buffer_p, test_buffer, offset + byte_length) == 0); } - jerry_release_value (buffer); + jerry_value_free (buffer); } - jerry_release_value (typedarray); + jerry_value_free (typedarray); } } /* test_typedarray_complex_creation */ @@ -334,8 +329,8 @@ test_property_by_index (test_entry_t test_entries[]) { jerry_value_t test_number; uint32_t test_numbers_length = sizeof (test_int_numbers) / sizeof (int); - jerry_value_t typedarray = jerry_create_typedarray (test_entries[i].typedarray_type, test_numbers_length); - jerry_typedarray_type_t type = jerry_get_typedarray_type (typedarray); + jerry_value_t typedarray = jerry_typedarray (test_entries[i].typedarray_type, test_numbers_length); + jerry_typedarray_type_t type = jerry_typedarray_type (typedarray); jerry_value_t set_result; jerry_value_t get_result; @@ -348,19 +343,19 @@ test_property_by_index (test_entry_t test_entries[]) { for (uint8_t j = 0; j < test_numbers_length; j++) { - test_number = jerry_create_number (test_int_numbers[j]); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - set_result = jerry_set_property_by_index (typedarray, j, test_number); - get_result = jerry_get_property_by_index (typedarray, j); + test_number = jerry_number (test_int_numbers[j]); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + set_result = jerry_object_set_index (typedarray, j, test_number); + get_result = jerry_object_get_index (typedarray, j); TEST_ASSERT (jerry_value_is_boolean (set_result)); TEST_ASSERT (jerry_value_is_true (set_result)); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - TEST_ASSERT (jerry_get_number_value (get_result) == test_int_numbers[j]); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + TEST_ASSERT (jerry_value_as_number (get_result) == test_int_numbers[j]); - jerry_release_value (test_number); - jerry_release_value (set_result); - jerry_release_value (get_result); + jerry_value_free (test_number); + jerry_value_free (set_result); + jerry_value_free (get_result); } break; } @@ -369,36 +364,36 @@ test_property_by_index (test_entry_t test_entries[]) { for (uint8_t j = 0; j < test_numbers_length; j++) { - test_number = jerry_create_number (test_double_numbers[j]); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - set_result = jerry_set_property_by_index (typedarray, j, test_number); - get_result = jerry_get_property_by_index (typedarray, j); + test_number = jerry_number (test_double_numbers[j]); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + set_result = jerry_object_set_index (typedarray, j, test_number); + get_result = jerry_object_get_index (typedarray, j); TEST_ASSERT (jerry_value_is_boolean (set_result)); TEST_ASSERT (jerry_value_is_true (set_result)); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); double epsilon = pow (10, -5); - double get_abs = fabs (jerry_get_number_value (get_result) - test_double_numbers[j]); + double get_abs = fabs (jerry_value_as_number (get_result) - test_double_numbers[j]); TEST_ASSERT (get_abs < epsilon); - jerry_release_value (test_number); - jerry_release_value (set_result); - jerry_release_value (get_result); + jerry_value_free (test_number); + jerry_value_free (set_result); + jerry_value_free (get_result); /* Testing positive and negative infinity */ for (uint8_t k = 0; k < 2; k++) { - jerry_value_t inf = jerry_create_number_infinity (k); - jerry_value_t set_inf = jerry_set_property_by_index (typedarray, 0, inf); + jerry_value_t inf = jerry_infinity (k); + jerry_value_t set_inf = jerry_object_set_index (typedarray, 0, inf); TEST_ASSERT (jerry_value_is_boolean (set_inf)); TEST_ASSERT (jerry_value_is_true (set_inf)); - jerry_value_t get_inf = jerry_get_property_by_index (typedarray, 0); - TEST_ASSERT (isinf (jerry_get_number_value (get_inf))); + jerry_value_t get_inf = jerry_object_get_index (typedarray, 0); + TEST_ASSERT (isinf (jerry_value_as_number (get_inf))); - jerry_release_value (inf); - jerry_release_value (set_inf); - jerry_release_value (get_inf); + jerry_value_free (inf); + jerry_value_free (set_inf); + jerry_value_free (get_inf); } } break; @@ -407,23 +402,23 @@ test_property_by_index (test_entry_t test_entries[]) { for (uint8_t j = 0; j < test_numbers_length; j++) { - test_number = jerry_create_bigint ((uint64_t *) &test_int64_numbers[j], 1, true); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - set_result = jerry_set_property_by_index (typedarray, j, test_number); - get_result = jerry_get_property_by_index (typedarray, j); + test_number = jerry_bigint ((uint64_t *) &test_int64_numbers[j], 1, true); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + set_result = jerry_object_set_index (typedarray, j, test_number); + get_result = jerry_object_get_index (typedarray, j); TEST_ASSERT (jerry_value_is_boolean (set_result)); TEST_ASSERT (jerry_value_is_true (set_result)); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); int64_t get_number; bool sign; - jerry_get_bigint_digits (get_result, (uint64_t *) &get_number, 1, &sign); + jerry_bigint_to_digits (get_result, (uint64_t *) &get_number, 1, &sign); TEST_ASSERT (sign ? get_number : -get_number == test_int64_numbers[j]); - jerry_release_value (test_number); - jerry_release_value (set_result); - jerry_release_value (get_result); + jerry_value_free (test_number); + jerry_value_free (set_result); + jerry_value_free (get_result); } break; } @@ -431,23 +426,23 @@ test_property_by_index (test_entry_t test_entries[]) { for (uint8_t j = 0; j < test_numbers_length; j++) { - test_number = jerry_create_bigint (&test_uint64_numbers[j], 1, false); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - set_result = jerry_set_property_by_index (typedarray, j, test_number); - get_result = jerry_get_property_by_index (typedarray, j); + test_number = jerry_bigint (&test_uint64_numbers[j], 1, false); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + set_result = jerry_object_set_index (typedarray, j, test_number); + get_result = jerry_object_get_index (typedarray, j); TEST_ASSERT (jerry_value_is_boolean (set_result)); TEST_ASSERT (jerry_value_is_true (set_result)); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); uint64_t get_number; bool sign; - jerry_get_bigint_digits (get_result, &get_number, 1, &sign); + jerry_bigint_to_digits (get_result, &get_number, 1, &sign); TEST_ASSERT (get_number == test_uint64_numbers[j]); - jerry_release_value (test_number); - jerry_release_value (set_result); - jerry_release_value (get_result); + jerry_value_free (test_number); + jerry_value_free (set_result); + jerry_value_free (get_result); } break; } @@ -455,40 +450,40 @@ test_property_by_index (test_entry_t test_entries[]) { for (uint8_t j = 0; j < test_numbers_length; j++) { - test_number = jerry_create_number (test_uint_numbers[j]); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - set_result = jerry_set_property_by_index (typedarray, j, test_number); - get_result = jerry_get_property_by_index (typedarray, j); + test_number = jerry_number (test_uint_numbers[j]); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + set_result = jerry_object_set_index (typedarray, j, test_number); + get_result = jerry_object_get_index (typedarray, j); TEST_ASSERT (jerry_value_is_boolean (set_result)); TEST_ASSERT (jerry_value_is_true (set_result)); - TEST_ASSERT (!jerry_delete_property_by_index (typedarray, j)); - TEST_ASSERT (jerry_get_number_value (get_result) == test_uint_numbers[j]); + TEST_ASSERT (!jerry_object_delete_index (typedarray, j)); + TEST_ASSERT (jerry_value_as_number (get_result) == test_uint_numbers[j]); - jerry_release_value (test_number); - jerry_release_value (set_result); - jerry_release_value (get_result); + jerry_value_free (test_number); + jerry_value_free (set_result); + jerry_value_free (get_result); } break; } } - jerry_value_t set_undefined = jerry_set_property_by_index (typedarray, 100, jerry_create_number (50)); + jerry_value_t set_undefined = jerry_object_set_index (typedarray, 100, jerry_number (50)); if (type == JERRY_TYPEDARRAY_BIGINT64 || type == JERRY_TYPEDARRAY_BIGUINT64) { - TEST_ASSERT (jerry_value_is_error (set_undefined)); + TEST_ASSERT (jerry_value_is_exception (set_undefined)); } else { TEST_ASSERT (jerry_value_is_boolean (set_undefined) && !jerry_value_is_true (set_undefined)); } - jerry_value_t get_undefined = jerry_get_property_by_index (typedarray, 100); + jerry_value_t get_undefined = jerry_object_get_index (typedarray, 100); if (type == JERRY_TYPEDARRAY_BIGINT64 || type == JERRY_TYPEDARRAY_BIGUINT64) { - TEST_ASSERT (jerry_value_is_error (set_undefined)); + TEST_ASSERT (jerry_value_is_exception (set_undefined)); } else { @@ -496,9 +491,9 @@ test_property_by_index (test_entry_t test_entries[]) } TEST_ASSERT (jerry_value_is_undefined (get_undefined)); - jerry_release_value (set_undefined); - jerry_release_value (get_undefined); - jerry_release_value (typedarray); + jerry_value_free (set_undefined); + jerry_value_free (get_undefined); + jerry_value_free (typedarray); } } /* test_property_by_index */ @@ -515,58 +510,58 @@ test_detached_arraybuffer (void) { const uint32_t length = 1; uint8_t *buffer_p = (uint8_t *) jerry_heap_alloc (length); - jerry_value_t arraybuffer = jerry_create_arraybuffer_external (length, buffer_p, NULL); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer_external (buffer_p, length, NULL); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); - jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (is_detachable)); + jerry_value_t is_detachable = jerry_arraybuffer_is_detachable (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (is_detachable)); TEST_ASSERT (jerry_value_is_true (is_detachable)); - jerry_release_value (is_detachable); + jerry_value_free (is_detachable); - jerry_value_t res = jerry_detach_arraybuffer (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (res); + jerry_value_t res = jerry_arraybuffer_detach (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (res); for (size_t idx = 0; idx < (sizeof (types) / sizeof (types[0])); idx++) { - jerry_value_t typedarray = jerry_create_typedarray_for_arraybuffer_sz (types[idx], arraybuffer, 0, 4); - TEST_ASSERT (jerry_value_is_error (typedarray)); - TEST_ASSERT (jerry_get_error_type (typedarray) == JERRY_ERROR_TYPE); - jerry_release_value (typedarray); + jerry_value_t typedarray = jerry_typedarray_with_buffer_span (types[idx], arraybuffer, 0, 4); + TEST_ASSERT (jerry_value_is_exception (typedarray)); + TEST_ASSERT (jerry_error_type (typedarray) == JERRY_ERROR_TYPE); + jerry_value_free (typedarray); } - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } /* Creating an TypedArray for a detached array buffer without length/offset is valid */ { const uint32_t length = 1; uint8_t *buffer_p = (uint8_t *) jerry_heap_alloc (length); - jerry_value_t arraybuffer = jerry_create_arraybuffer_external (length, buffer_p, NULL); - TEST_ASSERT (!jerry_value_is_error (arraybuffer)); + jerry_value_t arraybuffer = jerry_arraybuffer_external (buffer_p, length, NULL); + TEST_ASSERT (!jerry_value_is_exception (arraybuffer)); TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer)); - TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length); + TEST_ASSERT (jerry_arraybuffer_size (arraybuffer) == length); - jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (is_detachable)); + jerry_value_t is_detachable = jerry_arraybuffer_is_detachable (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (is_detachable)); TEST_ASSERT (jerry_value_is_true (is_detachable)); - jerry_release_value (is_detachable); + jerry_value_free (is_detachable); - jerry_value_t res = jerry_detach_arraybuffer (arraybuffer); - TEST_ASSERT (!jerry_value_is_error (res)); - jerry_release_value (res); + jerry_value_t res = jerry_arraybuffer_detach (arraybuffer); + TEST_ASSERT (!jerry_value_is_exception (res)); + jerry_value_free (res); for (size_t idx = 0; idx < (sizeof (types) / sizeof (types[0])); idx++) { - jerry_value_t typedarray = jerry_create_typedarray_for_arraybuffer (types[idx], arraybuffer); - TEST_ASSERT (jerry_value_is_error (typedarray)); - TEST_ASSERT (jerry_get_error_type (typedarray) == JERRY_ERROR_TYPE); - jerry_release_value (typedarray); + jerry_value_t typedarray = jerry_typedarray_with_buffer (types[idx], arraybuffer); + TEST_ASSERT (jerry_value_is_exception (typedarray)); + TEST_ASSERT (jerry_error_type (typedarray) == JERRY_ERROR_TYPE); + jerry_value_free (typedarray); } - jerry_release_value (arraybuffer); + jerry_value_free (arraybuffer); } } /* test_detached_arraybuffer */ @@ -575,16 +570,16 @@ main (void) { jerry_init (JERRY_INIT_EMPTY); - if (!jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY)) + if (!jerry_feature_enabled (JERRY_FEATURE_TYPEDARRAY)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "TypedArray is disabled!\n"); jerry_cleanup (); return 0; } - jerry_value_t function_val = jerry_create_external_function (assert_handler); + jerry_value_t function_val = jerry_function_external (assert_handler); register_js_value ("assert", function_val); - jerry_release_value (function_val); + jerry_value_free (function_val); test_entry_t test_entries[] = { #define TEST_ENTRY(TYPE, CONSTRUCTOR, COUNT, BYTES_PER_ELEMENT) { TYPE, CONSTRUCTOR, COUNT, BYTES_PER_ELEMENT } @@ -614,7 +609,7 @@ main (void) { const uint32_t element_count = 14; - jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_UINT8, element_count); + jerry_value_t array = jerry_typedarray (JERRY_TYPEDARRAY_UINT8, element_count); { uint8_t expected_value = 42; @@ -623,21 +618,21 @@ main (void) jerry_length_t byte_length; jerry_length_t offset; - jerry_value_t buffer = jerry_get_typedarray_buffer (array, &offset, &byte_length); + jerry_value_t buffer = jerry_typedarray_buffer (array, &offset, &byte_length); TEST_ASSERT (byte_length == element_count); jerry_length_t written = jerry_arraybuffer_write (buffer, offset, expected_data, element_count); TEST_ASSERT (written == element_count); - jerry_release_value (buffer); + jerry_value_free (buffer); - jerry_value_t js_element_count = jerry_create_number (element_count); - jerry_value_t js_expected_value = jerry_create_number (expected_value); + jerry_value_t js_element_count = jerry_number (element_count); + jerry_value_t js_expected_value = jerry_number (expected_value); register_js_value ("array", array); register_js_value ("expected_length", js_element_count); register_js_value ("expected_value", js_expected_value); - jerry_release_value (js_element_count); - jerry_release_value (js_expected_value); + jerry_value_free (js_element_count); + jerry_value_free (js_expected_value); } /* Check read and to write */ @@ -650,14 +645,14 @@ main (void) "};"); jerry_value_t result = jerry_eval (eval_src, sizeof (eval_src) - 1, JERRY_PARSE_STRICT_MODE); - TEST_ASSERT (!jerry_value_is_error (result)); - jerry_release_value (result); + TEST_ASSERT (!jerry_value_is_exception (result)); + jerry_value_free (result); /* Check write results */ { jerry_length_t byte_length; jerry_length_t offset; - jerry_value_t buffer = jerry_get_typedarray_buffer (array, &offset, &byte_length); + jerry_value_t buffer = jerry_typedarray_buffer (array, &offset, &byte_length); TEST_ASSERT (byte_length == element_count); JERRY_VLA (uint8_t, result_data, element_count); @@ -670,10 +665,10 @@ main (void) TEST_ASSERT (result_data[i] == i); } - jerry_release_value (buffer); + jerry_value_free (buffer); } - jerry_release_value (array); + jerry_value_free (array); } test_typedarray_complex_creation (test_entries, false); @@ -684,15 +679,15 @@ main (void) /* test invalid things */ { jerry_value_t values[] = { - jerry_create_number (11), - jerry_create_boolean (false), - jerry_create_string ((const jerry_char_t *) "test"), - jerry_create_object (), - jerry_create_null (), - jerry_create_arraybuffer (16), - jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error"), - jerry_create_undefined (), - jerry_create_promise (), + jerry_number (11), + jerry_boolean (false), + jerry_string_sz ("test"), + jerry_object (), + jerry_null (), + jerry_arraybuffer (16), + jerry_error_sz (JERRY_ERROR_TYPE, "error"), + jerry_undefined (), + jerry_promise (), }; for (size_t idx = 0; idx < sizeof (values) / sizeof (values[0]); idx++) @@ -702,11 +697,11 @@ main (void) TEST_ASSERT (is_typedarray == false); /* JERRY_TYPEDARRAY_INVALID should be returned for non-TypedArray objects */ - jerry_typedarray_type_t type = jerry_get_typedarray_type (values[idx]); + jerry_typedarray_type_t type = jerry_typedarray_type (values[idx]); TEST_ASSERT (type == JERRY_TYPEDARRAY_INVALID); /* Zero should be returned for non-TypedArray objects */ - jerry_length_t length = jerry_get_typedarray_length (values[idx]); + jerry_length_t length = jerry_typedarray_length (values[idx]); TEST_ASSERT (length == 0); /** @@ -716,11 +711,11 @@ main (void) { jerry_length_t offset = 22; jerry_length_t byte_count = 23; - jerry_value_t error = jerry_get_typedarray_buffer (values[idx], &offset, &byte_count); - TEST_ASSERT (jerry_value_is_error (error)); + jerry_value_t error = jerry_typedarray_buffer (values[idx], &offset, &byte_count); + TEST_ASSERT (jerry_value_is_exception (error)); TEST_ASSERT (offset == 22); TEST_ASSERT (byte_count == 23); - jerry_release_value (error); + jerry_value_free (error); } /** @@ -728,12 +723,12 @@ main (void) */ if (!jerry_value_is_arraybuffer (values[idx])) { - jerry_value_t error = jerry_create_typedarray_for_arraybuffer (JERRY_TYPEDARRAY_UINT8, values[idx]); - TEST_ASSERT (jerry_value_is_error (error)); - jerry_release_value (error); + jerry_value_t error = jerry_typedarray_with_buffer (JERRY_TYPEDARRAY_UINT8, values[idx]); + TEST_ASSERT (jerry_value_is_exception (error)); + jerry_value_free (error); } - jerry_release_value (values[idx]); + jerry_value_free (values[idx]); } } diff --git a/tests/unit-core/test-unicode.c b/tests/unit-core/test-unicode.c index 86a4db8465..4b9afd7d3a 100644 --- a/tests/unit-core/test-unicode.c +++ b/tests/unit-core/test-unicode.c @@ -24,13 +24,13 @@ test_syntax_error (char *script_p) /**< script */ bool result = false; - if (jerry_value_is_error (parse_result)) + if (jerry_value_is_exception (parse_result)) { result = true; - TEST_ASSERT (jerry_get_error_type (parse_result) == JERRY_ERROR_SYNTAX); + TEST_ASSERT (jerry_error_type (parse_result) == JERRY_ERROR_SYNTAX); } - jerry_release_value (parse_result); + jerry_value_free (parse_result); return result; } /* test_syntax_error */ diff --git a/tests/unit-core/test-vm-exec-stop.c b/tests/unit-core/test-vm-exec-stop.c index 083095e334..64939df3a0 100644 --- a/tests/unit-core/test-vm-exec-stop.c +++ b/tests/unit-core/test-vm-exec-stop.c @@ -27,10 +27,10 @@ vm_exec_stop_callback (void *user_p) { (*int_p)--; - return jerry_create_undefined (); + return jerry_undefined (); } - return jerry_create_string ((const jerry_char_t *) "Abort script"); + return jerry_string_sz ("Abort script"); } /* vm_exec_stop_callback */ int @@ -39,7 +39,7 @@ main (void) TEST_INIT (); /* Test stopping an infinite loop. */ - if (!jerry_is_feature_enabled (JERRY_FEATURE_VM_EXEC_STOP)) + if (!jerry_feature_enabled (JERRY_FEATURE_VM_EXEC_STOP)) { return 0; } @@ -47,19 +47,19 @@ main (void) jerry_init (JERRY_INIT_EMPTY); int countdown = 6; - jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16); + jerry_halt_cb (vm_exec_stop_callback, &countdown, 16); const jerry_char_t inf_loop_code_src1[] = "while(true) {}"; jerry_value_t parsed_code_val = jerry_parse (inf_loop_code_src1, sizeof (inf_loop_code_src1) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); TEST_ASSERT (countdown == 0); - TEST_ASSERT (jerry_value_is_error (res)); + TEST_ASSERT (jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); /* A more complex example. Although the callback error is captured * by the catch block, it is automatically thrown again. */ @@ -72,16 +72,16 @@ main (void) parsed_code_val = jerry_parse (inf_loop_code_src2, sizeof (inf_loop_code_src2) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); res = jerry_run (parsed_code_val); TEST_ASSERT (countdown == 0); /* The result must have an error flag which proves that * the error is thrown again inside the catch block. */ - TEST_ASSERT (jerry_value_is_error (res)); + TEST_ASSERT (jerry_value_is_exception (res)); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); jerry_cleanup (); return 0; diff --git a/tests/unit-core/test-vm-throw.c b/tests/unit-core/test-vm-throw.c index ba74da501f..861f5e78a8 100644 --- a/tests/unit-core/test-vm-throw.c +++ b/tests/unit-core/test-vm-throw.c @@ -33,7 +33,7 @@ vm_throw_callback (const jerry_value_t error_value, /**< captured error */ case 0: { TEST_ASSERT (counter == 1); - TEST_ASSERT (jerry_value_is_number (error_value) && jerry_get_number_value (error_value) == -5.6); + TEST_ASSERT (jerry_value_is_number (error_value) && jerry_value_as_number (error_value) == -5.6); break; } case 1: @@ -52,15 +52,15 @@ vm_throw_callback (const jerry_value_t error_value, /**< captured error */ TEST_ASSERT (counter >= 1 && counter <= 3); TEST_ASSERT (jerry_value_is_string (error_value)); - TEST_ASSERT (jerry_get_string_size (error_value) == size); - TEST_ASSERT (jerry_string_to_char_buffer (error_value, string_buf, size) == size); + TEST_ASSERT (jerry_string_size (error_value, JERRY_ENCODING_CESU8) == size); + TEST_ASSERT (jerry_string_to_buffer (error_value, string_buf, size, JERRY_ENCODING_CESU8) == size); TEST_ASSERT (string_buf[0] == 'e' && string_buf[1] == (char) ('0' + counter)); break; } case 3: { TEST_ASSERT (counter == 1); - TEST_ASSERT (jerry_get_error_type (error_value) == JERRY_ERROR_RANGE); + TEST_ASSERT (jerry_error_type (error_value) == JERRY_ERROR_RANGE); break; } case 4: @@ -69,7 +69,7 @@ vm_throw_callback (const jerry_value_t error_value, /**< captured error */ TEST_ASSERT (counter >= 1 && counter <= 2); jerry_error_t error = (counter == 1) ? JERRY_ERROR_REFERENCE : JERRY_ERROR_TYPE; - TEST_ASSERT (jerry_get_error_type (error_value) == error); + TEST_ASSERT (jerry_error_type (error_value) == error); break; } case 5: @@ -100,23 +100,23 @@ native_handler (const jerry_call_info_t *call_info_p, /**< call info */ if (mode == 7) { - jerry_value_t result = jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Error!"); + jerry_value_t result = jerry_throw_sz (JERRY_ERROR_COMMON, "Error!"); - TEST_ASSERT (!jerry_error_is_throw_captured (result)); - jerry_error_set_throw_capture (result, false); - TEST_ASSERT (jerry_error_is_throw_captured (result)); + TEST_ASSERT (!jerry_exception_is_captured (result)); + jerry_exception_allow_capture (result, false); + TEST_ASSERT (jerry_exception_is_captured (result)); return result; } jerry_char_t source[] = TEST_STRING_LITERAL ("throw false"); jerry_value_t result = jerry_eval (source, sizeof (source) - 1, JERRY_PARSE_NO_OPTS); - TEST_ASSERT (jerry_error_is_throw_captured (result)); + TEST_ASSERT (jerry_exception_is_captured (result)); if (mode == 6) { - jerry_error_set_throw_capture (result, true); - TEST_ASSERT (!jerry_error_is_throw_captured (result)); + jerry_exception_allow_capture (result, true); + TEST_ASSERT (!jerry_exception_is_captured (result)); } return result; } /* native_handler */ @@ -126,8 +126,8 @@ do_eval (const char *script_p, /**< script to evaluate */ bool should_throw) /**< script throws an error */ { jerry_value_t result = jerry_eval ((const jerry_char_t *) script_p, strlen (script_p), JERRY_PARSE_NO_OPTS); - TEST_ASSERT (jerry_value_is_error (result) == should_throw); - jerry_release_value (result); + TEST_ASSERT (jerry_value_is_exception (result) == should_throw); + jerry_value_free (result); } /* do_eval */ int @@ -136,14 +136,14 @@ main (void) TEST_INIT (); /* Test stopping an infinite loop. */ - if (!jerry_is_feature_enabled (JERRY_FEATURE_VM_THROW)) + if (!jerry_feature_enabled (JERRY_FEATURE_VM_THROW)) { return 0; } jerry_init (JERRY_INIT_EMPTY); - jerry_set_vm_throw_callback (vm_throw_callback, (void *) &mode); + jerry_throw_cb (vm_throw_callback, (void *) &mode); mode = 0; counter = 0; @@ -183,14 +183,14 @@ main (void) TEST_ASSERT (counter == 2); /* Native functions may trigger the call twice: */ - jerry_value_t global_object_value = jerry_get_global_object (); - jerry_value_t function_value = jerry_create_external_function (native_handler); - jerry_value_t function_name_value = jerry_create_string ((const jerry_char_t *) "native"); + jerry_value_t global_object_value = jerry_current_realm (); + jerry_value_t function_value = jerry_function_external (native_handler); + jerry_value_t function_name_value = jerry_string_sz ("native"); - jerry_release_value (jerry_set_property (global_object_value, function_name_value, function_value)); - jerry_release_value (function_name_value); - jerry_release_value (function_value); - jerry_release_value (global_object_value); + jerry_value_free (jerry_object_set (global_object_value, function_name_value, function_value)); + jerry_value_free (function_name_value); + jerry_value_free (function_value); + jerry_value_free (global_object_value); mode = 5; counter = 0; @@ -222,11 +222,11 @@ main (void) true); TEST_ASSERT (counter == 1); - jerry_value_t value = jerry_create_object (); - TEST_ASSERT (!jerry_error_is_throw_captured (value)); - jerry_error_set_throw_capture (value, false); - TEST_ASSERT (!jerry_error_is_throw_captured (value)); - jerry_release_value (value); + jerry_value_t value = jerry_object (); + TEST_ASSERT (!jerry_exception_is_captured (value)); + jerry_exception_allow_capture (value, false); + TEST_ASSERT (!jerry_exception_is_captured (value)); + jerry_value_free (value); jerry_cleanup (); return 0; diff --git a/tests/unit-ext/module/jerry-module-test.c b/tests/unit-ext/module/jerry-module-test.c index 201b38462a..e2c7b9cd56 100644 --- a/tests/unit-ext/module/jerry-module-test.c +++ b/tests/unit-ext/module/jerry-module-test.c @@ -80,13 +80,13 @@ const char eval_string7[] = "(function() {" static bool resolve_differently_handled_module (const jerry_value_t name, jerry_value_t *result) { - jerry_size_t name_size = jerry_get_utf8_string_size (name); + jerry_size_t name_size = jerry_string_size (name, JERRY_ENCODING_UTF8); JERRY_VLA (jerry_char_t, name_string, name_size); - jerry_string_to_utf8_char_buffer (name, name_string, name_size); + jerry_string_to_buffer (name, name_string, name_size, JERRY_ENCODING_UTF8); if (!strncmp ((char *) name_string, "differently-handled-module", name_size)) { - (*result) = jerry_create_number (29); + (*result) = jerry_number (29); return true; } return false; @@ -102,13 +102,13 @@ static jerryx_module_resolver_t differently_handled_module_resolver = { NULL, re static bool cache_check (const jerry_value_t name, jerry_value_t *result) { - jerry_size_t name_size = jerry_get_utf8_string_size (name); + jerry_size_t name_size = jerry_string_size (name, JERRY_ENCODING_UTF8); JERRY_VLA (jerry_char_t, name_string, name_size); - jerry_string_to_utf8_char_buffer (name, name_string, name_size); + jerry_string_to_buffer (name, name_string, name_size, JERRY_ENCODING_UTF8); if (!strncmp ((char *) name_string, "cache-check", name_size)) { - (*result) = jerry_create_object (); + (*result) = jerry_object (); return true; } return false; @@ -151,8 +151,8 @@ handle_require (const jerry_call_info_t *call_info_p, const jerry_value_t args_p static void assert_number (jerry_value_t js_value, double expected_result) { - TEST_ASSERT (!jerry_value_is_error (js_value)); - TEST_ASSERT (jerry_get_number_value (js_value) == expected_result); + TEST_ASSERT (!jerry_value_is_exception (js_value)); + TEST_ASSERT (jerry_value_as_number (js_value) == expected_result); } /* assert_number */ static void @@ -161,7 +161,7 @@ eval_one (const char *the_string, double expected_result) jerry_value_t js_eval_result = jerry_eval ((const jerry_char_t *) the_string, strlen (the_string), JERRY_PARSE_STRICT_MODE); assert_number (js_eval_result, expected_result); - jerry_release_value (js_eval_result); + jerry_value_free (js_eval_result); } /* eval_one */ #ifndef ENABLE_INIT_FINI @@ -184,27 +184,27 @@ main (int argc, char **argv) jerry_init (JERRY_INIT_EMPTY); - js_global = jerry_get_global_object (); + js_global = jerry_current_realm (); - js_function = jerry_create_external_function (handle_require); - js_property_name = jerry_create_string ((const jerry_char_t *) "require"); - res = jerry_set_property (js_global, js_property_name, js_function); - TEST_ASSERT (!jerry_value_is_error (res)); + js_function = jerry_function_external (handle_require); + js_property_name = jerry_string_sz ("require"); + res = jerry_object_set (js_global, js_property_name, js_function); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res) && jerry_value_is_true (res)); - jerry_release_value (res); - jerry_release_value (js_property_name); - jerry_release_value (js_function); - - js_function = jerry_create_external_function (handle_clear_require_cache); - js_property_name = jerry_create_string ((const jerry_char_t *) "clear_require_cache"); - res = jerry_set_property (js_global, js_property_name, js_function); - TEST_ASSERT (!jerry_value_is_error (res)); + jerry_value_free (res); + jerry_value_free (js_property_name); + jerry_value_free (js_function); + + js_function = jerry_function_external (handle_clear_require_cache); + js_property_name = jerry_string_sz ("clear_require_cache"); + res = jerry_object_set (js_global, js_property_name, js_function); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (jerry_value_is_boolean (res) && jerry_value_is_true (res)); - jerry_release_value (res); - jerry_release_value (js_property_name); - jerry_release_value (js_function); + jerry_value_free (res); + jerry_value_free (js_property_name); + jerry_value_free (js_function); - jerry_release_value (js_global); + jerry_value_free (js_global); eval_one (eval_string1, 42); eval_one (eval_string2, 29); diff --git a/tests/unit-ext/module/my-custom-module.c b/tests/unit-ext/module/my-custom-module.c index ab7800e6ee..f5a3e7d218 100644 --- a/tests/unit-ext/module/my-custom-module.c +++ b/tests/unit-ext/module/my-custom-module.c @@ -22,7 +22,7 @@ static jerry_value_t my_custom_module_on_resolve (void) { - return jerry_create_number (42); + return jerry_number (42); } /* my_custom_module_on_resolve */ JERRYX_NATIVE_MODULE (MODULE_NAME, my_custom_module_on_resolve) diff --git a/tests/unit-ext/test-ext-arg.c b/tests/unit-ext/test-ext-arg.c index 49f8657bfe..d32b865833 100644 --- a/tests/unit-ext/test-ext-arg.c +++ b/tests/unit-ext/test-ext-arg.c @@ -116,7 +116,7 @@ test_validator1_handler (const jerry_call_info_t *call_info_p, /**< call informa bool arg1; double arg2 = 0.0; char arg3[5] = "1234"; - jerry_value_t arg4 = jerry_create_undefined (); + jerry_value_t arg4 = jerry_undefined (); jerryx_arg_t mapping[] = { /* ignore this */ jerryx_arg_ignore (), @@ -135,7 +135,7 @@ test_validator1_handler (const jerry_call_info_t *call_info_p, /**< call informa if (validator1_count == 0) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (arg1); TEST_ASSERT (arg2 == 10.5); TEST_ASSERT (strcmp (arg3, "abc") == 0); @@ -143,7 +143,7 @@ test_validator1_handler (const jerry_call_info_t *call_info_p, /**< call informa } else if (validator1_count == 1) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (arg1); TEST_ASSERT (arg2 == 10.5); TEST_ASSERT (strcmp (arg3, "abc") == 0); @@ -151,7 +151,7 @@ test_validator1_handler (const jerry_call_info_t *call_info_p, /**< call informa } else if (validator1_count == 2) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (arg1); TEST_ASSERT (arg2 == 10.5); TEST_ASSERT (strcmp (arg3, "") == 0); @@ -159,14 +159,14 @@ test_validator1_handler (const jerry_call_info_t *call_info_p, /**< call informa } else { - TEST_ASSERT (jerry_value_is_error (is_ok)); + TEST_ASSERT (jerry_value_is_exception (is_ok)); } - jerry_release_value (is_ok); - jerry_release_value (arg4); + jerry_value_free (is_ok); + jerry_value_free (arg4); validator1_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator1_handler */ /** @@ -179,22 +179,22 @@ my_custom_transform (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< available JS jerry_value_t js_arg = jerryx_arg_js_iterator_pop (js_arg_iter_p); jerry_value_t to_number = jerry_value_to_number (js_arg); - if (jerry_value_is_error (to_number)) + if (jerry_value_is_exception (to_number)) { - jerry_release_value (to_number); + jerry_value_free (to_number); - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It can not be converted to a number."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "It can not be converted to a number."); } int expected_num = (int) c_arg_p->extra_info; - int get_num = (int) jerry_get_number_value (to_number); + int get_num = (int) jerry_value_as_number (to_number); if (get_num != expected_num) { - return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Number value is not expected."); + return jerry_throw_sz (JERRY_ERROR_TYPE, "Number value is not expected."); } - return jerry_create_undefined (); + return jerry_undefined (); } /* my_custom_transform */ /** @@ -220,19 +220,19 @@ test_validator2_handler (const jerry_call_info_t *call_info_p, /**< call informa if (validator2_count == 0) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (thing_p == &my_thing_a); TEST_ASSERT (thing_p->x == 1); } else { - TEST_ASSERT (jerry_value_is_error (is_ok)); + TEST_ASSERT (jerry_value_is_exception (is_ok)); } - jerry_release_value (is_ok); + jerry_value_free (is_ok); validator2_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator2_handler */ /** @@ -262,20 +262,20 @@ test_validator3_handler (const jerry_call_info_t *call_info_p, /**< call informa if (validator3_count == 0) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (arg1); TEST_ASSERT (arg2); } else if (validator3_count == 1) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (arg1); /* arg2 must be unchanged */ TEST_ASSERT (!arg2); } else if (validator3_count == 2) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); /* arg1 must be unchanged */ TEST_ASSERT (!arg1); /* arg2 must be unchanged */ @@ -283,17 +283,17 @@ test_validator3_handler (const jerry_call_info_t *call_info_p, /**< call informa } else if (validator3_count == 3) { - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); /* arg1 must be unchanged */ TEST_ASSERT (!arg1); /* arg2 must be unchanged */ TEST_ASSERT (!arg2); } - jerry_release_value (is_ok); + jerry_value_free (is_ok); validator3_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator3_handler */ /** @@ -323,14 +323,14 @@ test_validator_prop1_handler (const jerry_call_info_t *call_info_p, /**< call in mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (native1); TEST_ASSERT (native2 == 1.5); TEST_ASSERT (native3 == 3); validator_prop_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_prop1_handler */ /** @@ -367,7 +367,7 @@ test_validator_prop2_handler (const jerry_call_info_t *call_info_p, /**< call in jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); if (validator_prop_count == 1) { @@ -378,7 +378,7 @@ test_validator_prop2_handler (const jerry_call_info_t *call_info_p, /**< call in validator_prop_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_prop2_handler */ static jerry_value_t @@ -405,14 +405,14 @@ test_validator_prop3_handler (const jerry_call_info_t *call_info_p, /**< call in mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (jerry_value_is_error (is_ok)); + TEST_ASSERT (jerry_value_is_exception (is_ok)); TEST_ASSERT (!native1); TEST_ASSERT (native2); validator_prop_count++; - jerry_release_value (is_ok); + jerry_value_free (is_ok); - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_prop3_handler */ /* @@ -447,7 +447,7 @@ test_validator_int1_handler (const jerry_call_info_t *call_info_p, /**< call inf jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (num0 == 0); TEST_ASSERT (num1 == 255); TEST_ASSERT (num2 == 128); @@ -461,10 +461,10 @@ test_validator_int1_handler (const jerry_call_info_t *call_info_p, /**< call inf TEST_ASSERT (num10 == 2147483647); TEST_ASSERT (num11 == -2147483647); - jerry_release_value (is_ok); + jerry_value_free (is_ok); validator_int_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_int1_handler */ static jerry_value_t @@ -493,7 +493,7 @@ test_validator_int2_handler (const jerry_call_info_t *call_info_p, /**< call inf jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (jerry_value_is_error (is_ok)); + TEST_ASSERT (jerry_value_is_exception (is_ok)); TEST_ASSERT (num0 == -2); TEST_ASSERT (num1 == -2); TEST_ASSERT (num2 == -1); @@ -505,10 +505,10 @@ test_validator_int2_handler (const jerry_call_info_t *call_info_p, /**< call inf TEST_ASSERT (num8 == 127); TEST_ASSERT (num9 == 123); - jerry_release_value (is_ok); + jerry_value_free (is_ok); validator_int_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_int2_handler */ static jerry_value_t @@ -526,12 +526,12 @@ test_validator_int3_handler (const jerry_call_info_t *call_info_p, /**< call inf jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (jerry_value_is_error (is_ok)); + TEST_ASSERT (jerry_value_is_exception (is_ok)); - jerry_release_value (is_ok); + jerry_value_free (is_ok); validator_int_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_int3_handler */ static jerry_value_t @@ -560,7 +560,7 @@ test_validator_array1_handler (const jerry_call_info_t *call_info_p, /**< call i jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); if (validator_array_count == 0) { @@ -571,7 +571,7 @@ test_validator_array1_handler (const jerry_call_info_t *call_info_p, /**< call i validator_array_count++; - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_array1_handler */ static jerry_value_t @@ -590,14 +590,14 @@ test_validator_array2_handler (const jerry_call_info_t *call_info_p, /**< call i jerry_value_t is_ok = jerryx_arg_transform_array (args_p[0], item_mapping, ARRAY_SIZE (item_mapping)); - TEST_ASSERT (jerry_value_is_error (is_ok)); + TEST_ASSERT (jerry_value_is_exception (is_ok)); TEST_ASSERT (native1 == 1); TEST_ASSERT (!native2); validator_array_count++; - jerry_release_value (is_ok); + jerry_value_free (is_ok); - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_array2_handler */ /** @@ -673,7 +673,7 @@ jerry_arg_to_double_or_bool_t (jerryx_arg_js_iterator_t *js_arg_iter_p, const je (jerryx_arg_coerce_t) extra_info[0], JERRYX_ARG_OPTIONAL); conversion_result = conversion_function.func (js_arg_iter_p, &conversion_function); - if (!jerry_value_is_error (conversion_result)) + if (!jerry_value_is_exception (conversion_result)) { if (last_parameter) { @@ -696,9 +696,9 @@ jerry_arg_to_double_or_bool_t (jerryx_arg_js_iterator_t *js_arg_iter_p, const je (jerryx_arg_coerce_t) extra_info[0], (jerryx_arg_optional_t) extra_info[1]); - jerry_release_value (conversion_result); + jerry_value_free (conversion_result); conversion_result = conversion_function.func (js_arg_iter_p, &conversion_function); - if (!jerry_value_is_error (conversion_result)) + if (!jerry_value_is_exception (conversion_result)) { if (last_parameter) { @@ -717,8 +717,8 @@ jerry_arg_to_double_or_bool_t (jerryx_arg_js_iterator_t *js_arg_iter_p, const je /* Fall through indicates that whatever they gave us, it wasn't * one of the types we were expecting... */ - jerry_release_value (conversion_result); - return jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "double_or_bool-type error."); + jerry_value_free (conversion_result); + return jerry_throw_sz (JERRY_ERROR_TYPE, "double_or_bool-type error."); } /* jerry_arg_to_double_or_bool_t */ /** @@ -740,7 +740,7 @@ test_validator_restore_handler (const jerry_call_info_t *call_info_p, /**< call jerry_value_t is_ok = jerryx_arg_transform_args (args_p, args_cnt, item_mapping, ARRAY_SIZE (item_mapping)); - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); /* We are going to call this with [false, 3.0] and [3.0, false] parameters... */ bool arg1_is_false = (arg1.type_of_value == BOOL_VALUE && arg1.value.bool_field == false); @@ -749,16 +749,16 @@ test_validator_restore_handler (const jerry_call_info_t *call_info_p, /**< call bool arg2_is_three = (arg2.type_of_value == DOUBLE_VALUE && arg2.value.double_field == 3.0); TEST_ASSERT ((arg1_is_false && arg2_is_three) || (arg1_is_three && arg2_is_false)); - jerry_release_value (is_ok); + jerry_value_free (is_ok); - return jerry_create_undefined (); + return jerry_undefined (); } /* test_validator_restore_handler */ static void test_utf8_string (void) { /* test string: 'str: {DESERET CAPITAL LETTER LONG I}' */ - jerry_value_t str = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"); + jerry_value_t str = jerry_string_sz ("\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80"); char expect_utf8_buf[] = "\x73\x74\x72\x3a \xf0\x90\x90\x80"; size_t buf_len = sizeof (expect_utf8_buf) - 1; JERRY_VLA (char, buf, buf_len + 1); @@ -769,10 +769,10 @@ test_utf8_string (void) jerry_value_t is_ok = jerryx_arg_transform_args (&str, 1, mapping, ARRAY_SIZE (mapping)); - TEST_ASSERT (!jerry_value_is_error (is_ok)); + TEST_ASSERT (!jerry_value_is_exception (is_ok)); TEST_ASSERT (!strcmp (buf, expect_utf8_buf)); - jerry_release_value (str); + jerry_value_free (str); } /* test_utf8_string */ static jerry_value_t @@ -786,9 +786,9 @@ create_object_a_handler (const jerry_call_info_t *call_info_p, /**< call informa TEST_ASSERT (jerry_value_is_object (call_info_p->this_value)); my_thing_a.x = 1; - jerry_set_object_native_pointer (call_info_p->this_value, &my_thing_a, &thing_a_info); + jerry_object_set_native_ptr (call_info_p->this_value, &thing_a_info, &my_thing_a); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* create_object_a_handler */ static jerry_value_t @@ -802,9 +802,9 @@ create_object_b_handler (const jerry_call_info_t *call_info_p, /**< call informa TEST_ASSERT (jerry_value_is_object (call_info_p->this_value)); my_thing_b.x = false; - jerry_set_object_native_pointer (call_info_p->this_value, &my_thing_b, &thing_b_info); + jerry_object_set_native_ptr (call_info_p->this_value, &thing_b_info, &my_thing_b); - return jerry_create_boolean (true); + return jerry_boolean (true); } /* create_object_b_handler */ /** @@ -814,17 +814,17 @@ static void register_js_function (const char *name_p, /**< name of the function */ jerry_external_handler_t handler_p) /**< function callback */ { - jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t global_obj_val = jerry_current_realm (); - jerry_value_t function_val = jerry_create_external_function (handler_p); - jerry_value_t function_name_val = jerry_create_string ((const jerry_char_t *) name_p); - jerry_value_t result_val = jerry_set_property (global_obj_val, function_name_val, function_val); + jerry_value_t function_val = jerry_function_external (handler_p); + jerry_value_t function_name_val = jerry_string_sz (name_p); + jerry_value_t result_val = jerry_object_set (global_obj_val, function_name_val, function_val); - jerry_release_value (function_name_val); - jerry_release_value (function_val); - jerry_release_value (global_obj_val); + jerry_value_free (function_name_val); + jerry_value_free (function_val); + jerry_value_free (global_obj_val); - jerry_release_value (result_val); + jerry_value_free (result_val); } /* register_js_function */ int @@ -850,10 +850,10 @@ main (void) register_js_function ("test_validator_restore", test_validator_restore_handler); jerry_value_t parsed_code_val = jerry_parse (test_source, sizeof (test_source) - 1, NULL); - TEST_ASSERT (!jerry_value_is_error (parsed_code_val)); + TEST_ASSERT (!jerry_value_is_exception (parsed_code_val)); jerry_value_t res = jerry_run (parsed_code_val); - TEST_ASSERT (!jerry_value_is_error (res)); + TEST_ASSERT (!jerry_value_is_exception (res)); TEST_ASSERT (validator1_count == 5); TEST_ASSERT (validator2_count == 3); TEST_ASSERT (validator_prop_count == 4); @@ -861,8 +861,8 @@ main (void) TEST_ASSERT (validator_array_count == 3); TEST_ASSERT (validator_restore_count == 4); - jerry_release_value (res); - jerry_release_value (parsed_code_val); + jerry_value_free (res); + jerry_value_free (parsed_code_val); jerry_cleanup (); } /* main */ diff --git a/tests/unit-ext/test-ext-autorelease.c b/tests/unit-ext/test-ext-autorelease.c index 235f64bac3..b97de49fd9 100644 --- a/tests/unit-ext/test-ext-autorelease.c +++ b/tests/unit-ext/test-ext-autorelease.c @@ -42,8 +42,8 @@ static const jerry_object_native_info_t native_info = { static jerry_value_t create_object (void) { - jerry_value_t obj = jerry_create_object (); - jerry_set_object_native_pointer (obj, NULL, &native_info); + jerry_value_t obj = jerry_object (); + jerry_object_set_native_ptr (obj, &native_info, NULL); return obj; } /* create_object */ @@ -61,7 +61,7 @@ main (void) native_free_cb_call_count = 0; test_autorelease_val (); - jerry_gc (JERRY_GC_PRESSURE_HIGH); + jerry_heap_gc (JERRY_GC_PRESSURE_HIGH); TEST_ASSERT (native_free_cb_call_count == 1); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-handle-scope-escape.c b/tests/unit-ext/test-ext-handle-scope-escape.c index b967e05777..c9104a1952 100644 --- a/tests/unit-ext/test-ext-handle-scope-escape.c +++ b/tests/unit-ext/test-ext-handle-scope-escape.c @@ -44,8 +44,8 @@ create_object (void) { jerryx_escapable_handle_scope scope; jerryx_open_escapable_handle_scope (&scope); - jerry_value_t obj = jerryx_create_handle (jerry_create_object ()); - jerry_set_object_native_pointer (obj, NULL, &native_info); + jerry_value_t obj = jerryx_create_handle (jerry_object ()); + jerry_object_set_native_ptr (obj, &native_info, NULL); // If leaves `escaped` uninitialized, there will be a style error on linux thrown by compiler jerry_value_t escaped = 0; @@ -65,7 +65,7 @@ test_handle_scope_val (void) jerry_value_t obj = create_object (); (void) obj; - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 0); jerryx_close_handle_scope (scope); @@ -79,7 +79,7 @@ main (void) native_free_cb_call_count = 0; test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 1); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-handle-scope-handle-prelist-escape.c b/tests/unit-ext/test-ext-handle-scope-handle-prelist-escape.c index 9070d6d409..927f76c40f 100644 --- a/tests/unit-ext/test-ext-handle-scope-handle-prelist-escape.c +++ b/tests/unit-ext/test-ext-handle-scope-handle-prelist-escape.c @@ -51,8 +51,8 @@ create_object (void) jerry_value_t obj; for (size_t idx = 0; idx < handle_count; idx++) { - obj = jerryx_create_handle (jerry_create_object ()); - jerry_set_object_native_pointer (obj, NULL, &native_info); + obj = jerryx_create_handle (jerry_object ()); + jerry_object_set_native_ptr (obj, &native_info, NULL); } // If leaves `escaped` uninitialized, there will be a style error on linux thrown by compiler @@ -72,7 +72,7 @@ test_handle_scope_val (void) jerry_value_t obj = create_object (); (void) obj; - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == (handle_count - 1)); jerryx_close_handle_scope (scope); @@ -86,7 +86,7 @@ main (void) native_free_cb_call_count = 0; test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == handle_count); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-handle-scope-handle-prelist.c b/tests/unit-ext/test-ext-handle-scope-handle-prelist.c index e00d0fa81f..866ac1448f 100644 --- a/tests/unit-ext/test-ext-handle-scope-handle-prelist.c +++ b/tests/unit-ext/test-ext-handle-scope-handle-prelist.c @@ -51,8 +51,8 @@ create_object (void) jerry_value_t obj; for (size_t idx = 0; idx < handle_count; idx++) { - obj = jerryx_create_handle (jerry_create_object ()); - jerry_set_object_native_pointer (obj, NULL, &native_info); + obj = jerryx_create_handle (jerry_object ()); + jerry_object_set_native_ptr (obj, &native_info, NULL); } // If leaves `escaped` uninitialized, there will be a style error on linux thrown by compiler @@ -72,7 +72,7 @@ test_handle_scope_val (void) jerry_value_t obj = create_object (); (void) obj; - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == (handle_count - 1)); jerryx_close_handle_scope (scope); @@ -86,7 +86,7 @@ main (void) native_free_cb_call_count = 0; test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == handle_count); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-handle-scope-nested.c b/tests/unit-ext/test-ext-handle-scope-nested.c index 9e7a16a35a..24c21b3476 100644 --- a/tests/unit-ext/test-ext-handle-scope-nested.c +++ b/tests/unit-ext/test-ext-handle-scope-nested.c @@ -51,8 +51,8 @@ create_object_nested (int times) jerry_value_t obj; if (times == 0) { - obj = jerryx_create_handle (jerry_create_object ()); - jerry_set_object_native_pointer (obj, NULL, &native_info); + obj = jerryx_create_handle (jerry_object ()); + jerry_object_set_native_ptr (obj, &native_info, NULL); } else { @@ -85,7 +85,7 @@ test_handle_scope_val (void) TEST_ASSERT (jerryx_handle_scope_get_current () == scope); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 0); jerryx_close_handle_scope (scope); @@ -99,7 +99,7 @@ main (void) native_free_cb_call_count = 0; test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 2); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-handle-scope-remove.c b/tests/unit-ext/test-ext-handle-scope-remove.c index c1dacba70e..3a4d71ae14 100644 --- a/tests/unit-ext/test-ext-handle-scope-remove.c +++ b/tests/unit-ext/test-ext-handle-scope-remove.c @@ -44,8 +44,8 @@ create_object (void) { jerryx_escapable_handle_scope scope; jerryx_open_escapable_handle_scope (&scope); - jerry_value_t obj = jerryx_create_handle (jerry_create_object ()); - jerry_set_object_native_pointer (obj, NULL, &native_info); + jerry_value_t obj = jerryx_create_handle (jerry_object ()); + jerry_object_set_native_ptr (obj, &native_info, NULL); // If leaves `escaped` uninitialized, there will be a style error on linux thrown by compiler jerry_value_t escaped = 0; @@ -65,15 +65,15 @@ test_handle_scope_val (void) jerry_value_t obj = create_object (); (void) obj; - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 0); jerryx_close_handle_scope (scope); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 0); - jerry_release_value (obj); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_value_free (obj); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 1); } /* test_handle_scope_val */ diff --git a/tests/unit-ext/test-ext-handle-scope-root.c b/tests/unit-ext/test-ext-handle-scope-root.c index cd282fd685..9bcb463921 100644 --- a/tests/unit-ext/test-ext-handle-scope-root.c +++ b/tests/unit-ext/test-ext-handle-scope-root.c @@ -43,8 +43,8 @@ static const jerry_object_native_info_t native_info = { static jerry_value_t create_object (void) { - jerry_value_t obj = jerry_create_object (); - jerry_set_object_native_pointer (obj, NULL, &native_info); + jerry_value_t obj = jerry_object (); + jerry_object_set_native_ptr (obj, &native_info, NULL); return obj; } /* create_object */ @@ -58,7 +58,7 @@ test_handle_scope_val (void) jerry_value_t obj = jerryx_create_handle (create_object ()); (void) obj; jerryx_close_handle_scope (root); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == (i + 1)); } } /* test_handle_scope_val */ @@ -71,7 +71,7 @@ main (void) native_free_cb_call_count = 0; test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == reusing_times); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-handle-scope.c b/tests/unit-ext/test-ext-handle-scope.c index 5838173547..b8fc048d8e 100644 --- a/tests/unit-ext/test-ext-handle-scope.c +++ b/tests/unit-ext/test-ext-handle-scope.c @@ -42,8 +42,8 @@ static const jerry_object_native_info_t native_info = { static jerry_value_t create_object (void) { - jerry_value_t obj = jerry_create_object (); - jerry_set_object_native_pointer (obj, NULL, &native_info); + jerry_value_t obj = jerry_object (); + jerry_object_set_native_ptr (obj, &native_info, NULL); return obj; } /* create_object */ @@ -64,7 +64,7 @@ main (void) native_free_cb_call_count = 0; test_handle_scope_val (); - jerry_gc (JERRY_GC_PRESSURE_LOW); + jerry_heap_gc (JERRY_GC_PRESSURE_LOW); TEST_ASSERT (native_free_cb_call_count == 1); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-method-register.c b/tests/unit-ext/test-ext-method-register.c index d39c2892db..405b4ae6ea 100644 --- a/tests/unit-ext/test-ext-method-register.c +++ b/tests/unit-ext/test-ext-method-register.c @@ -31,7 +31,7 @@ method_hello (const jerry_call_info_t *call_info_p, /**< call information */ { (void) call_info_p; (void) jargv; - return jerry_create_number (jargc); + return jerry_number (jargc); } /* method_hello */ /** @@ -42,14 +42,14 @@ freeze_property (jerry_value_t target_obj, /**< target object */ const char *target_prop) /**< target property name */ { // "freeze" property - jerry_property_descriptor_t prop_desc = jerry_property_descriptor_create (); + jerry_property_descriptor_t prop_desc = jerry_property_descriptor (); prop_desc.flags |= JERRY_PROP_IS_CONFIGURABLE_DEFINED; - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) target_prop); - jerry_value_t return_value = jerry_define_own_property (target_obj, prop_name, &prop_desc); + jerry_value_t prop_name = jerry_string_sz (target_prop); + jerry_value_t return_value = jerry_object_define_own_prop (target_obj, prop_name, &prop_desc); TEST_ASSERT (jerry_value_is_boolean (return_value)); - jerry_release_value (return_value); - jerry_release_value (prop_name); + jerry_value_free (return_value); + jerry_value_free (prop_name); jerry_property_descriptor_free (&prop_desc); } /* freeze_property */ @@ -62,14 +62,14 @@ test_simple_registration (void) { jerry_init (JERRY_INIT_EMPTY); - jerry_value_t target_object = jerry_create_object (); + jerry_value_t target_object = jerry_object (); // Test simple registration jerryx_property_entry methods[] = { - JERRYX_PROPERTY_FUNCTION ("hello", method_hello), JERRYX_PROPERTY_NUMBER ("my_number", 42.5), - JERRYX_PROPERTY_STRING ("my_str", "super_str"), JERRYX_PROPERTY_STRING_SZ ("my_str_sz", "super_str", 6), - JERRYX_PROPERTY_BOOLEAN ("my_bool", true), JERRYX_PROPERTY_BOOLEAN ("my_bool_false", false), - JERRYX_PROPERTY_UNDEFINED ("my_non_value"), JERRYX_PROPERTY_LIST_END (), + JERRYX_PROPERTY_FUNCTION ("hello", method_hello), JERRYX_PROPERTY_NUMBER ("my_number", 42.5), + JERRYX_PROPERTY_STRING_SZ ("my_str", "super_str"), JERRYX_PROPERTY_STRING ("my_str_sz", "super_str", 6), + JERRYX_PROPERTY_BOOLEAN ("my_bool", true), JERRYX_PROPERTY_BOOLEAN ("my_bool_false", false), + JERRYX_PROPERTY_UNDEFINED ("my_non_value"), JERRYX_PROPERTY_LIST_END (), }; jerryx_register_result register_result = jerryx_set_properties (target_object, methods); @@ -78,19 +78,19 @@ test_simple_registration (void) TEST_ASSERT (jerry_value_is_undefined (register_result.result)); jerryx_release_property_entry (methods, register_result); - jerry_release_value (register_result.result); + jerry_value_free (register_result.result); - jerry_value_t global_obj = jerry_get_global_object (); + jerry_value_t global_obj = jerry_current_realm (); jerryx_set_property_str (global_obj, "test", target_object); - jerry_release_value (target_object); - jerry_release_value (global_obj); + jerry_value_free (target_object); + jerry_value_free (global_obj); { const char *test_A = "test.my_number"; jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_number (result)); - TEST_ASSERT (jerry_get_number_value (result) == 42.5); - jerry_release_value (result); + TEST_ASSERT (jerry_value_as_number (result) == 42.5); + jerry_value_free (result); } { @@ -98,7 +98,7 @@ test_simple_registration (void) jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); } { @@ -106,7 +106,7 @@ test_simple_registration (void) jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); } { @@ -114,7 +114,7 @@ test_simple_registration (void) jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result)); - jerry_release_value (result); + jerry_value_free (result); } { @@ -122,30 +122,30 @@ test_simple_registration (void) jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_boolean (result)); TEST_ASSERT (jerry_value_is_true (result) == false); - jerry_release_value (result); + jerry_value_free (result); } { const char *test_A = "test.my_non_value"; jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_undefined (result)); - jerry_release_value (result); + jerry_value_free (result); } { const char *test_A = "test.hello(33, 42, 2);"; jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_number (result)); - TEST_ASSERT ((uint32_t) jerry_get_number_value (result) == 3u); - jerry_release_value (result); + TEST_ASSERT ((uint32_t) jerry_value_as_number (result) == 3u); + jerry_value_free (result); } { const char *test_A = "test.hello();"; jerry_value_t result = jerry_eval ((const jerry_char_t *) test_A, strlen (test_A), 0); TEST_ASSERT (jerry_value_is_number (result)); - TEST_ASSERT ((uint32_t) jerry_get_number_value (result) == 0u); - jerry_release_value (result); + TEST_ASSERT ((uint32_t) jerry_value_as_number (result) == 0u); + jerry_value_free (result); } jerry_cleanup (); @@ -163,16 +163,16 @@ test_error_setvalue (void) jerry_init (JERRY_INIT_EMPTY); const char *target_prop = "test_err"; - jerry_value_t global_obj = jerry_get_global_object (); + jerry_value_t global_obj = jerry_current_realm (); freeze_property (global_obj, target_prop); - jerry_value_t new_object = jerry_create_object (); + jerry_value_t new_object = jerry_object (); jerry_value_t set_result = jerryx_set_property_str (global_obj, target_prop, new_object); - TEST_ASSERT (jerry_value_is_error (set_result)); + TEST_ASSERT (jerry_value_is_exception (set_result)); - jerry_release_value (set_result); - jerry_release_value (new_object); - jerry_release_value (global_obj); + jerry_value_free (set_result); + jerry_value_free (new_object); + jerry_value_free (global_obj); jerry_cleanup (); } /* test_error_setvalue */ @@ -189,7 +189,7 @@ test_error_single_function (void) jerry_init (JERRY_INIT_EMPTY); const char *target_prop = "test_err"; - jerry_value_t target_object = jerry_create_object (); + jerry_value_t target_object = jerry_object (); freeze_property (target_object, target_prop); jerryx_property_entry methods[] = { @@ -200,11 +200,11 @@ test_error_single_function (void) jerryx_register_result register_result = jerryx_set_properties (target_object, methods); TEST_ASSERT (register_result.registered == 0); - TEST_ASSERT (jerry_value_is_error (register_result.result)); + TEST_ASSERT (jerry_value_is_exception (register_result.result)); jerryx_release_property_entry (methods, register_result); - jerry_release_value (register_result.result); + jerry_value_free (register_result.result); - jerry_release_value (target_object); + jerry_value_free (target_object); jerry_cleanup (); } /* test_error_single_function */ @@ -220,7 +220,7 @@ test_error_multiple_functions (void) const char *prop_ok = "prop_ok"; const char *prop_err = "prop_err"; const char *prop_not = "prop_not"; - jerry_value_t target_object = jerry_create_object (); + jerry_value_t target_object = jerry_object (); freeze_property (target_object, prop_err); jerryx_property_entry methods[] = { @@ -233,59 +233,59 @@ test_error_multiple_functions (void) jerryx_register_result register_result = jerryx_set_properties (target_object, methods); TEST_ASSERT (register_result.registered == 1); - TEST_ASSERT (jerry_value_is_error (register_result.result)); + TEST_ASSERT (jerry_value_is_exception (register_result.result)); jerryx_release_property_entry (methods, register_result); - jerry_release_value (register_result.result); + jerry_value_free (register_result.result); { // Test if property "prop_ok" is correctly registered. - jerry_value_t prop_ok_val = jerry_create_string ((const jerry_char_t *) prop_ok); - jerry_value_t prop_ok_exists = jerry_has_own_property (target_object, prop_ok_val); + jerry_value_t prop_ok_val = jerry_string_sz (prop_ok); + jerry_value_t prop_ok_exists = jerry_object_has_own (target_object, prop_ok_val); TEST_ASSERT (jerry_value_is_true (prop_ok_exists)); - jerry_release_value (prop_ok_exists); + jerry_value_free (prop_ok_exists); // Try calling the method - jerry_value_t prop_ok_func = jerry_get_property (target_object, prop_ok_val); + jerry_value_t prop_ok_func = jerry_object_get (target_object, prop_ok_val); TEST_ASSERT (jerry_value_is_function (prop_ok_func) == true); jerry_value_t args[2] = { - jerry_create_number (22), - jerry_create_number (-3), + jerry_number (22), + jerry_number (-3), }; jerry_size_t args_cnt = sizeof (args) / sizeof (jerry_value_t); - jerry_value_t func_result = jerry_call_function (prop_ok_func, jerry_create_undefined (), args, args_cnt); + jerry_value_t func_result = jerry_call (prop_ok_func, jerry_undefined (), args, args_cnt); TEST_ASSERT (jerry_value_is_number (func_result) == true); - TEST_ASSERT ((uint32_t) jerry_get_number_value (func_result) == 2u); - jerry_release_value (func_result); + TEST_ASSERT ((uint32_t) jerry_value_as_number (func_result) == 2u); + jerry_value_free (func_result); for (jerry_size_t idx = 0; idx < args_cnt; idx++) { - jerry_release_value (args[idx]); + jerry_value_free (args[idx]); } - jerry_release_value (prop_ok_func); - jerry_release_value (prop_ok_val); + jerry_value_free (prop_ok_func); + jerry_value_free (prop_ok_val); } { // The "prop_err" should exist - as it was "freezed" - but it should not be a function - jerry_value_t prop_err_val = jerry_create_string ((const jerry_char_t *) prop_err); - jerry_value_t prop_err_exists = jerry_has_own_property (target_object, prop_err_val); + jerry_value_t prop_err_val = jerry_string_sz (prop_err); + jerry_value_t prop_err_exists = jerry_object_has_own (target_object, prop_err_val); TEST_ASSERT (jerry_value_is_true (prop_err_exists)); - jerry_release_value (prop_err_exists); + jerry_value_free (prop_err_exists); jerry_value_t prop_err_func = jerry_value_is_function (prop_err_val); TEST_ASSERT (jerry_value_is_function (prop_err_func) == false); - jerry_release_value (prop_err_val); + jerry_value_free (prop_err_val); } { // The "prop_not" is not available on the target object - jerry_value_t prop_not_val = jerry_create_string ((const jerry_char_t *) prop_not); - jerry_value_t prop_not_exists = jerry_has_own_property (target_object, prop_not_val); + jerry_value_t prop_not_val = jerry_string_sz (prop_not); + jerry_value_t prop_not_exists = jerry_object_has_own (target_object, prop_not_val); TEST_ASSERT (jerry_value_is_true (prop_not_exists) == false); - jerry_release_value (prop_not_exists); - jerry_release_value (prop_not_val); + jerry_value_free (prop_not_exists); + jerry_value_free (prop_not_val); } - jerry_release_value (target_object); + jerry_value_free (target_object); jerry_cleanup (); } /* test_error_multiple_functions */ diff --git a/tests/unit-ext/test-ext-module-canonical.c b/tests/unit-ext/test-ext-module-canonical.c index 07c00b039c..887a43fa23 100644 --- a/tests/unit-ext/test-ext-module-canonical.c +++ b/tests/unit-ext/test-ext-module-canonical.c @@ -26,36 +26,36 @@ static jerry_value_t get_canonical_name (const jerry_value_t name) { - jerry_size_t name_size = jerry_get_string_size (name); + jerry_size_t name_size = jerry_string_size (name, JERRY_ENCODING_CESU8); JERRY_VLA (jerry_char_t, name_string, name_size + 1); - jerry_string_to_char_buffer (name, name_string, name_size); + jerry_string_to_buffer (name, name_string, name_size, JERRY_ENCODING_CESU8); name_string[name_size] = 0; if (!strcmp ((char *) name_string, ACTUAL_NAME)) { - return jerry_acquire_value (name); + return jerry_value_copy (name); } else if (!strcmp ((char *) name_string, ALIAS_NAME)) { - return jerry_create_string ((jerry_char_t *) ACTUAL_NAME); + return jerry_string_sz (ACTUAL_NAME); } else { - return jerry_create_undefined (); + return jerry_undefined (); } } /* get_canonical_name */ static bool resolve (const jerry_value_t canonical_name, jerry_value_t *result) { - jerry_size_t name_size = jerry_get_string_size (canonical_name); + jerry_size_t name_size = jerry_string_size (canonical_name, JERRY_ENCODING_CESU8); JERRY_VLA (jerry_char_t, name_string, name_size + 1); - jerry_string_to_char_buffer (canonical_name, name_string, name_size); + jerry_string_to_buffer (canonical_name, name_string, name_size, JERRY_ENCODING_CESU8); name_string[name_size] = 0; if (!strcmp ((char *) name_string, ACTUAL_NAME)) { - *result = jerry_create_object (); + *result = jerry_object (); return true; } return false; @@ -76,28 +76,28 @@ main (int argc, char **argv) jerry_init (JERRY_INIT_EMPTY); - jerry_value_t actual_name = jerry_create_string ((jerry_char_t *) ACTUAL_NAME); - jerry_value_t alias_name = jerry_create_string ((jerry_char_t *) ALIAS_NAME); + jerry_value_t actual_name = jerry_string_sz (ACTUAL_NAME); + jerry_value_t alias_name = jerry_string_sz (ALIAS_NAME); /* It's important that we resolve by the non-canonical name first. */ jerry_value_t result2 = jerryx_module_resolve (alias_name, &resolver, 1); jerry_value_t result1 = jerryx_module_resolve (actual_name, &resolver, 1); - jerry_release_value (actual_name); - jerry_release_value (alias_name); + jerry_value_free (actual_name); + jerry_value_free (alias_name); /* An elaborate way of doing strict equal - set a property on one object and it "magically" appears on the other. */ - jerry_value_t prop_name = jerry_create_string ((jerry_char_t *) "something"); - jerry_value_t prop_value = jerry_create_number (TEST_VALUE); - jerry_release_value (jerry_set_property (result1, prop_name, prop_value)); - jerry_release_value (prop_value); - - prop_value = jerry_get_property (result2, prop_name); - TEST_ASSERT (jerry_get_number_value (prop_value) == TEST_VALUE); - jerry_release_value (prop_value); - - jerry_release_value (prop_name); - jerry_release_value (result1); - jerry_release_value (result2); + jerry_value_t prop_name = jerry_string_sz ("something"); + jerry_value_t prop_value = jerry_number (TEST_VALUE); + jerry_value_free (jerry_object_set (result1, prop_name, prop_value)); + jerry_value_free (prop_value); + + prop_value = jerry_object_get (result2, prop_name); + TEST_ASSERT (jerry_value_as_number (prop_value) == TEST_VALUE); + jerry_value_free (prop_value); + + jerry_value_free (prop_name); + jerry_value_free (result1); + jerry_value_free (result2); jerry_cleanup (); diff --git a/tests/unit-ext/test-ext-module-empty.c b/tests/unit-ext/test-ext-module-empty.c index b9b0ad22cc..950fbb2346 100644 --- a/tests/unit-ext/test-ext-module-empty.c +++ b/tests/unit-ext/test-ext-module-empty.c @@ -33,43 +33,43 @@ main (int argc, char **argv) jerry_init (JERRY_INIT_EMPTY); /* Attempt to load a non-existing module. */ - module_name = jerry_create_string ((jerry_char_t *) "some-unknown-module-name"); + module_name = jerry_string_sz ("some-unknown-module-name"); jerry_value_t module = jerryx_module_resolve (module_name, &resolver, 1); - jerry_release_value (module_name); + jerry_value_free (module_name); - TEST_ASSERT (jerry_value_is_error (module)); + TEST_ASSERT (jerry_value_is_exception (module)); /* Retrieve the error message. */ - module = jerry_get_value_from_error (module, true); - jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "message"); - jerry_value_t prop = jerry_get_property (module, prop_name); + module = jerry_exception_value (module, true); + jerry_value_t prop_name = jerry_string_sz ("message"); + jerry_value_t prop = jerry_object_get (module, prop_name); /* Assert that the error message is a string with specific contents. */ TEST_ASSERT (jerry_value_is_string (prop)); - bytes_copied = jerry_substring_to_utf8_char_buffer (prop, 0, 254, buffer, 256); + bytes_copied = jerry_string_to_buffer (prop, buffer, sizeof (buffer), JERRY_ENCODING_UTF8); buffer[bytes_copied] = 0; TEST_ASSERT (!strcmp ((const char *) buffer, "Module not found")); /* Release the error message property name and value. */ - jerry_release_value (prop); - jerry_release_value (prop_name); + jerry_value_free (prop); + jerry_value_free (prop_name); /* Retrieve the moduleName property. */ - prop_name = jerry_create_string ((const jerry_char_t *) "moduleName"); - prop = jerry_get_property (module, prop_name); + prop_name = jerry_string_sz ("moduleName"); + prop = jerry_object_get (module, prop_name); /* Assert that the moduleName property is a string containing the requested module name. */ TEST_ASSERT (jerry_value_is_string (prop)); - bytes_copied = jerry_substring_to_utf8_char_buffer (prop, 0, 254, buffer, 256); + bytes_copied = jerry_string_to_buffer (prop, buffer, sizeof (buffer), JERRY_ENCODING_UTF8); buffer[bytes_copied] = 0; TEST_ASSERT (!strcmp ((const char *) buffer, "some-unknown-module-name")); /* Release everything. */ - jerry_release_value (prop); - jerry_release_value (prop_name); - jerry_release_value (module); + jerry_value_free (prop); + jerry_value_free (prop_name); + jerry_value_free (module); return 0; } /* main */ diff --git a/tools/run-tests.py b/tools/run-tests.py index dd5cf68aaa..70cf9b0216 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -288,7 +288,7 @@ def create_binary(job, options): subprocess.check_output(build_cmd) ret = 0 except subprocess.CalledProcessError as err: - print(err.output) + print(err.output.decode("utf8")) ret = err.returncode BINARY_CACHE[binary_key] = (ret, build_dir_path) diff --git a/tools/version.py b/tools/version.py index 263723cd20..0b3a1fd82d 100755 --- a/tools/version.py +++ b/tools/version.py @@ -32,7 +32,7 @@ def main(): ) _ = parser.parse_args() - with open(os.path.join(settings.PROJECT_DIR, 'jerry-core', 'include', 'jerryscript-types.h'), 'r') as header: + with open(os.path.join(settings.PROJECT_DIR, 'jerry-core', 'include', 'jerryscript.h'), 'r') as header: version = {} version_re = re.compile(r'\s*#define\s+JERRY_API_(?PMAJOR|MINOR|PATCH)_VERSION\s+(?P\S+)') for line in header: