Last active
May 15, 2019 18:21
-
-
Save leobalter/4f3e6fa31fdd782b34d2c5ae88c6049f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
```js | |
Object.setPrototypeOf(Array.prototype, new Int8Array(0)); | |
const a = []; | |
a[0] = 4; | |
console.log(+a[0]); | |
``` | |
--- | |
`a[0] = 4;` | |
[[Set]] ( P, V, Receiver ) | |
1. Return ? OrdinarySet(O, P, V, Receiver). | |
--- | |
OrdinarySet ( O, P, V, Receiver ) | |
... | |
2. Let ownDesc be ? O.[[GetOwnProperty]](P). | |
3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc). | |
--- | |
[[GetOwnProperty]] ( P ) | |
1. Return ! OrdinaryGetOwnProperty(O, P). | |
--- | |
OrdinaryGetOwnProperty ( O, P ) | |
... | |
2. If O does not have an own property with key P, return undefined. | |
--- | |
OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) | |
... | |
2. If ownDesc is undefined, then | |
a. Let parent be ? O.[[GetPrototypeOf]](). | |
b. If parent is not null, then | |
i. Return ? parent.[[Set]](P, V, Receiver). | |
--- | |
9.4.5.5 [[Set]] ( P, V, Receiver ) (Integer-indexed exotic objects) | |
... | |
2. If Type(P) is String, then | |
a. Let numericIndex be ! CanonicalNumericIndexString(P). | |
b. If numericIndex is not undefined, then | |
i. Return ? IntegerIndexedElementSet(O, numericIndex, V). | |
--- | |
IntegerIndexedElementSet ( O, index, value ) | |
... | |
5. If IsInteger(index) is false, return false. | |
6. If index = -0, return false. | |
7. Let length be O.[[ArrayLength]]. | |
8. If index < 0 or index ≥ length, return false. // End of the line, `a[0] = 4;` returns false. Without setting anything. | |
--- | |
`+a[0];` | |
`a[0]` is `undefined`; `+undefined` is `NaN`; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment