Blob Blame History Raw
From 7540ae591278756db614fa4def55ca413150e1a3 Mon Sep 17 00:00:00 2001
From: Jordan Harband <ljharb@gmail.com>
Date: Sun, 30 Oct 2016 23:16:44 -0700
Subject: [PATCH] [Tests] ensure that this function remains anonymous, despite
 ES6 name inference.

---
 index.js   | 2 +-
 test/fn.js | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 817d66a..aa88a4a 100644
--- a/index.js
+++ b/index.js
@@ -150,7 +150,7 @@ function toStr (obj) {
 
 function nameOf (f) {
     if (f.name) return f.name;
-    var m = f.toString().match(/^function\s*([\w$]+)/);
+    var m = String(f).match(/^function\s*([\w$]+)/);
     if (m) return m[1];
 }
 
diff --git a/test/fn.js b/test/fn.js
index 55357db..be166ff 100644
--- a/test/fn.js
+++ b/test/fn.js
@@ -9,7 +9,9 @@ test('function', function (t) {
 
 test('function name', function (t) {
     t.plan(1);
-    var f = function () {};
+    var f = (function () {
+      return function () {};
+    }());
     f.toString = function () { return 'function xxx () {}' };
     var obj = [ 1, 2, f, 4 ];
     t.equal(inspect(obj), '[ 1, 2, [Function: xxx], 4 ]');