Skip to content

Phase 7.9: arrays and JSON built-ins - #290

Open
atiernan wants to merge 6 commits into
claude/js-builtinsfrom
claude/js-builtins-array-json
Open

atiernan wants to merge 6 commits into
claude/js-builtinsfrom
claude/js-builtins-array-json

Conversation

@atiernan

Copy link
Copy Markdown
Member

What this is

The second built-ins slice of phase 7 item 7.9: arrays and JSON. Stacked on #269 (claude/js-builtins, itself on #265), so the base is claude/js-builtins. tier = 0 unchanged for clazel-js-vm and clazel-js-builtins; no change to spec.rs, ops.rs, lemmas.rs, mutations.json, and clazel-json is used as is (not edited).

Continues the stopped previous agent's WIP commit (heap.rs array cell, Intrinsic::ArrayPrototype); kept what was sound, added the missing props.rs it declared, and did not squash.

In clazel-js-vm

  • props.rs: PropDesc; Vm::define_own_property (OrdinaryDefineOwnProperty / ValidateAndApplyPropertyDescriptor for data properties, and the Array exotic object's [[DefineOwnProperty]], §10.4.2.1); ArraySetLength (§10.4.2.4, incl. the non-configurable-element stop and the deferred writable: false); ArrayCreate (§10.4.2.2); CreateArrayFromList; CreateDataProperty(OrThrow); DefinePropertyOrThrow; [[Delete]] / DeletePropertyOrThrow; SameValue; IsArray.
  • Array elements are ordinary shape properties plus length in slot 0 (the heap's elements are Phase 7.5: clazel-js-heap elements and symbols (second slice) #211, not on this base), so a huge sparse index or a long shift is slow, not wrong.
  • Array [[Set]] goes through [[DefineOwnProperty]] for length and indices; inline-cache stores never hit an array.
  • Handlers: NewArray, DeleteProp, and DefineProp / DefineElem on arrays. The compiler now sets length for trailing elisions of a literal ([1,,] had length 2).
  • A bound of 150 on natives nested inside natives (a cyclic join is a RangeError, not a host stack overflow).
  • Intrinsic::ArrayConstructor; Vm::strict_equals is public.

In clazel-js-builtins

  • array.rs: Array (§23.1.1.1), Array.isArray, Array.of; Array.prototype (itself an array): push pop shift unshift slice splice concat join toString indexOf lastIndexOf includes reverse fill forEach map filter some every reduce reduceRight find findIndex sort (stable merge sort, SortCompare §23.1.3.30.2), each citing its algorithm and steps. The methods are generic over array-likes, as the standard writes them.
  • json.rs: JSON.parse over clazel-json's parser (reviver = InternalizeJSONProperty, §25.5.1.1) and JSON.stringify (§25.5.2: replacer function and array, space/gap with wrappers, toJSON, wrapper unwrapping, the cycle TypeError, QuoteJSONString from clazel-json).
  • Object.defineProperty now uses the VM's [[DefineOwnProperty]]; Object.keys returns a real array; Object.prototype.toString tags arrays.

Left for later (listed)

  • Not done, needs Symbols and iterators: Array.from, entries, keys, values, @@iterator, @@species, @@isConcatSpreadable, @@unscopables. ArraySpeciesCreate uses the receiver's constructor itself where the standard reads @@species.
  • Array spread and spread arguments: the bytecode has the ops and the compiler emits them, but they go through GetIterator/IterNext, still NotYet. Array literals (with elisions) work. CreateRestArray is NotYet.
  • Not implemented here: at, copyWithin, flat, flatMap, findLast, findLastIndex, toLocaleString, change-by-copy methods.
  • Deviations: JSON.stringify stops at 128 nesting levels with a RangeError (host stack; unoptimised frames are several KB, tests run on 2 MB); JSON.parse keeps clazel-json's 512-level bound (a SyntaxError). No BigInt/Symbol steps; the reviver's source-text context argument is not passed.

Evidence

  • Test262: built-ins/Array and built-ins/JSON are not vendored (SOURCE.md: only language/ and harness/; the built-ins directories join "with the items that record their results"), and I could not download them. So there are no per-directory counts to record. The Phase 7.9: the first built-ins (Object, Function, Error, Math, Number, String, Boolean) #269 runner over the vendored subset: pass 508 -> 542, xfail 4704 -> 4670, fail 0 (total 5212); the categories "global X is missing" went 10 -> 7 and the Array tests that were blocked on Array now run. Per directory: 0 tests of built-ins/Array and 0 of built-ins/JSON exist in the table.
  • Hand-written tests (what the standard says): tests/array.rs (7 tests, about 115 script cases: exotic object semantics, ArraySetLength, constructor, every method, generic array-likes, sort stability, bounds) and tests/json.rs (2 tests, about 65 cases: grammar, reviver order, replacer, gap, cycles, depth, round trip).

Commands

  • cargo fmt: clean. cargo clippy -p clazel-js-vm -p clazel-js-builtins -p clazel-json --all-targets -- -D warnings: clean. cargo xtask check: STATIC CHECKS PASSED.
  • cargo test -p clazel-js-vm -p clazel-js-builtins -p clazel-json: all pass.
  • cargo +nightly-2026-08-21 miri test -p clazel-js-builtins: all pass (the Math.pow exact-value test is still ignored under Miri). Under Miri the new tests run every eighth case; a rerun of array + json alone took 244 s and 172 s for the whole file (tests in parallel), the pre-existing builtins file 1030 s for its 12 tests in parallel. Miri does not print per-test times, so the slowest single test is not measured (run with every fourth case, the array file took 487 s as a whole before I lowered it).
  • Not run: cargo xtask verify (full or --changed), Kani, Verus, mutations. CI's full verification has not run on this PR; the proof jobs need a reviewer's approval of the full-verification environment. Not touched: docs/STATUS.md, SPEC-REVIEWS.md, SYS-AUDITS.md. No unsafe, no lint overrides.

🤖 Generated with Claude Code

atiernan and others added 6 commits November 22, 2026 10:59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ay.prototype

PropDesc and [[DefineOwnProperty]] (OrdinaryDefineOwnProperty and the Array
exotic object's, ArraySetLength), ArrayCreate, [[Delete]], NewArray and
DeleteProp handlers, array literals with trailing elisions, a bound on nested
natives, and the Array constructor with the core of Array.prototype.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviver (InternalizeJSONProperty), replacer function and array, space and gap,
toJSON, wrapper objects, the cycle TypeError, and the nesting bound (a
SyntaxError for parse, a RangeError past 128 levels for stringify).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atiernan

Copy link
Copy Markdown
Member Author

Included in #286, which verifies all open phase 7 pull requests together; this merges with it.

atiernan added a commit that referenced this pull request Nov 22, 2026
Array literals now run (#290), so language/comments/S7.4_A5.js reaches
eval, which is not there yet; the test catches the ReferenceError and
throws a bare Test262Error, so the runners cannot class it by name. It is
listed in both runners' KNOWN_GAPS with that reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant