Skip to content

Commit

Permalink
[NODERAWFS] Move filesystem wrapping to __postset (#22559)
Browse files Browse the repository at this point in the history
Resolves: #22553.
  • Loading branch information
kleisauke authored Sep 18, 2024
1 parent dd2add0 commit af2bc13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/library_noderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9753,6 +9753,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'),
Expand Down

0 comments on commit af2bc13

Please sign in to comment.