Friday, January 6, 2023

Global Environment Record

Global Environment Record

A global Environment Record is used to represent the outer most scope that is shared by all of the ECMAScript Script elements that are processed in a common realm. A global Environment Record provides the bindings for built-in globals, properties of the global object(FunctionDeclaration or VariableStatement), and for all top-level declarations(the let and const declarations) that occur within a Script.

A global Environment Record is logically a single record but it is specified as a composite encapsulating of object Environment Record([[ObjectRecord]]) and a declarative Environment Record([[DeclarativeRecord]]).

The object Environment Record has as its base object the global object of the associated Realm Record. This global object is the value returned by the global Environment Record's GetThisBinding concrete method:

 Let envRec be the global Environment Record for which the method was invoked.
 Return envRec.[[GlobalThisValue]]
 zxxu: according to ecma, Regular object Environment Records do not provide a this binding, so global Environment Record has a  [[GlobalThisValue]] field

The object Environment Record contains the bindings for all built-in globals and all bindings introduced by a FunctionDeclaration or VariableStatement contained in global code. The bindings for all other ECMAScript declarations(the let and const declarations) in global code are contained in the declarative Environment Record component.

Properties may exist upon a global object that were directly created rather than being declared using a var or function declaration. so global Environment Record also has a field [[VarNames]] for string names bound by FunctionDeclaration or VariableDeclaration.

No comments:

Post a Comment