Skip to content

[JSC] VM::DeletePropertyMode::IgnoreConfigurable deletes an element that is not configurable - #1039

Draft
robobun wants to merge 2 commits into
mainfrom
robobun/4f2d4122/ignore-configurable-deletes-an-element
Draft

robobun wants to merge 2 commits into
mainfrom
robobun/4f2d4122/ignore-configurable-deletes-an-element

Conversation

@robobun

@robobun robobun commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Draft: the owner of --isolate=modules first chooses between this route and one in Bun alone (see Notes). Bun's tests: oven-sh/bun#48630.

Problem

  • Under bun test --isolate=modules, an index key that a test file defines on a built-in without configurable stays for the later files. A fuzz run found it. The flag is in no release.
  • Bun deletes such a key in VM::DeletePropertyMode::IgnoreConfigurable. JSObject::deletePropertyByIndex() (runtime/JSObject.cpp) ignores the mode and returns false for a sparse-map entry with DontDelete.

Fix

  • In the mode, deletePropertyByIndex() removes the entry and gives the object a structure that no other object has (Structure::deleteNonConfigurableElementTransition()).
  • The structure is necessary: compiled code that folded the element is guarded only by a watchpoint or a check of its structure.
  • Verified: JSTests/stress/bun-ignore-configurable-deletes-an-element.js passes in 26 runner modes on a debug ASAN jsc. It fails without the change.
  • Self-reviewed: 4 concerns raised, 4 addressed, one in part (Notes).

Background

  • An element with attributes lives in the SparseArrayValueMap of the object's ArrayStorage.
  • The DFG folds a read of an element that is read-only and not configurable to a constant (foldGetByValOnConstantProperty(), x86 only).
  • Considered the delete in Bun's TestEnvironment.cpp: from there, only a jettison of all optimized code invalidates.

Downsides

  • A failed delete of such an element runs 27 more instructions, a delete of a configurable sparse element 2 more. Other paths: unchanged.
  • 1,094 bytes of text.
  • Not undone: such an element on a prototype leaves the realm's arrays in slow-put storage. An array loop in the next file ran about 10 times slower (debug build).
Notes

The symptom in Bun. With Object.defineProperty(Array.prototype, "7", { value: "fake" }) in one test file, the later files read fake from [][7], and Array.prototype.length stays 8: the restore cannot set it to 0 while the element is there, and it then leaves the rest of Array.prototype as the file left it. With configurable: true, with a named key, or with --isolate, the key is gone.

The choice that comes first. The restore of --isolate=modules cannot undo several changes: this key, a frozen or sealed built-in, a var, function or let that 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 branch robobun/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, and deletePropertyByIndex() 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.h describes IgnoreConfigurable as "force deletion of all properties including those that are non-configurable". JSC uses it in ProgramExecutable.cpp (a named key). Bun uses it in the restore of built-ins between test files (TestEnvironment.cpp), in spyOn (JSMockFunction.cpp) and in Error.captureStackTrace (FormatStackTraceForJS.cpp). Only the restore passes an index.

Why a structure that no other object has. foldGetByValOnConstantProperty() (dfg/DFGAbstractInterpreterInlines.h) reads SparseArrayValueMap::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.

  • With the entry removed and the structure kept, a warmed function read() { return Math[7]; } still returns the element.
  • With a structure from 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.cos and Math.sin are two such objects.
  • Structure::deleteNonConfigurableElementTransition() makes a structure for each call and adds it to no transition table, as makeListedPropertiesImmutableTransition() does. nonPropertyTransitionSlow() is not changed: its size is 2,134 bytes before and after.
  • The entry goes first and the structure second. A compiler thread that folded before the removal is invalidated by the transition, and one that reads after it finds no entry.

Why a new TransitionKind. The transition changes nothing but the StructureID. AddIndexedAccessors would set MayHaveIndexedAccessors without haveABadTime(), 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 in pristineBitsAfterTransition() with the kinds that keep the bits, and in dumpTransitionKind(). No table of the ahead-of-time compiler lists the kinds.

Why one function out of line with (object, index). With the mode read in deletePropertyByIndex() itself, the compiler keeps vm alive 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.

  • A read-only element on Math, a plain object, an array, an uncacheable and a cacheable dictionary, three times over: warmed readers return it, delete and Reflect.deleteProperty refuse it, the forced delete takes it from them, and the index can be defined again. The readers are plain, guarded by 7 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.
  • Two objects of one structure, as plain objects and as Math.cos and Math.sin: the reader of the second is compiled after the forced delete of the first, behind a check that lists both structures.
  • A writable element that is not configurable and an accessor. An element that Object.freeze() made not configurable. A named property. An array whose length can go to 0 only after the forced delete. The global object behind globalThis. A prototype of arrays: a setter defined after the forced delete is called for every store.

Tests run (debug jsc with ASAN and assertions, this change on 264cf6d, built in Bun's build graph)

  • The new file in default, no-ftl, no-llint, no-jit, no-cjit, no-cjit-validate-phases, no-cjit-collect-continuously, no-cjit-no-aso, no-cjit-no-access-inlining, eager-jettison-no-cjit, dfg-eager, dfg-eager-no-cjit-validate, ftl-no-cjit, misc-ftl-no-cjit, ftl-no-cjit-validate-sampling-profiler, ftl-no-cjit-no-put-stack-validate, ftl-no-cjit-no-inline-validate, ftl-no-cjit-osr-validation, ftl-eager, ftl-eager-no-cjit, ftl-eager-no-cjit-osr-validation, shadow-chicken, lockdown, mini-mode, and dfg-eager and ftl-eager with --collectContinuously=true: 26 of 26 pass.
  • Without the change in deletePropertyByIndex(): expected true but got false at the first forced delete (run in default and no-jit).
  • With the structure from the cached transition: 18 of 26 fail at the two objects of one structure (expected undefined but got second).
  • With the entry removed, the watchpoint of the structure fired and the structure kept: 22 of 26 fail, 21 of them at the readers that are guarded by a named property.
  • In Bun (bun test --isolate=modules: undo an index key that a file defines without configurable bun#48630, debug ASAN builds of Bun's main ccb3611f2a with WebKit 6fc709c and with this branch's preview build): the four new tests of test/cli/test/isolation.test.ts pass 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) and capture-stack-trace.test.js (77 pass) have the same counts with and without it. Earlier, on 264cf6d: with the cached transition the fourth test prints read b b.
  • Bun's CI with this branch's preview build (bun test --isolate=modules: undo an index key that a file defines without configurable bun#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.
  • This repository's CI on this branch, with main merged at 6fc709c (the commit that Bun's main built against at ccb3611f2a): all checks pass, the 7 test jobs included (3 on linux x64, 4 on linux arm64). The runner there also has the modes bytecode-cache and ftl-no-cjit-small-pool, which the list above does not have.

Where the 1,094 bytes are. deletePropertyByIndex grows by 22 bytes, the cold function deleteNonConfigurableElement is 280 and Structure::deleteNonConfigurableElementTransition is 755.

Measurements. The objects UnifiedSource-runtime-27.cpp.o (JSObject.cpp) and UnifiedSource-runtime-43.cpp.o (Structure.cpp) of 264cf6d with and without the change, from Bun's release-local configuration (clang 23, -O3, no LTO). Instructions are counted on the disassembly of both objects. perf and valgrind are not on the machine.

before after
JSObject::deletePropertyByIndex, bytes 758 780
deleteNonConfigurableElement, bytes 280
Structure::deleteNonConfigurableElementTransition, bytes 755
Structure::nonPropertyTransitionSlow, bytes 2,134 2,134
.text of the two objects, bytes 485,605 486,699
delete on Int32, Double, Contiguous storage or in the ArrayStorage vector +0 instructions
delete of an index that the sparse map does not have +0
delete of a configurable sparse element +2
delete that fails on an element with DontDelete 9 36

In Bun, with a breakpoint on the cold function:

  • 60 test files that add globals, named keys and configurable index keys, and delete array elements: 0 calls in 59 restores. A delete that fails on a frozen element calls it, and it returns false.
  • Three files, of which the first defines a key without configurable on Math, JSON, Reflect, Map.prototype and Date: 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, Object and Reflect, lookups through Object.prototype, Map and Set, 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.

holder key without configurable key with configurable: true a named key
Math 3 of 31 (mathMax, mathAbs, the reader) 0 3 of 31, the same
Object.prototype 0 0
globalThis 0 0 0

So 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. After Object.defineProperty(Array.prototype, "7", { value: "fake" }) in one file, the next file reads undefined from [][7], and [1, 2, 3] is ArrayWithSlowPutArrayStorage where it is CopyOnWriteArrayWithInt32 without that file. 200 rounds of 1,000 push calls 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.

  • The structure came from a cached transition. That is the second case under "Why a structure that no other object has". Fixed, with tests that fail on the first version.
  • The tests could not fail for the reason the change exists. Added: the two objects of one structure, the readers guarded by a named property, the cacheable dictionary. Not added: an assertion that numberOfDFGCompiles of 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 its prototype stays.
  • The table of optimized code was a count at the restore alone. It now says what 3,000 more calls add.

Not in this change.

  • Keep the elements of a frozen, sealed or non-extensible array in the ArrayStorage vector #752 adds a second place in deletePropertyByIndex() that refuses an element that is not configurable, in the vector. Whichever lands second gives that place the same call.
  • spyOn on an own element that is read-only installs nothing: SparseArrayValueMap::putDirect() refuses the overwrite. A named key works.
  • A delete of a var or function declaration of a classic script is refused in JSSymbolTableObject::deleteProperty() whatever the mode is.
  • The fold is on x86 only (webkit.org/b/134641). On arm64 the readers of the test never hold the element.
  • Upstream WebKit has the same deletePropertyByIndex().

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Preview build of d3c8cb3: autobuild-preview-pr-1039-d3c8cb30

…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
robobun force-pushed the robobun/4f2d4122/ignore-configurable-deletes-an-element branch from 6f64c96 to b58ea99 Compare November 12, 2026 13:38
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants