From be2db270a3701ea034bf52b83ca757d57ed95a54 Mon Sep 17 00:00:00 2001 From: guybedford Date: Mon, 22 Jun 2015 21:26:35 +0200 Subject: [PATCH] chrome extension eval support --- lib/global-eval.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/global-eval.js b/lib/global-eval.js index c2356110..8a86b0ba 100644 --- a/lib/global-eval.js +++ b/lib/global-eval.js @@ -28,8 +28,23 @@ var __exec; '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(load.metadata.sourceMap))) || '') } + // Web Worker and Chrome Extensions use original ESML eval + // this may lead to some global module execution differences (eg var not defining onto global) + if (isWorker || isBrowser && window.chrome && window.chrome.extension) { + __exec = function(load) { + try { + preExec(this); + new Function(getSource(load)).call(__global); + postExec(); + } + catch(e) { + throw addToError(e, 'Evaluating ' + load.address); + } + }; + } + // use script injection eval to get identical global script behaviour - if (typeof document != 'undefined') { + else if (typeof document != 'undefined') { var head; var scripts = document.getElementsByTagName('script'); @@ -55,20 +70,6 @@ var __exec; throw e; } } - // Web Worker uses original ESML eval - // this may lead to some global module execution differences (eg var not defining onto global) - else if (isWorker) { - __exec = function(load) { - try { - preExec(this); - new Function(getSource(load)).call(__global); - postExec(); - } - catch(e) { - throw addToError(e, 'Evaluating ' + load.address); - } - }; - } else { // global scoped eval for node var vmModule = 'vm';