From b55b10c6b69117ae9ad1a87a06767cbee99eb5a3 Mon Sep 17 00:00:00 2001
From: Wei Lu <luwei.here@gmail.com>
Date: Wed, 8 Oct 2014 09:26:45 -0700
Subject: [PATCH] types: replace Function.name with an IE compatible
 alternative

---
 src/types.js | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/types.js b/src/types.js
index 501934f..5f885d0 100644
--- a/src/types.js
+++ b/src/types.js
@@ -26,9 +26,15 @@ module.exports = function enforce(type, value) {
     }
 
     default: {
-      if (value.constructor.toString().match(/function (.*?)\(/)[1] === type.name) return
+      if (getName(value.constructor) === getName(type)) return
     }
   }
 
-  throw new TypeError('Expected ' + (type.name || type) + ', got ' + value)
+  throw new TypeError('Expected ' + (getName(type) || type) + ', got ' + value)
+}
+
+function getName(fn) {
+  // Why not fn.name: https://kangax.github.io/compat-table/es6/#function_name_property
+  var match = fn.toString().match(/function (.*?)\(/)
+  return match ? match[1] : null
 }