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

Fix closure warnings in JS library code #21670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Apr 1, 2024

For some reason closure doesn't report these real issues in the current configuration but they show up in the MODULARIZE_INSTANCE configuration that I'm working on.

Most of these issues consist of adding default parameters to functions declared on objects such as FS.

In addition there are a couple of other changes that are all real fixes:

  • ErrnoError unified between old FS and wasm FS. This should have been done as part of Use JavaScript class for FS.ErrnoError. NFC #21149
  • Default initializer for canvasResizedCallbackTargetThread removed since JSEvents.getTargetThreadForEventCallback() will always return undefined when called with no arguments
  • Extra arguments to copyIndexedColorData removed in library_sdl.js since it only ever called with one arg.
  • Sorting callback for JSEvents.deferredCalls.sort updated to correctly
    return number rather than a boolean.

This change is basically code size neutral with a few tests coming in a byte or two heavier and others a byte or two lighter.

@sbc100 sbc100 requested review from kripken and dschuff April 1, 2024 23:41
@sbc100 sbc100 force-pushed the fix_closure_warnings branch 2 times, most recently from 935bbdf to ca0367c Compare April 2, 2024 18:17
For some reason closure doesn't report these real issues in the current
configuration but they show up in the `MODULARIZE_INSTANCE`
configuration that I'm working on.

Most of these issues consist of adding default parameters to functions
declared on objects such as `FS`.

In addition there are a couple of other changes that are all real fixes:

- ErrnoError unified between old FS and wasm FS.  This should have been
  done as part of emscripten-core#21149
- Default initializer for `canvasResizedCallbackTargetThread` removed
  since `JSEvents.getTargetThreadForEventCallback()` will always return
  undefined when called with no arguments
- Extra arguments to copyIndexedColorData removed in library_sdl.js
  since it only ever called with one arg.
- Sorting callback for JSEvents.deferredCalls.sort updated to correctly
  return number rather than a boolean.

This change is basically code size neutral with a few tests coming in
a byte or two heavier and others a byte or two lighter.
@@ -628,7 +631,7 @@ var LibraryBrowser = {
Browser.resizeListeners.forEach((listener) => listener(canvas.width, canvas.height));
},

setCanvasSize(width, height, noUpdates) {
setCanvasSize(width, height, noUpdates = false) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it better perhaps to use a closure annotation here instead, which would not add code size? (As this is safe - it is just that closure flags it as a possible bug, but here it isn't.)

@dschuff
Copy link
Member

dschuff commented Apr 3, 2024

If you want a third set of eyes on this, then @brendandahl is probably a better set.

@dschuff dschuff requested review from brendandahl and removed request for dschuff April 3, 2024 15:52
for (var i = 0; i < JSEvents.eventHandlers.length; ++i) {
if (JSEvents.eventHandlers[i].target == target &&
(!eventTypeString || eventTypeString == JSEvents.eventHandlers[i].eventTypeString)) {
if (JSEvents.eventHandlers[i].target) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be JSEvents.eventHandlers[i].target == target?

mode = mode !== undefined ? mode : 438 /* 0666 */;
mode &= {{{ cDefs.S_IALLUGO }}};
mode |= {{{ cDefs.S_IFREG }}};
return FS.mknod(path, mode, 0);
},
mkdir(path, mode) {
mkdir(path, mode = undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does Closure optimize these = undefined away?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants