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:
@@ -44,9 +44,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
||||
{
|
||||
(void) call_info_p; /* unused */
|
||||
|
||||
const char *const null_str = "\\u0000";
|
||||
|
||||
jerry_value_t ret_val = jerry_create_undefined ();
|
||||
jerry_value_t ret_val = jerry_undefined ();
|
||||
|
||||
for (jerry_length_t arg_index = 0; arg_index < args_cnt; arg_index++)
|
||||
{
|
||||
@@ -54,69 +52,29 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
||||
|
||||
if (jerry_value_is_symbol (args_p[arg_index]))
|
||||
{
|
||||
str_val = jerry_get_symbol_descriptive_string (args_p[arg_index]);
|
||||
str_val = jerry_symbol_descriptive_string (args_p[arg_index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
str_val = jerry_value_to_string (args_p[arg_index]);
|
||||
}
|
||||
|
||||
if (jerry_value_is_error (str_val))
|
||||
if (jerry_value_is_exception (str_val))
|
||||
{
|
||||
/* There is no need to free the undefined value. */
|
||||
ret_val = str_val;
|
||||
break;
|
||||
}
|
||||
|
||||
jerry_length_t length = jerry_get_utf8_string_length (str_val);
|
||||
jerry_length_t substr_pos = 0;
|
||||
jerry_char_t substr_buf[256];
|
||||
|
||||
do
|
||||
if (arg_index > 0)
|
||||
{
|
||||
jerry_size_t substr_size = jerry_substring_to_utf8_char_buffer (str_val, substr_pos, length, substr_buf, 256 - 1);
|
||||
jerry_port_print_char (' ');
|
||||
}
|
||||
|
||||
jerry_char_t *buf_end_p = substr_buf + substr_size;
|
||||
|
||||
/* Update start position by the number of utf-8 characters. */
|
||||
for (jerry_char_t *buf_p = substr_buf; buf_p < buf_end_p; buf_p++)
|
||||
{
|
||||
/* Skip intermediate utf-8 octets. */
|
||||
if ((*buf_p & 0xc0) != 0x80)
|
||||
{
|
||||
substr_pos++;
|
||||
}
|
||||
}
|
||||
|
||||
if (substr_pos == length)
|
||||
{
|
||||
*buf_end_p++ = (arg_index < args_cnt - 1) ? ' ' : '\n';
|
||||
}
|
||||
|
||||
for (jerry_char_t *buf_p = substr_buf; buf_p < buf_end_p; buf_p++)
|
||||
{
|
||||
char chr = (char) *buf_p;
|
||||
|
||||
if (chr != '\0')
|
||||
{
|
||||
jerry_port_print_char (chr);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (jerry_size_t null_index = 0; null_str[null_index] != '\0'; null_index++)
|
||||
{
|
||||
jerry_port_print_char (null_str[null_index]);
|
||||
}
|
||||
}
|
||||
} while (substr_pos < length);
|
||||
|
||||
jerry_release_value (str_val);
|
||||
}
|
||||
|
||||
if (args_cnt == 0 || jerry_value_is_error (ret_val))
|
||||
{
|
||||
jerry_port_print_char ('\n');
|
||||
jerry_string_print (str_val);
|
||||
jerry_value_free (str_val);
|
||||
}
|
||||
|
||||
jerry_port_print_char ('\n');
|
||||
return ret_val;
|
||||
} /* jerryx_handler_print */
|
||||
|
||||
Reference in New Issue
Block a user