Use context's globals instead of serializing there #1220
Merged
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.
#1219 was kind of ugly: it serialized the
serialize
function, parsed it in the comptime context, and then ran it there, so that it could have access to the context's globals.This PR takes what I think is a cleaner approach: run the
serialize
in our usual context, but give it access to the comptime context'sglobalThis
and check for matching objects from eitherglobalThis
.In both approaches we have to copy globals over to comptime context, because new contexts don't get the usual Node builtins, such as
URL
. (See nodejs/node#28823) I'm now doing this in the way thatnode:repl
does, which is better: it gives the comptime context access to important Node globals likefetch
,atob
,process
, etc. This also restores Node'sglobal
which seems to be global to all modules, whereasglobalThis
is local to the module, which makes sense and enables some magic interactions.