From: Lady Date: Tue, 5 Sep 2023 00:49:47 +0000 (-0400) Subject: Cast to primitive when creating function names X-Git-Url: https://git.ladys.computer/Pisces/commitdiff_plain/225ca0613195c79140b32ea1b476e09efec20613?ds=sidebyside Cast to primitive when creating function names This matches the behaviour of `toPropertyKey`, which is a soft spec prerequisite (`SetFunctionName` takes a property key argument). --- diff --git a/function.js b/function.js index efb3871..7da0a3a 100644 --- a/function.js +++ b/function.js @@ -7,7 +7,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at . -import { ITERATOR } from "./value.js"; +import { ITERATOR, toPrimitive } from "./value.js"; export const { /** @@ -124,15 +124,16 @@ export const { }); }, toFunctionName: ($, prefix = undefined) => { + const key = toPrimitive($, "string"); const name = (() => { - if (typeof $ === "symbol") { + if (typeof key === "symbol") { // The provided value is a symbol; format its description. - const description = call(getSymbolDescription, $, []); + const description = call(getSymbolDescription, key, []); return description === undefined ? "" : `[${description}]`; } else { // The provided value not a symbol; convert it to a string // property key. - return `${$}`; + return `${key}`; } })(); return prefix !== undefined ? `${prefix} ${name}` : name;