1 // SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: MPL-2.0
4 * β βπ PiscΔs β· value.test.js
6 * Copyright Β© 2022β2023, 2025 Lady [@ Ladys Computer].
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
19 } from "./dev-deps.js";
22 canonicalNumericIndexSting
,
23 completePropertyDescriptor
,
29 isFullyPopulatedDescriptor
,
40 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
42 MINIMUM_SAFE_INTEGRAL_NUMBER
,
72 describe("ASYNC_ITERATOR", () => {
73 it("[[Get]] is @@asyncIterator", () => {
74 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
78 describe("HAS_INSTANCE", () => {
79 it("[[Get]] is @@hasInstance", () => {
80 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
84 describe("IS_CONCAT_SPREADABLE", () => {
85 it("[[Get]] is @@isConcatSpreadable", () => {
88 Symbol
.isConcatSpreadable
,
93 describe("ITERATOR", () => {
94 it("[[Get]] is @@iterator", () => {
95 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
99 describe("LN_10", () => {
100 it("[[Get]] is ln(10)", () => {
101 assertStrictEquals(LN_10
, Math
.LN10
);
105 describe("LN_2", () => {
106 it("[[Get]] is ln(2)", () => {
107 assertStrictEquals(LN_2
, Math
.LN2
);
111 describe("LOG10_π", () => {
112 it("[[Get]] is log10(π)", () => {
113 assertStrictEquals(LOG10_
π, Math
.LOG10E
);
117 describe("LOG2_π", () => {
118 it("[[Get]] is log2(β)", () => {
119 assertStrictEquals(LOG2_
π, Math
.LOG2E
);
123 describe("MATCH", () => {
124 it("[[Get]] is @@match", () => {
125 assertStrictEquals(MATCH
, Symbol
.match
);
129 describe("MATCH_ALL", () => {
130 it("[[Get]] is @@matchAll", () => {
131 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
135 describe("MAXIMUM_NUMBER", () => {
136 it("[[Get]] is the maximum number", () => {
137 assertStrictEquals(MAXIMUM_NUMBER
, Number
.MAX_VALUE
);
141 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
142 it("[[Get]] is the maximum safe integral number", () => {
144 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
145 Number
.MAX_SAFE_INTEGER
,
150 describe("MINIMUM_NUMBER", () => {
151 it("[[Get]] is the minimum number", () => {
152 assertStrictEquals(MINIMUM_NUMBER
, Number
.MIN_VALUE
);
156 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
157 it("[[Get]] is the minimum safe integral number", () => {
159 MINIMUM_SAFE_INTEGRAL_NUMBER
,
160 Number
.MIN_SAFE_INTEGER
,
165 describe("NAN", () => {
166 it("[[Get]] is nan", () => {
167 assertStrictEquals(NAN
, NaN
);
171 describe("NEGATIVE_INFINITY", () => {
172 it("[[Get]] is negative infinity", () => {
173 assertStrictEquals(NEGATIVE_INFINITY
, -Infinity
);
177 describe("NEGATIVE_ZERO", () => {
178 it("[[Get]] is negative zero", () => {
179 assertStrictEquals(NEGATIVE_ZERO
, -0);
183 describe("NULL", () => {
184 it("[[Get]] is null", () => {
185 assertStrictEquals(NULL
, null);
189 describe("POSITIVE_INFINITY", () => {
190 it("[[Get]] is negative infinity", () => {
191 assertStrictEquals(POSITIVE_INFINITY
, Infinity
);
195 describe("POSITIVE_ZERO", () => {
196 it("[[Get]] is positive zero", () => {
197 assertStrictEquals(POSITIVE_ZERO
, 0);
201 describe("RECIPROCAL_SQRT_2", () => {
202 it("[[Get]] is sqrt(Β½)", () => {
203 assertStrictEquals(RECIPROCAL_SQRT_2
, Math
.SQRT1_2
);
207 describe("REPLACE", () => {
208 it("[[Get]] is @@replace", () => {
209 assertStrictEquals(REPLACE
, Symbol
.replace
);
213 describe("SPECIES", () => {
214 it("[[Get]] is @@species", () => {
215 assertStrictEquals(SPECIES
, Symbol
.species
);
219 describe("SPLIT", () => {
220 it("[[Get]] is @@split", () => {
221 assertStrictEquals(SPLIT
, Symbol
.split
);
225 describe("SQRT_2", () => {
226 it("[[Get]] is sqrt(2)", () => {
227 assertStrictEquals(SQRT_2
, Math
.SQRT2
);
231 describe("TO_PRIMITIVE", () => {
232 it("[[Get]] is @@toPrimitive", () => {
233 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
237 describe("TO_STRING_TAG", () => {
238 it("[[Get]] is @@toStringTag", () => {
239 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
243 describe("UNDEFINED", () => {
244 it("[[Get]] is undefined", () => {
245 assertStrictEquals(UNDEFINED
, void {});
249 describe("UNSCOPABLES", () => {
250 it("[[Get]] is @@unscopables", () => {
251 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
255 describe("canonicalNumericIndexString", () => {
256 it("[[Call]] returns undefined for nonstrings", () => {
257 assertStrictEquals(canonicalNumericIndexString(1), void {});
260 it("[[Call]] returns undefined for noncanonical strings", () => {
261 assertStrictEquals(canonicalNumericIndexString(""), void {});
262 assertStrictEquals(canonicalNumericIndexString("01"), void {});
264 canonicalNumericIndexString("9007199254740993"),
269 it('[[Call]] returns -0 for "-0"', () => {
270 assertStrictEquals(canonicalNumericIndexString("-0"), -0);
273 it("[[Call]] returns the corresponding number for canonical strings", () => {
274 assertStrictEquals(canonicalNumericIndexString("0"), 0);
275 assertStrictEquals(canonicalNumericIndexString("-0.25"), -0.25);
277 canonicalNumericIndexString("9007199254740992"),
280 assertStrictEquals(canonicalNumericIndexString("NaN"), 0 / 0);
281 assertStrictEquals(canonicalNumericIndexString("Infinity"), 1 / 0);
283 canonicalNumericIndexString("-Infinity"),
288 it("[[Construct]] throws an error", () => {
289 assertThrows(() => new canonicalNumericIndexString(""));
292 describe(".length", () => {
293 it("[[Get]] returns the correct length", () => {
294 assertStrictEquals(canonicalNumericIndexString
.length
, 1);
298 describe(".name", () => {
299 it("[[Get]] returns the correct name", () => {
301 canonicalNumericIndexString
.name
,
302 "canonicalNumericIndexString",
308 describe("completePropertyDescriptor", () => {
309 it("[[Call]] completes a generic descriptor", () => {
311 completePropertyDescriptor(desc
);
320 it("[[Call]] completes a data descriptor", () => {
321 const desc
= { value: undefined };
322 completePropertyDescriptor(desc
);
331 it("[[Call]] completes an accessor descriptor", () => {
332 const desc
= { get: undefined };
333 completePropertyDescriptor(desc
);
342 it("[[Call]] throws an error when the descriptor is undefined", () => {
343 assertThrows(() => new completePropertyDescriptor(undefined));
346 it("[[Construct]] throws an error", () => {
347 assertThrows(() => new completePropertyDescriptor({}));
350 describe(".length", () => {
351 it("[[Get]] returns the correct length", () => {
352 assertStrictEquals(completePropertyDescriptor
.length
, 1);
356 describe(".name", () => {
357 it("[[Get]] returns the correct name", () => {
359 completePropertyDescriptor
.name
,
360 "completePropertyDescriptor",
366 describe("isAccessorDescriptor", () => {
367 it("[[Call]] returns false for a generic descriptor", () => {
368 assertStrictEquals(isAccessorDescriptor({}), false);
371 it("[[Get]] returns false for a data descriptor", () => {
373 isAccessorDescriptor({ value: undefined }),
377 isAccessorDescriptor({ writable: undefined }),
382 it("[[Get]] returns true for an accessor descriptor", () => {
383 assertStrictEquals(isAccessorDescriptor({ get: undefined }), true);
384 assertStrictEquals(isAccessorDescriptor({ set: undefined }), true);
387 it("[[Get]] returns false for undefined", () => {
388 assertStrictEquals(isAccessorDescriptor(undefined), false);
391 it("[[Construct]] throws an error", () => {
392 assertThrows(() => new isAccessorDescriptor({}));
395 describe(".length", () => {
396 it("[[Get]] returns the correct length", () => {
397 assertStrictEquals(isAccessorDescriptor
.length
, 1);
401 describe(".name", () => {
402 it("[[Get]] returns the correct name", () => {
404 isAccessorDescriptor
.name
,
405 "isAccessorDescriptor",
411 describe("isArrayIndexString", () => {
412 it("[[Call]] returns false for nonstrings", () => {
413 assertStrictEquals(isArrayIndexString(1), false);
416 it("[[Call]] returns false for noncanonical strings", () => {
417 assertStrictEquals(isArrayIndexString(""), false);
418 assertStrictEquals(isArrayIndexString("01"), false);
419 assertStrictEquals(isArrayIndexString("9007199254740993"), false);
422 it("[[Call]] returns false for nonfinite numbers", () => {
423 assertStrictEquals(isArrayIndexString("NaN"), false);
424 assertStrictEquals(isArrayIndexString("Infinity"), false);
425 assertStrictEquals(isArrayIndexString("-Infinity"), false);
428 it("[[Call]] returns false for negative numbers", () => {
429 assertStrictEquals(isArrayIndexString("-0"), false);
430 assertStrictEquals(isArrayIndexString("-1"), false);
433 it("[[Call]] returns false for nonintegers", () => {
434 assertStrictEquals(isArrayIndexString("0.25"), false);
435 assertStrictEquals(isArrayIndexString("1.1"), false);
438 it("[[Call]] returns false for numbers greater than or equal to -1 >>> 0", () => {
439 assertStrictEquals(isArrayIndexString(String(-1 >>> 0)), false);
441 isArrayIndexString(String((-1 >>> 0) + 1)),
446 it("[[Call]] returns true for array lengths less than -1 >>> 0", () => {
447 assertStrictEquals(isArrayIndexString("0"), true);
449 isArrayIndexString(String((-1 >>> 0) - 1)),
454 it("[[Construct]] throws an error", () => {
455 assertThrows(() => new isArrayIndexString("0"));
458 describe(".length", () => {
459 it("[[Get]] returns the correct length", () => {
460 assertStrictEquals(isArrayIndexString
.length
, 1);
464 describe(".name", () => {
465 it("[[Get]] returns the correct name", () => {
467 isArrayIndexString
.name
,
468 "isArrayIndexString",
474 describe("isDataDescriptor", () => {
475 it("[[Call]] returns false for a generic descriptor", () => {
476 assertStrictEquals(isDataDescriptor({}), false);
479 it("[[Get]] returns true for a data descriptor", () => {
480 assertStrictEquals(isDataDescriptor({ value: undefined }), true);
481 assertStrictEquals(isDataDescriptor({ writable: true }), true);
484 it("[[Get]] returns false for an accessor descriptor", () => {
485 assertStrictEquals(isDataDescriptor({ get: undefined }), false);
486 assertStrictEquals(isDataDescriptor({ set: undefined }), false);
489 it("[[Get]] returns false for undefined", () => {
490 assertStrictEquals(isDataDescriptor(undefined), false);
493 it("[[Construct]] throws an error", () => {
494 assertThrows(() => new isDataDescriptor({}));
497 describe(".length", () => {
498 it("[[Get]] returns the correct length", () => {
499 assertStrictEquals(isDataDescriptor
.length
, 1);
503 describe(".name", () => {
504 it("[[Get]] returns the correct name", () => {
505 assertStrictEquals(isDataDescriptor
.name
, "isDataDescriptor");
510 describe("isFullyPopulatedDescriptor", () => {
511 it("[[Call]] returns false for a generic descriptor", () => {
512 assertStrictEquals(isFullyPopulatedDescriptor({}), false);
515 it("[[Get]] returns false for a nonβfullyβpopulated data descriptor", () => {
517 isFullyPopulatedDescriptor({ value: undefined }),
521 isFullyPopulatedDescriptor({ writable: true }),
526 it("[[Get]] returns true for a fullyβpopulated data descriptor", () => {
528 isFullyPopulatedDescriptor({
538 it("[[Get]] returns false for a nonβfullyβpopulated accessor descriptor", () => {
540 isFullyPopulatedDescriptor({ get: undefined }),
544 isFullyPopulatedDescriptor({ set: undefined }),
549 it("[[Get]] returns true for a fullyβpopulated accessor descriptor", () => {
551 isFullyPopulatedDescriptor({
561 it("[[Get]] returns false for undefined", () => {
562 assertStrictEquals(isFullyPopulatedDescriptor(undefined), false);
565 it("[[Construct]] throws an error", () => {
566 assertThrows(() => new isFullyPopulatedDescriptor({}));
569 describe(".length", () => {
570 it("[[Get]] returns the correct length", () => {
571 assertStrictEquals(isFullyPopulatedDescriptor
.length
, 1);
575 describe(".name", () => {
576 it("[[Get]] returns the correct name", () => {
578 isFullyPopulatedDescriptor
.name
,
579 "isFullyPopulatedDescriptor",
585 describe("isGenericDescriptor", () => {
586 it("[[Call]] returns true for a generic descriptor", () => {
587 assertStrictEquals(isGenericDescriptor({}), true);
590 it("[[Get]] returns false for a data descriptor", () => {
592 isGenericDescriptor({ value: undefined }),
595 assertStrictEquals(isGenericDescriptor({ writable: true }), false);
598 it("[[Get]] returns false for an accessor descriptor", () => {
599 assertStrictEquals(isGenericDescriptor({ get: undefined }), false);
600 assertStrictEquals(isGenericDescriptor({ set: undefined }), false);
603 it("[[Get]] returns false for undefined", () => {
604 assertStrictEquals(isGenericDescriptor(undefined), false);
607 it("[[Construct]] throws an error", () => {
608 assertThrows(() => new isGenericDescriptor({}));
611 describe(".length", () => {
612 it("[[Get]] returns the correct length", () => {
613 assertStrictEquals(isGenericDescriptor
.length
, 1);
617 describe(".name", () => {
618 it("[[Get]] returns the correct name", () => {
620 isGenericDescriptor
.name
,
621 "isGenericDescriptor",
627 describe("isIntegerIndexString", () => {
628 it("[[Call]] returns false for nonstrings", () => {
629 assertStrictEquals(isIntegerIndexString(1), false);
632 it("[[Call]] returns false for noncanonical strings", () => {
633 assertStrictEquals(isIntegerIndexString(""), false);
634 assertStrictEquals(isIntegerIndexString("01"), false);
636 isIntegerIndexString("9007199254740993"),
641 it("[[Call]] returns false for nonfinite numbers", () => {
642 assertStrictEquals(isIntegerIndexString("NaN"), false);
643 assertStrictEquals(isIntegerIndexString("Infinity"), false);
644 assertStrictEquals(isIntegerIndexString("-Infinity"), false);
647 it("[[Call]] returns false for negative numbers", () => {
648 assertStrictEquals(isIntegerIndexString("-0"), false);
649 assertStrictEquals(isIntegerIndexString("-1"), false);
652 it("[[Call]] returns false for nonintegers", () => {
653 assertStrictEquals(isIntegerIndexString("0.25"), false);
654 assertStrictEquals(isIntegerIndexString("1.1"), false);
657 it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
659 isIntegerIndexString("9007199254740992"),
664 it("[[Call]] returns true for safe canonical integer strings", () => {
665 assertStrictEquals(isIntegerIndexString("0"), true);
666 assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
669 it("[[Construct]] throws an error", () => {
670 assertThrows(() => new isIntegerIndexString("0"));
673 describe(".length", () => {
674 it("[[Get]] returns the correct length", () => {
675 assertStrictEquals(isIntegerIndexString
.length
, 1);
679 describe(".name", () => {
680 it("[[Get]] returns the correct name", () => {
682 isIntegerIndexString
.name
,
683 "isIntegerIndexString",
689 describe("ordinaryToPrimitive", () => {
690 it("[[Call]] prefers `valueOf` by default", () => {
699 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
700 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
703 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
712 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
715 it('[[Call]] prefers `toString` for a "string" hint', () => {
724 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
727 it("[[Call]] falls back to the other method if the first isnβt callable", () => {
734 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
737 it("[[Call]] falls back to the other method if the first returns an object", () => {
743 return new String("failure");
746 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
749 it("[[Call]] throws an error if neither method is callable", () => {
754 assertThrows(() => ordinaryToPrimitive(obj
));
757 it("[[Call]] throws an error if neither method returns an object", () => {
760 return new String("failure");
763 return new String("failure");
766 assertThrows(() => ordinaryToPrimitive(obj
));
769 it("[[Construct]] throws an error", () => {
770 assertThrows(() => new ordinaryToPrimitive(""));
773 describe(".length", () => {
774 it("[[Get]] returns the correct length", () => {
775 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
779 describe(".name", () => {
780 it("[[Get]] returns the correct name", () => {
782 ordinaryToPrimitive
.name
,
783 "ordinaryToPrimitive",
789 describe("sameValue", () => {
790 it("[[Call]] returns false for null π undefined", () => {
791 assertStrictEquals(sameValue(null, undefined), false);
794 it("[[Call]] returns false for null π an object", () => {
795 assertStrictEquals(sameValue(null, {}), false);
798 it("[[Call]] returns true for null π null", () => {
799 assertStrictEquals(sameValue(null, null), true);
802 it("[[Call]] returns false for two different objects", () => {
803 assertStrictEquals(sameValue({}, {}), false);
806 it("[[Call]] returns true for the same object", () => {
808 assertStrictEquals(sameValue(obj
, obj
), true);
811 it("[[Call]] returns false for Β±0", () => {
812 assertStrictEquals(sameValue(0, -0), false);
815 it("[[Call]] returns true for -0", () => {
816 assertStrictEquals(sameValue(-0, -0), true);
819 it("[[Call]] returns true for nan", () => {
820 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
823 it("[[Call]] returns false for a primitive and its wrapped object", () => {
824 assertStrictEquals(sameValue(false, new Boolean(false)), false);
827 it("[[Construct]] throws an error", () => {
828 assertThrows(() => new sameValue(true, true));
831 describe(".length", () => {
832 it("[[Get]] returns the correct length", () => {
833 assertStrictEquals(sameValue
.length
, 2);
837 describe(".name", () => {
838 it("[[Get]] returns the correct name", () => {
839 assertStrictEquals(sameValue
.name
, "sameValue");
844 describe("sameValueZero", () => {
845 it("[[Call]] returns false for null π undefined", () => {
846 assertStrictEquals(sameValueZero(null, undefined), false);
849 it("[[Call]] returns false for null π an object", () => {
850 assertStrictEquals(sameValueZero(null, {}), false);
853 it("[[Call]] returns true for null π null", () => {
854 assertStrictEquals(sameValueZero(null, null), true);
857 it("[[Call]] returns false for two different objects", () => {
858 assertStrictEquals(sameValueZero({}, {}), false);
861 it("[[Call]] returns true for the same object", () => {
863 assertStrictEquals(sameValueZero(obj
, obj
), true);
866 it("[[Call]] returns true for Β±0", () => {
867 assertStrictEquals(sameValueZero(0, -0), true);
870 it("[[Call]] returns true for -0", () => {
871 assertStrictEquals(sameValueZero(-0, -0), true);
874 it("[[Call]] returns true for nan", () => {
875 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
878 it("[[Call]] returns false for a primitive and its wrapped object", () => {
880 sameValueZero(false, new Boolean(false)),
885 it("[[Construct]] throws an error", () => {
886 assertThrows(() => new sameValueZero(true, true));
889 describe(".length", () => {
890 it("[[Get]] returns the correct length", () => {
891 assertStrictEquals(sameValueZero
.length
, 2);
895 describe(".name", () => {
896 it("[[Get]] returns the correct name", () => {
897 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
902 describe("toFunctionName", () => {
903 it("[[Call]] works with strings and no prefix", () => {
904 assertStrictEquals(toFunctionName("etaoin"), "etaoin");
907 it("[[Call]] works with objects and no prefix", () => {
918 it("[[Call]] works with descriptionless symbols and no prefix", () => {
919 assertStrictEquals(toFunctionName(Symbol()), "");
922 it("[[Call]] works with empty description symbols and no prefix", () => {
923 assertStrictEquals(toFunctionName(Symbol("")), "[]");
926 it("[[Call]] works with described symbols and no prefix", () => {
927 assertStrictEquals(toFunctionName(Symbol("etaoin")), "[etaoin]");
930 it("[[Call]] works with strings and a prefix", () => {
931 assertStrictEquals(toFunctionName("etaoin", "foo"), "foo etaoin");
934 it("[[Call]] works with objects and no prefix", () => {
945 it("[[Call]] works with descriptionless symbols and no prefix", () => {
946 assertStrictEquals(toFunctionName(Symbol(), "foo"), "foo ");
949 it("[[Call]] works with empty description symbols and no prefix", () => {
950 assertStrictEquals(toFunctionName(Symbol(""), "foo"), "foo []");
953 it("[[Call]] works with described symbols and no prefix", () => {
955 toFunctionName(Symbol("etaoin"), "foo"),
960 it("[[Construct]] throws an error", () => {
961 assertThrows(() => new toFunctionName(""));
964 describe(".length", () => {
965 it("[[Get]] returns the correct length", () => {
966 assertStrictEquals(toFunctionName
.length
, 1);
970 describe(".name", () => {
971 it("[[Get]] returns the correct name", () => {
980 describe("toIndex", () => {
981 it("[[Call]] returns an index", () => {
982 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
985 it("[[Call]] returns zero for a zerolike argument", () => {
986 assertStrictEquals(toIndex(NaN
), 0);
987 assertStrictEquals(toIndex("failure"), 0);
988 assertStrictEquals(toIndex(-0), 0);
991 it("[[Call]] rounds down to the nearest integer", () => {
992 assertStrictEquals(toIndex(0.25), 0);
993 assertStrictEquals(toIndex(1.1), 1);
996 it("[[Call]] throws when provided a negative number", () => {
997 assertThrows(() => toIndex(-1));
998 assertThrows(() => toIndex(-Infinity
));
1001 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
1002 assertThrows(() => toIndex(9007199254740992));
1003 assertThrows(() => toIndex(Infinity
));
1006 it("[[Construct]] throws an error", () => {
1007 assertThrows(() => new toIndex(0));
1010 describe(".length", () => {
1011 it("[[Get]] returns the correct length", () => {
1012 assertStrictEquals(toIndex
.length
, 1);
1016 describe(".name", () => {
1017 it("[[Get]] returns the correct name", () => {
1018 assertStrictEquals(toIndex
.name
, "toIndex");
1023 describe("toLength", () => {
1024 it("[[Call]] returns a length", () => {
1025 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
1028 it("[[Call]] returns zero for a nan argument", () => {
1029 assertStrictEquals(toLength(NaN
), 0);
1030 assertStrictEquals(toLength("failure"), 0);
1033 it("[[Call]] rounds down to the nearest integer", () => {
1034 assertStrictEquals(toLength(0.25), 0);
1035 assertStrictEquals(toLength(1.1), 1);
1038 it("[[Call]] returns a result greater than or equal to zero", () => {
1039 assertStrictEquals(toLength(-0), 0);
1040 assertStrictEquals(toLength(-1), 0);
1041 assertStrictEquals(toLength(-Infinity
), 0);
1044 it("[[Call]] returns a result less than 2 ** 53", () => {
1045 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
1046 assertStrictEquals(toLength(Infinity
), 9007199254740991);
1049 it("[[Construct]] throws an error", () => {
1050 assertThrows(() => new toLength(0));
1053 describe(".length", () => {
1054 it("[[Get]] returns the correct length", () => {
1055 assertStrictEquals(toLength
.length
, 1);
1059 describe(".name", () => {
1060 it("[[Get]] returns the correct name", () => {
1061 assertStrictEquals(toLength
.name
, "toLength");
1066 describe("toPrimitive", () => {
1067 it("[[Call]] returns the argument when passed a primitive", () => {
1068 const value
= Symbol();
1069 assertStrictEquals(toPrimitive(value
), value
);
1072 it("[[Call]] works with nullish values", () => {
1073 assertStrictEquals(toPrimitive(null), null);
1074 assertStrictEquals(toPrimitive(), void {});
1077 it("[[Call]] calls ordinaryToPrimitive by default", () => {
1078 const value
= Object
.assign(
1079 Object
.create(null),
1086 assertStrictEquals(toPrimitive(value
), "success");
1089 it("[[Call]] accepts a hint", () => {
1090 const value
= Object
.assign(
1091 Object
.create(null),
1101 assertStrictEquals(toPrimitive(value
, "string"), "success");
1104 it("[[Call]] uses the exotic toPrimitive method if available", () => {
1105 const value
= Object
.assign(
1106 Object
.create(null),
1108 [Symbol
.toPrimitive
]() {
1113 assertStrictEquals(toPrimitive(value
), "success");
1116 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
1117 const value
= Object
.assign(
1118 Object
.create(null),
1120 [Symbol
.toPrimitive
](hint
) {
1121 return hint
=== "string" ? "success" : "failure";
1125 assertStrictEquals(toPrimitive(value
, "string"), "success");
1128 it('[[Call]] passes a "default" hint by default', () => {
1129 const value
= Object
.assign(
1130 Object
.create(null),
1132 [Symbol
.toPrimitive
](hint
) {
1133 return hint
=== "default" ? "success" : "failure";
1137 assertStrictEquals(toPrimitive(value
), "success");
1140 it("[[Call]] throws for an invalid hint", () => {
1141 const value1
= Object
.assign(
1142 Object
.create(null),
1144 [Symbol
.toPrimitive
]() {
1149 const value2
= Object
.assign(
1150 Object
.create(null),
1157 assertThrows(() => toPrimitive(value1
, "badhint"));
1158 assertThrows(() => toPrimitive(value2
, "badhint"));
1159 assertThrows(() => toPrimitive(true, "badhint"));
1162 it("[[Construct]] throws an error", () => {
1163 assertThrows(() => new toPrimitive(true));
1166 describe(".length", () => {
1167 it("[[Get]] returns the correct length", () => {
1168 assertStrictEquals(toPrimitive
.length
, 1);
1172 describe(".name", () => {
1173 it("[[Get]] returns the correct name", () => {
1174 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
1179 describe("toPropertyKey", () => {
1180 it("returns a string or symbol", () => {
1181 const sym
= Symbol();
1182 assertStrictEquals(toPropertyKey(sym
), sym
);
1184 toPropertyKey(new String("success")),
1189 it("favours the `toString` representation", () => {
1203 it("[[Construct]] throws an error", () => {
1204 assertThrows(() => new toPropertyKey(""));
1207 describe(".length", () => {
1208 it("[[Get]] returns the correct length", () => {
1209 assertStrictEquals(toPropertyKey
.length
, 1);
1213 describe(".name", () => {
1214 it("[[Get]] returns the correct name", () => {
1215 assertStrictEquals(toPropertyKey
.name
, "toPropertyKey");
1220 describe("type", () => {
1221 it('[[Call]] returns "null" for null', () => {
1222 assertStrictEquals(type(null), "null");
1225 it('[[Call]] returns "undefined" for undefined', () => {
1226 assertStrictEquals(type(void {}), "undefined");
1229 it('[[Call]] returns "object" for nonβcallable objects', () => {
1230 assertStrictEquals(type(Object
.create(null)), "object");
1233 it('[[Call]] returns "object" for callable objects', () => {
1234 assertStrictEquals(type(() => {}), "object");
1237 it('[[Call]] returns "object" for constructable objects', () => {
1238 assertStrictEquals(type(class {}), "object");
1241 it("[[Construct]] throws an error", () => {
1242 assertThrows(() => new type({}));
1245 describe(".length", () => {
1246 it("[[Get]] returns the correct length", () => {
1247 assertStrictEquals(type
.length
, 1);
1251 describe(".name", () => {
1252 it("[[Get]] returns the correct name", () => {
1253 assertStrictEquals(type
.name
, "type");
1258 describe("π", () => {
1259 it("[[Get]] is π", () => {
1260 assertStrictEquals(π, Math
.E
);
1264 describe("π", () => {
1265 it("[[Get]] is π", () => {
1266 assertStrictEquals(π, Number
.EPSILON
);
1270 describe("π", () => {
1271 it("[[Get]] is π", () => {
1272 assertStrictEquals(π, Math
.PI
);