File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -3630,15 +3630,22 @@ void Generator::GenerateFile(const GeneratorOptions& options,
36303630 // set "this" inside the function to the global object. This does not work
36313631 // if we are running in strict mode ("use strict"), so we fallback to the
36323632 // following things (in order from first to last):
3633+ // - globalThis: cross-platform standard, might not be defined in older
3634+ // versions of browsers
36333635 // - window: defined in browsers
36343636 // - global: defined in most server side environments like NodeJS
36353637 // - self: defined inside Web Workers (WorkerGlobalScope)
36363638 // - Function('return this')(): this will work on most platforms, but it
36373639 // may be blocked by things like CSP.
36383640 // Function('') is almost the same as eval('')
36393641 printer->Print (
3640- " var global = (function() { return this || window || global || self "
3641- " || Function('return this')(); }).call(null);\n\n " );
3642+ " var global =\n "
3643+ " (typeof globalThis !== 'undefined' && globalThis) ||\n "
3644+ " (typeof window !== 'undefined' && window) ||\n "
3645+ " (typeof global !== 'undefined' && global) ||\n "
3646+ " (typeof self !== 'undefined' && self) ||\n "
3647+ " (function () { return this; }).call(null) ||\n "
3648+ " Function('return this')();\n\n " );
36423649 }
36433650
36443651 for (int i = 0 ; i < file->dependency_count (); i++) {
You can’t perform that action at this time.
0 commit comments