1 // ♓🌟 Piscēs ∷ object.test.js
2 // ====================================================================
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
20 } from "./dev-deps.js";
28 getOwnPropertyDescriptor
,
29 getOwnPropertyDescriptors
,
31 getOwnPropertyStrings
,
32 getOwnPropertySymbols
,
58 describe("LazyLoader", () => {
59 const symbol
= Symbol("foo");
61 const etaoinMethod
= spy(() => "success");
62 const shrdluMethod
= spy(() => "success");
63 const cmfwypMethod
= spy(() => "success");
64 const vbgkqjMethod
= spy(() => "success");
65 const methodsObject
= Object
.create(
95 xz
fiflffffi: { configurable
: true, enumerable
: false, set(_
) {} },
105 it("[[Call]] throws an error", () => {
106 assertThrows(() => LazyLoader({}));
109 it("[[Construct]] creates a new object which inherits from the correct prototype", () => {
111 Object
.getPrototypeOf(new LazyLoader(methodsObject
)),
116 it("[[Construct]] creates a new object with the desired properties", () => {
118 Reflect
.ownKeys(new LazyLoader(methodsObject
)),
119 ["etaoin", "shrdlu", "cmfwyp", "vbgkqj", "xzfiflffffi", symbol
],
123 it("[[Construct]] creates a new object with configurable properties", () => {
127 for (const key
of Reflect
.ownKeys(ll
)) {
130 Object
.getOwnPropertyDescriptor(ll
, key
).configurable
,
133 }(new LazyLoader(methodsObject
)),
146 it("[[Construct]] creates a new object with the correct enumerability", () => {
150 for (const key
of Reflect
.ownKeys(ll
)) {
153 Object
.getOwnPropertyDescriptor(ll
, key
).enumerable
,
156 }(new LazyLoader(methodsObject
)),
169 it("[[Construct]] creates a new object with defined getters", () => {
173 for (const key
of Reflect
.ownKeys(ll
)) {
176 Object
.getOwnPropertyDescriptor(ll
, key
).get?.name
,
179 }(new LazyLoader(methodsObject
)),
182 etaoin
: "get etaoin",
183 shrdlu
: "get shrdlu",
184 cmfwyp
: "get cmfwyp",
185 vbgkqj
: "get vbgkqj",
186 xz
fiflffffi: "get xzfiflffffi",
187 [symbol
]: `get [${symbol.description}]`,
192 it("[[Construct]] creates a new object with defined setters for writable properties only", () => {
196 for (const key
of Reflect
.ownKeys(ll
)) {
199 Object
.getOwnPropertyDescriptor(ll
, key
).set?.name
,
202 }(new LazyLoader(methodsObject
)),
210 [symbol
]: `set [${symbol.description}]`,
215 it("[[Construct]] creates a new object with correct getter behaviour", () => {
216 const ll
= new LazyLoader(methodsObject
);
219 Object
.getOwnPropertyDescriptor(ll
, "etaoin"),
227 assertSpyCalls(etaoinMethod
, 1);
228 assertSpyCall(etaoinMethod
, 0, {
235 Object
.getOwnPropertyDescriptor(ll
, "shrdlu"),
243 assertSpyCalls(shrdluMethod
, 1);
244 assertSpyCall(shrdluMethod
, 0, {
251 Object
.getOwnPropertyDescriptor(ll
, "cmfwyp"),
259 assertSpyCalls(cmfwypMethod
, 1);
260 assertSpyCall(cmfwypMethod
, 0, {
267 Object
.getOwnPropertyDescriptor(ll
, "vbgkqj"),
275 assertSpyCalls(vbgkqjMethod
, 1);
276 assertSpyCall(vbgkqjMethod
, 0, {
281 assertThrows(() => ll
.xz
fiflffffi);
282 assertThrows(() => ll
[symbol
]);
285 it("[[Construct]] creates a new object with correct setter behaviour", () => {
286 const ll
= new LazyLoader(methodsObject
);
287 ll
[symbol
] = "success";
289 Object
.getOwnPropertyDescriptor(ll
, symbol
),
299 describe(".length", () => {
300 it("[[Get]] returns the correct length", () => {
301 assertStrictEquals(LazyLoader
.length
, 1);
305 describe(".name", () => {
306 it("[[Get]] returns the correct name", () => {
307 assertStrictEquals(LazyLoader
.name
, "LazyLoader");
312 describe("PropertyDescriptor", () => {
313 it("[[Call]] throws an error", () => {
314 assertThrows(() => PropertyDescriptor({}));
317 it("[[Construct]] creates a new PropertyDescriptor", () => {
319 Object
.getPrototypeOf(new PropertyDescriptor({})),
320 PropertyDescriptor
.prototype,
324 it("[[Construct]] throws for primitives", () => {
325 assertThrows(() => new PropertyDescriptor("failure"));
328 describe(".length", () => {
329 it("[[Get]] returns the correct length", () => {
330 assertStrictEquals(PropertyDescriptor
.length
, 1);
334 describe(".name", () => {
335 it("[[Get]] returns the correct name", () => {
337 PropertyDescriptor
.name
,
338 "PropertyDescriptor",
343 describe("::complete", () => {
344 it("[[Call]] completes a generic descriptor", () => {
346 PropertyDescriptor
.prototype.complete
.call(desc
);
355 it("[[Call]] completes a data descriptor", () => {
356 const desc
= { value
: undefined };
357 PropertyDescriptor
.prototype.complete
.call(desc
);
366 it("[[Call]] completes an accessor descriptor", () => {
367 const desc
= { get: undefined };
368 PropertyDescriptor
.prototype.complete
.call(desc
);
377 describe(".length", () => {
378 it("[[Get]] returns the correct length", () => {
380 PropertyDescriptor
.prototype.complete
.length
,
386 describe(".name", () => {
387 it("[[Get]] returns the correct name", () => {
389 PropertyDescriptor
.prototype.complete
.name
,
396 describe("::isAccessorDescriptor", () => {
397 it("[[Get]] returns false for a generic descriptor", () => {
400 PropertyDescriptor
.prototype,
401 "isAccessorDescriptor",
408 it("[[Get]] returns false for a data descriptor", () => {
411 PropertyDescriptor
.prototype,
412 "isAccessorDescriptor",
413 { value
: undefined },
419 it("[[Get]] returns true for an accessor descriptor", () => {
422 PropertyDescriptor
.prototype,
423 "isAccessorDescriptor",
430 describe("[[GetOwnProperty]].get.length", () => {
431 it("[[Get]] returns the correct length", () => {
433 Object
.getOwnPropertyDescriptor(
434 PropertyDescriptor
.prototype,
435 "isAccessorDescriptor",
442 describe("[[GetOwnProperty]].get.name", () => {
443 it("[[Get]] returns the correct name", () => {
445 Object
.getOwnPropertyDescriptor(
446 PropertyDescriptor
.prototype,
447 "isAccessorDescriptor",
449 "get isAccessorDescriptor",
455 describe("::isDataDescriptor", () => {
456 it("[[Get]] returns false for a generic descriptor", () => {
459 PropertyDescriptor
.prototype,
467 it("[[Get]] returns true for a data descriptor", () => {
470 PropertyDescriptor
.prototype,
472 { value
: undefined },
478 it("[[Get]] returns false for an accessor descriptor", () => {
481 PropertyDescriptor
.prototype,
489 describe("[[GetOwnProperty]].get.length", () => {
490 it("[[Get]] returns the correct length", () => {
492 Object
.getOwnPropertyDescriptor(
493 PropertyDescriptor
.prototype,
501 describe("[[GetOwnProperty]].get.name", () => {
502 it("[[Get]] returns the correct name", () => {
504 Object
.getOwnPropertyDescriptor(
505 PropertyDescriptor
.prototype,
508 "get isDataDescriptor",
514 describe("::isFullyPopulated", () => {
515 it("[[Get]] returns false for a generic descriptor", () => {
518 PropertyDescriptor
.prototype,
526 it("[[Get]] returns false for a non‐fully‐populated data descriptor", () => {
529 PropertyDescriptor
.prototype,
531 { value
: undefined },
537 it("[[Get]] returns true for a fully‐populated data descriptor", () => {
539 Reflect
.get(PropertyDescriptor
.prototype, "isFullyPopulated", {
549 it("[[Get]] returns false for a non‐fully‐populated accessor descriptor", () => {
552 PropertyDescriptor
.prototype,
560 it("[[Get]] returns true for a fully‐populated accessor descriptor", () => {
562 Reflect
.get(PropertyDescriptor
.prototype, "isFullyPopulated", {
572 describe("[[GetOwnProperty]].get.length", () => {
573 it("[[Get]] returns the correct length", () => {
575 Object
.getOwnPropertyDescriptor(
576 PropertyDescriptor
.prototype,
584 describe("[[GetOwnProperty]].get.name", () => {
585 it("[[Get]] returns the correct name", () => {
587 Object
.getOwnPropertyDescriptor(
588 PropertyDescriptor
.prototype,
591 "get isFullyPopulated",
597 describe("::isGenericDescriptor", () => {
598 it("[[Get]] returns true for a generic descriptor", () => {
601 PropertyDescriptor
.prototype,
602 "isGenericDescriptor",
609 it("[[Get]] returns true for a data descriptor", () => {
612 PropertyDescriptor
.prototype,
613 "isGenericDescriptor",
614 { value
: undefined },
620 it("[[Get]] returns false for an accessor descriptor", () => {
623 PropertyDescriptor
.prototype,
624 "isGenericDescriptor",
631 describe("[[GetOwnProperty]].get.length", () => {
632 it("[[Get]] returns the correct length", () => {
634 Object
.getOwnPropertyDescriptor(
635 PropertyDescriptor
.prototype,
636 "isGenericDescriptor",
643 describe("[[GetOwnProperty]].get.name", () => {
644 it("[[Get]] returns the correct name", () => {
646 Object
.getOwnPropertyDescriptor(
647 PropertyDescriptor
.prototype,
648 "isGenericDescriptor",
650 "get isGenericDescriptor",
656 describe("~configurable", () => {
657 it("[[DefineOwnProperty]] coerces to a boolean", () => {
658 const desc
= new PropertyDescriptor({});
659 Object
.defineProperty(desc
, "configurable", {});
660 assertStrictEquals(desc
.configurable
, false);
663 it("[[DefineOwnProperty]] throws for accessor properties", () => {
664 const desc
= new PropertyDescriptor({});
666 Object
.defineProperty(desc
, "configurable", { get: undefined })
670 it("[[Set]] coerces to a boolean", () => {
671 const desc
= new PropertyDescriptor({});
672 desc
.configurable
= undefined;
673 assertStrictEquals(desc
.configurable
, false);
676 it("[[Delete]] works", () => {
677 const desc
= new PropertyDescriptor({ configurable
: false });
678 delete desc
.configurable
;
679 assert(!("configurable" in desc
));
683 describe("~enumerable", () => {
684 it("[[DefineOwnProperty]] coerces to a boolean", () => {
685 const desc
= new PropertyDescriptor({});
686 Object
.defineProperty(desc
, "enumerable", {});
687 assertStrictEquals(desc
.enumerable
, false);
690 it("[[DefineOwnProperty]] throws for accessor properties", () => {
691 const desc
= new PropertyDescriptor({});
693 Object
.defineProperty(desc
, "enumerable", { get: undefined })
697 it("[[Set]] coerces to a boolean", () => {
698 const desc
= new PropertyDescriptor({});
699 desc
.enumerable
= undefined;
700 assertStrictEquals(desc
.enumerable
, false);
703 it("[[Delete]] works", () => {
704 const desc
= new PropertyDescriptor({ enumerable
: false });
705 delete desc
.enumerable
;
706 assert(!("enumerable" in desc
));
710 describe("~get", () => {
711 it("[[DefineOwnProperty]] works", () => {
712 const desc
= new PropertyDescriptor({});
713 Object
.defineProperty(desc
, "get", {});
714 assertStrictEquals(desc
.get, undefined);
717 it("[[DefineOwnProperty]] throws for accessor properties", () => {
718 const desc
= new PropertyDescriptor({});
720 Object
.defineProperty(desc
, "get", { get: undefined })
724 it("[[DefineOwnProperty]] throws if not callable or undefined", () => {
725 const desc
= new PropertyDescriptor({});
727 () => Object
.defineProperty(desc
, "get", { value
: null }),
731 it("[[DefineOwnProperty]] throws if a data property is defined", () => {
732 const desc
= new PropertyDescriptor({ value
: undefined });
733 assertThrows(() => Object
.defineProperty(desc
, "get", {}));
736 it("[[Set]] works", () => {
737 const desc
= new PropertyDescriptor({});
740 assertStrictEquals(desc
.get, fn
);
743 it("[[Set]] throws if not callable or undefined", () => {
744 const desc
= new PropertyDescriptor({});
745 assertThrows(() => desc
.get = null);
748 it("[[Set]] throws if a data property is defined", () => {
749 const desc
= new PropertyDescriptor({ value
: undefined });
750 assertThrows(() => desc
.get = undefined);
753 it("[[Delete]] works", () => {
754 const desc
= new PropertyDescriptor({ get: undefined });
756 assert(!("get" in desc
));
760 describe("~set", () => {
761 it("[[DefineOwnProperty]] works", () => {
762 const desc
= new PropertyDescriptor({});
763 Object
.defineProperty(desc
, "set", {});
764 assertStrictEquals(desc
.set, undefined);
767 it("[[DefineOwnProperty]] throws for accessor properties", () => {
768 const desc
= new PropertyDescriptor({});
770 Object
.defineProperty(desc
, "set", { get: undefined })
774 it("[[DefineOwnProperty]] throws if not callable or undefined", () => {
775 const desc
= new PropertyDescriptor({});
777 () => Object
.defineProperty(desc
, "set", { value
: null }),
781 it("[[DefineOwnProperty]] throws if a data property is defined", () => {
782 const desc
= new PropertyDescriptor({ value
: undefined });
783 assertThrows(() => Object
.defineProperty(desc
, "set", {}));
786 it("[[Set]] works", () => {
787 const desc
= new PropertyDescriptor({});
788 const fn
= (_
) => {};
790 assertStrictEquals(desc
.set, fn
);
793 it("[[Set]] throws if not callable or undefined", () => {
794 const desc
= new PropertyDescriptor({});
795 assertThrows(() => desc
.set = null);
798 it("[[Set]] throws if a data property is defined", () => {
799 const desc
= new PropertyDescriptor({ value
: undefined });
800 assertThrows(() => desc
.set = undefined);
803 it("[[Delete]] works", () => {
804 const desc
= new PropertyDescriptor({ set: undefined });
806 assert(!("set" in desc
));
810 describe("~value", () => {
811 it("[[DefineOwnProperty]] works", () => {
812 const desc
= new PropertyDescriptor({});
813 Object
.defineProperty(desc
, "value", {});
814 assertStrictEquals(desc
.value
, undefined);
817 it("[[DefineOwnProperty]] throws for accessor properties", () => {
818 const desc
= new PropertyDescriptor({});
820 Object
.defineProperty(desc
, "value", { get: undefined })
824 it("[[DefineOwnProperty]] throws if an accessor property is defined", () => {
825 const desc
= new PropertyDescriptor({ get: undefined });
826 assertThrows(() => Object
.defineProperty(desc
, "value", {}));
829 it("[[Set]] works", () => {
830 const desc
= new PropertyDescriptor({});
831 desc
.value
= "success";
832 assertStrictEquals(desc
.value
, "success");
835 it("[[Set]] throws if an accessor property is defined", () => {
836 const desc
= new PropertyDescriptor({ get: undefined });
837 assertThrows(() => desc
.value
= null);
840 it("[[Delete]] works", () => {
841 const desc
= new PropertyDescriptor({ value
: undefined });
843 assert(!("value" in desc
));
847 describe("~writable", () => {
848 it("[[DefineOwnProperty]] coerces to a boolean", () => {
849 const desc
= new PropertyDescriptor({});
850 Object
.defineProperty(desc
, "writable", {});
851 assertStrictEquals(desc
.writable
, false);
854 it("[[DefineOwnProperty]] throws for accessor properties", () => {
855 const desc
= new PropertyDescriptor({});
857 Object
.defineProperty(desc
, "writable", { get: undefined })
861 it("[[DefineOwnProperty]] throws if an accessor property is defined", () => {
862 const desc
= new PropertyDescriptor({ get: undefined });
863 assertThrows(() => Object
.defineProperty(desc
, "writable", {}));
866 it("[[Set]] coerces to a boolean", () => {
867 const desc
= new PropertyDescriptor({});
868 desc
.writable
= undefined;
869 assertStrictEquals(desc
.writable
, false);
872 it("[[Set]] throws if an accessor property is defined", () => {
873 const desc
= new PropertyDescriptor({ get: undefined });
874 assertThrows(() => desc
.writable
= false);
877 it("[[Delete]] works", () => {
878 const desc
= new PropertyDescriptor({ writable
: false });
879 delete desc
.writable
;
880 assert(!("writable" in desc
));
885 describe("defineOwnProperty", () => {
886 it("[[Call]] defines the property", () => {
888 defineOwnProperty(obj
, "etaoin", {});
889 assert("etaoin" in obj
);
892 it("[[Call]] returns the provided object", () => {
894 assertStrictEquals(defineOwnProperty(obj
, "etaoin", {}), obj
);
897 it("[[Construct]] throws an error", () => {
898 assertThrows(() => new defineOwnProperty(obj
, "etaoin", {}));
901 describe(".length", () => {
902 it("[[Get]] returns the correct length", () => {
903 assertStrictEquals(defineOwnProperty
.length
, 3);
907 describe(".name", () => {
908 it("[[Get]] returns the correct name", () => {
910 defineOwnProperty
.name
,
917 describe("defineOwnProperties", () => {
918 it("[[Call]] defines properties from the provided objects", () => {
920 defineOwnProperties(obj
, {
924 assert("etaoin" in obj
);
925 assert("shrdlu" in obj
);
926 assert("cmfwyp" in obj
);
929 it("[[Call]] overrides earlier declarations with later ones", () => {
930 const obj
= { etaoin
: undefined };
931 defineOwnProperties(obj
, {
932 etaoin
: { value
: "failure" },
934 etaoin
: { value
: "success" },
936 assertStrictEquals(obj
.etaoin
, "success");
939 it("[[Call]] returns the provided object", () => {
941 assertStrictEquals(defineOwnProperties(obj
), obj
);
944 it("[[Construct]] throws an error", () => {
945 assertThrows(() => new defineOwnProperties({}));
948 describe(".length", () => {
949 it("[[Get]] returns the correct length", () => {
950 assertStrictEquals(defineOwnProperties
.length
, 1);
954 describe(".name", () => {
955 it("[[Get]] returns the correct name", () => {
957 defineOwnProperties
.name
,
958 "defineOwnProperties",
964 describe("deleteOwnProperty", () => {
965 it("[[Call]] deletes the provided property on the provided object", () => {
966 const obj
= { failure
: undefined };
967 deleteOwnProperty(obj
, "failure");
968 assert(!("failure" in obj
));
971 it("[[Call]] does nothing if the property doesn’t exist", () => {
972 const obj
= Object
.freeze({});
973 deleteOwnProperty(obj
, "failure");
974 assert(!("failure" in obj
));
977 it("[[Call]] throws if the property can’t be deleted", () => {
978 const obj
= Object
.seal({ failure
: undefined });
979 assertThrows(() => deleteOwnProperty(obj
, "failure"));
982 it("[[Call]] returns the provided object", () => {
984 assertStrictEquals(deleteOwnProperty(obj
, ""), obj
);
987 it("[[Construct]] throws an error", () => {
988 assertThrows(() => new deleteOwnProperty({}, ""));
991 describe(".length", () => {
992 it("[[Get]] returns the correct length", () => {
993 assertStrictEquals(deleteOwnProperty
.length
, 2);
997 describe(".name", () => {
998 it("[[Get]] returns the correct name", () => {
999 assertStrictEquals(deleteOwnProperty
.name
, "deleteOwnProperty");
1004 describe("freeze", () => {
1005 it("[[Call]] freezes the object", () => {
1008 assert(Object
.isFrozen(obj
));
1011 it("[[Call]] returns the provided object", () => {
1013 assertStrictEquals(freeze(obj
), obj
);
1016 it("[[Construct]] throws an error", () => {
1017 assertThrows(() => new freeze({}));
1020 describe(".length", () => {
1021 it("[[Get]] returns the correct length", () => {
1022 assertStrictEquals(freeze
.length
, 1);
1026 describe(".name", () => {
1027 it("[[Get]] returns the correct name", () => {
1028 assertStrictEquals(freeze
.name
, "freeze");
1033 describe("frozenCopy", () => {
1034 it("[[Call]] returns a frozen object", () => {
1037 frozenCopy(Object
.create(null), {
1054 it("[[Call]] ignores non·enumerable properties", () => {
1057 Object
.create(null, {
1058 data
: { value
: undefined },
1059 accessor
: { get: undefined },
1066 it("[[Call]] preserves accessor properties", () => {
1067 const properties
= {
1069 configurable
: false,
1075 configurable
: false,
1081 configurable
: false,
1087 configurable
: false,
1094 Object
.getOwnPropertyDescriptors(
1095 frozenCopy(Object
.create(null, properties
)),
1101 it("[[Call]] does not copy properties on the prototype", () => {
1104 frozenCopy(Object
.create({ failure
: undefined }), {
1110 accessor
: { configurable
: true, get: undefined },
1115 it("[[Call]] uses the species of the constructor", () => {
1116 const species
= { prototype: {} };
1118 Object
.getPrototypeOf(
1119 frozenCopy({}, { [Symbol
.species
]: species
}),
1125 it("[[Call]] uses constructor if no species is defined", () => {
1126 const constructor = { [Symbol
.species
]: null, prototype: {} };
1128 Object
.getPrototypeOf(frozenCopy({}, constructor)),
1129 constructor.prototype,
1133 it("[[Call]] uses the constructor on the object if none is provided", () => {
1134 const constructor = { [Symbol
.species
]: null, prototype: {} };
1136 Object
.getPrototypeOf(frozenCopy({ constructor })),
1137 constructor.prototype,
1141 it("[[Call]] allows a null constructor", () => {
1143 Object
.getPrototypeOf(frozenCopy({}, null)),
1148 it("[[Construct]] throws an error", () => {
1149 assertThrows(() => new frozenCopy({}));
1152 describe(".length", () => {
1153 it("[[Get]] returns the correct length", () => {
1154 assertStrictEquals(frozenCopy
.length
, 1);
1158 describe(".name", () => {
1159 it("[[Get]] returns the correct name", () => {
1160 assertStrictEquals(frozenCopy
.name
, "frozenCopy");
1165 describe("getMethod", () => {
1166 it("[[Call]] gets a method", () => {
1167 const method
= () => {};
1168 assertStrictEquals(getMethod({ method
}, "method"), method
);
1171 it("[[Call]] works for values coercible to objects", () => {
1172 assertEquals(getMethod("", "toString"), String
.prototype.toString
);
1175 it("[[Call]] throws for null and undefined", () => {
1176 assertThrows(() => getMethod(null, "valueOf"));
1177 assertThrows(() => getMethod(undefined, "valueOf"));
1180 it("[[Call]] throws if the resulting value isn’t callable", () => {
1181 assertThrows(() => getMethod({ "failure": true }, "failure"));
1184 it("[[Construct]] throws an error", () => {
1185 assertThrows(() => new getMethod({ method() {} }, "method"));
1188 describe(".length", () => {
1189 it("[[Get]] returns the correct length", () => {
1190 assertStrictEquals(getMethod
.length
, 2);
1194 describe(".name", () => {
1195 it("[[Get]] returns the correct name", () => {
1196 assertStrictEquals(getMethod
.name
, "getMethod");
1201 describe("getOwnPropertyDescriptor", () => {
1202 it("[[Call]] gets the descriptor", () => {
1204 getOwnPropertyDescriptor({ success
: true }, "success"),
1214 it("[[Call]] returns undefined for non‐own properties", () => {
1216 getOwnPropertyDescriptor({}, "valueOf"),
1221 it("[[Construct]] throws an error", () => {
1222 assertThrows(() => new getOwnPropertyDescriptor({}, ""));
1225 describe(".length", () => {
1226 it("[[Get]] returns the correct length", () => {
1227 assertStrictEquals(getOwnPropertyDescriptor
.length
, 2);
1231 describe(".name", () => {
1232 it("[[Get]] returns the correct name", () => {
1234 getOwnPropertyDescriptor
.name
,
1235 "getOwnPropertyDescriptor",
1241 describe("getOwnPropertyDescriptors", () => {
1242 it("[[Call]] gets the descriptors", () => {
1244 getOwnPropertyDescriptors({ success
: true, etaoin
: "shrdlu" }),
1262 it("[[Construct]] throws an error", () => {
1263 assertThrows(() => new getOwnPropertyDescriptors({}));
1266 describe(".length", () => {
1267 it("[[Get]] returns the correct length", () => {
1268 assertStrictEquals(getOwnPropertyDescriptors
.length
, 1);
1272 describe(".name", () => {
1273 it("[[Get]] returns the correct name", () => {
1275 getOwnPropertyDescriptors
.name
,
1276 "getOwnPropertyDescriptors",
1282 describe("getOwnPropertyKeys", () => {
1283 it("[[Call]] gets own (but not inherited) property keys", () => {
1284 assertEquals(getOwnPropertyKeys({ success
: true }), ["success"]);
1287 it("[[Call]] works for values coercible to objects", () => {
1288 assertEquals(getOwnPropertyKeys("foo"), ["0", "1", "2", "length"]);
1291 it("[[Call]] throws for null and undefined", () => {
1292 assertThrows(() => getOwnPropertyKeys(null));
1293 assertThrows(() => getOwnPropertyKeys(undefined));
1296 it("[[Construct]] throws an error", () => {
1297 assertThrows(() => new getOwnPropertyKeys({}));
1300 describe(".length", () => {
1301 it("[[Get]] returns the correct length", () => {
1302 assertStrictEquals(getOwnPropertyKeys
.length
, 1);
1306 describe(".name", () => {
1307 it("[[Get]] returns the correct name", () => {
1309 getOwnPropertyKeys
.name
,
1310 "getOwnPropertyKeys",
1316 describe("getOwnPropertyStrings", () => {
1317 it("[[Call]] gets own string keys", () => {
1318 assertEquals(getOwnPropertyStrings({ success
: true }), [
1323 it("[[Call]] works for values coercible to objects", () => {
1324 assertEquals(getOwnPropertyStrings("foo"), [
1332 it("[[Call]] throws for null and undefined", () => {
1333 assertThrows(() => getOwnPropertyStrings(null));
1334 assertThrows(() => getOwnPropertyStrings(undefined));
1337 it("[[Construct]] throws an error", () => {
1338 assertThrows(() => new getOwnPropertyStrings({}));
1341 describe(".length", () => {
1342 it("[[Get]] returns the correct length", () => {
1343 assertStrictEquals(getOwnPropertyStrings
.length
, 1);
1347 describe(".name", () => {
1348 it("[[Get]] returns the correct name", () => {
1350 getOwnPropertyStrings
.name
,
1351 "getOwnPropertyStrings",
1357 describe("getOwnPropertySymbols", () => {
1358 it("[[Call]] gets own symbol keys", () => {
1359 const sym
= Symbol();
1360 assertEquals(getOwnPropertySymbols({ [sym
]: true }), [sym
]);
1363 it("[[Call]] works for values coercible to objects", () => {
1364 assertEquals(getOwnPropertySymbols("foo"), []);
1367 it("[[Call]] throws for null and undefined", () => {
1368 assertThrows(() => getOwnPropertySymbols(null));
1369 assertThrows(() => getOwnPropertySymbols(undefined));
1372 it("[[Construct]] throws an error", () => {
1373 assertThrows(() => new getOwnPropertySymbols({}));
1376 describe(".length", () => {
1377 it("[[Get]] returns the correct length", () => {
1378 assertStrictEquals(getOwnPropertySymbols
.length
, 1);
1382 describe(".name", () => {
1383 it("[[Get]] returns the correct name", () => {
1385 getOwnPropertySymbols
.name
,
1386 "getOwnPropertySymbols",
1392 describe("getPropertyValue", () => {
1393 it("[[Call]] gets property values on the provided object", () => {
1395 getPropertyValue({ success
: true }, "success"),
1400 it("[[Call]] works for values coercible to objects", () => {
1402 getPropertyValue("", "toString"),
1403 String
.prototype.toString
,
1407 it("[[Call]] throws for null and undefined", () => {
1408 assertThrows(() => getPropertyValue(null, "valueOf"));
1409 assertThrows(() => getPropertyValue(undefined, "valueOf"));
1412 it("[[Construct]] throws an error", () => {
1413 assertThrows(() => new getPropertyValue({}, "valueOf"));
1416 describe(".length", () => {
1417 it("[[Get]] returns the correct length", () => {
1418 assertStrictEquals(getPropertyValue
.length
, 2);
1422 describe(".name", () => {
1423 it("[[Get]] returns the correct name", () => {
1424 assertStrictEquals(getPropertyValue
.name
, "getPropertyValue");
1429 describe("getPrototype", () => {
1430 it("[[Call]] gets object prototypes", () => {
1431 assertStrictEquals(getPrototype({}), Object
.prototype);
1433 assertStrictEquals(getPrototype(Object
.create(proto
)), proto
);
1436 it("[[Call]] gets null prototypes", () => {
1437 assertStrictEquals(getPrototype(Object
.create(null)), null);
1440 it("[[Call]] gets prototypes for coercible primitives", () => {
1441 assertStrictEquals(getPrototype(1), Number
.prototype);
1442 assertStrictEquals(getPrototype(Symbol()), Symbol
.prototype);
1445 it("[[Call]] throws for null and undefined", () => {
1446 assertThrows(() => getPrototype(null));
1447 assertThrows(() => getPrototype(undefined));
1450 it("[[Construct]] throws an error", () => {
1451 assertThrows(() => new getPrototype({}));
1454 describe(".length", () => {
1455 it("[[Get]] returns the correct length", () => {
1456 assertStrictEquals(getPrototype
.length
, 1);
1460 describe(".name", () => {
1461 it("[[Get]] returns the correct name", () => {
1462 assertStrictEquals(getPrototype
.name
, "getPrototype");
1467 describe("hasProperty", () => {
1468 it("[[Call]] gets whether a property exists on the provided object", () => {
1470 hasProperty({ success
: "etaoin" }, "success"),
1473 assertStrictEquals(hasProperty({}, "hasOwnProperty"), true);
1476 it("[[Call]] works for values coercible to objects", () => {
1477 assertStrictEquals(hasProperty("", "length"), true);
1478 assertStrictEquals(hasProperty("", "toString"), true);
1481 it("[[Call]] throws for null and undefined", () => {
1482 assertThrows(() => hasProperty(null, "valueOf"));
1483 assertThrows(() => hasProperty(undefined, "valueOf"));
1486 it("[[Construct]] throws an error", () => {
1487 assertThrows(() => new hasProperty({}, "valueOf"));
1490 describe(".length", () => {
1491 it("[[Get]] returns the correct length", () => {
1492 assertStrictEquals(hasProperty
.length
, 2);
1496 describe(".name", () => {
1497 it("[[Get]] returns the correct name", () => {
1498 assertStrictEquals(hasProperty
.name
, "hasProperty");
1503 describe("hasOwnProperty", () => {
1504 it("[[Call]] gets whether an own property exists on the provided object", () => {
1506 hasOwnProperty({ success
: "etaoin" }, "success"),
1509 assertStrictEquals(hasOwnProperty({}, "hasOwnProperty"), false);
1512 it("[[Call]] works for values coercible to objects", () => {
1513 assertStrictEquals(hasOwnProperty("", "length"), true);
1514 assertStrictEquals(hasOwnProperty("", "toString"), false);
1517 it("[[Call]] throws for null and undefined", () => {
1518 assertThrows(() => hasOwnProperty(null, "valueOf"));
1519 assertThrows(() => hasOwnProperty(undefined, "valueOf"));
1522 it("[[Construct]] throws an error", () => {
1523 assertThrows(() => new hasOwnProperty({}, "valueOf"));
1526 describe(".length", () => {
1527 it("[[Get]] returns the correct length", () => {
1528 assertStrictEquals(hasOwnProperty
.length
, 2);
1532 describe(".name", () => {
1533 it("[[Get]] returns the correct name", () => {
1534 assertStrictEquals(hasOwnProperty
.name
, "hasOwnProperty");
1539 describe("isArraylikeObject", () => {
1540 it("[[Call]] returns false for primitives", () => {
1541 assertStrictEquals(isArraylikeObject("failure"), false);
1544 it("[[Call]] returns false if length throws", () => {
1555 it("[[Call]] returns false if length is not a number and cannot be converted to one", () => {
1556 assertStrictEquals(isArraylikeObject({ length
: 1n
}), false);
1559 it("[[Call]] returns true if length is convertable to a number", () => {
1560 assertStrictEquals(isArraylikeObject({ length
: -0 }), true);
1561 assertStrictEquals(isArraylikeObject({ length
: 1 }), true);
1562 assertStrictEquals(isArraylikeObject({ length
: -1.25 }), true);
1564 isArraylikeObject({ length
: 9007199254740992 }),
1567 assertStrictEquals(isArraylikeObject({ length
: Infinity
}), true);
1568 assertStrictEquals(isArraylikeObject({ length
: "success" }), true);
1571 it("[[Construct]] throws an error", () => {
1572 assertThrows(() => new isArraylikeObject({}));
1575 describe(".length", () => {
1576 it("[[Get]] returns the correct length", () => {
1577 assertStrictEquals(isArraylikeObject
.length
, 1);
1581 describe(".name", () => {
1582 it("[[Get]] returns the correct name", () => {
1584 isArraylikeObject
.name
,
1585 "isArraylikeObject",
1591 describe("isExtensibleObject", () => {
1592 it("[[Call]] returns true for extensible objects", () => {
1593 assertStrictEquals(isExtensibleObject({}), true);
1596 it("[[Call]] returns false for coercible primitives", () => {
1597 assertStrictEquals(isExtensibleObject(1), false);
1598 assertStrictEquals(isExtensibleObject(Symbol()), false);
1601 it("[[Call]] returns false for non·extensible objects", () => {
1603 isExtensibleObject(Object
.preventExtensions({})),
1608 it("[[Call]] returns false for null and undefined", () => {
1609 assertStrictEquals(isExtensibleObject(null), false);
1610 assertStrictEquals(isExtensibleObject(undefined), false);
1613 it("[[Construct]] throws an error", () => {
1614 assertThrows(() => new isExtensibleObject({}));
1617 describe(".length", () => {
1618 it("[[Get]] returns the correct length", () => {
1619 assertStrictEquals(isExtensibleObject
.length
, 1);
1623 describe(".name", () => {
1624 it("[[Get]] returns the correct name", () => {
1626 isExtensibleObject
.name
,
1627 "isExtensibleObject",
1633 describe("isUnfrozenObject", () => {
1634 it("[[Call]] returns true for unfrozen objects", () => {
1635 assertStrictEquals(isUnfrozenObject({}), true);
1638 it("[[Call]] returns false for coercible primitives", () => {
1639 assertStrictEquals(isUnfrozenObject(1), false);
1640 assertStrictEquals(isUnfrozenObject(Symbol()), false);
1643 it("[[Call]] returns false for frozen objects", () => {
1644 assertStrictEquals(isUnfrozenObject(Object
.freeze({})), false);
1647 it("[[Call]] returns false for null and undefined", () => {
1648 assertStrictEquals(isUnfrozenObject(null), false);
1649 assertStrictEquals(isUnfrozenObject(undefined), false);
1652 it("[[Construct]] throws an error", () => {
1653 assertThrows(() => new isUnfrozenObject({}));
1656 describe(".length", () => {
1657 it("[[Get]] returns the correct length", () => {
1658 assertStrictEquals(isUnfrozenObject
.length
, 1);
1662 describe(".name", () => {
1663 it("[[Get]] returns the correct name", () => {
1664 assertStrictEquals(isUnfrozenObject
.name
, "isUnfrozenObject");
1669 describe("isUnsealedObject", () => {
1670 it("[[Call]] returns true for unsealed objects", () => {
1671 assertStrictEquals(isUnsealedObject({}), true);
1674 it("[[Call]] returns false for coercible primitives", () => {
1675 assertStrictEquals(isUnsealedObject(1), false);
1676 assertStrictEquals(isUnsealedObject(Symbol()), false);
1679 it("[[Call]] returns false for sealed objects", () => {
1680 assertStrictEquals(isUnsealedObject(Object
.seal({})), false);
1683 it("[[Call]] returns false for null and undefined", () => {
1684 assertStrictEquals(isUnsealedObject(null), false);
1685 assertStrictEquals(isUnsealedObject(undefined), false);
1688 it("[[Construct]] throws an error", () => {
1689 assertThrows(() => new isUnsealedObject({}));
1692 describe(".length", () => {
1693 it("[[Get]] returns the correct length", () => {
1694 assertStrictEquals(isUnsealedObject
.length
, 1);
1698 describe(".name", () => {
1699 it("[[Get]] returns the correct name", () => {
1700 assertStrictEquals(isUnsealedObject
.name
, "isUnsealedObject");
1705 describe("lengthOfArraylike", () => {
1706 it("[[Call]] returns the length", () => {
1708 lengthOfArraylike({ length
: 9007199254740991 }),
1713 it("[[Call]] returns a non·nan result", () => {
1714 assertStrictEquals(lengthOfArraylike({ length
: NaN
}), 0);
1715 assertStrictEquals(lengthOfArraylike({ length
: "failure" }), 0);
1718 it("[[Call]] returns an integral result", () => {
1719 assertStrictEquals(lengthOfArraylike({ length
: 0.25 }), 0);
1720 assertStrictEquals(lengthOfArraylike({ length
: 1.1 }), 1);
1723 it("[[Call]] returns a result greater than or equal to zero", () => {
1724 assertStrictEquals(lengthOfArraylike({ length
: -0 }), 0);
1725 assertStrictEquals(lengthOfArraylike({ length
: -1 }), 0);
1726 assertStrictEquals(lengthOfArraylike({ length
: -Infinity
}), 0);
1729 it("[[Call]] returns a result less than 2 ** 53", () => {
1731 lengthOfArraylike({ length
: 9007199254740992 }),
1735 lengthOfArraylike({ length
: Infinity
}),
1740 it("[[Call]] does not require an object argument", () => {
1741 assertStrictEquals(lengthOfArraylike("string"), 6);
1742 assertStrictEquals(lengthOfArraylike(Symbol()), 0);
1745 it("[[Construct]] throws an error", () => {
1746 assertThrows(() => new lengthOfArraylike(""));
1749 describe(".length", () => {
1750 it("[[Get]] returns the correct length", () => {
1751 assertStrictEquals(lengthOfArraylike
.length
, 1);
1755 describe(".name", () => {
1756 it("[[Get]] returns the correct name", () => {
1757 assertStrictEquals(lengthOfArraylike
.name
, "lengthOfArraylike");
1762 describe("namedEntries", () => {
1763 it("[[Call]] gets named entries", () => {
1764 assertEquals(namedEntries({ success
: true }), [["success", true]]);
1767 it("[[Call]] works for values coercible to objects", () => {
1768 assertEquals(namedEntries("foo"), [
1775 it("[[Call]] throws for null and undefined", () => {
1776 assertThrows(() => namedEntries(null));
1777 assertThrows(() => namedEntries(undefined));
1780 it("[[Construct]] throws an error", () => {
1781 assertThrows(() => new namedEntries({}));
1784 describe(".length", () => {
1785 it("[[Get]] returns the correct length", () => {
1786 assertStrictEquals(namedEntries
.length
, 1);
1790 describe(".name", () => {
1791 it("[[Get]] returns the correct name", () => {
1792 assertStrictEquals(namedEntries
.name
, "namedEntries");
1797 describe("namedKeys", () => {
1798 it("[[Call]] gets named keys", () => {
1799 assertEquals(namedKeys({ success
: true }), ["success"]);
1802 it("[[Call]] works for values coercible to objects", () => {
1803 assertEquals(namedKeys("foo"), [
1810 it("[[Call]] throws for null and undefined", () => {
1811 assertThrows(() => namedKeys(null));
1812 assertThrows(() => namedKeys(undefined));
1815 it("[[Construct]] throws an error", () => {
1816 assertThrows(() => new namedKeys({}));
1819 describe(".length", () => {
1820 it("[[Get]] returns the correct length", () => {
1821 assertStrictEquals(namedKeys
.length
, 1);
1825 describe(".name", () => {
1826 it("[[Get]] returns the correct name", () => {
1827 assertStrictEquals(namedKeys
.name
, "namedKeys");
1832 describe("namedValues", () => {
1833 it("[[Call]] gets named values", () => {
1834 assertEquals(namedValues({ success
: true }), [true]);
1837 it("[[Call]] works for values coercible to objects", () => {
1838 assertEquals(namedValues("foo"), [
1845 it("[[Call]] throws for null and undefined", () => {
1846 assertThrows(() => namedValues(null));
1847 assertThrows(() => namedValues(undefined));
1850 it("[[Construct]] throws an error", () => {
1851 assertThrows(() => new namedValues({}));
1854 describe(".length", () => {
1855 it("[[Get]] returns the correct length", () => {
1856 assertStrictEquals(namedValues
.length
, 1);
1860 describe(".name", () => {
1861 it("[[Get]] returns the correct name", () => {
1862 assertStrictEquals(namedValues
.name
, "namedValues");
1867 describe("objectCreate", () => {
1868 it("[[Call]] creates an object", () => {
1869 const obj
= objectCreate(null);
1870 assertStrictEquals(Object(obj
), obj
);
1873 it("[[Call]] correctly sets the prototype", () => {
1876 Object
.getPrototypeOf(objectCreate(proto
)),
1880 Object
.getPrototypeOf(objectCreate(null)),
1885 it("[[Call]] correctly sets own properties", () => {
1887 Object
.getOwnPropertyDescriptors(
1888 objectCreate(null, { success
: { value
: true } }),
1892 configurable
: false,
1901 it("[[Call]] throws for coercible primitives", () => {
1902 assertThrows(() => objectCreate(1));
1903 assertThrows(() => objectCreate(Symbol()));
1906 it("[[Call]] throws for undefined", () => {
1907 assertThrows(() => objectCreate(undefined));
1910 it("[[Construct]] throws an error", () => {
1911 assertThrows(() => new objectCreate({}));
1914 describe(".length", () => {
1915 it("[[Get]] returns the correct length", () => {
1916 assertStrictEquals(objectCreate
.length
, 2);
1920 describe(".name", () => {
1921 it("[[Get]] returns the correct name", () => {
1922 assertStrictEquals(objectCreate
.name
, "objectCreate");
1927 describe("objectFromEntries", () => {
1928 it("[[Call]] creates an object", () => {
1929 const obj
= objectFromEntries([]);
1930 assertStrictEquals(Object(obj
), obj
);
1933 it("[[Call]] correctly sets the prototype", () => {
1935 Object
.getPrototypeOf(objectFromEntries([])),
1940 it("[[Call]] correctly sets own properties", () => {
1942 Object
.entries(objectFromEntries([["success", true]])),
1943 [["success", true]],
1947 it("[[Call]] throws if the argument is not a nested arraylike", () => {
1948 assertThrows(() => objectFromEntries(1));
1949 assertThrows(() => objectFromEntries(Symbol()));
1950 assertThrows(() => objectFromEntries(null));
1951 assertThrows(() => objectFromEntries(undefined));
1952 assertThrows(() => objectFromEntries({}));
1953 assertThrows(() => objectFromEntries([undefined]));
1956 it("[[Construct]] throws an error", () => {
1957 assertThrows(() => new objectFromEntries([]));
1960 describe(".length", () => {
1961 it("[[Get]] returns the correct length", () => {
1962 assertStrictEquals(objectFromEntries
.length
, 1);
1966 describe(".name", () => {
1967 it("[[Get]] returns the correct name", () => {
1968 assertStrictEquals(objectFromEntries
.name
, "objectFromEntries");
1973 describe("preventExtensions", () => {
1974 it("[[Call]] prevents extensions on the object", () => {
1976 preventExtensions(obj
);
1977 assert(!Object
.isExtensible(obj
));
1980 it("[[Call]] returns the provided object", () => {
1982 assertStrictEquals(preventExtensions(obj
), obj
);
1985 it("[[Construct]] throws an error", () => {
1986 assertThrows(() => new preventExtensions({}));
1989 describe(".length", () => {
1990 it("[[Get]] returns the correct length", () => {
1991 assertStrictEquals(preventExtensions
.length
, 1);
1995 describe(".name", () => {
1996 it("[[Get]] returns the correct name", () => {
1997 assertStrictEquals(preventExtensions
.name
, "preventExtensions");
2002 describe("seal", () => {
2003 it("[[Call]] seals the object", () => {
2006 assert(Object
.isSealed(obj
));
2009 it("[[Call]] returns the provided object", () => {
2011 assertStrictEquals(seal(obj
), obj
);
2014 it("[[Construct]] throws an error", () => {
2015 assertThrows(() => new seal({}));
2018 describe(".length", () => {
2019 it("[[Get]] returns the correct length", () => {
2020 assertStrictEquals(seal
.length
, 1);
2024 describe(".name", () => {
2025 it("[[Get]] returns the correct name", () => {
2026 assertStrictEquals(seal
.name
, "seal");
2031 describe("setPropertyValue", () => {
2032 it("[[Call]] sets the provided property on the provided object", () => {
2034 setPropertyValue(obj
, "success", true);
2035 assertStrictEquals(obj
.success
, true);
2038 it("[[Call]] calls setters", () => {
2039 const setter
= spy((_
) => {});
2040 const obj
= Object
.create(null, { success
: { set: setter
} });
2041 setPropertyValue(obj
, "success", true);
2042 assertSpyCalls(setter
, 1);
2043 assertSpyCall(setter
, 0, {
2049 it("[[Call]] walks the prototype chain", () => {
2050 const setter
= spy((_
) => {});
2051 const obj
= Object
.create(
2052 Object
.create(null, { success
: { set: setter
} }),
2054 setPropertyValue(obj
, "success", true);
2055 assertSpyCalls(setter
, 1);
2056 assertSpyCall(setter
, 0, {
2062 it("[[Call]] uses the provided receiver", () => {
2063 const setter
= spy((_
) => {});
2064 const obj
= Object
.create(null, { success
: { set: setter
} });
2065 const receiver
= {};
2066 setPropertyValue(obj
, "success", true, receiver
);
2067 assertSpyCalls(setter
, 1);
2068 assertSpyCall(setter
, 0, {
2074 it("[[Call]] throws if the property can’t be set", () => {
2075 const obj
= Object
.freeze({ failure
: undefined });
2076 assertThrows(() => setPropertyValue(obj
, "failure", true));
2079 it("[[Call]] returns the provided object", () => {
2081 assertStrictEquals(setPropertyValue(obj
, "", undefined), obj
);
2084 it("[[Construct]] throws an error", () => {
2085 assertThrows(() => new setPropertyValue({}, "", undefined));
2088 describe(".length", () => {
2089 it("[[Get]] returns the correct length", () => {
2090 assertStrictEquals(setPropertyValue
.length
, 3);
2094 describe(".name", () => {
2095 it("[[Get]] returns the correct name", () => {
2096 assertStrictEquals(setPropertyValue
.name
, "setPropertyValue");
2101 describe("setPropertyValues", () => {
2102 it("[[Call]] sets the provided properties on the provided object", () => {
2104 setPropertyValues(obj
, { success
: true, all
: "good" });
2105 assertStrictEquals(obj
.success
, true);
2106 assertStrictEquals(obj
.all
, "good");
2109 it("[[Call]] can take multiple objects", () => {
2113 { success
: false, all
: "good" },
2116 assertStrictEquals(obj
.success
, true);
2117 assertStrictEquals(obj
.all
, "good");
2120 it("[[Call]] ignores nullish arguments", () => {
2122 setPropertyValues(obj
, null, undefined, { success
: true });
2123 assertStrictEquals(obj
.success
, true);
2126 it("[[Call]] calls setters", () => {
2127 const setter
= spy((_
) => {});
2128 const obj
= Object
.create(null, { success
: { set: setter
} });
2129 setPropertyValues(obj
, { success
: true });
2130 assertSpyCalls(setter
, 1);
2131 assertSpyCall(setter
, 0, {
2137 it("[[Call]] calls setters multiple times if property appears more than once", () => {
2138 const setter
= spy((_
) => {});
2139 const obj
= Object
.create(null, { success
: { set: setter
} });
2140 setPropertyValues(obj
, { success
: false }, { success
: true });
2141 assertSpyCalls(setter
, 2);
2142 assertSpyCall(setter
, 0, {
2146 assertSpyCall(setter
, 1, {
2152 it("[[Call]] walks the prototype chain", () => {
2153 const setter
= spy((_
) => {});
2154 const obj
= Object
.create(
2155 Object
.create(null, { success
: { set: setter
} }),
2157 setPropertyValues(obj
, { success
: true });
2158 assertSpyCalls(setter
, 1);
2159 assertSpyCall(setter
, 0, {
2165 it("[[Call]] throws if the property can’t be set", () => {
2166 const obj
= Object
.freeze({ failure
: undefined });
2167 assertThrows(() => setPropertyValues(obj
, { failure
: true }));
2170 it("[[Call]] returns the provided object", () => {
2172 assertStrictEquals(setPropertyValues(obj
, { "": undefined }), obj
);
2175 it("[[Construct]] throws an error", () => {
2176 assertThrows(() => new setPropertyValues(obj
, { "": undefined }));
2179 describe(".length", () => {
2180 it("[[Get]] returns the correct length", () => {
2181 assertStrictEquals(setPropertyValues
.length
, 2);
2185 describe(".name", () => {
2186 it("[[Get]] returns the correct name", () => {
2187 assertStrictEquals(setPropertyValues
.name
, "setPropertyValues");
2192 describe("setPrototype", () => {
2193 it("[[Call]] sets object prototypes", () => {
2196 setPrototype(obj
, proto
);
2197 assertStrictEquals(Object
.getPrototypeOf(obj
), proto
);
2200 it("[[Call]] sets null prototypes", () => {
2202 setPrototype(obj
, null);
2203 assertStrictEquals(Object
.getPrototypeOf(obj
), null);
2206 it("[[Call]] can set coercible primitives to their same prototype", () => {
2207 setPrototype(1, Number
.prototype);
2208 setPrototype(Symbol(), Symbol
.prototype);
2211 it("[[Call]] throws when setting coercible primitives to a different prototype", () => {
2212 assertThrows(() => setPrototype(1, Object
.prototype));
2213 assertThrows(() => setPrototype(Symbol(), Object
.prototype));
2216 it("[[Call]] throws for null and undefined", () => {
2217 assertThrows(() => setPrototype(null, Object
.prototype));
2218 assertThrows(() => setPrototype(undefined, Object
.prototype));
2221 it("[[Call]] returns the provided value", () => {
2223 assertStrictEquals(setPrototype(obj
, null), obj
);
2224 assertStrictEquals(setPrototype(1, Number
.prototype), 1);
2227 it("[[Construct]] throws an error", () => {
2228 assertThrows(() => new setPrototype({}, null));
2231 describe(".length", () => {
2232 it("[[Get]] returns the correct length", () => {
2233 assertStrictEquals(setPrototype
.length
, 2);
2237 describe(".name", () => {
2238 it("[[Get]] returns the correct name", () => {
2239 assertStrictEquals(setPrototype
.name
, "setPrototype");
2244 describe("toObject", () => {
2245 it("returns the input for objects", () => {
2247 assertStrictEquals(toObject(obj
), obj
);
2250 it("throws for nullish values", () => {
2251 assertThrows(() => toObject(null));
2252 assertThrows(() => toObject(void {}));
2255 it("returns a wrapper object for other primitives", () => {
2256 const sym
= Symbol();
2257 assertStrictEquals(typeof toObject(sym
), "object");
2258 assertStrictEquals(toObject(sym
).valueOf(), sym
);
2261 it("[[Construct]] throws an error", () => {
2262 assertThrows(() => new toObject({}));
2265 describe(".length", () => {
2266 it("[[Get]] returns the correct length", () => {
2267 assertStrictEquals(toObject
.length
, 1);
2271 describe(".name", () => {
2272 it("[[Get]] returns the correct name", () => {
2273 assertStrictEquals(toObject
.name
, "toObject");
2278 describe("toPropertyKey", () => {
2279 it("returns a string or symbol", () => {
2280 const sym
= Symbol();
2281 assertStrictEquals(toPropertyKey(sym
), sym
);
2283 toPropertyKey(new String("success")),
2288 it("favours the `toString` representation", () => {
2302 it("[[Construct]] throws an error", () => {
2303 assertThrows(() => new toPropertyKey(""));
2306 describe(".length", () => {
2307 it("[[Get]] returns the correct length", () => {
2308 assertStrictEquals(toPropertyKey
.length
, 1);
2312 describe(".name", () => {
2313 it("[[Get]] returns the correct name", () => {
2314 assertStrictEquals(toPropertyKey
.name
, "toPropertyKey");