diff --git a/src/library_noderawfs.js b/src/library_noderawfs.js index a1df4d1246c5a..639e009dfd7ff 100644 --- a/src/library_noderawfs.js +++ b/src/library_noderawfs.js @@ -10,35 +10,27 @@ addToLibrary({ if (!ENVIRONMENT_IS_NODE) { throw new Error("NODERAWFS is currently only supported on Node.js environment.") } - // Use this to reference our in-memory filesystem - var VFS = Object.assign({}, FS); - // Override the init function with our own - FS.init = NODERAWFS.init;`, - $NODERAWFS: { - init() { - var _wrapNodeError = function(func) { - return function(...args) { - try { - return func(...args) - } catch (e) { - if (e.code) { - throw new FS.ErrnoError(ERRNO_CODES[e.code]); - } - throw e; + var _wrapNodeError = function(func) { + return function(...args) { + try { + return func(...args) + } catch (e) { + if (e.code) { + throw new FS.ErrnoError(ERRNO_CODES[e.code]); } + throw e; } - }; - - // Wrap the whole in-memory filesystem API with - // our Node.js based functions - for (var _key in NODERAWFS) { - /** @suppress {partialAlias} */ - FS[_key] = _wrapNodeError(NODERAWFS[_key]); } - - // Setup the stdin, stdout and stderr devices - FS.createStandardStreams(); - }, + }; + // Use this to reference our in-memory filesystem + /** @suppress {partialAlias} */ + var VFS = Object.assign({}, FS); + // Wrap the whole in-memory filesystem API with + // our Node.js based functions + for (var _key in NODERAWFS) { + FS[_key] = _wrapNodeError(NODERAWFS[_key]); + }`, + $NODERAWFS: { lookup(parent, name) { #if ASSERTIONS assert(parent) diff --git a/test/test_other.py b/test/test_other.py index 3214b22455fe0..01552b79789f0 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -9730,6 +9730,11 @@ def test_noderawfs_access_abspath(self): self.run_process([EMCC, 'access.c', '-sNODERAWFS']) self.run_js('a.out.js', args=[os.path.abspath('foo')]) + def test_noderawfs_readfile_prerun(self): + create_file('foo', 'bar') + self.add_pre_run("console.log(FS.readFile('foo', { encoding: 'utf8' }));") + self.do_runf('hello_world.c', 'bar', emcc_args=['-sNODERAWFS', '-sFORCE_FILESYSTEM']) + @disabled('https://github.com/nodejs/node/issues/18265') def test_node_code_caching(self): self.run_process([EMCC, test_file('hello_world.c'),