Skip to content

Commit e1b5978

Browse files
authored
Fix unnoticed exception in JS_DetectModule (#889)
JS_DetectModule calls JS_AddIntrinsicRegExp but that indirectly uses `ctx->global_obj` when it tries to define `globalThis.RegExp`. There is no `ctx->global_obj` however because JS_NewContextRaw doesn't create one. It raised an "not an object" TypeError that went unnoticed because there is no error checking in JS_NewGlobalCConstructor2. Using JS_AddIntrinsicRegExpCompiler is better all around because we only need to parse regexp literals, nothing more. JS_NewGlobalCConstructor2 should probably be changed to do proper error checking, and __JS_EvalInternal to return JS_EXCEPTION when an exception is pending on entry, but I'll save that for another commit.
1 parent 766d967 commit e1b5978

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

quickjs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -56285,7 +56285,7 @@ bool JS_DetectModule(const char *input, size_t input_len)
5628556285
JS_FreeRuntime(rt);
5628656286
return false;
5628756287
}
56288-
JS_AddIntrinsicRegExp(ctx); // otherwise regexp literals don't parse
56288+
JS_AddIntrinsicRegExpCompiler(ctx); // otherwise regexp literals don't parse
5628956289
val = __JS_EvalInternal(ctx, JS_UNDEFINED, input, input_len, "<unnamed>", 1,
5629056290
JS_EVAL_TYPE_MODULE|JS_EVAL_FLAG_COMPILE_ONLY, -1);
5629156291
if (JS_IsException(val)) {

0 commit comments

Comments
 (0)