Thursday, December 22, 2022

LexicallyScopedDeclarations

LexicallyScopedDeclarations

Block

  1. StatementList : StatementList StatementListItem //StatementListItem can be Statement or Declaration
        Let declarations be LexicallyScopedDeclarations of StatementList.
        Append to declarations the elements of the LexicallyScopedDeclarations of StatementListItem.
        Return declarations.
    
  2. StatementListItem : Declaration
        Return a new List containing the Declaration
    

FunctionStatementList : StatementList or Script

    Return the TopLevelLexicallyScopedDeclarations of StatementList.

LabelledItem : FunctionDeclaration

Return a new List containing FunctionDeclaration.

Others

not documented in ecma documents

`catch ( CatchParameter ) Block` is not mentioned, but according to "Runtime Semantics: CatchClauseEvaluation", CatchParameter should be Lexically Declared

VarScopedDeclarations

VarScopedDeclarations

Block

  1. Block : { }
        Return a new empty List.
    
  2. StatementList : StatementList StatementListItem //StatementListItem can be Statement or Declaration
        Let declarations be VarScopedDeclarations of StatementList.
        Append to declarations the elements of the VarScopedDeclarations of StatementListItem.
        Return declarations.
    
  3. StatementListItem : Declaration
        Return a new empty List// `let ` or `const ` Declaration is Lex, funct decl is top Var
    

Variable Statement

Return a new List contains all VariableDeclaration

FunctionStatementList : StatementList or Script

    Return the TopLevelVarScopedDeclarations of StatementList.

Statements contains subs

if/while/for/with/switch/label/try Statement, return a new List contains all VariableDeclaration of the sub(s)

for the case of `for(var `, the new List is pre-feed.

note in `catch ( CatchParameter ) Block`, CatchParameter is not included.

note in label Statement, `LabelledItem : FunctionDeclaration` Return a new empty List.

Others

not documented in ecma documents

Wednesday, December 21, 2022

let, var and const

let, var and const
function outer_func()
{
    {{
        var var01 = "var01";
        let innerLet = "innerLet";//        const innerCst = "innerCst";

        function inner_func()
        {
            alert("inner_func");
        }
    }}
    // var01 is accessible here
    // it's an early error to access innerLet here

    inner_func();
}

outer_func();

Monday, December 19, 2022

GetSuperConstructor

12.3.7.2 Runtime Semantics: GetSuperConstructor ( )

return GetThisEnvironment().[[FunctionObject]].[[GetPrototypeOf]]()

example

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super : super([arguments]) // calls the parent constructor.

12.3.7.1 Runtime Semantics: Evaluation of super . IdentifierName

12.3.7.1 Runtime Semantics: Evaluation of super . IdentifierName SuperProperty : super . IdentifierName:
  1. Let env be GetThisEnvironment()// loop up LexicalEnvironment until found an Environment who's HasThisBinding() returns true.
  2. Let actualThis be ?env.GetThisBinding()
  3. Let propertyKey be StringValue of IdentifierName
  4. If the code matched by this SuperProperty is strict mode code, let strict be true; else let strict be false.
  5. Let baseValue be ?env.GetSuperBase():
    • Let home be envRec.[[HomeObject]].
    • If home has the value undefined, return undefined.
    • Return ? home.[[GetPrototypeOf]]().
  6. Return a value of type Reference that is a Super Reference whose base value component is baseValue, whose referenced name component is propertyKey, whose thisValue component is actualThis, and whose strict reference flag is strict.

Sunday, December 18, 2022

Automatic Semicolon Insertion

Automatic Semicolon Insertion

There are following basic rules of semicolon insertion:

  1. When a token is encountered is not allowed by any production of the grammar, then a semicolon is automatically inserted before if one or more of the following conditions is true:
    • The offending token is separated from the previous token by at least one LineTerminator.
    • The offending token is }.
    • The previous token is ) and the inserted semicolon would then be parsed as the terminating semicolon of a do-while statement
  2. When a token is allowed by some production of the grammar, but the production is a restricted production and
    • the token would be the first token for a terminal or nonterminal immediately following the annotation "[no LineTerminator here]" within the restricted production(and therefore such a token is called a restricted token)
    • the restricted token is separated from the previous token by at least one LineTerminator

However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement or if that semicolon would become one of the two semicolons in the header of a for-statement

example 01

The source

return
a + b
is transformed by automatic semicolon insertion into the following:
return;
a + b;

according to rule 2 and `return [no LineTerminator here] Expression`

Saturday, December 17, 2022

ReservedWord

ReservedWord

IdentifierName can be devided into ReservedWord and Identifier.

A keyword is a token that matches IdentifierName, but also has a syntactic use.

Many keywords are reserved words, but some are reserved only in certain contexts. contextual keywords(await and yield) belong to ReservedWord but sometimes can be used as identifiers.

Followings belong to Identifier but not intepreted as so under certain syntactic productions:

  • let, static
  • implements, interface, package, private, protected, public; but in future, they will become reserved.
  • as, async, from, get, meta, of, set