From b10eb7a23b38b416bb17a89270db34719589c698 Mon Sep 17 00:00:00 2001 From: mohanson Date: Thu, 12 Oct 2023 13:14:07 +0800 Subject: [PATCH] Follow review suggestions --- quickjs/ckb_module.c | 5 ++++- quickjs/qjs.c | 20 ++++++++++++++----- .../test_data/fs_module_mount/main.js | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/quickjs/ckb_module.c b/quickjs/ckb_module.c index 9301c8f..1feab1a 100644 --- a/quickjs/ckb_module.c +++ b/quickjs/ckb_module.c @@ -463,6 +463,9 @@ static JSValue syscall_current_memory(JSContext *ctx, JSValueConst this_value, i static JSValue mount(JSContext *ctx, JSValueConst this_value, int argc, JSValueConst *argv) { JSValue buf = syscall_load_cell_data(ctx, this_value, argc, argv); + if (JS_IsException(buf)) { + return JS_EXCEPTION; + } size_t psize = 0; uint8_t *addr = JS_GetArrayBuffer(ctx, &psize, buf); int err = ckb_load_fs(addr, psize); @@ -515,7 +518,7 @@ int js_init_module_ckb(JSContext *ctx) { JS_SetPropertyStr(ctx, ckb, "current_memory", JS_NewCFunction(ctx, syscall_current_memory, "current_memory", 0)); JS_SetPropertyStr(ctx, ckb, "mount", - JS_NewCFunction(ctx, mount, "mount", 3)); + JS_NewCFunction(ctx, mount, "mount", 2)); JS_SetPropertyStr(ctx, ckb, "SOURCE_INPUT", JS_NewInt64(ctx, CKB_SOURCE_INPUT)); JS_SetPropertyStr(ctx, ckb, "SOURCE_OUTPUT", JS_NewInt64(ctx, CKB_SOURCE_OUTPUT)); JS_SetPropertyStr(ctx, ckb, "SOURCE_CELL_DEP", JS_NewInt64(ctx, CKB_SOURCE_CELL_DEP)); diff --git a/quickjs/qjs.c b/quickjs/qjs.c index f8af4ea..2760ce1 100644 --- a/quickjs/qjs.c +++ b/quickjs/qjs.c @@ -318,23 +318,33 @@ int main(int argc, const char **argv) { switch (type) { case RunJsWithCode: err = eval_buf(ctx, argv[1], strlen(argv[1]), "", 0); - js_std_loop(ctx); + if (err == 0) { + js_std_loop(ctx); + } break; case RunJsWithFile: err = run_from_cell_data(ctx, false); - js_std_loop(ctx); + if (err == 0) { + js_std_loop(ctx); + } break; case RunJsWithFileSystem: err = run_from_cell_data(ctx, true); - js_std_loop(ctx); + if (err == 0) { + js_std_loop(ctx); + } break; case RunJsWithDbgFile: err = run_from_local_file(ctx, false); - js_std_loop(ctx); + if (err == 0) { + js_std_loop(ctx); + } break; case RunJsWithDbgFileSystem: err = run_from_local_file(ctx, true); - js_std_loop(ctx); + if (err == 0) { + js_std_loop(ctx); + } break; case CompileWithFile: JS_SetModuleLoaderFunc(rt, NULL, js_module_dummy_loader, NULL); diff --git a/tests/ckb_js_tests/test_data/fs_module_mount/main.js b/tests/ckb_js_tests/test_data/fs_module_mount/main.js index a9cfe1b..4292b50 100644 --- a/tests/ckb_js_tests/test_data/fs_module_mount/main.js +++ b/tests/ckb_js_tests/test_data/fs_module_mount/main.js @@ -1,6 +1,6 @@ /* example of JS module */ -ckb.mount(2, 3) +ckb.mount(2, ckb.SOURCE_CELL_DEP) import('./fib_module.js') .then((module) => {