Skip to content

Commit 5b5497f

Browse files
authored
Use library aliases for FS_<symbol> functions. (#24116)
Removes the custom code for exporting the FS_<symbol> with EXPORTED_RUNTIME_FUNCTIONS. Using library symbols makes these exports behave like all the other library exports.
1 parent 4647567 commit 5b5497f

9 files changed

+29
-31
lines changed

src/lib/libfs.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
addToLibrary({
7+
var LibraryFS = {
88
$FS__deps: ['$randomFill', '$PATH', '$PATH_FS', '$TTY', '$MEMFS',
99
'$FS_createPreloadedFile',
1010
'$FS_modeStringToFlags',
@@ -38,9 +38,7 @@ addToLibrary({
3838
addAtExit('FS.quit();');
3939
return `
4040
FS.createPreloadedFile = FS_createPreloadedFile;
41-
FS.staticInit();
42-
// Set module methods based on EXPORTED_RUNTIME_METHODS
43-
{{{ EXPORTED_RUNTIME_METHODS.filter((func) => func.startsWith('FS_')).map((func) => "Module['" + func + "'] = FS." + func.slice(3) + ";\n").reduce((str, func) => str + func, '') }}}`;
41+
FS.staticInit();`;
4442
},
4543
$FS: {
4644
root: null,
@@ -1917,22 +1915,23 @@ FS.staticInit();
19171915
#endif
19181916
},
19191917

1920-
$FS_createDataFile__deps: ['$FS'],
1921-
$FS_createDataFile: (parent, name, fileData, canRead, canWrite, canOwn) => {
1922-
FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn);
1923-
},
1924-
1925-
$FS_unlink__deps: ['$FS'],
1926-
$FS_unlink: (path) => FS.unlink(path),
1927-
19281918
$FS_mkdirTree__docs: `
19291919
/**
19301920
* @param {number=} mode Optionally, the mode to create in. Uses mkdir's
19311921
* default if not set.
19321922
*/`,
1933-
$FS_mkdirTree__deps: ['$FS'],
1934-
$FS_mkdirTree: (path, mode) => FS.mkdirTree(path, mode),
1935-
1936-
$FS_createLazyFile__deps: ['$FS'],
1937-
$FS_createLazyFile: 'FS.createLazyFile',
1938-
});
1923+
$FS_mkdirTree__deps: ['$FS'],
1924+
$FS_mkdirTree: (path, mode) => FS.mkdirTree(path, mode),
1925+
};
1926+
1927+
// Add library aliases for all the FS.<symbol> as FS_<symbol>.
1928+
for (let key in LibraryFS.$FS) {
1929+
const alias = `$FS_${key}`;
1930+
// Skip defining the alias if it already exists or if it's not an API function.
1931+
if (LibraryFS[alias] || key[0] !== key[0].toLowerCase()) {
1932+
continue;
1933+
}
1934+
LibraryFS[alias] = `(...args) => FS.${key}(...args)`;
1935+
LibraryFS[`${alias}__deps`] = ['$FS'];
1936+
}
1937+
addToLibrary(LibraryFS);
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7785
1+
8292
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20761
1+
22165
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6099
1+
6595
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16143
1+
17534

test/other/embind_tsgen_ignore_1.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.
22
declare namespace RuntimeExports {
3-
let FS_createPath: any;
4-
function FS_createDataFile(parent: any, name: any, fileData: any, canRead: any, canWrite: any, canOwn: any): void;
3+
function FS_createPath(...args: any[]): any;
4+
function FS_createDataFile(...args: any[]): any;
55
function FS_createPreloadedFile(parent: any, name: any, url: any, canRead: any, canWrite: any, onload: any, onerror: any, dontCreateFile: any, canOwn: any, preFinish: any): void;
6-
function FS_unlink(path: any): any;
7-
let FS_createLazyFile: any;
8-
let FS_createDevice: any;
6+
function FS_unlink(...args: any[]): any;
7+
function FS_createLazyFile(...args: any[]): any;
8+
function FS_createDevice(...args: any[]): any;
99
let addRunDependency: any;
1010
let removeRunDependency: any;
1111
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
51593
1+
53547
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
49661
1+
51597

test/test_other.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4145,8 +4145,7 @@ def test_exported_runtime_methods(self):
41454145

41464146
# Check that the Module.FS_writeFile is not exported
41474147
out = self.run_js('index.js', assert_returncode=NON_ZERO)
4148-
self.assertContained('undefined', out),
4149-
self.assertContained("Aborted('wasmExports' was not exported. add it to EXPORTED_RUNTIME_METHODS", out)
4148+
self.assertContained("Aborted('FS_writeFile' was not exported. add it to EXPORTED_RUNTIME_METHODS", out)
41504149

41514150
def test_exported_runtime_methods_from_js_library(self):
41524151
create_file('pre.js', '''

0 commit comments

Comments
 (0)