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:
+18
-18
@@ -35,11 +35,11 @@ jerryx_arg_transform_args (const jerry_value_t *js_arg_p, /**< points to the arr
|
||||
const jerryx_arg_t *c_arg_p, /**< points to the array of validation/transformation steps */
|
||||
jerry_length_t c_arg_cnt) /**< the count of the `c_arg_p` array */
|
||||
{
|
||||
jerry_value_t ret = jerry_create_undefined ();
|
||||
jerry_value_t ret = jerry_undefined ();
|
||||
|
||||
jerryx_arg_js_iterator_t iterator = { .js_arg_p = js_arg_p, .js_arg_cnt = js_arg_cnt, .js_arg_idx = 0 };
|
||||
|
||||
for (; c_arg_cnt != 0 && !jerry_value_is_error (ret); c_arg_cnt--, c_arg_p++)
|
||||
for (; c_arg_cnt != 0 && !jerry_value_is_exception (ret); c_arg_cnt--, c_arg_p++)
|
||||
{
|
||||
ret = c_arg_p->func (&iterator, c_arg_p);
|
||||
}
|
||||
@@ -66,18 +66,18 @@ jerryx_arg_transform_this_and_args (const jerry_value_t this_val, /**< the this_
|
||||
{
|
||||
if (c_arg_cnt == 0)
|
||||
{
|
||||
return jerry_create_undefined ();
|
||||
return jerry_undefined ();
|
||||
}
|
||||
|
||||
jerryx_arg_js_iterator_t iterator = { .js_arg_p = &this_val, .js_arg_cnt = 1, .js_arg_idx = 0 };
|
||||
|
||||
jerry_value_t ret = c_arg_p->func (&iterator, c_arg_p);
|
||||
|
||||
if (jerry_value_is_error (ret))
|
||||
if (jerry_value_is_exception (ret))
|
||||
{
|
||||
jerry_release_value (ret);
|
||||
jerry_value_free (ret);
|
||||
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "'this' validation failed.");
|
||||
return jerry_throw_sz (JERRY_ERROR_TYPE, "'this' validation failed.");
|
||||
}
|
||||
|
||||
return jerryx_arg_transform_args (js_arg_p, js_arg_cnt, c_arg_p + 1, c_arg_cnt - 1);
|
||||
@@ -99,22 +99,22 @@ jerryx_arg_transform_object_properties (const jerry_value_t obj_val, /**< the JS
|
||||
{
|
||||
if (!jerry_value_is_object (obj_val))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Not an object.");
|
||||
return jerry_throw_sz (JERRY_ERROR_TYPE, "Not an object.");
|
||||
}
|
||||
|
||||
JERRY_VLA (jerry_value_t, prop, name_cnt);
|
||||
|
||||
for (jerry_length_t i = 0; i < name_cnt; i++, name_p++)
|
||||
{
|
||||
const jerry_value_t name_str = jerry_create_string (*name_p);
|
||||
prop[i] = jerry_get_property (obj_val, name_str);
|
||||
jerry_release_value (name_str);
|
||||
const jerry_value_t name_str = jerry_string_sz ((char *) (*name_p));
|
||||
prop[i] = jerry_object_get (obj_val, name_str);
|
||||
jerry_value_free (name_str);
|
||||
|
||||
if (jerry_value_is_error (prop[i]))
|
||||
if (jerry_value_is_exception (prop[i]))
|
||||
{
|
||||
for (jerry_length_t j = 0; j < i; j++)
|
||||
{
|
||||
jerry_release_value (prop[j]);
|
||||
jerry_value_free (prop[j]);
|
||||
}
|
||||
|
||||
return prop[i];
|
||||
@@ -125,7 +125,7 @@ jerryx_arg_transform_object_properties (const jerry_value_t obj_val, /**< the JS
|
||||
|
||||
for (jerry_length_t i = 0; i < name_cnt; i++)
|
||||
{
|
||||
jerry_release_value (prop[i]);
|
||||
jerry_value_free (prop[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -144,20 +144,20 @@ jerryx_arg_transform_array (const jerry_value_t array_val, /**< points to the JS
|
||||
{
|
||||
if (!jerry_value_is_array (array_val))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Not an array.");
|
||||
return jerry_throw_sz (JERRY_ERROR_TYPE, "Not an array.");
|
||||
}
|
||||
|
||||
JERRY_VLA (jerry_value_t, arr, c_arg_cnt);
|
||||
|
||||
for (jerry_length_t i = 0; i < c_arg_cnt; i++)
|
||||
{
|
||||
arr[i] = jerry_get_property_by_index (array_val, i);
|
||||
arr[i] = jerry_object_get_index (array_val, i);
|
||||
|
||||
if (jerry_value_is_error (arr[i]))
|
||||
if (jerry_value_is_exception (arr[i]))
|
||||
{
|
||||
for (jerry_length_t j = 0; j < i; j++)
|
||||
{
|
||||
jerry_release_value (arr[j]);
|
||||
jerry_value_free (arr[j]);
|
||||
}
|
||||
|
||||
return arr[i];
|
||||
@@ -168,7 +168,7 @@ jerryx_arg_transform_array (const jerry_value_t array_val, /**< points to the JS
|
||||
|
||||
for (jerry_length_t i = 0; i < c_arg_cnt; i++)
|
||||
{
|
||||
jerry_release_value (arr[i]);
|
||||
jerry_value_free (arr[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user