6 ECMAScript Data Types and Values
Algorithms within this specification manipulate values each of which has an associated
Within this specification, the notation “
6.1 ECMAScript Language Types
An ECMAScript language type corresponds to values that are directly manipulated by an ECMAScript programmer using the ECMAScript language. The ECMAScript language types are Undefined, Null, Boolean, String, Symbol, Number, BigInt, and Object. An ECMAScript language value is a value that is characterized by an ECMAScript language type.
6.1.1 The Undefined Type
The Undefined
6.1.2 The Null Type
The Null
6.1.3 The Boolean Type
The Boolean
6.1.4 The String Type
The String
ECMAScript operations that do not interpret String contents apply no further semantics. Operations that do interpret String values treat each element as a single UTF-16 code unit. However, ECMAScript does not restrict the value of or relationships between these code units, so operations that further interpret String contents as sequences of Unicode code points encoded in UTF-16 must account for ill-formed subsequences. Such operations apply special treatment to every code unit with a numeric value in the inclusive range 0xD800 to 0xDBFF (defined by the Unicode Standard as a leading surrogate, or more formally as a high-surrogate code unit) and every code unit with a numeric value in the inclusive range 0xDC00 to 0xDFFF (defined as a trailing surrogate, or more formally as a low-surrogate code unit) using the following rules:
-
A code unit that is not a
leading surrogate and not atrailing surrogate is interpreted as a code point with the same value. -
A sequence of two code units, where the first code unit c1 is a
leading surrogate and the second code unit c2 atrailing surrogate , is a surrogate pair and is interpreted as a code point with the value (c1 - 0xD800) × 0x400 + (c2 - 0xDC00) + 0x10000. (See11.1.3 ) -
A code unit that is a
leading surrogate ortrailing surrogate , but is not part of asurrogate pair , is interpreted as a code point with the same value.
The function String.prototype.normalize (see String.prototype.localeCompare (see
The rationale behind this design was to keep the implementation of Strings as simple and high-performing as possible. If ECMAScript source text is in Normalized Form C, string literals are guaranteed to also be normalized, as long as they do not contain any Unicode escape sequences.
In this specification, the phrase "the string-concatenation of A, B, ..." (where each argument is a String value, a code unit, or a sequence of code units) denotes the String value whose sequence of code units is the concatenation of the code units (in order) of each of the arguments (in order).
The phrase "the substring of S from inclusiveStart to exclusiveEnd" (where S is a String value or a sequence of code units and inclusiveStart and exclusiveEnd are integers) denotes the String value consisting of the consecutive code units of S beginning at index inclusiveStart and ending immediately before index exclusiveEnd (which is the empty String when inclusiveStart = exclusiveEnd). If the "to" suffix is omitted, the length of S is used as the value of exclusiveEnd.
6.1.4.1 StringIndexOf ( string, searchValue, fromIndex )
The abstract operation StringIndexOf takes arguments string (a String), searchValue (a String), and fromIndex (a non-negative
Assert :Type (string) is String.Assert :Type (searchValue) is String.Assert : fromIndex is a non-negativeinteger .- Let len be the length of string.
- If searchValue is the empty String and fromIndex ≤ len, return fromIndex.
- Let searchLen be the length of searchValue.
- For each
integer i starting with fromIndex such that i ≤ len - searchLen, in ascending order, do- Let candidate be the
substring of string from i to i + searchLen. - If candidate is the same sequence of code units as searchValue, return i.
- Let candidate be the
- Return -1.
If searchValue is the empty String and fromIndex is less than or equal to the length of string, this algorithm returns fromIndex. The empty String is effectively found at every position within a string, including after the last code unit.
This algorithm always returns -1 if fromIndex > the length of string.
6.1.5 The Symbol Type
The Symbol
Each possible Symbol value is unique and immutable.
Each Symbol value immutably holds an associated value called [[Description]] that is either
6.1.5.1 Well-Known Symbols
Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They are typically used as the keys of properties whose values serve as extension points of a specification algorithm. Unless otherwise specified, well-known symbols values are shared by all realms (
Within this specification a well-known symbol is referred to by using a notation of the form @@name, where “name” is one of the values listed in
| Specification Name | [[Description]] | Value and Purpose |
|---|---|---|
| @@asyncIterator |
|
A method that returns the default AsyncIterator for an object. Called by the semantics of the for-await-of statement.
|
| @@hasInstance |
|
A method that determines if a instanceof operator.
|
| @@isConcatSpreadable |
|
A Boolean valued property that if true indicates that an object should be flattened to its array elements by Array.prototype.concat |
| @@iterator |
|
A method that returns the default Iterator for an object. Called by the semantics of the for-of statement. |
| @@match |
|
A regular expression method that matches the regular expression against a string. Called by the String.prototype.match |
| @@matchAll |
|
A regular expression method that returns an iterator, that yields matches of the regular expression against a string. Called by the String.prototype.matchAll |
| @@replace |
|
A regular expression method that replaces matched substrings of a string. Called by the String.prototype.replace |
| @@search |
|
A regular expression method that returns the index within a string that matches the regular expression. Called by the String.prototype.search |
| @@species |
|
A function valued property that is the |
| @@split |
|
A regular expression method that splits a string at the indices that match the regular expression. Called by the String.prototype.split |
| @@toPrimitive |
|
A method that converts an object to a corresponding primitive value. Called by the |
| @@toStringTag |
|
A String valued property that is used in the creation of the default string description of an object. Accessed by the built-in method Object.prototype.toString |
| @@unscopables |
|
An object valued property whose own and inherited property names are property names that are excluded from the with environment bindings of the associated object.
|
6.1.6 Numeric Types
ECMAScript has two built-in numeric types: Number and BigInt. In this specification, every numeric
| Invocation Synopsis | Example source | Invoked by the Evaluation semantics of ... | Result |
|---|---|---|---|
| T::unaryMinus(x) |
-x
|
- Operator |
T |
| T::bitwiseNOT(x) |
~x
|
~ ) |
T |
| T::exponentiate(x, y) |
x ** y
|
|
T, may throw |
| T::multiply(x, y) |
x * y
|
|
T |
| T::divide(x, y) |
x / y
|
|
T, may throw |
| T::remainder(x, y) |
x % y
|
|
T, may throw |
| T::add(x, y) |
x ++++ xx + y
|
+ ) |
T |
| T::subtract(x, y) |
x ---- xx - y
|
- ) |
T |
| T::leftShift(x, y) |
x << y
|
<< ) |
T |
| T::signedRightShift(x, y) |
x >> y
|
>> ) |
T |
| T::unsignedRightShift(x, y) |
x >>> y
|
>>> ) |
T, may throw |
| T::lessThan(x, y) |
x < yx > yx <= yx >= y
|
|
Boolean or |
| T::equal(x, y) |
x == yx != yx === yx !== y
|
|
Boolean |
| T::sameValue(x, y) |
Object internal methods,
via |
Boolean | |
| T::sameValueZero(x, y) |
Array, Map, and |
Boolean | |
| T::bitwiseAND(x, y) |
x & y
|
|
T |
| T::bitwiseXOR(x, y) |
x ^ y
|
|
T |
| T::bitwiseOR(x, y) |
x | y
|
|
T |
| T::toString(x) |
String(x)
|
Many expressions and built-in functions, via |
String |
The T::unit value and T::op operations are not a part of the ECMAScript language; they are defined here solely to aid the specification of the semantics of the ECMAScript language. Other
Because the numeric types are in general not convertible without loss of precision or truncation, the ECMAScript language provides no implicit conversion among these types. Programmers must explicitly call Number and BigInt functions to convert among types when calling a function which requires another
The first and subsequent editions of ECMAScript have provided, for certain operators, implicit numeric conversions that could lose precision or truncate. These legacy implicit conversions are maintained for backward compatibility, but not provided for BigInt in order to minimize opportunity for programmer error, and to leave open the option of generalized value types in a future edition.
6.1.6.1 The Number Type
The Number NaN.) In some implementations, external code might be able to detect a difference between various Not-a-Number values, but such behaviour is
The bit pattern that might be observed in an ArrayBuffer (see
There are two other special values, called +Infinity (or simply Infinity) and -Infinity.)
The other 18,437,736,874,454,810,624 (that is,
Note that there is both a +0 (or simply 0) and -0.)
The 18,437,736,874,454,810,622 (that is,
18,428,729,675,200,069,632 (that is,
where s is 1 or -1, m is an
The remaining 9,007,199,254,740,990 (that is,
where s is 1 or -1, m is an
Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number
A finite number has an odd significand if it is non-zero and the
In this specification, the phrase “the Number value for x” where x represents an exact real mathematical quantity (which might even be an irrational number such as π) means a
The
Some ECMAScript operators deal only with integers in specific ranges such as
The Number::unit value is
6.1.6.1.1 Number::unaryMinus ( x )
The abstract operation Number::unaryMinus takes argument x (a Number). It performs the following steps when called:
- If x is
NaN , returnNaN . - Return the result of negating x; that is, compute a Number with the same magnitude but opposite sign.
6.1.6.1.2 Number::bitwiseNOT ( x )
The abstract operation Number::bitwiseNOT takes argument x (a Number). It performs the following steps when called:
- Let oldValue be !
ToInt32 (x). - Return the result of applying bitwise complement to oldValue. The
mathematical value of the result is exactly representable as a 32-bit two's complement bit string.
6.1.6.1.3 Number::exponentiate ( base, exponent )
The abstract operation Number::exponentiate takes arguments base (a Number) and exponent (a Number). It returns an
- If exponent is
NaN , returnNaN . - If exponent is
+0 𝔽 or exponent is-0 𝔽, return1 𝔽. - If base is
NaN , returnNaN . - If base is
+∞ 𝔽, then- If exponent >
+0 𝔽, return+∞ 𝔽. Otherwise, return+0 𝔽.
- If exponent >
- If base is
-∞ 𝔽, then- If exponent >
+0 𝔽, then- If exponent is an odd
integral Number , return-∞ 𝔽. Otherwise, return+∞ 𝔽.
- If exponent is an odd
- Else,
- If exponent is an odd
integral Number , return-0 𝔽. Otherwise, return+0 𝔽.
- If exponent is an odd
- If exponent >
- If base is
+0 𝔽, then- If exponent >
+0 𝔽, return+0 𝔽. Otherwise, return+∞ 𝔽.
- If exponent >
- If base is
-0 𝔽, then- If exponent >
+0 𝔽, then- If exponent is an odd
integral Number , return-0 𝔽. Otherwise, return+0 𝔽.
- If exponent is an odd
- Else,
- If exponent is an odd
integral Number , return-∞ 𝔽. Otherwise, return+∞ 𝔽.
- If exponent is an odd
- If exponent >
Assert : base is finite and is neither+0 𝔽 nor-0 𝔽.- If exponent is
+∞ 𝔽, then - If exponent is
-∞ 𝔽, then Assert : exponent is finite and is neither+0 𝔽 nor-0 𝔽.- If base <
+0 𝔽 and exponent is not anintegral Number , returnNaN . - Return an
implementation-approximated value representing the result of raising ℝ(base) to the ℝ(exponent) power.
The result of base ** exponent when base is
6.1.6.1.4 Number::multiply ( x, y )
The abstract operation Number::multiply takes arguments x (a Number) and y (a Number). It performs multiplication according to the rules of
- If x is
NaN or y isNaN , returnNaN . - If x is
+∞ 𝔽 or x is-∞ 𝔽, then- If y is
+0 𝔽 or y is-0 𝔽, returnNaN . - If y >
+0 𝔽, return x. - Return -x.
- If y is
- If y is
+∞ 𝔽 or y is-∞ 𝔽, then- If x is
+0 𝔽 or x is-0 𝔽, returnNaN . - If x >
+0 𝔽, return y. - Return -y.
- If x is
- Return 𝔽(ℝ(x) × ℝ(y)).
Finite-precision multiplication is commutative, but not always associative.
6.1.6.1.5 Number::divide ( x, y )
The abstract operation Number::divide takes arguments x (a Number) and y (a Number). It performs division according to the rules of
- If x is
NaN or y isNaN , returnNaN . - If x is
+∞ 𝔽 or x is-∞ 𝔽, then- If y is
+∞ 𝔽 or y is-∞ 𝔽, returnNaN . - If y is
+0 𝔽 or y >+0 𝔽, return x. - Return -x.
- If y is
- If y is
+∞ 𝔽, then- If x is
+0 𝔽 or x >+0 𝔽, return+0 𝔽. Otherwise, return-0 𝔽.
- If x is
- If y is
-∞ 𝔽, then- If x is
+0 𝔽 or x >+0 𝔽, return-0 𝔽. Otherwise, return+0 𝔽.
- If x is
- If x is
+0 𝔽 or x is-0 𝔽, then- If y is
+0 𝔽 or y is-0 𝔽, returnNaN . - If y >
+0 𝔽, return x. - Return -x.
- If y is
- If y is
+0 𝔽, then- If x >
+0 𝔽, return+∞ 𝔽. Otherwise, return-∞ 𝔽.
- If x >
- If y is
-0 𝔽, then- If x >
+0 𝔽, return-∞ 𝔽. Otherwise, return+∞ 𝔽.
- If x >
- Return 𝔽(ℝ(x) / ℝ(y)).
6.1.6.1.6 Number::remainder ( n, d )
The abstract operation Number::remainder takes arguments n (a Number) and d (a Number). It yields the remainder from an implied division of its operands where n is the dividend and d is the divisor. It performs the following steps when called:
- If n is
NaN or d isNaN , returnNaN . - If n is
+∞ 𝔽 or n is-∞ 𝔽, returnNaN . - If d is
+∞ 𝔽 or d is-∞ 𝔽, return n. - If d is
+0 𝔽 or d is-0 𝔽, returnNaN . - If n is
+0 𝔽 or n is-0 𝔽, return n. Assert : n and d are finite and non-zero.- Let r be ℝ(n) - (ℝ(d) × q) where q is an
integer that is negative if and only if n and d have opposite sign, and whose magnitude is as large as possible without exceeding the magnitude of ℝ(n) / ℝ(d). - Return 𝔽(r).
In C and C++, the remainder operator accepts only integral operands; in ECMAScript, it also accepts floating-point operands.
% operator is not the same as the “remainder” operation defined by % on floating-point operations to behave in a manner analogous to that of the Java 6.1.6.1.7 Number::add ( x, y )
The abstract operation Number::add takes arguments x (a Number) and y (a Number). It performs addition according to the rules of
- If x is
NaN or y isNaN , returnNaN . - If x is
+∞ 𝔽 and y is-∞ 𝔽, returnNaN . - If x is
-∞ 𝔽 and y is+∞ 𝔽, returnNaN . - If x is
+∞ 𝔽 or x is-∞ 𝔽, return x. - If y is
+∞ 𝔽 or y is-∞ 𝔽, return y. Assert : x and y are both finite.- If x is
-0 𝔽 and y is-0 𝔽, return-0 𝔽. - Return 𝔽(ℝ(x) + ℝ(y)).
Finite-precision addition is commutative, but not always associative.
6.1.6.1.8 Number::subtract ( x, y )
The abstract operation Number::subtract takes arguments x (a Number) and y (a Number). It performs subtraction, producing the difference of its operands; x is the minuend and y is the subtrahend. It performs the following steps when called:
- Return Number::add(x, Number::unaryMinus(y)).
It is always the case that x - y produces the same result as x + (-y).
6.1.6.1.9 Number::leftShift ( x, y )
The abstract operation Number::leftShift takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- Let lnum be !
ToInt32 (x). - Let rnum be !
ToUint32 (y). - Let shiftCount be ℝ(rnum)
modulo 32. - Return the result of left shifting lnum by shiftCount bits. The
mathematical value of the result is exactly representable as a 32-bit two's complement bit string.
6.1.6.1.10 Number::signedRightShift ( x, y )
The abstract operation Number::signedRightShift takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- Let lnum be !
ToInt32 (x). - Let rnum be !
ToUint32 (y). - Let shiftCount be ℝ(rnum)
modulo 32. - Return the result of performing a sign-extending right shift of lnum by shiftCount bits. The most significant bit is propagated. The
mathematical value of the result is exactly representable as a 32-bit two's complement bit string.
6.1.6.1.11 Number::unsignedRightShift ( x, y )
The abstract operation Number::unsignedRightShift takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- Let lnum be !
ToUint32 (x). - Let rnum be !
ToUint32 (y). - Let shiftCount be ℝ(rnum)
modulo 32. - Return the result of performing a zero-filling right shift of lnum by shiftCount bits. Vacated bits are filled with zero. The
mathematical value of the result is exactly representable as a 32-bit unsigned bit string.
6.1.6.1.12 Number::lessThan ( x, y )
The abstract operation Number::lessThan takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- If x is
NaN , returnundefined . - If y is
NaN , returnundefined . - If x and y are the same
Number value , returnfalse . - If x is
+0 𝔽 and y is-0 𝔽, returnfalse . - If x is
-0 𝔽 and y is+0 𝔽, returnfalse . - If x is
+∞ 𝔽, returnfalse . - If y is
+∞ 𝔽, returntrue . - If y is
-∞ 𝔽, returnfalse . - If x is
-∞ 𝔽, returntrue . Assert : x and y are finite and non-zero.- If ℝ(x) < ℝ(y), return
true . Otherwise, returnfalse .
6.1.6.1.13 Number::equal ( x, y )
The abstract operation Number::equal takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- If x is
NaN , returnfalse . - If y is
NaN , returnfalse . - If x is the same
Number value as y, returntrue . - If x is
+0 𝔽 and y is-0 𝔽, returntrue . - If x is
-0 𝔽 and y is+0 𝔽, returntrue . - Return
false .
6.1.6.1.14 Number::sameValue ( x, y )
The abstract operation Number::sameValue takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- If x is
NaN and y isNaN , returntrue . - If x is
+0 𝔽 and y is-0 𝔽, returnfalse . - If x is
-0 𝔽 and y is+0 𝔽, returnfalse . - If x is the same
Number value as y, returntrue . - Return
false .
6.1.6.1.15 Number::sameValueZero ( x, y )
The abstract operation Number::sameValueZero takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- If x is
NaN and y isNaN , returntrue . - If x is
+0 𝔽 and y is-0 𝔽, returntrue . - If x is
-0 𝔽 and y is+0 𝔽, returntrue . - If x is the same
Number value as y, returntrue . - Return
false .
6.1.6.1.16 NumberBitwiseOp ( op, x, y )
The abstract operation NumberBitwiseOp takes arguments op (a sequence of Unicode code points), x, and y. It performs the following steps when called:
Assert : op is&,^, or|.- Let lnum be !
ToInt32 (x). - Let rnum be !
ToInt32 (y). - Let lbits be the 32-bit two's complement bit string representing ℝ(lnum).
- Let rbits be the 32-bit two's complement bit string representing ℝ(rnum).
- If op is
&, let result be the result of applying the bitwise AND operation to lbits and rbits. - Else if op is
^, let result be the result of applying the bitwise exclusive OR (XOR) operation to lbits and rbits. - Else, op is
|. Let result be the result of applying the bitwise inclusive OR operation to lbits and rbits. - Return the
Number value for theinteger represented by the 32-bit two's complement bit string result.
6.1.6.1.17 Number::bitwiseAND ( x, y )
The abstract operation Number::bitwiseAND takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- Return
NumberBitwiseOp (&, x, y).
6.1.6.1.18 Number::bitwiseXOR ( x, y )
The abstract operation Number::bitwiseXOR takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- Return
NumberBitwiseOp (^, x, y).
6.1.6.1.19 Number::bitwiseOR ( x, y )
The abstract operation Number::bitwiseOR takes arguments x (a Number) and y (a Number). It performs the following steps when called:
- Return
NumberBitwiseOp (|, x, y).
6.1.6.1.20 Number::toString ( x )
The abstract operation Number::toString takes argument x (a Number). It converts x to String format. It performs the following steps when called:
- If x is
NaN , return the String"NaN" . - If x is
+0 𝔽 or-0 𝔽, return the String"0" . - If x <
+0 𝔽, return thestring-concatenation of"-" and ! Number::toString(-x). - If x is
+∞ 𝔽, return the String"Infinity" . - Otherwise, let n, k, and s be integers such that k ≥ 1, 10k - 1 ≤ s < 10k, s × 10n - k is ℝ(x), and k is as small as possible. Note that k is the number of digits in the decimal representation of s, that s is not divisible by 10, and that the least significant digit of s is not necessarily uniquely determined by these criteria.
- If k ≤ n ≤ 21, return the
string-concatenation of:- the code units of the k digits of the decimal representation of s (in order, with no leading zeroes)
- n - k occurrences of the code unit 0x0030 (DIGIT ZERO)
- If 0 < n ≤ 21, 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 -6 < n ≤ 0, return the
string-concatenation of:- the code unit 0x0030 (DIGIT ZERO)
- the code unit 0x002E (FULL STOP)
- -n occurrences of the code unit 0x0030 (DIGIT ZERO)
- the code units of the k digits of the decimal representation of s
- Otherwise, if k = 1, return the
string-concatenation of: - Return the
string-concatenation of:- the code units of the most significant digit of the decimal representation of s
- the code unit 0x002E (FULL STOP)
- the code units of the remaining k - 1 digits of the decimal representation of s
- the code unit 0x0065 (LATIN SMALL LETTER E)
- the code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether n - 1 is positive or negative
- the code units of the decimal representation of the
integer abs (n - 1) (with no leading zeroes)
The following observations may be useful as guidelines for implementations, but are not part of the normative requirements of this Standard:
-
If x is any
Number value other than-0 𝔽, thenToNumber (ToString (x)) is exactly the sameNumber value as x. -
The least significant digit of s is not always uniquely determined by the requirements listed in step
5 .
For implementations that provide more accurate conversions than required by the rules above, it is recommended that the following alternative version of step
- Otherwise, let n, k, and s be integers such that k ≥ 1, 10k - 1 ≤ s < 10k, s × 10n - k is ℝ(x), and k is as small as possible. If there are multiple possibilities for s, choose the value of s for which s × 10n - k is closest in value to ℝ(x). If there are two such possible values of s, choose the one that is even. Note that k is the number of digits in the decimal representation of s and that s is not divisible by 10.
Implementers of ECMAScript may find useful the paper and code written by David M. Gay for binary-to-decimal conversion of floating-point numbers:
Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical Analysis, Manuscript 90-10. AT&T Bell Laboratories (Murray Hill, New Jersey). 30 November 1990. Available as
http://ampl.com/REFS/abstracts.html#rounding. Associated code available as
http://netlib.sandia.gov/fp/dtoa.c and as
http://netlib.sandia.gov/fp/g_fmt.c and may also be found at the various netlib mirror sites.
6.1.6.2 The BigInt Type
The BigInt
The BigInt::unit value is
6.1.6.2.1 BigInt::unaryMinus ( x )
The abstract operation BigInt::unaryMinus takes argument x (a BigInt). It performs the following steps when called:
- If x is
0 ℤ, return0 ℤ. - Return the BigInt value that represents the negation of ℝ(x).
6.1.6.2.2 BigInt::bitwiseNOT ( x )
The abstract operation BigInt::bitwiseNOT takes argument x (a BigInt). It returns the one's complement of x; that is, -x -
6.1.6.2.3 BigInt::exponentiate ( base, exponent )
The abstract operation BigInt::exponentiate takes arguments base (a BigInt) and exponent (a BigInt). It performs the following steps when called:
- If exponent <
0 ℤ, throw aRangeError exception. - If base is
0 ℤ and exponent is0 ℤ, return1 ℤ. - Return the BigInt value that represents ℝ(base) raised to the power ℝ(exponent).
6.1.6.2.4 BigInt::multiply ( x, y )
The abstract operation BigInt::multiply takes arguments x (a BigInt) and y (a BigInt). It returns the BigInt value that represents the result of multiplying x and y.
6.1.6.2.5 BigInt::divide ( x, y )
The abstract operation BigInt::divide takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- If y is
0 ℤ, throw aRangeError exception. - Let quotient be ℝ(x) / ℝ(y).
- Return the BigInt value that represents quotient rounded towards 0 to the next
integer value.
6.1.6.2.6 BigInt::remainder ( n, d )
The abstract operation BigInt::remainder takes arguments n (a BigInt) and d (a BigInt). It performs the following steps when called:
- If d is
0 ℤ, throw aRangeError exception. - If n is
0 ℤ, return0 ℤ. - Let r be the BigInt defined by the mathematical relation r = n - (d × q) where q is a BigInt that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d.
- Return r.
6.1.6.2.7 BigInt::add ( x, y )
The abstract operation BigInt::add takes arguments x (a BigInt) and y (a BigInt). It returns the BigInt value that represents the sum of x and y.
6.1.6.2.8 BigInt::subtract ( x, y )
The abstract operation BigInt::subtract takes arguments x (a BigInt) and y (a BigInt). It returns the BigInt value that represents the difference x minus y.
6.1.6.2.9 BigInt::leftShift ( x, y )
The abstract operation BigInt::leftShift takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- If y <
0 ℤ, then- Return the BigInt value that represents ℝ(x) / 2-y, rounding down to the nearest
integer , including for negative numbers.
- Return the BigInt value that represents ℝ(x) / 2-y, rounding down to the nearest
- Return the BigInt value that represents ℝ(x) × 2y.
6.1.6.2.10 BigInt::signedRightShift ( x, y )
The abstract operation BigInt::signedRightShift takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Return BigInt::leftShift(x, -y).
6.1.6.2.11 BigInt::unsignedRightShift ( x, y )
The abstract operation BigInt::unsignedRightShift takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Throw a
TypeError exception.
6.1.6.2.12 BigInt::lessThan ( x, y )
The abstract operation BigInt::lessThan takes arguments x (a BigInt) and y (a BigInt). It returns
6.1.6.2.13 BigInt::equal ( x, y )
The abstract operation BigInt::equal takes arguments x (a BigInt) and y (a BigInt). It returns
6.1.6.2.14 BigInt::sameValue ( x, y )
The abstract operation BigInt::sameValue takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Return BigInt::equal(x, y).
6.1.6.2.15 BigInt::sameValueZero ( x, y )
The abstract operation BigInt::sameValueZero takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Return BigInt::equal(x, y).
6.1.6.2.16 BinaryAnd ( x, y )
6.1.6.2.17 BinaryOr ( x, y )
6.1.6.2.18 BinaryXor ( x, y )
6.1.6.2.19 BigIntBitwiseOp ( op, x, y )
The abstract operation BigIntBitwiseOp takes arguments op (a sequence of Unicode code points), x (a BigInt), and y (a BigInt). It performs the following steps when called:
Assert : op is&,^, or|.Set x to ℝ(x).Set y to ℝ(y).- Let result be 0.
- Let shift be 0.
- Repeat, until (x = 0 or x = -1) and (y = 0 or y = -1),
- If op is
&, let tmp beBinaryAnd (xmodulo 2, ymodulo 2). - Else if op is
|, let tmp beBinaryOr (xmodulo 2, ymodulo 2). - Else,
- If tmp ≠ 0, then
Set result to result - 2shift.- NOTE: This extends the sign.
- Return the BigInt value for result.
6.1.6.2.20 BigInt::bitwiseAND ( x, y )
The abstract operation BigInt::bitwiseAND takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Return
BigIntBitwiseOp (&, x, y).
6.1.6.2.21 BigInt::bitwiseXOR ( x, y )
The abstract operation BigInt::bitwiseXOR takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Return
BigIntBitwiseOp (^, x, y).
6.1.6.2.22 BigInt::bitwiseOR ( x, y )
The abstract operation BigInt::bitwiseOR takes arguments x (a BigInt) and y (a BigInt). It performs the following steps when called:
- Return
BigIntBitwiseOp (|, x, y).
6.1.6.2.23 BigInt::toString ( x )
The abstract operation BigInt::toString takes argument x (a BigInt). It converts x to String format. It performs the following steps when called:
- If x <
0 ℤ, return thestring-concatenation of the String"-" and ! BigInt::toString(-x). - Return the String value consisting of the code units of the digits of the decimal representation of x.
6.1.7 The Object Type
An Object is logically a collection of properties. Each property is either a data property, or an accessor property:
-
A data property associates a key value with an
ECMAScript language value and a set of Boolean attributes. -
An accessor property associates a key value with one or two accessor functions, and a set of Boolean attributes. The accessor functions are used to store or retrieve an
ECMAScript language value that is associated with the property.
Properties are identified using key values. A property key value is either an ECMAScript String value or a Symbol value. All String and Symbol values, including the empty String, are valid as property keys. A property name is a property key that is a String value.
An integer index is a String-valued property key that is a canonical numeric String (see
Property keys are used to access properties and their values. There are two kinds of access for properties: get and set, corresponding to value retrieval and assignment, respectively. The properties accessible via get and set access includes both own properties that are a direct part of an object and inherited properties which are provided by another associated object via a property inheritance relationship. Inherited properties may be either own or inherited properties of the associated object. Each own property of an object must each have a key value that is distinct from the key values of the other own properties of that object.
All objects are logically collections of properties, but there are multiple forms of objects that differ in their semantics for accessing and manipulating their properties. Please see
6.1.7.1 Property Attributes
Attributes are used in this specification to define and explain the state of Object properties. A
| Attribute Name | Value Domain | Description |
|---|---|---|
| [[Value]] |
Any |
The value retrieved by a get access of the property. |
| [[Writable]] | Boolean |
If |
| [[Enumerable]] | Boolean |
If |
| [[Configurable]] | Boolean |
If |
An
| Attribute Name | Value Domain | Description |
|---|---|---|
| [[Get]] | Object | Undefined |
If the value is an Object it must be a |
| [[Set]] | Object | Undefined |
If the value is an Object it must be a |
| [[Enumerable]] | Boolean |
If |
| [[Configurable]] | Boolean |
If |
If the initial values of a property's attributes are not explicitly specified by this specification, the default value defined in
| Attribute Name | Default Value |
|---|---|
| [[Value]] |
|
| [[Get]] |
|
| [[Set]] |
|
| [[Writable]] |
|
| [[Enumerable]] |
|
| [[Configurable]] |
|
6.1.7.2 Object Internal Methods and Internal Slots
The actual semantics of objects, in ECMAScript, are specified via algorithms called internal methods. Each object in an ECMAScript engine is associated with a set of internal methods that defines its runtime behaviour. These internal methods are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. However, each object within an implementation of ECMAScript must behave as specified by the internal methods associated with it. The exact manner in which this is accomplished is determined by the implementation.
Internal method names are polymorphic. This means that different object values may perform different algorithms when a common internal method name is invoked upon them. That actual object upon which an internal method is invoked is the “target” of the invocation. If, at runtime, the implementation of an algorithm attempts to use an internal method of an object that the object does not support, a
Internal slots correspond to internal state that is associated with objects and used by various ECMAScript specification algorithms. Internal slots are not object properties and they are not inherited. Depending upon the specific internal slot specification, such state may consist of values of any
Internal methods and internal slots are identified within this specification using names enclosed in double square brackets [[ ]].
An ordinary object is an object that satisfies all of the following criteria:
-
For the internal methods listed in
Table 6 , the object uses those defined in10.1 . -
If the object has a [[Call]] internal method, it uses the one defined in
10.2.1 . -
If the object has a [[Construct]] internal method, it uses the one defined in
10.2.2 .
An exotic object is an object that is not an
This specification recognizes different kinds of exotic objects by those objects' internal methods. An object that is behaviourally equivalent to a particular kind of
The “Signature” column of
In addition to its parameters, an internal method always has access to the object that is the target of the method invocation.
An internal method implicitly returns a
| Internal Method | Signature | Description |
|---|---|---|
| [[GetPrototypeOf]] | ( ) → Object | Null |
Determine the object that provides inherited properties for this object. A |
| [[SetPrototypeOf]] | (Object | Null) → Boolean |
Associate this object with another object that provides inherited properties. Passing |
| [[IsExtensible]] | ( ) → Boolean | Determine whether it is permitted to add additional properties to this object. |
| [[PreventExtensions]] | ( ) → Boolean |
Control whether new properties may be added to this object. Returns |
| [[GetOwnProperty]] |
(propertyKey) → Undefined | |
Return a |
| [[DefineOwnProperty]] | (propertyKey, PropertyDescriptor) → Boolean |
Create or alter the own property, whose key is propertyKey, to have the state described by PropertyDescriptor. Return |
| [[HasProperty]] | (propertyKey) → Boolean | Return a Boolean value indicating whether this object already has either an own or inherited property whose key is propertyKey. |
| [[Get]] | (propertyKey, Receiver) → any |
Return the value of the property whose key is propertyKey from this object. If any ECMAScript code must be executed to retrieve the property value, Receiver is used as the |
| [[Set]] | (propertyKey, value, Receiver) → Boolean |
|
| [[Delete]] | (propertyKey) → Boolean |
Remove the own property whose key is propertyKey from this object. Return |
| [[OwnPropertyKeys]] |
( ) → |
Return a |
| Internal Method | Signature | Description |
|---|---|---|
| [[Call]] |
(any, a |
Executes code associated with this object. Invoked via a function call expression. The arguments to the internal method are a |
| [[Construct]] |
(a |
Creates an object. Invoked via the new operator or a super call. The first argument to the internal method is a super call. The second argument is the object to which the new operator was initially applied. Objects that implement this internal method are called constructors. A |
The semantics of the essential internal methods for ordinary objects and standard exotic objects are specified in clause
6.1.7.3 Invariants of the Essential Internal Methods
The Internal Methods of Objects of an ECMAScript engine must conform to the list of invariants specified below. Ordinary ECMAScript Objects as well as all standard exotic objects in this specification maintain these invariants. ECMAScript Proxy objects maintain these invariants by means of runtime checks on the result of traps invoked on the [[ProxyHandler]] object.
Any implementation provided exotic objects must also maintain these invariants for those objects. Violation of these invariants may cause ECMAScript code to have unpredictable behaviour and create security issues. However, violation of these invariants must never compromise the memory safety of an implementation.
An implementation must not allow these invariants to be circumvented in any manner such as by providing alternative interfaces that implement the functionality of the essential internal methods without enforcing their invariants.
Definitions:
- The target of an internal method is the object upon which the internal method is called.
-
A target is non-extensible if it has been observed to return
false from its [[IsExtensible]] internal method, ortrue from its [[PreventExtensions]] internal method. - A non-existent property is a property that does not exist as an own property on a non-extensible target.
-
All references to
SameValue are according to the definition of theSameValue algorithm.
Return value:
The value returned by any internal method must be a
- [[Type]] =
normal , [[Target]] =empty , and [[Value]] = a value of the "normal returntype " shown below for that internal method, or - [[Type]] =
throw , [[Target]] =empty , and [[Value]] = anyECMAScript language value .
An internal method must not return a completion with [[Type]] =
[[GetPrototypeOf]] ( )
-
The normal return
type is either Object or Null. -
If target is non-extensible, and [[GetPrototypeOf]] returns a value V, then any future calls to [[GetPrototypeOf]] should return the
SameValue as V.
An object's prototype chain should have finite length (that is, starting from any object, recursively applying the [[GetPrototypeOf]] internal method to its result should eventually lead to the value
[[SetPrototypeOf]] ( V )
-
The normal return
type is Boolean. -
If target is non-extensible, [[SetPrototypeOf]] must return
false , unless V is theSameValue as the target's observed [[GetPrototypeOf]] value.
[[IsExtensible]] ( )
-
The normal return
type is Boolean. -
If [[IsExtensible]] returns
false , all future calls to [[IsExtensible]] on the target must returnfalse .
[[PreventExtensions]] ( )
-
The normal return
type is Boolean. -
If [[PreventExtensions]] returns
true , all future calls to [[IsExtensible]] on the target must returnfalse and the target is now considered non-extensible.
[[GetOwnProperty]] ( P )
-
The normal return
type is eitherProperty Descriptor or Undefined. -
If the
Type of the return value isProperty Descriptor , the return value must be a fully populatedProperty Descriptor . -
If P is described as a non-configurable, non-writable own
data property , all future calls to [[GetOwnProperty]] ( P ) must returnProperty Descriptor whose [[Value]] isSameValue as P's [[Value]] attribute. -
If P's attributes other than [[Writable]] may change over time or if the property might be deleted, then P's [[Configurable]] attribute must be
true . -
If the [[Writable]] attribute may change from
false totrue , then the [[Configurable]] attribute must betrue . -
If the target is non-extensible and P is non-existent, then all future calls to [[GetOwnProperty]] (P) on the target must describe P as non-existent (i.e. [[GetOwnProperty]] (P) must return
undefined ).
As a consequence of the third invariant, if a property is described as a
[[DefineOwnProperty]] ( P, Desc )
-
The normal return
type is Boolean. -
[[DefineOwnProperty]] must return
false if P has previously been observed as a non-configurable own property of the target, unless either:-
P is a writable
data property . A non-configurable writabledata property can be changed into a non-configurable non-writabledata property . -
All attributes of Desc are the
SameValue as P's attributes.
-
P is a writable
-
[[DefineOwnProperty]] (P, Desc) must return
false if target is non-extensible and P is a non-existent own property. That is, a non-extensible target object cannot be extended with new properties.
[[HasProperty]] ( P )
-
The normal return
type is Boolean. -
If P was previously observed as a non-configurable own data or
accessor property of the target, [[HasProperty]] must returntrue .
[[Get]] ( P, Receiver )
-
The normal return
type is anyECMAScript language type . -
If P was previously observed as a non-configurable, non-writable own
data property of the target with value V, then [[Get]] must return theSameValue as V. -
If P was previously observed as a non-configurable own
accessor property of the target whose [[Get]] attribute isundefined , the [[Get]] operation must returnundefined .
[[Set]] ( P, V, Receiver )
-
The normal return
type is Boolean. -
If P was previously observed as a non-configurable, non-writable own
data property of the target, then [[Set]] must returnfalse unless V is theSameValue as P's [[Value]] attribute. -
If P was previously observed as a non-configurable own
accessor property of the target whose [[Set]] attribute isundefined , the [[Set]] operation must returnfalse .
[[Delete]] ( P )
-
The normal return
type is Boolean. -
If P was previously observed as a non-configurable own data or
accessor property of the target, [[Delete]] must returnfalse .
[[OwnPropertyKeys]] ( )
-
The normal return
type isList . -
The returned
List must not contain any duplicate entries. -
The
Type of each element of the returnedList is either String or Symbol. -
The returned
List must contain at least the keys of all non-configurable own properties that have previously been observed. -
If the target is non-extensible, the returned
List must contain only the keys of all own properties of the target that are observable using [[GetOwnProperty]].
[[Call]] ( )
-
The normal return
type is anyECMAScript language type .
[[Construct]] ( )
-
The normal return
type is Object. - The target must also have a [[Call]] internal method.
6.1.7.4 Well-Known Intrinsic Objects
Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and which usually have
Within this specification a reference such as
| Intrinsic Name | Global Name | ECMAScript Language Association |
|---|---|---|
|
|
AggregateError
|
The AggregateError |
|
|
Array
|
The Array |
|
|
ArrayBuffer
|
The ArrayBuffer |
|
|
The prototype of Array iterator objects ( |
|
|
|
The prototype of async-from-sync iterator objects ( |
|
|
|
The |
|
|
|
The |
|
|
|
An object that all standard built-in async iterator objects indirectly inherit from | |
|
|
Atomics
|
The Atomics object ( |
|
|
BigInt
|
The BigInt |
|
|
BigInt64Array
|
The BigInt64Array |
|
|
BigUint64Array
|
The BigUint64Array |
|
|
Boolean
|
The Boolean |
|
|
DataView
|
The DataView |
|
|
Date
|
The Date |
|
|
decodeURI
|
The decodeURI function ( |
|
|
decodeURIComponent
|
The decodeURIComponent function ( |
|
|
encodeURI
|
The encodeURI function ( |
|
|
encodeURIComponent
|
The encodeURIComponent function ( |
|
|
Error
|
The Error |
|
|
eval
|
The eval function ( |
|
|
EvalError
|
The EvalError |
|
|
FinalizationRegistry
|
The |
|
|
Float32Array
|
The Float32Array |
|
|
Float64Array
|
The Float64Array |
|
|
The prototype of For-In iterator objects ( |
|
|
|
Function
|
The Function |
|
|
The |
|
|
|
Int8Array
|
The Int8Array |
|
|
Int16Array
|
The Int16Array |
|
|
Int32Array
|
The Int32Array |
|
|
isFinite
|
The isFinite function ( |
|
|
isNaN
|
The isNaN function ( |
|
|
An object that all standard built-in iterator objects indirectly inherit from | |
|
|
JSON
|
The JSON object ( |
|
|
Map
|
The Map |
|
|
The prototype of Map iterator objects ( |
|
|
|
Math
|
The Math object ( |
|
|
Number
|
The Number |
|
|
Object
|
The Object |
|
|
parseFloat
|
The parseFloat function ( |
|
|
parseInt
|
The parseInt function ( |
|
|
Promise
|
The Promise |
|
|
Proxy
|
The Proxy |
|
|
RangeError
|
The RangeError |
|
|
ReferenceError
|
The ReferenceError |
|
|
Reflect
|
The Reflect object ( |
|
|
RegExp
|
The RegExp |
|
|
The prototype of RegExp String Iterator objects ( |
|
|
|
Set
|
The |
|
|
The prototype of |
|
|
|
SharedArrayBuffer
|
The SharedArrayBuffer |
|
|
String
|
The String |
|
|
The prototype of String iterator objects ( |
|
|
|
Symbol
|
The Symbol |
|
|
SyntaxError
|
The SyntaxError |
|
|
A |
|
|
|
The super class of all typed Array constructors ( |
|
|
|
TypeError
|
The TypeError |
|
|
Uint8Array
|
The Uint8Array |
|
|
Uint8ClampedArray
|
The Uint8ClampedArray |
|
|
Uint16Array
|
The Uint16Array |
|
|
Uint32Array
|
The Uint32Array |
|
|
URIError
|
The URIError |
|
|
WeakMap
|
The WeakMap |
|
|
WeakRef
|
The |
|
|
WeakSet
|
The WeakSet |
Additional entries in
6.2 ECMAScript Specification Types
A specification
6.2.1 The List and Record Specification Types
The List new expressions, in function calls, and in other algorithms where a simple ordered list of values is needed. Values of the List
When an algorithm iterates over the elements of a List without specifying an order, the order used is the order of the elements in the List.
For notational convenience within this specification, a literal syntax can be used to express a new List value. For example, « 1, 2 » defines a List value that has two elements each of which is initialized to a specific value. A new empty List can be expressed as « ».
The Record
For notational convenience within this specification, an object literal-like syntax can be used to express a Record value. For example, { [[Field1]]: 42, [[Field2]]:
In specification text and algorithms, dot notation may be used to refer to a specific field of a Record value. For example, if R is the record shown in the previous paragraph then R.[[Field2]] is shorthand for “the field of R named [[Field2]]”.
Schema for commonly used Record field combinations may be named, and that name may be used as a prefix to a literal Record value to identify the specific kind of aggregations that is being described. For example: PropertyDescriptor { [[Value]]: 42, [[Writable]]:
6.2.2 The Set and Relation Specification Types
The Set
The Relation
A strict partial order is a Relation value R that satisfies the following.
-
For all a, b, and c in R's domain:
- It is not the case that a R a, and
- If a R b and b R c, then a R c.
The two properties above are called irreflexivity and transitivity, respectively.
A strict total order is a Relation value R that satisfies the following.
-
For all a, b, and c in R's domain:
- a is identical to b or a R b or b R a, and
- It is not the case that a R a, and
- If a R b and b R c, then a R c.
The three properties above are called totality, irreflexivity, and transitivity, respectively.
6.2.3 The Completion Record Specification Type
The Completion break, continue, return and throw) that perform nonlocal transfers of control.
Values of the Completion
| Field Name | Value | Meaning |
|---|---|---|
| [[Type]] |
One of |
The |
| [[Value]] |
any |
The value that was produced. |
| [[Target]] |
any ECMAScript string or |
The target label for directed control transfers. |
The term “abrupt completion” refers to any completion with a [[Type]] value other than
6.2.3.1 Await
Algorithm steps that say
- Let completion be Await(value).
mean the same thing as:
- Let asyncContext be the
running execution context . - Let promise be ?
PromiseResolve (%Promise% , value). - Let stepsFulfilled be the algorithm steps defined in
Await Fulfilled Functions . - Let lengthFulfilled be the number of non-optional parameters of the function definition in
Await Fulfilled Functions . - Let onFulfilled be !
CreateBuiltinFunction (stepsFulfilled, lengthFulfilled,"" , « [[AsyncContext]] »). Set onFulfilled.[[AsyncContext]] to asyncContext.- Let stepsRejected be the algorithm steps defined in
Await Rejected Functions . - Let lengthRejected be the number of non-optional parameters of the function definition in
Await Rejected Functions . - Let onRejected be !
CreateBuiltinFunction (stepsRejected, lengthRejected,"" , « [[AsyncContext]] »). Set onRejected.[[AsyncContext]] to asyncContext.- Perform !
PerformPromiseThen (promise, onFulfilled, onRejected). - Remove asyncContext from the
execution context stack and restore theexecution context that is at the top of theexecution context stack as therunning execution context . Set the code evaluation state of asyncContext such that when evaluation is resumed with aCompletion completion, the following steps of the algorithm that invoked Await will be performed, with completion available.- Return.
- NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of asyncContext.
where all aliases in the above steps, with the exception of completion, are ephemeral and visible only in the steps pertaining to Await.
Await can be combined with the ? and ! prefixes, so that for example
- Let result be ? Await(value).
means the same thing as:
- Let result be Await(value).
ReturnIfAbrupt (result).
6.2.3.1.1 Await Fulfilled Functions
An
When an
- Let F be the
active function object . - Let asyncContext be F.[[AsyncContext]].
- Let prevContext be the
running execution context . - Suspend prevContext.
- Push asyncContext onto the
execution context stack ; asyncContext is now therunning execution context . - Resume the suspended evaluation of asyncContext using
NormalCompletion (value) as the result of the operation that suspended it. Assert : When we reach this step, asyncContext has already been removed from theexecution context stack and prevContext is the currentlyrunning execution context .- Return
undefined .
The
6.2.3.1.2 Await Rejected Functions
An
When an
- Let F be the
active function object . - Let asyncContext be F.[[AsyncContext]].
- Let prevContext be the
running execution context . - Suspend prevContext.
- Push asyncContext onto the
execution context stack ; asyncContext is now therunning execution context . - Resume the suspended evaluation of asyncContext using
ThrowCompletion (reason) as the result of the operation that suspended it. Assert : When we reach this step, asyncContext has already been removed from theexecution context stack and prevContext is the currentlyrunning execution context .- Return
undefined .
The
6.2.3.2 NormalCompletion
The abstract operation NormalCompletion with a single argument, such as:
- Return NormalCompletion(argument).
Is a shorthand that is defined as follows:
- Return
Completion { [[Type]]:normal , [[Value]]: argument, [[Target]]:empty }.
6.2.3.3 ThrowCompletion
The abstract operation ThrowCompletion with a single argument, such as:
- Return ThrowCompletion(argument).
Is a shorthand that is defined as follows:
- Return
Completion { [[Type]]:throw , [[Value]]: argument, [[Target]]:empty }.
6.2.3.4 UpdateEmpty ( completionRecord, value )
The abstract operation UpdateEmpty takes arguments completionRecord and value. It performs the following steps when called:
Assert : If completionRecord.[[Type]] is eitherreturn orthrow , then completionRecord.[[Value]] is notempty .- If completionRecord.[[Value]] is not
empty , returnCompletion (completionRecord). - Return
Completion { [[Type]]: completionRecord.[[Type]], [[Value]]: value, [[Target]]: completionRecord.[[Target]] }.
6.2.4 The Reference Record Specification Type
The Reference Record delete, typeof, the assignment operators, the super
A Reference Record is a resolved name or property binding; its fields are defined by
| Field Name | Value | Meaning |
|---|---|---|
| [[Base]] |
One of:
|
The value or |
| [[ReferencedName]] | String or Symbol | The name of the binding. Always a String if [[Base]] value is an |
| [[Strict]] | Boolean | |
| [[ThisValue]] | any |
If not super |
The following
6.2.4.1 IsPropertyReference ( V )
The abstract operation IsPropertyReference takes argument V. It performs the following steps when called:
Assert : V is aReference Record .- If V.[[Base]] is
unresolvable , returnfalse . - If
Type (V.[[Base]]) is Boolean, String, Symbol, BigInt, Number, or Object, returntrue ; otherwise returnfalse .
6.2.4.2 IsUnresolvableReference ( V )
The abstract operation IsUnresolvableReference takes argument V. It performs the following steps when called:
Assert : V is aReference Record .- If V.[[Base]] is
unresolvable , returntrue ; otherwise returnfalse .
6.2.4.3 IsSuperReference ( V )
The abstract operation IsSuperReference takes argument V. It performs the following steps when called:
Assert : V is aReference Record .- If V.[[ThisValue]] is not
empty , returntrue ; otherwise returnfalse .
6.2.4.4 GetValue ( V )
The abstract operation GetValue takes argument V. It performs the following steps when called:
ReturnIfAbrupt (V).- If V is not a
Reference Record , return V. - If
IsUnresolvableReference (V) istrue , throw aReferenceError exception. - If
IsPropertyReference (V) istrue , then- Let baseObj be !
ToObject (V.[[Base]]). - Return ? baseObj.[[Get]](V.[[ReferencedName]],
GetThisValue (V)).
- Let baseObj be !
- Else,
- Let base be V.[[Base]].
Assert : base is anEnvironment Record .- Return ? base.GetBindingValue(V.[[ReferencedName]], V.[[Strict]]) (see
9.1 ).
The object that may be created in step
6.2.4.5 PutValue ( V, W )
The abstract operation PutValue takes arguments V and W. It performs the following steps when called:
ReturnIfAbrupt (V).ReturnIfAbrupt (W).- If V is not a
Reference Record , throw aReferenceError exception. - If
IsUnresolvableReference (V) istrue , then- If V.[[Strict]] is
true , throw aReferenceError exception. - Let globalObj be
GetGlobalObject (). - Return ?
Set (globalObj, V.[[ReferencedName]], W,false ).
- If V.[[Strict]] is
- If
IsPropertyReference (V) istrue , then- Let baseObj be !
ToObject (V.[[Base]]). - Let succeeded be ? baseObj.[[Set]](V.[[ReferencedName]], W,
GetThisValue (V)). - If succeeded is
false and V.[[Strict]] istrue , throw aTypeError exception. - Return.
- Let baseObj be !
- Else,
- Let base be V.[[Base]].
Assert : base is anEnvironment Record .- Return ? base.SetMutableBinding(V.[[ReferencedName]], W, V.[[Strict]]) (see
9.1 ).
The object that may be created in step
6.2.4.6 GetThisValue ( V )
The abstract operation GetThisValue takes argument V. It performs the following steps when called:
Assert :IsPropertyReference (V) istrue .- If
IsSuperReference (V) istrue , return V.[[ThisValue]]; otherwise return V.[[Base]].
6.2.4.7 InitializeReferencedBinding ( V, W )
The abstract operation InitializeReferencedBinding takes arguments V and W. It performs the following steps when called:
ReturnIfAbrupt (V).ReturnIfAbrupt (W).Assert : V is aReference Record .Assert :IsUnresolvableReference (V) isfalse .- Let base be V.[[Base]].
Assert : base is anEnvironment Record .- Return base.InitializeBinding(V.[[ReferencedName]], W).
6.2.5 The Property Descriptor Specification Type
The Property Descriptor
Property Descriptor values may be further classified as data Property Descriptors and accessor Property Descriptors based upon the existence or use of certain fields. A data Property Descriptor is one that includes any fields named either [[Value]] or [[Writable]]. An accessor Property Descriptor is one that includes any fields named either [[Get]] or [[Set]]. Any Property Descriptor may have fields named [[Enumerable]] and [[Configurable]]. A Property Descriptor value may not be both a data Property Descriptor and an accessor Property Descriptor; however, it may be neither. A generic Property Descriptor is a Property Descriptor value that is neither a data Property Descriptor nor an accessor Property Descriptor. A fully populated Property Descriptor is one that is either an accessor Property Descriptor or a data Property Descriptor and that has all of the fields that correspond to the property attributes defined in either
The following
6.2.5.1 IsAccessorDescriptor ( Desc )
The abstract operation IsAccessorDescriptor takes argument Desc (a
- If Desc is
undefined , returnfalse . - If both Desc.[[Get]] and Desc.[[Set]] are absent, return
false . - Return
true .
6.2.5.2 IsDataDescriptor ( Desc )
The abstract operation IsDataDescriptor takes argument Desc (a
- If Desc is
undefined , returnfalse . - If both Desc.[[Value]] and Desc.[[Writable]] are absent, return
false . - Return
true .
6.2.5.3 IsGenericDescriptor ( Desc )
The abstract operation IsGenericDescriptor takes argument Desc (a
- If Desc is
undefined , returnfalse . - If
IsAccessorDescriptor (Desc) andIsDataDescriptor (Desc) are bothfalse , returntrue . - Return
false .
6.2.5.4 FromPropertyDescriptor ( Desc )
The abstract operation FromPropertyDescriptor takes argument Desc (a
- If Desc is
undefined , returnundefined . - Let obj be !
OrdinaryObjectCreate (%Object.prototype% ). Assert : obj is an extensibleordinary object with no own properties.- If Desc has a [[Value]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"value" , Desc.[[Value]]).
- Perform !
- If Desc has a [[Writable]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"writable" , Desc.[[Writable]]).
- Perform !
- If Desc has a [[Get]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"get" , Desc.[[Get]]).
- Perform !
- If Desc has a [[Set]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"set" , Desc.[[Set]]).
- Perform !
- If Desc has an [[Enumerable]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"enumerable" , Desc.[[Enumerable]]).
- Perform !
- If Desc has a [[Configurable]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"configurable" , Desc.[[Configurable]]).
- Perform !
- Return obj.
6.2.5.5 ToPropertyDescriptor ( Obj )
The abstract operation ToPropertyDescriptor takes argument Obj. It performs the following steps when called:
- If
Type (Obj) is not Object, throw aTypeError exception. - Let desc be a new
Property Descriptor that initially has no fields. - Let hasEnumerable be ?
HasProperty (Obj,"enumerable" ). - If hasEnumerable is
true , then - Let hasConfigurable be ?
HasProperty (Obj,"configurable" ). - If hasConfigurable is
true , then - Let hasValue be ?
HasProperty (Obj,"value" ). - If hasValue is
true , then - Let hasWritable be ?
HasProperty (Obj,"writable" ). - If hasWritable is
true , then - Let hasGet be ?
HasProperty (Obj,"get" ). - If hasGet is
true , then- Let getter be ?
Get (Obj,"get" ). - If
IsCallable (getter) isfalse and getter is notundefined , throw aTypeError exception. Set desc.[[Get]] to getter.
- Let getter be ?
- Let hasSet be ?
HasProperty (Obj,"set" ). - If hasSet is
true , then- Let setter be ?
Get (Obj,"set" ). - If
IsCallable (setter) isfalse and setter is notundefined , throw aTypeError exception. Set desc.[[Set]] to setter.
- Let setter be ?
- If desc.[[Get]] is present or desc.[[Set]] is present, then
- If desc.[[Value]] is present or desc.[[Writable]] is present, throw a
TypeError exception.
- If desc.[[Value]] is present or desc.[[Writable]] is present, throw a
- Return desc.
6.2.5.6 CompletePropertyDescriptor ( Desc )
The abstract operation CompletePropertyDescriptor takes argument Desc (a
Assert : Desc is aProperty Descriptor .- Let like be the
Record { [[Value]]:undefined , [[Writable]]:false , [[Get]]:undefined , [[Set]]:undefined , [[Enumerable]]:false , [[Configurable]]:false }. - If
IsGenericDescriptor (Desc) istrue orIsDataDescriptor (Desc) istrue , then- If Desc does not have a [[Value]] field, set Desc.[[Value]] to like.[[Value]].
- If Desc does not have a [[Writable]] field, set Desc.[[Writable]] to like.[[Writable]].
- Else,
- If Desc does not have a [[Get]] field, set Desc.[[Get]] to like.[[Get]].
- If Desc does not have a [[Set]] field, set Desc.[[Set]] to like.[[Set]].
- If Desc does not have an [[Enumerable]] field, set Desc.[[Enumerable]] to like.[[Enumerable]].
- If Desc does not have a [[Configurable]] field, set Desc.[[Configurable]] to like.[[Configurable]].
- Return Desc.
6.2.6 The Environment Record Specification Type
The
6.2.7 The Abstract Closure Specification Type
The Abstract Closure specification
In algorithm steps that create an Abstract Closure, values are captured with the verb "capture" followed by a list of aliases. When an Abstract Closure is created, it captures the value that is associated with each alias at that time. In steps that specify the algorithm to be performed when an Abstract Closure is called, each captured value is referred to by the alias that was used to capture the value.
If an Abstract Closure returns a
Abstract Closures are created inline as part of other algorithms, shown in the following example.
- Let addend be 41.
- Let closure be a new Abstract Closure with parameters (x) that captures addend and performs the following steps when called:
- Return x + addend.
- Let val be closure(1).
Assert : val is 42.
6.2.8 Data Blocks
The Data Block specification
For notational convenience within this specification, an array-like syntax can be used to access the individual bytes of a Data Block value. This notation presents a Data Block value as a 0-origined
A data block that resides in memory that can be referenced from multiple agents concurrently is designated a Shared Data Block. A Shared Data Block has an identity (for the purposes of equality testing Shared Data Block values) that is address-free: it is tied not to the virtual addresses the block is mapped to in any process, but to the set of locations in memory that the block represents. Two data blocks are equal only if the sets of the locations they contain are equal; otherwise, they are not equal and the intersection of the sets of locations they contain is empty. Finally, Shared Data Blocks can be distinguished from Data Blocks.
The semantics of Shared Data Blocks is defined using Shared Data Block events by the
Shared Data Block events are modeled by Records, defined in the
The following
6.2.8.1 CreateByteDataBlock ( size )
The abstract operation CreateByteDataBlock takes argument size (an
Assert : size ≥ 0.- Let db be a new
Data Block value consisting of size bytes. If it is impossible to create such aData Block , throw aRangeError exception. Set all of the bytes of db to 0.- Return db.
6.2.8.2 CreateSharedByteDataBlock ( size )
The abstract operation CreateSharedByteDataBlock takes argument size (a non-negative
Assert : size ≥ 0.- Let db be a new
Shared Data Block value consisting of size bytes. If it is impossible to create such aShared Data Block , throw aRangeError exception. - Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is
AgentSignifier (). - Let zero be « 0 ».
- For each index i of db, do
- Append
WriteSharedMemory { [[Order]]:Init , [[NoTear]]:true , [[Block]]: db, [[ByteIndex]]: i, [[ElementSize]]: 1, [[Payload]]: zero } to eventList.
- Append
- Return db.
6.2.8.3 CopyDataBlockBytes ( toBlock, toIndex, fromBlock, fromIndex, count )
The abstract operation CopyDataBlockBytes takes arguments toBlock, toIndex (a non-negative
Assert : fromBlock and toBlock are distinctData Block orShared Data Block values.- Let fromSize be the number of bytes in fromBlock.
Assert : fromIndex + count ≤ fromSize.- Let toSize be the number of bytes in toBlock.
Assert : toIndex + count ≤ toSize.- Repeat, while count > 0,
- If fromBlock is a
Shared Data Block , then- Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is
AgentSignifier (). - Let bytes be a
List whose sole element is a nondeterministically chosenbyte value . - NOTE: In implementations, bytes is the result of a non-atomic read instruction on the underlying hardware. The nondeterminism is a semantic prescription of the
memory model to describe observable behaviour of hardware with weak consistency. - Let readEvent be
ReadSharedMemory { [[Order]]:Unordered , [[NoTear]]:true , [[Block]]: fromBlock, [[ByteIndex]]: fromIndex, [[ElementSize]]: 1 }. - Append readEvent to eventList.
- Append
Chosen Value Record { [[Event]]: readEvent, [[ChosenValue]]: bytes } to execution.[[ChosenValues]]. - If toBlock is a
Shared Data Block , then- Append
WriteSharedMemory { [[Order]]:Unordered , [[NoTear]]:true , [[Block]]: toBlock, [[ByteIndex]]: toIndex, [[ElementSize]]: 1, [[Payload]]: bytes } to eventList.
- Append
- Else,
Set toBlock[toIndex] to bytes[0].
- Let execution be the [[CandidateExecution]] field of the
- Else,
Assert : toBlock is not aShared Data Block .Set toBlock[toIndex] to fromBlock[fromIndex].
Set toIndex to toIndex + 1.Set fromIndex to fromIndex + 1.Set count to count - 1.
- If fromBlock is a
- Return
NormalCompletion (empty ).