Skip to content

Conversation

@bnoordhuis
Copy link
Contributor

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.

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.
@saghul
Copy link
Contributor

saghul commented Feb 6, 2025

Fun fact, I saw something weird happening when I was working on the build_backtrace refactor, but forgot to check again after I got it working with -m 😅

@bnoordhuis bnoordhuis merged commit e1b5978 into quickjs-ng:master Feb 6, 2025
59 checks passed
@bnoordhuis bnoordhuis deleted the fix-js-detect-module branch February 6, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants