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:
@@ -30,21 +30,21 @@ error_object_created_callback (const jerry_value_t error_object_t, /**< new erro
|
||||
error_object_created_callback_is_running = true;
|
||||
error_object_created_callback_count++;
|
||||
|
||||
jerry_value_t name = jerry_create_string ((const jerry_char_t *) "message");
|
||||
jerry_value_t message = jerry_create_string ((const jerry_char_t *) "Replaced message!");
|
||||
jerry_value_t name = jerry_string_sz ("message");
|
||||
jerry_value_t message = jerry_string_sz ("Replaced message!");
|
||||
|
||||
jerry_value_t result = jerry_set_property (error_object_t, name, message);
|
||||
jerry_value_t result = jerry_object_set (error_object_t, name, message);
|
||||
TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result));
|
||||
jerry_release_value (result);
|
||||
jerry_value_free (result);
|
||||
|
||||
/* This SyntaxError must not trigger a recusrsive call of the this callback. */
|
||||
const char *source_p = "Syntax Error in JS!";
|
||||
result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0);
|
||||
TEST_ASSERT (jerry_value_is_error (result));
|
||||
TEST_ASSERT (jerry_value_is_exception (result));
|
||||
|
||||
jerry_release_value (result);
|
||||
jerry_release_value (message);
|
||||
jerry_release_value (name);
|
||||
jerry_value_free (result);
|
||||
jerry_value_free (message);
|
||||
jerry_value_free (name);
|
||||
|
||||
error_object_created_callback_is_running = false;
|
||||
} /* error_object_created_callback */
|
||||
@@ -57,7 +57,7 @@ run_test (const char *source_p)
|
||||
{
|
||||
jerry_value_t result = jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), 0);
|
||||
TEST_ASSERT (jerry_value_is_boolean (result) && jerry_value_is_true (result));
|
||||
jerry_release_value (result);
|
||||
jerry_value_free (result);
|
||||
}
|
||||
} /* run_test */
|
||||
|
||||
@@ -71,8 +71,7 @@ main (void)
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
jerry_set_error_object_created_callback (error_object_created_callback,
|
||||
(void *) &error_object_created_callback_count);
|
||||
jerry_error_on_created (error_object_created_callback, (void *) &error_object_created_callback_count);
|
||||
|
||||
run_test ("var result = false\n"
|
||||
"try {\n"
|
||||
@@ -85,7 +84,7 @@ main (void)
|
||||
run_test ("var error = new Error()\n"
|
||||
"error.message === 'Replaced message!'\n");
|
||||
|
||||
jerry_release_value (jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Message"));
|
||||
jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, "Message"));
|
||||
|
||||
TEST_ASSERT (error_object_created_callback_count == 11);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user