diff --git a/test/built-ins/Reflect/setPrototypeOf/length.js b/test/built-ins/Reflect/setPrototypeOf/length.js new file mode 100644 index 0000000000..bcb8d164c6 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/length.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: 26.1.14 +description: > + Reflect.setPrototypeOf.length value and property descriptor +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.setPrototypeOf.length, 2, + 'The value of `Reflect.setPrototypeOf.length` is `2`' +); + +verifyNotEnumerable(Reflect.setPrototypeOf, 'length'); +verifyNotWritable(Reflect.setPrototypeOf, 'length'); +verifyConfigurable(Reflect.setPrototypeOf, 'length'); diff --git a/test/built-ins/Reflect/setPrototypeOf/name.js b/test/built-ins/Reflect/setPrototypeOf/name.js new file mode 100644 index 0000000000..f0a81a0d9e --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/name.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: 26.1.14 +description: > + Reflect.setPrototypeOf.name value and property descriptor +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.setPrototypeOf.name, 'setPrototypeOf', + 'The value of `Reflect.setPrototypeOf.name` is `"setPrototypeOf"`' +); + +verifyNotEnumerable(Reflect.setPrototypeOf, 'name'); +verifyNotWritable(Reflect.setPrototypeOf, 'name'); +verifyConfigurable(Reflect.setPrototypeOf, 'name'); diff --git a/test/built-ins/Reflect/setPrototypeOf/proto-is-not-object-and-not-null-throws.js b/test/built-ins/Reflect/setPrototypeOf/proto-is-not-object-and-not-null-throws.js new file mode 100644 index 0000000000..9f354653aa --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/proto-is-not-object-and-not-null-throws.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.14 +description: > + Throws a TypeError if proto is not Object or proto is not null. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 2. If Type(proto) is not Object and proto is not null, throw a TypeError + exception + ... +---*/ + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, undefined); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, 1); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, 'string'); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, true); +}); diff --git a/test/built-ins/Reflect/setPrototypeOf/proto-is-symbol-throws.js b/test/built-ins/Reflect/setPrototypeOf/proto-is-symbol-throws.js new file mode 100644 index 0000000000..680700fb92 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/proto-is-symbol-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.14 +description: > + Throws a TypeError if proto is a Symbol +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 2. If Type(proto) is not Object and proto is not null, throw a TypeError + exception + ... +features: [Symbol] +---*/ + +var s = Symbol(1); +assert.throws(TypeError, function() { + Reflect.setPrototypeOf({}, s); +}); diff --git a/test/built-ins/Reflect/setPrototypeOf/return-abrupt-from-result.js b/test/built-ins/Reflect/setPrototypeOf/return-abrupt-from-result.js new file mode 100644 index 0000000000..b896e20403 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/return-abrupt-from-result.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: 26.1.14 +description: > + Return abrupt result. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.setPrototypeOf(p, {}); +}); diff --git a/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-and-proto-are-the-same.js b/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-and-proto-are-the-same.js new file mode 100644 index 0000000000..1f5b266b62 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-and-proto-are-the-same.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: 26.1.14 +description: > + Return false if target and proto are the same, without setting a new prototype. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 8. Repeat while done is false, + a. If p is null, let done be true. + b. Else, if SameValue(p, O) is true, return false. + ... +---*/ + +var o1 = {}; +assert.sameValue(Reflect.setPrototypeOf(o1, o1), false); +assert.sameValue(Object.getPrototypeOf(o1), Object.prototype); diff --git a/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-not-extensible.js b/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-not-extensible.js new file mode 100644 index 0000000000..efa840eeea --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-not-extensible.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: 26.1.14 +description: > + Return false if target is not extensible, without changing the prototype. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 5. If extensible is false, return false. + ... +---*/ + +var o1 = {}; +Object.preventExtensions(o1); +assert.sameValue(Reflect.setPrototypeOf(o1, {}), false); +assert.sameValue(Object.getPrototypeOf(o1), Object.prototype); + +var o2 = {}; +Object.preventExtensions(o2); +assert.sameValue(Reflect.setPrototypeOf(o2, null), false); +assert.sameValue(Object.getPrototypeOf(o2), Object.prototype); + +var o3 = Object.create(null); +Object.preventExtensions(o3); +assert.sameValue(Reflect.setPrototypeOf(o3, {}), false); +assert.sameValue(Object.getPrototypeOf(o3), null); diff --git a/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-prototype-of-proto.js b/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-prototype-of-proto.js new file mode 100644 index 0000000000..a83e64b376 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/return-false-if-target-is-prototype-of-proto.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: 26.1.14 +description: > + Return false if target is found as a prototype of proto, without setting. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 8. Repeat while done is false, + a. If p is null, let done be true. + b. Else, if SameValue(p, O) is true, return false. + c. Else, + i. If the [[GetPrototypeOf]] internal method of p is not the ordinary + object internal method defined in 9.1.1, let done be true. + ii. Else, let p be the value of p’s [[Prototype]] internal slot. + ... +---*/ + +var target = {}; +var proto = Object.create(target); +assert.sameValue(Reflect.setPrototypeOf(target, proto), false); +assert.sameValue(Object.getPrototypeOf(target), Object.prototype); diff --git a/test/built-ins/Reflect/setPrototypeOf/return-true-if-new-prototype-is-set.js b/test/built-ins/Reflect/setPrototypeOf/return-true-if-new-prototype-is-set.js new file mode 100644 index 0000000000..a08f4ba600 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/return-true-if-new-prototype-is-set.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: 26.1.14 +description: > + Return true if the new prototype is set. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 9. Set the value of the [[Prototype]] internal slot of O to V. + 10. Return true. + ... +---*/ + +var o1 = {}; +assert.sameValue(Reflect.setPrototypeOf(o1, null), true); +assert.sameValue(Object.getPrototypeOf(o1), null); + +var o2 = Object.create(null); +assert.sameValue(Reflect.setPrototypeOf(o2, Object.prototype), true); +assert.sameValue(Object.getPrototypeOf(o2), Object.prototype); + +var o3 = {}; +var proto = {}; +assert.sameValue(Reflect.setPrototypeOf(o3, proto), true); +assert.sameValue(Object.getPrototypeOf(o3), proto); diff --git a/test/built-ins/Reflect/setPrototypeOf/return-true-if-proto-is-current.js b/test/built-ins/Reflect/setPrototypeOf/return-true-if-proto-is-current.js new file mode 100644 index 0000000000..e864715180 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/return-true-if-proto-is-current.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: 26.1.14 +description: > + Return true if proto has the same value as current target's prototype. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + ... + 3. Return target.[[SetPrototypeOf]](proto). + + 9.1.2 [[SetPrototypeOf]] (V) + + ... + 4. If SameValue(V, current), return true. + ... +---*/ + +var o1 = {}; +Object.preventExtensions(o1); +assert.sameValue(Reflect.setPrototypeOf(o1, Object.prototype), true); + +var o2 = Object.create(null); +Object.preventExtensions(o2); +assert.sameValue(Reflect.setPrototypeOf(o2, null), true); + +var proto = {}; +var o3 = Object.create(proto); +Object.preventExtensions(o3); +assert.sameValue(Reflect.setPrototypeOf(o3, proto), true); diff --git a/test/built-ins/Reflect/setPrototypeOf/setPrototypeOf.js b/test/built-ins/Reflect/setPrototypeOf/setPrototypeOf.js new file mode 100644 index 0000000000..3e3d790022 --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/setPrototypeOf.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: 26.1.14 +description: > + Reflect.setPrototypeOf is configurable, writable and not enumerable. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Reflect, 'setPrototypeOf'); +verifyWritable(Reflect, 'setPrototypeOf'); +verifyConfigurable(Reflect, 'setPrototypeOf'); diff --git a/test/built-ins/Reflect/setPrototypeOf/target-is-not-object-throws.js b/test/built-ins/Reflect/setPrototypeOf/target-is-not-object-throws.js new file mode 100644 index 0000000000..b916c835be --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/target-is-not-object-throws.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: 26.1.14 +description: > + Throws a TypeError if target is not an Object. +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(1, {}); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(null, {}); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(undefined, {}); +}); + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf('', {}); +}); diff --git a/test/built-ins/Reflect/setPrototypeOf/target-is-symbol-throws.js b/test/built-ins/Reflect/setPrototypeOf/target-is-symbol-throws.js new file mode 100644 index 0000000000..959a02ff3a --- /dev/null +++ b/test/built-ins/Reflect/setPrototypeOf/target-is-symbol-throws.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: 26.1.14 +description: > + Throws a TypeError if target is a Symbol +info: > + 26.1.14 Reflect.setPrototypeOf ( target, proto ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.setPrototypeOf(Symbol(1), {}); +});