From 5b7101ae713cd2a3a69189b8b06eca3d277018bb Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Fri, 18 Apr 2025 01:04:35 +0200 Subject: [PATCH] =?UTF-8?q?Add=C2=A0more=C2=A0tests=20for=C2=A0`Object.pro?= =?UTF-8?q?totype.[[SetPrototypeOf]]`=20(#4446)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...peOf-with-non-circular-values-__proto__.js | 33 +++++++++++++++++++ ...setPrototypeOf-with-non-circular-values.js | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js create mode 100644 test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js diff --git a/test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js b/test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js new file mode 100644 index 0000000000..8f8b690202 --- /dev/null +++ b/test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js @@ -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" +); diff --git a/test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js b/test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js new file mode 100644 index 0000000000..279d5ab6da --- /dev/null +++ b/test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js @@ -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" +);