Skip to content

Also copy function properties while wrapping function #130

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

Merged
merged 3 commits into from
Aug 24, 2013
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
23 changes: 16 additions & 7 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,23 @@ 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) {
if (func.hasOwnProperty(property)) {
wrappedFunction[property] = func[property];
}
};
}

return wrappedFunction;
},

/*
Expand Down
12 changes: 12 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down