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
18 changes: 11 additions & 7 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@ Raven.prototype = {
if (func.__raven__) {
return func;
}

// If this has already been wrapped in the past, return that
if (func.__raven_wrapper__ ){
return func.__raven_wrapper__ ;
}
} catch (e) {
// Just accessing the __raven__ prop in some Selenium environments
// Just accessing custom props in some Selenium environments
// can cause a "Permission denied" exception (see raven-js#495).
// Bail on wrapping and return the function as-is (defers to window.onerror).
return func;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a try/catch block above for __raven__ that also bails and returns func. Rather than repeat that code, lets move the check into that try/catch block.

}

// If this has already been wrapped in the past, return that
if (func.__raven_wrapper__ ){
return func.__raven_wrapper__ ;
}

function wrapped() {
var args = [], i = arguments.length,
deep = !options || options && options.deep !== false;
Expand Down Expand Up @@ -864,7 +864,11 @@ Raven.prototype = {
}, wrappedBuiltIns);
fill(proto, 'removeEventListener', function (orig) {
return function (evt, fn, capture, secure) {
fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn);
try {
fn = fn && (fn.__raven_wrapper__ ? fn.__raven_wrapper__ : fn);
} catch (e) {
// ignore, accessing __raven_wrapper__ will throw in some Selenium environments
}
return orig.call(this, evt, fn, capture, secure);
};
}, wrappedBuiltIns);
Expand Down
13 changes: 13 additions & 0 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,19 @@ describe('Raven (public API)', function() {
assert.equal(fn, wrapped);
});

it('should return input funciton as-is if accessing __raven_wrapper__ prop throws exception', function (){
// see raven-js#495
var fn = function () {};
Object.defineProperty(fn, '__raven_wrapper__', {
get: function () {
throw new Error('Permission denied')
}
});
assert.throw(function () { fn.__raven_wrapper__; }, 'Permission denied');
var wrapped = Raven.wrap(fn);
assert.equal(fn, wrapped);
});

});

describe('.context', function() {
Expand Down