With Options::es2015, vectorcraft-js reads and runs two ECMAScript 2020
forms: optional chains (a?.b, a?.[key], f?.(args) and the accesses and
calls after them) and ??.
- An optional step that finds undefined or null ends the whole chain
with undefined, without evaluating its other keys and arguments.
Parentheses end a chain. a?.b() and a.b?.() call with a as this,
(a?.b)() does too, eval?.(code) is an indirect eval, and delete a?.b
is true when a is undefined or null.
- ?? keeps any left side other than undefined and null.
- ?. before a digit still reads as ? and a number (a?.5:1).
- Mixing ?? with && or || without parentheses, assigning to or updating
an optional chain, a tagged template after one and new a?.b() are
syntax errors.
Two new jump instructions test for undefined and null, and the verifier
checks both of their paths. A chain of any length compiles with a loop.
.jsx files and source strings stay ES5.1, where ?. and ?? are syntax
errors.
The test262 ES2015 subset now also reads expressions/optional-chaining
and expressions/coalesce: 426 of 426 negative parse runs and 591 of 615
other runs pass with the option. The 24 failing runs are the same as
before this change.
With ES2015 scripts, a function declaration was judged by a property the
global object inherits, so a fixed property on Object.prototype stopped
`function name() {}`. The check now reads the global object's own
property, as ECMA-262 2015 section 8.1.1.4.16 does, and declares nothing
when the global object is not extensible and has no property of that
name. Indirect eval code makes the same check for all of its functions
before it declares any of them, and a function declaration never adds a
property to a global object that is not extensible.
A call to a function with a rest parameter built the array of its extra
arguments without reserving room for it, so `f.apply(null, big)` could
push the heap estimate past the limit. The call now counts the rest
array, its binding and one property per extra argument in the room it
reserves before the function's environment is made.
Spreading a concatenated string (`[...s]`, `f(...s)`) flattened it before
any limit was checked, so a script could make the host build the whole
copy before the per-element fuel and heap accounting ran. The spread now
flattens through the same counted helper the string built-ins use, which
ends the run with the heap limit before the copy is made.
A function declared in a block sets the enclosing variable of its name
only when that declaration itself is eligible, so a declaration inside
a let of the same name no longer assigns the variable because another
declaration of that name elsewhere in the body is eligible.
Spread of an object with a length property reads the length with
ToLength, so a negative or NaN length adds no elements instead of
wrapping to a count near 2^32. A function body's environments stay on
the collector's roots while its scope, functions and arguments object
are made.
Global code runs in the realm's lexical scope in either language, so a
function an earlier ES5.1 run, an indirect eval or the Function
constructor made can read a let or const a later .js run declares. With
the ES2015 option, a script whose function cannot replace a property of
the global object throws a TypeError before any of its let or const
names is declared, so a failed run leaves no name uninitialized.
vectorcraft-js gains Options::es2015, which reads and runs these
ECMAScript 2015 forms: let and const with block scope and their
temporal dead zone, a new let binding for each loop iteration,
function declarations scoped to their block (with the Annex B.3.3
variable outside strict mode code), arrow functions, template
literals and tagged templates, default and rest parameters, and
spread in array literals, calls and new. Spread reads arrays,
strings by code point and objects with a length, by index, and
throws a TypeError for anything else until iterators are added.
Eval code outside strict mode code cannot declare a var that clashes
with a let or const around it, or with a parameter inside a default
value. Spread, template objects and the new scopes take fuel and
count against the heap limit, and nested arrows and templates count
against the depth limit.
script.run sets the option for a .js file; eval, Function, #include
files, $.evalFile and a kept #targetengine read code the way the
running script does. A .jsx file and a source string stay ES5.1.
The test262 runner gains an ES2015 subset run, read without and with
the option. docs/mcp.md and docs/target-app-parity.md describe the
new forms.