Skip to content

Commit 93a5117

Browse files
author
alias-rahil
committed
fix: add check for globalThis object
1 parent 0b5f4f9 commit 93a5117

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

generator/js_generator.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,7 @@ 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: defined in browsers
36333634
// - window: defined in browsers
36343635
// - global: defined in most server side environments like NodeJS
36353636
// - self: defined inside Web Workers (WorkerGlobalScope)
@@ -3639,6 +3640,7 @@ void Generator::GenerateFile(const GeneratorOptions& options,
36393640
printer->Print(
36403641
"var global = (function() {\n"
36413642
" if (this) { return this; }\n"
3643+
" if (typeof globalThis !== 'undefined') { return globalThis; }\n"
36423644
" if (typeof window !== 'undefined') { return window; }\n"
36433645
" if (typeof global !== 'undefined') { return global; }\n"
36443646
" if (typeof self !== 'undefined') { return self; }\n"

0 commit comments

Comments
 (0)