Commit a0c8d58d authored by Boxiang Sun's avatar Boxiang Sun

erp5_notebook: Don't make function inside a loop...

parent 432fa12f
...@@ -124,34 +124,41 @@ ...@@ -124,34 +124,41 @@
// can't be done synchronously within the call to dlopen, we instantiate // can't be done synchronously within the call to dlopen, we instantiate
// every .so that comes our way up front, caching it in the // every .so that comes our way up front, caching it in the
// `preloadedWasm` dictionary. // `preloadedWasm` dictionary.
var queue, FS; var queue, FS, path;
queue = new RSVP.Queue(); queue = new RSVP.Queue();
FS = pyodide._module.FS; FS = pyodide._module.FS;
function recurseDir(rootpath) { function recurseDir(rootpath) {
var i, entry, dirs, path; var i, entry, dirs;
try { try {
dirs = FS.readdir(rootpath); dirs = FS.readdir(rootpath);
} catch (e) { } catch (e) {
return; return;
} }
function readModuleFile(path) {
return function () {
return Module.loadWebAssemblyModule(
FS.readFile(path),
{loadAsync: true}
);
};
}
function setModule(path) {
return function (module) {
Module.preloadedWasm[path] = module;
};
}
for (i = 0; i < dirs.length; i += 1) { for (i = 0; i < dirs.length; i += 1) {
entry = dirs[i]; entry = dirs[i];
if (!entry.startsWith('.')) { if (!entry.startsWith('.')) {
const path = rootpath + entry; path = rootpath + entry;
if (entry.endsWith('.so')) { if (entry.endsWith('.so')) {
if (Module.preloadedWasm[path] === undefined) { if (Module.preloadedWasm[path] === undefined) {
queue.push(function () { queue.push(readModuleFile(path))
return Module.loadWebAssemblyModule( .push(setModule(path));
FS.readFile(path), {
loadAsync: true
}
)
})
.push(function (module) {
Module.preloadedWasm[path] = module;
});
} }
} else if (FS.isDir(FS.lookupPath(path).node.mode)) { } else if (FS.isDir(FS.lookupPath(path).node.mode)) {
recurseDir(path + '/'); recurseDir(path + '/');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment