Skip to content

clazel-js-vm, clazel-js-builtins: Object, classes, Map/Set/Weak*, Reflect, accessors; unifies #299, #292 and #296 - #302

Merged
atiernan merged 31 commits into
mainfrom
claude/js-engine-4
Nov 24, 2026
Merged

atiernan merged 31 commits into
mainfrom
claude/js-engine-4

Conversation

@atiernan

@atiernan atiernan commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Phase 7, items 7.8 and 7.9: one engine branch that unifies three open pull requests and fills the largest built-in gaps.

This branch contains #299 (Promise, RegExp, the job queue, arguments/rest), #292 (the built-ins it is built on, which #299 already contains) and #296 (limits as errors, hostile-page tests). It also contains the commit 4d0c1d5a of #298 ("accessor properties, instanceof, re-entrant shared natives"), cherry-picked, so that this branch and #298 merge without a conflict on it.

How the three pull requests were combined

What is new

  • Object, complete (clazel-js-builtins/src/object.rs): getOwnPropertyDescriptor(s), getOwnPropertyNames, getOwnPropertySymbols, defineProperties, entries, values, assign, is, hasOwn, fromEntries, groupBy, freeze, seal, isFrozen, isSealed, preventExtensions, isExtensible, setPrototypeOf; Object.prototype.isPrototypeOf, propertyIsEnumerable, and Annex B's __proto__ accessor and __defineGetter__ family. In the VM: [[Extensible]] (a flag of the object; adding a property to a non-extensible object fails in ValidateAndApplyPropertyDescriptor, OrdinarySet and CreateDataProperty), OrdinarySetPrototypeOf with its cycle check, %Object.prototype% immutable (§10.4.7.1), and Set(O, P, V, true) from a native throws whatever the strictness of the running function.
  • Accessors in the built-ins: RegExp.prototype.flags/source/global/ignoreCase/multiline/dotAll/unicode/unicodeSets/sticky/hasIndices are the standard's getters (with RegExpHasFlag), and get RegExp/Promise/Array/Map/Set [ @@species ], Symbol.prototype.description, Map.prototype.size, Set.prototype.size are accessors. Phase 7: Promise and the job queue, RegExp's object half, arguments and rest parameters #299's listed deviation (flags as own data properties) is gone.
  • Classes run (clazel-js-vm/src/class.rs; the compiler and the ops of ops.rs were already there, the interpreter had no handlers for them): ClassSetup, SetHomeObject, SetInstanceInit, InitInstance, SuperCall/SuperCallSpread (Construct with a NewTarget), GetSuperBase/GetSuper/SetSuper, GetNewTarget, ConstructResult, NewPrivateName/GetPrivate/SetPrivate/DefinePrivate/HasPrivate; [[Construct]] takes a NewTarget and enters base and derived class constructors, so class extends Error/Array/Promise/Map work. DefineMethod is DefinePropertyOrThrow and names accessors with symbol keys; DefineProp/DefineElem are CreateDataPropertyOrThrow. Constructors, accessors, extends, super, fields, static blocks, private names: tests/classes.rs.
  • CopyDataProperties (object spread, the rest of an object pattern).
  • Map, Set, WeakMap, WeakSet (collections.rs): constructors, Map.groupBy, the iterators, the ES2025 Set methods (union ... isDisjointFrom), the upsert proposal's getOrInsert/getOrInsertComputed (Test262 at its head tests them). Storage is clazel-js-vm's insertion-ordered table with SameValueZero keys; deleted entries stay as empty places, so an iterator survives deletion as the standard's List does.
  • Reflect (reflect.rs): all thirteen functions, construct with a NewTarget.
  • Each algorithm quotes its steps (rule 5); modelling choices and deviations are at the top of each module.

Test262

The vendored table (tests/conformance_builtins.rs, 5,212 tests): 614 -> 701 pass, 0 fail (4,511 expected failures).

Spot check from a checkout of tc39/test262 at ebf6ae6 (the one #299 used; scratch runner, real harness files, sloppy and strict; not committed), before = #299's base, after = this branch:

directory tests pass before pass after unsupported after fail after
built-ins/Map 204 0 199 4 1
built-ins/Object 3411 757 3142 23 246
built-ins/Promise 732 447 629 7 96
built-ins/Reflect 153 0 140 1 12
built-ins/RegExp 1251 1014 1183 22 46
built-ins/Set 383 0 352 30 1
built-ins/Symbol 98 33 75 17 6
built-ins/WeakMap 141 0 139 2 0
built-ins/WeakSet 85 0 84 1 0
language/expressions/class 4102 617 2109 1736 257
language/statements/class 4413 664 2368 1742 303
total 14973 3532 10420 3585 968

"unsupported" is a NotYet of the VM (generators, await, eval, Function, BigInt literals, $262 members) or a harness file that needs one.

What the failures are: in language/*/class, 3,406 runs stop at GeneratorStart (generator methods and the yield tests: the VM has no generators); the rest of the class failures are eval, Proxy, Date, typed arrays, async functions. In built-ins/Object, 119 failures are Date (the harness), 85 Proxy, and about 30 are String exotic objects (a String wrapper has no index properties; materializing them would make every sloppy method call on a long string O(n), so it waits for [[GetOwnProperty]] on the wrapper) and the mapped arguments object.

Not done

  • Proxy (every internal method is the ordinary one), WeakRef, FinalizationRegistry; generators and async functions (GeneratorStart, Await); Date; typed arrays; eval and the Function constructor.
  • String exotic objects and the mapped arguments object.
  • RegExp literal early errors in the parser: clazel-js-syntax is Tier 0 with a Verus spec of its early errors, so a new rule there is a spec change, not a cheap one; the 29 negative literal tests still parse.
  • Symbol.dispose and Symbol.asyncDispose (newer than the edition).

Deviations (all listed in the module headers)

  • Weak collections hold their keys strongly until the collector (item 7.6); Map/Set tables are not compacted (a loop that adds and deletes without end grows a vector; the step budget and heap limit bound it).
  • A derived constructor's return 1 is a TypeError raised by ConstructResult inside the constructor's own try, so try { return 1 } catch {} can catch it (the standard raises it after the body); 3 Test262 tests.
  • strict arguments.callee is absent (the %ThrowTypeError% accessor), and the sloppy arguments object has no parameter map (both from Phase 7: Promise and the job queue, RegExp's object half, arguments and rest parameters #299).
  • new.target of a closure is kept in a stack of (frame base, value) pairs in the VM, because the frame header has four slots and none is free; private elements, home objects and instance initializers are tables of the VM keyed by function or object.

Verification

cargo xtask verify --changed origin/claude/phase7-integration (rustfmt, clippy, tests, Miri on the changed crates and their dependents with every test under 300 s, Kani, Verus, mutations for clazel-js-vm 237/237 killed, conformance) passed every step except the last, which is the known base-branch issue:

==> conformance clazel-js-builtins
    Test262 through the interpreter with the first built-ins: 701 pass, 4511 expected failures, 0 fail, of 5212
    PASS  conformance clazel-js-builtins
==> conformance clazel-web
    WPT dom/nodes selectors.js (querySelector[All], matches): 905 pass, 64 expected failures, 0 fail, of 969
    innerHTML round trip (html5lib trees): 9213 pass, 147 expected failures, 0 fail, of 9360
    PASS  conformance clazel-web
==> 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"]; check them too (`--changed` with an older base, or the full report)
    FAIL  status table and images
RESULT: FAILED

The missing rows are crates this change does not touch (docs/STATUS.md is not edited).

CI's full verification has not run on this pull request: the proof jobs wait for approval, so nothing here is "done" in the sense of CLAUDE.md. clazel-sys is untouched, no tier is raised, no mutation or theorem is removed or relabelled, and docs/STATUS.md, docs/SPEC-REVIEWS.md and docs/SYS-AUDITS.md are not edited. The ops the class handlers implement were already in ops.rs and spec.rs (rule 3: no op was added), so spec.rs and mutations.json are untouched.

🤖 Generated with Claude Code

atiernan and others added 29 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>
…ng and RegExp limits (7.19)

The heap counts bytes (cells, string payloads, properties) against a
settable limit; an op that runs out throws a RangeError made from a 64 KiB
reserve, and OutOfMemory only once that is spent. Nested runs of the
interpreter loop count against the native depth too, so recursion through
ToPrimitive cannot overflow the host stack; the default drops from 150 to
32, measured at about 40 KB of host stack a level unoptimised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esting limit (7.19)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Endless loop (Terminator), unbounded recursion through JS, natives and
ToPrimitive, a gigabyte string build, catching the heap limit for ever,
growing arrays and objects, 10^6 nested arrays in source and in JSON, and
recursion through the embedder's own natives.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oop (7.19)

clazel-js is a dev-dependency only, for tests/hostile.rs.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds globals with ToString

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

ObjKind::Host objects hold the internal slots of a built-in (Promise, RegExp);
natives can carry captured values (the closures of the standard); the job queue
(HostEnqueuePromiseJob) runs at the embedder's microtask checkpoint; NewRegExp
calls %RegExp% (RegExpCreate).

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

Promise (constructor, all, allSettled, any, race, reject, resolve, try,
withResolvers, then, catch, finally) over the VM's host objects and job
queue; AggregateError; SpeciesConstructor and Invoke helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ods that use it

RegExp (constructor, escape, exec, test, toString, compile, @@match,
@@matchall, @@replace, @@search, @@split, RegExp String Iterator) over
clazel-js-regexp, with the backtrack stack bounded (RangeError) and the
termination flag as the matcher's interrupt; String.prototype.match, matchAll
and search make a RegExp; GetSubstitution takes named captures;
Object.prototype.toString knows RegExp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreateUnmappedArguments, CreateMappedArguments (without the parameter map) and
CreateRestArray: a call of a function that reads its arguments keeps its
argument list, since the frame has slots for the parameters only. try/catch/
finally and throw already compiled and ran; tests cover them.

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

The vendored WPT testharness.js loads in its shell environment and runs sync
and promise tests through Promise, RegExp and the job queue. The Test262 runner
prints pass, expected failure and failure per directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Limits as errors and the hostile-page tests join Promise, RegExp and the job
queue. The RegExp matcher's backtrack stack is bounded by
Vm::regexp_backtrack_limit through regexp::backtrack_limit, as #299 describes,
so the catastrophic-pattern hostile test now asserts the real RangeError
instead of NotImplemented. The json.rs header keeps both deviation notes; the
heap's byte count handles the Symbol and iterator-record cells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The catastrophic-pattern test no longer expects NotImplemented: a pattern that
grows the backtrack stack ends in a RangeError at
Limits::regexp_backtrack_entries, and (a+)+b ends as Terminated when the
terminator is set. Both tests of #296 are kept in a stronger form.

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

WebIDL attributes are accessor properties on prototypes (WebIDL §3.7.6),
so item 7.12 needs them in the engine:

- clazel-js-vm: an accessor property is an ACCESSOR attribute bit and a
  Cell::Accessor pair in its slot. OrdinaryGet (§10.1.8.1 steps 4 to 8)
  and OrdinarySetWithOwnDescriptor (§10.1.9.2 steps 4 to 7) call the
  getter and setter with the receiver, for property reads and writes,
  global identifiers and primitive bases; ValidateAndApplyPropertyDescriptor
  (§10.1.6.3) gets its accessor steps (2.c, 5.c, 5.d, 6.a, 6.b); object
  literal getters and setters (DefineMethod forms 1 and 2) run; the
  instanceof operator (§13.10.2, OrdinaryHasInstance §7.3.21) runs.
- clazel-js-builtins: ToPropertyDescriptor (§6.2.6.5) reads get and set.
- clazel-js: define_property takes accessors; get_own_property;
  delete_property, new_array, new_array_from and is_array over the VM's
  arrays; shared_function, a re-entrant native for Sync closures (open
  question 14's proposal, beside function, which keeps its Busy rule).

The Test262 runners gain two classifications for tests that instanceof
now reaches and that stop at the missing eval (fail stays 0). The API
test that listed arrays and delete_property as NotImplemented now asserts
that they work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An object carries [[Extensible]] (§10.1.3). Once Vm::prevent_extensions ran
(§10.1.4.1), ValidateAndApplyPropertyDescriptor step 2.a refuses a new
property and OrdinarySet step 2.d.vi fails. Vm::set_prototype_of is
OrdinarySetPrototypeOf (§10.1.2.1) with its cycle check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getOwnPropertyDescriptor(s), getOwnPropertyNames and Symbols,
defineProperties, entries, values, assign, is, hasOwn, fromEntries, groupBy,
freeze, seal, isFrozen, isSealed, preventExtensions, isExtensible,
setPrototypeOf; Object.prototype isPrototypeOf, propertyIsEnumerable and
Annex B's __proto__ accessor, __defineGetter__ and friends. Each algorithm
quotes its steps; tests/object.rs runs them (also under Miri).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RegExp.prototype.flags, source, global, ignoreCase, multiline, dotAll,
unicode, unicodeSets, sticky and hasIndices are the getters of §22.2.6 (with
RegExpHasFlag), and get RegExp, Promise and Array [ @@species ] return the this
value, so the listed deviation of #299 goes. ArraySpeciesCreate reads
C[@@species] with Get. Symbol.prototype.description is the accessor of
§20.4.3.2.

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

The class ops the compiler already emits (specified in ops.rs) get their
handlers: ClassSetup (ClassDefinitionEvaluation steps 5 to 17), SetHomeObject
and GetSuperBase, GetSuper and SetSuper (super references with a receiver),
SuperCall and SuperCallSpread (Construct with NewTarget, BindThisValue's
once-only check), InitInstance and SetInstanceInit, ConstructResult (derived
return rules), GetNewTarget, and the private-name ops (PrivateGet, PrivateSet,
PrivateFieldAdd, PrivateMethodOrAccessorAdd, #x in o). [[Construct]] takes a
NewTarget and enters base and derived class constructors. DefineMethod uses
DefinePropertyOrThrow and names accessors with symbol keys. tests/classes.rs
runs constructors, accessors, extends (including Error, Array and Promise),
super, fields, static blocks and private names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constructors (AddEntriesFromIterable, the Set adder loop with
IteratorClose), Map.groupBy, @@species accessors, the prototypes' methods and
size accessors, the ES2025 Set methods (GetSetRecord, union, intersection,
difference, symmetricDifference, isSubsetOf, isSupersetOf, isDisjointFrom) and
the Map and Set iterators. The storage is clazel-js-vm's collections table: an
insertion-ordered list with SameValueZero keys whose deleted entries stay as
empty places, as the standard's List does, so an iterator survives deletion.
Weak collections hold strongly until the collector (item 7.6) exists; the
module header lists both deviations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
apply, construct (with NewTarget), defineProperty, deleteProperty, get and
set with a receiver, getOwnPropertyDescriptor, getPrototypeOf, setPrototypeOf,
has, isExtensible, preventExtensions, ownKeys and @@toStringTag, each quoting
its steps. clazel-js-vm gains the public OrdinaryGet and OrdinarySet with a
receiver (get_with_receiver, ordinary_set), which super references also use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…op creates data properties

CopyDataProperties (§7.3.25) runs: object spread and the rest of an object
pattern. A native's Set(O, P, V, true) throws a TypeError for a failed
assignment whatever the strictness of the running function (Object.assign
into a frozen or sealed target). DefineProp and DefineElem are
CreateDataPropertyOrThrow, so a class field on a frozen object or a static
field named prototype throws. The built-ins' lib.rs header lists what is
present and absent now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed; Object.prototype is immutable

The upsert proposal's methods (Test262 has their tests at its head) and
§10.4.7.1's immutable prototype for %Object.prototype%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atiernan
atiernan temporarily deployed to full-verification November 23, 2026 23:07 — with GitHub Actions Inactive
…, minutes); keep the embedder's limit test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atiernan
atiernan temporarily deployed to full-verification November 24, 2026 14:55 — with GitHub Actions Inactive
@atiernan
atiernan added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 23d73f0 Nov 24, 2026
21 checks passed
atiernan added a commit that referenced this pull request Nov 24, 2026
Both sides carry the accessor commit (4d0c1d5 here, 02c1cb2 on main,
rebased onto Promise/RegExp/Symbol). The engine files were merged with
4d0c1d5 as the base, so main's rebased accessor work, classes, Object,
Map/Set and Reflect come in whole, and this branch's later engine changes
(re-entrant natives, Scope::run_jobs, the inline-parsing switch) stay:

- clazel-js-vm (handlers, heap, interp, props), clazel-js-builtins (object,
  conformance_builtins), clazel-js tests/accessors: main's. This branch had
  nothing past the accessor commit in them.
- clazel-js (scope, state, native, lib, api tests): main's plus this
  branch's re-entrance and run_jobs; README open question 13 from main,
  14 (answered) from here.
- clazel-web Cargo.toml: clazel-js is already a dependency here, so main's
  second entry is dropped; the README no longer calls it dev-only.
- Cargo.lock: this branch's, then `cargo update -w` (clazel-js-builtins
  now names clazel-js-regexp).

Now that classes and for...of run, two WPT dom/events pages pass
(EventTarget-constructible, passive-by-default) and leave the expected
failures (40 pass, 226 subtests, 24 listed), and the scripting test of an
engine report uses a BigInt literal instead of a class.

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

This branch was previously deployed

1 inactive deployment
full-verification — d6e3570d Deployed Nov 24, 2026 by atiernan via Approve the proofs #808
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