Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

[jerryscript] Rebase to latest JerryScript #1883

Merged
merged 2 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/jerryscript
Submodule jerryscript updated 265 files
9 changes: 5 additions & 4 deletions src/ashell/jerry-code.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static jerry_value_t parsed_code = 0;
void javascript_eval_code(const char *source_buffer, ssize_t size)
{
ZVAL ret_val = jerry_eval((jerry_char_t *)source_buffer, size, false);
if (jerry_value_has_error_flag(ret_val)) {
if (jerry_value_is_error(ret_val)) {
printf("[ERR] failed to evaluate JS\n");
zjs_print_error_message(ret_val, ZJS_UNDEFINED);
}
Expand Down Expand Up @@ -63,8 +63,9 @@ int javascript_parse_code(const char *file_name)

if (buf && size > 0) {
/* Setup Global scope code */
parsed_code = jerry_parse((const jerry_char_t *)buf, size, false);
if (jerry_value_has_error_flag(parsed_code)) {
parsed_code = jerry_parse(NULL, 0, (const jerry_char_t *)buf, size,
JERRY_PARSE_NO_OPTS);
if (jerry_value_is_error(parsed_code)) {
DBG_PRINT("Error parsing JS\n");
zjs_print_error_message(parsed_code, ZJS_UNDEFINED);
jerry_release_value(parsed_code);
Expand All @@ -85,7 +86,7 @@ void javascript_run_code(const char *file_name)
/* Execute the parsed source code in the Global scope */
ZVAL ret_value = jerry_run(parsed_code);

if (jerry_value_has_error_flag(ret_value)) {
if (jerry_value_is_error(ret_value)) {
DBG_PRINT("Error running JS\n");
zjs_print_error_message(ret_value, ZJS_UNDEFINED);
}
Expand Down
9 changes: 9 additions & 0 deletions src/jerry-port/zjs_jerry_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ void jerry_port_log(jerry_log_level_t level, const char *format, ...)
#endif /* JERRY_DEBUGGER */
va_end(args);
}

void jerry_port_sleep (uint32_t sleep_time)
{
#ifdef ZJS_LINUX_BUILD
usleep ((useconds_t) sleep_time * 1000);
#else
k_sleep ((useconds_t) sleep_time);
#endif
}
22 changes: 13 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ int main(int argc, char *argv[])
#endif

#ifndef ZJS_SNAPSHOT_BUILD
code_eval = jerry_parse_named_resource((jerry_char_t *)file_name,
file_name_len,
(jerry_char_t *)script,
script_len,
false);
code_eval = jerry_parse((jerry_char_t *)file_name,
file_name_len,
(jerry_char_t *)script,
script_len,
JERRY_PARSE_NO_OPTS);

if (jerry_value_has_error_flag(code_eval)) {
if (jerry_value_is_error(code_eval)) {
DBG_PRINT("Error parsing JS\n");
zjs_print_error_message(code_eval, ZJS_UNDEFINED);
goto error;
Expand All @@ -311,12 +311,16 @@ int main(int argc, char *argv[])
#endif

#ifdef ZJS_SNAPSHOT_BUILD
result = jerry_exec_snapshot(snapshot_bytecode, snapshot_len, false);
result = jerry_exec_snapshot(snapshot_bytecode,
snapshot_len,
0,
JERRY_SNAPSHOT_EXEC_COPY_DATA);

#else
result = jerry_run(code_eval);
#endif

if (jerry_value_has_error_flag(result)) {
if (jerry_value_is_error(result)) {
DBG_PRINT("Error running JS\n");
zjs_print_error_message(result, ZJS_UNDEFINED);
goto error;
Expand Down Expand Up @@ -406,7 +410,7 @@ int main(int argc, char *argv[])
#ifdef BUILD_MODULE_PROMISE
// run queued jobs for promises
result = jerry_run_all_enqueued_jobs();
if (jerry_value_has_error_flag(result)) {
if (jerry_value_is_error(result)) {
DBG_PRINT("Error running JS in promise jobqueue\n");
zjs_print_error_message(result, ZJS_UNDEFINED);
goto error;
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/zjs_sensor_accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
zjs_sensor_create, g_instance, SENSOR_CHAN_ACCEL_XYZ, ACCEL_DEVICE_NAME,
0, 800, onchange, NULL, onstop);

if (!jerry_value_has_error_flag(sensor_obj)) {
if (!jerry_value_is_error(sensor_obj)) {
ZVAL null_val = jerry_create_null();
zjs_set_readonly_property(sensor_obj, "x", null_val);
zjs_set_readonly_property(sensor_obj, "y", null_val);
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/zjs_sensor_gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_GYRO_XYZ,
GYRO_DEVICE_NAME, 0, 800, onchange, NULL, onstop);

if (!jerry_value_has_error_flag(sensor_obj)) {
if (!jerry_value_is_error(sensor_obj)) {
ZVAL null_val = jerry_create_null();
zjs_set_readonly_property(sensor_obj, "x", null_val);
zjs_set_readonly_property(sensor_obj, "y", null_val);
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/zjs_sensor_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_LIGHT,
ADC_DEVICE_NAME, -1, 100, onchange, NULL, onstop);

if (!jerry_value_has_error_flag(sensor_obj)) {
if (!jerry_value_is_error(sensor_obj)) {
ZVAL null_val = jerry_create_null();
zjs_set_readonly_property(sensor_obj, "illuminance", null_val);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/zjs_sensor_magn.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_MAGN_XYZ,
MAGN_DEVICE_NAME, 0, 800, onchange, NULL, onstop);

if (!jerry_value_has_error_flag(sensor_obj)) {
if (!jerry_value_is_error(sensor_obj)) {
ZVAL null_val = jerry_create_null();
zjs_set_readonly_property(sensor_obj, "x", null_val);
zjs_set_readonly_property(sensor_obj, "y", null_val);
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/zjs_sensor_temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_TEMP,
TEMP_DEVICE_NAME, 0, 800, onchange, NULL, onstop);

if (!jerry_value_has_error_flag(sensor_obj)) {
if (!jerry_value_is_error(sensor_obj)) {
ZVAL null_val = jerry_create_null();
zjs_set_readonly_property(sensor_obj, "celsius", null_val);
}
Expand Down
2 changes: 1 addition & 1 deletion src/zjs_aio_a101.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static ZJS_DECL_FUNC(zjs_aio_open)
send.data.aio.pin = pin;

ZVAL result = zjs_aio_call_remote_function(&send);
if (jerry_value_has_error_flag(result))
if (jerry_value_is_error(result))
return result;

// create the AIOPin object
Expand Down
12 changes: 6 additions & 6 deletions src/zjs_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void zjs_ble_read_c_callback(void *handle, const void *argv)

jerry_value_t args[2] = { offset, callback };
ZVAL rval = jerry_call_function(cb->js_callback, chrc->chrc_obj, args, 2);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
DBG_PRINT("failed to call onReadRequest function\n");
}
}
Expand Down Expand Up @@ -366,7 +366,7 @@ static void zjs_ble_write_c_callback(void *handle, const void *argv)

jerry_value_t args[4] = { buf_obj, offset, without_response, callback };
ZVAL rval = jerry_call_function(cb->js_callback, chrc->chrc_obj, args, 4);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
DBG_PRINT("failed to call onWriteRequest function\n");
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ static void zjs_ble_subscribe_c_callback(void *handle, const void *argv)

jerry_value_t args[2] = { max_size, callback };
ZVAL rval = jerry_call_function(cb->js_callback, chrc->chrc_obj, args, 2);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
DBG_PRINT("failed to call onSubscribe function\n");
}
}
Expand All @@ -455,7 +455,7 @@ static void zjs_ble_unsubscribe_c_callback(void *handle, const void *argv)
ble_notify_handle_t *cb = &chrc->unsubscribe_cb;

ZVAL rval = jerry_call_function(cb->js_callback, chrc->chrc_obj, NULL, 0);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
DBG_PRINT("failed to call onUnsubscribe function\n");
}
}
Expand All @@ -466,7 +466,7 @@ static void zjs_ble_notify_c_callback(void *handle, const void *argv)
ble_notify_handle_t *cb = &chrc->notify_cb;

ZVAL rval = jerry_call_function(cb->js_callback, chrc->chrc_obj, NULL, 0);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
DBG_PRINT("failed to call onNotify function\n");
}
}
Expand Down Expand Up @@ -1212,7 +1212,7 @@ static ZJS_DECL_FUNC(zjs_ble_set_services)
ZVAL arg = success ? ZJS_UNDEFINED
: jerry_create_string("failed to register services");
ZVAL rval = jerry_call_function(argv[1], ZJS_UNDEFINED, &arg, 1);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
DBG_PRINT("failed to call callback function\n");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/zjs_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ void zjs_call_callback(zjs_callback_id id, const void *data, u32_t sz)
if (!jerry_value_is_undefined(cb_map[id]->js_func)) {
rval = jerry_call_function(cb_map[id]->js_func,
cb_map[id]->this, values, sz);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
#ifdef INSTRUMENT_CALLBACKS
DBG_PRINT("callback %d had error; creator: %s, "
"caller: %s\n",
Expand Down
4 changes: 2 additions & 2 deletions src/zjs_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static ZJS_DECL_FUNC(add_listener)
jerry_value_t rval = zjs_add_event_listener(this, name, argv[1]);
zjs_free(name);

if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
return rval;
}

Expand Down Expand Up @@ -422,7 +422,7 @@ bool zjs_emit_event_priv(jerry_value_t obj, const char *event_name,
listener_t *listener = event->listeners;
while (listener) {
ZVAL rval = jerry_call_function(listener->func, obj, argv, argc);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
ERR_PRINT("error calling listener\n");
}
listener = listener->next;
Expand Down
6 changes: 3 additions & 3 deletions src/zjs_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static jerry_value_t zjs_gfx_call_cb(u32_t x, u32_t y, u32_t w, u32_t h,
jerry_value_t ret = jerry_call_function(gfxHandle->drawDataCB,
gfxHandle->jsThis, args, 5);

if (jerry_value_has_error_flag(ret)) {
if (jerry_value_is_error(ret)) {
ERR_PRINT("JS callback failed with %u..\n", (u32_t)ret);
return ret;
}
Expand Down Expand Up @@ -273,7 +273,7 @@ static jerry_value_t zjs_gfx_flush(gfx_handle_t *gfxHandle)

ret = zjs_gfx_call_cb(xStart, yStart, currW, currH,
recBufObj, gfxHandle);
if (jerry_value_has_error_flag(ret)) {
if (jerry_value_is_error(ret)) {
zjs_gfx_reset_touched_pixels(gfxHandle);
return ret;
}
Expand Down Expand Up @@ -625,7 +625,7 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_string)

ret = zjs_gfx_draw_char_priv(x, argData.coords[1], argData.text[i],
argData.color, argData.size, handle);
if (jerry_value_has_error_flag(ret)) {
if (jerry_value_is_error(ret)) {
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions src/zjs_grove_lcd_ipm.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static jerry_value_t zjs_glcd_call_remote_function(zjs_ipm_message_t *send)
static jerry_value_t zjs_glcd_call_remote_ignore(zjs_ipm_message_t *send)
{
ZVAL rval = zjs_glcd_call_remote_function(send);
if (jerry_value_has_error_flag(rval))
if (jerry_value_is_error(rval))
return rval;

return ZJS_UNDEFINED;
Expand Down Expand Up @@ -231,7 +231,7 @@ static ZJS_DECL_FUNC(zjs_glcd_init)
send.type = TYPE_GLCD_INIT;

ZVAL result = zjs_glcd_call_remote_function(&send);
if (jerry_value_has_error_flag(result)) {
if (jerry_value_is_error(result)) {
return result;
}

Expand Down
13 changes: 7 additions & 6 deletions src/zjs_modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static bool javascript_eval_code(const char *source_buffer, ssize_t size,
jerry_value_t *ret_val)
{
(*ret_val) = jerry_eval((jerry_char_t *)source_buffer, size, false);
if (jerry_value_has_error_flag(*ret_val)) {
if (jerry_value_is_error(*ret_val)) {
ERR_PRINT("failed to evaluate JS\n");
return false;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ static bool load_js_module_fs(const jerry_value_t module_name,
}

(*result) = jerry_eval((jerry_char_t *)str, len, false);
if (jerry_value_has_error_flag(*result)) {
if (jerry_value_is_error(*result)) {
ERR_PRINT("failed to evaluate JS\n");
ret = false;
} else {
Expand Down Expand Up @@ -202,7 +202,7 @@ static ZJS_DECL_FUNC(native_require_handler)

// Try each of the resolvers to see if we can find the requested module
jerry_value_t result = jerryx_module_resolve(argv[0], resolvers, 3);
if (jerry_value_has_error_flag(result)) {
if (jerry_value_is_error(result)) {
DBG_PRINT("Couldn't load module %s\n", module);
return NOTSUPPORTED_ERROR("Module not found");
} else {
Expand Down Expand Up @@ -279,12 +279,13 @@ void zjs_modules_check_load_file()
size_t size;
jerry_value_t parsed_code = 0;
buf = read_file_alloc(load_file, &size);
parsed_code = jerry_parse((const jerry_char_t *)buf, size, false);
parsed_code = jerry_parse(NULL, 0, const jerry_char_t *)buf, size,
JERRY_PARSE_NO_OPTS);
zjs_free(buf);

if (!jerry_value_has_error_flag(parsed_code)) {
if (!jerry_value_is_error(parsed_code)) {
ZVAL ret_value = jerry_run(parsed_code);
if (jerry_value_has_error_flag(ret_value)) {
if (jerry_value_is_error(ret_value)) {
ERR_PRINT("Error running JS\n");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/zjs_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void zjs_sensor_trigger_change(jerry_value_t obj)
ZVAL event = zjs_create_object();
// if onreading exists, call it
ZVAL rval = jerry_call_function(func, obj, NULL, 0);
if (jerry_value_has_error_flag(rval)) {
if (jerry_value_is_error(rval)) {
ERR_PRINT("Error calling onreading\n");
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/zjs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ bool zjs_obj_get_boolean(jerry_value_t obj, const char *name, bool *flag)
ZVAL value = zjs_get_property(obj, name);
bool rval = false;

if (!jerry_value_has_error_flag(value) && jerry_value_is_boolean(value)) {
if (!jerry_value_is_error(value) && jerry_value_is_boolean(value)) {
*flag = jerry_get_boolean_value(value);
rval = true;
}
Expand All @@ -237,7 +237,7 @@ bool zjs_obj_get_string(jerry_value_t obj, const char *name, char *buffer,
ZVAL value = zjs_get_property(obj, name);
bool rval = false;

if (!jerry_value_has_error_flag(value) && jerry_value_is_string(value)) {
if (!jerry_value_is_error(value) && jerry_value_is_string(value)) {
jerry_size_t size = len;
zjs_copy_jstring(value, buffer, &size);
if (size)
Expand All @@ -254,7 +254,7 @@ bool zjs_obj_get_double(jerry_value_t obj, const char *name, double *num)
ZVAL value = zjs_get_property(obj, name);
bool rval = false;

if (!jerry_value_has_error_flag(value) && jerry_value_is_number(value)) {
if (!jerry_value_is_error(value) && jerry_value_is_number(value)) {
*num = jerry_get_number_value(value);
rval = true;
}
Expand All @@ -269,7 +269,7 @@ bool zjs_obj_get_uint32(jerry_value_t obj, const char *name, u32_t *num)
ZVAL value = zjs_get_property(obj, name);
bool rval = false;

if (!jerry_value_has_error_flag(value) && jerry_value_is_number(value)) {
if (!jerry_value_is_error(value) && jerry_value_is_number(value)) {
*num = (u32_t)jerry_get_number_value(value);
rval = true;
}
Expand All @@ -284,7 +284,7 @@ bool zjs_obj_get_int32(jerry_value_t obj, const char *name, s32_t *num)
ZVAL value = zjs_get_property(obj, name);
bool rval = false;

if (!jerry_value_has_error_flag(value) && jerry_value_is_number(value)) {
if (!jerry_value_is_error(value) && jerry_value_is_number(value)) {
*num = (s32_t)jerry_get_number_value(value);
rval = true;
}
Expand Down Expand Up @@ -738,7 +738,7 @@ int zjs_validate_args(const char *expectations[], const jerry_length_t argc,
int zjs_require_bool_if_prop(jerry_value_t obj, const char *prop, bool *result)
{
ZVAL value = zjs_get_property(obj, prop);
if (jerry_value_is_undefined(value) || jerry_value_has_error_flag(value)) {
if (jerry_value_is_undefined(value) || jerry_value_is_error(value)) {
// not found; leave default
return 0;
}
Expand All @@ -755,7 +755,7 @@ int zjs_require_string_if_prop_map(jerry_value_t obj, const char *prop,
str2int_t map[], int maxlen, int *result)
{
ZVAL value = zjs_get_property(obj, prop);
if (jerry_value_is_undefined(value) || jerry_value_has_error_flag(value)) {
if (jerry_value_is_undefined(value) || jerry_value_is_error(value)) {
// not found; leave default
return 0;
}
Expand Down
Loading