From 39eca1e43573b668f335940c874c597b1f1b68c6 Mon Sep 17 00:00:00 2001 From: stereobit Date: Wed, 14 Aug 2013 23:16:00 +0100 Subject: [PATCH 1/3] also copy function properties while wrapping function --- src/raven.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/raven.js b/src/raven.js index 94cfd4340d9b..44b6cc48c287 100644 --- a/src/raven.js +++ b/src/raven.js @@ -156,14 +156,21 @@ var Raven = { options = undefined; } - return function() { - try { - return func.apply(this, arguments); - } catch(e) { - Raven.captureException(e, options); - throw e; - } - }; + var property, + wrappedFunction = function() { + try { + func.apply(this, arguments); + } catch(e) { + Raven.captureException(e, options); + throw e; + } + }; + + for (property in func) { + wrappedFunction[property] = func[property]; + } + + return wrappedFunction; }, /* From e2c7e731c8dc3d47797e876f7a324048235c5c8c Mon Sep 17 00:00:00 2001 From: stereobit Date: Thu, 15 Aug 2013 09:36:57 +0100 Subject: [PATCH 2/3] check if property is specified property of the function before copying --- src/raven.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/raven.js b/src/raven.js index 44b6cc48c287..f43fe448f6f1 100644 --- a/src/raven.js +++ b/src/raven.js @@ -167,7 +167,9 @@ var Raven = { }; for (property in func) { - wrappedFunction[property] = func[property]; + if (func.hasOwnProperty(property)) { + wrappedFunction[property] = func[property]; + } } return wrappedFunction; From b299a49884d7de5d191eb4642935bcc1b2ed2092 Mon Sep 17 00:00:00 2001 From: stereobit Date: Thu, 15 Aug 2013 10:28:35 +0100 Subject: [PATCH 3/3] add some tests --- test/raven.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/raven.test.js b/test/raven.test.js index cac13620159f..b802cd7d63bb 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -873,6 +873,18 @@ describe('Raven (public API)', function() { wrapped(); assert.isTrue(spy.calledOnce); }); + it('should copy property when wrapping function', function() { + var func = function() {}; + func.test = true; + var wrapped = Raven.wrap(func); + assert.isTrue(wrapped.test); + }); + it('should not copy prototype property when wrapping function', function() { + var func = function() {}; + func.prototype.test = true; + var wrapped = Raven.wrap(func); + assert.isUndefined(new wrapped().test); + }); }); describe('.context', function() {