diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/object-assign-plain.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/object-assign-plain.js')
-rw-r--r-- | js/src/jit-test/tests/basic/object-assign-plain.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/object-assign-plain.js b/js/src/jit-test/tests/basic/object-assign-plain.js new file mode 100644 index 0000000000..0476eb8c09 --- /dev/null +++ b/js/src/jit-test/tests/basic/object-assign-plain.js @@ -0,0 +1,122 @@ +// Tests for Object.assign's fast path for plain objects. + +load(libdir + "asserts.js"); + +function testProtoSetter() { + var from = Object.create(null); + from.__proto__ = {}; + assertEq(Object.getPrototypeOf(from), null); + + var to = Object.assign({}, from); + assertEq(Object.getPrototypeOf(to), from.__proto__); + assertEq(Object.getOwnPropertyNames(to).length, 0); +} +testProtoSetter(); + +function testProtoDataProp() { + var to = Object.create(null); + to.__proto__ = 1; + var from = Object.create(null); + from.__proto__ = 2; + Object.assign(to, from); + assertEq(Object.getPrototypeOf(to), null); + assertEq(to.__proto__, 2); +} +testProtoDataProp(); + +function testNonExtensible() { + var to = Object.preventExtensions({x: 1}); + Object.assign(to, {x: 2}); + assertEq(to.x, 2); + assertThrowsInstanceOf(() => Object.assign(to, {x: 3, y: 4}), TypeError); + assertEq(to.x, 3); + assertEq("y" in to, false); +} +testNonExtensible(); + +function testNonExtensibleNoProps() { + var to = Object.preventExtensions({}); + Object.assign(to, {}); // No exception. +} +testNonExtensibleNoProps(); + +function testDenseElements() { + var to = Object.assign({}, {0: 1, 1: 2}); + assertEq(to[0], 1); + assertEq(to[1], 2); +} +testDenseElements(); + +function testNonWritableOnProto() { + var proto = {}; + Object.defineProperty(proto, "x", {value: 1, enumerable: true, configurable: true}); + var to = Object.create(proto); + assertThrowsInstanceOf(() => Object.assign(to, {x: 2}), TypeError); + assertEq(to.x, 1); + assertEq(Object.getOwnPropertyNames(to).length, 0); +} +testNonWritableOnProto(); + +function testAccessorOnProto() { + var setterVal; + var proto = {set a(v) { setterVal = v; }}; + var to = Object.assign(Object.create(proto), {a: 9}); + assertEq(setterVal, 9); + assertEq(Object.getOwnPropertyNames(to).length, 0); +} +testAccessorOnProto(); + +function testSetAndAdd() { + var to = Object.assign({x: 1, y: 2}, {x: 3, y: 4, z: 5}); + assertEq(to.x, 3); + assertEq(to.y, 4); + assertEq(to.z, 5); +} +testSetAndAdd(); + +function testNonConfigurableFrom() { + var from = {}; + Object.defineProperty(from, "x", {value: 1, enumerable: true, writable: true}); + var to = Object.assign({}, from); + assertEq(to.x, 1); + assertEq(Object.getOwnPropertyDescriptor(to, "x").configurable, true); +} +testNonConfigurableFrom(); + +function testNonEnumerableFrom() { + var from = {}; + Object.defineProperty(from, "x", {value: 1, configurable: true, writable: true}); + var to = Object.assign({}, from); + assertEq(Object.getOwnPropertyNames(to).length, 0); + assertEq(to.x, undefined); +} +testNonEnumerableFrom(); + +function testNonWritableFrom() { + var from = {}; + Object.defineProperty(from, "x", {value: 1, configurable: true, enumerable: true}); + var to = Object.assign({}, from); + assertEq(to.x, 1); + assertEq(Object.getOwnPropertyDescriptor(to, "x").writable, true); +} +testNonWritableFrom(); + +function testFrozenProto() { + var proto = Object.freeze({x: 1}); + var target = Object.create(proto); + Object.assign(target, {foo: 1}); + assertEq(target.foo, 1); + assertThrowsInstanceOf(() => Object.assign(target, {x: 2}), TypeError); + assertEq(target.x, 1); +} +testFrozenProto(); + +function testReuseShape() { + var from = {}; + from.x = 1; + from.y = 2; + var to = Object.assign({}, from); + assertEq(to.x, 1); + assertEq(to.y, 2); +} +testReuseShape(); |