* the provided value.
*/
createIllegalConstructor,
+
+ /**
+ * Returns a string function name generated from the provided value
+ * and optional prefix.
+ */
+ toFunctionName,
} = (() => {
// ☡ Because these functions are used to initialize module constants,
// they can’t depend on imports from elsewhere.
const {
create: objectCreate,
defineProperties: defineOwnProperties,
+ getOwnPropertyDescriptor,
getPrototypeOf: getPrototype,
setPrototypeOf: setPrototype,
} = Object;
};
},
};
+ const getSymbolDescription = getOwnPropertyDescriptor(
+ Symbol.prototype,
+ "description",
+ ).get;
+
return {
bind: ($, boundThis, boundArgs) =>
callBind(
createCallableFunction: ($, name = undefined) =>
defineOwnProperties(callBind(functionCall, $), {
length: { value: $.length + 1 },
- name: { value: name ?? $.name ?? "" },
+ name: {
+ value: toFunctionName(
+ name === undefined ? $.name ?? "" : name,
+ ),
+ },
}),
createIllegalConstructor: ($, proto = undefined) => {
const constructor = function () {
prototype: { value: $?.prototype ?? {}, writable: false },
});
},
+ 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;
+ },
};
})();
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;
- },
- };
-})();