From 0dfcd2bffe65c65f38b71f3462715f220b061430 Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Thu, 12 Sep 2013 14:34:37 -0700 Subject: [PATCH] dont assume document on global --- src/observe.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/observe.js b/src/observe.js index 918b55c..944de74 100644 --- a/src/observe.js +++ b/src/observe.js @@ -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; }