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

Commit 4d3bf23

Browse files
committed
Merge pull request #26 from mangini/master
Changed hasEval test to avoid console error when browser supports security policy
2 parents db1d00d + 18308da commit 4d3bf23

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/observe.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@
3737

3838
var hasObserve = detectObjectObserve();
3939

40-
var hasEval = false;
41-
try {
42-
var f = new Function('', 'return true;');
43-
hasEval = f();
44-
} catch (ex) {
40+
// don't test for eval if document has CSP securityPolicy object and we can see that
41+
// eval is not supported. This avoids an error message in console even when the exception
42+
// is caught
43+
var hasEval = ! ('securityPolicy' in document) || document.securityPolicy.allowsEval;
44+
if (hasEval) {
45+
try {
46+
var f = new Function('', 'return true;');
47+
hasEval = f();
48+
} catch (ex) {
49+
}
4550
}
4651

4752
function isIndex(s) {

0 commit comments

Comments
 (0)