1 // ♓🌟 Piscēs ∷ value.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
,
18 } from "./dev-deps.js";
21 completePropertyDescriptor
,
26 isFullyPopulatedDescriptor
,
28 isPropertyDescriptorRecord
,
37 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
39 MINIMUM_SAFE_INTEGRAL_NUMBER
,
69 describe("ASYNC_ITERATOR", () => {
70 it("[[Get]] is @@asyncIterator", () => {
71 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
75 describe("HAS_INSTANCE", () => {
76 it("[[Get]] is @@hasInstance", () => {
77 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
81 describe("IS_CONCAT_SPREADABLE", () => {
82 it("[[Get]] is @@isConcatSpreadable", () => {
85 Symbol
.isConcatSpreadable
,
90 describe("ITERATOR", () => {
91 it("[[Get]] is @@iterator", () => {
92 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
96 describe("LN10", () => {
97 it("[[Get]] is ln(10)", () => {
98 assertStrictEquals(LN10
, Math
.LN10
);
102 describe("LN2", () => {
103 it("[[Get]] is ln(2)", () => {
104 assertStrictEquals(LN2
, Math
.LN2
);
108 describe("LOG10ℇ", () => {
109 it("[[Get]] is log10(ℇ)", () => {
110 assertStrictEquals(LOG10
ℇ, Math
.LOG10E
);
114 describe("LOG2ℇ", () => {
115 it("[[Get]] is log2(ℇ)", () => {
116 assertStrictEquals(LOG2
ℇ, Math
.LOG2E
);
120 describe("MATCH", () => {
121 it("[[Get]] is @@match", () => {
122 assertStrictEquals(MATCH
, Symbol
.match
);
126 describe("MATCH_ALL", () => {
127 it("[[Get]] is @@matchAll", () => {
128 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
132 describe("MAXIMUM_NUMBER", () => {
133 it("[[Get]] is the maximum number", () => {
134 assertStrictEquals(MAXIMUM_NUMBER
, Number
.MAX_VALUE
);
138 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
139 it("[[Get]] is the maximum safe integral number", () => {
141 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
142 Number
.MAX_SAFE_INTEGER
,
147 describe("MINIMUM_NUMBER", () => {
148 it("[[Get]] is the minimum number", () => {
149 assertStrictEquals(MINIMUM_NUMBER
, Number
.MIN_VALUE
);
153 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
154 it("[[Get]] is the minimum safe integral number", () => {
156 MINIMUM_SAFE_INTEGRAL_NUMBER
,
157 Number
.MIN_SAFE_INTEGER
,
162 describe("NAN", () => {
163 it("[[Get]] is nan", () => {
164 assertStrictEquals(NAN
, NaN
);
168 describe("NEGATIVE_INFINITY", () => {
169 it("[[Get]] is negative infinity", () => {
170 assertStrictEquals(NEGATIVE_INFINITY
, -Infinity
);
174 describe("NEGATIVE_ZERO", () => {
175 it("[[Get]] is negative zero", () => {
176 assertStrictEquals(NEGATIVE_ZERO
, -0);
180 describe("NULL", () => {
181 it("[[Get]] is null", () => {
182 assertStrictEquals(NULL
, null);
186 describe("POSITIVE_INFINITY", () => {
187 it("[[Get]] is negative infinity", () => {
188 assertStrictEquals(POSITIVE_INFINITY
, Infinity
);
192 describe("POSITIVE_ZERO", () => {
193 it("[[Get]] is positive zero", () => {
194 assertStrictEquals(POSITIVE_ZERO
, 0);
198 describe("RECIPROCAL_SQRT2", () => {
199 it("[[Get]] is sqrt(½)", () => {
200 assertStrictEquals(RECIPROCAL_SQRT2
, Math
.SQRT1_2
);
204 describe("REPLACE", () => {
205 it("[[Get]] is @@replace", () => {
206 assertStrictEquals(REPLACE
, Symbol
.replace
);
210 describe("SPECIES", () => {
211 it("[[Get]] is @@species", () => {
212 assertStrictEquals(SPECIES
, Symbol
.species
);
216 describe("SPLIT", () => {
217 it("[[Get]] is @@split", () => {
218 assertStrictEquals(SPLIT
, Symbol
.split
);
222 describe("SQRT2", () => {
223 it("[[Get]] is sqrt(2)", () => {
224 assertStrictEquals(SQRT2
, Math
.SQRT2
);
228 describe("TO_PRIMITIVE", () => {
229 it("[[Get]] is @@toPrimitive", () => {
230 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
234 describe("TO_STRING_TAG", () => {
235 it("[[Get]] is @@toStringTag", () => {
236 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
240 describe("UNDEFINED", () => {
241 it("[[Get]] is undefined", () => {
242 assertStrictEquals(UNDEFINED
, void {});
246 describe("UNSCOPABLES", () => {
247 it("[[Get]] is @@unscopables", () => {
248 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
252 describe("completePropertyDescriptor", () => {
253 it("[[Call]] completes a generic descriptor", () => {
255 completePropertyDescriptor(desc
);
264 it("[[Call]] completes a data descriptor", () => {
265 const desc
= { value
: undefined };
266 completePropertyDescriptor(desc
);
275 it("[[Call]] completes an accessor descriptor", () => {
276 const desc
= { get: undefined };
277 completePropertyDescriptor(desc
);
286 it("[[Call]] throws an error when the descriptor is undefined", () => {
287 assertThrows(() => new completePropertyDescriptor(undefined));
290 it("[[Construct]] throws an error", () => {
291 assertThrows(() => new completePropertyDescriptor({}));
294 describe(".length", () => {
295 it("[[Get]] returns the correct length", () => {
296 assertStrictEquals(completePropertyDescriptor
.length
, 1);
300 describe(".name", () => {
301 it("[[Get]] returns the correct name", () => {
303 completePropertyDescriptor
.name
,
304 "completePropertyDescriptor",
310 describe("isAccessorDescriptor", () => {
311 it("[[Call]] returns false for a generic descriptor", () => {
312 assertStrictEquals(isAccessorDescriptor({}), false);
315 it("[[Get]] returns false for a data descriptor", () => {
317 isAccessorDescriptor({ value
: undefined }),
321 isAccessorDescriptor({ writable
: undefined }),
326 it("[[Get]] returns true for an accessor descriptor", () => {
327 assertStrictEquals(isAccessorDescriptor({ get: undefined }), true);
328 assertStrictEquals(isAccessorDescriptor({ set: undefined }), true);
331 it("[[Get]] returns false for undefined", () => {
332 assertStrictEquals(isAccessorDescriptor(undefined), false);
335 it("[[Construct]] throws an error", () => {
336 assertThrows(() => new isAccessorDescriptor({}));
339 describe(".length", () => {
340 it("[[Get]] returns the correct length", () => {
341 assertStrictEquals(isAccessorDescriptor
.length
, 1);
345 describe(".name", () => {
346 it("[[Get]] returns the correct name", () => {
348 isAccessorDescriptor
.name
,
349 "isAccessorDescriptor",
355 describe("isDataDescriptor", () => {
356 it("[[Call]] returns false for a generic descriptor", () => {
357 assertStrictEquals(isDataDescriptor({}), false);
360 it("[[Get]] returns true for a data descriptor", () => {
361 assertStrictEquals(isDataDescriptor({ value
: undefined }), true);
362 assertStrictEquals(isDataDescriptor({ writable
: true }), true);
365 it("[[Get]] returns false for an accessor descriptor", () => {
366 assertStrictEquals(isDataDescriptor({ get: undefined }), false);
367 assertStrictEquals(isDataDescriptor({ set: undefined }), false);
370 it("[[Get]] returns false for undefined", () => {
371 assertStrictEquals(isDataDescriptor(undefined), false);
374 it("[[Construct]] throws an error", () => {
375 assertThrows(() => new isDataDescriptor({}));
378 describe(".length", () => {
379 it("[[Get]] returns the correct length", () => {
380 assertStrictEquals(isDataDescriptor
.length
, 1);
384 describe(".name", () => {
385 it("[[Get]] returns the correct name", () => {
386 assertStrictEquals(isDataDescriptor
.name
, "isDataDescriptor");
391 describe("isFullyPopulatedDescriptor", () => {
392 it("[[Call]] returns false for a generic descriptor", () => {
393 assertStrictEquals(isFullyPopulatedDescriptor({}), false);
396 it("[[Get]] returns false for a non‐fully‐populated data descriptor", () => {
398 isFullyPopulatedDescriptor({ value
: undefined }),
402 isFullyPopulatedDescriptor({ writable
: true }),
407 it("[[Get]] returns true for a fully‐populated data descriptor", () => {
409 isFullyPopulatedDescriptor({
419 it("[[Get]] returns false for a non‐fully‐populated accessor descriptor", () => {
421 isFullyPopulatedDescriptor({ get: undefined }),
425 isFullyPopulatedDescriptor({ set: undefined }),
430 it("[[Get]] returns true for a fully‐populated accessor descriptor", () => {
432 isFullyPopulatedDescriptor({
442 it("[[Get]] returns false for undefined", () => {
443 assertStrictEquals(isFullyPopulatedDescriptor(undefined), false);
446 it("[[Construct]] throws an error", () => {
447 assertThrows(() => new isFullyPopulatedDescriptor({}));
450 describe(".length", () => {
451 it("[[Get]] returns the correct length", () => {
452 assertStrictEquals(isFullyPopulatedDescriptor
.length
, 1);
456 describe(".name", () => {
457 it("[[Get]] returns the correct name", () => {
459 isFullyPopulatedDescriptor
.name
,
460 "isFullyPopulatedDescriptor",
466 describe("isGenericDescriptor", () => {
467 it("[[Call]] returns true for a generic descriptor", () => {
468 assertStrictEquals(isGenericDescriptor({}), true);
471 it("[[Get]] returns false for a data descriptor", () => {
473 isGenericDescriptor({ value
: undefined }),
476 assertStrictEquals(isGenericDescriptor({ writable
: true }), false);
479 it("[[Get]] returns false for an accessor descriptor", () => {
480 assertStrictEquals(isGenericDescriptor({ get: undefined }), false);
481 assertStrictEquals(isGenericDescriptor({ set: undefined }), false);
484 it("[[Get]] returns false for undefined", () => {
485 assertStrictEquals(isGenericDescriptor(undefined), false);
488 it("[[Construct]] throws an error", () => {
489 assertThrows(() => new isGenericDescriptor({}));
492 describe(".length", () => {
493 it("[[Get]] returns the correct length", () => {
494 assertStrictEquals(isGenericDescriptor
.length
, 1);
498 describe(".name", () => {
499 it("[[Get]] returns the correct name", () => {
501 isGenericDescriptor
.name
,
502 "isGenericDescriptor",
508 describe("isPropertyDescriptorRecord", () => {
509 it("[[Call]] returns true for objects created by toPropertyDescriptor", () => {
511 isPropertyDescriptorRecord(toPropertyDescriptor({})),
516 it("[[Get]] returns false for other objects", () => {
518 isPropertyDescriptorRecord(Object
.create(null)),
523 it("[[Get]] returns false for undefined", () => {
524 assertStrictEquals(isPropertyDescriptorRecord(undefined), false);
527 it("[[Construct]] throws an error", () => {
528 assertThrows(() => new isPropertyDescriptorRecord({}));
531 describe(".length", () => {
532 it("[[Get]] returns the correct length", () => {
533 assertStrictEquals(isPropertyDescriptorRecord
.length
, 1);
537 describe(".name", () => {
538 it("[[Get]] returns the correct name", () => {
540 isPropertyDescriptorRecord
.name
,
541 "isPropertyDescriptorRecord",
547 describe("ordinaryToPrimitive", () => {
548 it("[[Call]] prefers `valueOf` by default", () => {
557 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
558 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
561 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
570 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
573 it('[[Call]] prefers `toString` for a "string" hint', () => {
582 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
585 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
592 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
595 it("[[Call]] falls back to the other method if the first returns an object", () => {
601 return new String("failure");
604 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
607 it("[[Call]] throws an error if neither method is callable", () => {
612 assertThrows(() => ordinaryToPrimitive(obj
));
615 it("[[Call]] throws an error if neither method returns an object", () => {
618 return new String("failure");
621 return new String("failure");
624 assertThrows(() => ordinaryToPrimitive(obj
));
627 it("[[Construct]] throws an error", () => {
628 assertThrows(() => new ordinaryToPrimitive(""));
631 describe(".length", () => {
632 it("[[Get]] returns the correct length", () => {
633 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
637 describe(".name", () => {
638 it("[[Get]] returns the correct name", () => {
640 ordinaryToPrimitive
.name
,
641 "ordinaryToPrimitive",
647 describe("sameValue", () => {
648 it("[[Call]] returns false for null 🆚 undefined", () => {
649 assertStrictEquals(sameValue(null, undefined), false);
652 it("[[Call]] returns false for null 🆚 an object", () => {
653 assertStrictEquals(sameValue(null, {}), false);
656 it("[[Call]] returns true for null 🆚 null", () => {
657 assertStrictEquals(sameValue(null, null), true);
660 it("[[Call]] returns false for two different objects", () => {
661 assertStrictEquals(sameValue({}, {}), false);
664 it("[[Call]] returns true for the same object", () => {
666 assertStrictEquals(sameValue(obj
, obj
), true);
669 it("[[Call]] returns false for ±0", () => {
670 assertStrictEquals(sameValue(0, -0), false);
673 it("[[Call]] returns true for -0", () => {
674 assertStrictEquals(sameValue(-0, -0), true);
677 it("[[Call]] returns true for nan", () => {
678 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
681 it("[[Call]] returns false for a primitive and its wrapped object", () => {
682 assertStrictEquals(sameValue(false, new Boolean(false)), false);
685 it("[[Construct]] throws an error", () => {
686 assertThrows(() => new sameValue(true, true));
689 describe(".length", () => {
690 it("[[Get]] returns the correct length", () => {
691 assertStrictEquals(sameValue
.length
, 2);
695 describe(".name", () => {
696 it("[[Get]] returns the correct name", () => {
697 assertStrictEquals(sameValue
.name
, "sameValue");
702 describe("sameValueZero", () => {
703 it("[[Call]] returns false for null 🆚 undefined", () => {
704 assertStrictEquals(sameValueZero(null, undefined), false);
707 it("[[Call]] returns false for null 🆚 an object", () => {
708 assertStrictEquals(sameValueZero(null, {}), false);
711 it("[[Call]] returns true for null 🆚 null", () => {
712 assertStrictEquals(sameValueZero(null, null), true);
715 it("[[Call]] returns false for two different objects", () => {
716 assertStrictEquals(sameValueZero({}, {}), false);
719 it("[[Call]] returns true for the same object", () => {
721 assertStrictEquals(sameValueZero(obj
, obj
), true);
724 it("[[Call]] returns true for ±0", () => {
725 assertStrictEquals(sameValueZero(0, -0), true);
728 it("[[Call]] returns true for -0", () => {
729 assertStrictEquals(sameValueZero(-0, -0), true);
732 it("[[Call]] returns true for nan", () => {
733 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
736 it("[[Call]] returns false for a primitive and its wrapped object", () => {
738 sameValueZero(false, new Boolean(false)),
743 it("[[Construct]] throws an error", () => {
744 assertThrows(() => new sameValueZero(true, true));
747 describe(".length", () => {
748 it("[[Get]] returns the correct length", () => {
749 assertStrictEquals(sameValueZero
.length
, 2);
753 describe(".name", () => {
754 it("[[Get]] returns the correct name", () => {
755 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
760 describe("toFunctionName", () => {
761 it("[[Call]] works with strings and no prefix", () => {
762 assertStrictEquals(toFunctionName("etaoin"), "etaoin");
765 it("[[Call]] works with objects and no prefix", () => {
776 it("[[Call]] works with descriptionless symbols and no prefix", () => {
777 assertStrictEquals(toFunctionName(Symbol()), "");
780 it("[[Call]] works with empty description symbols and no prefix", () => {
781 assertStrictEquals(toFunctionName(Symbol("")), "[]");
784 it("[[Call]] works with described symbols and no prefix", () => {
785 assertStrictEquals(toFunctionName(Symbol("etaoin")), "[etaoin]");
788 it("[[Call]] works with strings and a prefix", () => {
789 assertStrictEquals(toFunctionName("etaoin", "foo"), "foo etaoin");
792 it("[[Call]] works with objects and no prefix", () => {
803 it("[[Call]] works with descriptionless symbols and no prefix", () => {
804 assertStrictEquals(toFunctionName(Symbol(), "foo"), "foo ");
807 it("[[Call]] works with empty description symbols and no prefix", () => {
808 assertStrictEquals(toFunctionName(Symbol(""), "foo"), "foo []");
811 it("[[Call]] works with described symbols and no prefix", () => {
813 toFunctionName(Symbol("etaoin"), "foo"),
818 it("[[Construct]] throws an error", () => {
819 assertThrows(() => new toFunctionName(""));
822 describe(".length", () => {
823 it("[[Get]] returns the correct length", () => {
824 assertStrictEquals(toFunctionName
.length
, 1);
828 describe(".name", () => {
829 it("[[Get]] returns the correct name", () => {
838 describe("toIndex", () => {
839 it("[[Call]] returns an index", () => {
840 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
843 it("[[Call]] returns zero for a zerolike argument", () => {
844 assertStrictEquals(toIndex(NaN
), 0);
845 assertStrictEquals(toIndex("failure"), 0);
846 assertStrictEquals(toIndex(-0), 0);
849 it("[[Call]] rounds down to the nearest integer", () => {
850 assertStrictEquals(toIndex(0.25), 0);
851 assertStrictEquals(toIndex(1.1), 1);
854 it("[[Call]] throws when provided a negative number", () => {
855 assertThrows(() => toIndex(-1));
856 assertThrows(() => toIndex(-Infinity
));
859 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
860 assertThrows(() => toIndex(9007199254740992));
861 assertThrows(() => toIndex(Infinity
));
864 it("[[Construct]] throws an error", () => {
865 assertThrows(() => new toIndex(0));
868 describe(".length", () => {
869 it("[[Get]] returns the correct length", () => {
870 assertStrictEquals(toIndex
.length
, 1);
874 describe(".name", () => {
875 it("[[Get]] returns the correct name", () => {
876 assertStrictEquals(toIndex
.name
, "toIndex");
881 describe("toLength", () => {
882 it("[[Call]] returns a length", () => {
883 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
886 it("[[Call]] returns zero for a nan argument", () => {
887 assertStrictEquals(toLength(NaN
), 0);
888 assertStrictEquals(toLength("failure"), 0);
891 it("[[Call]] rounds down to the nearest integer", () => {
892 assertStrictEquals(toLength(0.25), 0);
893 assertStrictEquals(toLength(1.1), 1);
896 it("[[Call]] returns a result greater than or equal to zero", () => {
897 assertStrictEquals(toLength(-0), 0);
898 assertStrictEquals(toLength(-1), 0);
899 assertStrictEquals(toLength(-Infinity
), 0);
902 it("[[Call]] returns a result less than 2 ** 53", () => {
903 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
904 assertStrictEquals(toLength(Infinity
), 9007199254740991);
907 it("[[Construct]] throws an error", () => {
908 assertThrows(() => new toLength(0));
911 describe(".length", () => {
912 it("[[Get]] returns the correct length", () => {
913 assertStrictEquals(toLength
.length
, 1);
917 describe(".name", () => {
918 it("[[Get]] returns the correct name", () => {
919 assertStrictEquals(toLength
.name
, "toLength");
924 describe("toPrimitive", () => {
925 it("[[Call]] returns the argument when passed a primitive", () => {
926 const value
= Symbol();
927 assertStrictEquals(toPrimitive(value
), value
);
930 it("[[Call]] works with nullish values", () => {
931 assertStrictEquals(toPrimitive(null), null);
932 assertStrictEquals(toPrimitive(), void {});
935 it("[[Call]] calls ordinaryToPrimitive by default", () => {
936 const value
= Object
.assign(
944 assertStrictEquals(toPrimitive(value
), "success");
947 it("[[Call]] accepts a hint", () => {
948 const value
= Object
.assign(
959 assertStrictEquals(toPrimitive(value
, "string"), "success");
962 it("[[Call]] uses the exotic toPrimitive method if available", () => {
963 const value
= Object
.assign(
966 [Symbol
.toPrimitive
]() {
971 assertStrictEquals(toPrimitive(value
), "success");
974 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
975 const value
= Object
.assign(
978 [Symbol
.toPrimitive
](hint
) {
979 return hint
=== "string" ? "success" : "failure";
983 assertStrictEquals(toPrimitive(value
, "string"), "success");
986 it('[[Call]] passes a "default" hint by default', () => {
987 const value
= Object
.assign(
990 [Symbol
.toPrimitive
](hint
) {
991 return hint
=== "default" ? "success" : "failure";
995 assertStrictEquals(toPrimitive(value
), "success");
998 it("[[Call]] throws for an invalid hint", () => {
999 const value1
= Object
.assign(
1000 Object
.create(null),
1002 [Symbol
.toPrimitive
]() {
1007 const value2
= Object
.assign(
1008 Object
.create(null),
1015 assertThrows(() => toPrimitive(value1
, "badhint"));
1016 assertThrows(() => toPrimitive(value2
, "badhint"));
1017 assertThrows(() => toPrimitive(true, "badhint"));
1020 it("[[Construct]] throws an error", () => {
1021 assertThrows(() => new toPrimitive(true));
1024 describe(".length", () => {
1025 it("[[Get]] returns the correct length", () => {
1026 assertStrictEquals(toPrimitive
.length
, 1);
1030 describe(".name", () => {
1031 it("[[Get]] returns the correct name", () => {
1032 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
1037 describe("toPropertyDescriptor", () => {
1038 it("[[Call]] creates a new property descriptor record", () => {
1040 const desc
= toPropertyDescriptor(obj
);
1041 assertEquals(obj
, desc
);
1042 assertNotStrictEquals(obj
, desc
);
1045 it("[[Call]] coerces the values", () => {
1047 toPropertyDescriptor({
1048 configurable
: undefined,
1049 enumerable
: undefined,
1050 writable
: undefined,
1052 { configurable
: false, enumerable
: false, writable
: false },
1056 it("[[Construct]] throws for primitives", () => {
1057 assertThrows(() => toPropertyDescriptor(undefined));
1058 assertThrows(() => toPropertyDescriptor("failure"));
1061 it("[[Construct]] throws an error", () => {
1062 assertThrows(() => new toPropertyDescriptor({}));
1065 describe(".length", () => {
1066 it("[[Get]] returns the correct length", () => {
1067 assertStrictEquals(toPropertyDescriptor
.length
, 1);
1071 describe(".name", () => {
1072 it("[[Get]] returns the correct name", () => {
1074 toPropertyDescriptor
.name
,
1075 "toPropertyDescriptor",
1080 describe("~configurable", () => {
1081 it("[[DefineOwnProperty]] coerces to a boolean", () => {
1082 const desc
= toPropertyDescriptor({});
1083 Object
.defineProperty(desc
, "configurable", {});
1084 assertStrictEquals(desc
.configurable
, false);
1087 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1088 const desc
= toPropertyDescriptor({});
1090 Object
.defineProperty(desc
, "configurable", { get: undefined })
1094 it("[[Set]] coerces to a boolean", () => {
1095 const desc
= toPropertyDescriptor({});
1096 desc
.configurable
= undefined;
1097 assertStrictEquals(desc
.configurable
, false);
1100 it("[[Delete]] works", () => {
1101 const desc
= toPropertyDescriptor({ configurable
: false });
1102 delete desc
.configurable
;
1103 assert(!("configurable" in desc
));
1107 describe("~enumerable", () => {
1108 it("[[DefineOwnProperty]] coerces to a boolean", () => {
1109 const desc
= toPropertyDescriptor({});
1110 Object
.defineProperty(desc
, "enumerable", {});
1111 assertStrictEquals(desc
.enumerable
, false);
1114 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1115 const desc
= toPropertyDescriptor({});
1117 Object
.defineProperty(desc
, "enumerable", { get: undefined })
1121 it("[[Set]] coerces to a boolean", () => {
1122 const desc
= toPropertyDescriptor({});
1123 desc
.enumerable
= undefined;
1124 assertStrictEquals(desc
.enumerable
, false);
1127 it("[[Delete]] works", () => {
1128 const desc
= toPropertyDescriptor({ enumerable
: false });
1129 delete desc
.enumerable
;
1130 assert(!("enumerable" in desc
));
1134 describe("~get", () => {
1135 it("[[DefineOwnProperty]] works", () => {
1136 const desc
= toPropertyDescriptor({});
1137 Object
.defineProperty(desc
, "get", {});
1138 assertStrictEquals(desc
.get, undefined);
1141 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1142 const desc
= toPropertyDescriptor({});
1144 Object
.defineProperty(desc
, "get", { get: undefined })
1148 it("[[DefineOwnProperty]] throws if not callable or undefined", () => {
1149 const desc
= toPropertyDescriptor({});
1151 () => Object
.defineProperty(desc
, "get", { value
: null }),
1155 it("[[DefineOwnProperty]] throws if a data property is defined", () => {
1156 const desc
= toPropertyDescriptor({ value
: undefined });
1157 assertThrows(() => Object
.defineProperty(desc
, "get", {}));
1160 it("[[Set]] works", () => {
1161 const desc
= toPropertyDescriptor({});
1162 const fn
= () => {};
1164 assertStrictEquals(desc
.get, fn
);
1167 it("[[Set]] throws if not callable or undefined", () => {
1168 const desc
= toPropertyDescriptor({});
1169 assertThrows(() => desc
.get = null);
1172 it("[[Set]] throws if a data property is defined", () => {
1173 const desc
= toPropertyDescriptor({ value
: undefined });
1174 assertThrows(() => desc
.get = undefined);
1177 it("[[Delete]] works", () => {
1178 const desc
= toPropertyDescriptor({ get: undefined });
1180 assert(!("get" in desc
));
1184 describe("~set", () => {
1185 it("[[DefineOwnProperty]] works", () => {
1186 const desc
= toPropertyDescriptor({});
1187 Object
.defineProperty(desc
, "set", {});
1188 assertStrictEquals(desc
.set, undefined);
1191 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1192 const desc
= toPropertyDescriptor({});
1194 Object
.defineProperty(desc
, "set", { get: undefined })
1198 it("[[DefineOwnProperty]] throws if not callable or undefined", () => {
1199 const desc
= toPropertyDescriptor({});
1201 () => Object
.defineProperty(desc
, "set", { value
: null }),
1205 it("[[DefineOwnProperty]] throws if a data property is defined", () => {
1206 const desc
= toPropertyDescriptor({ value
: undefined });
1207 assertThrows(() => Object
.defineProperty(desc
, "set", {}));
1210 it("[[Set]] works", () => {
1211 const desc
= toPropertyDescriptor({});
1212 const fn
= (_
) => {};
1214 assertStrictEquals(desc
.set, fn
);
1217 it("[[Set]] throws if not callable or undefined", () => {
1218 const desc
= toPropertyDescriptor({});
1219 assertThrows(() => desc
.set = null);
1222 it("[[Set]] throws if a data property is defined", () => {
1223 const desc
= toPropertyDescriptor({ value
: undefined });
1224 assertThrows(() => desc
.set = undefined);
1227 it("[[Delete]] works", () => {
1228 const desc
= toPropertyDescriptor({ set: undefined });
1230 assert(!("set" in desc
));
1234 describe("~value", () => {
1235 it("[[DefineOwnProperty]] works", () => {
1236 const desc
= toPropertyDescriptor({});
1237 Object
.defineProperty(desc
, "value", {});
1238 assertStrictEquals(desc
.value
, undefined);
1241 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1242 const desc
= toPropertyDescriptor({});
1244 Object
.defineProperty(desc
, "value", { get: undefined })
1248 it("[[DefineOwnProperty]] throws if an accessor property is defined", () => {
1249 const desc
= toPropertyDescriptor({ get: undefined });
1250 assertThrows(() => Object
.defineProperty(desc
, "value", {}));
1253 it("[[Set]] works", () => {
1254 const desc
= toPropertyDescriptor({});
1255 desc
.value
= "success";
1256 assertStrictEquals(desc
.value
, "success");
1259 it("[[Set]] throws if an accessor property is defined", () => {
1260 const desc
= toPropertyDescriptor({ get: undefined });
1261 assertThrows(() => desc
.value
= null);
1264 it("[[Delete]] works", () => {
1265 const desc
= toPropertyDescriptor({ value
: undefined });
1267 assert(!("value" in desc
));
1271 describe("~writable", () => {
1272 it("[[DefineOwnProperty]] coerces to a boolean", () => {
1273 const desc
= toPropertyDescriptor({});
1274 Object
.defineProperty(desc
, "writable", {});
1275 assertStrictEquals(desc
.writable
, false);
1278 it("[[DefineOwnProperty]] throws for accessor properties", () => {
1279 const desc
= toPropertyDescriptor({});
1281 Object
.defineProperty(desc
, "writable", { get: undefined })
1285 it("[[DefineOwnProperty]] throws if an accessor property is defined", () => {
1286 const desc
= toPropertyDescriptor({ get: undefined });
1287 assertThrows(() => Object
.defineProperty(desc
, "writable", {}));
1290 it("[[Set]] coerces to a boolean", () => {
1291 const desc
= toPropertyDescriptor({});
1292 desc
.writable
= undefined;
1293 assertStrictEquals(desc
.writable
, false);
1296 it("[[Set]] throws if an accessor property is defined", () => {
1297 const desc
= toPropertyDescriptor({ get: undefined });
1298 assertThrows(() => desc
.writable
= false);
1301 it("[[Delete]] works", () => {
1302 const desc
= toPropertyDescriptor({ writable
: false });
1303 delete desc
.writable
;
1304 assert(!("writable" in desc
));
1309 describe("type", () => {
1310 it('[[Call]] returns "null" for null', () => {
1311 assertStrictEquals(type(null), "null");
1314 it('[[Call]] returns "undefined" for undefined', () => {
1315 assertStrictEquals(type(void {}), "undefined");
1318 it('[[Call]] returns "object" for non‐callable objects', () => {
1319 assertStrictEquals(type(Object
.create(null)), "object");
1322 it('[[Call]] returns "object" for callable objects', () => {
1323 assertStrictEquals(type(() => {}), "object");
1326 it('[[Call]] returns "object" for constructable objects', () => {
1327 assertStrictEquals(type(class {}), "object");
1330 it("[[Construct]] throws an error", () => {
1331 assertThrows(() => new type({}));
1334 describe(".length", () => {
1335 it("[[Get]] returns the correct length", () => {
1336 assertStrictEquals(type
.length
, 1);
1340 describe(".name", () => {
1341 it("[[Get]] returns the correct name", () => {
1342 assertStrictEquals(type
.name
, "type");
1347 describe("Ε", () => {
1348 it("[[Get]] is ε", () => {
1349 assertStrictEquals(Ε, Number
.EPSILON
);
1353 describe("Π", () => {
1354 it("[[Get]] is π", () => {
1355 assertStrictEquals(Π, Math
.PI
);
1359 describe("ℇ", () => {
1360 it("[[Get]] is ℇ", () => {
1361 assertStrictEquals(ℇ, Math
.E
);