-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
sbc100
wants to merge
1
commit into
emscripten-core:main
Choose a base branch
from
sbc100:fix_closure_warnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,6 @@ FS.staticInit();` + | |
devices: {}, | ||
streams: [], | ||
nextInode: 1, | ||
nameTable: null, | ||
currentPath: '/', | ||
initialized: false, | ||
// Whether we are currently ignoring permissions. Useful when preparing the | ||
|
@@ -62,40 +61,10 @@ FS.staticInit();` + | |
#if FS_DEBUG | ||
trackingDelegate: {}, | ||
#endif | ||
ErrnoError: null, // set during init | ||
genericErrors: {}, | ||
filesystems: null, | ||
syncFSRequests: 0, // we warn if there are multiple in flight at once | ||
|
||
#if ASSERTIONS | ||
ErrnoError: class extends Error { | ||
#else | ||
ErrnoError: class { | ||
#endif | ||
// We set the `name` property to be able to identify `FS.ErrnoError` | ||
// - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway. | ||
// - when using PROXYFS, an error can come from an underlying FS | ||
// as different FS objects have their own FS.ErrnoError each, | ||
// the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs. | ||
// we'll use the reliable test `err.name == "ErrnoError"` instead | ||
constructor(errno) { | ||
#if ASSERTIONS | ||
super(ERRNO_MESSAGES[errno]); | ||
#endif | ||
// TODO(sbc): Use the inline member declaration syntax once we | ||
// support it in acorn and closure. | ||
this.name = 'ErrnoError'; | ||
this.errno = errno; | ||
#if ASSERTIONS | ||
for (var key in ERRNO_CODES) { | ||
if (ERRNO_CODES[key] === errno) { | ||
this.code = key; | ||
break; | ||
} | ||
} | ||
#endif | ||
} | ||
}, | ||
ErrnoError: ErrnoError, | ||
|
||
FSStream: class { | ||
constructor() { | ||
|
@@ -304,7 +273,7 @@ FS.staticInit();` + | |
// if we failed to find it in the cache, call into the VFS | ||
return FS.lookup(parent, name); | ||
}, | ||
createNode(parent, name, mode, rdev) { | ||
createNode(parent, name, mode, rdev = 0) { | ||
#if ASSERTIONS | ||
assert(typeof parent == 'object') | ||
#endif | ||
|
@@ -670,13 +639,13 @@ FS.staticInit();` + | |
return parent.node_ops.mknod(parent, name, mode, dev); | ||
}, | ||
// helpers to create specific types of nodes | ||
create(path, mode) { | ||
create(path, mode = undefined) { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does Closure optimize these |
||
mode = mode !== undefined ? mode : 511 /* 0777 */; | ||
mode &= {{{ cDefs.S_IRWXUGO }}} | {{{ cDefs.S_ISVTX }}}; | ||
mode |= {{{ cDefs.S_IFDIR }}}; | ||
|
@@ -688,7 +657,7 @@ FS.staticInit();` + | |
return FS.mknod(path, mode, 0); | ||
}, | ||
// Creates a whole directory tree chain if it doesn't yet exist | ||
mkdirTree(path, mode) { | ||
mkdirTree(path, mode = undefined) { | ||
var dirs = path.split('/'); | ||
var d = ''; | ||
for (var i = 0; i < dirs.length; ++i) { | ||
|
@@ -701,7 +670,7 @@ FS.staticInit();` + | |
} | ||
} | ||
}, | ||
mkdev(path, mode, dev) { | ||
mkdev(path, mode, dev = undefined) { | ||
if (typeof dev == 'undefined') { | ||
dev = mode; | ||
mode = 438 /* 0666 */; | ||
|
@@ -906,7 +875,7 @@ FS.staticInit();` + | |
} | ||
return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link)); | ||
}, | ||
stat(path, dontFollow) { | ||
stat(path, dontFollow = false) { | ||
var lookup = FS.lookupPath(path, { follow: !dontFollow }); | ||
var node = lookup.node; | ||
if (!node) { | ||
|
@@ -920,7 +889,7 @@ FS.staticInit();` + | |
lstat(path) { | ||
return FS.stat(path, true); | ||
}, | ||
chmod(path, mode, dontFollow) { | ||
chmod(path, mode, dontFollow = false) { | ||
var node; | ||
if (typeof path == 'string') { | ||
var lookup = FS.lookupPath(path, { follow: !dontFollow }); | ||
|
@@ -943,7 +912,7 @@ FS.staticInit();` + | |
var stream = FS.getStreamChecked(fd); | ||
FS.chmod(stream.node, mode); | ||
}, | ||
chown(path, uid, gid, dontFollow) { | ||
chown(path, uid, gid, dontFollow = false) { | ||
var node; | ||
if (typeof path == 'string') { | ||
var lookup = FS.lookupPath(path, { follow: !dontFollow }); | ||
|
@@ -1009,7 +978,7 @@ FS.staticInit();` + | |
timestamp: Math.max(atime, mtime) | ||
}); | ||
}, | ||
open(path, flags, mode) { | ||
open(path, flags, mode = undefined) { | ||
if (path === "") { | ||
throw new FS.ErrnoError({{{ cDefs.ENOENT }}}); | ||
} | ||
|
@@ -1187,7 +1156,7 @@ FS.staticInit();` + | |
#endif | ||
return bytesRead; | ||
}, | ||
write(stream, buffer, offset, length, position, canOwn) { | ||
write(stream, buffer, offset, length, position = undefined, canOwn = false) { | ||
#if ASSERTIONS | ||
assert(offset >= 0); | ||
#endif | ||
|
@@ -1460,7 +1429,7 @@ FS.staticInit();` + | |
#endif | ||
}; | ||
}, | ||
init(input, output, error) { | ||
init(input = undefined, output = undefined, error = undefined) { | ||
#if ASSERTIONS | ||
assert(!FS.init.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)'); | ||
#endif | ||
|
@@ -1499,7 +1468,7 @@ FS.staticInit();` + | |
} | ||
return ret.object; | ||
}, | ||
analyzePath(path, dontResolveLastLink) { | ||
analyzePath(path, dontResolveLastLink = false) { | ||
// operate from within the context of the symlink's target | ||
try { | ||
var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink }); | ||
|
@@ -1570,7 +1539,7 @@ FS.staticInit();` + | |
FS.chmod(node, mode); | ||
} | ||
}, | ||
createDevice(parent, name, input, output) { | ||
createDevice(parent, name, input, output = undefined) { | ||
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name); | ||
var mode = FS_getMode(!!input, !!output); | ||
if (!FS.createDevice.major) FS.createDevice.major = 64; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,8 +94,7 @@ var LibraryHTML5 = { | |
return true; | ||
} | ||
// Test if the given call was already queued, and if so, don't add it again. | ||
for (var i in JSEvents.deferredCalls) { | ||
var call = JSEvents.deferredCalls[i]; | ||
for (var call of JSEvents.deferredCalls) { | ||
if (call.targetFunction == targetFunction && arraysHaveEqualContent(call.argsList, argsList)) { | ||
return; | ||
} | ||
|
@@ -106,7 +105,10 @@ var LibraryHTML5 = { | |
argsList | ||
}); | ||
|
||
JSEvents.deferredCalls.sort((x,y) => x.precedence < y.precedence); | ||
// sortcallback(x, y): | ||
// A negative value indicates that x should come before y. | ||
// A positive value indicates that x should come after y. | ||
JSEvents.deferredCalls.sort((x,y) => y.precedence - x.precedence); | ||
}, | ||
|
||
// Erases all deferred calls to the given target function from the queue list. | ||
|
@@ -151,10 +153,9 @@ var LibraryHTML5 = { | |
// Removes all event handlers on the given DOM element of the given type. | ||
// Pass in eventTypeString == undefined/null to remove all event handlers | ||
// regardless of the type. | ||
removeAllHandlersOnTarget: (target, eventTypeString) => { | ||
removeAllHandlersOnTarget: (target) => { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be |
||
JSEvents._removeHandler(i--); | ||
} | ||
} | ||
|
@@ -1512,9 +1513,6 @@ var LibraryHTML5 = { | |
filteringMode: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.filteringMode, 'i32') }}}, | ||
canvasResizedCallback: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallback, 'i32') }}}, | ||
canvasResizedCallbackUserData: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallbackUserData, 'i32') }}}, | ||
#if PTHREADS | ||
canvasResizedCallbackTargetThread: JSEvents.getTargetThreadForEventCallback(), | ||
#endif | ||
target, | ||
softFullscreen: true | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.)