Commit graph

48 commits

Author SHA1 Message Date
kommander
29915a5310 fix(codemode): assigning undefined fails like assigning a constant
As in the reference, `undefined = 12` and its compound, logical and destructuring forms throw "Cannot assign to constant 'undefined'." instead of a ReferenceError.

language/global-code/import.js fails in the reference as it does here (a relative import throws when it runs instead of a parse error), so it moves from rust-skipped.txt to the reference's skipped.txt.
2026-11-18 18:56:10 +01:00
kommander
e4c73711f3 feat(codemode): real array holes
Arrays hold holes from elisions, Array(n), delete, length and far writes. A hole is not an own property: reads and `in` fall through to the prototypes, keys and for-in skip it, and logs print it empty. Methods follow the reference: the callback methods skip indexes not in the array, the find methods read them live, sort puts holes last, flat drops them, and spreads and copies such as toReversed read them as undefined. Holes cross the extension boundary as holes.

Drops 40 files from rust-skipped.txt, and 15 stale entries from the reference's test262 skipped.txt that its runner passes.
2026-11-18 18:56:10 +01:00
kommander
a74841f11e fix(codemode): give function kinds their own prototypes, like the reference
Function.prototype is a function, and generator, async and async
generator functions inherit from their own prototype objects below it,
as the reference has them. Three test262 files the reference passes were
still in its skipped.txt; they are removed from it.
2026-11-18 18:56:09 +01:00
kommander
ebb15aeb19 feat(codemode): add URI functions, toExponential, Math.sumPrecise, f16round and copyWithin
- encodeURI/encodeURIComponent/decodeURI/decodeURIComponent with the
  reference's URIError messages.
- Number formatting follows JavaScriptCore: toString(radix) ports its exact
  integer digits and shortest-fraction algorithm, toExponential and
  toPrecision round half up on the exact value, toFixed keeps the sign of
  a negative that rounds to zero, and number-to-string picks the even
  digit when two shortest forms tie. Range errors use the host messages.
- Math.sumPrecise sums exactly and rounds once; Math.f16round rounds
  straight from the double; Array.prototype.copyWithin.

Number-to-string and its tie rule live in value.rs, so integers from 2^53
up print their shortest digits instead of every digit.

copyWithin converts its arguments through ToPrimitive like the other Array methods. Number-to-string decides ties in 128-bit integer arithmetic. test262: the reference's skipped.txt drops three copyWithin files the reference passes.
2026-11-18 18:56:09 +01:00
kommander
5cdf1ddc7c feat(codemode): add Iterator helpers, WeakMap, WeakSet, groupBy and Set methods
Iterator with Iterator.from and the lazy helpers (map, filter, take, drop,
flatMap) and consumers (reduce, toArray, forEach, some, every, find),
closing their source on early exit; Map getOrInsert(Computed), Map.groupBy,
Object.groupBy, the Set composition methods over Set-like operands, and
WeakMap/WeakSet. Map and Set methods now reject each other's receivers,
Iterator.prototype.next rejects foreign receivers, and exhausted built-in
iterators stay done, as in the reference.

RegExp: the flag accessors are listed on RegExp.prototype, and patterns
without u or v are matched as code units, so astral literals match.
No new dependencies.

test262: the reference's skipped.txt drops twelve Iterator and Set files the reference itself passes, which pass here too. Built-in iterators report their JS tags ([object Array Iterator], [object Set Iterator]), as the reference now does.
2026-11-18 18:56:09 +01:00
kommander
fccbad7d9e feat(codemode): add RegExp and regex-aware String methods
Regular expression literals, the RegExp constructor with flags, lastIndex,
exec/test, RegExp.escape, and match, matchAll, search, replace, replaceAll
and split with regex patterns, replacement templates and function
replacers.

Adds the regress crate (pure Rust, ECMAScript regex semantics, UTF-16
matching); the stripped embed example grows from 2139576 to 3047304 bytes.

The RegExp pattern, exec/test input and lastIndex convert without consulting program methods, as the reference's coerceToString/coerceToNumber do. test262: the files this fixes leave rust-skipped.txt, and the reference's skipped.txt drops Array lastIndexOf 15.4.4.15-5-21, which the reference passes since its Array arguments go through ToPrimitive.
2026-11-18 18:56:09 +01:00
kommander
230d462289 fix(codemode): parse Unicode 17 identifiers with acorn 8.16 2026-11-18 18:56:08 +01:00
kommander
3dbee2a738 fix(codemode): convert Array arguments, lengths and sort elements through ToPrimitive
The integer arguments of the Array methods, length = object, and the elements a default sort compares call the program's own valueOf/toString, as do String.fromCharCode/fromCodePoint, JSON.parse, and the string iterator's receiver. repeat(NaN) is "", as ToIntegerOrInfinity makes NaN 0.
2026-11-18 18:56:08 +01:00
kommander
0c5a6a6c2b fix(codemode): let in find an array hole's inherited index
The fast path for an integer in an array answered false for a hole; it now answers only for a present element and leaves the rest to the prototype walk, so forEach, some, and reduce visit an index inherited from Array.prototype.
2026-11-18 18:56:01 +01:00
kommander
58579fc70e fix(codemode): match JS in built-in object details
Resolving functions are anonymous, Set.prototype.keys is values, built-in iterators report their kind (Array Iterator, Map Iterator, ...), AggregateError has no own message unless given one, and generator and async functions inherit from their own non-callable function prototypes.
2026-11-18 18:56:01 +01:00
kommander
d4bb17439f fix(codemode): delete on a primitive base is true unless the wrapper owns the key
delete "abc"[5] and delete (1).x are true, as they delete from the wrapper; a string's own index or length still throws in strict mode.
2026-11-18 18:56:01 +01:00
kommander
e70845f198 fix(codemode): evaluate the right side of o.x = v before checking o
PutValue checks the base, so null.x = f() calls f before it throws, and (1).x = f() surfaces f's throw.
2026-11-18 18:55:49 +01:00
kommander
3afec0de63 fix(codemode): evaluate new arguments before checking the constructor
EvaluateNew evaluates the callee and its arguments before IsConstructor, so an argument's side effects and throws come first. Bumps the compiler version, since NEW no longer emits a separate check.
2026-11-18 18:55:49 +01:00
kommander
2a932f1331 fix(codemode): convert functions, generators and iterators through ToPrimitive
Operators and built-in arguments now call their valueOf/toString like any other object, as JS does: fn + 1 is "[object Function]1" and -fn is NaN. Promises and tool references still reject, so a missing await cannot hide.
2026-11-18 18:55:16 +01:00
James Long
b9029e64a0
refactor(codemode): split the language layer from Code Mode (#64487) 2026-11-17 15:21:51 -05:00
James Long
a73657f3f9
refactor(codemode): flatten the VM into src and remove two-engine leftovers (#63377) 2026-11-12 13:39:15 -05:00
James Long
72616be4db
refactor(codemode): remove the legacy interpreter; the VM is the only engine (#62642) 2026-11-11 11:25:37 -05:00
James Long
a04dc98d60
fix(codemode): drop test262 corpus symlinks committed by accident (#62394) 2026-11-06 12:51:26 -06:00
James Long
ffde0f7d47
feat(codemode): add a bytecode VM engine behind CodeMode.make({ engine: "vm" }) (#62357) 2026-11-06 11:37:45 -06:00
Aiden Cline
e26f85bcd3
refactor(codemode): run programs on one job queue instead of a fiber per async call (#57976) 2026-10-27 12:13:30 -05:00
Aiden Cline
5335347e80
feat(codemode): add WeakMap and WeakSet (#51257) 2026-09-25 00:15:19 -05:00
Aiden Cline
962c14a49c
fix(codemode): honor thisArg, program toString in computed keys, and ToPrimitive in String and Number arguments (#51264) 2026-09-24 23:46:15 -05:00
Aiden Cline
8061220b08
test(codemode): vendor every eligible test262 directory and bound unsupported globals (#51242) 2026-09-24 20:19:24 -05:00
Aiden Cline
e23d89c9a9
fix(codemode): destructure object patterns from primitives and convert Date components through ToPrimitive (#51239) 2026-09-24 19:32:19 -05:00
Aiden Cline
5256f30957
feat(codemode): honor program valueOf and toString in operators and conversions (#50837) 2026-09-24 18:45:48 -05:00
Aiden Cline
56262121ee
feat(codemode): bind this and arguments in functions, add Function.prototype.call, apply, and bind (#50831) 2026-09-24 16:34:46 -05:00
Aiden Cline
a16eedfed7
fix(codemode): make derived error constructors inherit from Error (#51045) 2026-09-24 14:03:10 -05:00
Aiden Cline
318a8c1aba
feat(codemode): add Object.freeze/seal/create/getPrototypeOf and structuredClone (#50834) 2026-09-24 00:50:54 -05:00
Aiden Cline
dc48655743
fix(codemode): compare with == by IsLooselyEqual and stop deep-walking operands for opaque references (#50830) 2026-09-24 00:36:41 -05:00
Aiden Cline
14a3311a61
feat(codemode): add Uint8Array callback methods and coerce indexOf start indexes (#50829) 2026-09-23 10:27:40 -05:00
Aiden Cline
68b28bdb98
fix(codemode): coerce match/search patterns, allow any for...in target, bind the last duplicate parameter (#50802) 2026-09-22 23:32:27 -05:00
Aiden Cline
17abc5906b
feat(codemode): add tagged templates and String.raw (#50791) 2026-09-22 21:25:21 -05:00
Aiden Cline
9fdcb8da41
fix(codemode): coerce built-in arguments as in JS instead of requiring numbers and strings (#50492) 2026-09-21 23:04:04 -05:00
Aiden Cline
6f8c5ae0aa
fix(codemode): bind generator parameters at the call, not the first next() (#50489) 2026-09-21 22:42:10 -05:00
Aiden Cline
651529d64e
fix(codemode): coerce any value to a property key (#50479) 2026-09-21 21:35:20 -05:00
Aiden Cline
02566f6219
fix(codemode): live Map/Set forEach, generator prototypes, repeated function declarations, delete on non-references (#50450) 2026-09-21 18:09:45 -05:00
Aiden Cline
4cc9b90f27
fix(codemode): add Promise.try and surface a failing iterator close on generator return (#50419) 2026-09-21 15:35:11 -05:00
Aiden Cline
97e833a297
feat(codemode): add Iterator helpers and Iterator.from (#50410) 2026-09-21 14:14:24 -05:00
Aiden Cline
1316576720
refactor(codemode): type program values and let built-ins answer for themselves (#50191) 2026-09-21 11:03:16 -05:00
Aiden Cline
62dc1f7696
feat(codemode): add toLocaleString, Error.isError, and Map.getOrInsert (#50098) 2026-09-20 10:23:23 -05:00
Aiden Cline
eb0e26b974
feat(codemode): return live iterators from keys, values, and entries (#50061) 2026-09-19 18:46:35 -05:00
Aiden Cline
9ae714d49d
feat(codemode): add Uint8Array, drop the Program prefix, and give built-ins one context (#49076) 2026-09-14 23:35:48 -05:00
Aiden Cline
5d3019e5a1
refactor(codemode): materialize interpreter failures once and locate them at the call boundary (#48770) 2026-09-13 20:19:31 -05:00
Aiden Cline
6add96698e
refactor(codemode): move built-ins onto real prototypes with native function objects (#48608) 2026-09-12 02:19:30 -05:00
Aiden Cline
b2e6e764a8
refactor(codemode): give errors a real prototype chain and JS error types (#48559) 2026-09-11 21:45:29 -05:00
Aiden Cline
68b862da49
refactor(codemode): make functions program objects with name and length (#48541) 2026-09-11 14:50:07 -05:00
Aiden Cline
10ae321bf3
refactor(codemode): give programs their own objects and arrays (#48527) 2026-09-11 13:36:35 -05:00
Aiden Cline
4c34ee5eab
test(codemode): run test262 files verbatim from a local checkout (#48446) 2026-09-11 10:40:02 -05:00