Skip to content

Commit

Permalink
Google Closure Compiler Java update (#5720)
Browse files Browse the repository at this point in the history
* Some new externs added to please Closure Compiler, small tweaks to resolve some issues with newer version

* Rewrite multiple `f.write()` calls into single call with more readable JavaScript code inside

* Google Closure Compiler updated to latest v20171023.0.0

* Fix for multiple duplicated `var ptr` declarations.
Fixes to externs (added File API externs).

* Suppress a lot of warnings that naturally occur in asm.js code

* Closure Compiler should run without errors now (warnings are present, but don't cause everything to fail)

* Fix JS optimizer to properly work with added suppression comment (resulted in corrupted JS build).
More externs fixes.

* WebIDL fixes for modern Closure Compiler

* Removed externs already included in latest Closure Compiler

* Fix for multiple declarations of `ASSERTION` variable.
Fix for `EmterpreterAsync` usage appearing in builds without `EmterpreterAsync` definition.
Suppress `FUNCTION_TABLE` undefined variable.
Fix for `getterReturnType` and `setterArgumentType` used while undefined (probably copy-paste typo, replaced with `rawFieldType`).

* Suppress errors about undefined variables
  • Loading branch information
nazar-pc authored and kripken committed Nov 7, 2017
1 parent 7802705 commit 93479ec
Show file tree
Hide file tree
Showing 19 changed files with 960 additions and 1,118 deletions.
25 changes: 13 additions & 12 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2383,18 +2383,19 @@ def modularize(final):
src = open(final).read()
final = final + '.modular.js'
f = open(final, 'w')
f.write('var ' + shared.Settings.EXPORT_NAME + ' = function(' + shared.Settings.EXPORT_NAME + ') {\n')
f.write(' ' + shared.Settings.EXPORT_NAME + ' = ' + shared.Settings.EXPORT_NAME + ' || {};\n')
f.write(' var Module = ' + shared.Settings.EXPORT_NAME + ';\n') # included code may refer to Module (e.g. from file packager), so alias it
f.write('\n')
f.write(src)
f.write('\n')
f.write(' return ' + shared.Settings.EXPORT_NAME + ';\n')
f.write('};\n')
# Export the function if this is for Node (or similar UMD-style exporting), otherwise it is lost.
f.write('if (typeof module === "object" && module.exports) {\n')
f.write(" module['exports'] = " + shared.Settings.EXPORT_NAME + ';\n')
f.write('};\n')
f.write('''var %(EXPORT_NAME)s = function(%(EXPORT_NAME)s) {
%(EXPORT_NAME)s = %(EXPORT_NAME)s || {};
var Module = %(EXPORT_NAME)s; // included code may refer to Module (e.g. from file packager), so alias it
%(src)s
return %(EXPORT_NAME)s;
};
// Export the function if this is for Node (or similar UMD-style exporting), otherwise it is lost.
if (typeof module === "object" && module.exports) {
module['exports'] = %(EXPORT_NAME)s;
};
''' % {"EXPORT_NAME": shared.Settings.EXPORT_NAME, "src": src})
f.close()
if DEBUG: save_intermediate('modularized', 'js')
return final
Expand Down
2 changes: 1 addition & 1 deletion emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ def create_asm_start_pre(asm_setup, the_global, sending, metadata, settings):
module_library = module_get.format(access=access_quote('asmLibraryArg'), val=sending)

asm_function_top = ('// EMSCRIPTEN_START_ASM\n'
'var asm = (function(global, env, buffer) {')
'var asm = (/** @suppress {uselessCode} */ function(global, env, buffer) {')

use_asm = "'almost asm';"
if settings['ASM_JS'] == 1:
Expand Down
1 change: 0 additions & 1 deletion src/arrayUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function intArrayFromString(stringy, dontAddNull, length) {
}

// Temporarily duplicating function pending Python preprocessor support
var ASSERTIONS;
var intArrayToString = ASSERTIONS ?
function (array) {
var ret = [];
Expand Down
299 changes: 190 additions & 109 deletions src/closure-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,6 @@
* The closure_compiler() method in tools/shared.py refers to this file when calling closure.
*/

// Closure externs used by library_uuid.js

/**
* @param {Array} typedArray
*/
crypto.getRandomValues = function(typedArray) {};

/**
BEGIN_NODE_INCLUDE
var crypto = require('crypto');
END_NODE_INCLUDE
*/

/**
* @type {Object.<string,*>}
*/
var crypto = {};

/**
* @param {number} size
* @param {function(Error, buffer.Buffer)} callback
*/
crypto.randomBytes = function(size, callback) {};


// Closure externs used by library_sockfs.js

/**
Expand Down Expand Up @@ -107,93 +82,12 @@ var flags = {};
*/
flags.binary;


/**
* @fileoverview Definitions for W3C's Gamepad specification.
* @see http://www.w3.org/TR/gamepad/
* @externs
*/

/**
* @typedef {{id: string, index: number, timestamp: number, axes: Array.<number>, buttons: Array.<number>}}
*/
var Gamepad;

/**
* @type {Array.<number>}
*/
Gamepad.buttons;

/**
* @type {Array.<number>}
*/
Gamepad.axes;

/**
* @type {number}
*/
Gamepad.index;

/**
* @type {string}
*/
Gamepad.id;

/**
* @type {number}
*/
Gamepad.timestamp;

/**
* @return {Array.<Gamepad>}
*/
navigator.getGamepads = function() {};

/**
* @return {Array.<Gamepad>}
*/
navigator.webkitGetGamepads = function() {};

/**
* @return {Array.<Gamepad>}
*/
navigator.webkitGamepads = function() {};

/**
* @return {Array.<Gamepad>}
*/
navigator.mozGamepads = function() {};

/**
* @return {Array.<Gamepad>}
*/
navigator.gamepads = function() {};

/**
* Backported from latest closure...
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript
*/
Document.prototype.currentScript;

//Atomics library (not yet in latest closure):
//See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics
var Atomics;
Atomics.prototype.NOTEQUAL = -1;
Atomics.prototype.OK = 0;
Atomics.prototype.TIMEDOUT = -2;
Atomics.prototype.add = function(typedArray, index, value) {};
Atomics.prototype.and = function(typedArray, index, value) {};
Atomics.prototype.compareExchange = function(typedArray, index, expectedValue, replacementValue) {};
Atomics.prototype.exchange = function(typedArray, index, value) {};
Atomics.prototype.load = function(typedArray, index) {};
Atomics.prototype.or = function(typedArray, index, value) {};
Atomics.prototype.store = function(typedArray, index, value) {};
Atomics.prototype.sub = function(typedArray, index, value) {};
Atomics.prototype.xor = function(typedArray, index, value) {};
Atomics.prototype.wait = function(typedArray, index, valuei, timeout) {};
Atomics.prototype.wake = function(typedArray, index, value) {};
Atomics.prototype.isLockFree = function(size) {};

/**
* SIMD.js support (not in upstream closure yet).
*/
Expand Down Expand Up @@ -918,7 +812,7 @@ var WebAssembly = {};
* @param {!BufferSource} bytes
*/
WebAssembly.Module = function(bytes) {};
/**
/**
* @constructor
* @param {!WebAssembly.Module} moduleObject
* @param {Object=} importObject
Expand Down Expand Up @@ -978,7 +872,7 @@ WebAssembly.validate = function(bytes) {};
* @return {!Array<{name:string, kind:string}>}
*/
WebAssembly.Module.exports = function(moduleObject) {};
/**
/**
* @param {!WebAssembly.Module} moduleObject
* @return {!Array<{module:string, name:string, kind:string}>}
*/
Expand All @@ -991,7 +885,7 @@ WebAssembly.Module.imports = function(moduleObject) {};
WebAssembly.Module.customSections = function(moduleObject, sectionName) {};
/** @dict */
WebAssembly.Instance.prototype.exports;
/**
/**
* @param {number} delta
* @return {number}
*/
Expand Down Expand Up @@ -1019,3 +913,190 @@ WebAssembly.Table.prototype.get = function(index) {};
* @param {?function(...)} value
*/
WebAssembly.Table.prototype.set = function(index, value) {};

// Random SpiderMonkey/V8 externs

/**
* @param {string} filename
* @param {string} type
* @return {string}
*/
var read = function(filename, type) {};
/**
* @param {string} expression
*/
var print = function(expression) {};
/**
* @param {string} expression
*/
var printErr = function(expression) {};
/**
* @param {string} filename
* @return {ArrayBuffer}
*/
var readbuffer = function(filename) {};
/**
* @const
*/
var scriptArgs = [];
/**
* @const
*/
var quit = function() {};
/**
* @return {number}
*/
var dateNow = function() {};

// WebIDL

/**
* @suppress {duplicate}
*/
var WrapperObject;
/**
* @suppress {duplicate}
*/
var getCache;
/**
* @suppress {duplicate}
*/
var wrapPointer;
/**
* @suppress {duplicate}
*/
var castObject;
/**
* @suppress {duplicate}
*/
var destroy;
/**
* @suppress {duplicate}
*/
var compare;
/**
* @suppress {duplicate}
*/
var getPointer;
/**
* @suppress {duplicate}
*/
var getClass;
/**
* @suppress {duplicate}
*/
var ensureCache;
/**
* @suppress {duplicate}
*/
var ensureString;
/**
* @suppress {duplicate}
*/
var ensureInt8;
/**
* @suppress {duplicate}
*/
var ensureInt16;
/**
* @suppress {duplicate}
*/
var ensureInt32;
/**
* @suppress {duplicate}
*/
var ensureFloat32;
/**
* @suppress {duplicate}
*/
var ensureFloat64;
/**
* @suppress {duplicate}
*/
var VoidPtr;


// Various Emscripten-specific global variables

var tempRet0;
var tempI64;
var tempDouble;
/**
* @suppress {duplicate}
*/
var WasmJS;
/**
* @suppress {duplicate}
*/
var Module;

// Various variables that get into WasmJS of Binaryen, but are not present in final build and never actually used (should probably be fixed in future)
// These are only needed for `interpret-asm2wasm` and not for `asmjs` or `native-wasm`

/**
* @suppress {duplicate}
*/
var Browser;
/**
* @suppress {duplicate}
*/
var SOCKFS = {};
/**
* @suppress {duplicate}
*/
var __read_sockaddr = function(addrp, addrlen) {};
/**
* @suppress {duplicate}
*/
var DNS = {};
/**
* @suppress {duplicate}
*/
var FS;
/**
* @suppress {undefinedVars}
*/
var wakaUnknownAfter;
/**
* @suppress {undefinedVars}
*/
var wakaUnknownBefore;
/**
* @suppress {duplicate}
*/
var env;
/**
* @suppress {duplicate}
*/
var ___cxa_free_exception = function() {};

// On top of node externs to avoid some `declared more than once` errors

/**
* @suppress {duplicate}
*/
var assert;
/**
* @suppress {duplicate}
*/
var buffer;
/**
* @suppress {duplicate}
*/
var fs;
/**
* @suppress {undefinedVars}
*/
var FUNCTION_TABLE;
/**
* @suppress {undefinedVars}
*/
var MozBlobBuilder;
/**
* @suppress {undefinedVars}
*/
var GL;
/**
* @suppress {undefinedVars}
*/
var SDL;
Loading

7 comments on commit 93479ec

@kripken
Copy link
Member

@kripken kripken commented on 93479ec Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke browser.test_emterpretify_file and a bunch of others, with a browser console message that mentions ReferenceError: ASSERTIONS is not defined, so looks related to the recent changes to that variable.

cc @nazar-pc @buu700

@kripken
Copy link
Member

@kripken kripken commented on 93479ec Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was just emterpreter stuff, but looks like it hits several others, e.g. browser.test_emscripten_main_loop_setimmediate

@nazar-pc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to move var ASSERTIONS from jsifier.js into preamble.js or some other common for all builds file, since it is now always defined.

@nazar-pc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filled #5749 that aims to resolve this, but need confirmation from @buu700

@kripken
Copy link
Member

@kripken kripken commented on 93479ec Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also broke several browser tests, such as browser.test_cubegeom_glew. Looks like they all use GL and closure together.

@nazar-pc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look at it shortly

@nazar-pc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filled #5765 that resolves major Closure Compiler complains at least for mentioned browser.test_cubegeom_glew

Please sign in to comment.