From 3fb882acd077670c5cb0ef2cd48ab82898b8ca92 Mon Sep 17 00:00:00 2001 From: Mike Pennisi <mike@mikepennisi.com> Date: Fri, 19 Jun 2015 11:36:37 -0400 Subject: [PATCH] Add tests for Object.setPrototypeOf --- .../built-ins/Object/setPrototypeOf/length.js | 29 +++++++++++++++ test/built-ins/Object/setPrototypeOf/name.js | 31 ++++++++++++++++ .../setPrototypeOf/o-not-obj-coercible.js | 17 +++++++++ .../Object/setPrototypeOf/o-not-obj.js | 21 +++++++++++ .../setPrototypeOf/property-descriptor.js | 17 +++++++++ .../Object/setPrototypeOf/proto-not-obj.js | 35 +++++++++++++++++++ .../Object/setPrototypeOf/set-error.js | 25 +++++++++++++ .../setPrototypeOf/set-failure-cycle.js | 21 +++++++++++ .../set-failure-non-extensible.js | 22 ++++++++++++ .../Object/setPrototypeOf/success.js | 28 +++++++++++++++ 10 files changed, 246 insertions(+) create mode 100644 test/built-ins/Object/setPrototypeOf/length.js create mode 100644 test/built-ins/Object/setPrototypeOf/name.js create mode 100644 test/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js create mode 100644 test/built-ins/Object/setPrototypeOf/o-not-obj.js create mode 100644 test/built-ins/Object/setPrototypeOf/property-descriptor.js create mode 100644 test/built-ins/Object/setPrototypeOf/proto-not-obj.js create mode 100644 test/built-ins/Object/setPrototypeOf/set-error.js create mode 100644 test/built-ins/Object/setPrototypeOf/set-failure-cycle.js create mode 100644 test/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js create mode 100644 test/built-ins/Object/setPrototypeOf/success.js diff --git a/test/built-ins/Object/setPrototypeOf/length.js b/test/built-ins/Object/setPrototypeOf/length.js new file mode 100644 index 0000000000..122e26ce1b --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/length.js @@ -0,0 +1,29 @@ +// 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'); diff --git a/test/built-ins/Object/setPrototypeOf/name.js b/test/built-ins/Object/setPrototypeOf/name.js new file mode 100644 index 0000000000..ca236427e7 --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/name.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 '`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'); + diff --git a/test/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js b/test/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js new file mode 100644 index 0000000000..18f2c33e3e --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js @@ -0,0 +1,17 @@ +// 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); +}); diff --git a/test/built-ins/Object/setPrototypeOf/o-not-obj.js b/test/built-ins/Object/setPrototypeOf/o-not-obj.js new file mode 100644 index 0000000000..82893866fc --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/o-not-obj.js @@ -0,0 +1,21 @@ +// 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); diff --git a/test/built-ins/Object/setPrototypeOf/property-descriptor.js b/test/built-ins/Object/setPrototypeOf/property-descriptor.js new file mode 100644 index 0000000000..41b58ab7e9 --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/property-descriptor.js @@ -0,0 +1,17 @@ +// 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'); diff --git a/test/built-ins/Object/setPrototypeOf/proto-not-obj.js b/test/built-ins/Object/setPrototypeOf/proto-not-obj.js new file mode 100644 index 0000000000..40afda2f38 --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/proto-not-obj.js @@ -0,0 +1,35 @@ +// 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')); +}); diff --git a/test/built-ins/Object/setPrototypeOf/set-error.js b/test/built-ins/Object/setPrototypeOf/set-error.js new file mode 100644 index 0000000000..0ab4d5956c --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/set-error.js @@ -0,0 +1,25 @@ +// 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); +}); diff --git a/test/built-ins/Object/setPrototypeOf/set-failure-cycle.js b/test/built-ins/Object/setPrototypeOf/set-failure-cycle.js new file mode 100644 index 0000000000..746fca890b --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/set-failure-cycle.js @@ -0,0 +1,21 @@ +// 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); +}); diff --git a/test/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js b/test/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js new file mode 100644 index 0000000000..2c9d46a4e7 --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/set-failure-non-extensible.js @@ -0,0 +1,22 @@ +// 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); +}); diff --git a/test/built-ins/Object/setPrototypeOf/success.js b/test/built-ins/Object/setPrototypeOf/success.js new file mode 100644 index 0000000000..45de3a54e3 --- /dev/null +++ b/test/built-ins/Object/setPrototypeOf/success.js @@ -0,0 +1,28 @@ +// 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.sameValue(Object.hasOwnProperty.call(obj, 'test262prop'), false); +assert.sameValue(obj.test262prop, propValue); -- GitLab