feat: install host globals natively in the runtime (#38) - #43
Merged
Conversation
Globals were installed by prepending generated JS to the user's code, which
shifted sandbox stack-trace line numbers and interpolated global names into
identifier positions. The client now sends each global as a structured
GlobalDef (bridge / string / data / shim) and the runtime installs it via the
V8 API: string/shim expressions evaluate as their own scripts, so user code
starts at line 1, and a global's name only ever travels as a string.
Adds a data-valued global kind ({ kind: 'data', value }) carried as a
WireValue and materialised natively — no more JSON.stringify-into-code.
Wire-protocol change: the `globals` field of Run/Precompile/PrefixRun is now a
List<GlobalDef>. @iso4/sandbox and the @iso4/v8-* binaries release together.
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.
Closes #38.
What
Globals are no longer installed by prepending generated JavaScript to the user's code. The client sends each global as a structured
GlobalDefand the Rust runtime installs it natively on the sandbox global object.globalson the wire changes fromList<String>(names) toList<GlobalDef>, a tagged union:bridgename(unchanged)stringexpr(expr)as its own script →object.set(name, …)data(new)WireValuewire_to_v8_value→object.set(name, …)shimshim,handlerNamehandlerName+ wrapper built by a fixed factory →object.set(name, …)Why this closes #38
object.set(or aWireValuefield), never pasted into an identifier position. This removes the injection class flagged in the issue's "Additional findings".{ kind: 'data', value }) — constants cross as aWireValueand materialise natively (same supported set as host-module data leaves), killing theJSON.stringify-into-code pattern.Hot path unchanged
For precompiled prefixes, string/data globals and shim wrappers are baked into the snapshot at
precompile()(viainstall_value_globalsin the snapshot isolate);prefix.run()only re-installs bridge stubs, exactly as before. No new per-run cost on the repeated-run path.Tests
GlobalDefkinds).Uint8Array/bigint/null) and a line-number regression test asserting a user error reports line 1 with globals configured.cargo fmtclean; clippy introduces zero new lints vsmain; eslint/tsc clean.Notes
@iso4/sandboxand the@iso4/v8-*binaries must release together (changeset marks all asminor, matching the fixed group).