Skip to content

Commit ab48ede

Browse files
authored
Handle js_module_set_import_meta errors (#843)
1 parent 11b7592 commit ab48ede

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

qjs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ static JSValue load_standalone_module(JSContext *ctx)
8787
JS_FreeValue(ctx, obj);
8888
goto exception;
8989
}
90-
js_module_set_import_meta(ctx, obj, false, true);
90+
if (js_module_set_import_meta(ctx, obj, false, true) < 0) {
91+
JS_FreeValue(ctx, obj);
92+
goto exception;
93+
}
9194
val = JS_EvalFunction(ctx, JS_DupValue(ctx, obj));
9295
val = js_std_await(ctx, val);
9396

@@ -116,7 +119,11 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
116119
val = JS_Eval(ctx, buf, buf_len, filename,
117120
eval_flags | JS_EVAL_FLAG_COMPILE_ONLY);
118121
if (!JS_IsException(val)) {
119-
js_module_set_import_meta(ctx, val, true, true);
122+
if (js_module_set_import_meta(ctx, val, true, true) < 0) {
123+
js_std_dump_error(ctx);
124+
ret = -1;
125+
goto end;
126+
}
120127
val = JS_EvalFunction(ctx, val);
121128
}
122129
val = js_std_await(ctx, val);
@@ -129,6 +136,7 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
129136
} else {
130137
ret = 0;
131138
}
139+
end:
132140
JS_FreeValue(ctx, val);
133141
return ret;
134142
}

quickjs-libc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,10 @@ JSModuleDef *js_module_loader(JSContext *ctx,
716716
js_free(ctx, buf);
717717
if (JS_IsException(func_val))
718718
return NULL;
719-
/* XXX: could propagate the exception */
720-
js_module_set_import_meta(ctx, func_val, true, false);
719+
if (js_module_set_import_meta(ctx, func_val, true, false) < 0) {
720+
JS_FreeValue(ctx, func_val);
721+
return NULL;
722+
}
721723
/* the module is already referenced, so we must free it */
722724
m = JS_VALUE_GET_PTR(func_val);
723725
JS_FreeValue(ctx, func_val);
@@ -900,7 +902,8 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val,
900902
if (JS_ResolveModule(ctx, obj) < 0)
901903
return JS_EXCEPTION;
902904

903-
js_module_set_import_meta(ctx, obj, false, false);
905+
if (js_module_set_import_meta(ctx, obj, false, false) < 0)
906+
return JS_EXCEPTION;
904907

905908
return JS_EvalFunction(ctx, obj);
906909
}
@@ -4257,15 +4260,17 @@ void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len,
42574260
goto exception;
42584261
if (load_only) {
42594262
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
4260-
js_module_set_import_meta(ctx, obj, false, false);
4263+
if (js_module_set_import_meta(ctx, obj, false, false) < 0)
4264+
goto exception;
42614265
}
42624266
} else {
42634267
if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {
42644268
if (JS_ResolveModule(ctx, obj) < 0) {
42654269
JS_FreeValue(ctx, obj);
42664270
goto exception;
42674271
}
4268-
js_module_set_import_meta(ctx, obj, false, true);
4272+
if (js_module_set_import_meta(ctx, obj, false, true) < 0)
4273+
goto exception;
42694274
val = JS_EvalFunction(ctx, obj);
42704275
val = js_std_await(ctx, val);
42714276
} else {

0 commit comments

Comments
 (0)