Add more tests for Object.prototype.[[SetPrototypeOf]] (#4446)

This commit is contained in:
ExE Boss 2025-04-18 01:04:35 +02:00 committed by GitHub
parent 8da5438d7a
commit 5b7101ae71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// Copyright (C) 2025 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-immutable-prototype-exotic-objects-setprototypeof-v
description: >
Object.prototype's [[SetPrototypeOf]] returns false even in cases where
OrdinarySetPrototypeOf(O, V) would return true
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.
19.1.3 Properties of the Object Prototype Object
The value of the [[Prototype]] internal slot of the Object prototype object is
null and the initial value of the [[Extensible]] internal slot is true.
features: [Reflect.setPrototypeOf]
---*/
var ObjProto = Object.prototype;
assert.throws(TypeError, function() {
Object.setPrototypeOf(ObjProto, { __proto__: null });
}, "Object.setPrototypeOf(ObjProto, { __proto__: null }) throws a TypeError");
assert.sameValue(
Reflect.setPrototypeOf(ObjProto, { __proto__: null }),
false,
"Reflect.setPrototypeOf(ObjProto, { __proto__: null }) returns false"
);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2025 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-immutable-prototype-exotic-objects-setprototypeof-v
description: >
Object.prototype's [[SetPrototypeOf]] returns false even in cases where
OrdinarySetPrototypeOf(O, V) would return true
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.
19.1.3 Properties of the Object Prototype Object
The value of the [[Prototype]] internal slot of the Object prototype object is
null and the initial value of the [[Extensible]] internal slot is true.
features: [Reflect.setPrototypeOf]
---*/
var ObjProto = Object.prototype;
assert.throws(TypeError, function() {
Object.setPrototypeOf(ObjProto, Object.create(null));
}, "Object.setPrototypeOf(ObjProto, Object.create(null)) throws a TypeError");
assert.sameValue(
Reflect.setPrototypeOf(ObjProto, Object.create(null)),
false,
"Reflect.setPrototypeOf(ObjProto, Object.create(null)) returns false"
);