Introduce JERRY_ZSTR_ARG macro to avoid jerryx_print_string, jerryx_print_byte, jerry_port_print_byte, strlen (#4982)
Replace usage of jerryx_print_byte, jerryx_print_string with jerryx_print_buffer. As we now have JERRY_ZSTR_ARG, so we can take advantage of it With this, the jerry_port_print_byte port api won't need any more this reduced the port api surface JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
This commit is contained in:
@@ -116,18 +116,6 @@ void jerry_port_context_free (void);
|
|||||||
void jerry_port_log (const char *message_p);
|
void jerry_port_log (const char *message_p);
|
||||||
```
|
```
|
||||||
|
|
||||||
```c
|
|
||||||
/**
|
|
||||||
* Print a single character to standard output.
|
|
||||||
*
|
|
||||||
* This port function is never called from jerry-core directly, it is only used by jerry-ext components to print
|
|
||||||
* information.
|
|
||||||
*
|
|
||||||
* @param byte: the byte to print.
|
|
||||||
*/
|
|
||||||
void jerry_port_print_byte (jerry_char_t byte);
|
|
||||||
```
|
|
||||||
|
|
||||||
```c
|
```c
|
||||||
/**
|
/**
|
||||||
* Print a buffer to standard output
|
* Print a buffer to standard output
|
||||||
|
|||||||
@@ -316,15 +316,14 @@ jerryx_handler_gc (const jerry_call_info_t *call_info_p,
|
|||||||
**Summary**
|
**Summary**
|
||||||
|
|
||||||
Provide a `print` implementation for scripts. The routine converts all of its
|
Provide a `print` implementation for scripts. The routine converts all of its
|
||||||
arguments to strings and outputs them char-by-char using
|
arguments to strings and outputs them by using `jerry_port_print_buffer`.
|
||||||
`jerry_port_print_byte`. The NULL character is output as "\u0000",
|
The NULL character is output as "\u0000", other characters are output bytewise.
|
||||||
other characters are output bytewise.
|
|
||||||
|
|
||||||
*Note*: This implementation does not use standard C `printf` to print its
|
*Note*: This implementation does not use standard C `printf` to print its
|
||||||
output. This allows more flexibility but also extends the core JerryScript
|
output. This allows more flexibility but also extends the core JerryScript
|
||||||
engine port API. Applications that want to use `jerryx_handler_print` must
|
engine port API. Applications that want to use `jerryx_handler_print` must
|
||||||
ensure that their port implementation also provides
|
ensure that their port implementation also provides
|
||||||
`jerry_port_print_byte`.
|
`jerry_port_print_buffer`.
|
||||||
|
|
||||||
**Prototype**
|
**Prototype**
|
||||||
|
|
||||||
@@ -345,7 +344,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p,
|
|||||||
**See also**
|
**See also**
|
||||||
|
|
||||||
- [jerryx_register_global](#jerryx_register_global)
|
- [jerryx_register_global](#jerryx_register_global)
|
||||||
- [jerry_port_print_byte](05.PORT-API.md#jerry_port_print_char)
|
- [jerry_port_print_buffer](05.PORT-API.md#jerry_port_print_buffer)
|
||||||
|
|
||||||
|
|
||||||
# Handler registration helper
|
# Handler registration helper
|
||||||
|
|||||||
@@ -770,3 +770,4 @@ In this section the new API functions are listed.
|
|||||||
- [`jerry_port_get_current_context`](05.PORT-API.md#jerry_port_get_current_context)
|
- [`jerry_port_get_current_context`](05.PORT-API.md#jerry_port_get_current_context)
|
||||||
- [`jerry_port_fatal`](05.PORT-API.md#jerry_port_fatal)
|
- [`jerry_port_fatal`](05.PORT-API.md#jerry_port_fatal)
|
||||||
- [`jerry_port_sleep`](05.PORT-API.md#jerry_port_sleep)
|
- [`jerry_port_sleep`](05.PORT-API.md#jerry_port_sleep)
|
||||||
|
- [`jerry_port_print_byte`](05.PORT-API.md#jerry_port_print_byte)
|
||||||
|
|||||||
@@ -1455,22 +1455,17 @@ jerry_save_literals_sort (ecma_string_t *literals[], /**< array of literals */
|
|||||||
static uint8_t *
|
static uint8_t *
|
||||||
jerry_append_chars_to_buffer (uint8_t *buffer_p, /**< buffer */
|
jerry_append_chars_to_buffer (uint8_t *buffer_p, /**< buffer */
|
||||||
uint8_t *buffer_end_p, /**< the end of the buffer */
|
uint8_t *buffer_end_p, /**< the end of the buffer */
|
||||||
const char *chars, /**< string */
|
const jerry_char_t *chars, /**< string */
|
||||||
lit_utf8_size_t string_size) /**< string size */
|
jerry_size_t string_size) /**< string size */
|
||||||
{
|
{
|
||||||
if (buffer_p > buffer_end_p)
|
if (buffer_p > buffer_end_p)
|
||||||
{
|
{
|
||||||
return buffer_p;
|
return buffer_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string_size == 0)
|
|
||||||
{
|
|
||||||
string_size = (lit_utf8_size_t) strlen (chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer_p + string_size <= buffer_end_p)
|
if (buffer_p + string_size <= buffer_end_p)
|
||||||
{
|
{
|
||||||
memcpy ((char *) buffer_p, chars, string_size);
|
memcpy ((char *) buffer_p, (const char *) chars, string_size);
|
||||||
|
|
||||||
return buffer_p + string_size;
|
return buffer_p + string_size;
|
||||||
}
|
}
|
||||||
@@ -1492,8 +1487,10 @@ jerry_append_ecma_string_to_buffer (uint8_t *buffer_p, /**< buffer */
|
|||||||
ECMA_STRING_TO_UTF8_STRING (string_p, str_buffer_p, str_buffer_size);
|
ECMA_STRING_TO_UTF8_STRING (string_p, str_buffer_p, str_buffer_size);
|
||||||
|
|
||||||
/* Append the string to the buffer. */
|
/* Append the string to the buffer. */
|
||||||
uint8_t *new_buffer_p =
|
uint8_t *new_buffer_p = jerry_append_chars_to_buffer (buffer_p,
|
||||||
jerry_append_chars_to_buffer (buffer_p, buffer_end_p, (const char *) str_buffer_p, str_buffer_size);
|
buffer_end_p,
|
||||||
|
(const jerry_char_t *) str_buffer_p,
|
||||||
|
(jerry_size_t) str_buffer_size);
|
||||||
|
|
||||||
ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
|
ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
|
||||||
|
|
||||||
@@ -1516,7 +1513,10 @@ jerry_append_number_to_buffer (uint8_t *buffer_p, /**< buffer */
|
|||||||
|
|
||||||
JERRY_ASSERT (utf8_str_size <= ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32);
|
JERRY_ASSERT (utf8_str_size <= ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32);
|
||||||
|
|
||||||
return jerry_append_chars_to_buffer (buffer_p, buffer_end_p, (const char *) uint32_to_str_buffer, utf8_str_size);
|
return jerry_append_chars_to_buffer (buffer_p,
|
||||||
|
buffer_end_p,
|
||||||
|
(const jerry_char_t *) uint32_to_str_buffer,
|
||||||
|
(jerry_size_t) utf8_str_size);
|
||||||
} /* jerry_append_number_to_buffer */
|
} /* jerry_append_number_to_buffer */
|
||||||
|
|
||||||
#endif /* JERRY_SNAPSHOT_SAVE */
|
#endif /* JERRY_SNAPSHOT_SAVE */
|
||||||
@@ -1609,26 +1609,27 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
/* Save literal count. */
|
/* Save literal count. */
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "jerry_length_t literal_count = ", 0);
|
lit_buf_p =
|
||||||
|
jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("jerry_length_t literal_count = "));
|
||||||
|
|
||||||
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, literal_count);
|
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, literal_count);
|
||||||
|
|
||||||
/* Save the array of literals. */
|
/* Save the array of literals. */
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, ";\n\njerry_char_t *literals[", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (";\n\njerry_char_t *literals["));
|
||||||
|
|
||||||
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, literal_count);
|
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, literal_count);
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "] =\n{\n", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("] =\n{\n"));
|
||||||
|
|
||||||
for (lit_utf8_size_t i = 0; i < literal_count; i++)
|
for (lit_utf8_size_t i = 0; i < literal_count; i++)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, " \"", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (" \""));
|
||||||
ECMA_STRING_TO_UTF8_STRING (literal_array[i], str_buffer_p, str_buffer_size);
|
ECMA_STRING_TO_UTF8_STRING (literal_array[i], str_buffer_p, str_buffer_size);
|
||||||
for (lit_utf8_size_t j = 0; j < str_buffer_size; j++)
|
for (lit_utf8_size_t j = 0; j < str_buffer_size; j++)
|
||||||
{
|
{
|
||||||
uint8_t byte = str_buffer_p[j];
|
uint8_t byte = str_buffer_p[j];
|
||||||
if (byte < 32 || byte > 127)
|
if (byte < 32 || byte > 127)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\\x", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("\\x"));
|
||||||
ecma_char_t hex_digit = (ecma_char_t) (byte >> 4);
|
ecma_char_t hex_digit = (ecma_char_t) (byte >> 4);
|
||||||
*lit_buf_p++ = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
|
*lit_buf_p++ = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
|
||||||
hex_digit = (lit_utf8_byte_t) (byte & 0xf);
|
hex_digit = (lit_utf8_byte_t) (byte & 0xf);
|
||||||
@@ -1645,20 +1646,21 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
}
|
}
|
||||||
|
|
||||||
ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
|
ECMA_FINALIZE_UTF8_STRING (str_buffer_p, str_buffer_size);
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\"", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("\""));
|
||||||
|
|
||||||
if (i < literal_count - 1)
|
if (i < literal_count - 1)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, ",", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (","));
|
||||||
}
|
}
|
||||||
|
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\n", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "};\n\njerry_length_t literal_sizes[", 0);
|
lit_buf_p =
|
||||||
|
jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("};\n\njerry_length_t literal_sizes["));
|
||||||
|
|
||||||
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, literal_count);
|
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, literal_count);
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "] =\n{\n", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("] =\n{\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the literal sizes respectively. */
|
/* Save the literal sizes respectively. */
|
||||||
@@ -1668,22 +1670,22 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
|
|
||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, " ", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, str_size);
|
lit_buf_p = jerry_append_number_to_buffer (lit_buf_p, buffer_end_p, str_size);
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, " ", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (" "));
|
||||||
|
|
||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
/* Show the given string as a comment. */
|
/* Show the given string as a comment. */
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "/* ", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("/* "));
|
||||||
lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p, buffer_end_p, literal_array[i]);
|
lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p, buffer_end_p, literal_array[i]);
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, " */", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (" */"));
|
||||||
|
|
||||||
if (i < literal_count - 1)
|
if (i < literal_count - 1)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, ",", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG (","));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1691,12 +1693,12 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
|||||||
lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p, buffer_end_p, literal_array[i]);
|
lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p, buffer_end_p, literal_array[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "\n", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, "};\n", 0);
|
lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p, buffer_end_p, JERRY_ZSTR_ARG ("};\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
JMEM_FINALIZE_LOCAL_ARRAY (literal_array);
|
JMEM_FINALIZE_LOCAL_ARRAY (literal_array);
|
||||||
|
|||||||
@@ -142,16 +142,6 @@ void jerry_port_context_free (void);
|
|||||||
*/
|
*/
|
||||||
void jerry_port_log (const char *message_p);
|
void jerry_port_log (const char *message_p);
|
||||||
|
|
||||||
/**
|
|
||||||
* Print a single character to standard output.
|
|
||||||
*
|
|
||||||
* This port function is never called from jerry-core directly, it is only used by jerry-ext components to print
|
|
||||||
* information.
|
|
||||||
*
|
|
||||||
* @param byte: the byte to print.
|
|
||||||
*/
|
|
||||||
void jerry_port_print_byte (jerry_char_t byte);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a buffer to standard output
|
* Print a buffer to standard output
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -856,6 +856,11 @@ typedef void (*jerry_arraybuffer_free_cb_t) (jerry_arraybuffer_type_t buffer_typ
|
|||||||
void *arraybuffer_user_p,
|
void *arraybuffer_user_p,
|
||||||
void *user_p);
|
void *user_p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to expand string literal to [string pointer, string size] argument pair.
|
||||||
|
*/
|
||||||
|
#define JERRY_ZSTR_ARG(str) ((const jerry_char_t *) (str)), ((jerry_size_t) (sizeof (str) - 1))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,9 +22,7 @@
|
|||||||
JERRY_C_API_BEGIN
|
JERRY_C_API_BEGIN
|
||||||
|
|
||||||
jerry_value_t jerryx_print_value (const jerry_value_t value);
|
jerry_value_t jerryx_print_value (const jerry_value_t value);
|
||||||
void jerryx_print_byte (jerry_char_t ch);
|
|
||||||
void jerryx_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size);
|
void jerryx_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size);
|
||||||
void jerryx_print_string (const char *str_p);
|
|
||||||
void jerryx_print_backtrace (unsigned depth);
|
void jerryx_print_backtrace (unsigned depth);
|
||||||
void jerryx_print_unhandled_exception (jerry_value_t exception);
|
void jerryx_print_unhandled_exception (jerry_value_t exception);
|
||||||
void jerryx_print_unhandled_rejection (jerry_value_t exception);
|
void jerryx_print_unhandled_rejection (jerry_value_t exception);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
JERRY_C_API_BEGIN
|
JERRY_C_API_BEGIN
|
||||||
|
|
||||||
void jerryx_repl (const char* prompt_p);
|
void jerryx_repl (const jerry_char_t *prompt_p, jerry_size_t prompt_size);
|
||||||
|
|
||||||
JERRY_C_API_END
|
JERRY_C_API_END
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
* Provide a 'print' implementation for scripts.
|
* Provide a 'print' implementation for scripts.
|
||||||
*
|
*
|
||||||
* The routine converts all of its arguments to strings and outputs them
|
* The routine converts all of its arguments to strings and outputs them
|
||||||
* char-by-char using jerry_port_print_byte.
|
* by using jerry_port_print_buffer.
|
||||||
*
|
*
|
||||||
* The NUL character is output as "\u0000", other characters are output
|
* The NULL character is output as "\u0000", other characters are output
|
||||||
* bytewise.
|
* bytewise.
|
||||||
*
|
*
|
||||||
* Note:
|
* Note:
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
* output. This allows more flexibility but also extends the core
|
* output. This allows more flexibility but also extends the core
|
||||||
* JerryScript engine port API. Applications that want to use
|
* JerryScript engine port API. Applications that want to use
|
||||||
* `jerryx_handler_print` must ensure that their port implementation also
|
* `jerryx_handler_print` must ensure that their port implementation also
|
||||||
* provides `jerry_port_print_byte`.
|
* provides `jerry_port_print_buffer`.
|
||||||
*
|
*
|
||||||
* @return undefined - if all arguments could be converted to strings,
|
* @return undefined - if all arguments could be converted to strings,
|
||||||
* error - otherwise.
|
* error - otherwise.
|
||||||
@@ -51,7 +51,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
|||||||
{
|
{
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
{
|
{
|
||||||
jerryx_print_byte (' ');
|
jerryx_print_buffer (JERRY_ZSTR_ARG (" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
jerry_value_t result = jerryx_print_value (args_p[index]);
|
jerry_value_t result = jerryx_print_value (args_p[index]);
|
||||||
@@ -62,7 +62,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jerryx_print_byte ('\n');
|
jerryx_print_buffer (JERRY_ZSTR_ARG ("\n"));
|
||||||
return jerry_undefined ();
|
return jerry_undefined ();
|
||||||
} /* jerryx_handler_print */
|
} /* jerryx_handler_print */
|
||||||
|
|
||||||
|
|||||||
+1
-33
@@ -61,7 +61,7 @@ jerryx_buffered_print (uint32_t value, void *user_p)
|
|||||||
jerryx_print_buffer (buffer_p->data, buffer_p->index);
|
jerryx_print_buffer (buffer_p->data, buffer_p->index);
|
||||||
buffer_p->index = 0;
|
buffer_p->index = 0;
|
||||||
|
|
||||||
jerryx_print_string ("\\u0000");
|
jerryx_print_buffer (JERRY_ZSTR_ARG ("\\u0000"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,20 +111,6 @@ jerryx_print_value (const jerry_value_t value)
|
|||||||
return jerry_undefined ();
|
return jerry_undefined ();
|
||||||
} /* jerryx_print */
|
} /* jerryx_print */
|
||||||
|
|
||||||
/**
|
|
||||||
* Print a character to standard output, also sending it to the debugger, if connected.
|
|
||||||
*
|
|
||||||
* @param ch: input character
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
jerryx_print_byte (jerry_char_t byte)
|
|
||||||
{
|
|
||||||
jerry_port_print_byte (byte);
|
|
||||||
#if JERRY_DEBUGGER
|
|
||||||
jerry_debugger_send_output (&byte, 1);
|
|
||||||
#endif /* JERRY_DEBUGGER */
|
|
||||||
} /* jerryx_print_char */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a buffer to standard output, also sending it to the debugger, if connected.
|
* Print a buffer to standard output, also sending it to the debugger, if connected.
|
||||||
*
|
*
|
||||||
@@ -140,24 +126,6 @@ jerryx_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size)
|
|||||||
#endif /* JERRY_DEBUGGER */
|
#endif /* JERRY_DEBUGGER */
|
||||||
} /* jerryx_print_buffer */
|
} /* jerryx_print_buffer */
|
||||||
|
|
||||||
/**
|
|
||||||
* Print a zero-terminated string to standard output, also sending it to the debugger, if connected.
|
|
||||||
*
|
|
||||||
* @param buffer_p: inptut string buffer
|
|
||||||
* @param buffer_size: size of the string
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
jerryx_print_string (const char *str_p)
|
|
||||||
{
|
|
||||||
const jerry_char_t *buffer_p = (jerry_char_t *) str_p;
|
|
||||||
jerry_size_t buffer_size = (jerry_size_t) (strlen (str_p));
|
|
||||||
|
|
||||||
jerry_port_print_buffer (buffer_p, buffer_size);
|
|
||||||
#if JERRY_DEBUGGER
|
|
||||||
jerry_debugger_send_output (buffer_p, buffer_size);
|
|
||||||
#endif /* JERRY_DEBUGGER */
|
|
||||||
} /* jerryx_print_string */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print backtrace as log messages up to a specific depth.
|
* Print backtrace as log messages up to a specific depth.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -24,13 +24,13 @@
|
|||||||
#include "jerryscript-ext/print.h"
|
#include "jerryscript-ext/print.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
jerryx_repl (const char *prompt_p)
|
jerryx_repl (const jerry_char_t *prompt_p, jerry_size_t prompt_size)
|
||||||
{
|
{
|
||||||
jerry_value_t result;
|
jerry_value_t result;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
jerryx_print_string (prompt_p);
|
jerryx_print_buffer (prompt_p, prompt_size);
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
|
|
||||||
jerry_size_t length;
|
jerry_size_t length;
|
||||||
@@ -38,7 +38,7 @@ jerryx_repl (const char *prompt_p)
|
|||||||
|
|
||||||
if (line_p == NULL)
|
if (line_p == NULL)
|
||||||
{
|
{
|
||||||
jerryx_print_byte ('\n');
|
jerryx_print_buffer (JERRY_ZSTR_ARG ("\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ jerryx_repl (const char *prompt_p)
|
|||||||
goto exception;
|
goto exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
jerryx_print_byte ('\n');
|
jerryx_print_buffer (JERRY_ZSTR_ARG ("\n"));
|
||||||
|
|
||||||
jerry_value_free (result);
|
jerry_value_free (result);
|
||||||
result = jerry_run_jobs ();
|
result = jerry_run_jobs ();
|
||||||
|
|||||||
@@ -222,8 +222,14 @@ restart:
|
|||||||
}
|
}
|
||||||
else if (arguments.source_count == 0)
|
else if (arguments.source_count == 0)
|
||||||
{
|
{
|
||||||
const char *prompt_p = (arguments.option_flags & OPT_FLAG_NO_PROMPT) ? "" : "jerry> ";
|
if ((arguments.option_flags & OPT_FLAG_NO_PROMPT))
|
||||||
jerryx_repl (prompt_p);
|
{
|
||||||
|
jerryx_repl (JERRY_ZSTR_ARG (""));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jerryx_repl (JERRY_ZSTR_ARG ("jerry> "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = jerry_run_jobs ();
|
result = jerry_run_jobs ();
|
||||||
|
|||||||
@@ -28,29 +28,11 @@ jerry_port_log (const char *message_p) /**< message */
|
|||||||
fputs (message_p, stderr);
|
fputs (message_p, stderr);
|
||||||
} /* jerry_port_log */
|
} /* jerry_port_log */
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of jerry_port_print_byte. Uses 'putchar' to
|
|
||||||
* print a single character to standard output.
|
|
||||||
*/
|
|
||||||
void JERRY_ATTR_WEAK
|
void JERRY_ATTR_WEAK
|
||||||
jerry_port_print_byte (jerry_char_t byte) /**< the character to print */
|
jerry_port_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size)
|
||||||
{
|
{
|
||||||
putchar (byte);
|
fwrite (buffer_p, 1, buffer_size, stdout);
|
||||||
} /* jerry_port_print_byte */
|
} /* jerry_port_print_buffer */
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of jerry_port_print_buffer. Uses 'jerry_port_print_byte' to
|
|
||||||
* print characters of the input buffer.
|
|
||||||
*/
|
|
||||||
void JERRY_ATTR_WEAK
|
|
||||||
jerry_port_print_buffer (const jerry_char_t *buffer_p, /**< string buffer */
|
|
||||||
jerry_size_t buffer_size) /**< string size*/
|
|
||||||
{
|
|
||||||
for (jerry_size_t i = 0; i < buffer_size; i++)
|
|
||||||
{
|
|
||||||
jerry_port_print_byte (buffer_p[i]);
|
|
||||||
}
|
|
||||||
} /* jerry_port_print_byte */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a line from standard input as a zero-terminated string.
|
* Read a line from standard input as a zero-terminated string.
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ jerry_main (int argc, char *argv[])
|
|||||||
|
|
||||||
if (files_counter == 0)
|
if (files_counter == 0)
|
||||||
{
|
{
|
||||||
jerryx_repl ("jerry> ");
|
jerryx_repl (JERRY_ZSTR_ARG ("jerry> "));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ main (void)
|
|||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
jerryx_register_global ("print", jerryx_handler_print);
|
jerryx_register_global ("print", jerryx_handler_print);
|
||||||
|
|
||||||
jerryx_repl ("js> ");
|
jerryx_repl (JERRY_ZSTR_ARG ("js> "));
|
||||||
|
|
||||||
jerry_cleanup ();
|
jerry_cleanup ();
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|||||||
Reference in New Issue
Block a user