Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to prevent wrapping also the functions arguments #182

Merged
merged 4 commits into from
Jan 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,13 @@ 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.
while(i--) args[i] = Raven.wrap(options, arguments[i]);

while(i--) args[i] = deep ? Raven.wrap(options, arguments[i]) : arguments[i];

try {
/*jshint -W040*/
return func.apply(this, args);
Expand Down
12 changes: 11 additions & 1 deletion test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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.isUndefined(f.__raven__);
f();
});
wrapped(spy);
assert.isTrue(spy.calledOnce);
});

it('should maintain the correct scope', function() {
var foo = {};
var bar = function() {
Expand Down