Skip to content

Commit 0b147bc

Browse files
committed
fix: reference fixes found while porting the language to Rust
Language fixes made to the TypeScript reference while the Rust port matched it: new evaluates its arguments before checking the constructor, o.x = v evaluates the right side before checking o, delete on a primitive base, Array arguments, lengths and sort elements convert through ToPrimitive, a blocking host call parks a running sync generator up to the nearest async boundary, copyWithin reads its length once, delete super[key] throws before ToPropertyKey, AggregateError without a message has no own message, BigInt literal property names in classes and patterns, and smaller built-in details. The Effect Host.fn keeps a function's name and length. acorn moves to 8.16.0. test262 skipped list regenerated.
1 parent d456e72 commit 0b147bc

36 files changed

Lines changed: 680 additions & 295 deletions

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ The interpreter is tested against [test262](https://github.com/tc39/test262) at
295295
`test/test262/manifest.json`). The files aren't committed and CI doesn't run them yet: sync a local checkout (see
296296
[`test/test262/README.md`](test/test262/README.md)) and run `bun test test/test262.test.ts`. The sync leaves out
297297
features that are out of scope by design (prototype mutation, `Proxy`, `eval`, sloppy mode and others). Of the
298-
22,253 files it keeps, 19,408 pass and 2,845 are skipped as known gaps (`test/test262/skipped.txt`), with no failures.
298+
22,253 files it keeps, 19,521 pass and 2,732 are skipped as known gaps (`test/test262/skipped.txt`), with no failures.
299299

300300
## Development
301301

‎bun.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎interpreter-support.md‎

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ the ultimate source of truth. Upstream test262 files run verbatim from `test/tes
6363
site, as in JS, but it is not frozen: `strings[0] = "x"` succeeds here where JS throws.
6464
- [x] Regular-expression literals.
6565
- [x] `NaN` and `Infinity` globals.
66-
- [x] BigInt literals (`1n`, `0xffn`, `1_000n`, and as object keys), with arithmetic inside the program; see
67-
[BigInt](#bigint). A BigInt cannot cross to the host.
66+
- [x] BigInt literals (`1n`, `0xffn`, `1_000n`, and as property names in object literals, classes and patterns),
67+
with arithmetic inside the program; see [BigInt](#bigint). A BigInt cannot cross to the host.
6868
- [ ] Arbitrary Symbol primitive values and symbol-keyed properties. The confined `Symbol.iterator` and
6969
`Symbol.asyncIterator` keys are available only for the iterator protocols.
7070
- [x] Getter and setter definitions in object literals (`get x() {}`, `set x(v) {}`, computed and symbol keys), named
@@ -90,7 +90,7 @@ the ultimate source of truth. Upstream test262 files run verbatim from `test/tes
9090
- [x] Object and array destructuring in declarations, parameters, assignment expressions, and `for...of` bindings.
9191
- [x] Nested patterns, defaults, elisions, and rest elements.
9292
- [x] Assignment to identifiers, plain-object fields, non-negative integer array indexes, and writable URL
93-
fields.
93+
fields. `o.x = v` evaluates `v` before checking `o`, so `null.x = f()` calls `f` and then throws.
9494
- [x] Direct function declarations are hoisted in program and block statement lists.
9595
- [x] Parameter defaults observe a temporal dead zone for later parameters.
9696
- [x] `var` is function-scoped and hoisted: names declared anywhere in a function or program body, including loop
@@ -195,8 +195,10 @@ Math.floor)` is `"3"`). A detached method loses its receiver, as in JS: `values.
195195
- [x] Redeclaring a function in the same scope, or alongside a `var`, is allowed: the last declaration wins.
196196
- [x] Generator functions have their own `prototype` (inheriting the shared generator prototype), so
197197
`g() instanceof g` holds. Plain functions have none, since they cannot construct.
198-
- [ ] `GeneratorFunction.prototype`: every function, generator or not, inherits directly from `Function.prototype`,
199-
and a generator whose `prototype` was replaced by a non-object still creates from the shared generator prototype.
198+
- [x] `GeneratorFunction.prototype`, `AsyncGeneratorFunction.prototype`, and `AsyncFunction.prototype`: generator,
199+
async generator, and async functions (arrows included) inherit from these non-callable objects, which inherit
200+
`Function.prototype`; the generator ones link to the shared generator prototypes through `prototype` and
201+
`constructor`. A generator whose `prototype` was replaced by a non-object creates from the shared one.
200202
- [x] Generator and async generator functions bind parameters (defaults, destructuring) at the call and defer only the
201203
body to the first `next()`, so a bad argument throws synchronously from the call site, as in JS.
202204
- [x] Synchronous and async generator declarations/expressions, `yield`, and `yield*`, including lazy bodies,
@@ -252,18 +254,23 @@ Math.floor)` is `"3"`). A detached method loses its receiver, as in JS: `values.
252254
creates a hole without changing its length. Deleting a non-configurable property (`length`) or
253255
assigning a read-only one (`Math.PI`, `fn.name`) throws a `TypeError`, as in strict mode. `delete` of a
254256
non-reference (`delete 0`, `delete f()`) evaluates the operand and is `true`; `delete x` on a variable throws.
257+
A primitive base deletes from its wrapper: `delete "abc"[5]` and `delete (1).x` are `true`, while a string's
258+
own index or `length` throws.
255259
- [x] Coercion helpers and template interpolation accept functions and namespaces: `String(fn)` and `${fn}` give
256-
`"[object Function]"` rather than the source text, `isNaN(fn)` is `true`.
260+
`"[object Function]"` rather than the source text (unless the function has its own `toString` or `valueOf`),
261+
`isNaN(fn)` is `true`.
257262
- [x] `==` and `!=` follow IsLooselyEqual: objects (including functions and host references) compare by identity, a
258263
nullish operand never coerces the other side, and a data object facing a primitive converts through its own
259264
`valueOf`/`toString` (default hint) (`fn == null` is `false`, `fn == fn` is `true`, `[1] == 1` and `[1, 2] == "1,2"` are `true`).
260265
`switch` matches cases with `===`, so `switch (fn) { case fn: }` selects, and `Object.is` compares any two
261266
values. Operators inspect only their direct operands, so `rows == null` on a large array costs the same as
262267
`rows === null`, and an object merely holding a function inside (`[fn] + ""`, `-[fn]`) coerces like any other
263268
data object (`"[object Function]"`, `NaN`).
264-
- [ ] Coercing a function, promise, generator, or host reference itself: `fn + ""`, `-fn`, `fn++`, and `fn == 1`
265-
throw `TypeError: Binary operators require data values.` (or the unary/update form) where JavaScript would use
266-
the source text or `NaN`.
269+
- [x] Functions, generators, and iterators convert through ToPrimitive like any other object, in operators and in
270+
built-in arguments: `fn + ""` is `"[object Function]"` (not the source text), `-fn` and `fn++` give `NaN`,
271+
`fn == 1` is `false`, and an own `valueOf` or `toString` is used. A promise or host reference is never
272+
converted, so a missing `await` cannot hide: `promise + 1`, `-promise`, and `promise == 1` throw
273+
`TypeError: Binary operators require data values.` (or the unary/update form).
267274
- [x] ToPrimitive on program objects: `+ - * / % **`, the relational and bitwise operators, unary `+ - ~`, `++`/`--`,
268275
compound assignment, `${x}`, `Number`/`String`/`isNaN`/`isFinite`, `parseInt`/`parseFloat` (text and radix),
269276
`Math.*` arguments, `Error(message)`, and `Array.prototype.join`/`toString` elements call the object's own
@@ -276,14 +283,20 @@ Math.floor)` is `"3"`). A detached method loses its receiver, as in JS: `values.
276283
hint (`"abc".indexOf({ toString() { return "b" } })` is `1`, `(255).toString({ valueOf() { return 16 } })` is
277284
`"ff"`, `String.prototype.trim.call({ toString() { return " a " } })` is `"a"`). Only consumed positions
278285
convert; a RegExp pattern is used as is, and `includes`/`startsWith`/`endsWith` reject one before converting.
279-
- [ ] ToPrimitive elsewhere: `Error.prototype.toString` on an object `message` and numeric arguments of the Array and
286+
- [x] Array methods, lengths, and elements convert through ToPrimitive: the integer arguments of `at`, `indexOf`,
287+
`lastIndexOf`, `includes`, `slice`, `splice`, `toSpliced`, `fill`, `copyWithin`, `with`, and `flat` (in order,
288+
before the array is read, and not at all for an empty array's `indexOf`/`lastIndexOf`/`includes`),
289+
`length = object` (number hint), and the elements a default `sort` compares (one ToString each). So do
290+
`String.fromCharCode`/`fromCodePoint` arguments, `JSON.parse(text)`, and a `String.prototype[Symbol.iterator]`
291+
receiver; `repeat(NaN)` is `""`.
292+
- [ ] ToPrimitive elsewhere: `Error.prototype.toString` on an object `message` and numeric arguments of the
280293
Uint8Array methods (`at`, `indexOf` start, `slice`) still use the built-in form (`NaN`, `"[object Object]"`) and
281294
ignore own methods.
282295
- [x] Property keys follow ToPropertyKey: `x[null]` and `x[true]` become string keys, and a data object key
283296
converts through its own `toString`/`valueOf` (string hint) exactly once per access, in reads, writes,
284297
compound assignment, `++`, `delete`, `in`, object literals, and destructuring:
285298
`o[{ toString() { return "id" } }] += 1` updates `o.id`. A nullish base throws before the key converts, as
286-
in JS. Opaque values (functions, promises, host references) keep their built-in string form.
299+
in JS. Promises and host references keep their built-in string form.
287300

288301
## Promises and host calls
289302

@@ -323,7 +336,7 @@ Math.floor)` is `"3"`). A detached method loses its receiver, as in JS: `values.
323336
accepted, including `.then`/`.catch` handlers and collection callbacks, and vanish at the data boundary like
324337
any function.
325338
- [x] `Promise.withResolvers()`: the same promise and resolver callables as the constructor, as a `{ promise, resolve,
326-
reject }` object.
339+
reject }` object. The resolvers are anonymous (`name` is `""`) with `length` 1, as every resolving function is.
327340
- [x] `Promise.try(fn, ...args)`: calls `fn` synchronously; a throw rejects, a return fulfils, and a returned promise or
328341
thenable is adopted.
329342
- [x] Recursive assimilation of objects with an own callable `then` field across `Promise.resolve`, combinators,
@@ -336,7 +349,8 @@ reject }` object.
336349
- [x] Own-field reads and writes on plain data objects.
337350
- [x] `new` dispatches on the evaluated constructor value, so aliases (`const D = Date; new D()`), constructors held in
338351
objects, and constructors passed as arguments work, while a shadowed name (`const Date = 5; new Date()`) does
339-
not construct.
352+
not construct. The arguments are evaluated before the callee is checked, so `new x(x = Date)` with `x = 1`
353+
throws its `TypeError` after the assignment.
340354
- [x] `Object()` and `new Object()` return `{}` for nullish arguments and pass objects through unchanged;
341355
primitive wrapper objects (`Object(1)`) are rejected explicitly.
342356
- [x] Computed property names and object spread. Any value works as a key (ToPropertyKey): strings, numbers, and the
@@ -391,7 +405,8 @@ reject }` object.
391405

392406
- [x] The `Array` constructor with or without `new`: `Array(a, b)` collects arguments and `Array(n)` creates a sparse
393407
array of that length; invalid lengths throw `RangeError`. Iteration, spread, join, `flatMap`, and JSON handle
394-
holes like JavaScript, and host results normalize holes to `null`.
408+
holes like JavaScript, and host results normalize holes to `null`. A hole reads, and `in` finds, an index
409+
inherited from `Array.prototype`, so the callback methods visit it.
395410
- [x] Static methods: `Array.isArray`, `Array.of`, and `Array.from`, including the `Array.from` mapper form with
396411
`(value, index)` arguments and stepwise synchronous iterator consumption.
397412
- [x] Iteration/transformation: `map`, `filter`, `flatMap`, and `forEach`.
@@ -407,7 +422,8 @@ reject }` object.
407422
with `next()` and `[Symbol.iterator]`, as in JS. Iterator objects are opaque references: they print as
408423
`[opaque reference]`, serialize to `{}`, and cannot be passed to host functions. Every built-in collection iterator
409424
shares one prototype, where JavaScript gives each collection its own; `Object.getPrototypeOf` shows the
410-
difference.
425+
difference. `Object.prototype.toString` still reports each one's kind: `[object Array Iterator]`,
426+
`[object Map Iterator]`, `[object String Iterator]`, and so on.
411427
- [x] `length`, numeric indexing, index assignment, spread, and `for...of`.
412428
- [x] `Array.prototype.toSpliced`.
413429
- [x] Canonical array/string index parsing: keys such as `"01"` are ordinary properties rather than aliases of index
@@ -422,8 +438,8 @@ reject }` object.
422438
`String.fromCharCode("65")`, and the Uint8Array equivalents. `join(sep)` and `JSON.parse(text)` apply ToString
423439
(`join(null)` is `"1null2"`, `JSON.parse(123)` is `123`). `Array.from({ length: "2" })` applies ToLength; a
424440
promise source still throws with an `await` hint rather than JS's silent `[]`. `join`, `Math.*`, `parseInt`,
425-
and the String and Number methods consult a program object's own `valueOf`/`toString`; the array methods do not
426-
yet (see ToPrimitive above).
441+
and the String, Number, and Array methods consult a program object's own `valueOf`/`toString`; the Uint8Array
442+
methods do not yet (see ToPrimitive above).
427443

428444
## Strings
429445

@@ -442,7 +458,7 @@ reject }` object.
442458
- [x] Native argument coercion for supported String methods; for example, `includes(1)` and `slice("1")` coerce like
443459
native JS, `split(undefined)` returns the whole string, and `includes`/`startsWith`/`endsWith` reject regular
444460
expressions with a native-style `TypeError`. Data objects convert through their own `toString`/`valueOf` (see
445-
ToPrimitive above). Opaque runtime references still reject as data errors, and `repeat` still requires a finite
461+
ToPrimitive above). Promises and tool references still reject as data errors, and `repeat` still requires a finite
446462
non-negative count.
447463
- [x] Native no-argument parity for `match()`, `matchAll()`, and `search()`; all behave as an empty pattern.
448464
- [x] `String.raw`, on a template object or any `{ raw }` object; raw strings and substitutions coerce through their own
@@ -469,7 +485,7 @@ reject }` object.
469485
- [x] Native zero-argument behavior for `Number()` and `String()`: they produce `0` and `""`, while
470486
`Number(undefined)` stays `NaN` and `String(undefined)` stays `"undefined"`.
471487
- [x] `++` and `--` use psychoscript numeric coercion (numeric strings increment, plain data objects become `NaN`, Dates
472-
use their epoch time) and reject opaque runtime references as data errors.
488+
use their epoch time, functions become `NaN`) and reject promises and host references as data errors.
473489
- [x] Unknown static members on global namespaces and on `Number`/`String`/the coercion functions read as `undefined`
474490
for feature detection. Calling any undefined value reports a native-style `TypeError` naming the callee, for
475491
example `Math.sum is not a function.` or `JSON.rawJSON is not a function.` Unknown `Promise` statics keep
@@ -574,7 +590,7 @@ reject }` object.
574590
- [x] `new Set()` from synchronous iterables.
575591
- [x] Set `add`, `has`, `delete`, `clear`, `size`, and `forEach`.
576592
- [x] Live `keys`, `values`, `entries`, and `[Symbol.iterator]` iterators for Map and Set; a Set-like operand's `keys()`
577-
may return any iterator or an array.
593+
may return any iterator or an array. `Set.prototype.keys` is the same function as `values`.
578594
- [x] Spread, `for...of`, `Array.from`, and `Object.fromEntries` integration.
579595
- [x] Map and Set values serialize to `{}` at host/JSON boundaries.
580596
- [x] Set composition and relation methods: `union`, `intersection`, `difference`, `symmetricDifference`, `isSubsetOf`,
@@ -705,7 +721,8 @@ Host functions a host opts in through `Host.fn`, `Host.durableFn`, and `Host.nam
705721
- [x] `Error`, `TypeError`, `RangeError`, `SyntaxError`, `ReferenceError`, `EvalError`, and `URIError`, callable with
706722
or without `new`.
707723
- [x] `AggregateError` with the `(errors, message?)` signature and an own `errors` array, constructed directly or by
708-
an all-rejected `Promise.any`; direct construction accepts custom synchronous iterators and generators.
724+
an all-rejected `Promise.any`; direct construction accepts custom synchronous iterators and generators. Without
725+
a message it has no own `message`, as in JS, and inherits `""`.
709726
- [x] Error `name`/`message`, error inheritance through `instanceof`, and plain-data serialization. `message` is an own
710727
non-enumerable property and `name` is inherited, as in JS, so `Object.keys(err)` is `[]` for a plain error. The
711728
result boundary still emits `{ name, message, ...own enumerable }`, so a field such as `code` crosses. `cause` is

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"prepublishOnly": "bun run build"
5757
},
5858
"dependencies": {
59-
"acorn": "8.15.0"
59+
"acorn": "8.16.0"
6060
},
6161
"peerDependencies": {
6262
"effect": "^4.1.0"

‎script/disasm.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ const formatOperand = (c: Code, op: number, a: number, bx: number, sbx: number):
142142
case Op.PICK:
143143
case Op.ROT:
144144
case Op.CALL:
145-
return String(a)
146145
case Op.NEW:
147-
return a === 255 ? "check" : String(a)
146+
return String(a)
148147
case Op.GET_LOCAL:
149148
case Op.HOLE_LOCAL:
150149
case Op.COPY_CELL:
@@ -195,7 +194,9 @@ const formatOperand = (c: Code, op: number, a: number, bx: number, sbx: number):
195194
? `.writeProp ${JSON.stringify(c.consts[bx])}`
196195
: a === CheckBaseKind.WRITE_ELEM
197196
? ".writeElem"
198-
: ".destructure"
197+
: a === CheckBaseKind.ASSIGN_PROP
198+
? `.assignProp ${JSON.stringify(c.consts[bx])}`
199+
: ".destructure"
199200
case Op.BINOP:
200201
return BinOpSymbols[a] ?? String(a)
201202
case Op.UNARY:

0 commit comments

Comments
 (0)