From ce9c13df50c81892ddafa0c60839c15674e6ddea Mon Sep 17 00:00:00 2001 From: stereobit Date: Sat, 18 Jan 2014 16:12:16 +0000 Subject: [PATCH 1/4] add option to prevent wrapping also the functions arguments --- src/raven.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/raven.js b/src/raven.js index b11dd014e460..27258d12bae9 100644 --- a/src/raven.js +++ b/src/raven.js @@ -181,7 +181,10 @@ var Raven = { var args = [], i = arguments.length; // Recursively wrap all of a function's arguments that are // functions themselves. - while(i--) args[i] = Raven.wrap(options, arguments[i]); + if (options.deep !== false) { + while(i--) args[i] = Raven.wrap(options, arguments[i]); + } + try { /*jshint -W040*/ return func.apply(this, args); From 7e17ce456f8b5719bb4dab6aaf092b630075e603 Mon Sep 17 00:00:00 2001 From: stereobit Date: Sat, 18 Jan 2014 17:26:33 +0000 Subject: [PATCH 2/4] check for options before checking for options.deep --- src/raven.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raven.js b/src/raven.js index 27258d12bae9..5181fef61c72 100644 --- a/src/raven.js +++ b/src/raven.js @@ -181,7 +181,7 @@ var Raven = { var args = [], i = arguments.length; // Recursively wrap all of a function's arguments that are // functions themselves. - if (options.deep !== false) { + if (!options || options && options.deep !== false) { while(i--) args[i] = Raven.wrap(options, arguments[i]); } From 44015cbae075a3d690d0e576e974b65d506413de Mon Sep 17 00:00:00 2001 From: stereobit Date: Sat, 18 Jan 2014 17:33:03 +0000 Subject: [PATCH 3/4] add test for deep wrapping --- test/raven.test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/raven.test.js b/test/raven.test.js index 864ad0062e70..90878f05b6fd 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -1040,7 +1040,7 @@ describe('Raven (public API)', function() { }); it('should return the result of a wrapped function', function() { - var func = function() { return 'foo' }; + var func = function() { return 'foo'; }; var wrapped = Raven.wrap(func); assert.equal(wrapped(), 'foo'); }); @@ -1063,6 +1063,16 @@ describe('Raven (public API)', function() { assert.isTrue(spy.calledOnce); }); + it('should not wrap function arguments', function() { + var spy = this.sinon.spy(); + var wrapped = Raven.wrap({ deep: false }, function(f) { + assert.isTrue(f.__raven__); + f(); + }); + wrapped(spy); + assert.isFalse(spy.calledOnce); + }); + it('should maintain the correct scope', function() { var foo = {}; var bar = function() { From e8522b692b99bfae7dd3a2367c7431f506244ac6 Mon Sep 17 00:00:00 2001 From: stereobit Date: Sat, 18 Jan 2014 17:54:08 +0000 Subject: [PATCH 4/4] fix wrapping option test --- src/raven.js | 8 ++++---- test/raven.test.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/raven.js b/src/raven.js index 5181fef61c72..abb43f3e8203 100644 --- a/src/raven.js +++ b/src/raven.js @@ -178,12 +178,12 @@ var Raven = { } function wrapped() { - var args = [], i = arguments.length; + var args = [], i = arguments.length, + deep = !options || options && options.deep !== false; // Recursively wrap all of a function's arguments that are // functions themselves. - if (!options || options && options.deep !== false) { - while(i--) args[i] = Raven.wrap(options, arguments[i]); - } + + while(i--) args[i] = deep ? Raven.wrap(options, arguments[i]) : arguments[i]; try { /*jshint -W040*/ diff --git a/test/raven.test.js b/test/raven.test.js index 90878f05b6fd..5d99e37dfca5 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -1066,11 +1066,11 @@ describe('Raven (public API)', function() { it('should not wrap function arguments', function() { var spy = this.sinon.spy(); var wrapped = Raven.wrap({ deep: false }, function(f) { - assert.isTrue(f.__raven__); + assert.isUndefined(f.__raven__); f(); }); wrapped(spy); - assert.isFalse(spy.calledOnce); + assert.isTrue(spy.calledOnce); }); it('should maintain the correct scope', function() {