How to Read the ECMAScript Specification (Timothygu.me)
preface
The Javascript engine is implemented according to the ES specification. The specification describes syntax, runtime semantics, APIs, and so on. Does not include the API provided by the host, how to load, etc. ECMAScript® 2022 Language Specification (TC39.es)
Runtime semantic
The specification describes the steps of the algorithm in a more accurate way, similar to pseudocode.
A sample set of algorithm steps are:
1. Let a be 1.
2. Let b be a + a.
3. If b is 2, then
1. Hooray! Arithmetics isn’t broken.
4. Else
1. Boo!
Copy the code
Abstract operations
When `Boolean` is called with argument `value`, the following steps are taken:
1. Let `b` be ! ToBoolean(value)
2. ...
Copy the code
ToBoolean is an abstract method.
Abstract methods are like functions that take inputs and outputs. But not exposed to JavaScript code, just used to describe algorithms used to reduce repeated descriptions.
[[this]] symbols
-
The field representing the Record
In the specification, Record refers to a set of key-values, similar to the C language structure. Exists only in the ES specification.
-
Represents an internal slot for a JavaScirpt Object
Cannot be accessed by JavaScirpt code. For example ` O `. [[Prototype]].
-
Represents an internal method of a javascript Object
Such as the call method of a function. Such as f. [[Call]] (` V `, ` argumentsList `).
?
和 !
symbol
Pre-knowledge, each Runtime Semantic returns a Completion Record. There are also normal completion and abnormal completion. ECMAScript® 2022 Language Specification (TC39.es)
? Make sure you get the [[value]] of Normal Completion for the abstract operation to be invoked. That is, if the abstract operation throws an exception, the algorithmic step here terminates.
! This explicitly states that an abstract operation must not throw an exception.
JavaScript
object
Divided into original objects and variable objects, directly on the class diagram:
practice
The author also takes the reader to analyze 3 standard algorithm examples, if you are interested, please go to read. How to Read the ECMAScript Specification (timothygu.me)
The resources
How to Read the ECMAScript Specification (timothygu.me)
ECMAScript® 2022 Language Specification (tc39.es)