From 063835c9658a2760fecf08686dd037a63b8f2797 Mon Sep 17 00:00:00 2001 From: Michael Dyck Date: Wed, 20 Mar 2024 15:59:20 -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 70286aa4bc6..44264bfdf9a 100644 --- a/spec.html +++ b/spec.html @@ -9701,7 +9701,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~. @@ -11843,7 +11843,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_). @@ -13479,7 +13479,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~. @@ -16210,6 +16210,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*. + +
@@ -16879,7 +16892,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.
@@ -17146,7 +17159,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. @@ -18003,7 +18016,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"*.
@@ -18015,7 +18028,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*.
@@ -18064,7 +18077,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"*. @@ -19097,14 +19110,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 @@ -19118,14 +19131,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 @@ -19226,7 +19239,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_). @@ -19285,7 +19298,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 @@ -19293,7 +19306,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 @@ -19476,12 +19489,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 @@ -19503,7 +19516,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 @@ -19511,7 +19524,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 @@ -19817,7 +19830,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.
    • @@ -22537,7 +22550,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*. @@ -23325,10 +23338,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*. @@ -23894,10 +23907,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*. @@ -24135,8 +24148,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*.
            • @@ -25081,8 +25094,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*.
              • @@ -25354,7 +25367,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*. @@ -25768,8 +25781,8 @@

                Static Semantics: Early Errors

              - -

              Static Semantics: IsStrict ( ): a Boolean

              + +

              Static Semantics: ScriptIsStrict ( ): a Boolean

              Script : ScriptBody? @@ -28908,7 +28921,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 @@ -50524,7 +50537,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 @@ -50595,7 +50608,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|. @@ -50609,7 +50622,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|.