Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle js_module_set_import_meta errors #843

Merged
merged 2 commits into from
Jan 22, 2025
Merged
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
12 changes: 10 additions & 2 deletions qjs.c
Original file line number Diff line number Diff line change
@@ -87,7 +87,10 @@ static JSValue load_standalone_module(JSContext *ctx)
JS_FreeValue(ctx, obj);
goto exception;
}
js_module_set_import_meta(ctx, obj, false, true);
if (js_module_set_import_meta(ctx, obj, false, true) < 0) {
JS_FreeValue(ctx, obj);
goto exception;
}
val = JS_EvalFunction(ctx, JS_DupValue(ctx, obj));
val = js_std_await(ctx, val);

@@ -116,7 +119,11 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
val = JS_Eval(ctx, buf, buf_len, filename,
eval_flags | JS_EVAL_FLAG_COMPILE_ONLY);
if (!JS_IsException(val)) {
js_module_set_import_meta(ctx, val, true, true);
if (js_module_set_import_meta(ctx, val, true, true) < 0) {
js_std_dump_error(ctx);
ret = -1;
goto end;
}
val = JS_EvalFunction(ctx, val);
}
val = js_std_await(ctx, val);
@@ -129,6 +136,7 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
} else {
ret = 0;
}
end:
JS_FreeValue(ctx, val);
return ret;
}
15 changes: 10 additions & 5 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
@@ -716,8 +716,10 @@ JSModuleDef *js_module_loader(JSContext *ctx,
js_free(ctx, buf);
if (JS_IsException(func_val))
return NULL;
/* XXX: could propagate the exception */
js_module_set_import_meta(ctx, func_val, true, false);
if (js_module_set_import_meta(ctx, func_val, true, false) < 0) {
JS_FreeValue(ctx, func_val);
return NULL;
}
/* the module is already referenced, so we must free it */
m = JS_VALUE_GET_PTR(func_val);
JS_FreeValue(ctx, func_val);
@@ -900,7 +902,8 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val,
if (JS_ResolveModule(ctx, obj) < 0)
return JS_EXCEPTION;

js_module_set_import_meta(ctx, obj, false, false);
if (js_module_set_import_meta(ctx, obj, false, false) < 0)
return JS_EXCEPTION;

return JS_EvalFunction(ctx, obj);
}
@@ -4257,15 +4260,17 @@ void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
goto exception;
if (load_only) {
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
js_module_set_import_meta(ctx, obj, false, false);
if (js_module_set_import_meta(ctx, obj, false, false) < 0)
goto exception;
}
} else {
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
if (JS_ResolveModule(ctx, obj) < 0) {
JS_FreeValue(ctx, obj);
goto exception;
}
js_module_set_import_meta(ctx, obj, false, true);
if (js_module_set_import_meta(ctx, obj, false, true) < 0)
goto exception;
val = JS_EvalFunction(ctx, obj);
val = js_std_await(ctx, val);
} else {
Loading