Skip to content

Commit 3e0877a

Browse files
scothisbenvinegar
authored andcommitted
Guard property access to __raven_wrapper__ (#720)
1 parent 9988f5e commit 3e0877a

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/raven.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,18 @@ Raven.prototype = {
258258
if (func.__raven__) {
259259
return func;
260260
}
261+
262+
// If this has already been wrapped in the past, return that
263+
if (func.__raven_wrapper__ ){
264+
return func.__raven_wrapper__ ;
265+
}
261266
} catch (e) {
262-
// Just accessing the __raven__ prop in some Selenium environments
267+
// Just accessing custom props in some Selenium environments
263268
// can cause a "Permission denied" exception (see raven-js#495).
264269
// Bail on wrapping and return the function as-is (defers to window.onerror).
265270
return func;
266271
}
267272

268-
// If this has already been wrapped in the past, return that
269-
if (func.__raven_wrapper__ ){
270-
return func.__raven_wrapper__ ;
271-
}
272-
273273
function wrapped() {
274274
var args = [], i = arguments.length,
275275
deep = !options || options && options.deep !== false;
@@ -864,7 +864,11 @@ Raven.prototype = {
864864
}, wrappedBuiltIns);
865865
fill(proto, 'removeEventListener', function (orig) {
866866
return function (evt, fn, capture, secure) {
867-
fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn);
867+
try {
868+
fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn);
869+
} catch (e) {
870+
// ignore, accessing __raven_wrapper__ will throw in some Selenium environments
871+
}
868872
return orig.call(this, evt, fn, capture, secure);
869873
};
870874
}, wrappedBuiltIns);

test/raven.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,19 @@ describe('Raven (public API)', function() {
17351735
assert.equal(fn, wrapped);
17361736
});
17371737

1738+
it('should return input funciton as-is if accessing __raven_wrapper__ prop throws exception', function (){
1739+
// see raven-js#495
1740+
var fn = function () {};
1741+
Object.defineProperty(fn, '__raven_wrapper__', {
1742+
get: function () {
1743+
throw new Error('Permission denied')
1744+
}
1745+
});
1746+
assert.throw(function () { fn.__raven_wrapper__; }, 'Permission denied');
1747+
var wrapped = Raven.wrap(fn);
1748+
assert.equal(fn, wrapped);
1749+
});
1750+
17381751
});
17391752

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

0 commit comments

Comments
 (0)