Remove the built-in print and the jerry_port_console port API functions (#1749)
The built-in `print` is removed from jerry-core, but an external `print` implementation is added to jerry-main. From now on, all embedders of the engine have to implement their own `print` if they need such a functionality. For printing results in REPL mode of jerry-main, the external `print` handler is called directly instead of looking up the `print` function registered into the global object. (The two are the same, but the indirection is not needed anymore.) Because jerry-core does not contain `print` anymore, `jerry_port_console` is removed from the port API. The default port is updated, i.e., the implementation of `jerry_port_console` is removed. Additionally, all references to `jerry_port_console` in jerry-main are replaced by `printf`. Speculatively, `jerry_port_console` is also removed from all non-default targets. Most targets implemented it for the sake of the engine only; in those targets the removal was trivial. Where the function was called from the embedder application as well, the calls were replaced with equivalents (e.g., `printf`, `printk`). NOTE 1: This is a breaking change! NOTE 2: This patch still leaves several targets without a JS `print` implementation. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
+12
-12
@@ -173,38 +173,38 @@ created by API functions has the error flag set.
|
||||
The following example function will output a JavaScript value:
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
static void
|
||||
print_value (const jerry_value_t value)
|
||||
{
|
||||
if (jerry_value_is_undefined (value))
|
||||
{
|
||||
jerry_port_console ("undefined");
|
||||
printf ("undefined");
|
||||
}
|
||||
else if (jerry_value_is_null (value))
|
||||
{
|
||||
jerry_port_console ("null");
|
||||
printf ("null");
|
||||
}
|
||||
else if (jerry_value_is_boolean (value))
|
||||
{
|
||||
if (jerry_get_boolean_value (value))
|
||||
{
|
||||
jerry_port_console ("true");
|
||||
printf ("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
jerry_port_console ("false");
|
||||
printf ("false");
|
||||
}
|
||||
}
|
||||
/* Float value */
|
||||
else if (jerry_value_is_number (value))
|
||||
{
|
||||
jerry_port_console ("number");
|
||||
printf ("number");
|
||||
}
|
||||
/* String value */
|
||||
else if (jerry_value_is_string (value))
|
||||
@@ -216,15 +216,15 @@ print_value (const jerry_value_t value)
|
||||
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
|
||||
str_buf_p[req_sz] = '\0';
|
||||
|
||||
jerry_port_console ("%s", (const char *) str_buf_p);
|
||||
printf ("%s", (const char *) str_buf_p);
|
||||
}
|
||||
/* Object reference */
|
||||
else if (jerry_value_is_object (value))
|
||||
{
|
||||
jerry_port_console ("[JS object]");
|
||||
printf ("[JS object]");
|
||||
}
|
||||
|
||||
jerry_port_console ("\n");
|
||||
printf ("\n");
|
||||
}
|
||||
```
|
||||
|
||||
@@ -243,11 +243,11 @@ Shell operation can be described with the following loop:
|
||||
- loop.
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
static void print_value (const jerry_value_t);
|
||||
|
||||
@@ -265,7 +265,7 @@ main (int argc, char *argv[])
|
||||
char *cmd_tail = cmd;
|
||||
size_t len = 0;
|
||||
|
||||
jerry_port_console ("> ");
|
||||
printf ("> ");
|
||||
|
||||
/* Read next command */
|
||||
while (true)
|
||||
@@ -302,7 +302,7 @@ main (int argc, char *argv[])
|
||||
{
|
||||
/* Evaluated JS code thrown an exception
|
||||
* and didn't handle it with try-catch-finally */
|
||||
jerry_port_console ("Unhandled JS exception occured: ");
|
||||
printf ("Unhandled JS exception occured: ");
|
||||
}
|
||||
|
||||
print_value (ret_val);
|
||||
|
||||
Reference in New Issue
Block a user