mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 04:54:44 +02:00
Add tests for Object.setPrototypeOf
This commit is contained in:
parent
12cc01484e
commit
3fb882acd0
29
test/built-ins/Object/setPrototypeOf/length.js
Normal file
29
test/built-ins/Object/setPrototypeOf/length.js
Normal file
@ -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');
|
31
test/built-ins/Object/setPrototypeOf/name.js
Normal file
31
test/built-ins/Object/setPrototypeOf/name.js
Normal file
@ -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');
|
||||||
|
|
17
test/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js
Normal file
17
test/built-ins/Object/setPrototypeOf/o-not-obj-coercible.js
Normal file
@ -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);
|
||||||
|
});
|
21
test/built-ins/Object/setPrototypeOf/o-not-obj.js
Normal file
21
test/built-ins/Object/setPrototypeOf/o-not-obj.js
Normal file
@ -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);
|
17
test/built-ins/Object/setPrototypeOf/property-descriptor.js
Normal file
17
test/built-ins/Object/setPrototypeOf/property-descriptor.js
Normal file
@ -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');
|
35
test/built-ins/Object/setPrototypeOf/proto-not-obj.js
Normal file
35
test/built-ins/Object/setPrototypeOf/proto-not-obj.js
Normal file
@ -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'));
|
||||||
|
});
|
25
test/built-ins/Object/setPrototypeOf/set-error.js
Normal file
25
test/built-ins/Object/setPrototypeOf/set-error.js
Normal file
@ -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);
|
||||||
|
});
|
21
test/built-ins/Object/setPrototypeOf/set-failure-cycle.js
Normal file
21
test/built-ins/Object/setPrototypeOf/set-failure-cycle.js
Normal file
@ -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);
|
||||||
|
});
|
@ -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);
|
||||||
|
});
|
28
test/built-ins/Object/setPrototypeOf/success.js
Normal file
28
test/built-ins/Object/setPrototypeOf/success.js
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user