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/>.
13 assertNotStrictEquals
,
21 } from "./dev-deps.js";
23 defineOwnDataProperty
,
24 defineOwnNonenumerableDataProperty
,
31 getOwnPropertyDescriptor
,
32 getOwnPropertyDescriptors
,
34 getOwnPropertyStrings
,
35 getOwnPropertySymbols
,
41 isConcatSpreadableObject
,
43 isPropertyDescriptorRecord
,
59 toPropertyDescriptorRecord
,
62 describe("LazyLoader", () => {
63 const symbol
= Symbol("foo");
65 const etaoinMethod
= spy(() => "success");
66 const shrdluMethod
= spy(() => "success");
67 const cmfwypMethod
= spy(() => "success");
68 const vbgkqjMethod
= spy(() => "success");
69 const methodsObject
= Object
.create(
99 xz
fiflffffi: { configurable
: true, enumerable
: false, set(_
) {} },
109 it("[[Call]] throws an error", () => {
110 assertThrows(() => LazyLoader({}));
113 it("[[Construct]] creates a new object which inherits from the correct prototype", () => {
115 Object
.getPrototypeOf(new LazyLoader(methodsObject
)),
120 it("[[Construct]] creates a new object with the desired properties", () => {
122 Reflect
.ownKeys(new LazyLoader(methodsObject
)),
123 ["etaoin", "shrdlu", "cmfwyp", "vbgkqj", "xzfiflffffi", symbol
],
127 it("[[Construct]] creates a new object with configurable properties", () => {
131 for (const key
of Reflect
.ownKeys(ll
)) {
134 Object
.getOwnPropertyDescriptor(ll
, key
).configurable
,
137 }(new LazyLoader(methodsObject
)),
150 it("[[Construct]] creates a new object with the correct enumerability", () => {
154 for (const key
of Reflect
.ownKeys(ll
)) {
157 Object
.getOwnPropertyDescriptor(ll
, key
).enumerable
,
160 }(new LazyLoader(methodsObject
)),
173 it("[[Construct]] creates a new object with defined getters", () => {
177 for (const key
of Reflect
.ownKeys(ll
)) {
180 Object
.getOwnPropertyDescriptor(ll
, key
).get?.name
,
183 }(new LazyLoader(methodsObject
)),
186 etaoin
: "get etaoin",
187 shrdlu
: "get shrdlu",
188 cmfwyp
: "get cmfwyp",
189 vbgkqj
: "get vbgkqj",
190 xz
fiflffffi: "get xzfiflffffi",
191 [symbol
]: `get [${symbol.description}]`,
196 it("[[Construct]] creates a new object with defined setters for writable properties only", () => {
200 for (const key
of Reflect
.ownKeys(ll
)) {
203 Object
.getOwnPropertyDescriptor(ll
, key
).set?.name
,
206 }(new LazyLoader(methodsObject
)),
214 [symbol
]: `set [${symbol.description}]`,
219 it("[[Construct]] creates a new object with correct getter behaviour", () => {
220 const ll
= new LazyLoader(methodsObject
);
223 Object
.getOwnPropertyDescriptor(ll
, "etaoin"),
231 assertSpyCalls(etaoinMethod
, 1);
232 assertSpyCall(etaoinMethod
, 0, {
239 Object
.getOwnPropertyDescriptor(ll
, "shrdlu"),
247 assertSpyCalls(shrdluMethod
, 1);
248 assertSpyCall(shrdluMethod
, 0, {
255 Object
.getOwnPropertyDescriptor(ll
, "cmfwyp"),
263 assertSpyCalls(cmfwypMethod
, 1);
264 assertSpyCall(cmfwypMethod
, 0, {
271 Object
.getOwnPropertyDescriptor(ll
, "vbgkqj"),
279 assertSpyCalls(vbgkqjMethod
, 1);
280 assertSpyCall(vbgkqjMethod
, 0, {
285 assertThrows(() => ll
.xz
fiflffffi);
286 assertThrows(() => ll
[symbol
]);
289 it("[[Construct]] creates a new object with correct setter behaviour", () => {
290 const ll
= new LazyLoader(methodsObject
);
291 ll
[symbol
] = "success";
293 Object
.getOwnPropertyDescriptor(ll
, symbol
),
303 describe(".length", () => {
304 it("[[Get]] returns the correct length", () => {
305 assertStrictEquals(LazyLoader
.length
, 1);
309 describe(".name", () => {
310 it("[[Get]] returns the correct name", () => {
311 assertStrictEquals(LazyLoader
.name
, "LazyLoader");
316 describe("defineOwnDataProperty", () => {
317 it("[[Call]] defines the property", () => {
319 defineOwnDataProperty(obj
, "etaoin", "success");
320 assert(Object
.hasOwn(obj
, "etaoin"));
321 assertStrictEquals(obj
.etaoin
, "success");
324 it("[[Call]] defines a configurable, enumerable, writable property", () => {
326 defineOwnDataProperty(obj
, "etaoin", "success");
328 Object
.getOwnPropertyDescriptor(obj
, "etaoin"),
338 it("[[Call]] returns the provided object", () => {
341 defineOwnDataProperty(obj
, "etaoin", null),
346 it("[[Construct]] throws an error", () => {
347 assertThrows(() => new defineOwnDataProperty(obj
, "etaoin", null));
350 describe(".length", () => {
351 it("[[Get]] returns the correct length", () => {
352 assertStrictEquals(defineOwnDataProperty
.length
, 3);
356 describe(".name", () => {
357 it("[[Get]] returns the correct name", () => {
359 defineOwnDataProperty
.name
,
360 "defineOwnDataProperty",
366 describe("defineOwnNonenumerableDataProperty", () => {
367 it("[[Call]] defines the property", () => {
369 defineOwnNonenumerableDataProperty(obj
, "etaoin", "success");
370 assert(Object
.hasOwn(obj
, "etaoin"));
371 assertStrictEquals(obj
.etaoin
, "success");
374 it("[[Call]] defines a configurable, non·enumerable, writable property", () => {
376 defineOwnNonenumerableDataProperty(obj
, "etaoin", "success");
378 Object
.getOwnPropertyDescriptor(obj
, "etaoin"),
388 it("[[Call]] returns the provided object", () => {
391 defineOwnNonenumerableDataProperty(obj
, "etaoin", null),
396 it("[[Construct]] throws an error", () => {
398 new defineOwnNonenumerableDataProperty(obj
, "etaoin", null)
402 describe(".length", () => {
403 it("[[Get]] returns the correct length", () => {
404 assertStrictEquals(defineOwnNonenumerableDataProperty
.length
, 3);
408 describe(".name", () => {
409 it("[[Get]] returns the correct name", () => {
411 defineOwnNonenumerableDataProperty
.name
,
412 "defineOwnNonenumerableDataProperty",
418 describe("defineOwnProperty", () => {
419 it("[[Call]] defines the property", () => {
421 defineOwnProperty(obj
, "etaoin", {});
422 assert(Object
.hasOwn(obj
, "etaoin"));
425 it("[[Call]] returns the provided object", () => {
427 assertStrictEquals(defineOwnProperty(obj
, "etaoin", {}), obj
);
430 it("[[Construct]] throws an error", () => {
431 assertThrows(() => new defineOwnProperty(obj
, "etaoin", {}));
434 describe(".length", () => {
435 it("[[Get]] returns the correct length", () => {
436 assertStrictEquals(defineOwnProperty
.length
, 3);
440 describe(".name", () => {
441 it("[[Get]] returns the correct name", () => {
443 defineOwnProperty
.name
,
450 describe("defineOwnProperties", () => {
451 it("[[Call]] defines properties from the provided objects", () => {
453 defineOwnProperties(obj
, {
457 assert("etaoin" in obj
);
458 assert("shrdlu" in obj
);
459 assert("cmfwyp" in obj
);
462 it("[[Call]] overrides earlier declarations with later ones", () => {
463 const obj
= { etaoin
: undefined };
464 defineOwnProperties(obj
, {
465 etaoin
: { value
: "failure" },
467 etaoin
: { value
: "success" },
469 assertStrictEquals(obj
.etaoin
, "success");
472 it("[[Call]] returns the provided object", () => {
474 assertStrictEquals(defineOwnProperties(obj
), obj
);
477 it("[[Construct]] throws an error", () => {
478 assertThrows(() => new defineOwnProperties({}));
481 describe(".length", () => {
482 it("[[Get]] returns the correct length", () => {
483 assertStrictEquals(defineOwnProperties
.length
, 1);
487 describe(".name", () => {
488 it("[[Get]] returns the correct name", () => {
490 defineOwnProperties
.name
,
491 "defineOwnProperties",
497 describe("deleteOwnProperty", () => {
498 it("[[Call]] deletes the provided property on the provided object", () => {
499 const obj
= { failure
: undefined };
500 deleteOwnProperty(obj
, "failure");
501 assert(!("failure" in obj
));
504 it("[[Call]] does nothing if the property doesn’t exist", () => {
505 const obj
= Object
.freeze({});
506 deleteOwnProperty(obj
, "failure");
507 assert(!("failure" in obj
));
510 it("[[Call]] throws if the property can’t be deleted", () => {
511 const obj
= Object
.seal({ failure
: undefined });
512 assertThrows(() => deleteOwnProperty(obj
, "failure"));
515 it("[[Call]] returns the provided object", () => {
517 assertStrictEquals(deleteOwnProperty(obj
, ""), obj
);
520 it("[[Construct]] throws an error", () => {
521 assertThrows(() => new deleteOwnProperty({}, ""));
524 describe(".length", () => {
525 it("[[Get]] returns the correct length", () => {
526 assertStrictEquals(deleteOwnProperty
.length
, 2);
530 describe(".name", () => {
531 it("[[Get]] returns the correct name", () => {
532 assertStrictEquals(deleteOwnProperty
.name
, "deleteOwnProperty");
537 describe("freeze", () => {
538 it("[[Call]] freezes the object", () => {
541 assert(Object
.isFrozen(obj
));
544 it("[[Call]] returns the provided object", () => {
546 assertStrictEquals(freeze(obj
), obj
);
549 it("[[Construct]] throws an error", () => {
550 assertThrows(() => new freeze({}));
553 describe(".length", () => {
554 it("[[Get]] returns the correct length", () => {
555 assertStrictEquals(freeze
.length
, 1);
559 describe(".name", () => {
560 it("[[Get]] returns the correct name", () => {
561 assertStrictEquals(freeze
.name
, "freeze");
566 describe("frozenCopy", () => {
567 it("[[Call]] returns a frozen object", () => {
570 frozenCopy(Object
.create(null), {
587 it("[[Call]] ignores non·enumerable properties", () => {
590 Object
.create(null, {
591 data
: { value
: undefined },
592 accessor
: { get: undefined },
599 it("[[Call]] preserves accessor properties", () => {
627 Object
.getOwnPropertyDescriptors(
628 frozenCopy(Object
.create(null, properties
)),
634 it("[[Call]] preserves data properties", () => {
654 Object
.getOwnPropertyDescriptors(
655 frozenCopy(Object
.create(null, properties
)),
659 ...properties
.implied
,
663 writable
: { ...properties
.writable
, writable
: false },
664 nonwritable
: properties
.nonwritable
,
669 it("[[Call]] does not copy properties on the prototype", () => {
672 frozenCopy(Object
.create({ failure
: undefined }))),
676 it("[[Call]] uses the species of the constructor", () => {
677 const species
= { prototype: {} };
679 Object
.getPrototypeOf(
680 frozenCopy({}, { [Symbol
.species
]: species
}),
686 it("[[Call]] uses constructor if no species is defined", () => {
687 const constructor = { [Symbol
.species
]: null, prototype: {} };
689 Object
.getPrototypeOf(frozenCopy({}, constructor)),
690 constructor.prototype,
694 it("[[Call]] uses the constructor on the object if none is provided", () => {
695 const constructor = { [Symbol
.species
]: null, prototype: {} };
697 Object
.getPrototypeOf(frozenCopy({ constructor })),
698 constructor.prototype,
702 it("[[Call]] allows a null constructor", () => {
704 Object
.getPrototypeOf(frozenCopy({}, null)),
709 it("[[Construct]] throws an error", () => {
710 assertThrows(() => new frozenCopy({}));
713 describe(".length", () => {
714 it("[[Get]] returns the correct length", () => {
715 assertStrictEquals(frozenCopy
.length
, 1);
719 describe(".name", () => {
720 it("[[Get]] returns the correct name", () => {
721 assertStrictEquals(frozenCopy
.name
, "frozenCopy");
726 describe("getMethod", () => {
727 it("[[Call]] gets a method", () => {
728 const method
= () => {};
729 assertStrictEquals(getMethod({ method
}, "method"), method
);
732 it("[[Call]] works for values coercible to objects", () => {
733 assertEquals(getMethod("", "toString"), String
.prototype.toString
);
736 it("[[Call]] throws for null and undefined", () => {
737 assertThrows(() => getMethod(null, "valueOf"));
738 assertThrows(() => getMethod(undefined, "valueOf"));
741 it("[[Call]] throws if the resulting value isn’t callable", () => {
742 assertThrows(() => getMethod({ "failure": true }, "failure"));
745 it("[[Construct]] throws an error", () => {
746 assertThrows(() => new getMethod({ method() {} }, "method"));
749 describe(".length", () => {
750 it("[[Get]] returns the correct length", () => {
751 assertStrictEquals(getMethod
.length
, 2);
755 describe(".name", () => {
756 it("[[Get]] returns the correct name", () => {
757 assertStrictEquals(getMethod
.name
, "getMethod");
762 describe("getOwnPropertyDescriptor", () => {
763 it("[[Call]] gets the descriptor", () => {
765 getOwnPropertyDescriptor({ success
: true }, "success"),
775 it("[[Call]] returns undefined for non‐own properties", () => {
777 getOwnPropertyDescriptor({}, "valueOf"),
782 it("[[Construct]] throws an error", () => {
783 assertThrows(() => new getOwnPropertyDescriptor({}, ""));
786 describe(".length", () => {
787 it("[[Get]] returns the correct length", () => {
788 assertStrictEquals(getOwnPropertyDescriptor
.length
, 2);
792 describe(".name", () => {
793 it("[[Get]] returns the correct name", () => {
795 getOwnPropertyDescriptor
.name
,
796 "getOwnPropertyDescriptor",
802 describe("getOwnPropertyDescriptors", () => {
803 it("[[Call]] gets the descriptors", () => {
805 getOwnPropertyDescriptors({ success
: true, etaoin
: "shrdlu" }),
823 it("[[Construct]] throws an error", () => {
824 assertThrows(() => new getOwnPropertyDescriptors({}));
827 describe(".length", () => {
828 it("[[Get]] returns the correct length", () => {
829 assertStrictEquals(getOwnPropertyDescriptors
.length
, 1);
833 describe(".name", () => {
834 it("[[Get]] returns the correct name", () => {
836 getOwnPropertyDescriptors
.name
,
837 "getOwnPropertyDescriptors",
843 describe("getOwnPropertyKeys", () => {
844 it("[[Call]] gets own (but not inherited) property keys", () => {
845 assertEquals(getOwnPropertyKeys({ success
: true }), ["success"]);
848 it("[[Call]] works for values coercible to objects", () => {
849 assertEquals(getOwnPropertyKeys("foo"), ["0", "1", "2", "length"]);
852 it("[[Call]] throws for null and undefined", () => {
853 assertThrows(() => getOwnPropertyKeys(null));
854 assertThrows(() => getOwnPropertyKeys(undefined));
857 it("[[Construct]] throws an error", () => {
858 assertThrows(() => new getOwnPropertyKeys({}));
861 describe(".length", () => {
862 it("[[Get]] returns the correct length", () => {
863 assertStrictEquals(getOwnPropertyKeys
.length
, 1);
867 describe(".name", () => {
868 it("[[Get]] returns the correct name", () => {
870 getOwnPropertyKeys
.name
,
871 "getOwnPropertyKeys",
877 describe("getOwnPropertyStrings", () => {
878 it("[[Call]] gets own string keys", () => {
879 assertEquals(getOwnPropertyStrings({ success
: true }), [
884 it("[[Call]] works for values coercible to objects", () => {
885 assertEquals(getOwnPropertyStrings("foo"), [
893 it("[[Call]] throws for null and undefined", () => {
894 assertThrows(() => getOwnPropertyStrings(null));
895 assertThrows(() => getOwnPropertyStrings(undefined));
898 it("[[Construct]] throws an error", () => {
899 assertThrows(() => new getOwnPropertyStrings({}));
902 describe(".length", () => {
903 it("[[Get]] returns the correct length", () => {
904 assertStrictEquals(getOwnPropertyStrings
.length
, 1);
908 describe(".name", () => {
909 it("[[Get]] returns the correct name", () => {
911 getOwnPropertyStrings
.name
,
912 "getOwnPropertyStrings",
918 describe("getOwnPropertySymbols", () => {
919 it("[[Call]] gets own symbol keys", () => {
920 const sym
= Symbol();
921 assertEquals(getOwnPropertySymbols({ [sym
]: true }), [sym
]);
924 it("[[Call]] works for values coercible to objects", () => {
925 assertEquals(getOwnPropertySymbols("foo"), []);
928 it("[[Call]] throws for null and undefined", () => {
929 assertThrows(() => getOwnPropertySymbols(null));
930 assertThrows(() => getOwnPropertySymbols(undefined));
933 it("[[Construct]] throws an error", () => {
934 assertThrows(() => new getOwnPropertySymbols({}));
937 describe(".length", () => {
938 it("[[Get]] returns the correct length", () => {
939 assertStrictEquals(getOwnPropertySymbols
.length
, 1);
943 describe(".name", () => {
944 it("[[Get]] returns the correct name", () => {
946 getOwnPropertySymbols
.name
,
947 "getOwnPropertySymbols",
953 describe("getPropertyValue", () => {
954 it("[[Call]] gets property values on the provided object", () => {
956 getPropertyValue({ success
: true }, "success"),
961 it("[[Call]] works for values coercible to objects", () => {
963 getPropertyValue("", "toString"),
964 String
.prototype.toString
,
968 it("[[Call]] throws for null and undefined", () => {
969 assertThrows(() => getPropertyValue(null, "valueOf"));
970 assertThrows(() => getPropertyValue(undefined, "valueOf"));
973 it("[[Construct]] throws an error", () => {
974 assertThrows(() => new getPropertyValue({}, "valueOf"));
977 describe(".length", () => {
978 it("[[Get]] returns the correct length", () => {
979 assertStrictEquals(getPropertyValue
.length
, 2);
983 describe(".name", () => {
984 it("[[Get]] returns the correct name", () => {
985 assertStrictEquals(getPropertyValue
.name
, "getPropertyValue");
990 describe("getPrototype", () => {
991 it("[[Call]] gets object prototypes", () => {
992 assertStrictEquals(getPrototype({}), Object
.prototype);
994 assertStrictEquals(getPrototype(Object
.create(proto
)), proto
);
997 it("[[Call]] gets null prototypes", () => {
998 assertStrictEquals(getPrototype(Object
.create(null)), null);
1001 it("[[Call]] gets prototypes for coercible primitives", () => {
1002 assertStrictEquals(getPrototype(1), Number
.prototype);
1003 assertStrictEquals(getPrototype(Symbol()), Symbol
.prototype);
1006 it("[[Call]] throws for null and undefined", () => {
1007 assertThrows(() => getPrototype(null));
1008 assertThrows(() => getPrototype(undefined));
1011 it("[[Construct]] throws an error", () => {
1012 assertThrows(() => new getPrototype({}));
1015 describe(".length", () => {
1016 it("[[Get]] returns the correct length", () => {
1017 assertStrictEquals(getPrototype
.length
, 1);
1021 describe(".name", () => {
1022 it("[[Get]] returns the correct name", () => {
1023 assertStrictEquals(getPrototype
.name
, "getPrototype");
1028 describe("hasProperty", () => {
1029 it("[[Call]] gets whether a property exists on the provided object", () => {
1031 hasProperty({ success
: "etaoin" }, "success"),
1034 assertStrictEquals(hasProperty({}, "hasOwnProperty"), true);
1037 it("[[Call]] works for values coercible to objects", () => {
1038 assertStrictEquals(hasProperty("", "length"), true);
1039 assertStrictEquals(hasProperty("", "toString"), true);
1042 it("[[Call]] throws for null and undefined", () => {
1043 assertThrows(() => hasProperty(null, "valueOf"));
1044 assertThrows(() => hasProperty(undefined, "valueOf"));
1047 it("[[Construct]] throws an error", () => {
1048 assertThrows(() => new hasProperty({}, "valueOf"));
1051 describe(".length", () => {
1052 it("[[Get]] returns the correct length", () => {
1053 assertStrictEquals(hasProperty
.length
, 2);
1057 describe(".name", () => {
1058 it("[[Get]] returns the correct name", () => {
1059 assertStrictEquals(hasProperty
.name
, "hasProperty");
1064 describe("hasOwnProperty", () => {
1065 it("[[Call]] gets whether an own property exists on the provided object", () => {
1067 hasOwnProperty({ success
: "etaoin" }, "success"),
1070 assertStrictEquals(hasOwnProperty({}, "hasOwnProperty"), false);
1073 it("[[Call]] works for values coercible to objects", () => {
1074 assertStrictEquals(hasOwnProperty("", "length"), true);
1075 assertStrictEquals(hasOwnProperty("", "toString"), false);
1078 it("[[Call]] throws for null and undefined", () => {
1079 assertThrows(() => hasOwnProperty(null, "valueOf"));
1080 assertThrows(() => hasOwnProperty(undefined, "valueOf"));
1083 it("[[Construct]] throws an error", () => {
1084 assertThrows(() => new hasOwnProperty({}, "valueOf"));
1087 describe(".length", () => {
1088 it("[[Get]] returns the correct length", () => {
1089 assertStrictEquals(hasOwnProperty
.length
, 2);
1093 describe(".name", () => {
1094 it("[[Get]] returns the correct name", () => {
1095 assertStrictEquals(hasOwnProperty
.name
, "hasOwnProperty");
1100 describe("isArraylikeObject", () => {
1101 it("[[Call]] returns false for primitives", () => {
1102 assertStrictEquals(isArraylikeObject("failure"), false);
1105 it("[[Call]] returns false if length throws", () => {
1116 it("[[Call]] returns false if length is not a number and cannot be converted to one", () => {
1117 assertStrictEquals(isArraylikeObject({ length
: 1n
}), false);
1120 it("[[Call]] returns true if length is convertable to a number", () => {
1121 assertStrictEquals(isArraylikeObject({ length
: -0 }), true);
1122 assertStrictEquals(isArraylikeObject({ length
: 1 }), true);
1123 assertStrictEquals(isArraylikeObject({ length
: -1.25 }), true);
1125 isArraylikeObject({ length
: 9007199254740992 }),
1128 assertStrictEquals(isArraylikeObject({ length
: Infinity
}), true);
1129 assertStrictEquals(isArraylikeObject({ length
: "success" }), true);
1132 it("[[Construct]] throws an error", () => {
1133 assertThrows(() => new isArraylikeObject({}));
1136 describe(".length", () => {
1137 it("[[Get]] returns the correct length", () => {
1138 assertStrictEquals(isArraylikeObject
.length
, 1);
1142 describe(".name", () => {
1143 it("[[Get]] returns the correct name", () => {
1145 isArraylikeObject
.name
,
1146 "isArraylikeObject",
1152 describe("isConcatSpreadableObject", () => {
1153 it("[[Call]] returns false for primitives", () => {
1154 assertStrictEquals(isConcatSpreadableObject("failure"), false);
1157 it("[[Call]] returns false if [Symbol.isConcatSpreadable] is null or false", () => {
1159 isConcatSpreadableObject(
1160 Object
.assign([], { [Symbol
.isConcatSpreadable
]: null }),
1165 isConcatSpreadableObject(
1166 Object
.assign([], { [Symbol
.isConcatSpreadable
]: false }),
1172 it("[[Call]] returns true if [Symbol.isConcatSpreadable] is undefined and the object is an array", () => {
1174 isConcatSpreadableObject(
1175 Object
.assign([], { [Symbol
.isConcatSpreadable
]: undefined }),
1181 it("[[Call]] returns true if [Symbol.isConcatSpreadable] is true", () => {
1183 isConcatSpreadableObject({ [Symbol
.isConcatSpreadable
]: true }),
1188 it("[[Construct]] throws an error", () => {
1189 assertThrows(() => new isConcatSpreadableObject({}));
1192 describe(".length", () => {
1193 it("[[Get]] returns the correct length", () => {
1194 assertStrictEquals(isConcatSpreadableObject
.length
, 1);
1198 describe(".name", () => {
1199 it("[[Get]] returns the correct name", () => {
1201 isConcatSpreadableObject
.name
,
1202 "isConcatSpreadableObject",
1208 describe("isExtensibleObject", () => {
1209 it("[[Call]] returns true for extensible objects", () => {
1210 assertStrictEquals(isExtensibleObject({}), true);
1213 it("[[Call]] returns false for coercible primitives", () => {
1214 assertStrictEquals(isExtensibleObject(1), false);
1215 assertStrictEquals(isExtensibleObject(Symbol()), false);
1218 it("[[Call]] returns false for non·extensible objects", () => {
1220 isExtensibleObject(Object
.preventExtensions({})),
1225 it("[[Call]] returns false for null and undefined", () => {
1226 assertStrictEquals(isExtensibleObject(null), false);
1227 assertStrictEquals(isExtensibleObject(undefined), false);
1230 it("[[Construct]] throws an error", () => {
1231 assertThrows(() => new isExtensibleObject({}));
1234 describe(".length", () => {
1235 it("[[Get]] returns the correct length", () => {
1236 assertStrictEquals(isExtensibleObject
.length
, 1);
1240 describe(".name", () => {
1241 it("[[Get]] returns the correct name", () => {
1243 isExtensibleObject
.name
,
1244 "isExtensibleObject",
1250 describe("isPropertyDescriptorRecord", () => {
1251 it("[[Call]] returns true for objects created by toPropertyDescriptorRecord", () => {
1253 isPropertyDescriptorRecord(toPropertyDescriptorRecord({})),
1258 it("[[Get]] returns false for other objects", () => {
1260 isPropertyDescriptorRecord(Object
.create(null)),
1265 it("[[Get]] returns false for undefined", () => {
1266 assertStrictEquals(isPropertyDescriptorRecord(undefined), false);
1269 it("[[Construct]] throws an error", () => {
1270 assertThrows(() => new isPropertyDescriptorRecord({}));
1273 describe(".length", () => {
1274 it("[[Get]] returns the correct length", () => {
1275 assertStrictEquals(isPropertyDescriptorRecord
.length
, 1);
1279 describe(".name", () => {
1280 it("[[Get]] returns the correct name", () => {
1282 isPropertyDescriptorRecord
.name
,
1283 "isPropertyDescriptorRecord",
1289 describe("isUnfrozenObject", () => {
1290 it("[[Call]] returns true for unfrozen objects", () => {
1291 assertStrictEquals(isUnfrozenObject({}), true);
1294 it("[[Call]] returns false for coercible primitives", () => {
1295 assertStrictEquals(isUnfrozenObject(1), false);
1296 assertStrictEquals(isUnfrozenObject(Symbol()), false);
1299 it("[[Call]] returns false for frozen objects", () => {
1300 assertStrictEquals(isUnfrozenObject(Object
.freeze({})), false);
1303 it("[[Call]] returns false for null and undefined", () => {
1304 assertStrictEquals(isUnfrozenObject(null), false);
1305 assertStrictEquals(isUnfrozenObject(undefined), false);
1308 it("[[Construct]] throws an error", () => {
1309 assertThrows(() => new isUnfrozenObject({}));
1312 describe(".length", () => {
1313 it("[[Get]] returns the correct length", () => {
1314 assertStrictEquals(isUnfrozenObject
.length
, 1);
1318 describe(".name", () => {
1319 it("[[Get]] returns the correct name", () => {
1320 assertStrictEquals(isUnfrozenObject
.name
, "isUnfrozenObject");
1325 describe("isUnsealedObject", () => {
1326 it("[[Call]] returns true for unsealed objects", () => {
1327 assertStrictEquals(isUnsealedObject({}), true);
1330 it("[[Call]] returns false for coercible primitives", () => {
1331 assertStrictEquals(isUnsealedObject(1), false);
1332 assertStrictEquals(isUnsealedObject(Symbol()), false);
1335 it("[[Call]] returns false for sealed objects", () => {
1336 assertStrictEquals(isUnsealedObject(Object
.seal({})), false);
1339 it("[[Call]] returns false for null and undefined", () => {
1340 assertStrictEquals(isUnsealedObject(null), false);
1341 assertStrictEquals(isUnsealedObject(undefined), false);
1344 it("[[Construct]] throws an error", () => {
1345 assertThrows(() => new isUnsealedObject({}));
1348 describe(".length", () => {
1349 it("[[Get]] returns the correct length", () => {
1350 assertStrictEquals(isUnsealedObject
.length
, 1);
1354 describe(".name", () => {
1355 it("[[Get]] returns the correct name", () => {
1356 assertStrictEquals(isUnsealedObject
.name
, "isUnsealedObject");
1361 describe("lengthOfArraylike", () => {
1362 it("[[Call]] returns the length", () => {
1364 lengthOfArraylike({ length
: 9007199254740991 }),
1369 it("[[Call]] returns a non·nan result", () => {
1370 assertStrictEquals(lengthOfArraylike({ length
: NaN
}), 0);
1371 assertStrictEquals(lengthOfArraylike({ length
: "failure" }), 0);
1374 it("[[Call]] returns an integral result", () => {
1375 assertStrictEquals(lengthOfArraylike({ length
: 0.25 }), 0);
1376 assertStrictEquals(lengthOfArraylike({ length
: 1.1 }), 1);
1379 it("[[Call]] returns a result greater than or equal to zero", () => {
1380 assertStrictEquals(lengthOfArraylike({ length
: -0 }), 0);
1381 assertStrictEquals(lengthOfArraylike({ length
: -1 }), 0);
1382 assertStrictEquals(lengthOfArraylike({ length
: -Infinity
}), 0);
1385 it("[[Call]] returns a result less than 2 ** 53", () => {
1387 lengthOfArraylike({ length
: 9007199254740992 }),
1391 lengthOfArraylike({ length
: Infinity
}),
1396 it("[[Call]] does not require an object argument", () => {
1397 assertStrictEquals(lengthOfArraylike("string"), 6);
1398 assertStrictEquals(lengthOfArraylike(Symbol()), 0);
1401 it("[[Construct]] throws an error", () => {
1402 assertThrows(() => new lengthOfArraylike(""));
1405 describe(".length", () => {
1406 it("[[Get]] returns the correct length", () => {
1407 assertStrictEquals(lengthOfArraylike
.length
, 1);
1411 describe(".name", () => {
1412 it("[[Get]] returns the correct name", () => {
1413 assertStrictEquals(lengthOfArraylike
.name
, "lengthOfArraylike");
1418 describe("namedEntries", () => {
1419 it("[[Call]] gets named entries", () => {
1420 assertEquals(namedEntries({ success
: true }), [["success", true]]);
1423 it("[[Call]] works for values coercible to objects", () => {
1424 assertEquals(namedEntries("foo"), [
1431 it("[[Call]] throws for null and undefined", () => {
1432 assertThrows(() => namedEntries(null));
1433 assertThrows(() => namedEntries(undefined));
1436 it("[[Construct]] throws an error", () => {
1437 assertThrows(() => new namedEntries({}));
1440 describe(".length", () => {
1441 it("[[Get]] returns the correct length", () => {
1442 assertStrictEquals(namedEntries
.length
, 1);
1446 describe(".name", () => {
1447 it("[[Get]] returns the correct name", () => {
1448 assertStrictEquals(namedEntries
.name
, "namedEntries");
1453 describe("namedKeys", () => {
1454 it("[[Call]] gets named keys", () => {
1455 assertEquals(namedKeys({ success
: true }), ["success"]);
1458 it("[[Call]] works for values coercible to objects", () => {
1459 assertEquals(namedKeys("foo"), [
1466 it("[[Call]] throws for null and undefined", () => {
1467 assertThrows(() => namedKeys(null));
1468 assertThrows(() => namedKeys(undefined));
1471 it("[[Construct]] throws an error", () => {
1472 assertThrows(() => new namedKeys({}));
1475 describe(".length", () => {
1476 it("[[Get]] returns the correct length", () => {
1477 assertStrictEquals(namedKeys
.length
, 1);
1481 describe(".name", () => {
1482 it("[[Get]] returns the correct name", () => {
1483 assertStrictEquals(namedKeys
.name
, "namedKeys");
1488 describe("namedValues", () => {
1489 it("[[Call]] gets named values", () => {
1490 assertEquals(namedValues({ success
: true }), [true]);
1493 it("[[Call]] works for values coercible to objects", () => {
1494 assertEquals(namedValues("foo"), [
1501 it("[[Call]] throws for null and undefined", () => {
1502 assertThrows(() => namedValues(null));
1503 assertThrows(() => namedValues(undefined));
1506 it("[[Construct]] throws an error", () => {
1507 assertThrows(() => new namedValues({}));
1510 describe(".length", () => {
1511 it("[[Get]] returns the correct length", () => {
1512 assertStrictEquals(namedValues
.length
, 1);
1516 describe(".name", () => {
1517 it("[[Get]] returns the correct name", () => {
1518 assertStrictEquals(namedValues
.name
, "namedValues");
1523 describe("objectCreate", () => {
1524 it("[[Call]] creates an object", () => {
1525 const obj
= objectCreate(null);
1526 assertStrictEquals(Object(obj
), obj
);
1529 it("[[Call]] correctly sets the prototype", () => {
1532 Object
.getPrototypeOf(objectCreate(proto
)),
1536 Object
.getPrototypeOf(objectCreate(null)),
1541 it("[[Call]] correctly sets own properties", () => {
1543 Object
.getOwnPropertyDescriptors(
1544 objectCreate(null, { success
: { value
: true } }),
1548 configurable
: false,
1557 it("[[Call]] throws for coercible primitives", () => {
1558 assertThrows(() => objectCreate(1));
1559 assertThrows(() => objectCreate(Symbol()));
1562 it("[[Call]] throws for undefined", () => {
1563 assertThrows(() => objectCreate(undefined));
1566 it("[[Construct]] throws an error", () => {
1567 assertThrows(() => new objectCreate({}));
1570 describe(".length", () => {
1571 it("[[Get]] returns the correct length", () => {
1572 assertStrictEquals(objectCreate
.length
, 2);
1576 describe(".name", () => {
1577 it("[[Get]] returns the correct name", () => {
1578 assertStrictEquals(objectCreate
.name
, "objectCreate");
1583 describe("objectFromEntries", () => {
1584 it("[[Call]] creates an object", () => {
1585 const obj
= objectFromEntries([]);
1586 assertStrictEquals(Object(obj
), obj
);
1589 it("[[Call]] correctly sets the prototype", () => {
1591 Object
.getPrototypeOf(objectFromEntries([])),
1596 it("[[Call]] correctly sets own properties", () => {
1598 Object
.entries(objectFromEntries([["success", true]])),
1599 [["success", true]],
1603 it("[[Call]] throws if the argument is not a nested arraylike", () => {
1604 assertThrows(() => objectFromEntries(1));
1605 assertThrows(() => objectFromEntries(Symbol()));
1606 assertThrows(() => objectFromEntries(null));
1607 assertThrows(() => objectFromEntries(undefined));
1608 assertThrows(() => objectFromEntries({}));
1609 assertThrows(() => objectFromEntries([undefined]));
1612 it("[[Construct]] throws an error", () => {
1613 assertThrows(() => new objectFromEntries([]));
1616 describe(".length", () => {
1617 it("[[Get]] returns the correct length", () => {
1618 assertStrictEquals(objectFromEntries
.length
, 1);
1622 describe(".name", () => {
1623 it("[[Get]] returns the correct name", () => {
1624 assertStrictEquals(objectFromEntries
.name
, "objectFromEntries");
1629 describe("preventExtensions", () => {
1630 it("[[Call]] prevents extensions on the object", () => {
1632 preventExtensions(obj
);
1633 assert(!Object
.isExtensible(obj
));
1636 it("[[Call]] returns the provided object", () => {
1638 assertStrictEquals(preventExtensions(obj
), obj
);
1641 it("[[Construct]] throws an error", () => {
1642 assertThrows(() => new preventExtensions({}));
1645 describe(".length", () => {
1646 it("[[Get]] returns the correct length", () => {
1647 assertStrictEquals(preventExtensions
.length
, 1);
1651 describe(".name", () => {
1652 it("[[Get]] returns the correct name", () => {
1653 assertStrictEquals(preventExtensions
.name
, "preventExtensions");
1658 describe("seal", () => {
1659 it("[[Call]] seals the object", () => {
1662 assert(Object
.isSealed(obj
));
1665 it("[[Call]] returns the provided object", () => {
1667 assertStrictEquals(seal(obj
), obj
);
1670 it("[[Construct]] throws an error", () => {
1671 assertThrows(() => new seal({}));
1674 describe(".length", () => {
1675 it("[[Get]] returns the correct length", () => {
1676 assertStrictEquals(seal
.length
, 1);
1680 describe(".name", () => {
1681 it("[[Get]] returns the correct name", () => {
1682 assertStrictEquals(seal
.name
, "seal");
1687 describe("setPropertyValue", () => {
1688 it("[[Call]] sets the provided property on the provided object", () => {
1690 setPropertyValue(obj
, "success", true);
1691 assertStrictEquals(obj
.success
, true);
1694 it("[[Call]] calls setters", () => {
1695 const setter
= spy((_
) => {});
1696 const obj
= Object
.create(null, { success
: { set: setter
} });
1697 setPropertyValue(obj
, "success", true);
1698 assertSpyCalls(setter
, 1);
1699 assertSpyCall(setter
, 0, {
1705 it("[[Call]] walks the prototype chain", () => {
1706 const setter
= spy((_
) => {});
1707 const obj
= Object
.create(
1708 Object
.create(null, { success
: { set: setter
} }),
1710 setPropertyValue(obj
, "success", true);
1711 assertSpyCalls(setter
, 1);
1712 assertSpyCall(setter
, 0, {
1718 it("[[Call]] uses the provided receiver", () => {
1719 const setter
= spy((_
) => {});
1720 const obj
= Object
.create(null, { success
: { set: setter
} });
1721 const receiver
= {};
1722 setPropertyValue(obj
, "success", true, receiver
);
1723 assertSpyCalls(setter
, 1);
1724 assertSpyCall(setter
, 0, {
1730 it("[[Call]] throws if the property can’t be set", () => {
1731 const obj
= Object
.freeze({ failure
: undefined });
1732 assertThrows(() => setPropertyValue(obj
, "failure", true));
1735 it("[[Call]] returns the provided object", () => {
1737 assertStrictEquals(setPropertyValue(obj
, "", undefined), obj
);
1740 it("[[Construct]] throws an error", () => {
1741 assertThrows(() => new setPropertyValue({}, "", undefined));
1744 describe(".length", () => {
1745 it("[[Get]] returns the correct length", () => {
1746 assertStrictEquals(setPropertyValue
.length
, 3);
1750 describe(".name", () => {
1751 it("[[Get]] returns the correct name", () => {
1752 assertStrictEquals(setPropertyValue
.name
, "setPropertyValue");
1757 describe("setPropertyValues", () => {
1758 it("[[Call]] sets the provided properties on the provided object", () => {
1760 setPropertyValues(obj
, { success
: true, all
: "good" });
1761 assertStrictEquals(obj
.success
, true);
1762 assertStrictEquals(obj
.all
, "good");
1765 it("[[Call]] can take multiple objects", () => {
1769 { success
: false, all
: "good" },
1772 assertStrictEquals(obj
.success
, true);
1773 assertStrictEquals(obj
.all
, "good");
1776 it("[[Call]] ignores nullish arguments", () => {
1778 setPropertyValues(obj
, null, undefined, { success
: true });
1779 assertStrictEquals(obj
.success
, true);
1782 it("[[Call]] calls setters", () => {
1783 const setter
= spy((_
) => {});
1784 const obj
= Object
.create(null, { success
: { set: setter
} });
1785 setPropertyValues(obj
, { success
: true });
1786 assertSpyCalls(setter
, 1);
1787 assertSpyCall(setter
, 0, {
1793 it("[[Call]] calls setters multiple times if property appears more than once", () => {
1794 const setter
= spy((_
) => {});
1795 const obj
= Object
.create(null, { success
: { set: setter
} });
1796 setPropertyValues(obj
, { success
: false }, { success
: true });
1797 assertSpyCalls(setter
, 2);
1798 assertSpyCall(setter
, 0, {
1802 assertSpyCall(setter
, 1, {
1808 it("[[Call]] walks the prototype chain", () => {
1809 const setter
= spy((_
) => {});
1810 const obj
= Object
.create(
1811 Object
.create(null, { success
: { set: setter
} }),
1813 setPropertyValues(obj
, { success
: true });
1814 assertSpyCalls(setter
, 1);
1815 assertSpyCall(setter
, 0, {
1821 it("[[Call]] throws if the property can’t be set", () => {
1822 const obj
= Object
.freeze({ failure
: undefined });
1823 assertThrows(() => setPropertyValues(obj
, { failure
: true }));
1826 it("[[Call]] returns the provided object", () => {
1828 assertStrictEquals(setPropertyValues(obj
, { "": undefined }), obj
);
1831 it("[[Construct]] throws an error", () => {
1832 assertThrows(() => new setPropertyValues(obj
, { "": undefined }));
1835 describe(".length", () => {
1836 it("[[Get]] returns the correct length", () => {
1837 assertStrictEquals(setPropertyValues
.length
, 2);
1841 describe(".name", () => {
1842 it("[[Get]] returns the correct name", () => {
1843 assertStrictEquals(setPropertyValues
.name
, "setPropertyValues");
1848 describe("setPrototype", () => {
1849 it("[[Call]] sets object prototypes", () => {
1852 setPrototype(obj
, proto
);
1853 assertStrictEquals(Object
.getPrototypeOf(obj
), proto
);
1856 it("[[Call]] sets null prototypes", () => {
1858 setPrototype(obj
, null);
1859 assertStrictEquals(Object
.getPrototypeOf(obj
), null);
1862 it("[[Call]] can set coercible primitives to their same prototype", () => {
1863 setPrototype(1, Number
.prototype);
1864 setPrototype(Symbol(), Symbol
.prototype);
1867 it("[[Call]] throws when setting coercible primitives to a different prototype", () => {
1868 assertThrows(() => setPrototype(1, Object
.prototype));
1869 assertThrows(() => setPrototype(Symbol(), Object
.prototype));
1872 it("[[Call]] throws for null and undefined", () => {
1873 assertThrows(() => setPrototype(null, Object
.prototype));
1874 assertThrows(() => setPrototype(undefined, Object
.prototype));
1877 it("[[Call]] returns the provided value", () => {
1879 assertStrictEquals(setPrototype(obj
, null), obj
);
1880 assertStrictEquals(setPrototype(1, Number
.prototype), 1);
1883 it("[[Construct]] throws an error", () => {
1884 assertThrows(() => new setPrototype({}, null));
1887 describe(".length", () => {
1888 it("[[Get]] returns the correct length", () => {
1889 assertStrictEquals(setPrototype
.length
, 2);
1893 describe(".name", () => {
1894 it("[[Get]] returns the correct name", () => {
1895 assertStrictEquals(setPrototype
.name
, "setPrototype");
1900 describe("toObject", () => {
1901 it("returns the input for objects", () => {
1903 assertStrictEquals(toObject(obj
), obj
);
1906 it("throws for nullish values", () => {
1907 assertThrows(() => toObject(null));
1908 assertThrows(() => toObject(void {}));
1911 it("returns a wrapper object for other primitives", () => {
1912 const sym
= Symbol();
1913 assertStrictEquals(typeof toObject(sym
), "object");
1914 assertStrictEquals(toObject(sym
).valueOf(), sym
);
1917 it("[[Construct]] throws an error", () => {
1918 assertThrows(() => new toObject({}));
1921 describe(".length", () => {
1922 it("[[Get]] returns the correct length", () => {
1923 assertStrictEquals(toObject
.length
, 1);
1927 describe(".name", () => {
1928 it("[[Get]] returns the correct name", () => {
1929 assertStrictEquals(toObject
.name
, "toObject");
1934 describe("toPropertyDescriptorRecord", () => {
1935 it("[[Call]] creates a new property descriptor record", () => {
1937 const desc
= toPropertyDescriptorRecord(obj
);
1938 assertEquals(obj
, desc
);
1939 assertNotStrictEquals(obj
, desc
);
1942 it("[[Call]] coerces the values", () => {
1944 toPropertyDescriptorRecord({
1945 configurable
: undefined,
1946 enumerable
: undefined,
1947 writable
: undefined,
1949 { configurable
: false, enumerable
: false, writable
: false },
1953 it("[[Construct]] throws for primitives", () => {
1954 assertThrows(() => toPropertyDescriptorRecord(undefined));
1955 assertThrows(() => toPropertyDescriptorRecord("failure"));
1958 it("[[Construct]] throws an error", () => {
1959 assertThrows(() => new toPropertyDescriptorRecord({}));
1962 describe(".length", () => {
1963 it("[[Get]] returns the correct length", () => {
1964 assertStrictEquals(toPropertyDescriptorRecord
.length
, 1);
1968 describe(".name", () => {
1969 it("[[Get]] returns the correct name", () => {
1971 toPropertyDescriptorRecord
.name
,
1972 "toPropertyDescriptorRecord",
1977 describe("~configurable", () => {
1978 it("[[DefineOwnProperty]] coerces to a boolean", () => {
1979 const desc
= toPropertyDescriptorRecord({});
1980 Object
.defineProperty(desc
, "configurable", {});
1981 assertStrictEquals(desc
.configurable
, false);
1984 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1985 const desc
= toPropertyDescriptorRecord({});
1987 Object
.defineProperty(desc
, "configurable", { get: undefined })
1991 it("[[Set]] coerces to a boolean", () => {
1992 const desc
= toPropertyDescriptorRecord({});
1993 desc
.configurable
= undefined;
1994 assertStrictEquals(desc
.configurable
, false);
1997 it("[[Delete]] works", () => {
1998 const desc
= toPropertyDescriptorRecord({ configurable
: false });
1999 delete desc
.configurable
;
2000 assert(!("configurable" in desc
));
2004 describe("~enumerable", () => {
2005 it("[[DefineOwnProperty]] coerces to a boolean", () => {
2006 const desc
= toPropertyDescriptorRecord({});
2007 Object
.defineProperty(desc
, "enumerable", {});
2008 assertStrictEquals(desc
.enumerable
, false);
2011 it("[[DefineOwnProperty]] throws for accessor properties", () => {
2012 const desc
= toPropertyDescriptorRecord({});
2014 Object
.defineProperty(desc
, "enumerable", { get: undefined })
2018 it("[[Set]] coerces to a boolean", () => {
2019 const desc
= toPropertyDescriptorRecord({});
2020 desc
.enumerable
= undefined;
2021 assertStrictEquals(desc
.enumerable
, false);
2024 it("[[Delete]] works", () => {
2025 const desc
= toPropertyDescriptorRecord({ enumerable
: false });
2026 delete desc
.enumerable
;
2027 assert(!("enumerable" in desc
));
2031 describe("~get", () => {
2032 it("[[DefineOwnProperty]] works", () => {
2033 const desc
= toPropertyDescriptorRecord({});
2034 Object
.defineProperty(desc
, "get", {});
2035 assertStrictEquals(desc
.get, undefined);
2038 it("[[DefineOwnProperty]] throws for accessor properties", () => {
2039 const desc
= toPropertyDescriptorRecord({});
2041 Object
.defineProperty(desc
, "get", { get: undefined })
2045 it("[[DefineOwnProperty]] throws if not callable or undefined", () => {
2046 const desc
= toPropertyDescriptorRecord({});
2048 () => Object
.defineProperty(desc
, "get", { value
: null }),
2052 it("[[DefineOwnProperty]] throws if a data property is defined", () => {
2053 const desc
= toPropertyDescriptorRecord({ value
: undefined });
2054 assertThrows(() => Object
.defineProperty(desc
, "get", {}));
2057 it("[[Set]] works", () => {
2058 const desc
= toPropertyDescriptorRecord({});
2059 const fn
= () => {};
2061 assertStrictEquals(desc
.get, fn
);
2064 it("[[Set]] throws if not callable or undefined", () => {
2065 const desc
= toPropertyDescriptorRecord({});
2066 assertThrows(() => desc
.get = null);
2069 it("[[Set]] throws if a data property is defined", () => {
2070 const desc
= toPropertyDescriptorRecord({ value
: undefined });
2071 assertThrows(() => desc
.get = undefined);
2074 it("[[Delete]] works", () => {
2075 const desc
= toPropertyDescriptorRecord({ get: undefined });
2077 assert(!("get" in desc
));
2081 describe("~set", () => {
2082 it("[[DefineOwnProperty]] works", () => {
2083 const desc
= toPropertyDescriptorRecord({});
2084 Object
.defineProperty(desc
, "set", {});
2085 assertStrictEquals(desc
.set, undefined);
2088 it("[[DefineOwnProperty]] throws for accessor properties", () => {
2089 const desc
= toPropertyDescriptorRecord({});
2091 Object
.defineProperty(desc
, "set", { get: undefined })
2095 it("[[DefineOwnProperty]] throws if not callable or undefined", () => {
2096 const desc
= toPropertyDescriptorRecord({});
2098 () => Object
.defineProperty(desc
, "set", { value
: null }),
2102 it("[[DefineOwnProperty]] throws if a data property is defined", () => {
2103 const desc
= toPropertyDescriptorRecord({ value
: undefined });
2104 assertThrows(() => Object
.defineProperty(desc
, "set", {}));
2107 it("[[Set]] works", () => {
2108 const desc
= toPropertyDescriptorRecord({});
2109 const fn
= (_
) => {};
2111 assertStrictEquals(desc
.set, fn
);
2114 it("[[Set]] throws if not callable or undefined", () => {
2115 const desc
= toPropertyDescriptorRecord({});
2116 assertThrows(() => desc
.set = null);
2119 it("[[Set]] throws if a data property is defined", () => {
2120 const desc
= toPropertyDescriptorRecord({ value
: undefined });
2121 assertThrows(() => desc
.set = undefined);
2124 it("[[Delete]] works", () => {
2125 const desc
= toPropertyDescriptorRecord({ set: undefined });
2127 assert(!("set" in desc
));
2131 describe("~value", () => {
2132 it("[[DefineOwnProperty]] works", () => {
2133 const desc
= toPropertyDescriptorRecord({});
2134 Object
.defineProperty(desc
, "value", {});
2135 assertStrictEquals(desc
.value
, undefined);
2138 it("[[DefineOwnProperty]] throws for accessor properties", () => {
2139 const desc
= toPropertyDescriptorRecord({});
2141 Object
.defineProperty(desc
, "value", { get: undefined })
2145 it("[[DefineOwnProperty]] throws if an accessor property is defined", () => {
2146 const desc
= toPropertyDescriptorRecord({ get: undefined });
2147 assertThrows(() => Object
.defineProperty(desc
, "value", {}));
2150 it("[[Set]] works", () => {
2151 const desc
= toPropertyDescriptorRecord({});
2152 desc
.value
= "success";
2153 assertStrictEquals(desc
.value
, "success");
2156 it("[[Set]] throws if an accessor property is defined", () => {
2157 const desc
= toPropertyDescriptorRecord({ get: undefined });
2158 assertThrows(() => desc
.value
= null);
2161 it("[[Delete]] works", () => {
2162 const desc
= toPropertyDescriptorRecord({ value
: undefined });
2164 assert(!("value" in desc
));
2168 describe("~writable", () => {
2169 it("[[DefineOwnProperty]] coerces to a boolean", () => {
2170 const desc
= toPropertyDescriptorRecord({});
2171 Object
.defineProperty(desc
, "writable", {});
2172 assertStrictEquals(desc
.writable
, false);
2175 it("[[DefineOwnProperty]] throws for accessor properties", () => {
2176 const desc
= toPropertyDescriptorRecord({});
2178 Object
.defineProperty(desc
, "writable", { get: undefined })
2182 it("[[DefineOwnProperty]] throws if an accessor property is defined", () => {
2183 const desc
= toPropertyDescriptorRecord({ get: undefined });
2184 assertThrows(() => Object
.defineProperty(desc
, "writable", {}));
2187 it("[[Set]] coerces to a boolean", () => {
2188 const desc
= toPropertyDescriptorRecord({});
2189 desc
.writable
= undefined;
2190 assertStrictEquals(desc
.writable
, false);
2193 it("[[Set]] throws if an accessor property is defined", () => {
2194 const desc
= toPropertyDescriptorRecord({ get: undefined });
2195 assertThrows(() => desc
.writable
= false);
2198 it("[[Delete]] works", () => {
2199 const desc
= toPropertyDescriptorRecord({ writable
: false });
2200 delete desc
.writable
;
2201 assert(!("writable" in desc
));