File tree 1 file changed +9
-2
lines changed
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,
3630
3630
// set "this" inside the function to the global object. This does not work
3631
3631
// if we are running in strict mode ("use strict"), so we fallback to the
3632
3632
// following things (in order from first to last):
3633
+ // - globalThis: cross-platform standard, might not be defined in older
3634
+ // versions of browsers
3633
3635
// - window: defined in browsers
3634
3636
// - global: defined in most server side environments like NodeJS
3635
3637
// - self: defined inside Web Workers (WorkerGlobalScope)
3636
3638
// - Function('return this')(): this will work on most platforms, but it
3637
3639
// may be blocked by things like CSP.
3638
3640
// Function('') is almost the same as eval('')
3639
3641
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 " );
3642
3649
}
3643
3650
3644
3651
for (int i = 0 ; i < file->dependency_count (); i++) {
You can’t perform that action at this time.
0 commit comments