bv-ui-core
Advanced tools
Comparing version 0.14.0 to 0.14.1
@@ -10,13 +10,27 @@ /** | ||
var constructors = {}; | ||
var constructorNameRegExp = /function\s+([^\(\s]+)/ | ||
var iframe; | ||
var getOriginalConstructor = function getOriginalConstructor (constructor) { | ||
if (!constructors[constructor.name]) { | ||
var iframe = document.createElement('iframe'); | ||
var constructorName = constructor.name; | ||
// IE11 doesn't have a constructor.name property, so just in case any other | ||
// browsers also don't, use a simple regex to pull the constructor's name | ||
// out of the .toString()'d function declaration, e.g. "function Array()" | ||
if (!constructorName) { | ||
constructorName = constructorNameRegExp.exec(constructor.toString())[1]; | ||
} | ||
if (!iframe) { | ||
iframe = document.createElement('iframe'); | ||
iframe.src = 'about:blank'; | ||
document.head.appendChild(iframe); | ||
constructors[constructor.name] = iframe.contentWindow[constructor.name]; | ||
document.head.removeChild(iframe); | ||
} return constructors[constructor.name]; | ||
} | ||
if (!constructors[constructorName]) { | ||
constructors[constructorName] = iframe.contentWindow[constructorName]; | ||
} | ||
return constructors[constructorName]; | ||
}; | ||
module.exports = getOriginalConstructor; |
{ | ||
"name": "bv-ui-core", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"license": "Apache 2.0", | ||
@@ -5,0 +5,0 @@ "description": "Bazaarvoice UI-related JavaScript", |
@@ -34,2 +34,19 @@ /** | ||
it('Should return the definition for constructor.name when constructor.name exists', function () { | ||
var constructor = function Array () {}; | ||
Object.defineProperty(constructor, 'name', { | ||
value: 'Array' | ||
}) | ||
// We should pull the Array constructor, with prototype, if this is working properly | ||
expect(getOriginalConstructor(constructor)).to.have.property('prototype'); | ||
}); | ||
it('Should return the definition for the function name where constructor.name doesn\'t exist', function () { | ||
var constructor = function Array () {}; | ||
// We should pull the Array constructor, with prototype, if this is working properly | ||
expect(getOriginalConstructor(constructor)).to.have.property('prototype'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196146
4592