Function.prototype[Symbol.hasInstance],
"ordinaryHasInstance",
);
+
+export const {
+ /**
+ * Returns a string function name generated from the provided value
+ * and optional prefix.
+ */
+ toFunctionName,
+} = (() => {
+ const getSymbolDescription = Object.getOwnPropertyDescriptor(
+ Symbol.prototype,
+ "description",
+ ).get;
+
+ return {
+ toFunctionName: ($, prefix = undefined) => {
+ const name = (() => {
+ if (typeof $ === "symbol") {
+ // The provided value is a symbol; format its description.
+ const description = call(getSymbolDescription, $, []);
+ return description === undefined ? "" : `[${description}]`;
+ } else {
+ // The provided value not a symbol; convert it to a string
+ // property key.
+ return `${$}`;
+ }
+ })();
+ return prefix !== undefined ? `${prefix} ${name}` : name;
+ },
+ };
+})();
isCallable,
isConstructor,
ordinaryHasInstance,
+ toFunctionName,
} from "./function.js";
describe("bind", () => {
});
});
});
+
+describe("toFunctionName", () => {
+ it("[[Call]] works with strings and no prefix", () => {
+ assertStrictEquals(toFunctionName("etaoin"), "etaoin");
+ });
+
+ it("[[Call]] works with objects and no prefix", () => {
+ assertStrictEquals(
+ toFunctionName({
+ toString() {
+ return "etaoin";
+ },
+ }),
+ "etaoin",
+ );
+ });
+
+ it("[[Call]] works with descriptionless symbols and no prefix", () => {
+ assertStrictEquals(toFunctionName(Symbol()), "");
+ });
+
+ it("[[Call]] works with empty description symbols and no prefix", () => {
+ assertStrictEquals(toFunctionName(Symbol("")), "[]");
+ });
+
+ it("[[Call]] works with described symbols and no prefix", () => {
+ assertStrictEquals(toFunctionName(Symbol("etaoin")), "[etaoin]");
+ });
+
+ it("[[Call]] works with strings and a prefix", () => {
+ assertStrictEquals(toFunctionName("etaoin", "foo"), "foo etaoin");
+ });
+
+ it("[[Call]] works with objects and no prefix", () => {
+ assertStrictEquals(
+ toFunctionName({
+ toString() {
+ return "etaoin";
+ },
+ }, "foo"),
+ "foo etaoin",
+ );
+ });
+
+ it("[[Call]] works with descriptionless symbols and no prefix", () => {
+ assertStrictEquals(toFunctionName(Symbol(), "foo"), "foo ");
+ });
+
+ it("[[Call]] works with empty description symbols and no prefix", () => {
+ assertStrictEquals(toFunctionName(Symbol(""), "foo"), "foo []");
+ });
+
+ it("[[Call]] works with described symbols and no prefix", () => {
+ assertStrictEquals(
+ toFunctionName(Symbol("etaoin"), "foo"),
+ "foo [etaoin]",
+ );
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new toFunctionName(""));
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ toFunctionName.name,
+ "toFunctionName",
+ );
+ });
+ });
+});