You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Editorial: Remove "Outside" wording for eval errors (#1245)
- Be explicit about interleaving errors
It took me a few times over the specification to understand that the
headings and introductory text with descriptions like
"when a direct eval call occurs outside of any function"
were non-normative. Here's a confusing case:
new class { constructor() { function f() { eval("super()") } f(); } }
This example will throw a SyntaxError because the enclosing
ThisEnvironment when eval runs is not a derived constructor. However,
in the ordinary English sense of "outside", I'd say that the eval
call is not outside of a constructor.
This patch removes the use of the term "outside" when describing the
distribution of this error case. It puts the error text inline in
PerformEval, where it's easier to see the relationship with where
the error condition comes from.
1. Let _script_ be the ECMAScript code that is the result of parsing _x_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, for the goal symbol |Script|. If _inFunction_ is *false*, additional early error rules from <emu-xref href="#sec-performeval-rules-outside-functions"></emu-xref> are applied. If _inMethod_ is *false*, additional early error rules from <emu-xref href="#sec-performeval-rules-outside-methods"></emu-xref> are applied. If _inDerivedConstructor_ is *false*, additional early error rules from <emu-xref href="#sec-performeval-rules-outside-constructors"></emu-xref> are applied. If the parse fails, throw a *SyntaxError* exception. If any early errors are detected, throw a *SyntaxError* or a *ReferenceError* exception, depending on the type of the error (but see also clause <emu-xref href="#sec-error-handling-and-language-extensions"></emu-xref>). Parsing and early error detection may be interweaved in an implementation-dependent manner.
23437
-
1. If _script_ Contains |ScriptBody| is *false*, return *undefined*.
23438
-
1. Let _body_ be the |ScriptBody| of _script_.
23436
+
1. Perform the following substeps in an implementation-dependent order, possibly interleaving parsing and error detection:
23437
+
1. Let _script_ be the ECMAScript code that is the result of parsing _x_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, for the goal symbol |Script|. If the parse fails, throw a *SyntaxError* exception. If any early errors are detected, throw a *SyntaxError* or a *ReferenceError* exception, depending on the type of the error (but see also clause <emu-xref href="#sec-error-handling-and-language-extensions"></emu-xref>).
23438
+
1. If _script_ Contains |ScriptBody| is *false*, return *undefined*.
23439
+
1. Let _body_ be the |ScriptBody| of _script_.
23440
+
1. If _inFunction_ is *false*, and _body_ Contains |NewTarget|, throw a *SyntaxError* exception.
23441
+
1. If _inMethod_ is *false*, and _body_ Contains |SuperProperty|, throw a *SyntaxError* exception.
23442
+
1. If _inDerivedConstructor_ is *false*, and _body_ Contains |SuperCall|, throw a *SyntaxError* exception.
23439
23443
1. If _strictCaller_ is *true*, let _strictEval_ be *true*.
23440
23444
1. Else, let _strictEval_ be IsStrict of _script_.
<p>The eval code cannot instantiate variable or function bindings in the variable environment of the calling context that invoked the eval if the calling context is evaluating formal parameter initializers or if either the code of the calling context or the eval code is strict mode code. Instead such bindings are instantiated in a new VariableEnvironment that is only accessible to the eval code. Bindings introduced by `let`, `const`, or `class` declarations are always instantiated in a new LexicalEnvironment.</p>
<h1>Additional Early Error Rules for Eval Outside Constructor Methods</h1>
23491
-
<p>These static semantics are applied by PerformEval when a direct eval call occurs outside of the <emu-xref href="#sec-static-semantics-constructormethod">constructor method</emu-xref> of a |ClassDeclaration| or |ClassExpression|.</p>
1. Let _parameters_ be the result of parsing _P_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, using _parameterGoal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
24754
-
1. Let _body_ be the result of parsing _bodyText_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, using _goal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
24755
-
1. Let _strict_ be ContainsUseStrict of _body_.
24756
-
1. If any static semantics errors are detected for _parameters_ or _body_, throw a *SyntaxError* or a *ReferenceError* exception, depending on the type of the error. If _strict_ is *true*, the Early Error rules for <emu-grammar>UniqueFormalParameters : FormalParameters</emu-grammar> are applied. Parsing and early error detection may be interweaved in an implementation-dependent manner.
24757
-
1. If _strict_ is *true* and IsSimpleParameterList of _parameters_ is *false*, throw a *SyntaxError* exception.
24758
-
1. If any element of the BoundNames of _parameters_ also occurs in the LexicallyDeclaredNames of _body_, throw a *SyntaxError* exception.
24759
-
1. If _body_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
24760
-
1. If _parameters_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
24761
-
1. If _body_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
24762
-
1. If _parameters_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
24763
-
1. If _kind_ is `"generator"` or `"async generator"`, then
24764
-
1. If _parameters_ Contains |YieldExpression| is *true*, throw a *SyntaxError* exception.
24765
-
1. If _kind_ is `"async"` or `"async generator"`, then
24766
-
1. If _parameters_ Contains |AwaitExpression| is *true*, throw a *SyntaxError* exception.
24767
-
1. If _strict_ is *true*, then
24768
-
1. If BoundNames of _parameters_ contains any duplicate elements, throw a *SyntaxError* exception.
24730
+
1. Perform the following substeps in an implementation-dependent order, possibly interleaving parsing and error detection:
24731
+
1. Let _parameters_ be the result of parsing _P_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, using _parameterGoal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
24732
+
1. Let _body_ be the result of parsing _bodyText_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, using _goal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
24733
+
1. Let _strict_ be ContainsUseStrict of _body_.
24734
+
1. If any static semantics errors are detected for _parameters_ or _body_, throw a *SyntaxError* or a *ReferenceError* exception, depending on the type of the error. If _strict_ is *true*, the Early Error rules for <emu-grammar>UniqueFormalParameters : FormalParameters</emu-grammar> are applied.
24735
+
1. If _strict_ is *true* and IsSimpleParameterList of _parameters_ is *false*, throw a *SyntaxError* exception.
24736
+
1. If any element of the BoundNames of _parameters_ also occurs in the LexicallyDeclaredNames of _body_, throw a *SyntaxError* exception.
24737
+
1. If _body_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
24738
+
1. If _parameters_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
24739
+
1. If _body_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
24740
+
1. If _parameters_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
24741
+
1. If _kind_ is `"generator"` or `"async generator"`, then
24742
+
1. If _parameters_ Contains |YieldExpression| is *true*, throw a *SyntaxError* exception.
24743
+
1. If _kind_ is `"async"` or `"async generator"`, then
24744
+
1. If _parameters_ Contains |AwaitExpression| is *true*, throw a *SyntaxError* exception.
24745
+
1. If _strict_ is *true*, then
24746
+
1. If BoundNames of _parameters_ contains any duplicate elements, throw a *SyntaxError* exception.
24769
24747
1. Let _proto_ be ? GetPrototypeFromConstructor(_newTarget_, _fallbackProto_).
24770
24748
1. Let _F_ be FunctionAllocate(_proto_, _strict_, _kind_).
0 commit comments