Skip to content

Phase 7: Promise and the job queue, RegExp's object half, arguments and rest parameters - #299

Closed
atiernan wants to merge 10 commits into
mainfrom
claude/js-promise-regexp
Closed

atiernan wants to merge 10 commits into
mainfrom
claude/js-promise-regexp

Conversation

@atiernan

Copy link
Copy Markdown
Member

Phase 7, items 7.9 (Promise and the job queue) and 7.10 (RegExp's object half and the String methods that use it), built on #292 (claude/js-builtins-3).

What is in it

  • clazel-js-vm
    • host module: host objects with internal slots (ObjKind::Host), native functions with captured slots (the closures of the standard), and the job queue (enqueue_job, run_jobs, take_job_errors). The VM never runs the queue by itself: the embedder runs it at its microtask checkpoint.
    • The NewRegExp handler: a regular expression literal calls %RegExp% (RegExpCreate), so the 57 Test262 literal tests that waited on it now run.
    • The arguments object and rest parameters (CreateUnmappedArguments, CreateMappedArguments, CreateRestArray): a call of a function that reads them keeps its argument list, since the frame has slots for the parameters only. Deviation: the sloppy object has no parameter map (no aliasing), and a strict arguments.callee is absent (it is an accessor; the VM has none).
  • clazel-js-builtins
    • Promise: constructor, all, allSettled, any, race, reject, resolve, try, withResolvers, then, catch, finally, @@toStringTag; AggregateError; SpeciesConstructor/Invoke helpers.
    • RegExp: constructor, RegExp.escape, exec, test, toString, compile (Annex B), @@match, @@matchAll, @@replace, @@search, @@split, the RegExp String Iterator; over clazel-js-regexp. String.prototype.match, matchAll, search make a RegExp (RegExpCreate) and invoke it; replace, replaceAll and split delegate to the @@ methods, as before; IsRegExp sees [[RegExpMatcher]]; GetSubstitution takes named captures; Object.prototype.toString knows RegExp and Arguments.
    • Each algorithm quotes the steps it covers (rule 5); the modelling choices and every deviation are listed at the top of promise.rs and regexp.rs.
  • try/catch/finally and throw were already compiled and run (the report that "the engine lacks try/catch" does not hold on this base); tests/arguments.rs now covers them.
  • testharness.js (the vendored WPT one) loads and runs: tests/testharness.rs runs test, a failing assert, a throwing test and a promise_test in the harness's shell environment, through Promise, RegExp, the job queue, arguments and rest parameters.

The matcher's limits and #296

The backtrack stack is bounded and the excess is a RangeError (tests/regexp.rs makes a 1.4M-character match overflow it); the VM's termination flag is the matcher's interrupt hook (a catastrophic pattern ends as Terminated). #296 is not in this base, so the integration point is one function, regexp::backtrack_limit(vm): it returns the matcher's default (a million entries) today, and becomes usize::try_from(vm.regexp_backtrack_limit()).unwrap_or(usize::MAX) once Vm::regexp_backtrack_limit (#296) is merged.

Test262

built-ins/ is not vendored (SOURCE.md: it joins with the items that record it), so the recorded suite is still the table through the interpreter (tests/conformance_builtins.rs): 552 -> 614 pass, 0 fail of 5,212 (the difference is the regular expression literal tests and the three that read arguments; language/literals/regexp: 28 pass, the other 210 are the parser's negative tests). The runner now also prints pass, expected failure and failure per directory.

A spot check of the unvendored directories, from a checkout of tc39/test262 at ebf6ae6 (HEAD today, not the vendored commit; scratch runner, not committed), real harness files, sloppy and strict, 2-5 s per test:

directory tests pass unsupported fail
built-ins/Promise 732 447 128 157
built-ins/RegExp (without property-escapes and one match-indices file: not run, too slow in debug) 1,264 1,020 62 182

Almost every failure is outside this change: propertyHelper.js needs Object.getOwnPropertyDescriptor and the rest of Object (about 207 of the failures); accessor property descriptors (104, one is Promise.allKeyed, a proposal newer than the edition: 74), class (37), Proxy, Reflect, eval, Map; 29 negative RegExp literal tests the parser does not reject (early errors of a literal's pattern are not checked by clazel-js-syntax). In this change: about ten tests that redefine global/unicode on an instance and expect flags to follow (the accessor deviation below).

Deviations (all listed in the module headers)

  • No accessor properties in the VM: RegExp.prototype.flags/source/global/... are own non-writable data properties of each instance; get Promise[@@species] and get RegExp[@@species] are data properties holding the constructor.
  • HostPromiseRejectionTracker is not called; the legacy RegExp.$1 static properties are absent.
  • A match copies the input to a Vec<u16>, so a global replace over a long string is quadratic.

Not done

  • property-escapes Test262 run; vendoring test/built-ins/Promise and RegExp into the table (it changes xtask and every crate that reads the table).
  • Subclassing (class extends Promise): the VM has no class constructors yet.
  • arguments parameter mapping.

Verification

cargo xtask verify --changed origin/claude/phase7-integration (rustfmt, clippy, tests, Miri, Kani and Verus for clazel-js-vm, mutations 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: 614 pass, 4598 expected failures, 0 fail, of 5212
    PASS  conformance clazel-js-builtins
==> 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" yet in the sense of CLAUDE.md.

🤖 Generated with Claude Code

atiernan and others added 10 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>
…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>
@atiernan

Copy link
Copy Markdown
Member Author

Contained in #302 (engine: Object, classes, Map/Set, Reflect), which merges this branch; one verification. Branch kept.

@atiernan atiernan closed this Nov 23, 2026

This branch was successfully deployed

No deployments
full-verification — b69ef258 Deployed Nov 23, 2026 by atiernan via Approve the proofs #793
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