targets: zephyr: Reinstate "print" function and error printing. (#1851)
Re-add "print" function following resent refactors when it was moved from jerry-core to jerry-ext. This is done in particular to keep detailed messages on errors. JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
This commit is contained in:
committed by
László Langó
parent
557fa5006c
commit
b51b6824bb
@@ -17,6 +17,6 @@ $(info Compiling application)
|
||||
endif
|
||||
|
||||
# Adding path for jerry script APIs
|
||||
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
|
||||
ZEPHYRINCLUDE += $(JERRY_INCLUDE)
|
||||
|
||||
obj-y += main-zephyr.o getline-zephyr.o jerry-port.o
|
||||
|
||||
@@ -72,3 +72,13 @@ jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
|
||||
|
||||
return true;
|
||||
} /* jerry_port_get_time_zone */
|
||||
|
||||
/**
|
||||
* Provide the implementation of jerryx_port_handler_print_char.
|
||||
* Uses 'printf' to print a single character to standard output.
|
||||
*/
|
||||
void
|
||||
jerryx_port_handler_print_char (char c) /**< the character to print */
|
||||
{
|
||||
printf ("%c", c);
|
||||
} /* jerryx_port_handler_print_char */
|
||||
|
||||
@@ -22,9 +22,28 @@
|
||||
#include "getline-zephyr.h"
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-ext/handler.h"
|
||||
|
||||
static jerry_value_t print_function;
|
||||
|
||||
/**
|
||||
* Register a JavaScript function in the global object.
|
||||
*/
|
||||
static void
|
||||
register_js_function (const char *name_p, /**< name of the function */
|
||||
jerry_external_handler_t handler_p) /**< function callback */
|
||||
{
|
||||
jerry_value_t result_val = jerryx_handler_register_global ((const jerry_char_t *) name_p, handler_p);
|
||||
|
||||
if (jerry_value_has_error_flag (result_val))
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Warning: failed to register '%s' method.", name_p);
|
||||
}
|
||||
|
||||
jerry_release_value (result_val);
|
||||
} /* register_js_function */
|
||||
|
||||
static int shell_cmd_handler (char *source_buffer)
|
||||
{
|
||||
jerry_value_t ret_val;
|
||||
@@ -69,6 +88,7 @@ void main (void)
|
||||
|
||||
zephyr_getline_init ();
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
register_js_function ("print", jerryx_handler_print);
|
||||
jerry_value_t global_obj_val = jerry_get_global_object ();
|
||||
|
||||
jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
|
||||
|
||||
Reference in New Issue
Block a user