Skip to content
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