forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for [[SetPrototypeOf]] on Object.prototype
Object.prototype is the immutable prototype exotic object Ref tc39/ecma262#308
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
test/built-ins/Object/prototype/setPrototypeOf-with-different-values.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (C) 2016 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
id: sec-immutable-prototype-exotic-objects-setprototypeof-v | ||
description: > | ||
Object.prototype's [[SetPrototypeOf]] returns false if value is not the same | ||
info: > | ||
9.4.7.1 [[SetPrototypeOf]] (V) | ||
... | ||
2. Let current be the value of the [[Prototype]] internal slot of O. | ||
3. If SameValue(V, current), return true. | ||
4. Return false. | ||
features: [Reflect.setPrototypeOf] | ||
---*/ | ||
|
||
var ObjProto = Object.prototype; | ||
|
||
assert.throws(TypeError, function() { | ||
Object.setPrototypeOf(ObjProto, {}); | ||
}, "Object.setPrototypeOf(ObjProto, {}) throws a TypeError"); | ||
|
||
assert.throws(TypeError, function() { | ||
Object.setPrototypeOf(ObjProto, Array.prototype); | ||
}, "Object.setPrototypeOf(ObjProto, Array.prototype) throws a TypeError"); | ||
|
||
assert.throws(TypeError, function() { | ||
Object.setPrototypeOf(ObjProto, null); | ||
}, "Object.setPrototypeOf(ObjProto, null) throws a TypeError"); | ||
|
||
assert.sameValue( | ||
Reflect.setPrototypeOf(ObjProto, {}), | ||
false, | ||
"Reflect.setPrototypeOf(ObjProto, {}) returns false" | ||
); | ||
|
||
assert.sameValue( | ||
Reflect.setPrototypeOf(ObjProto, Array.prototype), | ||
false, | ||
"Reflect.setPrototypeOf(ObjProto, Array.prototype) returns false" | ||
); | ||
|
||
assert.sameValue( | ||
Reflect.setPrototypeOf(ObjProto, null), | ||
false, | ||
"Reflect.setPrototypeOf(ObjProto, null) returns false" | ||
); |
39 changes: 39 additions & 0 deletions
39
test/built-ins/Object/prototype/setPrototypeOf-with-same-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) 2016 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
id: sec-immutable-prototype-exotic-objects-setprototypeof-v | ||
description: > | ||
Object.prototype's [[SetPrototypeOf]] returns true if value is same | ||
info: > | ||
9.4.7.1 [[SetPrototypeOf]] (V) | ||
... | ||
2. Let current be the value of the [[Prototype]] internal slot of O. | ||
3. If SameValue(V, current), return true. | ||
4. Return false. | ||
features: [Reflect.setPrototypeOf] | ||
---*/ | ||
|
||
var ObjProto = Object.prototype; | ||
|
||
assert.sameValue( | ||
Object.setPrototypeOf(ObjProto, ObjProto), | ||
ObjProto, | ||
"Object.setPrototypeOf(ObjProto, ObjProto) returns the Object.prototype" | ||
); | ||
|
||
assert( | ||
Object.isExtensible(ObjProto), | ||
"Object.prototype is still extensible after a setPrototypeOf operation - #1" | ||
); | ||
|
||
assert.sameValue( | ||
Reflect.setPrototypeOf(ObjProto, ObjProto), | ||
true, | ||
"Reflect.setPrototypeOf(ObjProto, ObjProto) returns true" | ||
); | ||
|
||
assert( | ||
Object.isExtensible(ObjProto), | ||
"Object.prototype is still extensible after a setPrototypeOf operation - #2" | ||
); |