// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
import { call, createCallableFunction } from "./function.js";
-import { lengthOfArraylike, toIndex, type } from "./value.js";
+import { toIndex, type } from "./value.js";
const { prototype: arrayPrototype } = Array;
"indices",
);
-/** Returns whether the provided value is arraylike. */
-export const isArraylikeObject = ($) => {
- if (type($) !== "object") {
- return false;
- } else {
- try {
- lengthOfArraylike($); // throws if not arraylike
- return true;
- } catch {
- return false;
- }
- }
-};
/**
* Returns whether the provided object is a collection.
} from "./dev-deps.js";
import {
findIndexedEntry,
- isArraylikeObject,
isCollection,
isConcatSpreadable,
} from "./collection.js";
});
});
-describe("isArraylikeObject", () => {
- it("[[Call]] returns false for primitives", () => {
- assertStrictEquals(isArraylikeObject("failure"), false);
- });
-
- it("[[Call]] returns false if length throws", () => {
- assertStrictEquals(
- isArraylikeObject({
- get length() {
- throw void {};
- },
- }),
- false,
- );
- });
-
- it("[[Call]] returns false if length is not a number and cannot be converted to one", () => {
- assertStrictEquals(isArraylikeObject({ length: 1n }), false);
- });
-
- it("[[Call]] returns true if length is convertable to a number", () => {
- assertStrictEquals(isArraylikeObject({ length: -0 }), true);
- assertStrictEquals(isArraylikeObject({ length: 1 }), true);
- assertStrictEquals(isArraylikeObject({ length: -1.25 }), true);
- assertStrictEquals(
- isArraylikeObject({ length: 9007199254740992 }),
- true,
- );
- assertStrictEquals(isArraylikeObject({ length: Infinity }), true);
- assertStrictEquals(isArraylikeObject({ length: "success" }), true);
- });
-});
-
describe("isCollection", () => {
it("[[Call]] returns false for primitives", () => {
assertStrictEquals(isCollection("failure"), false);
createArrowFunction,
toFunctionName,
} from "./function.js";
-import { ITERATOR, SPECIES, toPrimitive, type } from "./value.js";
+import {
+ ITERATOR,
+ SPECIES,
+ toLength,
+ toPrimitive,
+ type,
+} from "./value.js";
/**
* An object whose properties are lazy‐loaded from the methods on the
name: "hasOwnProperty",
});
+/** Returns whether the provided value is an arraylike object. */
+export const isArraylikeObject = ($) => {
+ if (type($) !== "object") {
+ return false;
+ } else {
+ try {
+ lengthOfArraylike($); // throws if not arraylike
+ return true;
+ } catch {
+ return false;
+ }
+ }
+};
+
/**
* Returns whether the provided object is extensible.
*
{ name: "isExtensibleObject" },
);
+/**
+ * Returns the length of the provided arraylike value.
+ *
+ * This can produce larger lengths than can actually be stored in
+ * arrays, because no such restrictions exist on arraylike methods.
+ *
+ * ☡ This function throws if the provided value is not arraylike.
+ */
+export const lengthOfArraylike = ({ length }) => toLength(length);
+
/**
* Returns an array of key~value pairs for the enumerable,
* string‐valued property keys on the provided object.
getPrototype,
hasOwnProperty,
hasProperty,
+ isArraylikeObject,
isExtensibleObject,
isUnfrozenObject,
isUnsealedObject,
LazyLoader,
+ lengthOfArraylike,
namedEntries,
namedKeys,
namedValues,
});
});
+describe("isArraylikeObject", () => {
+ it("[[Call]] returns false for primitives", () => {
+ assertStrictEquals(isArraylikeObject("failure"), false);
+ });
+
+ it("[[Call]] returns false if length throws", () => {
+ assertStrictEquals(
+ isArraylikeObject({
+ get length() {
+ throw void {};
+ },
+ }),
+ false,
+ );
+ });
+
+ it("[[Call]] returns false if length is not a number and cannot be converted to one", () => {
+ assertStrictEquals(isArraylikeObject({ length: 1n }), false);
+ });
+
+ it("[[Call]] returns true if length is convertable to a number", () => {
+ assertStrictEquals(isArraylikeObject({ length: -0 }), true);
+ assertStrictEquals(isArraylikeObject({ length: 1 }), true);
+ assertStrictEquals(isArraylikeObject({ length: -1.25 }), true);
+ assertStrictEquals(
+ isArraylikeObject({ length: 9007199254740992 }),
+ true,
+ );
+ assertStrictEquals(isArraylikeObject({ length: Infinity }), true);
+ assertStrictEquals(isArraylikeObject({ length: "success" }), true);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new isArraylikeObject({}));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(isArraylikeObject.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ isArraylikeObject.name,
+ "isArraylikeObject",
+ );
+ });
+ });
+});
+
describe("isExtensibleObject", () => {
it("[[Call]] returns true for extensible objects", () => {
assertStrictEquals(isExtensibleObject({}), true);
});
});
+describe("lengthOfArraylike", () => {
+ it("[[Call]] returns the length", () => {
+ assertStrictEquals(
+ lengthOfArraylike({ length: 9007199254740991 }),
+ 9007199254740991,
+ );
+ });
+
+ it("[[Call]] returns a non·nan result", () => {
+ assertStrictEquals(lengthOfArraylike({ length: NaN }), 0);
+ assertStrictEquals(lengthOfArraylike({ length: "failure" }), 0);
+ });
+
+ it("[[Call]] returns an integral result", () => {
+ assertStrictEquals(lengthOfArraylike({ length: 0.25 }), 0);
+ assertStrictEquals(lengthOfArraylike({ length: 1.1 }), 1);
+ });
+
+ it("[[Call]] returns a result greater than or equal to zero", () => {
+ assertStrictEquals(lengthOfArraylike({ length: -0 }), 0);
+ assertStrictEquals(lengthOfArraylike({ length: -1 }), 0);
+ assertStrictEquals(lengthOfArraylike({ length: -Infinity }), 0);
+ });
+
+ it("[[Call]] returns a result less than 2 ** 53", () => {
+ assertStrictEquals(
+ lengthOfArraylike({ length: 9007199254740992 }),
+ 9007199254740991,
+ );
+ assertStrictEquals(
+ lengthOfArraylike({ length: Infinity }),
+ 9007199254740991,
+ );
+ });
+
+ it("[[Call]] does not require an object argument", () => {
+ assertStrictEquals(lengthOfArraylike("string"), 6);
+ assertStrictEquals(lengthOfArraylike(Symbol()), 0);
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new lengthOfArraylike(""));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(lengthOfArraylike.length, 1);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(lengthOfArraylike.name, "lengthOfArraylike");
+ });
+ });
+});
+
describe("namedEntries", () => {
it("[[Call]] gets named entries", () => {
assertEquals(namedEntries({ success: true }), [["success", true]]);
/** The undefined primitive. */
export const UNDEFINED = undefined;
-/**
- * Returns the length of the provided arraylike value.
- *
- * This can produce larger lengths than can actually be stored in
- * arrays, because no such restrictions exist on arraylike methods.
- *
- * ☡ This function throws if the provided value is not arraylike.
- */
-export const lengthOfArraylike = ({ length }) => toLength(length);
-
export const {
/**
* Returns the primitive value of the provided object per its
HAS_INSTANCE,
IS_CONCAT_SPREADABLE,
ITERATOR,
- lengthOfArraylike,
MATCH,
MATCH_ALL,
NULL,
});
});
-describe("lengthOfArraylike", () => {
- it("[[Call]] returns the length", () => {
- assertStrictEquals(
- lengthOfArraylike({ length: 9007199254740991 }),
- 9007199254740991,
- );
- });
-
- it("[[Call]] returns a non·nan result", () => {
- assertStrictEquals(lengthOfArraylike({ length: NaN }), 0);
- assertStrictEquals(lengthOfArraylike({ length: "failure" }), 0);
- });
-
- it("[[Call]] returns an integral result", () => {
- assertStrictEquals(lengthOfArraylike({ length: 0.25 }), 0);
- assertStrictEquals(lengthOfArraylike({ length: 1.1 }), 1);
- });
-
- it("[[Call]] returns a result greater than or equal to zero", () => {
- assertStrictEquals(lengthOfArraylike({ length: -0 }), 0);
- assertStrictEquals(lengthOfArraylike({ length: -1 }), 0);
- assertStrictEquals(lengthOfArraylike({ length: -Infinity }), 0);
- });
-
- it("[[Call]] returns a result less than 2 ** 53", () => {
- assertStrictEquals(
- lengthOfArraylike({ length: 9007199254740992 }),
- 9007199254740991,
- );
- assertStrictEquals(
- lengthOfArraylike({ length: Infinity }),
- 9007199254740991,
- );
- });
-
- it("[[Call]] does not require an object argument", () => {
- assertStrictEquals(lengthOfArraylike("string"), 6);
- assertStrictEquals(lengthOfArraylike(Symbol()), 0);
- });
-
- it("[[Construct]] throws an error", () => {
- assertThrows(() => new lengthOfArraylike(""));
- });
-
- describe(".length", () => {
- it("[[Get]] returns the correct length", () => {
- assertStrictEquals(lengthOfArraylike.length, 1);
- });
- });
-
- describe(".name", () => {
- it("[[Get]] returns the correct name", () => {
- assertStrictEquals(lengthOfArraylike.name, "lengthOfArraylike");
- });
- });
-});
-
describe("ordinaryToPrimitive", () => {
it("[[Call]] prefers `valueOf` by default", () => {
const obj = {