Skip to content

Commit 28576e2

Browse files
committed
Merge pull request #130 from Stereobit/master
Also copy function properties while wrapping function
2 parents 103a855 + b299a49 commit 28576e2

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/raven.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,23 @@ var Raven = {
156156
options = undefined;
157157
}
158158

159-
return function() {
160-
try {
161-
return func.apply(this, arguments);
162-
} catch(e) {
163-
Raven.captureException(e, options);
164-
throw e;
159+
var property,
160+
wrappedFunction = function() {
161+
try {
162+
func.apply(this, arguments);
163+
} catch(e) {
164+
Raven.captureException(e, options);
165+
throw e;
166+
}
167+
};
168+
169+
for (property in func) {
170+
if (func.hasOwnProperty(property)) {
171+
wrappedFunction[property] = func[property];
165172
}
166-
};
173+
}
174+
175+
return wrappedFunction;
167176
},
168177

169178
/*

test/raven.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,18 @@ describe('Raven (public API)', function() {
873873
wrapped();
874874
assert.isTrue(spy.calledOnce);
875875
});
876+
it('should copy property when wrapping function', function() {
877+
var func = function() {};
878+
func.test = true;
879+
var wrapped = Raven.wrap(func);
880+
assert.isTrue(wrapped.test);
881+
});
882+
it('should not copy prototype property when wrapping function', function() {
883+
var func = function() {};
884+
func.prototype.test = true;
885+
var wrapped = Raven.wrap(func);
886+
assert.isUndefined(new wrapped().test);
887+
});
876888
});
877889

878890
describe('.context', function() {

0 commit comments

Comments
 (0)