Repository navigation
Conversation
Web IDL makes the operations and attributes of an interface configurable. The members of TextDecoder, Blob, File, Request, Response and Crypto were not, so a program could not redefine or delete one, or replace a getter. They have been locked since ed72bee and f947987 (bun-v0.5.6). Today the lock is the default of a bindgen class, which a schema lifts with `configurable: true`. - Set `configurable: true` on the schemas of TextDecoder, Blob, Request, Response and Crypto. - Drop DontDelete from the four accessors that tables written by hand add to a web interface: Headers.prototype.count, FormData.prototype.length, URLSearchParams.prototype.length and Worker.prototype.threadId. - Define `Crypto.prototype.subtle` when the class is set up, without DontDelete. It was defined when the `crypto` object was made, over any definition that a program had made before. - Keep the cached getters of a locked prototype in the table of built-ins that `bun build --compile --aot` reads. The table stays as it is.
Pre-merge checks:
|
|
Updated 10:48 PM PT - Nov 11th, 2026
✅ @robobun, your commit d55c1d644b12f1470240f78670cd19904a330e81 passed in 🧪 To try this PR locally: bunx bun-pr 48540That installs a local version of the PR into your bun-48540 --bun |
|
Status Reproduced on main (98cda0d and 89452d2), release and debug builds, linux-x64: const real = TextDecoder.prototype.decode;
Object.defineProperty(TextDecoder.prototype, "decode", {
value(...args) { return "wrapped " + real.apply(this, args); },
writable: true,
configurable: true,
});
// main: TypeError: Attempting to change configurable attribute of unconfigurable property.
// this PR and Node v26.3.0: new TextDecoder().decode(new Uint8Array([97])) === "wrapped a"The same script lists With vitest 4.1.9 on main, The new tests fail on main and pass on this branch. The description asks a maintainer two things. First, to confirm that the lock from ed72bee can go for the web interfaces. Second, where the reads of |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline findings, I also checked the initLater override for JSCrypto in src/jsc/bindings/ZigGlobalObject.cpp: it is the statement directly after m_bindgenAdditions.initialize(), which only stores a per-class callback (src/jsc/bindings/Bindgen/AdditionsToGlobalObject.cpp), nothing calls get on that structure in between, and src/runtime/webcore/Crypto.bind.ts declares no subtle row, so there is no duplicate definition or ordering hazard. The regenerated own-properties.txt matches the four hand-written table edits (length/count flip to ac; FormData from/toJSON stay locked). I did not run the test suite or the --aot table generator, so the "byte-identical table" claim is unverified here.
Extended reasoning...
The change flips configurable: true on five bindgen schemas, removes DontDelete from four hand-written WebCore accessors, moves the Crypto.prototype.subtle custom accessor into a LazyClassStructure initializer override, and adjusts the AOT builtins table rule in collect-bindgen.ts; no injection, auth or data-exposure surface is touched. Two inline findings (Worker.threadId reliance in node:worker_threads, a typecheck error in the vitest test) are posted, and the PR itself reverses a 2023 maintainer decision on property attributes, so a human decision is needed regardless.
node:worker_threads reads threadId from the web Worker that it wraps and routes the messages between threads by it. No standard has the member, so it stays as it is on main. The walk in web-globals.test.js expects exactly the three members that stay locked. Type the file map that createVitestProject takes.
There was a problem hiding this comment.
I re-reviewed the PR after the second commit and found no bugs; both points from my earlier review are addressed (Worker.prototype.threadId stays DontDelete and the walk test lists it, and createVitestProject now takes Record<string, string>). Since the PR itself asks a maintainer to decide whether to reverse ed72bee for the web interfaces, a human look is still the right next step.
What was reviewed:
- The
JSCryptoinitializer override insrc/jsc/bindings/ZigGlobalObject.cpp: it replaces theinitLaterthatAdditionsToGlobalObject::initialize()installs, calls the generatedsetupCryptoClassStructure(which runsinit.setPrototype) before touchinginit.prototype, and the getter still resolves the singleton throughcryptoObject()outside the initializer, so no re-entrancy. cachedFieldOfincollect-bindgen.tsagainstisLocked/lockedMembers: Blob, Request and Response keep their cached fields; TextDecoder and Crypto are unlocked and follow redefinition, matching the new fixed-run and parallel AOT fixtures.- The four hand-written hash-table rows and
own-properties.txt/snapshot updates line up with the.bind.tschanges;FormData.fromandFormData.prototype.toJSONremain locked as stated. - Not run here: the codegen and the AOT builtins-table comparison, so the claim that the 13 table files stay byte-identical rests on the PR description.
Extended reasoning...
The change flips configurable: true on five bindgen schemas (Blob, Crypto, TextDecoder, Request, Response), drops DontDelete from four hand-written WebCore accessor rows, moves the Crypto.prototype.subtle custom accessor from the lazy crypto global initializer into the JSCrypto lazy class-structure initializer, and adjusts cachedFieldOf so locked prototypes keep cached-getter reads under --aot. It touches no auth or injection surface; the crypto-adjacent change is only property attributes on Crypto.prototype. Both findings from the earlier review were addressed in commit d55c1d6, the bug hunt ran to a dry streak, and the test additions span node:test, vitest, web-crypto subprocess cases and AOT fixtures. Approval is withheld because the PR explicitly asks a maintainer to ratify reversing a 2023 decision that locked these members, and because the JSC binding and codegen edits are owned areas where the generated output and table-identity claims were not reproduced in this run.
Problem
TextDecoder,Blob,File,Request,ResponseorCryptocan be redefined or deleted.Object.defineProperty(TextDecoder.prototype, "decode", { value, configurable: true })throwsTypeError: Attempting to change configurable attribute of unconfigurable property.Under vitest,vi.spyOn(crypto, "randomUUID")stays aftervi.restoreAllMocks().Fix
configurable: trueon the five bindgen schemas, and dropDontDeletefrom three hand-written accessors. 70 properties change.Crypto.prototype.subtlewith the class. Before, creatingcryptodefined it over a program's own definition.cachedFieldOfkeeps the cached getters of a locked prototype: the--aottable stays byte-identical.test/js/web/web-globals.test.jsand four more files: 12 new tests fail on main. Self-reviewed: 20 concerns raised, 19 addressed (notes).Background
.bind.tsschema. By default its rows getDontDelete, which means not configurable (src/codegen/bindgen-lib-internal.ts:3879).--aotreads a cached getter (request.url) from a field.lockedMembers: ["prototype"]makes an executable refuse such changes.Downsides
TypeErrorchanges. Bun's own code reads a replaced getter in the places that the notes list. One of them,new Request(request, init), differs from Node.js. It must be closed before this merges.Worker.prototype.threadIdstill stay..text+256 B,.rodata+0 B. Getter reads: 1,353.08 M instructions, 1,353.09 M on main.Notes
Supersedes #40617, which did this for
Cryptoalone against the generator that #46329 deleted. Related to #40612.Questions for a maintainer
configurable: falseonTextDecoder,Request,ResponseandBlob, and f947987 made it the default of the generator. The members were configurable through bun-v0.5.5. fix(web): make URLSearchParams.prototype.size configurable #25762 lifted the lock forURLSearchParams.prototype.sizewith Web IDL as the reason.configurabletest incachedFieldOflooks more careful than the compiler needs: in every run below, an executable refuses or follows each change to a member that compiled code reads. This PR keeps the test and adds&& !isLocked(type), so the table does not move. Without the test,SocketAddressgains two cached getters (107 to 109) and five table files change. That is for the owner of the compiler to decide.cachedFieldOfthe table generator fails.new Request(request, init)get closed? See "Members that Bun's own code reads by name". They can be three input-gated arms in the rewrite of http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528, whoseconstruct_intopassesrequest: Noneand still readsurl,signaland a null or used body by name. Or they can be a change to main's loop that lands with this PR. This PR must not merge before one of them.Who meets the lock (main 98cda0d, this branch, Node v26.3.0)
vi.spyOn(crypto, "randomUUID"),vi.spyOn(response, "ok", "get"),vi.spyOn(TextDecoder.prototype, "encoding", "get"), each withvi.restoreAllMocks()): main 0 of 3, this branch 3 of 3, Node 3 of 3.@vitest/spydefines the spy on the object with the attributes of the inherited member and removes it withReflect.deleteProperty(), which answersfalsefor a property that is not configurable.node:test,t.mock.getter()thent.mock.restoreAll()onTextDecoder#encoding,Blob#size,Request#url,Response#ok: main 0 of 4 (TypeError: Attempting to change the getter of an unconfigurable property.), this branch 4 of 4, Node 4 of 4.TypeErrorandfalse false false false | true. This branch printswrapped aandtrue true true true | true, as Node does.Object.defineProperty()withvaluealone, andspyOnofbun:test, which installs natively.Crypto.prototype.subtlecryptoglobal defines it, withDontDelete. JSC runs that initializer when it links a code block that namescrypto, so the accessor can arrive before or after a definition of the program.ASSERTION FAILED: !hadPropertyinJSObject::putDirectCustomAccessor.--aotexecutable on main has nosubtleon the prototype untilcryptois read.AllowLazyMaterializationOfImmutablePropertiesscope is needed. A build without it givescrypto.subtle === undefinedin an--aotexecutable that only reads it.What stays locked on a web interface
FormData.fromandFormData.prototype.toJSON. They are read-only functions that Bun calls by name:Bun.readableStreamToFormData()the first,console.log()of aFormDatathe second.Worker.prototype.threadId.node:worker_threadsreads it from the webWorkerthat it wraps, a private field, and routes the messages between threads by it (src/js/node/worker_threads.ts:962). The first revision of this PR unlocked it, and a review found that a program could then redirect that routing.--aot, what the prototypes ofRequest,ResponseandBlobhave stays read-only, asdocs/compiler/compatibility.mdxsays.bun runand an executable now differ for them as they do forHeadersandURL.paramsandcookiesof the request that aBun.serveroute gets belong to a class of Bun's own.Members that Bun's own code reads by name
A getter that a program redefines or deletes reaches these readers. None of them is closed in this PR.
new Request(request, init):url,signaland an empty or usedbody(src/runtime/webcore/Request.rs:1182,:1216,:1260). This is the one place where this PR moves Bun away from Node.js. Afterdelete Request.prototype.urlthe copy throwsFailed to construct 'Request': url is required., aurlgetter gives the copy its own answer, asignalgetter that answers a string throws, and abodygetter that throws makes the copy throw. Node v26.3.0 copies the real request in all four.new Request(request)andrequest.clone()are not affected.bun:testspy onRequest.prototype.urlgives the copy the mock's URL on main. Akeepalivegetter that a program adds toRequest.prototypemakes the copy of a request with an empty body throwTypeError: keepaliveon 1.4.3-canary.Requestis the input. Getter calls on the input went from 3 to 0. In a table of 14 call forms and 144 prototype changes, a change steered the result in 68 rows before and in 28 after, all 28 with aRequestorResponsein the place ofinit, where Node.js reads by name too (42 rows). The 14 rows without a change stayed the same.robobun/110698b9/request-input-own-state. It is not a PR. Its self-review found two things. A native copy of the signal loses the abort reason after a collection:fetch()of the copy rejects withundefinedwhere main givesTimeoutError, because only the JS object of the signal keeps the reason alive. And http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528 rewrites this function. So the fix waits for question 4.Requestwith an own property or of a subclass:new Request()andfetch()read every member by name, the rule of SvelteKit fetch issue #4718. A getter that is redefined onRequest.prototypenow reaches them too. webcore: copy internal state in new Request(request) instead of calling getters #37033 covers them.RequestorResponsein the place ofinit:url,signaland a null or empty body are read by name. Node.js readsinitby name too.undici.request()readsstatus,headers,bodyandbodyUsedof its ownResponse(src/js/thirdparty/undici.ts:68,:71,:233). With astatusgetter that answers 500, a 201 response givesstatusCode500.node:cryptoreadscrypto.subtleonce when it loads (src/js/node/crypto.ts:233). A getter that throws stopsrequire("node:crypto"). An own property oncryptodoes the same on 1.4.3-canary.req.cookiesof aBun.serveroute readsheadersof a request that the program holds (src/jsc/bindings/JSBunRequest.cpp:242).signalgetter onRequest.prototype,request.clone()throwsTypeError: Invalid value used as weak map key. Bun gives the real request.bun test --isolate=modulesThe runner puts back what a test file changed on the shared global object (
src/js/internal/test/globals.ts). These members now take part in that.Response.jsonthat a file replaces and makes read-only is put back. On main the replacement stays, because the runner skips a property that is neither configurable nor writable.Headers.prototype.geton main.Not in this PR
Timeout,Immediate,net.BlockList,module.SourceMap, the zlib handles. Node makes their members configurable and most of them non-enumerable, so they need more than this key. 40 members on 12 holders still differ from Node v26.3.0 inconfigurable(93 on 18 on main).server.publishstill stays.Measurements (linux-x64)
The size, instruction and attribute numbers are from this branch on 98cda0d. The row counts and the table comparison were taken again after the rebase onto 89452d2.
DontDelete: 1428 to 1361. Four generated files change, and each changed line loses only that token. Three rows in tables written by hand lose it too.--aot: cached getters 107 to 107 (101 without theisLockedclause). 13 of 13 generated table files have the sha256 of main's, also afterown-properties.txtwas regenerated (8 lines).Worker.prototype.threadId: 71 became configurable (70 withoutthreadId),Crypto.prototype.subtleis new before the first read ofcrypto, nothing else changed.size -A:.text+256 B,.rodata+0 B, file +4,096 B (one page). No host function added.BUN_JSC_useConcurrentJIT=0. A loop of 5,000,000 iterations that reads six getters: main median 1,353,088,356 (range 42,836), this branch 1,353,079,184 (range 35,895). An empty script: main 3,695,758 (range 22,077), this branch 3,697,512 (range 24,393).perfandvalgrindare not on the machine, so a small program opened the counter withperf_event_open.CustomGetterSettercells: +1 afterCryptois touched (main +0), +1 after the first read ofcrypto(main +1), 37 at start on both.Ahead-of-time compiler
test/aot/parallel/host-classes/replaced-prototype-getters.tsgains rows.TextDecoder.encoding: the executable reads every redefinition, deletion and restore as plain Bun does.Request.urlandResponse.statusText: each change throwsCannot assign to Request.prototype.url because built-in objects are read-only in a compiled executable.TextDecoder.fatalandCrypto.subtle: a change under a name that the build cannot read is refused.replaced-methods-and-statics.ts(new) does the same fordecode,randomUUID,Response.json,Response.redirectand the lockedResponse.prototype.clone.spelled-out-changes-of-host-members.mjs(new) writes the object and the name out. All three pass as written, with types erased, with failing speculations and with proof checks, and fail on main.test/aot/fixed-runs/closed/getters-kept-in-a-field-redefined-by-a-test.txt(new): underbun test --aot, typed reads ofRequest.url,Response.statusTextandTextDecoder.encodingfollow a definition, a deletion and a restore as underbun test. It fails on main.test/aot/fuzz/grids/tests-write-on-every-accessor-of-built-in-classes.ts, withCryptono longer left out, prints the same 639 lines underbun test --isolateandbun test --aot --isolate.bun test --aot: a getter spy onTextDecoder.prototype.encodingthrough an object that the build cannot read is now taken, and the compiled read sees it. main refuses it withCannot spy on TextDecoder.prototype.encoding.Self-review
20 concerns, 19 addressed. The scope changed with it:
Timeout,Immediateandnet.BlockListleft this PR, and the accessors ofHeaders,FormDataandURLSearchParamscame in. Not done: a stored test-run row that fails on main for the getter spy above. Inside the shared projects oftest/aot/fixed-runsmain takes that spy too, so the row would prove nothing.Tests
test/js/web/web-globals.test.js: every function and accessor of every global interface is configurable but for the three that stay locked, and a matrix of redefine, replace, delete and restore on eight interfaces.test/js/web/crypto/web-crypto.test.ts: six orders of reading and writingsubtle.test/js/node/test_runner/node-test.test.tswith a fixture that also passes under Node.test/js/third_party/vitest/vitest.test.ts: the three vitest cases.test/internal/builtins-table/direct-entries-of-getters.test.ts: the rule ofcachedFieldOf.own-properties.test.ts,fixed-runs-closed.test.ts,mock-fn.test.js,visible-surface.test.ts, the fetch, FormData, Headers, URLSearchParams and worker suites,isolation.test.ts.no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/web/web-globals.test.js