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.
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.
The test called Entropy::seeded directly, so it still passed if export
stopped reading the OS random source. Entropy::new now reads the OS
bytes and the time through seed_sources(), which a test can set for
its thread, and the test runs protect with fixed OS bytes, other OS
bytes and a failed OS read. The OS read in vectorcraft-js's os_random()
is now one function for tests and builds alike.
Five assertions accepted any positive value, so a wrong result could pass:
- host_tests: the evaluator site column and the thrown error's column are
now 3, where the indented call and throw start.
- promise_tests: rejections relayed through Promise.all, Promise.race and
a catch handler report column 3, not any column above 0.
- xmp_tests: the sample packet's padding is exactly 1.
- corners tests: a 10 pt radius at a 120 degree polygon corner spans
10 pt, within 1e-6, instead of anything in (5, 10.5].
Realm::with_os_random made a realm and then replaced its seed, so the
test still passed if Interp::new stopped seeding from the OS random
source. The OS read now goes through os_random(), which a test can set
for the realms made on its thread, and with_os_random builds its realm
with Realm::new. The test fails when Interp::new uses a fixed seed.
The PDF encryption and Math.random seed tests read their source files
and searched for names. They now build the seed from given OS bytes:
equal bytes give an equal stream, other bytes give another stream, and
a failed OS read is an error for the PDF key. Mixing any other source
into either seed fails the tests.
The PDF seed is split into Entropy::seeded, which takes the OS bytes
and the time, and the module doc now names the OS random source.
When show() failed (an answer that could not be read, a host call that
threw, or a handler that threw), the dialog's failure function called the
host's end and dropped its result, so an Abort from end did not stop the
run and the script could catch the error and finish. The failure function
now returns that stop, and the answer and call paths end the run with it
before the error reaches the script.
The Array.prototype methods that skip missing elements, such as forEach
and map, read each index of a host collection with one indexer call
that has `true` as a third argument and use its answer as the element.
The docs of the module, HostClass::index and host_index now say that
such a call gives the element itself, or undefined when there is none,
and that reads without the third argument, such as those of join, are
ordinary reads.
- pageItems, pathItems and textFrames build their list of a document again
after every edit. The rebuild walked the whole document without counting
anything against the run, so a loop that edits and reads a collection in a
large document did unbounded host work. A rebuilt list now counts 16 bytes
per object (as the selection's list does) against the run's host-call
allowance, and the path and type lists count the page items they scan.
- An edit's own ordinary error was returned ahead of a stop (an uncatchable
Abort) from putting back the selection or switching back to the active
document, so a script could catch it and go on. A stop now comes first.
- An answer to a waiting call that could not be read as a value (nested too
deep, too many entries) ended the run instead of being thrown at the call.
It is now thrown there, where the script can catch it, and a ScriptUI dialog
that waited for the answer stops showing, as when its host call fails.
- The selection cost test also compares the host calls, under the same
64 KiB limit for both documents.
Array.prototype methods called on a host collection with more than 4,096
elements, such as forEach over a document's page items, visited only the
indices held as properties. A host collection keeps its elements in the
host, so those methods skipped every element. They now visit every
index of an object whose class has an indexer.
Each element read also called the indexer twice, once to test presence
and once to read the value. The methods now read an index of such an
object with one call, the one `k in object` makes, and take its answer as
the element.
A Symbol key on a proxy read, wrote, tested, deleted and described the
proxy's own Symbol table, so the target never saw it and no trap ran.
Every Symbol path now resolves a proxy the way a string key does: the
get, set, has, deleteProperty, defineProperty and getOwnPropertyDescriptor
traps receive the Symbol, and without a trap the operation reaches the
target with its writable and accessor checks. A super write and a write
on a primitive that reach a proxy go through its [[Set]].
- ownKeys traps may return Symbols; a duplicate Symbol (by identity) or
any other value is a TypeError, and the result is checked against the
target's non-configurable and, for a non-extensible target, all keys
of both kinds, in the target's own key order.
- Reflect.ownKeys lists Symbols, in the trap's order for a proxy, and
Reflect's other functions take Symbol keys. Object.freeze, seal,
isFrozen and isSealed include a proxy's Symbols instead of throwing.
- Symbol key lists stay rooted and charged to the heap until released.
- new Proxy and Proxy.revocable reject a revoked target or handler.
- A typed array reached on the prototype chain as the receiver converts
the value for an index it lacks.
- The eval redeclaration test asserts the runtime SyntaxError.
A realm made with Options::es2015 had no Object.setPrototypeOf, so a
call threw "the value is not a function". It now follows ECMA-262 2015
section 19.1.2.18: undefined or null for the object, or a prototype
that is neither an object nor null, is a TypeError; any other primitive
is returned unchanged; an object whose [[SetPrototypeOf]] gives false
is a TypeError.
It calls the same [[SetPrototypeOf]] as Reflect.setPrototypeOf
(Interp::set_prototype_of in crates/js/src/proxy.rs). A non-extensible
object given a different prototype, Object.prototype given any other
prototype than null, and a prototype whose chain leads back to the
object give false. For a proxy it calls the handler's setPrototypeOf
trap, or sets the target's prototype when there is no trap; a false
result, a revoked proxy and a trap that breaks the section 9.5.2
invariant are TypeErrors. Each prototype the cycle check passes takes
fuel, and a sparse array walk that is running sees indices the new
prototype brings. The function has length 2 and the name
setPrototypeOf, and a realm made without the option does not have it.
The tests from #10023 for `super` and `new.target` in global eval,
indirect eval and `Function` bodies check only that a SyntaxError is
thrown. The interpreter also throws one at run time when `super` has no
home object or constructor (class_ops.rs:450 and :555), so a case the
parser let through would still pass them if it threw only at run time.
Two tests in es2015_tests.rs put `x = 1` ahead of the forbidden form:
- eval_code_with_a_forbidden_super_or_new_target_runs_none_of_it covers
13 cases of `super.y`, `super(...)` and `new.target` in global eval,
indirect eval, direct eval in a plain function, and direct eval in a
method or constructor that does not allow the form. Each leaves `x`
at 0 and throws a SyntaxError.
- a_function_body_with_super_is_not_made covers 5 `Function` calls with
`super` in the body or a parameter default. Each throws a SyntaxError
from `Function` itself, so no function is returned and `x` stays 0.
Every case was already rejected by the parser; the tests change no
behavior.
main's Document member list held saveAs and close as members that are not
available yet; this branch's save_open members implement them, so the
merge drops them from that list and keeps main's other entries. The
script host test lists take main's members together with this branch's
open, userInteractionLevel, fullName, path, saved and option classes,
and the heap accounting keeps main's ModuleNamespace arm beside the
FsEntry string arm.
Reflect.construct of Map, Set, WeakMap and WeakSet with another newTarget fills the collection through the new prototype's adder, new through an empty-handler proxy of a host class constructs the class, Reflect has Symbol.toStringTag, and an ownKeys result is read in full before a duplicate is refused.
A revoked proxy no longer gives its own Symbol properties, the reflect extension reads proxies without running traps, key lists a proxy gives stay counted against the heap while callers use them, has through a proxy of a host collection asks the collection, a proxy's invariant checks keep a namespace's uninitialized-export errors, and a binary constructor checks its arguments before it reads newTarget's prototype. Trap arguments stay rooted while a trap runs.
Reflect.ownKeys and a proxy without an ownKeys trap list integer-index keys in ascending order first. Reflect.construct takes another newTarget for Map, Set and typed arrays, for-in reads each proxy key's descriptor once, deleting a with binding runs only the deleteProperty trap, a write past a typed array's view on the prototype chain is ignored, and a target's descriptor stays reachable while a trap runs. The crate documentation states that traps take string keys only.
A proxy's descriptor and write paths honor a module namespace's uninitialized exports and read-only writes, for-in through proxies counts the keys it keeps against the heap limit, new through an empty-handler proxy of a built-in constructs it, and revoke has its standard name and length. Object.freeze, seal, isFrozen and isSealed throw a TypeError for a proxy whose target chain has Symbol properties.
Function.prototype.bind reads a proxy's prototype through its trap, Object.prototype.toString reads a proxy's Symbol.toStringTag from its target, Reflect.set writes a typed array's elements, a super assignment runs the set trap of a proxy on the home object's chain, and 'in' asks a proxy's has trap once. The name a trap is given is counted against the heap and fuel limits, and Proxy and Reflect stay reachable while their functions are installed.