Repository navigation
Conversation
|
Preview build of d3c8cb3: |
…hat is not configurable JSObject::deleteProperty() reads the mode for a named property only. For an index it calls deletePropertyByIndex(), and that returned false for an entry of the sparse map with DontDelete whatever the mode was. In the mode, deletePropertyByIndex() now removes the entry and gives the object a structure that no other object has, of the new TransitionKind::DeleteNonConfigurableElement. The DFG folds a read of an element that is read-only and not configurable into the code (foldGetByValOnConstantProperty() in DFGAbstractInterpreterInlines.h) and guards that code with the structure of the object alone, by a watchpoint or by a check. A check can list several structures. So Structure::deleteNonConfigurableElementTransition() puts the new structure in no transition table: a second object of the same structure gets another one, which no compiled code lists. The entry goes first: a compiler thread that reads the map after that finds nothing to fold. The new code is one function out of line, which takes the object and the index. A delete that finds no such element runs the instructions it ran. $vm.deletePropertyIgnoringConfigurable(object, key) deletes in the mode, for JSTests/stress/bun-ignore-configurable-deletes-an-element.js.
robobun
force-pushed
the
robobun/4f2d4122/ignore-configurable-deletes-an-element
branch
from
November 12, 2026 13:38
6f64c96 to
b58ea99
Compare
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Nov 12, 2026
The preview is WebKit 6fc709c2984, the commit that main built against at ccb3611, plus that pull request. Before this branch merges, the value has to be that pull request's commit on WebKit's main.
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.
Draft: the owner of
--isolate=modulesfirst chooses between this route and one in Bun alone (see Notes). Bun's tests: oven-sh/bun#48630.Problem
bun test --isolate=modules, an index key that a test file defines on a built-in withoutconfigurablestays for the later files. A fuzz run found it. The flag is in no release.VM::DeletePropertyMode::IgnoreConfigurable.JSObject::deletePropertyByIndex()(runtime/JSObject.cpp) ignores the mode and returns false for a sparse-map entry withDontDelete.Fix
deletePropertyByIndex()removes the entry and gives the object a structure that no other object has (Structure::deleteNonConfigurableElementTransition()).JSTests/stress/bun-ignore-configurable-deletes-an-element.jspasses in 26 runner modes on a debug ASANjsc. It fails without the change.Background
SparseArrayValueMapof the object'sArrayStorage.foldGetByValOnConstantProperty(), x86 only).TestEnvironment.cpp: from there, only a jettison of all optimized code invalidates.Downsides
deleteof such an element runs 27 more instructions, adeleteof a configurable sparse element 2 more. Other paths: unchanged.Notes
The symptom in Bun. With
Object.defineProperty(Array.prototype, "7", { value: "fake" })in one test file, the later files readfakefrom[][7], andArray.prototype.lengthstays 8: the restore cannot set it to 0 while the element is there, and it then leaves the rest ofArray.prototypeas the file left it. Withconfigurable: true, with a named key, or with--isolate, the key is gone.The choice that comes first. The restore of
--isolate=modulescannot undo several changes: this key, a frozen or sealed built-in, avar, function orletthat a script declares, and the engine state below. This change undoes the first one in place. A route in Bun alone is written on the branchrobobun/ec67d1aa/isolate-modules-fresh-global-after-lock(fa6c706e94d, 11 files, no pull request, not built by me): it detects such changes and gives the next files a new global object. It names this key too, and a refused delete is one of its triggers. With both as they are, this change removes that trigger. So the two need one decision: this route, that route, or both with the other branch keyed on the state and not on the refusal.What oven-sh/bun#44833 says about a key of this kind. A comment there answers a report of the same kind for a name: after
Object.defineProperty(globalThis, "fetch", { value, writable: true, configurable: false })the next file saw the stub and every property added after it. Its fix is the forced delete: "a property that was configurable in the snapshot is deleted before it's redefined, whether or not it's writable now". It names one change that the restore cannot undo: a frozen or non-extensible built-in. For an index key the restore calls the same forced delete, anddeletePropertyByIndex()refuses it. oven-sh/bun#48686 (open) puts properties back on a built-in that a file locked, and says that it leaves an index key as the file left it.Who uses the mode.
VM.hdescribesIgnoreConfigurableas "force deletion of all properties including those that are non-configurable". JSC uses it inProgramExecutable.cpp(a named key). Bun uses it in the restore of built-ins between test files (TestEnvironment.cpp), inspyOn(JSMockFunction.cpp) and inError.captureStackTrace(FormatStackTraceForJS.cpp). Only the restore passes an index.Why a structure that no other object has.
foldGetByValOnConstantProperty()(dfg/DFGAbstractInterpreterInlines.h) readsSparseArrayValueMap::getConcurrently()and registers no watchpoint for the element. It requires only that the structure set of the constant is finite, by a watchpoint or by a check.function read() { return Math[7]; }still returns the element.Structure::nonPropertyTransition(), which takes a cached transition, two objects of one structure come to the same new structure. Code that was compiled in between checks for both structures and keeps the element of the second object. The first version of this pull request did that.Math.cosandMath.sinare two such objects.Structure::deleteNonConfigurableElementTransition()makes a structure for each call and adds it to no transition table, asmakeListedPropertiesImmutableTransition()does.nonPropertyTransitionSlow()is not changed: its size is 2,134 bytes before and after.Why a new TransitionKind. The transition changes nothing but the StructureID.
AddIndexedAccessorswould setMayHaveIndexedAccessorswithouthaveABadTime(), so a setter that a prototype gets later would not be called for stores to arrays.convertToDictionary()asserts on an uncacheable dictionary. The new kind is listed inpristineBitsAfterTransition()with the kinds that keep the bits, and indumpTransitionKind(). No table of the ahead-of-time compiler lists the kinds.Why one function out of line with
(object, index). With the mode read indeletePropertyByIndex()itself, the compiler keepsvmalive through the sparse lookup and moves registers in the entry block of every call. With the call as it is, the disassembly of both objects differs only inside the sparse-map arm.What the stress test holds.
Math, a plain object, an array, an uncacheable and a cacheable dictionary, three times over: warmed readers return it,deleteandReflect.deletePropertyrefuse it, the forced delete takes it from them, and the index can be defined again. The readers are plain, guarded by7 in holder, inlined into a loop, and guarded by a named property ("named" in holder). The last kind is new in each round, with a text of its own, so that its code checks the structure of the holder in every round.Math.cosandMath.sin: the reader of the second is compiled after the forced delete of the first, behind a check that lists both structures.Object.freeze()made not configurable. A named property. An array whoselengthcan go to 0 only after the forced delete. The global object behindglobalThis. A prototype of arrays: a setter defined after the forced delete is called for every store.Tests run (debug
jscwith ASAN and assertions, this change on 264cf6d, built in Bun's build graph)--collectContinuously=true: 26 of 26 pass.deletePropertyByIndex():expected true but got falseat the first forced delete (run in default and no-jit).expected undefined but got second).configurablebun#48630, debug ASAN builds of Bun's main ccb3611f2a with WebKit 6fc709c and with this branch's preview build): the four new tests oftest/cli/test/isolation.test.tspass with the preview build, and 0 of 4 pass without the change.mock-fn.test.js(848 pass),spyMatchers.test.ts(150 pass, 3 todo) andcapture-stack-trace.test.js(77 pass) have the same counts with and without it. Earlier, on 264cf6d: with the cached transition the fourth test printsread b b.configurablebun#48630, build 140811): the 186 jobs that ran pass, the tests on Linux, Windows and macOS arm64 included. Two macOS x64 test jobs found no agent, the one with the new tests among them.Where the 1,094 bytes are.
deletePropertyByIndexgrows by 22 bytes, the cold functiondeleteNonConfigurableElementis 280 andStructure::deleteNonConfigurableElementTransitionis 755.Measurements. The objects
UnifiedSource-runtime-27.cpp.o(JSObject.cpp) andUnifiedSource-runtime-43.cpp.o(Structure.cpp) of 264cf6d with and without the change, from Bun'srelease-localconfiguration (clang 23,-O3, no LTO). Instructions are counted on the disassembly of both objects.perfandvalgrindare not on the machine.JSObject::deletePropertyByIndex, bytesdeleteNonConfigurableElement, bytesStructure::deleteNonConfigurableElementTransition, bytesStructure::nonPropertyTransitionSlow, bytes.textof the two objects, bytesdeleteon Int32, Double, Contiguous storage or in the ArrayStorage vectordeleteof an index that the sparse map does not havedeleteof a configurable sparse elementdeletethat fails on an element withDontDeleteIn Bun, with a breakpoint on the cold function:
deletethat fails on a frozen element calls it, and it returns false.configurableonMath,JSON,Reflect,Map.prototypeandDate: 5 calls in the run, one for each key. Each call makes one Structure.Optimized code: 31 functions of one module (arithmetic, arrays, calls of
Math,JSON,ObjectandReflect, lookups throughObject.prototype,MapandSet, and one reader of index 7 of the holder), all compiled by the DFG in the file that defines the key. The count is of functions whose optimized code is gone in the next file before any call (numberOfDFGCompiles,reoptimizationRetryCount). After 3,000 more calls of each, one more function is compiled again in every row, the control with no key included.configurableconfigurable: trueMathmathMax,mathAbs, the reader)Object.prototypeglobalThisSo a forced delete costs in optimized code what the delete of a named key of that object costs.
What is not undone. A read-only or accessor element on a prototype calls
JSGlobalObject::haveABadTime(), which is one-way. AfterObject.defineProperty(Array.prototype, "7", { value: "fake" })in one file, the next file readsundefinedfrom[][7], and[1, 2, 3]isArrayWithSlowPutArrayStoragewhere it isCopyOnWriteArrayWithInt32without that file. 200 rounds of 1,000pushcalls and 1,000 reads took 1,130 to 1,430 ms against 100 to 137 ms on the debug build. Main has the same state after such a file.The self-review. It raised four concerns.
numberOfDFGCompilesof a reader rises across the forced delete. It stays the same in 3 of 26 modes (no-cjit-no-access-inlining, dfg-eager-no-cjit-validate, dfg-eager-collect-continuously), where the reader has no check of the structure or is not compiled again in time.$vm.deletePropertyIgnoringConfigurable()is hidden from fuzzing and the diff did not say why. A comment at its registration says so now: a proxy runs its trap in the mode, and a class constructor asserts that itsprototypestays.Not in this change.
deletePropertyByIndex()that refuses an element that is not configurable, in the vector. Whichever lands second gives that place the same call.spyOnon an own element that is read-only installs nothing:SparseArrayValueMap::putDirect()refuses the overwrite. A named key works.varor function declaration of a classic script is refused inJSSymbolTableObject::deleteProperty()whatever the mode is.deletePropertyByIndex().