diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/Record | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Record')
-rw-r--r-- | js/src/tests/non262/Record/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/non262/Record/constructor.js | 37 | ||||
-rw-r--r-- | js/src/tests/non262/Record/cross-realm.js | 9 | ||||
-rw-r--r-- | js/src/tests/non262/Record/enumeration.js | 54 | ||||
-rw-r--r-- | js/src/tests/non262/Record/equality.js | 23 | ||||
-rw-r--r-- | js/src/tests/non262/Record/json.js | 13 | ||||
-rw-r--r-- | js/src/tests/non262/Record/literal.js | 41 | ||||
-rw-r--r-- | js/src/tests/non262/Record/properties.js | 20 | ||||
-rw-r--r-- | js/src/tests/non262/Record/property-descriptors.js | 89 | ||||
-rw-r--r-- | js/src/tests/non262/Record/shell.js | 0 | ||||
-rw-r--r-- | js/src/tests/non262/Record/syntax.js | 27 | ||||
-rw-r--r-- | js/src/tests/non262/Record/wrapper.js | 25 |
12 files changed, 338 insertions, 0 deletions
diff --git a/js/src/tests/non262/Record/browser.js b/js/src/tests/non262/Record/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/Record/browser.js diff --git a/js/src/tests/non262/Record/constructor.js b/js/src/tests/non262/Record/constructor.js new file mode 100644 index 0000000000..827179c68e --- /dev/null +++ b/js/src/tests/non262/Record/constructor.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +assertThrowsInstanceOf( + () => new Record(), + TypeError, + "Record is not a constructor" +); + +assertEq(typeof Record({}), "record"); +assertEq(typeof Object(Record({})), "object"); +assertEq(Record({}) instanceof Record, false); + +// TODO: It's still not decided what the prototype of records should be +//assertThrowsInstanceOf(() => Object(Record({})) instanceof Record, TypeError); +// assertEq(Record.prototype, null); +// assertEq(Record({}).__proto__, null); +// assertEq(Object(Record({})).__proto__, null); + +assertThrowsInstanceOf( + () => Record(), + TypeError, + "can't convert undefined to object" +); + +assertThrowsInstanceOf( + () => Record(undefined), + TypeError, + "can't convert undefined to object" +); + +assertThrowsInstanceOf( + () => Record(null), + TypeError, + "can't convert null to object" +); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/cross-realm.js b/js/src/tests/non262/Record/cross-realm.js new file mode 100644 index 0000000000..e67a07d51e --- /dev/null +++ b/js/src/tests/non262/Record/cross-realm.js @@ -0,0 +1,9 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +const realm = newGlobal(); + +const realm_record = realm.eval(`Record({ x: 1, y: 2 })`); + +assertEq(realm_record === #{ x: 1, y: 2 }, true); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/enumeration.js b/js/src/tests/non262/Record/enumeration.js new file mode 100644 index 0000000000..9ed7bec415 --- /dev/null +++ b/js/src/tests/non262/Record/enumeration.js @@ -0,0 +1,54 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +var rec = #{ x: 1, y: 2, a: 3 }; + +var keys = Object.keys(rec); +assertEq(keys.length, 3); +assertEq(keys[0], "a"); +assertEq(keys[1], "x"); +assertEq(keys[2], "y"); + +var values = Object.values(rec); +assertEq(values.length, 3); +assertEq(values[0], 3); +assertEq(values[1], 1); +assertEq(values[2], 2); + +var entries = Object.entries(rec); +assertEq(entries.length, 3); +assertEq(entries[0][0], "a"); +assertEq(entries[0][1], 3); +assertEq(entries[1][0], "x"); +assertEq(entries[1][1], 1); +assertEq(entries[2][0], "y"); +assertEq(entries[2][1], 2); + +var ownKeys = Reflect.ownKeys(Object(rec)); +assertEq(ownKeys.length, 3); +assertEq(ownKeys[0], "a"); +assertEq(ownKeys[1], "x"); +assertEq(ownKeys[2], "y"); + +var spreadKeys = Object.keys({ ...rec }); +assertEq(spreadKeys.length, 3); +assertEq(spreadKeys[0], "a"); +assertEq(spreadKeys[1], "x"); +assertEq(spreadKeys[2], "y"); + +var spreadKeysObj = Object.keys({ ...Object(rec) }); +assertEq(spreadKeysObj.length, 3); +assertEq(spreadKeysObj[0], "a"); +assertEq(spreadKeysObj[1], "x"); +assertEq(spreadKeysObj[2], "y"); + +var i = 0; +for (var key in rec) { + switch (i++) { + case 0: assertEq(key, "a"); break; + case 1: assertEq(key, "x"); break; + case 2: assertEq(key, "y"); break; + default: assertUnreachable(); + } +} + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/equality.js b/js/src/tests/non262/Record/equality.js new file mode 100644 index 0000000000..6e8665af19 --- /dev/null +++ b/js/src/tests/non262/Record/equality.js @@ -0,0 +1,23 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +assertEq(#{} === #{}, true); +assertEq(#{} === #{ x: 1 }, false); +assertEq(#{} === #{ x: undefined }, false); +assertEq(#{ x: 1 } === #{ x: 1 }, true); +assertEq(#{ x: 2 } === #{ x: 1 }, false); +assertEq(#{ y: 1 } === #{ x: 1 }, false); +assertEq(#{ x: 1, y: 2 } === #{ y: 2, x: 1 }, true); +assertEq(#{ x: 1, y: 2 } === #{ y: 1, x: 2 }, false); + +let withPositiveZero = #{ x: +0 }; +let withNegativeZero = #{ x: -0 }; + +assertEq(withPositiveZero === withNegativeZero, true); +assertEq(#[withPositiveZero] === #[withNegativeZero], true); +assertEq(Object.is(withPositiveZero, withNegativeZero), false); +assertEq(Object.is(#[withPositiveZero], #[withNegativeZero]), false); + +assertEq(#{ x: NaN } === #{ x: NaN }, true); +assertEq(Object.is(#{ x: NaN }, #{ x: NaN }), true); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/json.js b/js/src/tests/non262/Record/json.js new file mode 100644 index 0000000000..8a327f2eea --- /dev/null +++ b/js/src/tests/non262/Record/json.js @@ -0,0 +1,13 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +assertEq( + JSON.stringify(#{ x: 1, a: #[1, 2, #{}, #[]] }), + '{"a":[1,2,{},[]],"x":1}' +); + +assertEq( + JSON.stringify({ rec: Object(#{ x: 1 }), tup: Object(#[1, 2]) }), + '{"rec":{"x":1},"tup":[1,2]}' +); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/literal.js b/js/src/tests/non262/Record/literal.js new file mode 100644 index 0000000000..f0d9d67e22 --- /dev/null +++ b/js/src/tests/non262/Record/literal.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +let rec = #{ x: 1, "y": 2, 0: 3, 1n: 4, [`key${4}`]: 5 }; + +assertEq(rec.x, 1); +assertEq(rec.y, 2); +assertEq(rec[0], 3); +assertEq(rec[1], 4); +assertEq(rec.key4, 5); + +let dup = #{ x: 1, x: 2 }; +assertEq(dup.x, 2); + +assertThrowsInstanceOf( + () => #{ [Symbol()]: 1 }, + TypeError, + "Symbols cannot be used as record keys" + ); + +let rec2 = #{ x: 1, ...{ a: 2, z: 3 }, b: 4, ...{ d: 5 } }; +assertEq(rec2.x, 1); +assertEq(rec2.a, 2); +assertEq(rec2.z, 3); +assertEq(rec2.b, 4); +assertEq(rec2.d, 5); + +assertThrowsInstanceOf( + () => #{ ...{ [Symbol()]: 1 } }, + TypeError, + "Symbols cannot be used as record keys" +); + +let rec3 = #{ + ...Object.defineProperty({}, "x", { value: 1 }), + ...Object.defineProperty({}, Symbol(), { value: 2 }), +}; +assertEq(rec3.x, undefined); + +let rec4 = #{ ...{}, ...{}, ...{} }; + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/properties.js b/js/src/tests/non262/Record/properties.js new file mode 100644 index 0000000000..c8139488c0 --- /dev/null +++ b/js/src/tests/non262/Record/properties.js @@ -0,0 +1,20 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +var rec = Record({ + x: 1, + 4: 2, + z: 10n ** 100n, + w: Record({}), + n: Tuple(), + [Symbol.iterator]: 4, +}); + +assertEq(rec.x, 1); +assertEq(rec[4], 2); +assertEq(rec.z, 10n ** 100n); +assertEq(typeof rec.w, "record"); +assertEq(typeof rec.n, "tuple"); +assertEq(rec[Symbol.iterator], undefined); +assertEq(rec.hasOwnProperty, undefined); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/property-descriptors.js b/js/src/tests/non262/Record/property-descriptors.js new file mode 100644 index 0000000000..fea6187536 --- /dev/null +++ b/js/src/tests/non262/Record/property-descriptors.js @@ -0,0 +1,89 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +var rec = Record({ x: 1, y: 2, a: 3 }); + +var desc = Object.getOwnPropertyDescriptor(rec, "x"); +assertEq(desc.value, 1); +assertEq(desc.writable, false); +assertEq(desc.enumerable, true); +assertEq(desc.configurable, false); + +assertEq(Object.getOwnPropertyDescriptor(rec, "z"), undefined); + +var recO = Object(rec); + +assertThrowsInstanceOf( + () => Object.defineProperty(rec, "x", { value: 1 }), + TypeError, + "#{ \"a\": 3, \"x\": 1, \"y\": 2 } is not a non-null object" +); + +assertThrowsInstanceOf( + () => Object.defineProperty(recO, "b", {}), + TypeError, + "can't define property \"b\": Record is not extensible" +); + +assertThrowsInstanceOf( + () => Object.defineProperty(recO, Symbol(), {}), + TypeError, + "can't define property \"b\": Record is not extensible" +); + +assertThrowsInstanceOf( + () => Object.defineProperty(recO, "x", { value: 2 }), + TypeError, + '"x" is read-only' +); + +Object.defineProperty(recO, "x", { value: 1 }); + +assertThrowsInstanceOf( + () => Object.defineProperty(recO, "x", { value: 2, writable: true }), + TypeError, + 'Invalid record property descriptor' +); + +assertThrowsInstanceOf( + () => Object.defineProperty(recO, "x", { value: 2, enumerable: false }), + TypeError, + 'Invalid record property descriptor' +); + +assertThrowsInstanceOf( + () => Object.defineProperty(recO, "x", { value: 2, configurable: true }), + TypeError, + 'Invalid record property descriptor' +); + +assertEq(Object.prototype.propertyIsEnumerable.call(rec, "x"), true); +assertEq(Object.prototype.propertyIsEnumerable.call(rec, "x"), true); +assertEq(Object.prototype.propertyIsEnumerable.call(rec, "w"), false); +assertEq(Object.prototype.propertyIsEnumerable.call(rec, "w"), false); +assertEq(Object.prototype.propertyIsEnumerable.call(recO, "x"), true); +assertEq(Object.prototype.propertyIsEnumerable.call(recO, "x"), true); +assertEq(Object.prototype.propertyIsEnumerable.call(recO, "w"), false); +assertEq(Object.prototype.propertyIsEnumerable.call(recO, "w"), false); + +assertEq(Object.prototype.hasOwnProperty.call(rec, "x"), true); +assertEq(Object.prototype.hasOwnProperty.call(rec, "x"), true); +assertEq(Object.prototype.hasOwnProperty.call(rec, "w"), false); +assertEq(Object.prototype.hasOwnProperty.call(rec, "w"), false); +assertEq(Object.prototype.hasOwnProperty.call(recO, "x"), true); +assertEq(Object.prototype.hasOwnProperty.call(recO, "x"), true); +assertEq(Object.prototype.hasOwnProperty.call(recO, "w"), false); +assertEq(Object.prototype.hasOwnProperty.call(recO, "w"), false); + +assertEq("x" in recO, true); +assertEq("w" in recO, false); + +assertEq(delete rec.x, false); +assertEq(delete rec.x, false); +assertEq(delete rec.w, true); +assertEq(delete rec.w, true); +assertEq(delete recO.x, false); +assertEq(delete recO.x, false); +assertEq(delete recO.w, true); +assertEq(delete recO.w, true); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/shell.js b/js/src/tests/non262/Record/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/Record/shell.js diff --git a/js/src/tests/non262/Record/syntax.js b/js/src/tests/non262/Record/syntax.js new file mode 100644 index 0000000000..1291cd3bab --- /dev/null +++ b/js/src/tests/non262/Record/syntax.js @@ -0,0 +1,27 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +Reflect.parse("#{}"); +Reflect.parse("#{ foo: 1, bar: 2 }"); +Reflect.parse("#{ foo: 1, bar: 2, }"); +Reflect.parse("#{ foo, ...bar }"); +Reflect.parse("#{ foo, ...bar, }"); +Reflect.parse("#{ foo: 1, ...bar, baz: 2 }"); +Reflect.parse("#{ foo }"); +Reflect.parse("#{ foo, }"); +Reflect.parse("#{ foo, bar }"); +Reflect.parse("#{ foo: 1, bar }"); +Reflect.parse("#{ foo, bar: 2 }"); +Reflect.parse("#{ foo: bar() }"); + +Reflect.parse("#{ __proto__ }"); +Reflect.parse("#{ ['__proto__']: 2 }"); + +assertThrowsInstanceOf(() => Reflect.parse("#{,}"), SyntaxError); +assertThrowsInstanceOf(() => Reflect.parse("#{ foo() {} }"), SyntaxError); +assertThrowsInstanceOf(() => Reflect.parse("#{ get foo() {} }"), SyntaxError); +assertThrowsInstanceOf(() => Reflect.parse("#{ __proto__: 2 }"), SyntaxError); +assertThrowsInstanceOf(() => Reflect.parse("#{ '__proto__': 2 }"), SyntaxError); +assertThrowsInstanceOf(() => Reflect.parse("#{ foo = 2 }"), SyntaxError); +assertThrowsInstanceOf(() => Reflect.parse("#{ foo } = bar"), SyntaxError); + +if (typeof reportCompare === "function") reportCompare(0, 0); diff --git a/js/src/tests/non262/Record/wrapper.js b/js/src/tests/non262/Record/wrapper.js new file mode 100644 index 0000000000..1c905739a5 --- /dev/null +++ b/js/src/tests/non262/Record/wrapper.js @@ -0,0 +1,25 @@ +// |reftest| skip-if(!this.hasOwnProperty("Record")) + +var boxO = Object(#{ x: 1, y: 2 }); + +assertEq(Object.isExtensible(boxO), false); +assertEq(Object.isSealed(boxO), true); +assertEq(Object.isFrozen(boxO), true); + +boxO.x = 3; +assertEq(boxO.x, 1); +assertThrowsInstanceOf(() => { "use strict"; boxO.x = 3; }, TypeError); +assertEq(boxO.x, 1); + +boxO.z = 3; +assertEq(boxO.z, undefined); +assertThrowsInstanceOf(() => { "use strict"; boxO.z = 3; }, TypeError); +assertEq(boxO.z, undefined); + +assertThrowsInstanceOf(() => { Object.defineProperty(boxO, "x", { value: 3 }); }, TypeError); +assertEq(boxO.x, 1); + +assertThrowsInstanceOf(() => { Object.defineProperty(boxO, "z", { value: 3 }); }, TypeError); +assertEq(boxO.z, undefined); + +if (typeof reportCompare === "function") reportCompare(0, 0); |