Last active
February 9, 2018 19:42
-
-
Save DmitrySoshnikov/042e683f83c39071aa69a2ec2b83072e to your computer and use it in GitHub Desktop.
ES7 Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by Dmitry Soshnikov | |
ES7: | |
== Lexical environment == | |
- Environment Record | |
- parent (can be null) | |
== Environment Record == | |
* Two main types: | |
- DeclarativeEnvRecord (function declarations, vars, catch-clause) | |
- ObjectEnvRecord (with-statement) | |
* There are also: | |
- FunctionEnvRecord extends DeclarativeEnvRecord | |
- ModuleEnvRecord extends DeclarativeEnvRecord | |
* ObjectEnvRecord: | |
- Binding Object {x: 1, '0': 2} | |
- Bound names: only `x`, since 0 isn't ID | |
* FunctionEnvRecord: | |
- [[ThisValue]] | |
- [[ThisBindingStatus]]: {lexical, initialized, uninitialized} | |
(if lexical, then it's an Arrow function, and doesn't have local `this`) | |
- [[FunctionObject]] - the function whose invocation created the record | |
- [[HomeObject]] - if a function has `super` call, and is not an Arrow function, | |
this is the object that the function is bound to as a method (default is `undefined`) | |
- [[NewTarget]] - if the record is created by [[Construct]], this contains the value of | |
the `newTarget` parameter of the [[Construct]], otherwise `undefined`. | |
Methods: BindThisValue, GetThisBinding, GetSuperBase (returns [[HomeObject]]). | |
== GlobalEnvRecord == | |
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. | |
- GlobalEnvRecord is a composite record, and has both, ObjectEnvRecord, and DeclarativeEnvRecord. | |
- The ObjectEnvRecord has the Global object (of this Realm) as the binding object. | |
The Global object is returned by the GetThisBinding, i.e. `this` is the Global in the Global context. | |
- The ObjectEnvRecord stores all Global built-ins, as well as function declarations, generators, vars. | |
Binding can be created also by just creating props direclty. ES distinguishes a binding created | |
as `var foo = 10;`, and `this.bar = 20;`. | |
- Other things, like `let`, `const`, are included in the DeclarativeEnvRecord, | |
so can't access them as props of global object. | |
GlobalEnvRecord: | |
- [[ObjectRecord]] - binding is the Global object: built-ins, FunctionDeclaration, | |
GeneratorDeclarations, VariableDeclarations of the current Realm. | |
- [[GlobalThisValue]] - `this` value of the global context (usually the global object | |
itself, though hosts may provide any) | |
- [[DeclarativeRecord]] - all other declarations (`let`, `const`, etc) | |
- [[VarNames]] - list of names appeared in FunctionDeclaration, | |
GeneratorDeclarations, VariableDeclarations. | |
== ModuleEnvRecord == | |
ModuleEnvRecord extends DeclarativeRecord, it's an outer scope of a module. | |
In additional to normal mutable and immutable bindings, module Environment | |
Records also provide immutable import bindings which are bindings that provide | |
indirect access to a target binding that exists in another Environment Record. | |
== Realms == | |
Before it is evaluated, all ECMAScript code must be associated with a realm. | |
Conceptually, a realm consists of a set of intrinsic objects, an ECMAScript | |
global environment, all of the ECMAScript code that is loaded within the scope | |
of that global environment, and other associated state and resources. | |
- [[Intrinsic]] - The intrinsic values used by code associated with this realm | |
- [[GlobalObject]] - The global object for this realm | |
- [[GlobalEnv]] - The global environment for this realm | |
- [[TemplateMap]] - for template literals within this realm | |
== Execution context == | |
A context is create at function call, eval, or Global context. The contexts are | |
pushed onto the stack (the top is the running context). | |
Structure: | |
- Code evaluation state - any state needed to perform, suspend, and resume | |
evaluation of the code associated with this execution context. | |
- Function - if this execution context is evaluating the code of a function | |
object, then the value of this component is that function object. If the | |
context is evaluating the code of a Script or Module, the value is null. | |
- Realm - The Realm Record from which associated code accesses ECMAScript resources. | |
- ScriptOrModule - The Module Record or Script Record from which associated | |
code originates. If there is no originating script or module, as is the case | |
for the original execution context created in InitializeHostDefinedRealm, | |
the value is null. | |
- LexicalEnvironment | |
- VariableEnvironment | |
- Generator | |
== Jobs and Queues == | |
A Job is an abstract operation that initiates an ECMAScript computation when no other | |
ECMAScript computation is currently in progress. A Job abstract operation may be | |
defined to accept an arbitrary set of job parameters. | |
Execution of a Job can be initiated only when there is no running execution context | |
and the execution context stack is empty. A PendingJob is a request for the future | |
execution of a Job. A PendingJob is an internal Record with the fields. | |
- [[Job]] - the name of a job. Jobs use NextStep instead of return to pass control | |
- [[Arguments]] - arguments for the job | |
- [[Realm]] - the realm associated with an Execution Context when the job is created | |
- [[ScriptOrModule]] - The script or module for the initial execution context | |
when this PendingJob is initiated | |
- [[HostDefined]] - any other fields for the job defined by a host | |
Once execution of a Job is initiated, the Job always executes to completion. | |
No other Job may be initiated until the currently running Job completes. However, | |
the currently running Job or external events may cause the enqueuing of additional | |
PendingJobs that may be initiated sometime after completion of the currently running Job. | |
A Job Queue is a FIFO queue of PendingJob records. Each Job Queue has a name and | |
the full set of available Job Queues are defined by an ECMAScript implementation. | |
There are at least two queues: | |
- ScriptJobs - Jobs that validate and evaluate ECMAScript Script and Module source text | |
- PromiseJobs - Jobs that are responses to the settlement of a Promise | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment