Godot Engine – Multi-platform 2D and 3D game engine
web: Enable closure compiler warnings for engine files
Fabio Alessandrellif58c2c768768
diff --git a/platform/web/emscripten_helpers.py b/platform/web/emscripten_helpers.pyindex ebd800c1182..f387d23f6c3 100644--- a/platform/web/emscripten_helpers.py+++ b/platform/web/emscripten_helpers.py@@ -15,6 +15,13 @@ def run_closure_compiler(target, source, env, for_signature):)cmd = [WhereIs("node"), closure_bin]cmd.extend(["--compilation_level", "ADVANCED_OPTIMIZATIONS"])+ for allow in ["header", "callback"]:+ cmd.extend(["--extra_annotation_name", allow])+ if env["warnings"] != "none":+ if env["werror"]:+ cmd.append("--jscomp_error='*'")+ else:+ cmd.append("--jscomp_warning='*'")for f in env["JSEXTERNS"]:cmd.extend(["--externs", f.get_abspath()])for f in source:diff --git a/platform/web/js/engine/config.js b/platform/web/js/engine/config.jsindex 013a76530df..d78f1e61fc4 100644--- a/platform/web/js/engine/config.js+++ b/platform/web/js/engine/config.js@@ -7,13 +7,14 @@** ``const MyConfig = { executable: 'godot', unloadAfterInit: false }``*- * @typedef {Object} EngineConfig+ * @typedef {!Object} EngineConfig*/const EngineConfig = {}; // eslint-disable-line no-unused-vars/*** @struct* @constructor+ * @param {?EngineConfig} initConfig* @ignore*/const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-vars@@ -21,6 +22,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** Whether to unload the engine automatically after the instance is initialized.*+ * @export* @memberof EngineConfig* @default* @type {boolean}@@ -31,6 +33,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-** By default, the first canvas element in the document will be used is none is specified.*+ * @export* @memberof EngineConfig* @default* @type {?HTMLCanvasElement}@@ -39,6 +42,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** The name of the WASM file without the extension. (Set by Godot Editor export process).*+ * @export* @memberof EngineConfig* @default* @type {string}@@ -47,6 +51,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** An alternative name for the game pck to load. The executable name is used otherwise.*+ * @export* @memberof EngineConfig* @default* @type {?string}@@ -58,6 +63,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-* The browser locale will be used if none is specified. See complete list of* :ref:`supported locales <doc_locales>`.*+ * @export* @memberof EngineConfig* @type {?string}* @default@@ -73,6 +79,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-** ``2`` means Godot will adapt the canvas size to match the whole browser window.*+ * @export* @memberof EngineConfig* @type {number}* @default@@ -85,14 +92,16 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-** **Note**: :js:meth:`startGame <Engine.prototype.startGame>` will always add the ``--main-pack`` argument.*+ * @export* @memberof EngineConfig- * @type {Array<string>}+ * @type {!Array<string>}* @default*/args: [],/*** When enabled, the game canvas will automatically grab the focus when the engine starts.*+ * @export* @memberof EngineConfig* @type {boolean}* @default@@ -101,6 +110,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** When enabled, this will turn on experimental virtual keyboard support on mobile.*+ * @export* @memberof EngineConfig* @type {boolean}* @default@@ -108,6 +118,8 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-experimentalVK: false,/*** The progressive web app service worker to install.+ *+ * @export* @memberof EngineConfig* @default* @type {string}@@ -115,31 +127,37 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-serviceWorker: '',/*** @ignore- * @type {Array.<string>}+ * @export+ * @type {!Array<string>}*/persistentPaths: ['/userfs'],/*** @ignore- * @type {Array.<string>}+ * @export+ * @type {!Array<string>}*/gdextensionLibs: [],/*** @ignore- * @type {Object<string, number>}+ * @export+ * @type {!Object<string, number>}*/fileSizes: {},/*** @ignore+ * @export* @type {number}*/emscriptenPoolSize: 8,/*** @ignore+ * @export* @type {number}*/godotPoolSize: 4,/*** A MessagePort used to send debug messages when using protocol messageport://+ * @export* @memberof EngineConfig* @default* @type {?MessagePort}@@ -148,6 +166,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** The Process ID assigned to this instance (useful for debugging).* @memberof EngineConfig+ * @export* @default* @type {number}*/@@ -159,11 +178,12 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-** @callback EngineConfig.onExecute* @param {string} path The path that Godot's wants executed.- * @param {Array.<string>} args The arguments of the "command" to execute.+ * @param {!Array<string>} args The arguments of the "command" to execute.*//*** @ignore- * @type {?function(string, Array.<string>):?number}+ * @export+ * @type {?function(string, !Array<string>):?number}*/onExecute: null,/**@@ -176,6 +196,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-*//*** @ignore+ * @export* @type {?function(number)}*/onTerminatePID: null,@@ -189,6 +210,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-*//*** @ignore+ * @export* @type {?function(number)}*/onExit: null,@@ -211,6 +233,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-*//*** @ignore+ * @export* @type {?function(number, number)}*/onProgress: null,@@ -224,6 +247,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-*//*** @ignore+ * @export* @type {?function(...*)}*/onPrint: function () {@@ -239,6 +263,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-*//*** @ignore+ * @export* @type {?function(...*)}*/onPrintError: function (var_args) {@@ -248,9 +273,9 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** @ignore- * @struct* @constructor- * @param {EngineConfig} opts+ * @struct+ * @param {?EngineConfig} opts*/function Config(opts) {this.update(opts);@@ -260,50 +285,25 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** @ignore- * @param {EngineConfig} opts+ * @param {?EngineConfig} opts*/Config.prototype.update = function (opts) {const config = opts || {};- // NOTE: We must explicitly pass the default, accessing it via- // the key will fail due to closure compiler renames.- function parse(key, def) {- if (typeof (config[key]) === 'undefined') {- return def;- }- return config[key];- }- // Module config- this.unloadAfterInit = parse('unloadAfterInit', this.unloadAfterInit);- this.onPrintError = parse('onPrintError', this.onPrintError);- this.onPrint = parse('onPrint', this.onPrint);- this.onProgress = parse('onProgress', this.onProgress);-- // Godot config- this.canvas = parse('canvas', this.canvas);- this.executable = parse('executable', this.executable);- this.mainPack = parse('mainPack', this.mainPack);- this.locale = parse('locale', this.locale);- this.canvasResizePolicy = parse('canvasResizePolicy', this.canvasResizePolicy);- this.persistentPaths = parse('persistentPaths', this.persistentPaths);- this.experimentalVK = parse('experimentalVK', this.experimentalVK);- this.focusCanvas = parse('focusCanvas', this.focusCanvas);- this.serviceWorker = parse('serviceWorker', this.serviceWorker);- this.gdextensionLibs = parse('gdextensionLibs', this.gdextensionLibs);- this.fileSizes = parse('fileSizes', this.fileSizes);- this.emscriptenPoolSize = parse('emscriptenPoolSize', this.emscriptenPoolSize);- this.godotPoolSize = parse('godotPoolSize', this.godotPoolSize);- this.pid = parse('pid', this.pid);- this.args = parse('args', this.args);- this.debugPort = parse('debugPort', this.debugPort);- this.onExecute = parse('onExecute', this.onExecute);- this.onTerminatePID = parse('onTerminatePID', this.onTerminatePID);- this.onExit = parse('onExit', this.onExit);+ const me = this;+ Object.keys(cfg).forEach((key) => {+ /**+ * @ignore+ * @suppress {checkTypes}+ */+ me[key] = typeof (config[key]) === 'undefined' ? me[key] : config[key];+ });};/*** @ignore* @param {string} loadPath- * @param {Response} response+ * @param {!Response} response+ * @return {!Object}*/Config.prototype.getModuleConfig = function (loadPath, response) {let r = response;@@ -353,6 +353,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-/*** @ignore* @param {function()} cleanup+ * @return {!Object}*/Config.prototype.getGodotConfig = function (cleanup) {// Try to find a canvasdiff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.jsindex 9575681c4ff..592a97f9e90 100644--- a/platform/web/js/engine/engine.js+++ b/platform/web/js/engine/engine.js@@ -24,7 +24,7 @@ const Engine = (function () {** @global* @constructor- * @param {EngineConfig} initConfig The initial config for this instance.+ * @param {?EngineConfig} initConfig The initial config for this instance.*/function Engine(initConfig) { // eslint-disable-line no-shadowthis.config = new InternalConfig(initConfig);@@ -34,9 +34,10 @@ const Engine = (function () {/*** Load the engine from the specified base path.*+ * @export* @param {string} basePath Base path of the engine to load.* @param {number=} [size=0] The file size if known.- * @returns {Promise} A Promise that resolves once the engine is loaded.+ * @return {!Promise} A Promise that resolves once the engine is loaded.** @function Engine.load*/@@ -54,6 +55,7 @@ const Engine = (function () {** This method will be called automatically depending on the configuration. See :js:attr:`unloadAfterInit`.*+ * @export* @function Engine.unload*/Engine.unload = function () {@@ -71,8 +73,9 @@ const Engine = (function () {* Initialize the engine instance. Optionally, pass the base path to the engine to load it,* if it hasn't been loaded yet. See :js:meth:`Engine.load`.*+ * @export* @param {string=} basePath Base path of the engine to load.- * @return {Promise} A Promise that resolves once the engine is loaded and initialized.+ * @return {!Promise} A Promise that resolves once the engine is loaded and initialized.*/init: function (basePath) {if (initPromise) {@@ -117,18 +120,19 @@ const Engine = (function () {** If not provided, the ``path`` is derived from the URL of the loaded file.*- * @param {string|ArrayBuffer} file The file to preload.+ * @param {string|!ArrayBuffer} file The file to preload.** If a ``string`` the file will be loaded from that path.** If an ``ArrayBuffer`` or a view on one, the buffer will used as the content of the file.*+ * @export* @param {string=} path Path by which the file will be accessible. Required, if ``file`` is not a string.- *- * @returns {Promise} A Promise that resolves once the file is loaded.+ * @return {!Promise} A Promise that resolves once the file is loaded.*/preloadFile: function (file, path) {- return preloader.preload(file, path, this.config.fileSizes[file]);+ const size = typeof (file) == 'string' ? this.config.fileSizes[file] : 0;+ return preloader.preload(file, path, size);},/**@@ -140,8 +144,9 @@ const Engine = (function () {** Fails if a canvas cannot be found on the page, or not specified in the configuration.*- * @param {EngineConfig} override An optional configuration override.- * @return {Promise} A Promise that resolves once the engine started.+ * @export+ * @param {?EngineConfig} override An optional configuration override.+ * @return {!Promise} A Promise that resolves once the engine started.*/start: function (override) {this.config.update(override);@@ -190,8 +195,9 @@ const Engine = (function () {* This method expects the initial config (or the override) to have both the :js:attr:`executable` and :js:attr:`mainPack`* properties set (normally done by the editor during export).*- * @param {EngineConfig} override An optional configuration override.- * @return {Promise} A Promise that resolves once the game started.+ * @export+ * @param {?EngineConfig} override An optional configuration override.+ * @return {!Promise} A Promise that resolves once the game started.*/startGame: function (override) {this.config.update(override);@@ -212,8 +218,9 @@ const Engine = (function () {/*** Create a file at the specified ``path`` with the passed as ``buffer`` in the instance's file system.*+ * @export* @param {string} path The location where the file will be created.- * @param {ArrayBuffer} buffer The content of the file.+ * @param {!ArrayBuffer} buffer The content of the file.*/copyToFS: function (path, buffer) {if (this.rtenv == null) {@@ -228,6 +235,7 @@ const Engine = (function () {* This is akin the user pressing the close button in the window manager, and will* have no effect if the engine has crashed, or is stuck in a loop.*+ * @export*/requestQuit: function () {if (this.rtenv) {@@ -241,6 +249,7 @@ const Engine = (function () {* This is akin to terminating the process on a regular OS, and *may* be able to terminate* the engine and free resources even if the engine has crashed, or is stuck in a loop.*+ * @export*/forceQuit: function () {if (this.rtenv) {@@ -253,7 +262,8 @@ const Engine = (function () {** Adds a new EditorDebuggerSession connected via the given port.*- * @param {MessagePort} port The port used for the debugger session.+ * @export+ * @param {!MessagePort} port The port used for the debugger session.*/addDebuggerSession: function (port) {if (this.rtenv) {@@ -263,7 +273,9 @@ const Engine = (function () {/*** Install the progressive-web app service worker.- * @returns {Promise} The service worker registration promise.+ *+ * @export+ * @return {!Promise} The service worker registration promise.*/installServiceWorker: function () {if (this.config.serviceWorker && 'serviceWorker' in navigator) {@@ -278,19 +290,6 @@ const Engine = (function () {};Engine.prototype = proto;- // Closure compiler exported instance methods.- Engine.prototype['init'] = Engine.prototype.init;- Engine.prototype['preloadFile'] = Engine.prototype.preloadFile;- Engine.prototype['start'] = Engine.prototype.start;- Engine.prototype['startGame'] = Engine.prototype.startGame;- Engine.prototype['copyToFS'] = Engine.prototype.copyToFS;- Engine.prototype['requestQuit'] = Engine.prototype.requestQuit;- Engine.prototype['forceQuit'] = Engine.prototype.forceQuit;- Engine.prototype['addDebuggerSession'] = Engine.prototype.addDebuggerSession;- Engine.prototype['installServiceWorker'] = Engine.prototype.installServiceWorker;- // Also expose static methods as instance methods- Engine.prototype['load'] = Engine.load;- Engine.prototype['unload'] = Engine.unload;return new Engine(initConfig);}diff --git a/platform/web/js/engine/features.js b/platform/web/js/engine/features.jsindex 20b0500436e..12d8ac9113c 100644--- a/platform/web/js/engine/features.js+++ b/platform/web/js/engine/features.js@@ -8,7 +8,8 @@ const Features = {*/isWebGLAvailable: function (majorVersion = 1) {try {- return !!document.createElement('canvas').getContext(['webgl', 'webgl2'][majorVersion - 1]);+ const canvas = /** @type {!HTMLCanvasElement} */ (document.createElement('canvas'));+ return !!canvas.getContext(['webgl', 'webgl2'][majorVersion - 1]);} catch (e) { /* Not available */ }return false;},@@ -70,9 +71,9 @@ const Features = {/*** Return an array of missing required features (as string).*- * @returns {Array<string>} A list of human-readable missing features.+ * @returns {!Array<string>} A list of human-readable missing features.* @function Engine.getMissingFeatures- * @param {{threads: (boolean|undefined)}} supportedFeatures+ * @param {{threads: (boolean|undefined)}=} supportedFeatures*/getMissingFeatures: function (supportedFeatures = {}) {const {