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/tests/test262/built-ins/Object/setPrototypeOf | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Object/setPrototypeOf')
14 files changed, 321 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/bigint.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/bigint.js new file mode 100644 index 0000000000..36477cd529 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/bigint.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: RequireObjectCoercible for BigInt values +esid: pending +features: [BigInt] +---*/ + +try { + let {} = 0n; +} catch (e) { + throw new Test262Error('Expected RequireObjectCoercible to succeed for BigInt values'); +} + +assert.sameValue(Object.setPrototypeOf(0n, null), 0n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/browser.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/browser.js diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/length.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/length.js new file mode 100644 index 0000000000..f2f8d611b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf '`length` property' +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Object.setPrototypeOf.length, + 2, + 'The value of `Object.setPrototypeOf.length` is `2`' +); + +verifyNotEnumerable(Object.setPrototypeOf, 'length'); +verifyNotWritable(Object.setPrototypeOf, 'length'); +verifyConfigurable(Object.setPrototypeOf, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/name.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/name.js new file mode 100644 index 0000000000..1c9ab55a58 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/name.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf '`name` property' +info: | + ES6 Section 17: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + + [...] + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Object.setPrototypeOf.name, + 'setPrototypeOf', + 'The value of `Object.setPrototypeOf.name` is `"setPrototypeOf"`' +); + +verifyNotEnumerable(Object.setPrototypeOf, 'name'); +verifyNotWritable(Object.setPrototypeOf, 'name'); +verifyConfigurable(Object.setPrototypeOf, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/not-a-constructor.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/not-a-constructor.js new file mode 100644 index 0000000000..625f438f4a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Object.setPrototypeOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Object.setPrototypeOf), + false, + 'isConstructor(Object.setPrototypeOf) must return false' +); + +assert.throws(TypeError, () => { + new Object.setPrototypeOf({}, {}); +}, '`new Object.setPrototypeOf({}, {})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js new file mode 100644 index 0000000000..242fbed95a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf invoked with a non-object-coercible value +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + Object.setPrototypeOf(null); +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/o-not-obj.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/o-not-obj.js new file mode 100644 index 0000000000..e269b9a809 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/o-not-obj.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf invoked with a non-object value +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). + 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. + 4. If Type(O) is not Object, return O. +features: [Symbol] +---*/ + +var symbol; + +assert.sameValue(Object.setPrototypeOf(true, null), true); +assert.sameValue(Object.setPrototypeOf(3, null), 3); +assert.sameValue(Object.setPrototypeOf('string', null), 'string'); + +symbol = Symbol('s'); +assert.sameValue(Object.setPrototypeOf(symbol, null), symbol); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/property-descriptor.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/property-descriptor.js new file mode 100644 index 0000000000..946db0ad9c --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/property-descriptor.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf property descriptor +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof Object.setPrototypeOf, 'function'); + +verifyNotEnumerable(Object, 'setPrototypeOf'); +verifyWritable(Object, 'setPrototypeOf'); +verifyConfigurable(Object, 'setPrototypeOf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/proto-not-obj.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/proto-not-obj.js new file mode 100644 index 0000000000..6d8e70c14d --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/proto-not-obj.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf invoked with an invalid prototype value +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). + 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Object.setPrototypeOf({}); +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf({}, undefined); +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf({}, true); +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf({}, 1); +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf({}, 'string'); +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf({}, Symbol('s')); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-error.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-error.js new file mode 100644 index 0000000000..c15891e442 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-error.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: > + Object.setPrototypeOf invoked with an object whose prototype cannot be set +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). + 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. + 4. If Type(O) is not Object, return O. + 5. Let status be O.[[SetPrototypeOf]](proto). + 6. ReturnIfAbrupt(status). +features: [Proxy] +---*/ + +var obj = new Proxy({}, { + setPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.setPrototypeOf(obj, null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-failure-cycle.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-failure-cycle.js new file mode 100644 index 0000000000..0e8a664f21 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-failure-cycle.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: > + Object.setPrototypeOf invoked with a value that would create a cycle +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). + 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. + 4. If Type(O) is not Object, return O. + 5. Let status be O.[[SetPrototypeOf]](proto). + 6. ReturnIfAbrupt(status). + 7. If status is false, throw a TypeError exception. +---*/ + +var obj = {}; + +assert.throws(TypeError, function() { + Object.setPrototypeOf(Object.prototype, Array.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js new file mode 100644 index 0000000000..168cad6773 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf invoked with a non-extensible object +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). + 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. + 4. If Type(O) is not Object, return O. + 5. Let status be O.[[SetPrototypeOf]](proto). + 6. ReturnIfAbrupt(status). + 7. If status is false, throw a TypeError exception. +---*/ + +var obj = {}; + +Object.preventExtensions(obj); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(obj, null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/shell.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/shell.js diff --git a/js/src/tests/test262/built-ins/Object/setPrototypeOf/success.js b/js/src/tests/test262/built-ins/Object/setPrototypeOf/success.js new file mode 100644 index 0000000000..34442ccbed --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/setPrototypeOf/success.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.18 +description: Object.setPrototypeOf invoked with a non-extensible object +info: | + 1. Let O be RequireObjectCoercible(O). + 2. ReturnIfAbrupt(O). + 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. + 4. If Type(O) is not Object, return O. + 5. Let status be O.[[SetPrototypeOf]](proto). + 6. ReturnIfAbrupt(status). + 7. If status is false, throw a TypeError exception. + 8. Return O. +---*/ + +var propValue = {}; +var newProto = { + test262prop: propValue +}; +var obj = {}; +var result; + +result = Object.setPrototypeOf(obj, newProto); + +assert.sameValue(result, obj, 'Return value'); +assert( + !Object.prototype.hasOwnProperty.call(obj, 'test262prop'), + "'test262prop' isn't copied to an own property" +); +assert.sameValue(obj.test262prop, propValue); + +reportCompare(0, 0); |