Commit Graph
5 Commits
Author SHA1 Message Date
dotCooCoo 2f9621bc38 Scripts: direct eval inside a function reads its new.target
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.
2026-11-28 14:47:16 -08:00
dotCooCoo 2b2ff867a5 Scripts: class and object literal methods are named, computed methods keep their home object
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.
2026-11-27 23:02:32 -08:00
dotCooCoo 09c58a297d Merge main into feat/js-es2015-classes
# Conflicts:
#	crates/js/src/ast.rs
#	crates/js/src/bytecode.rs
#	crates/js/src/compiler.rs
#	crates/js/src/es2015_tests.rs
#	crates/js/src/interp.rs
#	crates/js/src/interp_tests.rs
#	crates/js/src/lib.rs
#	crates/js/src/parser.rs
#	crates/js/tests/test262.rs
#	docs/mcp.md
#	docs/target-app-parity.md
2026-11-27 22:40:21 -08:00
dotCooCoo 029482d0d7 Scripts: class code, eval and block functions follow the ES2015 rules
- 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.
2026-11-22 06:41:35 -08:00
dotCooCoo 95d1f70041 Scripts: .js scripts define classes with extends, super and new.target
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.
2026-11-22 01:17:22 -08:00