8000 Syncing from internal · graup/protobuf-javascript@5b9dd92 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b9dd92

Browse files
committed
Syncing from internal
2 parents 9ad78c5 + 31aec6f commit 5b9dd92

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

commonjs/export.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ goog.require('jspb.ExtensionFieldInfo');
1515
goog.require('jspb.Message');
1616
goog.require('jspb.Map');
1717

18-
if ( typeof exports === 'object' ) {
18+
if (typeof exports === 'object') {
1919
exports.Map = jspb.Map;
2020
exports.Message = jspb.Message;
2121
exports.BinaryReader = jspb.BinaryReader;
2222
exports.BinaryWriter = jspb.BinaryWriter;
2323
exports.ExtensionFieldInfo = jspb.ExtensionFieldInfo;
2424
exports.ExtensionFieldBinaryInfo = jspb.ExtensionFieldBinaryInfo;
2525

26-
// These are used by generated code but should not be used directly by clients.
26+
// These are used by generated code but should not be used directly by
27+
// clients.
2728
exports.exportSymbol = goog.exportSymbol;
2829
exports.inherits = goog.inherits;
2930
exports.object = {extend: goog.object.extend};

src/google/protobuf/compiler/js/js_generator.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,23 +3625,19 @@ void Generator::GenerateFile(const GeneratorOptions& options,
36253625
if (options.import_style == GeneratorOptions::kImportCommonJsStrict) {
36263626
printer->Print("var proto = {};\n\n");
36273627
} else {
3628-
// To get the global object we call a function with .call(null), this will set "this" inside the
3629-
// function to the global object.
3630-
// This does not work if we are running in strict mode ("use strict"),
3631-
// so we fallback to the following things (in order from first to last):
3628+
// To get the global object we call a function with .call(null), this will
3629+
// set "this" inside the function to the global object. This does not work
3630+
// if we are running in strict mode ("use strict"), so we fallback to the
3631+
// following things (in order from first to last):
36323632
// - window: defined in browsers
36333633
// - global: defined in most server side environments like NodeJS
36343634
// - self: defined inside Web Workers (WorkerGlobalScope)
3635-
// - Function('return this')(): this will work on most platforms, but it may be blocked by things like CSP.
3635+
// - Function('return this')(): this will work on most platforms, but it
3636+
// may be blocked by things like CSP.
36363637
// Function('') is almost the same as eval('')
36373638
printer->Print(
3638-
"var global = (function() {\n"
3639-
" if (this) { return this; }\n"
3640-
" if (typeof window !== 'undefined') { return window; }\n"
3641-
" if (typeof global !== 'undefined') { return global; }\n"
3642-
" if (typeof self !== 'undefined') { return self; }\n"
3643-
" return Function('return this')();\n"
3644-
"}.call(null));\n\n");
3639+
"var global = (function() { return this || window || global || self "
3640+
"|| Function('return this')(); }).call(null);\n\n");
36453641
}
36463642

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

0 commit comments

Comments
 (0)
0