Skip to content

Commit 0b5f4f9

Browse files
author
alias-rahil
committed
fix: #8 window is undefined error
1 parent 3561b05 commit 0b5f4f9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

generator/js_generator.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,8 +3637,13 @@ void Generator::GenerateFile(const GeneratorOptions& options,
36373637
// may be blocked by things like CSP.
36383638
// Function('') is almost the same as eval('')
36393639
printer->Print(
3640-
"var global = (function() { return this || window || global || self "
3641-
"|| Function('return this')(); }).call(null);\n\n");
3640+
"var global = (function() {\n"
3641+
" if (this) { return this; }\n"
3642+
" if (typeof window !== 'undefined') { return window; }\n"
3643+
" if (typeof global !== 'undefined') { return global; }\n"
3644+
" if (typeof self !== 'undefined') { return self; }\n"
3645+
" return Function('return this')();\n"
3646+
"}).call(null);\n\n");
36423647
}
36433648

36443649
for (int i = 0; i < file->dependency_count(); i++) {

0 commit comments

Comments
 (0)