A 32-bit signed value can be treated as having a binary point immediately after its sign bit. This is equivalent
to dividing its signed integer value by 231, so that it can now represent numbers from –1 to (1 – 2–31). When
a 32-bit value is used to represent a fractional number in this fashion, it is known as a Q31 number.
Saturated additions, subtractions, and doublings can be performed on Q31 numbers using the same
instructions as are used for saturated integer arithmetic, since everything is simply scaled down by a factor
of 2–31.
If two Q15 numbers are multiplied together as integers, the resulting integer needs to be scaled down by a
factor of 2–15 × 2–15 == 2–30. For example, multiplying the Q15 number 0x8000 (representing –1) by itself
using an integer multiplication instruction yields the value 0x40000000, which is 230 times the desired
result of +1.
This means that the result of the integer multiplication instruction is not quite in Q31 form. To get it into
Q31 form, it must be doubled, so that the required scaling factor becomes 2–31. Furthermore, it is possible
that the doubling will cause integer overflow, so the result should in fact be doubled with saturation. In
particular, the result 0x40000000 from the multiplication of 0x8000 by itself should be doubled with
saturation to produce 0x7FFFFFFF (the closest possible Q31 number to the correct mathematical result of
–1 × –1 == +1). If it were doubled without saturation, it would instead produce 0x80000000, which is the
Q31 representation of –1.
To implement a saturated Q15 × Q15 --> Q31 multiplication, therefore, an integer multiply instruction
should be followed by a saturated integer doubling. The latter can be performed by a QADD instruction
adding the multiply result to itself.
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.
If m is less than zero, return the String concatenation of the String "-" and ToString(-m).
If m is infinity, return the String "Infinity".
let n, k, and s be integers such that k >= 1, s in [10^(k-1), 10^k), the Number value for s * 10^(n-k) is m. Note that k is the number of digits in the decimal representation of s, that s is not divisible by 10.
if both k and n are no greater than 21:
if k is no greater than n, return the string-concatenation of:
the k digits of the decimal representation of s
n−k occurrences of the character 0
if n is greater than 0, return the string-concatenation of:
the code units of the most significant n digits of the decimal representation of s
the code unit 0x002E (FULL STOP)
the code units of the remaining k - n digits of the decimal representation of s
If NewTarget is not undefined, throw a TypeError exception.
Note: the Symbol Constructor is not intended to be used with the new operator(not the target for new)
If description is undefined, let descString be undefined; Else, let descString be ? ToString(description).
Return a new unique Symbol value whose [[Description]] value is descString.
Note: the Symbol() function returns a Symbol type instead of a Symbol object
Symbol Prototype Object
abstract operation thisSymbolValue(value)
If Type(value) is Symbol, return value.
If Type(value) is Object and value has a [[SymbolData]] internal slot
then Return value.[[SymbolData]] //a Symbol Object
Throw a TypeError exception.
Example
mySymbol = Symbol( "my symbol" )
// Object() performs a type conversion when called as a function rather than as a constructor.
mySymObj = Object(mySymbol)
console.log(mySymObj.toString()) // Symbol(my symbol)