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

Commit 2b033e1

Browse files
Jimmy Huanggrgustaf
authored andcommitted
[jerryscript] Rebase to latest JerryScript (#1883)
Signed-off-by: Jimmy Huang <[email protected]>
1 parent f90d9d1 commit 2b033e1

19 files changed

+70
-54
lines changed

deps/jerryscript

Submodule jerryscript updated 265 files

src/ashell/jerry-code.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static jerry_value_t parsed_code = 0;
3535
void javascript_eval_code(const char *source_buffer, ssize_t size)
3636
{
3737
ZVAL ret_val = jerry_eval((jerry_char_t *)source_buffer, size, false);
38-
if (jerry_value_has_error_flag(ret_val)) {
38+
if (jerry_value_is_error(ret_val)) {
3939
printf("[ERR] failed to evaluate JS\n");
4040
zjs_print_error_message(ret_val, ZJS_UNDEFINED);
4141
}
@@ -63,8 +63,9 @@ int javascript_parse_code(const char *file_name)
6363

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

88-
if (jerry_value_has_error_flag(ret_value)) {
89+
if (jerry_value_is_error(ret_value)) {
8990
DBG_PRINT("Error running JS\n");
9091
zjs_print_error_message(ret_value, ZJS_UNDEFINED);
9192
}

src/jerry-port/zjs_jerry_port.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ void jerry_port_log(jerry_log_level_t level, const char *format, ...)
5757
#endif /* JERRY_DEBUGGER */
5858
va_end(args);
5959
}
60+
61+
void jerry_port_sleep (uint32_t sleep_time)
62+
{
63+
#ifdef ZJS_LINUX_BUILD
64+
usleep ((useconds_t) sleep_time * 1000);
65+
#else
66+
k_sleep ((useconds_t) sleep_time);
67+
#endif
68+
}

src/main.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,13 @@ int main(int argc, char *argv[])
293293
#endif
294294

295295
#ifndef ZJS_SNAPSHOT_BUILD
296-
code_eval = jerry_parse_named_resource((jerry_char_t *)file_name,
297-
file_name_len,
298-
(jerry_char_t *)script,
299-
script_len,
300-
false);
296+
code_eval = jerry_parse((jerry_char_t *)file_name,
297+
file_name_len,
298+
(jerry_char_t *)script,
299+
script_len,
300+
JERRY_PARSE_NO_OPTS);
301301

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

313313
#ifdef ZJS_SNAPSHOT_BUILD
314-
result = jerry_exec_snapshot(snapshot_bytecode, snapshot_len, false);
314+
result = jerry_exec_snapshot(snapshot_bytecode,
315+
snapshot_len,
316+
0,
317+
JERRY_SNAPSHOT_EXEC_COPY_DATA);
318+
315319
#else
316320
result = jerry_run(code_eval);
317321
#endif
318322

319-
if (jerry_value_has_error_flag(result)) {
323+
if (jerry_value_is_error(result)) {
320324
DBG_PRINT("Error running JS\n");
321325
zjs_print_error_message(result, ZJS_UNDEFINED);
322326
goto error;
@@ -406,7 +410,7 @@ int main(int argc, char *argv[])
406410
#ifdef BUILD_MODULE_PROMISE
407411
// run queued jobs for promises
408412
result = jerry_run_all_enqueued_jobs();
409-
if (jerry_value_has_error_flag(result)) {
413+
if (jerry_value_is_error(result)) {
410414
DBG_PRINT("Error running JS in promise jobqueue\n");
411415
zjs_print_error_message(result, ZJS_UNDEFINED);
412416
goto error;

src/sensors/zjs_sensor_accel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
4747
zjs_sensor_create, g_instance, SENSOR_CHAN_ACCEL_XYZ, ACCEL_DEVICE_NAME,
4848
0, 800, onchange, NULL, onstop);
4949

50-
if (!jerry_value_has_error_flag(sensor_obj)) {
50+
if (!jerry_value_is_error(sensor_obj)) {
5151
ZVAL null_val = jerry_create_null();
5252
zjs_set_readonly_property(sensor_obj, "x", null_val);
5353
zjs_set_readonly_property(sensor_obj, "y", null_val);

src/sensors/zjs_sensor_gyro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
4747
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_GYRO_XYZ,
4848
GYRO_DEVICE_NAME, 0, 800, onchange, NULL, onstop);
4949

50-
if (!jerry_value_has_error_flag(sensor_obj)) {
50+
if (!jerry_value_is_error(sensor_obj)) {
5151
ZVAL null_val = jerry_create_null();
5252
zjs_set_readonly_property(sensor_obj, "x", null_val);
5353
zjs_set_readonly_property(sensor_obj, "y", null_val);

src/sensors/zjs_sensor_light.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
4141
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_LIGHT,
4242
ADC_DEVICE_NAME, -1, 100, onchange, NULL, onstop);
4343

44-
if (!jerry_value_has_error_flag(sensor_obj)) {
44+
if (!jerry_value_is_error(sensor_obj)) {
4545
ZVAL null_val = jerry_create_null();
4646
zjs_set_readonly_property(sensor_obj, "illuminance", null_val);
4747
}

src/sensors/zjs_sensor_magn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
4747
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_MAGN_XYZ,
4848
MAGN_DEVICE_NAME, 0, 800, onchange, NULL, onstop);
4949

50-
if (!jerry_value_has_error_flag(sensor_obj)) {
50+
if (!jerry_value_is_error(sensor_obj)) {
5151
ZVAL null_val = jerry_create_null();
5252
zjs_set_readonly_property(sensor_obj, "x", null_val);
5353
zjs_set_readonly_property(sensor_obj, "y", null_val);

src/sensors/zjs_sensor_temp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static ZJS_DECL_FUNC(zjs_sensor_constructor)
4141
ZJS_CHAIN_FUNC_ARGS(zjs_sensor_create, g_instance, SENSOR_CHAN_TEMP,
4242
TEMP_DEVICE_NAME, 0, 800, onchange, NULL, onstop);
4343

44-
if (!jerry_value_has_error_flag(sensor_obj)) {
44+
if (!jerry_value_is_error(sensor_obj)) {
4545
ZVAL null_val = jerry_create_null();
4646
zjs_set_readonly_property(sensor_obj, "celsius", null_val);
4747
}

src/zjs_aio_a101.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static ZJS_DECL_FUNC(zjs_aio_open)
239239
send.data.aio.pin = pin;
240240

241241
ZVAL result = zjs_aio_call_remote_function(&send);
242-
if (jerry_value_has_error_flag(result))
242+
if (jerry_value_is_error(result))
243243
return result;
244244

245245
// create the AIOPin object

src/zjs_ble.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static void zjs_ble_read_c_callback(void *handle, const void *argv)
260260

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

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

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

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

468468
ZVAL rval = jerry_call_function(cb->js_callback, chrc->chrc_obj, NULL, 0);
469-
if (jerry_value_has_error_flag(rval)) {
469+
if (jerry_value_is_error(rval)) {
470470
DBG_PRINT("failed to call onNotify function\n");
471471
}
472472
}
@@ -1212,7 +1212,7 @@ static ZJS_DECL_FUNC(zjs_ble_set_services)
12121212
ZVAL arg = success ? ZJS_UNDEFINED
12131213
: jerry_create_string("failed to register services");
12141214
ZVAL rval = jerry_call_function(argv[1], ZJS_UNDEFINED, &arg, 1);
1215-
if (jerry_value_has_error_flag(rval)) {
1215+
if (jerry_value_is_error(rval)) {
12161216
DBG_PRINT("failed to call callback function\n");
12171217
}
12181218
}

src/zjs_callbacks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ void zjs_call_callback(zjs_callback_id id, const void *data, u32_t sz)
523523
if (!jerry_value_is_undefined(cb_map[id]->js_func)) {
524524
rval = jerry_call_function(cb_map[id]->js_func,
525525
cb_map[id]->this, values, sz);
526-
if (jerry_value_has_error_flag(rval)) {
526+
if (jerry_value_is_error(rval)) {
527527
#ifdef INSTRUMENT_CALLBACKS
528528
DBG_PRINT("callback %d had error; creator: %s, "
529529
"caller: %s\n",

src/zjs_event.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static ZJS_DECL_FUNC(add_listener)
136136
jerry_value_t rval = zjs_add_event_listener(this, name, argv[1]);
137137
zjs_free(name);
138138

139-
if (jerry_value_has_error_flag(rval)) {
139+
if (jerry_value_is_error(rval)) {
140140
return rval;
141141
}
142142

@@ -422,7 +422,7 @@ bool zjs_emit_event_priv(jerry_value_t obj, const char *event_name,
422422
listener_t *listener = event->listeners;
423423
while (listener) {
424424
ZVAL rval = jerry_call_function(listener->func, obj, argv, argc);
425-
if (jerry_value_has_error_flag(rval)) {
425+
if (jerry_value_is_error(rval)) {
426426
ERR_PRINT("error calling listener\n");
427427
}
428428
listener = listener->next;

src/zjs_gfx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static jerry_value_t zjs_gfx_call_cb(u32_t x, u32_t y, u32_t w, u32_t h,
188188
jerry_value_t ret = jerry_call_function(gfxHandle->drawDataCB,
189189
gfxHandle->jsThis, args, 5);
190190

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

274274
ret = zjs_gfx_call_cb(xStart, yStart, currW, currH,
275275
recBufObj, gfxHandle);
276-
if (jerry_value_has_error_flag(ret)) {
276+
if (jerry_value_is_error(ret)) {
277277
zjs_gfx_reset_touched_pixels(gfxHandle);
278278
return ret;
279279
}
@@ -625,7 +625,7 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_string)
625625

626626
ret = zjs_gfx_draw_char_priv(x, argData.coords[1], argData.text[i],
627627
argData.color, argData.size, handle);
628-
if (jerry_value_has_error_flag(ret)) {
628+
if (jerry_value_is_error(ret)) {
629629
return ret;
630630
}
631631

src/zjs_grove_lcd_ipm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static jerry_value_t zjs_glcd_call_remote_function(zjs_ipm_message_t *send)
7575
static jerry_value_t zjs_glcd_call_remote_ignore(zjs_ipm_message_t *send)
7676
{
7777
ZVAL rval = zjs_glcd_call_remote_function(send);
78-
if (jerry_value_has_error_flag(rval))
78+
if (jerry_value_is_error(rval))
7979
return rval;
8080

8181
return ZJS_UNDEFINED;
@@ -231,7 +231,7 @@ static ZJS_DECL_FUNC(zjs_glcd_init)
231231
send.type = TYPE_GLCD_INIT;
232232

233233
ZVAL result = zjs_glcd_call_remote_function(&send);
234-
if (jerry_value_has_error_flag(result)) {
234+
if (jerry_value_is_error(result)) {
235235
return result;
236236
}
237237

src/zjs_modules.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static bool javascript_eval_code(const char *source_buffer, ssize_t size,
5050
jerry_value_t *ret_val)
5151
{
5252
(*ret_val) = jerry_eval((jerry_char_t *)source_buffer, size, false);
53-
if (jerry_value_has_error_flag(*ret_val)) {
53+
if (jerry_value_is_error(*ret_val)) {
5454
ERR_PRINT("failed to evaluate JS\n");
5555
return false;
5656
}
@@ -114,7 +114,7 @@ static bool load_js_module_fs(const jerry_value_t module_name,
114114
}
115115

116116
(*result) = jerry_eval((jerry_char_t *)str, len, false);
117-
if (jerry_value_has_error_flag(*result)) {
117+
if (jerry_value_is_error(*result)) {
118118
ERR_PRINT("failed to evaluate JS\n");
119119
ret = false;
120120
} else {
@@ -202,7 +202,7 @@ static ZJS_DECL_FUNC(native_require_handler)
202202

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

285-
if (!jerry_value_has_error_flag(parsed_code)) {
286+
if (!jerry_value_is_error(parsed_code)) {
286287
ZVAL ret_value = jerry_run(parsed_code);
287-
if (jerry_value_has_error_flag(ret_value)) {
288+
if (jerry_value_is_error(ret_value)) {
288289
ERR_PRINT("Error running JS\n");
289290
}
290291
}

src/zjs_sensor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void zjs_sensor_trigger_change(jerry_value_t obj)
171171
ZVAL event = zjs_create_object();
172172
// if onreading exists, call it
173173
ZVAL rval = jerry_call_function(func, obj, NULL, 0);
174-
if (jerry_value_has_error_flag(rval)) {
174+
if (jerry_value_is_error(rval)) {
175175
ERR_PRINT("Error calling onreading\n");
176176
}
177177
}

src/zjs_util.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ bool zjs_obj_get_boolean(jerry_value_t obj, const char *name, bool *flag)
217217
ZVAL value = zjs_get_property(obj, name);
218218
bool rval = false;
219219

220-
if (!jerry_value_has_error_flag(value) && jerry_value_is_boolean(value)) {
220+
if (!jerry_value_is_error(value) && jerry_value_is_boolean(value)) {
221221
*flag = jerry_get_boolean_value(value);
222222
rval = true;
223223
}
@@ -237,7 +237,7 @@ bool zjs_obj_get_string(jerry_value_t obj, const char *name, char *buffer,
237237
ZVAL value = zjs_get_property(obj, name);
238238
bool rval = false;
239239

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

257-
if (!jerry_value_has_error_flag(value) && jerry_value_is_number(value)) {
257+
if (!jerry_value_is_error(value) && jerry_value_is_number(value)) {
258258
*num = jerry_get_number_value(value);
259259
rval = true;
260260
}
@@ -269,7 +269,7 @@ bool zjs_obj_get_uint32(jerry_value_t obj, const char *name, u32_t *num)
269269
ZVAL value = zjs_get_property(obj, name);
270270
bool rval = false;
271271

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

287-
if (!jerry_value_has_error_flag(value) && jerry_value_is_number(value)) {
287+
if (!jerry_value_is_error(value) && jerry_value_is_number(value)) {
288288
*num = (s32_t)jerry_get_number_value(value);
289289
rval = true;
290290
}
@@ -738,7 +738,7 @@ int zjs_validate_args(const char *expectations[], const jerry_length_t argc,
738738
int zjs_require_bool_if_prop(jerry_value_t obj, const char *prop, bool *result)
739739
{
740740
ZVAL value = zjs_get_property(obj, prop);
741-
if (jerry_value_is_undefined(value) || jerry_value_has_error_flag(value)) {
741+
if (jerry_value_is_undefined(value) || jerry_value_is_error(value)) {
742742
// not found; leave default
743743
return 0;
744744
}
@@ -755,7 +755,7 @@ int zjs_require_string_if_prop_map(jerry_value_t obj, const char *prop,
755755
str2int_t map[], int maxlen, int *result)
756756
{
757757
ZVAL value = zjs_get_property(obj, prop);
758-
if (jerry_value_is_undefined(value) || jerry_value_has_error_flag(value)) {
758+
if (jerry_value_is_undefined(value) || jerry_value_is_error(value)) {
759759
// not found; leave default
760760
return 0;
761761
}

0 commit comments

Comments
 (0)