Skip to content

Commit

Permalink
[runtime] Use globalThis before Function() (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 22, 2021
1 parent dbbddd9 commit cc0cde9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,17 @@ try {
} catch (accidentalStrictMode) {
// This module should not be running in strict mode, so the above
// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, we can escape
// in case runtime.js accidentally runs in strict mode, in modern engines
// we can explicitly access globalThis. In older engines we can escape
// strict mode using a global Function call. This could conceivably fail
// if a Content Security Policy forbids using Function, but in that case
// the proper solution is to fix the accidental strict mode problem. If
// you've misconfigured your bundler to force strict mode and applied a
// CSP to forbid Function, and you're not willing to fix either of those
// problems, please detail your unique predicament in a GitHub issue.
Function("r", "regeneratorRuntime = r")(runtime);
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
}
}

0 comments on commit cc0cde9

Please sign in to comment.