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:
@@ -25,8 +25,8 @@ check_eval (const jerry_call_info_t *call_info_p, /**< call information */
|
||||
{
|
||||
JERRY_UNUSED (call_info_p);
|
||||
|
||||
TEST_ASSERT (args_cnt == 2 && jerry_is_eval_code (args_p[0]) == jerry_value_is_true (args_p[1]));
|
||||
return jerry_create_boolean (true);
|
||||
TEST_ASSERT (args_cnt == 2 && jerry_function_is_dynamic (args_p[0]) == jerry_value_is_true (args_p[1]));
|
||||
return jerry_boolean (true);
|
||||
} /* check_eval */
|
||||
|
||||
static void
|
||||
@@ -34,22 +34,22 @@ test_parse (const char *source_p, /**< source code */
|
||||
jerry_parse_options_t *options_p) /**< options passed to jerry_parse */
|
||||
{
|
||||
jerry_value_t parse_result = jerry_parse ((const jerry_char_t *) source_p, strlen (source_p), options_p);
|
||||
TEST_ASSERT (!jerry_value_is_error (parse_result));
|
||||
TEST_ASSERT (!jerry_is_eval_code (parse_result));
|
||||
TEST_ASSERT (!jerry_value_is_exception (parse_result));
|
||||
TEST_ASSERT (!jerry_function_is_dynamic (parse_result));
|
||||
|
||||
jerry_value_t result;
|
||||
|
||||
if (options_p->options & JERRY_PARSE_HAS_ARGUMENT_LIST)
|
||||
{
|
||||
jerry_value_t this_value = jerry_create_undefined ();
|
||||
result = jerry_call_function (parse_result, this_value, NULL, 0);
|
||||
jerry_release_value (this_value);
|
||||
jerry_value_t this_value = jerry_undefined ();
|
||||
result = jerry_call (parse_result, this_value, NULL, 0);
|
||||
jerry_value_free (this_value);
|
||||
}
|
||||
else if (options_p->options & JERRY_PARSE_MODULE)
|
||||
{
|
||||
result = jerry_module_link (parse_result, NULL, NULL);
|
||||
TEST_ASSERT (!jerry_value_is_error (result));
|
||||
jerry_release_value (result);
|
||||
TEST_ASSERT (!jerry_value_is_exception (result));
|
||||
jerry_value_free (result);
|
||||
result = jerry_module_evaluate (parse_result);
|
||||
}
|
||||
else
|
||||
@@ -57,10 +57,10 @@ test_parse (const char *source_p, /**< source code */
|
||||
result = jerry_run (parse_result);
|
||||
}
|
||||
|
||||
TEST_ASSERT (!jerry_value_is_error (result));
|
||||
TEST_ASSERT (!jerry_value_is_exception (result));
|
||||
|
||||
jerry_release_value (parse_result);
|
||||
jerry_release_value (result);
|
||||
jerry_value_free (parse_result);
|
||||
jerry_value_free (result);
|
||||
} /* test_parse */
|
||||
|
||||
int
|
||||
@@ -70,15 +70,15 @@ main (void)
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
jerry_value_t global_object_value = jerry_get_global_object ();
|
||||
jerry_value_t global_object_value = jerry_current_realm ();
|
||||
|
||||
jerry_value_t function_value = jerry_create_external_function (check_eval);
|
||||
jerry_value_t function_name_value = jerry_create_string ((const jerry_char_t *) "check_eval");
|
||||
jerry_release_value (jerry_set_property (global_object_value, function_name_value, function_value));
|
||||
jerry_value_t function_value = jerry_function_external (check_eval);
|
||||
jerry_value_t function_name_value = jerry_string_sz ("check_eval");
|
||||
jerry_value_free (jerry_object_set (global_object_value, function_name_value, function_value));
|
||||
|
||||
jerry_release_value (function_name_value);
|
||||
jerry_release_value (function_value);
|
||||
jerry_release_value (global_object_value);
|
||||
jerry_value_free (function_name_value);
|
||||
jerry_value_free (function_value);
|
||||
jerry_value_free (global_object_value);
|
||||
|
||||
jerry_parse_options_t parse_options;
|
||||
const char *source_p = TEST_STRING_LITERAL ("eval('check_eval(function() {}, true)')\n"
|
||||
@@ -87,23 +87,23 @@ main (void)
|
||||
parse_options.options = JERRY_PARSE_NO_OPTS;
|
||||
test_parse (source_p, &parse_options);
|
||||
|
||||
if (jerry_is_feature_enabled (JERRY_FEATURE_MODULE))
|
||||
if (jerry_feature_enabled (JERRY_FEATURE_MODULE))
|
||||
{
|
||||
parse_options.options = JERRY_PARSE_MODULE;
|
||||
test_parse (source_p, &parse_options);
|
||||
}
|
||||
|
||||
parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST;
|
||||
parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "");
|
||||
parse_options.argument_list = jerry_string_sz ("");
|
||||
test_parse (source_p, &parse_options);
|
||||
jerry_release_value (parse_options.argument_list);
|
||||
jerry_value_free (parse_options.argument_list);
|
||||
|
||||
parse_options.options = JERRY_PARSE_NO_OPTS;
|
||||
source_p = TEST_STRING_LITERAL ("check_eval(new Function('a', 'return a'), true)");
|
||||
test_parse (source_p, &parse_options);
|
||||
|
||||
source_p = TEST_STRING_LITERAL ("check_eval(function() {}, true)");
|
||||
jerry_release_value (jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), JERRY_PARSE_NO_OPTS));
|
||||
jerry_value_free (jerry_eval ((const jerry_char_t *) source_p, strlen (source_p), JERRY_PARSE_NO_OPTS));
|
||||
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user