// License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
-import { ITERATOR } from "./value.js";
+import { ITERATOR, toPrimitive } from "./value.js";
 
 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;