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:
@@ -25,9 +25,9 @@
|
||||
* Provide a 'print' implementation for scripts.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Note:
|
||||
@@ -35,7 +35,7 @@
|
||||
* output. This allows more flexibility but also extends the core
|
||||
* JerryScript engine port API. Applications that want to use
|
||||
* `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,
|
||||
* error - otherwise.
|
||||
@@ -51,7 +51,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
jerryx_print_byte (' ');
|
||||
jerryx_print_buffer (JERRY_ZSTR_ARG (" "));
|
||||
}
|
||||
|
||||
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 ();
|
||||
} /* 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);
|
||||
buffer_p->index = 0;
|
||||
|
||||
jerryx_print_string ("\\u0000");
|
||||
jerryx_print_buffer (JERRY_ZSTR_ARG ("\\u0000"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,20 +111,6 @@ jerryx_print_value (const jerry_value_t value)
|
||||
return jerry_undefined ();
|
||||
} /* 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.
|
||||
*
|
||||
@@ -140,24 +126,6 @@ jerryx_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size)
|
||||
#endif /* JERRY_DEBUGGER */
|
||||
} /* 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.
|
||||
*
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
#include "jerryscript-ext/print.h"
|
||||
|
||||
void
|
||||
jerryx_repl (const char *prompt_p)
|
||||
jerryx_repl (const jerry_char_t *prompt_p, jerry_size_t prompt_size)
|
||||
{
|
||||
jerry_value_t result;
|
||||
|
||||
while (true)
|
||||
{
|
||||
jerryx_print_string (prompt_p);
|
||||
jerryx_print_buffer (prompt_p, prompt_size);
|
||||
fflush (stdout);
|
||||
|
||||
jerry_size_t length;
|
||||
@@ -38,7 +38,7 @@ jerryx_repl (const char *prompt_p)
|
||||
|
||||
if (line_p == NULL)
|
||||
{
|
||||
jerryx_print_byte ('\n');
|
||||
jerryx_print_buffer (JERRY_ZSTR_ARG ("\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ jerryx_repl (const char *prompt_p)
|
||||
goto exception;
|
||||
}
|
||||
|
||||
jerryx_print_byte ('\n');
|
||||
jerryx_print_buffer (JERRY_ZSTR_ARG ("\n"));
|
||||
|
||||
jerry_value_free (result);
|
||||
result = jerry_run_jobs ();
|
||||
|
||||
Reference in New Issue
Block a user