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
@@ -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)
{