]);
const {
create: objectCreate,
- defineProperty: defineOwnProperty,
+ defineProperties: defineOwnProperties,
getPrototypeOf: getPrototype,
} = Object;
const { [ITERATOR]: arrayIterator } = Array.prototype;
{ args: { value: boundArgs } },
),
),
- makeCallable: ($) =>
- defineOwnProperty(
- callBind(functionCall, $),
- "length",
- { value: $.length + 1 },
- ),
+ makeCallable: ($, name = undefined) =>
+ defineOwnProperties(callBind(functionCall, $), {
+ length: { value: $.length + 1 },
+ name: { value: name ?? $.name ?? "" },
+ }),
};
})();
* Calls the provided function with the provided this value and
* arguments list.
*
- * ☡ This is an alias for `Reflect.apply`—the arguments must be
- * passed as an arraylike.
+ * ☡ This is effectively an alias for `Reflect.apply`—the arguments
+ * must be passed as an arraylike.
*/
- apply: call,
+ call,
/**
* Constructs the provided function with the provided arguments list
* and new target.
*
- * ☡ This is an alias for `Reflect.construct`—the arguments must be
- * passed as an arraylike.
+ * ☡ This is effectively an alias for `Reflect.construct`—the
+ * arguments must be passed as an arraylike.
*/
construct,
-} = Reflect;
+
+ /** Returns whether the provided value is a constructor. */
+ isConstructor,
+} = (() => {
+ const { apply, construct } = Reflect;
+ return {
+ call: (target, thisArgument, argumentsList) =>
+ apply(target, thisArgument, argumentsList),
+ construct: (target, argumentsList, ...args) =>
+ args.length > 0
+ ? construct(target, argumentsList, args[0])
+ : construct(target, argumentsList),
+ isConstructor: ($) =>
+ completesNormally(() =>
+ // Try constructing a new object with the provided value as its
+ // `new.target`. This will throw if the provided value is not a
+ // constructor.
+ construct(function () {}, [], $)
+ ),
+ };
+})();
/**
* Returns whether calling the provided function with no `this` value
/** Returns whether the provided value is callable. */
export const isCallable = ($) => typeof $ === "function";
-/** Returns whether the provided value is a constructor. */
-export const isConstructor = ($) => {
- // The provided value is an object.
- try {
- // Try constructing a new object with the provided value as its
- // `new.target`. This will throw if the provided value is not a
- // constructor.
- construct(
- function () {},
- [],
- $,
- );
- return true;
- } catch {
- // The provided value was not a constructor.
- return false;
- }
-};
-
/**
* Returns whether the provided object inherits from the prototype of
* the provided function.
*/
export const ordinaryHasInstance = makeCallable(
Function.prototype[Symbol.hasInstance],
+ "ordinaryHasInstance",
);
["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(bind.name, "bind");
+ });
+ });
});
describe("call", () => {
["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(call.name, "call");
+ });
+ });
});
describe("completesNormally", () => {
completesNormally();
});
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(completesNormally.name, "completesNormally");
+ });
+ });
});
describe("construct", () => {
["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(construct.name, "construct");
+ });
+ });
});
describe("identity", () => {
const value = {};
assertStrictEquals(new class extends identity {}(value), value);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(identity.name, "identity");
+ });
+ });
});
describe("isCallable", () => {
it("[[Call]] returns false for objects", () => {
assertStrictEquals(isCallable({}), false);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(isCallable.name, "isCallable");
+ });
+ });
});
describe("isConstructor", () => {
it("[[Call]] returns false for objects", () => {
assertStrictEquals(isConstructor({}), false);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(isConstructor.name, "isConstructor");
+ });
+ });
});
describe("makeCallable", () => {
["etaoin", "shrdlu", "cmfwyp"],
);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(makeCallable.name, "makeCallable");
+ });
+ });
});
describe("ordinaryHasInstance", () => {
true,
);
});
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ ordinaryHasInstance.name,
+ "ordinaryHasInstance",
+ );
+ });
+ });
});