Repository navigation
refactor(codemode): extensions are host functions only - #49196
Merged
Merged
Conversation
rekram1-node
force-pushed
the
extensions-functions
branch
from
September 15, 2026 18:34
03ad6c6 to
c8fbec4
Compare
This was referenced Sep 15, 2026
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
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.
An extension is a set of named host functions. Arguments come in as copies, results go out as copies, and a function inside a result is callable the same way. The class mirror (constructors, prototype walk, statics, accessors,
Handle, brand checks) is deleted.Why
A leak audit of
extensions.tsfound both rank-1 host-corruption paths in the reflection layer, not the copy seam: static lookup walked past exposed classes intoEventEmitter/Object, and a sloppy constructor called withoutnewran withthis === globalThis. Every embeddable runtime (QuickJS, V8 templates, workerd, JSI, Deno ops, Lua userdata, WIT resources) registers functions one at a time and never discovers members by walking a prototype chain. This PR moves to that shape.What changes
Extension.make({ name, globals }) globals values: - class → mirrored: constructor, prototype methods, statics, accessors, inheritance, - per-run prototypes, Handle wrapping, WeakMap identity, brand checks function → callable; args copied in, result copied out + function inside a result → callable, same rules, named by path in diagnostics (`fetch.json`)What an extension looks like now
The closure is the handle: host state stays in the host closure, the program never holds a host object, and there is no
this, no brand check, and nothing to reflect over.Date,RegExp,URL,URLSearchParams,Map,Set,Uint8Array,ErrorTypeErrorArrayBuffer,ErrorNativeTypeErrorLost
new X(),instanceof X, and accessors on host objects. If a program ever needs to construct host objects, the next step is a declared method table, not a prototype walk.Checks
bun test5119 pass / 0 fail (extensions.test.ts28 → 22, class cases replaced by nested-function cases)bun run checkgreeninterpreter-support.mdExtensions section rewritten