Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

[WIP] Remove in property checking for ObjectValues - fixes 2510 #2512

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/intrinsics/ecma262/ArrayBufferPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception.
if (!("$ArrayBufferData" in O)) {
if (O.$ArrayBufferData === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have an [[ArrayBufferData]] internal slot"
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception.
if (!("$ArrayBufferData" in O)) {
if (O.$ArrayBufferData === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have an [[ArrayBufferData]] internal slot"
Expand Down
6 changes: 3 additions & 3 deletions src/intrinsics/ecma262/DataViewPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[DataView]] internal slot, throw a TypeError exception.
if (!("$DataView" in O)) {
if (O.$DataView === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[DataView]] internal slot"
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[DataView]] internal slot, throw a TypeError exception.
if (!("$DataView" in O)) {
if (O.$DataView === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[DataView]] internal slot"
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[DataView]] internal slot, throw a TypeError exception.
if (!("$DataView" in O)) {
if (O.$DataView === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[DataView]] internal slot"
Expand Down
2 changes: 1 addition & 1 deletion src/intrinsics/ecma262/SetIteratorPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have all of the internal slots of a Set Iterator Instance (23.2.5.3), throw a TypeError exception.
if (!("$IteratedSet" in O) || !("$SetNextIndex" in O) || !("$SetIterationKind" in O)) {
if (O.$IteratedSet === undefined || O.$SetNextIndex === undefined || O.$SetIterationKind === undefined) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "SetIteratorPrototype.next isn't generic");
}

Expand Down
2 changes: 1 addition & 1 deletion src/intrinsics/ecma262/StringIteratorPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have all of the internal slots of an String Iterator Instance (21.1.5.3), throw a TypeError exception.
if (!("$IteratedString" in O && "$StringIteratorNextIndex" in O)) {
if (O.$IteratedString === undefined && O.$StringIteratorNextIndex === undefined) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(O) is not Object");
}

Expand Down
12 changes: 6 additions & 6 deletions src/intrinsics/ecma262/TypedArrayPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
if (!("$TypedArrayName" in O)) {
if (O.$TypedArrayName === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[TypedArrayName]] internal slot"
Expand Down Expand Up @@ -70,7 +70,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
if (!("$TypedArrayName" in O)) {
if (O.$TypedArrayName === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[TypedArrayName]] internal slot"
Expand Down Expand Up @@ -106,7 +106,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
if (!("$TypedArrayName" in O)) {
if (O.$TypedArrayName === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[TypedArrayName]] internal slot"
Expand Down Expand Up @@ -781,7 +781,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
if (!("$TypedArrayName" in O)) {
if (O.$TypedArrayName === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[TypedArrayName]] internal slot"
Expand Down Expand Up @@ -1666,7 +1666,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
}

// 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
if (!("$TypedArrayName" in O)) {
if (O.$TypedArrayName === undefined) {
throw realm.createErrorThrowCompletion(
realm.intrinsics.TypeError,
"O does not have a [[TypedArrayName]] internal slot"
Expand Down Expand Up @@ -1802,7 +1802,7 @@ export default function(realm: Realm, obj: ObjectValue): void {
if (!(O instanceof ObjectValue)) return realm.intrinsics.undefined;

// 3. If O does not have a [[TypedArrayName]] internal slot, return undefined.
if (!("$TypedArrayName" in O)) return realm.intrinsics.undefined;
if (O.$TypedArrayName === undefined) return realm.intrinsics.undefined;

// 4. Let name be O.[[TypedArrayName]].
let name = O.$TypedArrayName;
Expand Down
6 changes: 2 additions & 4 deletions src/methods/typedarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,8 @@ export function AllocateTypedArrayBuffer(realm: Realm, O: ObjectValue, length: n
invariant(realm.isNewObject(O));

// 1. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
invariant(
O instanceof ObjectValue && "$ViewedArrayBuffer" in O,
"O is an Object that has a [[ViewedArrayBuffer]] internal slot"
);
// [[ViewedArrayBuffer]] will always be an internal slot, but that of undefined by default, see #2512
invariant(O instanceof ObjectValue, "O is an Object that has a [[ViewedArrayBuffer]] internal slot");

// 2. Assert: O.[[ViewedArrayBuffer]] is undefined.
invariant(O.$ViewedArrayBuffer === undefined, "O.[[ViewedArrayBuffer]] is undefined");
Expand Down
13 changes: 13 additions & 0 deletions src/values/ObjectValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ export default class ObjectValue extends ConcreteValue {
// as other code checks whether this.$IsClassPrototype === undefined
// as a proxy for whether initialization is still ongoing.
this.$IsClassPrototype = false;
// These properties were possibly not defined before, but now are always defined
// and set to undefined as their default slot state. Furthermore, these ensure
// that ObjectValue has the same hidden class for these properties.
// TODO ensure all other properties are also defined in the constructor to ensure
// they make ObjectValue have the same hidden class. See #2510.
this.$ViewedArrayBuffer = undefined;
this.$DataView = undefined;
this.$IteratedSet = undefined;
this.$SetNextIndex = undefined;
this.$SetIterationKind = undefined;
this.$TypedArrayName = undefined;
this.$IteratedString = undefined;
this.$StringIteratorNextIndex = undefined;
}

static trackedPropertyNames = [
Expand Down