From c993e3da6ae9a5c635f7911801a41e82c7ca9803 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Wed, 21 Feb 2024 18:53:01 +0100 Subject: [PATCH 1/2] Fixes to build with Closure (--closure 1) --- src/closure-externs/closure-externs.js | 9 +++++++++ src/library_browser.js | 11 ++++++++--- src/library_idbfs.js | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/closure-externs/closure-externs.js b/src/closure-externs/closure-externs.js index 9fb433b70a6eb..07eb010f5df5f 100644 --- a/src/closure-externs/closure-externs.js +++ b/src/closure-externs/closure-externs.js @@ -260,3 +260,12 @@ var moduleArg; */ Navigator.prototype.webkitGetUserMedia = function( constraints, successCallback, errorCallback) {}; + +/** + * Global object for custom event target mappings, see: + * https://emscripten.org/docs/api_reference/html5.h.html#how-to-use-this-api + * + * @type {Object} + * @suppress {duplicate} + */ +var specialHTMLTargets; diff --git a/src/library_browser.js b/src/library_browser.js index c493d8be54dc9..f0613644e3e08 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -138,7 +138,9 @@ var LibraryBrowser = { #endif var img = new Image(); img.onload = () => { +#if ASSERTIONS assert(img.complete, `Image ${name} could not be decoded`); +#endif var canvas = /** @type {!HTMLCanvasElement} */ (document.createElement('canvas')); canvas.width = img.width; canvas.height = img.height; @@ -302,8 +304,9 @@ var LibraryBrowser = { if (!ctx) return null; if (setInModule) { +#if ASSERTIONS if (!useWebGL) assert(typeof GLctx == 'undefined', 'cannot set in module if GLctx is used, but we are a non-GL context that would replace it'); - +#endif Module.ctx = ctx; if (useWebGL) GL.makeContextCurrent(contextHandle); Module.useWebGL = useWebGL; @@ -783,8 +786,9 @@ var LibraryBrowser = { return onerror ? onerror() : undefined; } #endif +#if ASSERTIONS assert(runDependencies === 0, 'async_load_script must be run when no other dependencies are active'); - +#endif {{{ runtimeKeepalivePush() }}} var loadDone = () => { @@ -911,8 +915,9 @@ var LibraryBrowser = { * @param {boolean=} noSetTiming */`, $setMainLoop: (browserIterationFunc, fps, simulateInfiniteLoop, arg, noSetTiming) => { +#if ASSERTIONS assert(!Browser.mainLoop.func, 'emscripten_set_main_loop: there can only be one main loop function at once: call emscripten_cancel_main_loop to cancel the previous one before setting a new one with different parameters.'); - +#endif Browser.mainLoop.func = browserIterationFunc; Browser.mainLoop.arg = arg; diff --git a/src/library_idbfs.js b/src/library_idbfs.js index 3f482866b53d7..5831fcd40a2ef 100644 --- a/src/library_idbfs.js +++ b/src/library_idbfs.js @@ -16,7 +16,9 @@ addToLibrary({ if (typeof indexedDB != 'undefined') return indexedDB; var ret = null; if (typeof window == 'object') ret = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; +#if ASSERTIONS assert(ret, 'IDBFS used, but indexedDB not supported'); +#endif return ret; }, DB_VERSION: 21, From 7cdee4f7a294f71c535aaeee38ba4dd2a8762199 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Fri, 23 Feb 2024 10:36:23 +0100 Subject: [PATCH 2/2] Remove annotation from the global externs to local to the lib --- src/closure-externs/closure-externs.js | 9 --------- src/library_html5.js | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/closure-externs/closure-externs.js b/src/closure-externs/closure-externs.js index 07eb010f5df5f..9fb433b70a6eb 100644 --- a/src/closure-externs/closure-externs.js +++ b/src/closure-externs/closure-externs.js @@ -260,12 +260,3 @@ var moduleArg; */ Navigator.prototype.webkitGetUserMedia = function( constraints, successCallback, errorCallback) {}; - -/** - * Global object for custom event target mappings, see: - * https://emscripten.org/docs/api_reference/html5.h.html#how-to-use-this-api - * - * @type {Object} - * @suppress {duplicate} - */ -var specialHTMLTargets; diff --git a/src/library_html5.js b/src/library_html5.js index 50c6877638390..73ce86c7dbd0d 100644 --- a/src/library_html5.js +++ b/src/library_html5.js @@ -315,6 +315,7 @@ var LibraryHTML5 = { // Users can also add more special event targets, basically by just doing something like // specialHTMLTargets["!canvas"] = Module.canvas; // (that will let !canvas map to the canvas held in Module.canvas). + $specialHTMLTargets__docs: '/** @type {Object} */', #if ENVIRONMENT_MAY_BE_WORKER || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL || PTHREADS $specialHTMLTargets: "[0, typeof document != 'undefined' ? document : 0, typeof window != 'undefined' ? window : 0]", #else