diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c index 0ffa623a9..6a48c6d18 100644 --- a/jerry-core/api/jerry.c +++ b/jerry-core/api/jerry.c @@ -48,6 +48,14 @@ JERRY_STATIC_ASSERT ((int) ECMA_ERROR_COMMON == (int) JERRY_ERROR_COMMON && (int) ECMA_ERROR_URI == (int) JERRY_ERROR_URI, ecma_standard_error_t_must_be_equal_to_jerry_error_t); +JERRY_STATIC_ASSERT ((int) ECMA_INIT_EMPTY == (int) JERRY_INIT_EMPTY + && (int) ECMA_INIT_SHOW_OPCODES == (int) JERRY_INIT_SHOW_OPCODES + && (int) ECMA_INIT_SHOW_REGEXP_OPCODES == (int) JERRY_INIT_SHOW_REGEXP_OPCODES + && (int) ECMA_INIT_MEM_STATS == (int) JERRY_INIT_MEM_STATS + && (int) ECMA_INIT_MEM_STATS_SEPARATE == (int) JERRY_INIT_MEM_STATS_SEPARATE + && (int) ECMA_INIT_DEBUGGER == (int) JERRY_INIT_DEBUGGER, + ecma_init_flag_t_must_be_equal_to_jerry_init_flag_t); + #ifndef JERRY_JS_PARSER #error JERRY_JS_PARSER must be defined with 0 (disabled) or 1 (enabled) #elif !JERRY_JS_PARSER && !defined (JERRY_ENABLE_SNAPSHOT_EXEC) @@ -169,11 +177,11 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ */ void jerry_init_with_user_context (jerry_init_flag_t flags, /**< combination of Jerry flags */ - jerry_user_context_init_cb init_cb, /**< callback to call to create the user context or - * NULL, in which case no user context will be - * created */ - jerry_user_context_deinit_cb deinit_cb) /**< callback to call to free the user context or - * NULL if it does not need to be freed */ + jerry_user_context_init_t init_cb, /**< callback to call to create the user context or + * NULL, in which case no user context will be + * created */ + jerry_user_context_deinit_t deinit_cb) /**< callback to call to free the user context or + * NULL if it does not need to be freed */ { jerry_init (flags); JERRY_CONTEXT (user_context_p) = (init_cb ? init_cb () : NULL); @@ -956,7 +964,7 @@ jerry_create_external_function (jerry_external_handler_t handler_p) /**< pointer { jerry_assert_api_available (); - ecma_object_t *func_obj_p = ecma_op_create_external_function_object ((ecma_external_pointer_t) handler_p); + ecma_object_t *func_obj_p = ecma_op_create_external_function_object (handler_p); return ecma_make_object_value (func_obj_p); } /* jerry_create_external_function */ @@ -2076,7 +2084,7 @@ jerry_get_object_native_pointer (const jerry_value_t obj_val, /**< object to get if (out_native_info_p) { - *out_native_info_p = (const jerry_object_native_info_t *) native_pointer_p->info_p; + *out_native_info_p = (const jerry_object_native_info_t *) native_pointer_p->u.info_p; } return true; diff --git a/jerry-core/debugger/jerry-debugger-ws.c b/jerry-core/debugger/jerry-debugger-ws.c index 29e3603c4..5d16b00d8 100644 --- a/jerry-core/debugger/jerry-debugger-ws.c +++ b/jerry-core/debugger/jerry-debugger-ws.c @@ -314,7 +314,7 @@ jerry_debugger_accept_connection (void) struct sockaddr_in addr; socklen_t sin_size = sizeof (struct sockaddr_in); - JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER); + JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & ECMA_INIT_DEBUGGER); addr.sin_family = AF_INET; addr.sin_port = htons (JERRY_DEBUGGER_PORT); diff --git a/jerry-core/ecma/base/ecma-gc.c b/jerry-core/ecma/base/ecma-gc.c index e08ea0d98..3160dd36b 100644 --- a/jerry-core/ecma/base/ecma-gc.c +++ b/jerry-core/ecma/base/ecma-gc.c @@ -408,22 +408,20 @@ ecma_gc_free_native_pointer (ecma_property_t *property_p, /**< property */ if (id == LIT_INTERNAL_MAGIC_STRING_NATIVE_HANDLE) { - if (native_pointer_p->info_p != NULL) + if (native_pointer_p->u.callback_p != NULL) { - ecma_external_pointer_t freecb_p = (ecma_external_pointer_t) native_pointer_p->info_p; - ((jerry_object_free_callback_t) freecb_p) ((uintptr_t) native_pointer_p->data_p); + native_pointer_p->u.callback_p ((uintptr_t) native_pointer_p->data_p); } } else { - if (native_pointer_p->info_p != NULL) + if (native_pointer_p->u.info_p != NULL) { - jerry_object_free_callback_t free_cb; - free_cb = (jerry_object_free_callback_t) ((const jerry_object_native_info_t *) native_pointer_p->info_p)->free_cb; + ecma_object_native_free_callback_t free_cb = native_pointer_p->u.info_p->free_cb; if (free_cb != NULL) { - free_cb ((uintptr_t) native_pointer_p->data_p); + free_cb (native_pointer_p->data_p); } } } diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h index a1353e659..e2f0b8757 100644 --- a/jerry-core/ecma/base/ecma-globals.h +++ b/jerry-core/ecma/base/ecma-globals.h @@ -53,6 +53,19 @@ * @} */ +/** + * JerryScript init flags. + */ +typedef enum +{ + ECMA_INIT_EMPTY = (0u), /**< empty flag set */ + ECMA_INIT_SHOW_OPCODES = (1u << 0), /**< dump byte-code to log after parse */ + ECMA_INIT_SHOW_REGEXP_OPCODES = (1u << 1), /**< dump regexp byte-code to log after compilation */ + ECMA_INIT_MEM_STATS = (1u << 2), /**< dump memory statistics */ + ECMA_INIT_MEM_STATS_SEPARATE = (1u << 3), /**< dump memory statistics and reset peak values after parse */ + ECMA_INIT_DEBUGGER = (1u << 4), /**< enable all features required by debugging */ +} ecma_init_flag_t; + /** * Type of ecma value */ @@ -195,13 +208,53 @@ typedef int32_t ecma_integer_value_t; */ typedef uintptr_t ecma_external_pointer_t; +/** + * Callback which tells whether the ECMAScript execution should be stopped. + */ +typedef ecma_value_t (*ecma_vm_exec_stop_callback_t) (void *user_p); + +/** + * Function type for user context deallocation + */ +typedef void (*ecma_user_context_deinit_t) (void *user_context_p); + +/** + * Type of an external function handler. + */ +typedef ecma_value_t (*ecma_external_handler_t) (const ecma_value_t function_obj, + const ecma_value_t this_val, + const ecma_value_t args_p[], + const ecma_length_t args_count); + +/** + * Native free callback of an object (deprecated). + */ +typedef void (*ecma_object_free_callback_t) (const uintptr_t native_p); + +/** + * Native free callback of an object. + */ +typedef void (*ecma_object_native_free_callback_t) (void *native_p); + +/** + * Type information of a native pointer. + */ +typedef struct +{ + ecma_object_native_free_callback_t free_cb; /**< the free callback of the native pointer */ +} ecma_object_native_info_t; + /** * Representation for native pointer data. */ typedef struct { void *data_p; /**< points to the data of the object */ - void *info_p; /**< free info or callback */ + union + { + ecma_object_free_callback_t callback_p; /**< callback */ + ecma_object_native_info_t *info_p; /**< native info */ + } u; } ecma_native_pointer_t; /** @@ -720,7 +773,7 @@ typedef struct ecma_length_t args_length; /**< length of arguments */ } bound_function; - ecma_external_pointer_t external_function; /**< external function */ + ecma_external_handler_t external_handler_cb; /**< external function */ } u; } ecma_extended_object_t; diff --git a/jerry-core/ecma/base/ecma-helpers-external-pointers.c b/jerry-core/ecma/base/ecma-helpers-external-pointers.c index bd81ec35f..6a5ad2b56 100644 --- a/jerry-core/ecma/base/ecma-helpers-external-pointers.c +++ b/jerry-core/ecma/base/ecma-helpers-external-pointers.c @@ -72,7 +72,7 @@ ecma_create_native_property (ecma_object_t *obj_p, /**< object to create propert JERRY_ASSERT (ECMA_STRING_IS_REF_EQUALS_TO_ONE (&name)); native_pointer_p->data_p = data_p; - native_pointer_p->info_p = info_p; + native_pointer_p->u.info_p = info_p; return is_new; } /* ecma_create_native_property */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c b/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c index f8e4ca4ed..3438bde28 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-promise.c @@ -496,7 +496,7 @@ ecma_builtin_promise_do_all (ecma_value_t array, /**< the array for all */ /* k. */ ecma_object_t *res_ele_p; - res_ele_p = ecma_op_create_external_function_object ((ecma_external_pointer_t) ecma_builtin_promise_all_handler); + res_ele_p = ecma_op_create_external_function_object (ecma_builtin_promise_all_handler); /* l. */ ecma_op_object_put (res_ele_p, str_already_called, diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index ff0f9ccf1..a5a1b4f2a 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -310,7 +310,7 @@ ecma_op_function_try_lazy_instantiate_property (ecma_object_t *object_p, /**< th * @return pointer to newly created external function object */ ecma_object_t * -ecma_op_create_external_function_object (ecma_external_pointer_t code_p) /**< pointer to external native handler */ +ecma_op_create_external_function_object (ecma_external_handler_t handler_cb) /**< pointer to external native handler */ { ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE); @@ -328,7 +328,7 @@ ecma_op_create_external_function_object (ecma_external_pointer_t code_p) /**< po */ ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) function_obj_p; - ext_func_obj_p->u.external_function = code_p; + ext_func_obj_p->u.external_handler_cb = handler_cb; ecma_string_t *magic_string_prototype_p = ecma_get_magic_string (LIT_MAGIC_STRING_PROTOTYPE); ecma_builtin_helper_def_prop (function_obj_p, @@ -536,12 +536,11 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */ else if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION) { ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p; - jerry_external_handler_t handler_p = (jerry_external_handler_t) ext_func_obj_p->u.external_function; - ret_value = handler_p (ecma_make_object_value (func_obj_p), - this_arg_value, - arguments_list_p, - arguments_list_len); + ret_value = ext_func_obj_p->u.external_handler_cb (ecma_make_object_value (func_obj_p), + this_arg_value, + arguments_list_p, + arguments_list_len); } else { diff --git a/jerry-core/ecma/operations/ecma-function-object.h b/jerry-core/ecma/operations/ecma-function-object.h index 84ca80935..a52c5b193 100644 --- a/jerry-core/ecma/operations/ecma-function-object.h +++ b/jerry-core/ecma/operations/ecma-function-object.h @@ -42,7 +42,7 @@ ecma_property_t * ecma_op_function_try_lazy_instantiate_property (ecma_object_t *object_p, ecma_string_t *property_name_p); ecma_object_t * -ecma_op_create_external_function_object (ecma_external_pointer_t code_p); +ecma_op_create_external_function_object (ecma_external_handler_t handler_cb); ecma_value_t ecma_op_function_call (ecma_object_t *func_obj_p, ecma_value_t this_arg_value, diff --git a/jerry-core/ecma/operations/ecma-promise-object.c b/jerry-core/ecma/operations/ecma-promise-object.c index 321e351d8..1b4abe579 100644 --- a/jerry-core/ecma/operations/ecma-promise-object.c +++ b/jerry-core/ecma/operations/ecma-promise-object.c @@ -416,7 +416,7 @@ ecma_promise_create_resolving_functions (ecma_object_t *object_p) /**< the promi ecma_init_ecma_magic_string (&str_already_resolved, LIT_INTERNAL_MAGIC_STRING_ALREADY_RESOLVED); /* 2. */ ecma_object_t *resolve_p; - resolve_p = ecma_op_create_external_function_object ((ecma_external_pointer_t) ecma_promise_resolve_handler); + resolve_p = ecma_op_create_external_function_object (ecma_promise_resolve_handler); /* 3. */ ecma_op_object_put (resolve_p, @@ -430,7 +430,7 @@ ecma_promise_create_resolving_functions (ecma_object_t *object_p) /**< the promi false); /* 5. */ ecma_object_t *reject_p; - reject_p = ecma_op_create_external_function_object ((ecma_external_pointer_t) ecma_promise_reject_handler); + reject_p = ecma_op_create_external_function_object (ecma_promise_reject_handler); /* 6. */ ecma_op_object_put (reject_p, &str_promise, diff --git a/jerry-core/include/jerryscript-core.h b/jerry-core/include/jerryscript-core.h index 0024b0ca1..0c9a3001b 100644 --- a/jerry-core/include/jerryscript-core.h +++ b/jerry-core/include/jerryscript-core.h @@ -198,12 +198,12 @@ typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_na /** * Function type for user context allocation */ -typedef void *(*jerry_user_context_init_cb) (void); +typedef void *(*jerry_user_context_init_t) (void); /** * Function type for user context deallocation */ -typedef void (*jerry_user_context_deinit_cb) (void *user_context_p); +typedef void (*jerry_user_context_deinit_t) (void *user_context_p); /** * Type information of a native pointer. @@ -218,8 +218,8 @@ typedef struct */ void jerry_init (jerry_init_flag_t flags); void jerry_init_with_user_context (jerry_init_flag_t flags, - jerry_user_context_init_cb init_cb, - jerry_user_context_deinit_cb deinit_cb); + jerry_user_context_init_t init_cb, + jerry_user_context_deinit_t deinit_cb); void jerry_cleanup (void); void jerry_register_magic_strings (const jerry_char_ptr_t *ex_str_items_p, uint32_t count, const jerry_length_t *str_lengths_p); diff --git a/jerry-core/jcontext/jcontext.h b/jerry-core/jcontext/jcontext.h index 32f49b32f..16342ce47 100644 --- a/jerry-core/jcontext/jcontext.h +++ b/jerry-core/jcontext/jcontext.h @@ -62,7 +62,7 @@ typedef struct ecma_object_t *ecma_global_lex_env_p; /**< global lexical environment */ vm_frame_ctx_t *vm_top_context_p; /**< top (current) interpreter context */ void *user_context_p; /**< user-provided context-specific pointer */ - jerry_user_context_deinit_cb user_context_deinit_cb; /**< user-provided deleter for context-specific pointer */ + ecma_user_context_deinit_t user_context_deinit_cb; /**< user-provided deleter for context-specific pointer */ 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 */ @@ -88,8 +88,8 @@ typedef struct uint32_t vm_exec_stop_frequency; /**< reset value for vm_exec_stop_counter */ uint32_t vm_exec_stop_counter; /**< down counter for reducing the calls of vm_exec_stop_cb */ void *vm_exec_stop_user_p; /**< user pointer for vm_exec_stop_cb */ - jerry_vm_exec_stop_callback_t vm_exec_stop_cb; /**< user function which returns whether the - * ECMAScript execution should be stopped */ + ecma_vm_exec_stop_callback_t vm_exec_stop_cb; /**< user function which returns whether the + * ECMAScript execution should be stopped */ #endif /* JERRY_VM_EXEC_STOP */ #ifdef JERRY_DEBUGGER diff --git a/jerry-core/jmem/jmem-allocator.c b/jerry-core/jmem/jmem-allocator.c index a99dc19c5..a3400b924 100644 --- a/jerry-core/jmem/jmem-allocator.c +++ b/jerry-core/jmem/jmem-allocator.c @@ -42,7 +42,7 @@ jmem_finalize (void) jmem_pools_finalize (); #ifdef JMEM_STATS - if (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_MEM_STATS) + if (JERRY_CONTEXT (jerry_init_flags) & ECMA_INIT_MEM_STATS) { jmem_stats_print (); } diff --git a/jerry-core/jrt/jrt.h b/jerry-core/jrt/jrt.h index c667a0dc4..583d3136a 100644 --- a/jerry-core/jrt/jrt.h +++ b/jerry-core/jrt/jrt.h @@ -19,7 +19,6 @@ #include #include -#include "jerryscript.h" #include "jerryscript-port.h" #include "jrt-types.h" diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index cd15cfdf0..0bc933558 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -1901,7 +1901,7 @@ parser_parse_source (const uint8_t *source_p, /**< valid UTF-8 source code */ #endif /* !JERRY_NDEBUG */ #ifdef PARSER_DUMP_BYTE_CODE - context.is_show_opcodes = (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_SHOW_OPCODES); + context.is_show_opcodes = (JERRY_CONTEXT (jerry_init_flags) & ECMA_INIT_SHOW_OPCODES); context.total_byte_code_size = 0; if (context.is_show_opcodes) diff --git a/jerry-core/parser/regexp/re-compiler.c b/jerry-core/parser/regexp/re-compiler.c index cae945d71..433e88169 100644 --- a/jerry-core/parser/regexp/re-compiler.c +++ b/jerry-core/parser/regexp/re-compiler.c @@ -601,7 +601,7 @@ re_compile_bytecode (const re_compiled_code_t **out_bytecode_p, /**< [out] point else { #ifdef REGEXP_DUMP_BYTE_CODE - if (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_SHOW_REGEXP_OPCODES) + if (JERRY_CONTEXT (jerry_init_flags) & ECMA_INIT_SHOW_REGEXP_OPCODES) { re_dump_bytecode (&bc_ctx); }