Skip to content

Commit f3d84f1

Browse files
authored
WasmFS: Fix and add deps (#19630)
Use the same method on readfile as on cwd. That works better for a method inside a big object like FS. And it really makes a lot of sense the more I get used to it: when the wasm code is there, expose the JS method that calls it, and not otherwise; that avoids all possible problems (aside from code not including the wasm code when it needs to - but that would be a bug in the other code). This gets us much closer to being able to run a closure+FULL_LIBRARY test.
1 parent 6387beb commit f3d84f1

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

src/library_wasmfs.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ FS.createPreloadedFile = FS_createPreloadedFile;
9292
}
9393
return current;
9494
},
95+
96+
#if hasExportedSymbol('_wasmfs_read_file') // Support the JS function exactly
97+
// when the __wasmfs_* function is
98+
// present to be called (otherwise,
99+
// we'd error anyhow). This depends
100+
// on other code including the
101+
// __wasmfs_* method properly.
95102
readFile: (path, opts = {}) => {
96103
opts.encoding = opts.encoding || 'binary';
97104
if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
@@ -113,18 +120,9 @@ FS.createPreloadedFile = FS_createPreloadedFile;
113120

114121
return ret;
115122
},
123+
#endif
116124

117-
// FS.cwd is in the awkward position of being used from various JS
118-
// libraries through PATH_FS. FORCE_FILESYSTEM may not have been set while
119-
// using those libraries, which means we cannot put this method in the
120-
// ifdef for that setting just below. Instead, what we can use to tell if we
121-
// need this method is whether the compiled get_cwd() method is present, as
122-
// we include that both when FORCE_FILESYSTEM *and* when PATH_FS is in use
123-
// (see the special PATH_FS deps logic for WasmFS).
124-
//
125-
// While this may seem odd, it also makes sense: we include this JS method
126-
// exactly when the wasm method it wants to call is present.
127-
#if hasExportedSymbol('_wasmfs_get_cwd')
125+
#if hasExportedSymbol('_wasmfs_get_cwd') // Similar to readFile, above.
128126
cwd: () => UTF8ToString(__wasmfs_get_cwd()),
129127
#endif
130128

src/library_wasmfs_fetch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mergeInto(LibraryManager.library, {
1313
'$wasmFS$backends',
1414
'$wasmFS$JSMemoryFiles',
1515
'_wasmfs_create_js_file_backend_js',
16+
'_wasmfs_fetch_get_file_path',
1617
],
1718
_wasmfs_create_fetch_backend_js: async function(backend) {
1819
// Get a promise that fetches the data and stores it in JS memory (if it has

src/library_wasmfs_jsimpl.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mergeInto(LibraryManager.library, {
5252
// implementors of backends: the hooks we call should return Promises, which
5353
// we then connect to the calling C++.
5454

55+
_wasmfs_jsimpl_async_alloc_file__deps: ['emscripten_proxy_finish'],
5556
_wasmfs_jsimpl_async_alloc_file: async function(ctx, backend, file) {
5657
#if ASSERTIONS
5758
assert(wasmFS$backends[backend]);
@@ -60,6 +61,7 @@ mergeInto(LibraryManager.library, {
6061
_emscripten_proxy_finish(ctx);
6162
},
6263

64+
_wasmfs_jsimpl_async_free_file__deps: ['emscripten_proxy_finish'],
6365
_wasmfs_jsimpl_async_free_file: async function(ctx, backend, file) {
6466
#if ASSERTIONS
6567
assert(wasmFS$backends[backend]);
@@ -68,6 +70,7 @@ mergeInto(LibraryManager.library, {
6870
_emscripten_proxy_finish(ctx);
6971
},
7072

73+
_wasmfs_jsimpl_async_write__deps: ['emscripten_proxy_finish'],
7174
_wasmfs_jsimpl_async_write: async function(ctx, backend, file, buffer, length, {{{ defineI64Param('offset') }}}, result_p) {
7275
{{{ receiveI64ParamAsDouble('offset') }}}
7376
#if ASSERTIONS
@@ -78,6 +81,7 @@ mergeInto(LibraryManager.library, {
7881
_emscripten_proxy_finish(ctx);
7982
},
8083

84+
_wasmfs_jsimpl_async_read__deps: ['emscripten_proxy_finish'],
8185
_wasmfs_jsimpl_async_read: async function(ctx, backend, file, buffer, length, {{{ defineI64Param('offset') }}}, result_p) {
8286
{{{ receiveI64ParamAsDouble('offset') }}}
8387
#if ASSERTIONS
@@ -88,6 +92,7 @@ mergeInto(LibraryManager.library, {
8892
_emscripten_proxy_finish(ctx);
8993
},
9094

95+
_wasmfs_jsimpl_async_get_size__deps: ['emscripten_proxy_finish'],
9196
_wasmfs_jsimpl_async_get_size: async function(ctx, backend, file, size_p) {
9297
#if ASSERTIONS
9398
assert(wasmFS$backends[backend]);

src/library_wasmfs_node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ mergeInto(LibraryManager.library, {
5656
_wasmfs_node_readdir__deps: [
5757
'$wasmfsNodeConvertNodeCode',
5858
'$withStackSave',
59-
'$stringToUTF8OnStack'
59+
'$stringToUTF8OnStack',
60+
'_wasmfs_node_record_dirent',
6061
],
6162
_wasmfs_node_readdir: function(path_p, vec) {
6263
let path = UTF8ToString(path_p);

src/library_wasmfs_opfs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ mergeInto(LibraryManager.library, {
148148
wasmfsOPFSProxyFinish(ctx);
149149
},
150150

151-
_wasmfs_opfs_get_entries__deps: ['$wasmfsOPFSProxyFinish', '$withStackSave'],
151+
_wasmfs_opfs_get_entries__deps: [
152+
'$wasmfsOPFSProxyFinish',
153+
'$withStackSave',
154+
'_wasmfs_opfs_record_entry',
155+
],
152156
_wasmfs_opfs_get_entries: async function(ctx, dirID, entriesPtr, errPtr) {
153157
let dirHandle = wasmfsOPFSDirectoryHandles.get(dirID);
154158

0 commit comments

Comments
 (0)