Skip to content

Commit

Permalink
Make wrappers for functions without prototype work
Browse files Browse the repository at this point in the history
  • Loading branch information
David Aurelio committed Feb 24, 2012
1 parent 9eb42ca commit 5c9d349
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/prfl.js
Expand Up @@ -108,7 +108,7 @@
// measure time and execute wrapped function
start = getTime();
try {
if (this instanceof wrapper) {
if (wrapper.prototype && this instanceof wrapper) {
constructed = createObject(func.prototype);
returnValue = func.apply(constructed, arguments);
if (typeof returnValue !== 'object') {
Expand Down
7 changes: 7 additions & 0 deletions test/profile-spec.js
Expand Up @@ -86,6 +86,13 @@ suite('Function wrapping functionality', function() {
expect(new WrappedConstructor()).to.be.a(WrappedConstructor);
});

// only applicable for ES5
if (/\{ \[native code\] \}$/.test(Array.isArray)) {
test('ES5: Wrappers of functions without prototype should not throw exceptions', function() {
expect(new Profiler().wrapFunction('isArray', Array.isArray)).not.to.throwException();
});
}

test('Function wrappers expose properties of the wrapped function', function() {
function testedFunction() {}
testedFunction.nonFunctionProperty = {};
Expand Down

0 comments on commit 5c9d349

Please sign in to comment.