In a .js script, `class B extends A { m() { return eval("super.x"); } }`
and `class B extends A { constructor() { eval("super()"); } }` threw a
SyntaxError: eval code was parsed with only `new.target` allowed, never
`super` (ECMA-262 2015 section 18.2.1.1).
Each compiled code now records what `super` and `new.target` may do in
eval code it runs: the rules of its function's body, the rules of the
code around an arrow function, or the rules the eval code itself was read
with. A direct eval parses its code with the caller's rules, so
`super.name` and `super[key]` work inside a method, accessor or class
constructor, and `super(...)` works inside a derived class's
constructor, also from an arrow function or a nested eval there. A plain
function inside a method, the top of a script, an indirect eval and a
`Function` body still give a SyntaxError. `super(...)` in eval code binds
`this` once; a second call is a ReferenceError.
Two tests in es2015_tests.rs cover the allowed and SyntaxError cases and
fail without the change; a third checks that a `Function` body reads its
own `new.target`. docs/mcp.md describes the rule. Follows #9094.
In a .js script, `function F() { return eval("new.target"); } new F()`
threw a SyntaxError: eval code was always parsed as if it were at the
top of a script, where `new.target` is not allowed (ECMA-262 2015
section 18.2.1.1).
A function that calls eval now keeps its new.target in the hidden
binding arrow functions already use, also when it was compiled as ES5.1.
A direct eval looks that binding up through the caller's scopes (one
unit of fuel per scope); when it finds one, the eval code may use
`new.target` and reads that value. At the top of a script, in an arrow
function there, and through an indirect eval it stays a SyntaxError.
`super` in eval code is still not supported.
A test in es2015_tests.rs covers plain, strict, arrow, nested-eval and
class-constructor callers and the three SyntaxError cases; it fails
without the change. Follows #9094.
The merge of main left object literal methods without a `name`, since
main named them with SetFunctionName and the branch defines them through
InitMethod. Methods and accessors defined with a home object are now
named as they are defined: after their key, with `get ` or `set ` before
an accessor's name and a Symbol's description in brackets.
- A named class's constructor takes the class's name before its methods
are defined, so a static `name` member replaces it. An anonymous class
takes the name it is assigned to unless a static member defines `name`.
- Computed methods and accessors in object literals have the object as
their home object (new InitMethodKey), so `super` works in them.
- Class method keys and `super[key]` keep Symbol keys instead of
converting them to strings.
- Classes have generator methods (`*m() {}`); a generator constructor is
a syntax error.
- docs/target-app-parity.md and docs/mcp.md describe the new behavior;
the class line drops test262 counts measured before main added
destructuring, generators and function names.
- A read or write that reaches a module namespace through a prototype
chain checks the export's temporal dead zone and refuses the write;
for-in over a namespace lists its keys without reading the exports.
- `delete this.x` and a delete inside `with` remove only the property,
so a later `let x` is still a SyntaxError.
- An arrow function's `length` is configurable.
- `let [` cannot start the body of if, else, while, for or a label.
- A specifier with an unpaired surrogate parses; the loader refuses it
before reading any file.
- Each module's code counts against the heap from when it loads, and
export lookups use an index instead of copying export lists.
- A module reached again through another path is not read or counted
against the 32 MiB source limit again, its relative imports are read
from the folder the file is in, and on Windows two files whose names
differ only in case in a case-sensitive folder stay two modules.
- `$.evalFile` in a module reads beside that module.
- `script.run` takes `module`, and a `.mjs` file picked on the web runs
as a module.
- Without `es2015`, the compiler does not collect the block scopes that
only Annex B block functions read.
- The test262 runner grades negative module tests by their phase and
counts panics on their own.
script.run, File > Scripts and Other Script... run a file ending in .mjs as a
module: strict code with import and export declarations at its top level.
parse_module reads the module grammar and its early errors, and
Realm::start_module and Realm::run_module load the module graph through the
host, link every import before any module runs, and run each module once,
after the modules it imports. Imports read the exporting binding each time;
a read before initialization is a ReferenceError and an assignment is a
TypeError. import * as ns gives a namespace object that is not extensible,
and Object.isSealed and Object.isFrozen on it throw a ReferenceError for an
export its module has not initialized.
Specifiers are ./ and ../ paths to .mjs and .js files, resolved against the
importing file and read only through the script's file scope, so a module
can import only from the script's folder and the folders below it. Bare
names, URLs and absolute paths are a SyntaxError that names the specifier.
Module files count against the #include limits: 64 files besides the
script, 16 imports deep. import and export stay syntax errors in .js and
.jsx scripts; import() is not read. script.listInstalled lists .mjs files.
The test262 runner also runs the module tests under language/module-code,
import and export, reading the fixture files they import from the suite.
Conflicts were resolved by keeping both sides:
- The compiler keeps the base branch's `declared_function` and its block
function names, and `list_scope` also declares class names.
- Global and eval code keep their environments and code reachable through
`instantiate_global`, and declarations check functions before variables
with `check_global_functions` and `check_global_vars`.
- A call's frame keeps `new.target` and the class bindings, and its heap
reservation counts the class code's hidden bindings.
- Spread reads `String` objects and an array's length as the base branch
does, and keeps its list of elements counted until the elements are the
array's properties. A string's characters are counted only until the
elements are reachable from the roots, so a collection does not count
them twice.
- A block function whose name a function of an enclosing block declares is
not assigned to the variable of that name.
- A labelled function in a block is made when the block is entered, and the
parser checks it against the `let` and `const` names of its statement list.
- A function standing alone as an `if` branch gets a block of its own.
- Spread reads a `String` object by code point, and reads an array's length
again before each element.
- A `var` or function declared on the global object stops a later `let` or
`const` of its name until its property is deleted, and a `var` the global
object cannot take is a `TypeError` before anything is declared.
- A call keeps its callee, receiver and arguments reachable until its frame
holds them, and global and eval code keep their environment and their heap
charge until their frame is pushed.
- Template objects are released when no code that can run holds their sites,
even when one code has several sites.
- `Realm::set_es2015` during a run applies once the run ends.
- A template piece that spans lines does not let a preprocessor line start
after it on its last line.
A realm made with Options::es2015 reads function* declarations and
expressions, *name() methods in object literals, yield and yield*, as
ECMA-262 11th edition sections 14.4 and 25.4 define them. A suspended
generator keeps its frame in its object; next, return and throw on
%GeneratorPrototype% push it back on the interpreter's frame stack, so
a resumption takes fuel and counts against the frame limit, and return
runs the finally blocks around the yield. Resuming a running generator
throws a TypeError. yield* passes next, throw and return on to its
iterator and closes one without throw before throwing a TypeError.
%GeneratorFunction% is reached through a generator function's
constructor. Outside generators, sloppy code still reads yield as a
name, and a realm without the option reads function* as a syntax error.
An engine that #targetengine kept from a .jsx run has no generator
built-ins, so a generator function called there throws a TypeError.
cargo xtask test262 runs the generator folders: 509 of 549 runs pass
(94 of 96 before). Docs: docs/mcp.md, docs/target-app-parity.md.
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.
- Direct eval in a derived constructor, or in an arrow function inside
one, reads the constructor's this binding when it runs, so
eval('this') before super() throws a ReferenceError, and an arrow
function made by the eval code sees this once super() returns.
- A class's heritage and computed keys run as strict mode code inside
sloppy code; the code after the class, and a handler of what they
throw, stay sloppy.
- A super property write that cannot be made throws with
Realm::set_strict_writes, as other property writes do.
- A labeled function in a block is made when the block is entered and
declares its name in the block, so { let f; L: function f() {} } is
a SyntaxError. A block function whose name a function of an
enclosing block also declares no longer assigns the outer variable.
- Methods reject duplicate parameter names outside strict mode code.
- With a global object that is not extensible, a var that would add a
property throws a TypeError before the script or the eval code
declares anything.
- The receiver, arguments and new.target of a call, a strict eval's
own environment and spread's elements stay reachable while their
scopes and properties are made, and spread counts the array's new
properties against the heap limit before it adds them.
- Tagged template strings objects are dropped once nothing but the
cache holds their code, also for code with several sites.
- A //@ or # directive after a template with a substitution that
spans lines is read only at the start of a line.
- The code size estimate counts a block scope's entries by their size.
With Options::es2015, vectorcraft-js reads and runs ECMAScript 2015
classes: declarations, scoped to their block like let, and
expressions, with extends, static members, getters and setters and
computed method names. Class code is strict mode code, methods are
not enumerable and cannot be constructed, and calling a class without
new throws a TypeError.
A derived constructor's this throws a ReferenceError until super(...)
returns, and its default constructor passes its arguments on.
super.name and super[key] read, call and write through the prototype
of the method's home object, in class methods and in object literal
methods, which ES2015 allows in a .js script. new.target names the
constructor new was applied to, in functions and their arrow
functions. A class can extend null, a function, a class, or the
built-in constructors Object, Function, Array, String, Number,
Boolean, RegExp, Date and the error types; extending any other
built-in throws a TypeError. Each class and method takes fuel and
counts against the heap limit, and deep constructor chains stop at
the frame limit. A .jsx file and a source string stay ES5.1, where
class syntax is a SyntaxError.
The test262 runner adds the class, super and new.target tests to its
ES2015 subset (1,125 tests). With the option, 554 of 554 negative
parse runs and 1,527 of 1,633 other runs pass; the failing runs use
Object.setPrototypeOf, RegExp.prototype.flags, function name
properties, a configurable length, the caller and arguments
restrictions, or super and new.target in direct eval.
Docs: docs/mcp.md, docs/target-app-parity.md.
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.
With Options::e4x set, an E4X name standing alone (@a, @ns::a, @[expr],
ns::a, *) is now a valid target for =, compound assignment, ++, --,
delete and for/for each loops, as well as a read. The target is the
nearest XML or XMLList value in scope whose [[HasProperty]] accepts the
name (ECMA-357 section 11.1). The name is evaluated once, and the
target resolves before the right-hand side runs.
When no XML value in scope holds the name, a read or write throws a
ReferenceError and creates no child or attribute. A read no longer
falls back to the first XML value in scope, so a filter such as
list.(@id == '1') throws when an item has no @id and no outer XML
value holds one, instead of treating that item as not matching.
With `Options::e4x` set, vectorcraft-js runs ECMA-357 (2nd edition):
XML and XMLList literals with embedded expressions, the `..`, `.@`,
`.*`, `.()` and `::` selectors, assignment and `delete` on selected
nodes, `for each`, `default xml namespace`, and the four objects with
their methods and settings. The option is off by default, and without
it the syntax and globals do not exist.
Parsing, serializing, comparing and copying trees use no native stack,
and each takes fuel and counts against the heap limit. Inserting a node
into itself or its descendants throws a TypeError before the tree
changes. A literal or XML string nested past `Options::max_depth` gives
a SyntaxError, and a tree built past that depth stops at the heap limit.
`XML.prototype.xpath` is not provided.
is_id_start accepts the letter categories (Lu, Ll, Lt, Lm, Lo, Nl) and
is_id_part adds Mn, Mc, Nd and Pc, read with unicode-general-category.
A superscript digit (No) inside an identifier and a mark such as U+09BE
at its start are now SyntaxErrors, and identifiers with marks outside
the old list, such as the Bengali and Tamil viramas, now parse.
Labels in scope are kept in a map, and duplicate labels in a chain and
duplicate parameters of a strict function are found with a hash set, so
long chains, many labeled statements and long parameter lists are
checked in linear time.
Current test262 (ECMA-262 2017 Annex B.3.6) accepts `for (var x = 1 in o)` only outside strict
mode code. The parser now rejects the initializer in strict code, with the error at `in`.
New crate vectorcraft-js reads ECMAScript 5.1 source into a syntax tree
with source positions: a UTF-16 lexer (line and column tracking, automatic
semicolon insertion, the regexp and division goals), preprocessor lines
read as directive tokens, a recursive-descent parser to an arena tree, and
the ES5 early errors, strict mode included. Nesting deeper than
Options::max_depth (200 by default) gives a SyntaxError with its line and
column rather than overflowing the stack. Nothing runs scripts yet.
cargo xtask test262 downloads test262 at a pinned commit, checks its
SHA-256, unpacks it into the gitignored corpus/ folder and runs the ES5
syntax tests. A differential test in the engine compares the lexer with
scriptcheck on line counts, directives and unterminated literals.