]> Lady’s Gitweb - Pisces/commitdiff
Cast to primitive when creating function names
authorLady <redacted>
Tue, 5 Sep 2023 00:49:47 +0000 (20:49 -0400)
committerLady <redacted>
Wed, 6 Sep 2023 03:13:34 +0000 (23:13 -0400)
This matches the behaviour of `toPropertyKey`, which is a soft spec
prerequisite (`SetFunctionName` takes a property key argument).

function.js

index efb3871e071040212cde3a0bc9386a90064c294c..7da0a3a1ccfc7f3f9a63df3a30835459bdf54773 100644 (file)
@@ -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 <https://mozilla.org/MPL/2.0/>.
 
-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;
This page took 0.022835 seconds and 4 git commands to generate.