Skip to content

Commit 935bbdf

Browse files
committed
Fix closure warnings in JS library code
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.
1 parent a8b489d commit 935bbdf

27 files changed

+106
-119
lines changed

src/library_browser.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ var LibraryBrowser = {
5454
timingValue: 0,
5555
currentFrameNumber: 0,
5656
queue: [],
57+
#if USE_CLOSURE_COMPILER
58+
expectedBlockers: 0,
59+
#endif
5760
pause() {
5861
Browser.mainLoop.scheduler = null;
5962
// Incrementing this signals the previous main loop that it's now become old, and it must return.
@@ -628,7 +631,7 @@ var LibraryBrowser = {
628631
Browser.resizeListeners.forEach((listener) => listener(canvas.width, canvas.height));
629632
},
630633

631-
setCanvasSize(width, height, noUpdates) {
634+
setCanvasSize(width, height, noUpdates = false) {
632635
var canvas = Module['canvas'];
633636
Browser.updateCanvasDimensions(canvas, width, height);
634637
if (!noUpdates) Browser.updateResizeListeners();
@@ -658,7 +661,7 @@ var LibraryBrowser = {
658661
Browser.updateResizeListeners();
659662
},
660663

661-
updateCanvasDimensions(canvas, wNative, hNative) {
664+
updateCanvasDimensions(canvas, wNative = 0, hNative = 0) {
662665
if (wNative && hNative) {
663666
canvas.widthNative = wNative;
664667
canvas.heightNative = hNative;

src/library_fs.js

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ FS.staticInit();` +
5151
devices: {},
5252
streams: [],
5353
nextInode: 1,
54-
nameTable: null,
5554
currentPath: '/',
5655
initialized: false,
5756
// Whether we are currently ignoring permissions. Useful when preparing the
@@ -62,40 +61,10 @@ FS.staticInit();` +
6261
#if FS_DEBUG
6362
trackingDelegate: {},
6463
#endif
65-
ErrnoError: null, // set during init
6664
genericErrors: {},
6765
filesystems: null,
6866
syncFSRequests: 0, // we warn if there are multiple in flight at once
69-
70-
#if ASSERTIONS
71-
ErrnoError: class extends Error {
72-
#else
73-
ErrnoError: class {
74-
#endif
75-
// We set the `name` property to be able to identify `FS.ErrnoError`
76-
// - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
77-
// - when using PROXYFS, an error can come from an underlying FS
78-
// as different FS objects have their own FS.ErrnoError each,
79-
// the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
80-
// we'll use the reliable test `err.name == "ErrnoError"` instead
81-
constructor(errno) {
82-
#if ASSERTIONS
83-
super(ERRNO_MESSAGES[errno]);
84-
#endif
85-
// TODO(sbc): Use the inline member declaration syntax once we
86-
// support it in acorn and closure.
87-
this.name = 'ErrnoError';
88-
this.errno = errno;
89-
#if ASSERTIONS
90-
for (var key in ERRNO_CODES) {
91-
if (ERRNO_CODES[key] === errno) {
92-
this.code = key;
93-
break;
94-
}
95-
}
96-
#endif
97-
}
98-
},
67+
ErrnoError: SharedErrnoError,
9968

10069
FSStream: class {
10170
constructor() {
@@ -304,7 +273,7 @@ FS.staticInit();` +
304273
// if we failed to find it in the cache, call into the VFS
305274
return FS.lookup(parent, name);
306275
},
307-
createNode(parent, name, mode, rdev) {
276+
createNode(parent, name, mode, rdev = 0) {
308277
#if ASSERTIONS
309278
assert(typeof parent == 'object')
310279
#endif
@@ -670,13 +639,13 @@ FS.staticInit();` +
670639
return parent.node_ops.mknod(parent, name, mode, dev);
671640
},
672641
// helpers to create specific types of nodes
673-
create(path, mode) {
642+
create(path, mode = undefined) {
674643
mode = mode !== undefined ? mode : 438 /* 0666 */;
675644
mode &= {{{ cDefs.S_IALLUGO }}};
676645
mode |= {{{ cDefs.S_IFREG }}};
677646
return FS.mknod(path, mode, 0);
678647
},
679-
mkdir(path, mode) {
648+
mkdir(path, mode = undefined) {
680649
mode = mode !== undefined ? mode : 511 /* 0777 */;
681650
mode &= {{{ cDefs.S_IRWXUGO }}} | {{{ cDefs.S_ISVTX }}};
682651
mode |= {{{ cDefs.S_IFDIR }}};
@@ -688,7 +657,7 @@ FS.staticInit();` +
688657
return FS.mknod(path, mode, 0);
689658
},
690659
// Creates a whole directory tree chain if it doesn't yet exist
691-
mkdirTree(path, mode) {
660+
mkdirTree(path, mode = undefined) {
692661
var dirs = path.split('/');
693662
var d = '';
694663
for (var i = 0; i < dirs.length; ++i) {
@@ -701,7 +670,7 @@ FS.staticInit();` +
701670
}
702671
}
703672
},
704-
mkdev(path, mode, dev) {
673+
mkdev(path, mode, dev = undefined) {
705674
if (typeof dev == 'undefined') {
706675
dev = mode;
707676
mode = 438 /* 0666 */;
@@ -906,7 +875,7 @@ FS.staticInit();` +
906875
}
907876
return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link));
908877
},
909-
stat(path, dontFollow) {
878+
stat(path, dontFollow = false) {
910879
var lookup = FS.lookupPath(path, { follow: !dontFollow });
911880
var node = lookup.node;
912881
if (!node) {
@@ -920,7 +889,7 @@ FS.staticInit();` +
920889
lstat(path) {
921890
return FS.stat(path, true);
922891
},
923-
chmod(path, mode, dontFollow) {
892+
chmod(path, mode, dontFollow = false) {
924893
var node;
925894
if (typeof path == 'string') {
926895
var lookup = FS.lookupPath(path, { follow: !dontFollow });
@@ -943,7 +912,7 @@ FS.staticInit();` +
943912
var stream = FS.getStreamChecked(fd);
944913
FS.chmod(stream.node, mode);
945914
},
946-
chown(path, uid, gid, dontFollow) {
915+
chown(path, uid, gid, dontFollow = false) {
947916
var node;
948917
if (typeof path == 'string') {
949918
var lookup = FS.lookupPath(path, { follow: !dontFollow });
@@ -1009,7 +978,7 @@ FS.staticInit();` +
1009978
timestamp: Math.max(atime, mtime)
1010979
});
1011980
},
1012-
open(path, flags, mode) {
981+
open(path, flags, mode = undefined) {
1013982
if (path === "") {
1014983
throw new FS.ErrnoError({{{ cDefs.ENOENT }}});
1015984
}
@@ -1187,7 +1156,7 @@ FS.staticInit();` +
11871156
#endif
11881157
return bytesRead;
11891158
},
1190-
write(stream, buffer, offset, length, position, canOwn) {
1159+
write(stream, buffer, offset, length, position = undefined, canOwn = false) {
11911160
#if ASSERTIONS
11921161
assert(offset >= 0);
11931162
#endif
@@ -1460,7 +1429,7 @@ FS.staticInit();` +
14601429
#endif
14611430
};
14621431
},
1463-
init(input, output, error) {
1432+
init(input = undefined, output = undefined, error = undefined) {
14641433
#if ASSERTIONS
14651434
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)');
14661435
#endif
@@ -1499,7 +1468,7 @@ FS.staticInit();` +
14991468
}
15001469
return ret.object;
15011470
},
1502-
analyzePath(path, dontResolveLastLink) {
1471+
analyzePath(path, dontResolveLastLink = false) {
15031472
// operate from within the context of the symlink's target
15041473
try {
15051474
var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
@@ -1570,7 +1539,7 @@ FS.staticInit();` +
15701539
FS.chmod(node, mode);
15711540
}
15721541
},
1573-
createDevice(parent, name, input, output) {
1542+
createDevice(parent, name, input, output = undefined) {
15741543
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
15751544
var mode = FS_getMode(!!input, !!output);
15761545
if (!FS.createDevice.major) FS.createDevice.major = 64;

src/library_fs_shared.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7+
#if ASSERTIONS
8+
class SharedErrnoError extends Error {
9+
#else
10+
class SharedErrnoError {
11+
#endif
12+
// We set the `name` property to be able to identify `FS.ErrnoError`
13+
// - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
14+
// - when using PROXYFS, an error can come from an underlying FS
15+
// as different FS objects have their own FS.ErrnoError each,
16+
// the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
17+
// we'll use the reliable test `err.name == "ErrnoError"` instead
18+
constructor(errno) {
19+
#if ASSERTIONS
20+
super(ERRNO_MESSAGES[errno]);
21+
#endif
22+
// TODO(sbc): Use the inline member declaration syntax once we
23+
// support it in acorn and closure.
24+
this.name = 'ErrnoError';
25+
this.errno = errno;
26+
#if ASSERTIONS
27+
for (var key in ERRNO_CODES) {
28+
if (ERRNO_CODES[key] === errno) {
29+
this.code = key;
30+
break;
31+
}
32+
}
33+
#endif
34+
}
35+
}
36+
737
addToLibrary({
838
$preloadPlugins: "{{{ makeModuleReceiveExpr('preloadPlugins', '[]') }}}",
939

@@ -50,7 +80,7 @@ addToLibrary({
5080
'$FS_handledByPreloadPlugin',
5181
#endif
5282
],
53-
$FS_createPreloadedFile: (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
83+
$FS_createPreloadedFile: (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn = false, preFinish = undefined) => {
5484
// TODO we should allow people to just pass in a complete filename instead
5585
// of parent and name being that we just join them anyways
5686
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;

src/library_glemu.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ var LibraryGLEmulation = {
6969
fogStart: 0,
7070
fogEnd: 1,
7171
fogDensity: 1.0,
72-
fogColor: null,
7372
fogMode: 0x800, // GL_EXP
7473
fogEnabled: false,
7574

@@ -2127,7 +2126,7 @@ var LibraryGLEmulation = {
21272126
return renderer;
21282127
},
21292128

2130-
createRenderer(renderer) {
2129+
createRenderer() {
21312130
var useCurrProgram = !!GL.currProgram;
21322131
var hasTextures = false;
21332132
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
@@ -2995,7 +2994,7 @@ var LibraryGLEmulation = {
29952994
}
29962995
},
29972996

2998-
flush(numProvidedIndexes, startIndex = 0, ptr = 0) {
2997+
flush(numProvidedIndexes = 0, startIndex = 0, ptr = 0) {
29992998
#if ASSERTIONS
30002999
assert(numProvidedIndexes >= 0 || !numProvidedIndexes);
30013000
#endif

src/library_html5.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ var LibraryHTML5 = {
9494
return true;
9595
}
9696
// Test if the given call was already queued, and if so, don't add it again.
97-
for (var i in JSEvents.deferredCalls) {
98-
var call = JSEvents.deferredCalls[i];
97+
for (var call of JSEvents.deferredCalls) {
9998
if (call.targetFunction == targetFunction && arraysHaveEqualContent(call.argsList, argsList)) {
10099
return;
101100
}
@@ -106,7 +105,10 @@ var LibraryHTML5 = {
106105
argsList
107106
});
108107

109-
JSEvents.deferredCalls.sort((x,y) => x.precedence < y.precedence);
108+
// sortcallback(x, y):
109+
// A negative value indicates that x should come before y.
110+
// A positive value indicates that x should come after y.
111+
JSEvents.deferredCalls.sort((x,y) => y.precedence - x.precedence);
110112
},
111113

112114
// Erases all deferred calls to the given target function from the queue list.
@@ -151,10 +153,9 @@ var LibraryHTML5 = {
151153
// Removes all event handlers on the given DOM element of the given type.
152154
// Pass in eventTypeString == undefined/null to remove all event handlers
153155
// regardless of the type.
154-
removeAllHandlersOnTarget: (target, eventTypeString) => {
156+
removeAllHandlersOnTarget: (target) => {
155157
for (var i = 0; i < JSEvents.eventHandlers.length; ++i) {
156-
if (JSEvents.eventHandlers[i].target == target &&
157-
(!eventTypeString || eventTypeString == JSEvents.eventHandlers[i].eventTypeString)) {
158+
if (JSEvents.eventHandlers[i].target) {
158159
JSEvents._removeHandler(i--);
159160
}
160161
}
@@ -1512,9 +1513,6 @@ var LibraryHTML5 = {
15121513
filteringMode: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.filteringMode, 'i32') }}},
15131514
canvasResizedCallback: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallback, 'i32') }}},
15141515
canvasResizedCallbackUserData: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallbackUserData, 'i32') }}},
1515-
#if PTHREADS
1516-
canvasResizedCallbackTargetThread: JSEvents.getTargetThreadForEventCallback(),
1517-
#endif
15181516
target,
15191517
softFullscreen: true
15201518
};

src/library_nodefs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ addToLibrary({
5353
#if ASSERTIONS
5454
assert(ENVIRONMENT_IS_NODE);
5555
#endif
56-
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
56+
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root));
5757
},
58-
createNode(parent, name, mode, dev) {
58+
createNode(parent, name, mode) {
5959
if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
6060
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
6161
}
@@ -169,7 +169,7 @@ addToLibrary({
169169
return NODEFS.createNode(parent, name, mode);
170170
},
171171
mknod(parent, name, mode, dev) {
172-
var node = NODEFS.createNode(parent, name, mode, dev);
172+
var node = NODEFS.createNode(parent, name, mode);
173173
// create the backing node for this in the fs root as well
174174
var path = NODEFS.realPath(node);
175175
try {
@@ -320,7 +320,7 @@ addToLibrary({
320320
return { ptr, allocated: true };
321321
},
322322
msync(stream, buffer, offset, length, mmapFlags) {
323-
NODEFS.stream_ops.write(stream, buffer, 0, length, offset, false);
323+
NODEFS.stream_ops.write(stream, buffer, 0, length, offset);
324324
// should we check if bytesWritten and length are the same?
325325
return 0;
326326
}

src/library_openal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ var LibraryOpenAL = {
103103
// represents the queue of buffers scheduled for physical playback. These two queues are
104104
// distinct because of the differing semantics of OpenAL and web audio. Some changes
105105
// to OpenAL parameters, such as pitch, may require the web audio queue to be flushed and rescheduled.
106-
scheduleSourceAudio: (src, lookahead) => {
106+
scheduleSourceAudio: (src, lookahead = false) => {
107107
// See comment on scheduleContextAudio above.
108108
if (Browser.mainLoop.timingMode === {{{ cDefs.EM_TIMING_RAF }}} && document['visibilityState'] != 'visible') {
109109
return;

0 commit comments

Comments
 (0)