Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to build with Closure (--closure 1) #21385

Merged
merged 2 commits into from
Feb 23, 2024
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
11 changes: 8 additions & 3 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */',
cwoffenden marked this conversation as resolved.
Show resolved Hide resolved
#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
Expand Down
2 changes: 2 additions & 0 deletions src/library_idbfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be great to get test coverage for these changes. Perhaps we can add a _closure variant to one or more of the existing browser tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing tests are enough, but I'm guessing aren't being run with both -sSTRICT and --closure. Looking at #20592 when this was introduced @kripken asks "Do we not have any assertions outside of ifdef ASSERTIONS?" the answer is yes, and probably more than I fixed here.

specialHTMLTargets is not the same, that's a regular Closure issue, just rolled into this fix (because it was in front of me at the time).

I don't mind taking a look, but it won't be in the next weeks, and it's probably asking a bigger question: what to do with asserts that aren't guarded and then silently ignored?

Copy link
Member

Choose a reason for hiding this comment

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

I agree adding tests would be good, but I think should not block this from landing as incremental progress towards that goal. Unless you disagree @sbc100 ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I'm fine with landing this. Especially now that it doesn't include the specialHTMLElements thing which was a little confusing to me (since its declared as an array but used like an object).

return ret;
},
DB_VERSION: 21,
Expand Down
Loading