Skip to content

Commit

Permalink
[NODERAWFS] Move filesystem wrapping to __postset
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Sep 11, 2024
1 parent 52e8c4b commit c8c3d60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/library_noderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,26 @@ addToLibrary({
}
// 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();
},
// 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]);
}`,
$NODERAWFS: {
lookup(parent, name) {
#if ASSERTIONS
assert(parent)
Expand Down
10 changes: 10 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9730,6 +9730,16 @@ 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')
create_file('main.c', r'''
int main() { return 0; }
''')
create_file('pre.js', f'''
Module.preRun = () => console.log(FS.readFile('{os.path.abspath('foo')}', {{ encoding: 'utf8' }}));
''')
self.do_runf('main.c', 'bar\n', emcc_args=['--pre-js', 'pre.js', '-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 c8c3d60

Please sign in to comment.