From 80c4419202b4ce213d30a9e6003b8b92a913edb4 Mon Sep 17 00:00:00 2001 From: Michael Dyck Date: Wed, 20 Mar 2024 15:59:47 -0700 Subject: [PATCH] Editorial: Introduce IsStrict() abstract operation (#3209) (The pre-existing "IsStrict" AO is renamed to "ScriptIsStrict".) --- spec.html | 85 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/spec.html b/spec.html index 3ebc012ea9..1259b79998 100644 --- a/spec.html +++ b/spec.html @@ -9699,7 +9699,7 @@

Static Semantics: AssignmentTargetType ( ): ~simple~ or ~invalid~

IdentifierReference : Identifier - 1. If this |IdentifierReference| is contained in strict mode code and StringValue of |Identifier| is either *"eval"* or *"arguments"*, return ~invalid~. + 1. If IsStrict(this |IdentifierReference|) is *true* and StringValue of |Identifier| is either *"eval"* or *"arguments"*, return ~invalid~. 1. Return ~simple~. @@ -11841,7 +11841,7 @@

1. If _env_ is not present or _env_ is *undefined*, then 1. Set _env_ to the running execution context's LexicalEnvironment. 1. Assert: _env_ is an Environment Record. - 1. If the source text matched by the syntactic production that is being evaluated is contained in strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(the syntactic production that is being evaluated). 1. Return ? GetIdentifierReference(_env_, _name_, _strict_). @@ -13477,7 +13477,7 @@

1. Set _F_.[[SourceText]] to _sourceText_. 1. Set _F_.[[FormalParameters]] to _ParameterList_. 1. Set _F_.[[ECMAScriptCode]] to _Body_. - 1. If the source text matched by _Body_ is strict mode code, let _Strict_ be *true*; else let _Strict_ be *false*. + 1. Let _Strict_ be IsStrict(_Body_). 1. Set _F_.[[Strict]] to _Strict_. 1. If _thisMode_ is ~lexical-this~, set _F_.[[ThisMode]] to ~lexical~. 1. Else if _Strict_ is *true*, set _F_.[[ThisMode]] to ~strict~. @@ -16209,6 +16209,19 @@

Strict Mode Code

ECMAScript code that is not strict mode code is called non-strict code.

+ + +

+ Static Semantics: IsStrict ( + _node_: a Parse Node, + ): a Boolean +

+
+
+ + 1. If the source text matched by _node_ is strict mode code, return *true*; else return *false*. + +
@@ -16878,7 +16891,7 @@

Static Semantics: Early Errors

DecimalIntegerLiteral :: NonOctalDecimalIntegerLiteral
    -
  • It is a Syntax Error if the source text matched by this production is strict mode code.
  • +
  • It is a Syntax Error if IsStrict(this production) is *true*.
In non-strict code, this syntax is Legacy.
@@ -17145,7 +17158,7 @@

Static Semantics: Early Errors

NonOctalDecimalEscapeSequence
    -
  • It is a Syntax Error if the source text matched by this production is strict mode code.
  • +
  • It is a Syntax Error if IsStrict(this production) is *true*.
In non-strict code, this syntax is Legacy. @@ -18002,7 +18015,7 @@

Static Semantics: Early Errors

BindingIdentifier : Identifier
  • - It is a Syntax Error if the source text matched by this production is contained in strict mode code and the StringValue of |Identifier| is either *"arguments"* or *"eval"*. + It is a Syntax Error if IsStrict(this production) is *true* and the StringValue of |Identifier| is either *"arguments"* or *"eval"*.
@@ -18014,7 +18027,7 @@

Static Semantics: Early Errors

  • - It is a Syntax Error if the source text matched by this production is contained in strict mode code. + It is a Syntax Error if IsStrict(this production) is *true*.
@@ -18063,7 +18076,7 @@

Static Semantics: Early Errors

Identifier : IdentifierName but not ReservedWord
  • - It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of |IdentifierName| is one of *"implements"*, *"interface"*, *"let"*, *"package"*, *"private"*, *"protected"*, *"public"*, *"static"*, or *"yield"*. + It is a Syntax Error if IsStrict(this phrase) is *true* and the StringValue of |IdentifierName| is one of *"implements"*, *"interface"*, *"let"*, *"package"*, *"private"*, *"protected"*, *"public"*, *"static"*, or *"yield"*.
  • It is a Syntax Error if the goal symbol of the syntactic grammar is |Module| and the StringValue of |IdentifierName| is *"await"*. @@ -19096,14 +19109,14 @@

    Runtime Semantics: Evaluation

    1. Let _baseReference_ be ? Evaluation of |MemberExpression|. 1. Let _baseValue_ be ? GetValue(_baseReference_). - 1. If the source text matched by this |MemberExpression| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |MemberExpression|). 1. Return ? EvaluatePropertyAccessWithExpressionKey(_baseValue_, |Expression|, _strict_). MemberExpression : MemberExpression `.` IdentifierName 1. Let _baseReference_ be ? Evaluation of |MemberExpression|. 1. Let _baseValue_ be ? GetValue(_baseReference_). - 1. If the source text matched by this |MemberExpression| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |MemberExpression|). 1. Return EvaluatePropertyAccessWithIdentifierKey(_baseValue_, |IdentifierName|, _strict_). MemberExpression : MemberExpression `.` PrivateIdentifier @@ -19117,14 +19130,14 @@

    Runtime Semantics: Evaluation

    1. Let _baseReference_ be ? Evaluation of |CallExpression|. 1. Let _baseValue_ be ? GetValue(_baseReference_). - 1. If the source text matched by this |CallExpression| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |CallExpression|). 1. Return ? EvaluatePropertyAccessWithExpressionKey(_baseValue_, |Expression|, _strict_). CallExpression : CallExpression `.` IdentifierName 1. Let _baseReference_ be ? Evaluation of |CallExpression|. 1. Let _baseValue_ be ? GetValue(_baseReference_). - 1. If the source text matched by this |CallExpression| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |CallExpression|). 1. Return EvaluatePropertyAccessWithIdentifierKey(_baseValue_, |IdentifierName|, _strict_). CallExpression : CallExpression `.` PrivateIdentifier @@ -19225,7 +19238,7 @@

    Runtime Semantics: Evaluation

    1. Let _argList_ be ? ArgumentListEvaluation of _arguments_. 1. If _argList_ has no elements, return *undefined*. 1. Let _evalArg_ be the first element of _argList_. - 1. If the source text matched by this |CallExpression| is strict mode code, let _strictCaller_ be *true*. Otherwise let _strictCaller_ be *false*. + 1. If IsStrict(this |CallExpression|) is *true*, let _strictCaller_ be *true*. Otherwise let _strictCaller_ be *false*. 1. [id="step-callexpression-evaluation-direct-eval"] Return ? PerformEval(_evalArg_, _strictCaller_, *true*). 1. Let _thisCall_ be this |CallExpression|. 1. Let _tailCall_ be IsInTailPosition(_thisCall_). @@ -19284,7 +19297,7 @@

    Runtime Semantics: Evaluation

    1. Let _propertyNameReference_ be ? Evaluation of |Expression|. 1. Let _propertyNameValue_ be ? GetValue(_propertyNameReference_). 1. Let _propertyKey_ be ? ToPropertyKey(_propertyNameValue_). - 1. If the source text matched by this |SuperProperty| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |SuperProperty|). 1. Return ? MakeSuperPropertyReference(_actualThis_, _propertyKey_, _strict_). SuperProperty : `super` `.` IdentifierName @@ -19292,7 +19305,7 @@

    Runtime Semantics: Evaluation

    1. Let _env_ be GetThisEnvironment(). 1. Let _actualThis_ be ? _env_.GetThisBinding(). 1. Let _propertyKey_ be StringValue of |IdentifierName|. - 1. If the source text matched by this |SuperProperty| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |SuperProperty|). 1. Return ? MakeSuperPropertyReference(_actualThis_, _propertyKey_, _strict_). SuperCall : `super` Arguments @@ -19475,12 +19488,12 @@

    OptionalChain : `?.` `[` Expression `]` - 1. If the source text matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |OptionalChain|). 1. Return ? EvaluatePropertyAccessWithExpressionKey(_baseValue_, |Expression|, _strict_). OptionalChain : `?.` IdentifierName - 1. If the source text matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |OptionalChain|). 1. Return EvaluatePropertyAccessWithIdentifierKey(_baseValue_, |IdentifierName|, _strict_). OptionalChain : `?.` PrivateIdentifier @@ -19502,7 +19515,7 @@

    1. Let _optionalChain_ be |OptionalChain|. 1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_. 1. Let _newValue_ be ? GetValue(_newReference_). - 1. If the source text matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |OptionalChain|). 1. Return ? EvaluatePropertyAccessWithExpressionKey(_newValue_, |Expression|, _strict_). OptionalChain : OptionalChain `.` IdentifierName @@ -19510,7 +19523,7 @@

    1. Let _optionalChain_ be |OptionalChain|. 1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_. 1. Let _newValue_ be ? GetValue(_newReference_). - 1. If the source text matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*. + 1. Let _strict_ be IsStrict(this |OptionalChain|). 1. Return EvaluatePropertyAccessWithIdentifierKey(_newValue_, |IdentifierName|, _strict_). OptionalChain : OptionalChain `.` PrivateIdentifier @@ -19816,7 +19829,7 @@

    Static Semantics: Early Errors

    UnaryExpression : `delete` UnaryExpression
    • - It is a Syntax Error if the |UnaryExpression| is contained in strict mode code and the derived |UnaryExpression| is PrimaryExpression : IdentifierReference, MemberExpression : MemberExpression `.` PrivateIdentifier, CallExpression : CallExpression `.` PrivateIdentifier, OptionalChain : `?.` PrivateIdentifier, or OptionalChain : OptionalChain `.` PrivateIdentifier. + It is a Syntax Error if IsStrict(the |UnaryExpression|) is *true* and the derived |UnaryExpression| is PrimaryExpression : IdentifierReference, MemberExpression : MemberExpression `.` PrivateIdentifier, CallExpression : CallExpression `.` PrivateIdentifier, OptionalChain : `?.` PrivateIdentifier, or OptionalChain : OptionalChain `.` PrivateIdentifier.
    • @@ -22536,7 +22549,7 @@

      Static Semantics: Early Errors

      WithStatement : `with` `(` Expression `)` Statement
      • - It is a Syntax Error if the source text matched by this production is contained in strict mode code. + It is a Syntax Error if IsStrict(this production) is *true*.
      • It is a Syntax Error if IsLabelledFunction(|Statement|) is *true*. @@ -23324,10 +23337,10 @@

        Static Semantics: Early Errors

        • - If the source text matched by |FormalParameters| is strict mode code, the Early Error rules for UniqueFormalParameters : FormalParameters are applied. + If IsStrict(|FormalParameters|) is *true*, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
        • - If |BindingIdentifier| is present and the source text matched by |BindingIdentifier| is strict mode code, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*. + If |BindingIdentifier| is present and IsStrict(|BindingIdentifier|) is *true*, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*.
        • It is a Syntax Error if FunctionBodyContainsUseStrict of |FunctionBody| is *true* and IsSimpleParameterList of |FormalParameters| is *false*. @@ -23893,10 +23906,10 @@

          Static Semantics: Early Errors

          • - If the source text matched by |FormalParameters| is strict mode code, the Early Error rules for UniqueFormalParameters : FormalParameters are applied. + If IsStrict(|FormalParameters|) is *true*, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
          • - If |BindingIdentifier| is present and the source text matched by |BindingIdentifier| is strict mode code, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*. + If |BindingIdentifier| is present and IsStrict(|BindingIdentifier|) is *true*, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*.
          • It is a Syntax Error if FunctionBodyContainsUseStrict of |GeneratorBody| is *true* and IsSimpleParameterList of |FormalParameters| is *false*. @@ -24134,8 +24147,8 @@

            Static Semantics: Early Errors

            `async` `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
              -
            • If the source text matched by |FormalParameters| is strict mode code, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
            • -
            • If |BindingIdentifier| is present and the source text matched by |BindingIdentifier| is strict mode code, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*.
            • +
            • If IsStrict(|FormalParameters|) is *true*, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
            • +
            • If |BindingIdentifier| is present and IsStrict(|BindingIdentifier|) is *true*, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*.
            • It is a Syntax Error if FunctionBodyContainsUseStrict of |AsyncGeneratorBody| is *true* and IsSimpleParameterList of |FormalParameters| is *false*.
            • It is a Syntax Error if any element of the BoundNames of |FormalParameters| also occurs in the LexicallyDeclaredNames of |AsyncGeneratorBody|.
            • It is a Syntax Error if |FormalParameters| Contains |YieldExpression| is *true*.
            • @@ -25080,8 +25093,8 @@

              Static Semantics: Early Errors

              • It is a Syntax Error if FunctionBodyContainsUseStrict of |AsyncFunctionBody| is *true* and IsSimpleParameterList of |FormalParameters| is *false*.
              • It is a Syntax Error if |FormalParameters| Contains |AwaitExpression| is *true*.
              • -
              • If the source text matched by |FormalParameters| is strict mode code, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
              • -
              • If |BindingIdentifier| is present and the source text matched by |BindingIdentifier| is strict mode code, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*.
              • +
              • If IsStrict(|FormalParameters|) is *true*, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
              • +
              • If |BindingIdentifier| is present and IsStrict(|BindingIdentifier|) is *true*, it is a Syntax Error if the StringValue of |BindingIdentifier| is either *"eval"* or *"arguments"*.
              • It is a Syntax Error if any element of the BoundNames of |FormalParameters| also occurs in the LexicallyDeclaredNames of |AsyncFunctionBody|.
              • It is a Syntax Error if |FormalParameters| Contains |SuperProperty| is *true*.
              • It is a Syntax Error if |AsyncFunctionBody| Contains |SuperProperty| is *true*.
              • @@ -25353,7 +25366,7 @@

                - 1. If the source text matched by _call_ is non-strict code, return *false*. + 1. If IsStrict(_call_) is *false*, return *false*. 1. If _call_ is not contained within a |FunctionBody|, a |ConciseBody|, or an |AsyncConciseBody|, return *false*. 1. Let _body_ be the |FunctionBody|, |ConciseBody|, or |AsyncConciseBody| that most closely contains _call_. 1. If _body_ is the |FunctionBody| of a |GeneratorBody|, return *false*. @@ -25767,8 +25780,8 @@

                Static Semantics: Early Errors

              - -

              Static Semantics: IsStrict ( ): a Boolean

              + +

              Static Semantics: ScriptIsStrict ( ): a Boolean

              Script : ScriptBody? @@ -28907,7 +28920,7 @@

              1. If _inDerivedConstructor_ is *false* and _body_ Contains |SuperCall|, throw a *SyntaxError* exception. 1. If _inClassFieldInitializer_ is *true* and ContainsArguments of _body_ is *true*, throw a *SyntaxError* exception. 1. If _strictCaller_ is *true*, let _strictEval_ be *true*. - 1. Else, let _strictEval_ be IsStrict of _script_. + 1. Else, let _strictEval_ be ScriptIsStrict of _script_. 1. Let _runningContext_ be the running execution context. 1. NOTE: If _direct_ is *true*, _runningContext_ will be the execution context that performed the direct eval. If _direct_ is *false*, _runningContext_ will be the execution context for the invocation of the `eval` function. 1. If _direct_ is *true*, then @@ -50523,7 +50536,7 @@

              Changes to GlobalDeclarationInstantiation

              During GlobalDeclarationInstantiation the following steps are performed in place of step :

              1. Perform the following steps: - 1. Let _strict_ be IsStrict of _script_. + 1. Let _strict_ be ScriptIsStrict of _script_. 1. If _strict_ is *false*, then 1. Let _declaredFunctionOrVarNames_ be the list-concatenation of _declaredFunctionNames_ and _declaredVarNames_. 1. For each |FunctionDeclaration| _f_ that is directly contained in the |StatementList| of a |Block|, |CaseClause|, or |DefaultClause| Contained within _script_, do @@ -50594,7 +50607,7 @@

              Changes to Block Static Semantics: Early Errors

              Block : `{` StatementList `}`
              • - It is a Syntax Error if the LexicallyDeclaredNames of |StatementList| contains any duplicate entries, unless the source text matched by this production is not strict mode code and the duplicate entries are only bound by FunctionDeclarations. + It is a Syntax Error if the LexicallyDeclaredNames of |StatementList| contains any duplicate entries, unless IsStrict(this production) is *false* and the duplicate entries are only bound by FunctionDeclarations.
              • It is a Syntax Error if any element of the LexicallyDeclaredNames of |StatementList| also occurs in the VarDeclaredNames of |StatementList|. @@ -50608,7 +50621,7 @@

                Changes to `switch` Statement Static Semantics: Early Errors

                SwitchStatement : `switch` `(` Expression `)` CaseBlock
                • - It is a Syntax Error if the LexicallyDeclaredNames of |CaseBlock| contains any duplicate entries, unless the source text matched by this production is not strict mode code and the duplicate entries are only bound by FunctionDeclarations. + It is a Syntax Error if the LexicallyDeclaredNames of |CaseBlock| contains any duplicate entries, unless IsStrict(this production) is *false* and the duplicate entries are only bound by FunctionDeclarations.
                • It is a Syntax Error if any element of the LexicallyDeclaredNames of |CaseBlock| also occurs in the VarDeclaredNames of |CaseBlock|.