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();
Wednesday, December 21, 2022
let, var and const
Monday, December 19, 2022
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
- Let env be GetThisEnvironment()// loop up LexicalEnvironment until found an Environment who's HasThisBinding() returns true.
- Let actualThis be ?env.GetThisBinding()
- Let propertyKey be StringValue of IdentifierName
- If the code matched by this SuperProperty is strict mode code, let strict be true; else let strict be false.
- Let baseValue be ?env.GetSuperBase():
- Let home be envRec.[[HomeObject]].
- If home has the value undefined, return undefined.
- Return ? home.[[GetPrototypeOf]]().
- 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
There are following basic rules of semicolon insertion:
- 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
- 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 + bis 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
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
Friday, December 16, 2022
Proxy Objects
A proxy object is an exotic object whose essential internal methods are partially implemented using ECMAScript code. Every proxy object has an internal slot called [[ProxyHandler]]. The value of [[ProxyHandler]] is an object, called the proxy's handler object, or null. Every proxy object also has an internal slot called [[ProxyTarget]] whose value is either an object or the null value. This object is called the proxy's target object.
When a handler method is called to provide the implementation of a proxy object internal method, the handler method is passed the proxy's target object as a parameter. Invoking an internal method on the proxy results in the invocation of the corresponding internal method on the proxy's target object if the handler object does not have a method corresponding to the internal trap.
[[GetPrototypeOf]] ( )
- Let trap be ? GetMethod(handler, "getPrototypeOf").
- If not IsExtensible(target) or trap is undefined, Return ? target.[[GetPrototypeOf]]().
- return call trap on target to get target's prototype
[[SetPrototypeOf]] ( V )
- if not IsExtensible(target), return true
- Let trap be ? GetMethod(handler, "setPrototypeOf").
- If trap is undefined, Return ? target.[[SetPrototypeOf]](V).
- return call trap on target&V to set target's prototype
Arguments Exotic Objects
Most ECMAScript functions make an arguments object available to their code. Depending upon the characteristics of the function definition, its arguments object is either an ordinary object or an arguments exotic object.
An arguments exotic object is an exotic object whose array index properties map to the formal parameters bindings.
Arguments exotic objects have a [[ParameterMap]] internal slot. Ordinary arguments objects also have a [[ParameterMap]] internal slot whose value is always undefined.
[[GetOwnProperty]] ( P )
- Let args be the arguments object.
- Let desc be OrdinaryGetOwnProperty(args, P).
- If desc is undefined, return desc.
- Let map be args.[[ParameterMap]].
- Let isMapped be HasOwnProperty(map, P).
- If isMapped, set desc.[[Value]] to Get(map, P)
- Return desc.
[[DefineOwnProperty]] ( P, Desc )
- Let newArgDesc be Desc.
- If isMapped and Desc.[[Value]] is not present and Desc.[[Writable]] is false,
Set newArgDesc to a copy of Desc except newArgDesc.[[Value]] as Get(map, P)
- if not OrdinaryDefineOwnProperty(args, P, newArgDesc), return false.
- If isMapped is false, return true
- If IsAccessorDescriptor(Desc), call map.[[Delete]](P) and return true
- If Desc.[[Value]] is present, Set(map, P, Desc.[[Value]], false).
- If Desc.[[Writable]] is false, Call map.[[Delete]](P)