types: replace Function.name with an IE compatible alternative

This commit is contained in:
Wei Lu 2014-10-08 09:26:45 -07:00
parent eb4e8884d9
commit b55b10c6b6

View file

@ -26,9 +26,15 @@ module.exports = function enforce(type, value) {
} }
default: { 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
} }