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:
@@ -27,10 +27,10 @@ vm_exec_stop_callback (void *user_p)
|
||||
{
|
||||
(*int_p)--;
|
||||
|
||||
return jerry_create_undefined ();
|
||||
return jerry_undefined ();
|
||||
}
|
||||
|
||||
return jerry_create_string ((const jerry_char_t *) "Abort script");
|
||||
return jerry_string_sz ("Abort script");
|
||||
} /* vm_exec_stop_callback */
|
||||
|
||||
int
|
||||
@@ -39,7 +39,7 @@ main (void)
|
||||
TEST_INIT ();
|
||||
|
||||
/* Test stopping an infinite loop. */
|
||||
if (!jerry_is_feature_enabled (JERRY_FEATURE_VM_EXEC_STOP))
|
||||
if (!jerry_feature_enabled (JERRY_FEATURE_VM_EXEC_STOP))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -47,19 +47,19 @@ main (void)
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
int countdown = 6;
|
||||
jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);
|
||||
jerry_halt_handler (16, vm_exec_stop_callback, &countdown);
|
||||
|
||||
const jerry_char_t inf_loop_code_src1[] = "while(true) {}";
|
||||
jerry_value_t parsed_code_val = jerry_parse (inf_loop_code_src1, sizeof (inf_loop_code_src1) - 1, NULL);
|
||||
|
||||
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
|
||||
TEST_ASSERT (!jerry_value_is_exception (parsed_code_val));
|
||||
jerry_value_t res = jerry_run (parsed_code_val);
|
||||
TEST_ASSERT (countdown == 0);
|
||||
|
||||
TEST_ASSERT (jerry_value_is_error (res));
|
||||
TEST_ASSERT (jerry_value_is_exception (res));
|
||||
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (parsed_code_val);
|
||||
jerry_value_free (res);
|
||||
jerry_value_free (parsed_code_val);
|
||||
|
||||
/* A more complex example. Although the callback error is captured
|
||||
* by the catch block, it is automatically thrown again. */
|
||||
@@ -72,16 +72,16 @@ main (void)
|
||||
|
||||
parsed_code_val = jerry_parse (inf_loop_code_src2, sizeof (inf_loop_code_src2) - 1, NULL);
|
||||
|
||||
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
|
||||
TEST_ASSERT (!jerry_value_is_exception (parsed_code_val));
|
||||
res = jerry_run (parsed_code_val);
|
||||
TEST_ASSERT (countdown == 0);
|
||||
|
||||
/* The result must have an error flag which proves that
|
||||
* the error is thrown again inside the catch block. */
|
||||
TEST_ASSERT (jerry_value_is_error (res));
|
||||
TEST_ASSERT (jerry_value_is_exception (res));
|
||||
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (parsed_code_val);
|
||||
jerry_value_free (res);
|
||||
jerry_value_free (parsed_code_val);
|
||||
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user