Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/libwasmfs_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

var wasmFSNodeLibrary = {
$wasmfsNodeIsWindows: "!!process.platform.match(/^win/)",
$wasmfsNodeIsWindows: "!!globalThis.process?.platform.match(/^win/)",

$wasmfsNodeConvertNodeCode__deps: ['$ERRNO_CODES'],
$wasmfsNodeConvertNodeCode: (e) => {
Expand Down
29 changes: 29 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5347,6 +5347,35 @@ def test_wasmfs_opfs_errors(self):
args = ['-sWASMFS', '-pthread', '-sPROXY_TO_PTHREAD', '--post-js', postjs]
self.btest(test, cflags=args, expected='0')

def test_wasmfs_multi_environment(self):
# Test that WasmFS's Node backend can be enabled conditionally, allowing
# the same binaries to run on both web and Node.js environments.
create_file('main.c', r'''
#include <stdio.h>
#include <assert.h>
#include <unistd.h>

#include <emscripten/emscripten.h>
#include <emscripten/wasmfs.h>

EM_JS(bool, is_node, (), { return ENVIRONMENT_IS_NODE; });

// This is equivalent to building with `-sWASMFS -sNODERAWFS`, except
// that the Wasm binary can also be used on the web.
backend_t wasmfs_create_root_dir() {
return is_node() ? wasmfs_create_node_backend("")
: wasmfs_create_memory_backend();
}

int main(int argc, char** argv) {
printf("testing access to /tmp\n");
int rtn = access("/tmp", F_OK);
assert(rtn == 0);
return 0;
}
''')
self.btest_exit('main.c', cflags=['-sWASMFS', '-sENVIRONMENT=web,node'])

@no_firefox('no 4GB support yet')
def test_emmalloc_memgrowth(self):
if not self.is_4gb():
Expand Down
Loading