Parent: #459
Problem
This is a missing early error, not a message-text divergence — found while sweeping error messages, but it is a spec-conformance bug.
new.target outside a function or class static block is an early SyntaxError
(ECMA-262 sec-static-semantics-early-errors for NewTarget). zig-js accepts it and
evaluates it, so the whole program runs where it should have been rejected at parse time:
eval("new.target") // JSC: SyntaxError zig-js: no throw
eval("var t = new.target; t") // JSC: SyntaxError zig-js: no throw
eval("if (true) { new.target; }") // JSC: SyntaxError zig-js: no throwJavaScriptCore: SyntaxError: new.target is only valid inside functions or static blocks.
Verified directly against a real JSC backend, and reproduced independently of the sweep agent that first surfaced it.
The legal positions already behave correctly, so only the rejection is missing:
(function () { return new.target; })() // fine on both
class C { m() { return new.target; } } new C().m() // fine on bothWhy it matters beyond wording
Every other item in this sweep is a string difference. This one changes which programs
run: a typo'd new.target at top level silently evaluates to undefined instead of
failing at parse time, so the error surfaces far from its cause.
Note on the existing gate
parseNew already has the machinery — it checks self.new_target_depth == 0 and returns
ParseError.UnexpectedToken for the meta-property. Worth checking why the top-level case
does not reach that gate (script/eval top level may be seeding a nonzero depth), since the
fix may be to the depth bookkeeping rather than to the check.
test262 has coverage under test/language/expressions/new.target/, which currently
passes at 12/12 — so whatever it asserts does not include the top-level rejection, and a
case should be added alongside the fix.