Skip to content

Phase 7.9: iterators, String, Number, Boolean and more Array built-ins - #292

Closed
atiernan wants to merge 4 commits into
claude/phase7-integrationfrom
claude/js-builtins-3
Closed

atiernan wants to merge 4 commits into
claude/phase7-integrationfrom
claude/js-builtins-3

Conversation

@atiernan

Copy link
Copy Markdown
Member

Phase 7 item 7.9 (built-ins), the next slice: Symbols and the iterator protocol in the VM, so spread, for-of and destructuring run end to end; Symbol; the Array and String iterators; most of String.prototype; the rest of Number.prototype; and the rest of Array.prototype. Base: claude/phase7-integration (#286).

What landed

clazel-js-vm (commit 1)

  • Symbol values: one heap cell per Symbol (so identity is equality); the 13 well-known ones are made by Vm::new with ids 0 to 12, as clazel-js-heap's symbol contract (Y1) numbers them. A Symbol is a property key through the contract's Y4 encoding (top bit set), which the string interner never reaches.
  • Symbols reach: typeof ("symbol"), ToPropertyKey (§7.1.19, also the ToPropertyKey op, so computed keys work), ToString/ToNumber (TypeError), ToObject (Symbol wrapper), IsLooselyEqual (steps 1 and 14), SetFunctionName of a computed method key ([desc]), [[Get]] on a Symbol primitive. Heap::own_properties stays String-keyed (every existing caller wants that); own_symbol_properties lists the rest.
  • ToPrimitive now consults @@toPrimitive (§7.1.1 step 1.b).
  • New ops run: GetIterator, IterNext, IterClose (§7.4 GetIterator/GetIteratorFromMethod, IteratorStepValue, IteratorClose), ForInIterator (§14.7.5.9), CallSpread, NewSpread, InstanceOf (§13.10.2 with @@hasInstance, OrdinaryHasInstance §7.3.21), ToObject, ThrowIfNotObject. An Iterator Record is a heap cell only registers hold. Public helpers for natives: get_iterator, get_iterator_from_method, iterator_step_value, iterator_close, iterator_close_on_throw, iterator_to_list, new_symbol, well_known_symbol, instance_of, ...
  • clazel-js's Scope::kind reports ValueKind::Symbol (one line; nothing else in the embedding API changed).

clazel-js-builtins (commits 2 and 3)

  • Symbol (§20.4): constructor (not new-able), Symbol.for/keyFor, the well-known symbols, Symbol.prototype.toString, valueOf, @@toPrimitive, @@toStringTag.
  • Iteration: %Iterator.prototype%[@@iterator], %ArrayIteratorPrototype%.next, %StringIteratorPrototype%.next (code points), CreateIterResultObject.
  • Function.prototype[@@hasInstance]; Object.prototype.toString reads @@toStringTag; Object.prototype.toLocaleString; @@toStringTag on Math, JSON and the iterator prototypes.
  • Array: from (iterable and array-like), at, copyWithin, entries, keys, values (= @@iterator), findLast, findLastIndex, flat, flatMap, toLocaleString, toReversed, toSorted, toSpliced, with, @@unscopables; concat reads @@isConcatSpreadable, ArraySpeciesCreate reads @@species.
  • String: fromCodePoint, raw; at, codePointAt, concat, endsWith, includes, isWellFormed, lastIndexOf, localeCompare, match, matchAll, padEnd, padStart, repeat, replace, replaceAll (GetSubstitution), search, split, startsWith, toLowerCase, toUpperCase, toLocaleLowerCase, toLocaleUpperCase, toWellFormed, trim, trimEnd, trimStart, @@iterator; Annex B substr, trimLeft, trimRight (same function objects as trimStart/trimEnd). String(sym) gives SymbolDescriptiveString.
  • Number.prototype: toExponential, toPrecision (over clazel-js-number), toLocaleString.
  • Every function's doc comment cites its ECMA-262 algorithm (§n†) and quotes the steps it covers.

Tests (new, no files read, so they run under Miri at a stride of 8): tests/iteration.rs (Symbols, instanceof, spread/for-of/destructuring including iterator closing on break, return and throw, the Array and String iterators, Array.from, for-in) and tests/strings.rs (String statics and methods, GetSubstitution, split, Number, Boolean, the new Array methods, @@isConcatSpreadable, @@species).

Test262 (the vendored suite has no built-ins/ directory, so this moves little)

  • conformance_builtins (with the built-ins): pass 545 → 552, fail 0 (xfail 4667 → 4660).
  • conformance_interp (bare VM): pass 456 → 457, fail 0.
  • KNOWN_GAPS: no entry removed (none started passing). One added, with its reason: language/directive-prologue/10.1.1-11-s.js (calls the missing eval; the test catches the ReferenceError and asserts err instanceof SyntaxError, reached now that instanceof runs). The classifier now also recognises a missing global reported inside a test's own Test262Error message (... Actual: ReferenceError: eval is not defined, 16 RegExp-literal tests reached now that instanceof runs); they stay expected failures under "global eval is missing".

Not done

  • normalize (needs NFD/NFKC/NFKD data), the Annex B HTML methods of String, Iterator and the iterator helpers, generators' prototypes, Array.fromAsync.
  • RegExp-backed match/matchAll/search (they delegate to a pattern's @@match/@@matchAll/@@search and are NotYet otherwise), and replace/replaceAll/split with a RegExp (they work with any pattern object that has @@replace/@@split).
  • CreateRestArray (rest parameters): a frame keeps only nparams arguments, so the extra ones are not reachable yet.
  • The embedding API's new_symbol, well_known_symbol, iterate and instance_of with a bound function still return NotImplemented (clazel-js's contract is reviewed separately; they can now be built on the VM's public helpers).

Deviations (each is also listed in the module header it belongs to)

  • No accessors, so get Array[@@species] and Symbol.prototype.description are absent. ArraySpeciesCreate uses the constructor itself when it has no @@species property at all (what the missing getter would return); a script-defined @@species, null included, is honoured.
  • for-in takes its keys when the loop starts (each enumerable string key of the object and its chain once, shadowed ones left out) and skips a key no longer present when reached; keys added during the loop are not visited. §14.7.5.9 allows this.
  • Case conversion is Rust's to_lowercase/to_uppercase (full Unicode Default Case Conversion with SpecialCasing and Final Sigma at the toolchain's Unicode version); lone surrogates are kept and split the text. Locale variants are the same functions.
  • localeCompare compares code units (no ECMA-402; canonically equivalent strings do not compare equal). toLocaleString of Number and Array use toString and ,.
  • A String wrapper object still has no index properties (unchanged; Object('ab')[0] is undefined, String.raw({ raw: 'xyz' }) sees no literals). Primitive strings and their iterator are right.
  • String length limit: a result past the heap's 2^30 - 1 units is a RangeError ("Invalid string length").
  • FlattenIntoArray recursion is bounded at 10,000 levels (a RangeError), for a self-containing array with depth Infinity.
  • The GlobalSymbolRegistry is an object held only in the VM's intrinsics table (Intrinsic::SymbolRegistry, documented as not a standard intrinsic).
  • builtins.rs now runs every eighth case under Miri (was every third): installing the built-ins grew (about 25 s a case under Miri) and object_constructor_and_prototype was already at 298 s.

Verification

cargo xtask verify --changed origin/claude/phase7-integration (changed crates: clazel-js-vm, clazel-js-builtins, clazel-js, clazel-jit) ended in RESULT: FAILED, on one step only:

  • PASS: static checks, rustfmt, clippy, tests, tests under Miri (293 tests), Kani clazel-js-vm, Verus clazel-jit and clazel-js-vm, proof mutation tests clazel-jit and clazel-js-vm, conformance clazel-js-vm and clazel-js-builtins.
  • FAIL: "status table and images": no committed row to carry over for ["clazel-deflate", "clazel-forms", "clazel-gif", "clazel-image-shape", "clazel-jpeg", "clazel-png", "clazel-svg", "clazel-webp"]. These are the phase 6 crates merged into the base from main; the base's docs/STATUS.md has no rows for them (CI writes the table only on main), so this fails on the base too and is unrelated to this change. STATUS.md is not edited here, per CLAUDE.md.

Under Miri every built-in test runs in at most 142 s (json_parse), well under the 300 s limit; the new test files take at most 105 s per test.

CI's full verification has not run yet; the proof jobs wait for a full-verification reviewer's approval. Not done until it is green.

🤖 Generated with Claude Code

atiernan and others added 4 commits November 23, 2026 01:55
…nstanceof

Symbol values are heap cells (one per Symbol, so identity is equality),
the 13 well-known ones made with the VM; a Symbol is a property key through
clazel-js-heap's symbol contract (Y4), which the interner never collides
with. typeof, ToPropertyKey, ToString/ToNumber (TypeError), ToObject,
IsLooselyEqual, SetFunctionName of a computed method key and ToPrimitive's
@@toPrimitive now see them; own_properties stays String-keyed and
own_symbol_properties lists the rest.

The ops GetIterator, IterNext, IterClose (§7.4), ForInIterator
(§14.7.5.9), CallSpread, NewSpread, InstanceOf (§13.10.2 with
@@hasInstance and OrdinaryHasInstance), ToObject and ThrowIfNotObject run.
An Iterator Record is a heap cell only registers hold. The iterators
themselves are built-ins, so a bare VM has nothing iterable.

The built-ins runner classes a missing eval reported inside a test's own
Test262Error, and lists 10.1.1-11-s.js (reached now that instanceof runs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Symbol (§20.4) with Symbol.for/keyFor, the well-known symbols and
Symbol.prototype; %Iterator.prototype%, the Array and String iterators
(§23.1.5, §22.1.5); Function.prototype[@@hasInstance]; @@toStringTag in
Object.prototype.toString and on Math, JSON and the iterator prototypes;
Object.prototype.toLocaleString.

Array: from, at, copyWithin, entries, keys, values (= @@iterator),
findLast, findLastIndex, flat, flatMap, toLocaleString, toReversed,
toSorted, toSpliced, with, @@unscopables; concat reads
@@isConcatSpreadable and ArraySpeciesCreate reads @@species (the
constructor itself while get Array[@@species], an accessor, is missing).

Spread, for-of and destructuring over arrays and strings now run end to
end (tests/iteration.rs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
String: fromCodePoint, raw, and at, codePointAt, concat, endsWith,
includes, isWellFormed, lastIndexOf, localeCompare, match, matchAll,
padEnd, padStart, repeat, replace, replaceAll (GetSubstitution), search,
split, startsWith, toLowerCase/toUpperCase (and the locale forms),
toWellFormed, trim, trimEnd, trimStart, @@iterator, and Annex B substr,
trimLeft, trimRight. The RegExp-taking methods delegate to a pattern's
@@match/@@replace/... and are NotYet otherwise (no RegExp yet).

Number: toExponential, toPrecision (clazel-js-number) and toLocaleString.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Installing the built-ins grew with Symbol, the iterators and String (about
25 s a case under Miri), so builtins.rs takes the stride the other
built-in tests use, which keeps each test well under xtask's 300 s limit.

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

Copy link
Copy Markdown
Member Author

Contained in #299 (Promise, RegExp), which was cut from this branch. Branch kept.

This branch is waiting to be deployed

1 waiting deployment
full-verification — edb6d1ca Waiting Nov 23, 2026 by atiernan via Approve the proofs #777
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