Rework the public API (#4829)

Related to #4186.

Some notable changes:
  - The term 'Error' now strictly refers to native Error objects defined in
    the ECMA standard, which are ordinary objects. All other uses of
    'error' or 'error reference' where the term refers to a thrown value is
    now called 'exception'.

  - Simplified the naming scheme of many String API functions. These functions
    will now also take an 'encoding' argument to specify the desired
    encoding in which to operate.

  - Removed the substring-copy-to-buffer functions. These functions
    behaved awkwardly, as they use character index to specify the
    start/end positions, and were mostly used incorrectly with byte
    offsets instead. The functionality can still be replicated with
    other functions if necessary.

  - String-to-buffer functions will no longer fail if the buffer is not
    sufficiently large, the string will instead be cropped.

  - Fixed the usage of the '_sz' prefix in many API functions. The term
    'sz' means zero-terminated string in hungarian notation, this was
    used incorrectly in many cases.

  - Renamed most of the public API functions to have shorter, more on-point
    names, rather than the often too long descriptive names. Functions are now
    also grouped by the type of value they operate on, where this makes
    sense.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
Dániel Bátyai
2021-12-06 10:20:09 +01:00
committed by GitHub
parent 81d2319144
commit 9860d66a56
180 changed files with 10738 additions and 11025 deletions
+3 -3
View File
@@ -38,7 +38,7 @@ set(JERRY_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing
set(JERRY_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?")
set(JERRY_SYSTEM_ALLOCATOR OFF CACHE BOOL "Enable system allocator?")
set(JERRY_VALGRIND OFF CACHE BOOL "Enable Valgrind support?")
set(JERRY_VM_EXEC_STOP OFF CACHE BOOL "Enable VM execution stop callback?")
set(JERRY_VM_HALT OFF CACHE BOOL "Enable VM execution stop callback?")
set(JERRY_VM_THROW OFF CACHE BOOL "Enable VM throw callback?")
set(JERRY_GLOBAL_HEAP_SIZE "(512)" CACHE STRING "Size of memory heap, in kilobytes")
set(JERRY_GC_LIMIT "(0)" CACHE STRING "Heap usage limit to trigger garbage collection")
@@ -98,7 +98,7 @@ message(STATUS "JERRY_SNAPSHOT_EXEC " ${JERRY_SNAPSHOT_EXEC} ${JERRY_
message(STATUS "JERRY_SNAPSHOT_SAVE " ${JERRY_SNAPSHOT_SAVE} ${JERRY_SNAPSHOT_SAVE_MESSAGE})
message(STATUS "JERRY_SYSTEM_ALLOCATOR " ${JERRY_SYSTEM_ALLOCATOR})
message(STATUS "JERRY_VALGRIND " ${JERRY_VALGRIND})
message(STATUS "JERRY_VM_EXEC_STOP " ${JERRY_VM_EXEC_STOP})
message(STATUS "JERRY_VM_HALT " ${JERRY_VM_HALT})
message(STATUS "JERRY_VM_THROW " ${JERRY_VM_THROW})
message(STATUS "JERRY_GLOBAL_HEAP_SIZE " ${JERRY_GLOBAL_HEAP_SIZE})
message(STATUS "JERRY_GC_LIMIT " ${JERRY_GC_LIMIT})
@@ -642,7 +642,7 @@ if(JERRY_VALGRIND)
endif()
# Enable VM execution stop callback
jerry_add_define01(JERRY_VM_EXEC_STOP)
jerry_add_define01(JERRY_VM_HALT)
# Enable VM throw callback
jerry_add_define01(JERRY_VM_THROW)
+7 -7
View File
@@ -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;
+32 -55
View File
@@ -33,23 +33,6 @@
#if JERRY_SNAPSHOT_SAVE || JERRY_SNAPSHOT_EXEC
/**
* 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
*
* @return value of the constructed error object
*/
static jerry_value_t
jerry_create_error_from_id (jerry_error_t error_type, /**< type of error */
ecma_error_msg_t msg) /**< ecma_error_msg id of value of 'message' property
* of constructed error object */
{
return jerry_create_error (error_type, (jerry_char_t *) ecma_get_error_utf8 (msg));
} /* jerry_create_error_from_id */
/**
* Get snapshot configuration flags.
*
@@ -159,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))
{
@@ -170,7 +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_from_id (JERRY_ERROR_RANGE, ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE);
globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE));
return 0;
}
@@ -184,7 +167,8 @@ 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_from_id (JERRY_ERROR_RANGE, ECMA_ERR_TAGGED_TEMPLATE_LITERALS);
globals_p->snapshot_error =
jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_TAGGED_TEMPLATE_LITERALS));
return 0;
}
@@ -200,8 +184,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;
}
@@ -222,8 +205,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 */
}
@@ -257,7 +239,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;
}
@@ -331,7 +313,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 */
/**
@@ -354,7 +336,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_from_id (JERRY_ERROR_RANGE, ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE);
globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE));
return 0;
}
@@ -369,7 +351,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
{
/* Regular expression literals are not supported. */
globals_p->snapshot_error =
jerry_create_error_from_id (JERRY_ERROR_RANGE, ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED);
jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED));
return 0;
}
@@ -379,7 +361,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_from_id (JERRY_ERROR_RANGE, ECMA_ERR_SNAPSHOT_BUFFER_SMALL);
globals_p->snapshot_error = jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_SNAPSHOT_BUFFER_SMALL));
return 0;
}
@@ -766,7 +748,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func
if ((generate_snapshot_opts & ~allowed_options) != 0)
{
return jerry_create_error_from_id (JERRY_ERROR_RANGE, ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED);
return jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED));
}
const ecma_compiled_code_t *bytecode_data_p = NULL;
@@ -798,7 +780,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 *) "Unsupported compiled code");
return jerry_throw_sz (JERRY_ERROR_RANGE, ecma_get_error_msg (ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE));
}
snapshot_globals_t globals;
@@ -848,7 +830,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_from_id (JERRY_ERROR_COMMON, ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS);
return jerry_throw_sz (JERRY_ERROR_COMMON, ecma_get_error_msg (ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS));
}
jerry_snapshot_set_offsets (buffer_p + (aligned_header_size / sizeof (uint32_t)),
@@ -872,7 +854,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_get_error_msg (ECMA_ERR_SNAPSHOT_SAVE_DISABLED));
#endif /* JERRY_SNAPSHOT_SAVE */
} /* jerry_generate_snapshot */
@@ -880,7 +862,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
@@ -902,16 +884,15 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
if ((exec_snapshot_opts & ~(allowed_opts)) != 0)
{
ecma_raise_range_error (ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_RANGE,
ecma_get_error_msg (ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED));
}
const uint8_t *snapshot_data_p = (uint8_t *) snapshot_p;
if (snapshot_size <= sizeof (jerry_snapshot_header_t))
{
ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_FORMAT);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_INVALID_SNAPSHOT_FORMAT));
}
const jerry_snapshot_header_t *header_p = (const jerry_snapshot_header_t *) snapshot_data_p;
@@ -919,20 +900,17 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
if (header_p->magic != JERRY_SNAPSHOT_MAGIC || header_p->version != JERRY_SNAPSHOT_VERSION
|| !snapshot_check_global_flags (header_p->global_flags))
{
ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES));
}
if (header_p->lit_table_offset > snapshot_size)
{
ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES));
}
if (func_index >= header_p->number_of_funcs)
{
ecma_raise_range_error (ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_TYPE, ecma_get_error_msg (ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM));
}
JERRY_ASSERT ((header_p->lit_table_offset % sizeof (uint32_t)) == 0);
@@ -944,14 +922,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_STATIC_SNAPSHOTS_ARE_NOT_ENABLED);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_COMMON, ecma_get_error_msg (ECMA_ERR_STATIC_SNAPSHOTS_ARE_NOT_ENABLED));
}
if (exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_COPY_DATA)
{
ecma_raise_common_error (ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY);
return ecma_create_error_reference_from_context ();
return jerry_throw_sz (JERRY_ERROR_COMMON,
ecma_get_error_msg (ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY));
}
}
else
@@ -979,16 +956,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
@@ -1061,7 +1038,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;
@@ -1072,7 +1049,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_get_error_msg (ECMA_ERR_SNAPSHOT_EXEC_DISABLED));
#endif /* JERRY_SNAPSHOT_EXEC */
} /* jerry_exec_snapshot */
+1462 -1483
View File
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -454,9 +454,9 @@
* 0: Disable vm exec stop callback support.
* 1: Enable vm exec stop callback support.
*/
#ifndef JERRY_VM_EXEC_STOP
#define JERRY_VM_EXEC_STOP 0
#endif /* !defined (JERRY_VM_EXEC_STOP) */
#ifndef JERRY_VM_HALT
#define JERRY_VM_HALT 0
#endif /* !defined (JERRY_VM_HALT) */
/**
* Enable/Disable the vm throw callback function.
@@ -690,9 +690,9 @@
#if (JERRY_VALGRIND != 0) && (JERRY_VALGRIND != 1)
#error "Invalid value for 'JERRY_VALGRIND' macro."
#endif /* (JERRY_VALGRIND != 0) && (JERRY_VALGRIND != 1) */
#if (JERRY_VM_EXEC_STOP != 0) && (JERRY_VM_EXEC_STOP != 1)
#error "Invalid value for 'JERRY_VM_EXEC_STOP' macro."
#endif /* (JERRY_VM_EXEC_STOP != 0) && (JERRY_VM_EXEC_STOP != 1) */
#if (JERRY_VM_HALT != 0) && (JERRY_VM_HALT != 1)
#error "Invalid value for 'JERRY_VM_HALT' macro."
#endif /* (JERRY_VM_HALT != 0) && (JERRY_VM_HALT != 1) */
#if (JERRY_VM_THROW != 0) && (JERRY_VM_THROW != 1)
#error "Invalid value for 'JERRY_VM_THROW' macro."
#endif /* (JERRY_VM_THROW != 0) && (JERRY_VM_THROW != 1) */
+10 -3
View File
@@ -31,6 +31,7 @@ ECMA_ERROR_DEF (ECMA_ERR_OBJECT_EXPECTED, "Object expected")
#if JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ARGUMENT, "Invalid argument")
#endif /* JERRY_BUILTIN_ANNEXB && JERRY_BUILTIN_REGEXP */
ECMA_ERROR_DEF (ECMA_ERR_INVALID_ENCODING, "Invalid encoding")
#if JERRY_BUILTIN_REGEXP
ECMA_ERROR_DEF (ECMA_ERR_NOTHING_TO_REPEAT, "Nothing to repeat")
#endif /* JERRY_BUILTIN_REGEXP */
@@ -189,6 +190,9 @@ ECMA_ERROR_DEF (ECMA_ERR_THE_STRUCTURE_IS_CYCLICAL, "The structure is cyclical")
#if JERRY_BUILTIN_REGEXP
ECMA_ERROR_DEF (ECMA_ERR_UNEXPECTED_END_OF_PATTERN, "Unexpected end of pattern")
#endif /* JERRY_BUILTIN_REGEXP */
#if JERRY_SNAPSHOT_SAVE
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE, "Unsupported compiled code")
#endif /* JERRY_SNAPSHOT_SAVE */
#if !(JERRY_BUILTIN_BIGINT)
ECMA_ERROR_DEF (ECMA_ERR_BIGINT_NOT_SUPPORTED, "BigInt support is disabled")
#endif /* !(JERRY_BUILTIN_BIGINT) */
@@ -305,6 +309,9 @@ ECMA_ERROR_DEF (ECMA_ERR_PRIVATE_METHOD_IS_NOT_WRITABLE, "Private method is not
ECMA_ERROR_DEF (ECMA_ERR_RADIX_IS_OUT_OF_RANGE, "Radix must be between 2 and 36")
#endif /* JERRY_BUILTIN_BIGINT \
|| JERRY_BUILTIN_NUMBER */
#if !(JERRY_SNAPSHOT_EXEC)
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_EXEC_DISABLED, "Snapshot execution is disabled")
#endif /* !(JERRY_SNAPSHOT_EXEC) */
#if !(JERRY_BUILTIN_TYPEDARRAY)
ECMA_ERROR_DEF (ECMA_ERR_TYPED_ARRAY_NOT_SUPPORTED, "TypedArray support is disabled")
#endif /* !(JERRY_BUILTIN_TYPEDARRAY) */
@@ -318,6 +325,9 @@ ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_NEXT_IS_NOT_CALLABLE, "Iterator 'next' is not
ECMA_ERROR_DEF (ECMA_ERR_ITERATOR_VALUE_IS_NOT_AN_OBJECT, "Iterator value is not an object")
ECMA_ERROR_DEF (ECMA_ERR_RESOLVE_METHOD_MUST_BE_CALLABLE, "Resolve method must be callable")
#endif /* JERRY_ESNEXT */
#if !(JERRY_SNAPSHOT_SAVE)
ECMA_ERROR_DEF (ECMA_ERR_SNAPSHOT_SAVE_DISABLED, "Snapshot generation is disabled")
#endif /* !(JERRY_SNAPSHOT_SAVE) */
#if !(JERRY_PARSER)
ECMA_ERROR_DEF (ECMA_ERR_PARSER_NOT_SUPPORTED, "Source code parsing is disabled")
#endif /* !(JERRY_PARSER) */
@@ -384,9 +394,6 @@ ECMA_ERROR_DEF (ECMA_ERR_CALLBACK_IS_NOT_CALLABLE, "Callback function is not cal
#if JERRY_BUILTIN_TYPEDARRAY
ECMA_ERROR_DEF (ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED, "Initial value cannot be undefined")
#endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_BUILTIN_REGEXP
ECMA_ERROR_DEF (ECMA_ERR_INPUT_MUST_BE_A_VALID_UTF8_STRING, "Input must be a valid utf8 string")
#endif /* JERRY_BUILTIN_REGEXP */
#if JERRY_BUILTIN_SHAREDARRAYBUFFER
ECMA_ERROR_DEF (ECMA_ERR_INVALID_SHARED_ARRAYBUFFER_LENGTH, "Invalid Shared ArrayBuffer length")
#endif /* JERRY_BUILTIN_SHAREDARRAYBUFFER */
+4 -1
View File
@@ -120,7 +120,6 @@ ECMA_ERR_INCORRECT_RETURN_PROXY_GET_TRAP = "Incorrect value is returned by a Pro
ECMA_ERR_INCORRECT_RETURN_PROXY_SET_TRAP = "Incorrect value is returned by a Proxy 'set' trap"
ECMA_ERR_INFINITY_OR_NAN_CANNOT_BE_CONVERTED_TO_BIGINT = "Infinity or NaN cannot be converted to BigInt"
ECMA_ERR_INITIAL_VALUE_CANNOT_BE_UNDEFINED = "Initial value cannot be undefined"
ECMA_ERR_INPUT_MUST_BE_A_VALID_UTF8_STRING = "Input must be a valid utf8 string"
ECMA_ERR_INVALID_ARRAYBUFFER_LENGTH = "Invalid ArrayBuffer length"
ECMA_ERR_INVALID_JSON_FORMAT = "Invalid JSON format"
ECMA_ERR_INVALID_REGEXP_FLAGS = "Invalid RegExp flags"
@@ -129,6 +128,7 @@ ECMA_ERR_INVALID_TYPEDARRAY_LENGTH = "Invalid TypedArray length"
ECMA_ERR_INVALID_UTF8_CHARACTER = "Invalid UTF8 character"
ECMA_ERR_INVALID_UTF8_CODEPOINT = "Invalid UTF8 codepoint"
ECMA_ERR_INVALID_UTF8_STRING = "Invalid UTF8 string"
ECMA_ERR_INVALID_ENCODING = "Invalid encoding"
ECMA_ERR_INVALID_ARGUMENT = "Invalid argument"
ECMA_ERR_INVALID_ARGUMENT_IS_PASSED_TO_REGEXP_FUNCTION = "Invalid argument is passed to RegExp function"
ECMA_ERR_INVALID_ARGUMENT_TYPE_IN_TOPRIMITIVE = "Invalid argument type in toPrimitive"
@@ -305,7 +305,10 @@ ECMA_ERR_LET_CONST_NOT_INITIALIZED = "Variables declared by let/const must be in
ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE = "Maximum snapshot size reached"
ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED = "Regular expression literals are not supported"
ECMA_ERR_SNAPSHOT_BUFFER_SMALL = "Snapshot buffer too small"
ECMA_ERR_SNAPSHOT_UNSUPPORTED_COMPILED_CODE = "Unsupported compiled code"
ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED = "Unsupported generate snapshot flags specified"
ECMA_ERR_SNAPSHOT_SAVE_DISABLED = "Snapshot generation is disabled"
ECMA_ERR_SNAPSHOT_EXEC_DISABLED = "Snapshot execution is disabled"
ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS = "Cannot allocate memory for literals"
ECMA_ERR_TAGGED_TEMPLATE_LITERALS = "Unsupported feature: tagged template literals"
ECMA_ERR_CONTAINER_NEEDED = "Value is not a Container or Iterator"
+7 -7
View File
@@ -21,15 +21,15 @@
*/
typedef struct
{
lit_utf8_byte_t *text; /* Text of ecma error message. */
char *text; /* Text of ecma error message. */
uint8_t size; /* Size of ecma error message. */
} ecma_error_message_t;
/* Error message texts with size. */
static ecma_error_message_t ecma_error_messages[] JERRY_ATTR_CONST_DATA = {
{ (lit_utf8_byte_t *) "", 0 }, /* ECMA_ERR_EMPTY */
{ "", 0 }, /* ECMA_ERR_EMPTY */
/** @cond doxygen_suppress */
#define ECMA_ERROR_DEF(id, utf8_string) { (lit_utf8_byte_t *) utf8_string, sizeof (utf8_string) - 1 },
#define ECMA_ERROR_DEF(id, string) { string, sizeof (string) - 1 },
#include "ecma-error-messages.inc.h"
#undef ECMA_ERROR_DEF
/** @endcond */
@@ -41,8 +41,8 @@ static ecma_error_message_t ecma_error_messages[] JERRY_ATTR_CONST_DATA = {
*
* @return pointer to zero-terminated ecma error
*/
const lit_utf8_byte_t *
ecma_get_error_utf8 (uint32_t id) /**< ecma error id */
const char *
ecma_get_error_msg (ecma_error_msg_t id) /**< ecma error id */
{
JERRY_ASSERT (id != ECMA_IS_VALID_CONSTRUCTOR);
@@ -51,7 +51,7 @@ ecma_get_error_utf8 (uint32_t id) /**< ecma error id */
#else /* !JERRY_ERROR_MESSAGES */
return NULL;
#endif /* JERRY_ERROR_MESSAGES */
} /* ecma_get_error_utf8 */
} /* ecma_get_error_msg */
/**
* Get size of specified ecma error
@@ -59,7 +59,7 @@ ecma_get_error_utf8 (uint32_t id) /**< ecma error id */
* @return size in bytes
*/
lit_utf8_size_t
ecma_get_error_size (uint32_t id) /**< ecma error id */
ecma_get_error_size (ecma_error_msg_t id) /**< ecma error id */
{
JERRY_ASSERT (id != ECMA_IS_VALID_CONSTRUCTOR);
+2 -2
View File
@@ -33,7 +33,7 @@ typedef enum
ECMA_IS_VALID_CONSTRUCTOR /* used as return value when checking constructor */
} ecma_error_msg_t;
const lit_utf8_byte_t* ecma_get_error_utf8 (uint32_t id);
lit_utf8_size_t ecma_get_error_size (uint32_t id);
const char* ecma_get_error_msg (ecma_error_msg_t id);
lit_utf8_size_t ecma_get_error_size (ecma_error_msg_t id);
#endif /* !ECMA_ERRORS_H */
+2 -2
View File
@@ -1300,7 +1300,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)
{
@@ -1324,7 +1324,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)
{
+8 -8
View File
@@ -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 */
@@ -1763,14 +1763,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.
+69 -299
View File
@@ -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,31 +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
*/
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 */)
{
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);
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 the specified encoding and copy it to the buffer.
* String data will be truncated to fit the buffer.
*
* @return number of bytes copied to the buffer.
*/
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 */
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_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
@@ -1111,295 +1124,55 @@ ecma_string_copy_to_cesu8_buffer (const ecma_string_t *string_p, /**< ecma-strin
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);
}
}
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 */
/**
* 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.
*
* @return number of bytes, actually 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 */
{
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;
}
}
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;
}
}
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)
switch (encoding)
{
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)
case JERRY_ENCODING_CESU8:
{
size = buffer_size;
}
copy_size = JERRY_MIN (string_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)
if (copy_size < string_size)
{
/* Do not copy partial characters */
while ((chars_p[copy_size] & LIT_UTF8_EXTRA_BYTE_MASK) == LIT_UTF8_EXTRA_BYTE_MARKER)
{
copy_size--;
}
}
memcpy (buffer_p, chars_p, copy_size);
break;
}
case JERRY_ENCODING_UTF8:
{
if (string_size == ecma_string_get_length (string_p))
{
copy_size = JERRY_MIN (string_size, buffer_size);
memcpy (buffer_p, chars_p, copy_size);
break;
}
end_p += code_unit_size;
size += code_unit_size;
copy_size = lit_convert_cesu8_string_to_utf8_string (chars_p, string_size, buffer_p, buffer_size);
break;
}
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)
{
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)
default:
{
size = buffer_size;
break;
}
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))
{
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))
{
JERRY_ASSERT (code_unit_size == next_ch_size);
cesu8_str_p += code_unit_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--)
{
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)
{
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;
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;
}
utf8_pos = buffer_p + size;
cesu8_pos += code_unit_size;
}
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 */
/**
+2 -2
View File
@@ -424,10 +424,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
+26 -26
View File
@@ -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)
/**
+12 -24
View File
@@ -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,
@@ -498,15 +486,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);
@@ -520,7 +508,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) */
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
}
+7 -7
View File
@@ -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 @@ restart:
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;
}
+2 -2
View File
@@ -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);
@@ -255,7 +255,7 @@ ecma_builtin_async_from_sync_iterator_prototype_do (ecma_async_from_sync_iterato
ecma_free_value (call_result);
#if JERRY_ERROR_MESSAGES
const lit_utf8_byte_t *msg_p = ecma_get_error_utf8 (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT);
const lit_utf8_byte_t *msg_p = (lit_utf8_byte_t *) ecma_get_error_msg (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT);
lit_utf8_size_t msg_size = ecma_get_error_size (ECMA_ERR_ARGUMENT_IS_NOT_AN_OBJECT);
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_ascii (msg_p, msg_size);
#else /* !JERRY_ERROR_MESSAGES */
@@ -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;
@@ -54,11 +54,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;
@@ -80,9 +81,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);
@@ -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));
@@ -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));
@@ -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;
+9 -8
View File
@@ -300,13 +300,14 @@ ecma_get_error_type (ecma_object_t *error_object_p) /**< possible error object *
*/
ecma_value_t
ecma_raise_standard_error (jerry_error_t error_type, /**< error type */
const lit_utf8_byte_t *msg_p) /**< error message */
const char *msg_p) /**< error message */
{
ecma_object_t *error_obj_p;
const lit_utf8_byte_t *str_p = (lit_utf8_byte_t *) msg_p;
if (msg_p != NULL)
{
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_utf8 (msg_p, lit_zt_utf8_string_size (msg_p));
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_utf8 (str_p, lit_zt_utf8_string_size (str_p));
error_obj_p = ecma_new_standard_error (error_type, error_msg_p);
ecma_deref_ecma_string (error_msg_p);
}
@@ -416,7 +417,7 @@ ecma_raise_standard_error_with_format (jerry_error_t error_type, /**< error type
ecma_value_t
ecma_raise_common_error (ecma_error_msg_t msg) /**< error message */
{
return ecma_raise_standard_error (JERRY_ERROR_COMMON, ecma_get_error_utf8 (msg));
return ecma_raise_standard_error (JERRY_ERROR_COMMON, ecma_get_error_msg (msg));
} /* ecma_raise_common_error */
/**
@@ -430,7 +431,7 @@ ecma_raise_common_error (ecma_error_msg_t msg) /**< error message */
ecma_value_t
ecma_raise_range_error (ecma_error_msg_t msg) /**< error message */
{
return ecma_raise_standard_error (JERRY_ERROR_RANGE, ecma_get_error_utf8 (msg));
return ecma_raise_standard_error (JERRY_ERROR_RANGE, ecma_get_error_msg (msg));
} /* ecma_raise_range_error */
/**
@@ -444,7 +445,7 @@ ecma_raise_range_error (ecma_error_msg_t msg) /**< error message */
ecma_value_t
ecma_raise_reference_error (ecma_error_msg_t msg) /**< error message */
{
return ecma_raise_standard_error (JERRY_ERROR_REFERENCE, ecma_get_error_utf8 (msg));
return ecma_raise_standard_error (JERRY_ERROR_REFERENCE, ecma_get_error_msg (msg));
} /* ecma_raise_reference_error */
/**
@@ -458,7 +459,7 @@ ecma_raise_reference_error (ecma_error_msg_t msg) /**< error message */
ecma_value_t
ecma_raise_syntax_error (ecma_error_msg_t msg) /**< error message */
{
return ecma_raise_standard_error (JERRY_ERROR_SYNTAX, ecma_get_error_utf8 (msg));
return ecma_raise_standard_error (JERRY_ERROR_SYNTAX, ecma_get_error_msg (msg));
} /* ecma_raise_syntax_error */
/**
@@ -472,7 +473,7 @@ ecma_raise_syntax_error (ecma_error_msg_t msg) /**< error message */
ecma_value_t
ecma_raise_type_error (ecma_error_msg_t msg) /**< error message */
{
return ecma_raise_standard_error (JERRY_ERROR_TYPE, ecma_get_error_utf8 (msg));
return ecma_raise_standard_error (JERRY_ERROR_TYPE, ecma_get_error_msg (msg));
} /* ecma_raise_type_error */
/**
@@ -486,7 +487,7 @@ ecma_raise_type_error (ecma_error_msg_t msg) /**< error message */
ecma_value_t
ecma_raise_uri_error (ecma_error_msg_t msg) /**< error message */
{
return ecma_raise_standard_error (JERRY_ERROR_URI, ecma_get_error_utf8 (msg));
return ecma_raise_standard_error (JERRY_ERROR_URI, ecma_get_error_msg (msg));
} /* ecma_raise_uri_error */
#if (JERRY_STACK_LIMIT != 0)
+1 -1
View File
@@ -32,7 +32,7 @@ ecma_object_t *ecma_new_standard_error (jerry_error_t error_type, ecma_string_t
#if JERRY_ERROR_MESSAGES
ecma_value_t ecma_raise_standard_error_with_format (jerry_error_t error_type, const char *msg_p, ...);
#endif /* JERRY_ERROR_MESSAGES */
ecma_value_t ecma_raise_standard_error (jerry_error_t error_type, const lit_utf8_byte_t *msg_p);
ecma_value_t ecma_raise_standard_error (jerry_error_t error_type, const char *msg_p);
ecma_value_t ecma_raise_common_error (ecma_error_msg_t msg);
ecma_value_t ecma_raise_range_error (ecma_error_msg_t msg);
ecma_value_t ecma_raise_reference_error (ecma_error_msg_t msg);
@@ -1287,9 +1287,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;
}
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -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);
+4 -4
View File
@@ -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 */
+90 -93
View File
@@ -24,25 +24,11 @@
JERRY_C_API_BEGIN
/** \addtogroup jerry Jerry engine interface
/**
* @defgroup 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.
*/
@@ -52,8 +38,6 @@ typedef enum
JERRY_INIT_SHOW_OPCODES = (1u << 0), /**< dump byte-code to log after parse */
JERRY_INIT_SHOW_REGEXP_OPCODES = (1u << 1), /**< dump regexp byte-code to log after compilation */
JERRY_INIT_MEM_STATS = (1u << 2), /**< dump memory statistics */
JERRY_INIT_MEM_STATS_SEPARATE = (1u << 3), /**< deprecated, an unused placeholder now */
JERRY_INIT_DEBUGGER = (1u << 4), /**< deprecated, an unused placeholder now */
} jerry_init_flag_t;
/**
@@ -81,7 +65,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 +151,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 +164,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 +229,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 +271,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 +281,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_vm_throw_callback_t) (const jerry_value_t error_value, void *user_p);
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_string_iterate_cb_t) (uint8_t byte, void *user_p);
/**
* Function type applied for each data property of an object.
*/
typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name,
const jerry_value_t property_value,
void *user_data_p);
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 +346,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 +379,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 +387,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 +422,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_frame_t definition.
*/
struct jerry_frame_internal_t;
/**
* Internal data structure for jerry_backtrace_frame_t definition.
* Backtrace frame data passed to the jerry_backtrace_cb_t handler.
*/
struct jerry_backtrace_frame_internal_t;
typedef struct jerry_frame_internal_t jerry_frame_t;
/**
* Backtrace frame data passed to the jerry_backtrace_callback_t handler.
* Callback function which is called by jerry_backtrace for each stack frame.
*/
typedef struct jerry_backtrace_frame_internal_t jerry_backtrace_frame_t;
/**
* Callback function which is called by jerry_backtrace_capture 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 +478,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 +497,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 +551,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 +563,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 +608,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 +626,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 +677,7 @@ typedef enum
} jerry_promise_event_type_t;
/**
* Filter types for jerry_promise_set_callback callback function.
* Filter types for jerry_promise_on_event callback function.
* The callback is only called for those events which are enabled by the filters.
*/
typedef enum
@@ -712,7 +709,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 +785,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 +830,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);
/**
* @}
+15
View File
@@ -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"
+15 -15
View File
@@ -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,30 +194,30 @@ 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
* arraybuffer memory */
jerry_arraybuffer_free_t arraybuffer_free_callback; /**< callback for freeing arraybuffer memory */
jerry_arraybuffer_allocate_cb_t arraybuffer_allocate_callback; /**< callback for allocating
* 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 */
#if JERRY_VM_EXEC_STOP
#if JERRY_VM_HALT
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 */
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 */
#endif /* JERRY_VM_HALT */
#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)
+4 -4
View File
@@ -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__) */
+26 -32
View File
@@ -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 */
/**
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -982,7 +982,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 */
+10 -10
View File
@@ -2109,18 +2109,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 */
@@ -2263,7 +2263,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);
@@ -2431,7 +2431,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)
@@ -2515,7 +2515,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);
@@ -3361,7 +3361,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_PARSER_NOT_SUPPORTED);
return NULL;
+3 -3
View File
@@ -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 */
};
+3 -3
View File
@@ -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);
+7 -7
View File
@@ -1112,7 +1112,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
if (opcode_data & VM_OC_BACKWARD_BRANCH)
{
#if JERRY_VM_EXEC_STOP
#if JERRY_VM_HALT
if (JERRY_CONTEXT (vm_exec_stop_cb) != NULL && --JERRY_CONTEXT (vm_exec_stop_counter) == 0)
{
result = JERRY_CONTEXT (vm_exec_stop_cb) (JERRY_CONTEXT (vm_exec_stop_user_p));
@@ -1125,9 +1125,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
{
@@ -1140,7 +1140,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
goto error;
}
}
#endif /* JERRY_VM_EXEC_STOP */
#endif /* JERRY_VM_HALT */
branch_offset = -branch_offset;
}
@@ -3819,7 +3819,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
if (ecma_are_values_integer_numbers (left_value, right_value))
{
bool is_less = (ecma_integer_value_t) left_value < (ecma_integer_value_t) right_value;
#if !JERRY_VM_EXEC_STOP
#if !JERRY_VM_HALT
/* This is a lookahead to the next opcode to improve performance.
* If it is CBC_BRANCH_IF_TRUE_BACKWARD, execute it. */
if (*byte_code_p <= CBC_BRANCH_IF_TRUE_BACKWARD_3 && *byte_code_p >= CBC_BRANCH_IF_TRUE_BACKWARD)
@@ -3853,7 +3853,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
continue;
}
#endif /* !JERRY_VM_EXEC_STOP */
#endif /* !JERRY_VM_HALT */
*stack_top_p++ = ecma_make_boolean_value (is_less);
continue;
}
@@ -4842,7 +4842,7 @@ error:
{
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)
{