Skip to content

Commit

Permalink
Follow review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Oct 12, 2023
1 parent 9d67cd1 commit b10eb7a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion quickjs/ckb_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
20 changes: 15 additions & 5 deletions quickjs/qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,23 +318,33 @@ int main(int argc, const char **argv) {
switch (type) {
case RunJsWithCode:
err = eval_buf(ctx, argv[1], strlen(argv[1]), "<cmdline>", 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);
Expand Down
2 changes: 1 addition & 1 deletion tests/ckb_js_tests/test_data/fs_module_mount/main.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit b10eb7a

Please sign in to comment.