mirror of https://github.com/tc39/test262.git
Add tests for Reflect.setPrototypeOf
This commit is contained in:
parent
d3743c3ba7
commit
40675b1eb5
|
@ -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');
|
|
@ -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');
|
|
@ -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);
|
||||||
|
});
|
|
@ -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);
|
||||||
|
});
|
|
@ -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, {});
|
||||||
|
});
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
|
@ -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');
|
|
@ -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('', {});
|
||||||
|
});
|
|
@ -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), {});
|
||||||
|
});
|
Loading…
Reference in New Issue