diff --git a/src/lib/libfs_shared.js b/src/lib/libfs_shared.js index 48359df38a74a..4ec5921df1660 100644 --- a/src/lib/libfs_shared.js +++ b/src/lib/libfs_shared.js @@ -19,15 +19,13 @@ addToLibrary({ if (typeof Browser != 'undefined') Browser.init(); #endif - var handled = false; - preloadPlugins.forEach((plugin) => { - if (handled) return; + for (var plugin of preloadPlugins) { if (plugin['canHandle'](fullname)) { plugin['handle'](byteArray, fullname, finish, onerror); - handled = true; + return true; } - }); - return handled; + } + return false; }, #endif diff --git a/src/lib/liblz4.js b/src/lib/liblz4.js index 3f651506bf49e..9022ae6c65df0 100644 --- a/src/lib/liblz4.js +++ b/src/lib/liblz4.js @@ -30,7 +30,7 @@ addToLibrary({ compressedData['cachedOffset'] + (i+1)*LZ4.CHUNK_SIZE); assert(compressedData['cachedChunks'][i].length === LZ4.CHUNK_SIZE); } - pack['metadata'].files.forEach((file) => { + for (var file of pack['metadata'].files) { var dir = PATH.dirname(file.filename); var name = PATH.basename(file.filename); FS.createPath('', dir, true, true); @@ -40,7 +40,7 @@ addToLibrary({ start: file.start, end: file.end, }); - }); + } // Preload files if necessary. This code is largely similar to // createPreloadedFile in library_fs.js. However, a main difference here // is that we only decompress the file if it can be preloaded. @@ -48,21 +48,19 @@ addToLibrary({ // worth. if (preloadPlugin) { Browser.init(); - pack['metadata'].files.forEach((file) => { - var handled = false; + for (var file of pack['metadata'].files) { var fullname = file.filename; - preloadPlugins.forEach((plugin) => { - if (handled) return; + for (var plugin of preloadPlugins) { if (plugin['canHandle'](fullname)) { var dep = getUniqueRunDependency('fp ' + fullname); addRunDependency(dep); var finish = () => removeRunDependency(dep); var byteArray = FS.readFile(fullname); plugin['handle'](byteArray, fullname, finish, finish); - handled = true; + break; } - }); - }); + } + } } }, createNode(parent, name, mode, dev, contents, mtime) { diff --git a/test/code_size/test_codesize_hello_dylink_all.json b/test/code_size/test_codesize_hello_dylink_all.json index 76cdfda0ccd64..480f965e14989 100644 --- a/test/code_size/test_codesize_hello_dylink_all.json +++ b/test/code_size/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 246847, + "a.out.js": 246838, "a.out.nodebug.wasm": 597826, - "total": 844673, + "total": 844664, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/test_other.py b/test/test_other.py index 440c0bbad285c..0a8e7ae1d90f3 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -15596,10 +15596,11 @@ def test_add_js_function_bigint(self, memory64, wasm_function): @parameterized({ '': ([],), + 'lz4': (['-sLZ4'],), 'pthread': (['-g', '-pthread', '-Wno-experimental', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'],), }) def test_preload_module(self, args): - if args: + if '-pthread' in args: self.setup_node_pthreads() # TODO(sbc): This test is copyied from test_browser.py. Perhaps find a better way to # share code between them. @@ -15649,7 +15650,7 @@ def test_preload_module(self, args): } ''') expected = 'done\n' - if args: + if '-pthread' in args: expected = "sharedModules: { '/library.so': Module [WebAssembly.Module] {} }\ndone\n" self.do_runf('main.c', expected, cflags=['-sMAIN_MODULE=2', '--preload-file', 'tmp.so@library.so', '--use-preload-plugins'] + args)