From 6297e4ec00809d0dab895463981a67d49dbf1ff4 Mon Sep 17 00:00:00 2001 From: sandstrom Date: Tue, 31 Jan 2017 14:40:36 +0100 Subject: [PATCH] Determine global scope without using eval --- papaparse.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/papaparse.js b/papaparse.js index 69a025f..59a846c 100644 --- a/papaparse.js +++ b/papaparse.js @@ -26,7 +26,19 @@ { 'use strict'; - var global = Function('return this')(); + var global = (function () { + // alternative method, similar to `Function('return this')()` + // but without using `eval` (which is disabled when + // using Content Security Policy). + + if (typeof self !== 'undefined') { return self; } + if (typeof window !== 'undefined') { return window; } + if (typeof global !== 'undefined') { return global; } + + throw new Error('Cannot determine global object'); + })(); + + var IS_WORKER = !global.document && !!global.postMessage, IS_PAPA_WORKER = IS_WORKER && /(\?|&)papaworker(=|&|$)/.test(global.location.search), LOADED_SYNC = false, AUTO_SCRIPT_PATH;