This requires moving the definition of `toFunctionName` inside the same
closure as `createCallableFunction` to ensure that it is defined before
`createCallableFunction` is called (e·g when defining
`ordinaryHasInstance`).
* the provided value.
*/
createIllegalConstructor,
* 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.
} = (() => {
// ☡ Because these functions are used to initialize module constants,
// they can’t depend on imports from elsewhere.
const {
create: objectCreate,
defineProperties: defineOwnProperties,
const {
create: objectCreate,
defineProperties: defineOwnProperties,
+ getOwnPropertyDescriptor,
getPrototypeOf: getPrototype,
setPrototypeOf: setPrototype,
} = Object;
getPrototypeOf: getPrototype,
setPrototypeOf: setPrototype,
} = Object;
+ const getSymbolDescription = getOwnPropertyDescriptor(
+ Symbol.prototype,
+ "description",
+ ).get;
+
return {
bind: ($, boundThis, boundArgs) =>
callBind(
return {
bind: ($, boundThis, boundArgs) =>
callBind(
createCallableFunction: ($, name = undefined) =>
defineOwnProperties(callBind(functionCall, $), {
length: { value: $.length + 1 },
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 () {
}),
createIllegalConstructor: ($, proto = undefined) => {
const constructor = function () {
prototype: { value: $?.prototype ?? {}, writable: false },
});
},
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",
);
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;
- },
- };
-})();