Skip to content

Commit

Permalink
Add tests for [[SetPrototypeOf]] on Object.prototype
Browse files Browse the repository at this point in the history
Object.prototype is the immutable prototype exotic object

Ref tc39/ecma262#308
  • Loading branch information
leobalter committed Feb 11, 2016
1 parent 5cb97c2 commit a6f6d17
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
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 test/built-ins/Object/prototype/setPrototypeOf-with-same-value.js
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"
);

0 comments on commit a6f6d17

Please sign in to comment.