`export async function f() {}` stopped with "expected a declaration after
'export'", because the module parser checked only for `var`, `function`
and lexical declarations. `export default async function` read the
function as an expression bound to the default binding, so a named one
did not bind its name in the module and was not hoisted.
Both forms now parse as async function declarations, as ECMA-262 2017
section 15.2.3 (ExportDeclaration with HoistableDeclaration) gives.
Async generators stay syntax errors here, as in a plain declaration.
The export forms were missed when #9131 added async functions.
`new` on a class that extends `AsyncFunction` or `GeneratorFunction`
threw "this built-in cannot be subclassed", because the subclass check
listed only `Function` among the function constructors. Both now take
the subclass's prototype from `new.target`, as CreateDynamicFunction
asks (ECMA-262 2017 section 19.2.1.1.1). `AsyncFunction` also parses
its source before it reads `new.target.prototype`, as `Function` and
`GeneratorFunction` already did.
The check came in with the classes support (#9094) and `AsyncFunction`
with async functions (#9131).
A block function in eval code run from a default parameter's value no
longer replaces a parameter of the same name with its variable. The
parameters are bindings between the eval code and the function's
variable environment, so the function gets no variable (Annex B.3.2.3)
and stays in its block. A name that no parameter has still gets the
variable.
The fault came with b900ea2308, which checks the environments out to
the variable environment but not the parameters' environment that a
default parameter's eval declares into.
CI's test-lint step failed on with_e4x_async_before_a_double_colon_is_a_qualified_name:
both of its assertions only checked is_ok. The test now runs x.async::b with async
bound to a Namespace and asserts that it selects the namespaced child.
- AsyncFunction.prototype has Symbol.toStringTag "AsyncFunction",
configurable only.
- await checks the room for the awaited promise's reaction or job and
the suspended frame's bytes before it attaches the reaction, so a
suspension stays within the heap limit.
- An async function's return pops its frame before resolving its
promise, so a then getter on the returned value runs without it.
Returning the function's own promise rejects it at the return.
- Block functions whose variable was not declared are kept in a hash
set, so each block function's lookup takes constant time.
- A shorthand await in an object pattern of an async arrow function's
head is a syntax error, and the head accepts patterns with defaults
such as async ({a = 1}) => a. async({a = 1}) without an arrow is
still a syntax error.
- docs: .jsx files and source strings run with module: true have
Promise and the async syntax; await is an identifier only in script
code.
Object.defineProperties, Object.create, seal and freeze read an ordinary
object's own names in ECMAScript order (array indices ascending first) in
an ES2015 run, through proxies without an ownKeys trap too; without the
option they keep the order for-in visits.
concat reads Symbol.isConcatSpreadable and with scopes read
Symbol.unscopables only in an ES2015 run, so a Symbol set by an earlier
run does not change code run without the option.
Tests: the host-function proxy refusal checks the throw and that neither
the host function nor the trap ran; the bound-constructor test sets the
custom prototype before constructing.
A getPrototypeOf trap may return the same proxy again. Its second visit
replaced the positions the first visit recorded, so a name only the first
ownKeys call returned was never visited. Each visit now adds its new
positions to the proxy's record, each pair counted once against the heap
limit, and the records are sorted and compacted once after the walk.
A for-in loop asks only the proxies whose ownKeys trap listed a name for
its descriptor. When a getPrototypeOf trap returned a new proxy of the
same target on each call, the proxy met before each name was not the one
that listed it, so the name was skipped. The loop now records, for each
proxy, the proxy its prototype lookup returned, and a new proxy of that
same target in its place answers for it. Proxies that list nothing are
recorded too, so another proxy of their target does not answer for them,
and the listing proxies stay rooted until the iterator holds them.
Follows #10185.
- A `with` scope reads `Symbol.unscopables` after it finds a name, through
a proxy's `get` trap, and skips the binding when that object's property
for the name is truthy.
- `concat` reads `Symbol.isConcatSpreadable`, through proxy traps; a
defined value decides whether the object is spread.
- `Object.keys` and `Object.getOwnPropertyNames` keep the target's order
through empty-handler proxies.
- `%TypedArray%.from` and `of` construct through a proxy constructor and
check that the result is a typed array long enough.
- `reflect.find` reads the reflection object and its lists with ordinary
[[GetOwnProperty]], so a proxy receiver throws a TypeError without its
getOwnPropertyDescriptor trap running.
- `JSON.stringify` charges each distinct name a replacer array keeps for
the length of the call, instead of reserving bytes for the whole length,
so a long sparse replacer list no longer hits the heap limit.
- A test checks that an outer proxy reads an inner proxy target's
descriptors in its trap's combined order of names and Symbols.
main's failed-install roll back (#10544) read one object for each family
and handle, while this branch keeps one for each branch of the family.
The install now records the class and prototype of each of those objects
and the roll back puts each one back, so the merged tree builds again.
A read of a Symbol key on a proxy, or on an object with a proxy on its
prototype chain, now calls the proxy's get trap with the Symbol and the
receiver (ECMA-262 9.5.8) and checks the result against the target's
non-configurable Symbol properties.
An ownKeys trap may now return Symbol keys (9.5.11). A Symbol given
twice, a non-configurable Symbol key of the target left out, and for a
non-extensible target any Symbol key left out or added throw a
TypeError. The target's descriptors are read in its key order with one
isExtensible call. Reflect.ownKeys, Object.getOwnPropertySymbols and the
Object functions that list keys take a proxy's keys from one trap call
and keep the order the trap gave, Symbols included.
Clippy's useless_conversion lint stopped the gate at
crates/js/src/proxy_tests.rs:127, where `names.clone().into()` converted
a String to itself. The assertion compares the same value.
Realm::define_host_classes registered each class, and defined its global
constructor, before it checked the next one. A batch whose second class
named an unknown parent or a member twice failed with the first class
already installed, so a retry failed with "defined twice". A failed
instance did the same, and could leave an object scripts held with a
class the realm no longer had.
Every class's name, parent and members are now checked before any class
is added, so a child must still follow its parent in the batch. A
failure after that point removes the classes added, puts back each
global the call replaced and the class of each object an instance moved
to a new class. The replaced globals stay rooted until the call ends, so
a collection during the call does not free them.
- A for-in loop now records, for each proxy whose ownKeys trap it called,
the positions of the names that proxy returned, and asks a proxy for a
name's descriptor only when that proxy listed the name. A proxy that did
not list a name no longer hides an inherited one, and the proxy that did
is still asked after a prototype change moves it on the chain. The
records keep their proxies reachable and count against the heap limit.
- The check before each name walks own properties object by object, so a
typed array without the element a name gives no longer hides that name
on its prototypes.
- Function.prototype.apply reads the list's length with ToLength in a run
with the ES2015 option, so a negative length gives no arguments; other
runs keep ToUint32.
- Docs: typeof on a revoked proxy does not throw, and a setPrototypeOf
trap that returns true may leave the prototype unchanged.
- A Symbol key on a proxy now goes to its innermost target for every
operation: a definition, write or deletion no longer lands on the proxy
object itself. Object.freeze, Object.seal, Object.isFrozen and
Object.isSealed therefore work on a proxy whose target has Symbol
properties instead of throwing a TypeError.
- Reflect.get, set, has, defineProperty, deleteProperty and
getOwnPropertyDescriptor keep a Symbol key as a Symbol, and
Reflect.ownKeys lists Symbol keys after the string keys.
- A realm whose global object an earlier run made non-extensible runs its
ECMAScript 2015 code without Proxy and Reflect, instead of failing every
run with an installation error.
- JSON.stringify charges a replacer array's names to the heap as they are
kept, not the array's whole length up front.
- for-in checks each name's descriptor from the object that listed it, so a
proxy that did not list a name does not hide an inherited one.
- An Array subclass constructed with a proxy newTarget runs the proxy's get
trap before any revoked inner proxy is reached.
- The legacy reflect.find reads its lists without calling proxy traps.
The gate's fmt step failed at b3c1a31: rustfmt with max_width 150 and
use_small_heuristics Max puts the e4x if/else in Interp's for-in step on one
line, and the previous commit wrapped it over five.
- A non-object `prototype` on `new.target` walks its bound and proxy chain
(GetFunctionRealm), so a get trap that revokes the proxy throws a
TypeError instead of running the constructor.
- A subclassable built-in such as Number no longer unwraps a revoked
`new.target` before its own argument conversion runs.
- for-in records how many proxies came before the object that first listed
each name, and the recheck does not ask those proxies for a descriptor, so
a proxy that did not list a name cannot hide an inherited enumerable one.
- Names from an ownKeys trap take fuel for their code units, and so do the
names the ownKeys invariant check hashes.
- The DataView argument test expects TypeError for a non-buffer and
RangeError for a bad offset or length.