Repository navigation
Js globals reset - #227
Draft
andreaTP wants to merge 3 commits into
Draft
Js globals reset#227andreaTP wants to merge 3 commits into
andreaTP wants to merge 3 commits into
Conversation
andreaTP
force-pushed
the
js-globals-reset
branch
from
December 3, 2026 12:25
96fb6ce to
a5613f3
Compare
andreaTP
marked this pull request as ready for review
December 3, 2026 18:54
andreaTP
marked this pull request as draft
December 4, 2026 17:07
withJsGlobals(false) skips the globalThis.<module>.<function> wrappers for builtins (quickjs4j_engine included) and the exports of guest functions. Builtins stay reachable through java_invoke. The code appended after the guest library now calls the guest function through a generated table and java_invoke, so it no longer depends on those globals in either mode. Smaller fixes: - an unknown module or guest function throws IllegalArgumentException instead of NullPointerException - invoking a guest function from inside a builtin fails with a clear IllegalStateException instead of a QuickJS panic - builtins sharing a module name with invokables are no longer dropped
andreaTP
force-pushed
the
js-globals-reset
branch
from
December 4, 2026 17:37
c0605f1 to
202aefb
Compare
The guard only fired when the inner call's code was already cached, and the engine was unusable afterwards anyway. Builtins that share a module with invokables now fail fast when a name clashes with a guest function or its _set_result setter, instead of one silently replacing the other. exec and guestOutput keep the underlying exception as the cause.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Engine.builder().withJsGlobals(false). It skips the generated globals:globalThis.<module>.<function>wrappers for builtins,quickjs4j_engineincluded;Guest functions are still invoked from Java as usual, and builtins stay reachable through
java_invoke.To make that work, the code appended after the guest library now calls the guest function through a generated table and
java_invoke. It no longer readsquickjs4j_engineorglobalThis.<module>, so it works the same with the globals on or off.Smaller fixes:
IllegalArgumentExceptioninstead ofNullPointerException_set_resultsetter fails withIllegalArgumentExceptionEmbedders that build their own JavaScript API over
java_invoke, such as camel-quickjs, can usewithJsGlobals(false)instead of stubbing and restoring these globals around every script.