From 4efc6899803c087af25021fae1d557004b192e24 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sat, 4 Aug 2018 05:29:26 +1000 Subject: [PATCH] Fix unsafe-eval CSP violation - closes #336 (#346) --- packages/regenerator-runtime/runtime-module.js | 4 +++- packages/regenerator-runtime/runtime.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/regenerator-runtime/runtime-module.js b/packages/regenerator-runtime/runtime-module.js index ed2843177..aa947dd0d 100644 --- a/packages/regenerator-runtime/runtime-module.js +++ b/packages/regenerator-runtime/runtime-module.js @@ -7,7 +7,9 @@ // This method of obtaining a reference to the global object needs to be // kept identical to the way it is obtained in runtime.js -var g = (function() { return this })() || Function("return this")(); +var g = (function() { + return this || (typeof self === "object" && self); +})() || Function("return this")(); // Use `getOwnPropertyNames` because not all browsers support calling // `hasOwnProperty` on the global `self` object in a worker. See #183. diff --git a/packages/regenerator-runtime/runtime.js b/packages/regenerator-runtime/runtime.js index 3543a819d..8dffb5324 100644 --- a/packages/regenerator-runtime/runtime.js +++ b/packages/regenerator-runtime/runtime.js @@ -715,5 +715,7 @@ // In sloppy mode, unbound `this` refers to the global object, fallback to // Function constructor if we're in global strict mode. That is sadly a form // of indirect eval which violates Content Security Policy. - (function() { return this })() || Function("return this")() + (function() { + return this || (typeof self === "object" && self); + })() || Function("return this")() );