Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions generator/js_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3641,26 +3641,7 @@ void Generator::GenerateFile(const GeneratorOptions& options,
if (options.import_style == GeneratorOptions::kImportCommonJsStrict) {
printer->Print("var proto = {};\n\n");
} else {
// To get the global object we call a function with .call(null), this will
// set "this" inside the function to the global object. This does not work
// if we are running in strict mode ("use strict"), so we fallback to the
// following things (in order from first to last):
// - globalThis: cross-platform standard, might not be defined in older
// versions of browsers
// - window: defined in browsers
// - global: defined in most server side environments like NodeJS
// - self: defined inside Web Workers (WorkerGlobalScope)
// - Function('return this')(): this will work on most platforms, but it
// may be blocked by things like CSP.
// Function('') is almost the same as eval('')
printer->Print(
"var global =\n"
" (typeof globalThis !== 'undefined' && globalThis) ||\n"
" (typeof window !== 'undefined' && window) ||\n"
" (typeof global !== 'undefined' && global) ||\n"
" (typeof self !== 'undefined' && self) ||\n"
" (function () { return this; }).call(null) ||\n"
" Function('return this')();\n\n");
printer->Print("var global = globalThis;\n\n");
}

for (int i = 0; i < file->dependency_count(); i++) {
Expand Down
3 changes: 1 addition & 2 deletions internal_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* @fileoverview Internal options for.
* @fileoverview Internal options.
*/
goog.module('jspb.internal_options');

/**
* @return {boolean} True if BigInt is permitted for use and supported by the
* platform.
* @nosideeffects
*/
function isBigIntAvailable() {
return goog.FEATURESET_YEAR >= 2021 || (typeof BigInt === 'function');
Expand Down