Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
dont assume document on global
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed Sep 12, 2013
1 parent 0ac1ea1 commit 0dfcd2b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@

var hasObserve = detectObjectObserve();

// don't test for eval if document has CSP securityPolicy object and we can see that
// eval is not supported. This avoids an error message in console even when the exception
// is caught
var hasEval = ! ('securityPolicy' in document) || document.securityPolicy.allowsEval;
if (hasEval) {
function detectEval() {
// don't test for eval if document has CSP securityPolicy object and we can see that
// eval is not supported. This avoids an error message in console even when the exception
// is caught
if (global.document &&
'securityPolicy' in global.document &&
!global.document.securityPolicy.allowsEval) {
return false;
}

try {
var f = new Function('', 'return true;');
hasEval = f();
return f();
} catch (ex) {
return false;
}
}

var hasEval = detectEval();

function isIndex(s) {
return +s === s >>> 0;
}
Expand Down

0 comments on commit 0dfcd2b

Please sign in to comment.