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:
@@ -23,38 +23,38 @@ main (void)
|
||||
TEST_INIT ();
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL))
|
||||
if (!jerry_feature_enabled (JERRY_FEATURE_SYMBOL))
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ES.next support is disabled\n");
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
jerry_value_t undefined_this_arg = jerry_create_undefined ();
|
||||
jerry_char_t pattern2[] = "\\u{61}.\\u{62}";
|
||||
jerry_value_t undefined_this_arg = jerry_undefined ();
|
||||
char pattern2[] = "\\u{61}.\\u{62}";
|
||||
uint16_t flags = JERRY_REGEXP_FLAG_DOTALL | JERRY_REGEXP_FLAG_UNICODE | JERRY_REGEXP_FLAG_STICKY;
|
||||
jerry_value_t regex_obj = jerry_create_regexp (pattern2, flags);
|
||||
jerry_value_t regex_obj = jerry_regexp_sz (pattern2, flags);
|
||||
TEST_ASSERT (jerry_value_is_object (regex_obj));
|
||||
|
||||
const jerry_char_t func_src2[] = "return [regex.exec('a\\nb'), regex.dotAll, regex.sticky, regex.unicode ];";
|
||||
|
||||
jerry_parse_options_t parse_options;
|
||||
parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST;
|
||||
parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "regex");
|
||||
parse_options.argument_list = jerry_string_sz ("regex");
|
||||
|
||||
jerry_value_t func_val = jerry_parse (func_src2, sizeof (func_src2) - 1, &parse_options);
|
||||
jerry_release_value (parse_options.argument_list);
|
||||
jerry_value_free (parse_options.argument_list);
|
||||
|
||||
jerry_value_t res = jerry_call_function (func_val, undefined_this_arg, ®ex_obj, 1);
|
||||
jerry_value_t regex_res = jerry_get_property_by_index (res, 0);
|
||||
jerry_value_t regex_res_str = jerry_get_property_by_index (regex_res, 0);
|
||||
jerry_value_t is_dotall = jerry_get_property_by_index (res, 1);
|
||||
jerry_value_t is_sticky = jerry_get_property_by_index (res, 2);
|
||||
jerry_value_t is_unicode = jerry_get_property_by_index (res, 3);
|
||||
jerry_value_t res = jerry_call (func_val, undefined_this_arg, ®ex_obj, 1);
|
||||
jerry_value_t regex_res = jerry_object_get_index (res, 0);
|
||||
jerry_value_t regex_res_str = jerry_object_get_index (regex_res, 0);
|
||||
jerry_value_t is_dotall = jerry_object_get_index (res, 1);
|
||||
jerry_value_t is_sticky = jerry_object_get_index (res, 2);
|
||||
jerry_value_t is_unicode = jerry_object_get_index (res, 3);
|
||||
|
||||
jerry_size_t str_size = jerry_get_string_size (regex_res_str);
|
||||
jerry_size_t str_size = jerry_string_size (regex_res_str, JERRY_ENCODING_CESU8);
|
||||
JERRY_VLA (jerry_char_t, res_buff, str_size);
|
||||
jerry_size_t res_size = jerry_string_to_char_buffer (regex_res_str, res_buff, str_size);
|
||||
jerry_size_t res_size = jerry_string_to_buffer (regex_res_str, JERRY_ENCODING_CESU8, res_buff, str_size);
|
||||
|
||||
const char expected_result[] = "a\nb";
|
||||
TEST_ASSERT (res_size == (sizeof (expected_result) - 1));
|
||||
@@ -63,14 +63,14 @@ main (void)
|
||||
TEST_ASSERT (jerry_value_is_true (is_sticky));
|
||||
TEST_ASSERT (jerry_value_is_true (is_unicode));
|
||||
|
||||
jerry_release_value (regex_obj);
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (func_val);
|
||||
jerry_release_value (regex_res);
|
||||
jerry_release_value (regex_res_str);
|
||||
jerry_release_value (is_dotall);
|
||||
jerry_release_value (is_sticky);
|
||||
jerry_release_value (is_unicode);
|
||||
jerry_value_free (regex_obj);
|
||||
jerry_value_free (res);
|
||||
jerry_value_free (func_val);
|
||||
jerry_value_free (regex_res);
|
||||
jerry_value_free (regex_res_str);
|
||||
jerry_value_free (is_dotall);
|
||||
jerry_value_free (is_sticky);
|
||||
jerry_value_free (is_unicode);
|
||||
|
||||
jerry_cleanup ();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user