Skip to content

Commit af2bc13

Browse files
authored
[NODERAWFS] Move filesystem wrapping to __postset (emscripten-core#22559)
Resolves: emscripten-core#22553.
1 parent dd2add0 commit af2bc13

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

src/library_noderawfs.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,27 @@ addToLibrary({
1010
if (!ENVIRONMENT_IS_NODE) {
1111
throw new Error("NODERAWFS is currently only supported on Node.js environment.")
1212
}
13-
// Use this to reference our in-memory filesystem
14-
var VFS = Object.assign({}, FS);
15-
// Override the init function with our own
16-
FS.init = NODERAWFS.init;`,
17-
$NODERAWFS: {
18-
init() {
19-
var _wrapNodeError = function(func) {
20-
return function(...args) {
21-
try {
22-
return func(...args)
23-
} catch (e) {
24-
if (e.code) {
25-
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
26-
}
27-
throw e;
13+
var _wrapNodeError = function(func) {
14+
return function(...args) {
15+
try {
16+
return func(...args)
17+
} catch (e) {
18+
if (e.code) {
19+
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
2820
}
21+
throw e;
2922
}
30-
};
31-
32-
// Wrap the whole in-memory filesystem API with
33-
// our Node.js based functions
34-
for (var _key in NODERAWFS) {
35-
/** @suppress {partialAlias} */
36-
FS[_key] = _wrapNodeError(NODERAWFS[_key]);
3723
}
38-
39-
// Setup the stdin, stdout and stderr devices
40-
FS.createStandardStreams();
41-
},
24+
};
25+
// Use this to reference our in-memory filesystem
26+
/** @suppress {partialAlias} */
27+
var VFS = Object.assign({}, FS);
28+
// Wrap the whole in-memory filesystem API with
29+
// our Node.js based functions
30+
for (var _key in NODERAWFS) {
31+
FS[_key] = _wrapNodeError(NODERAWFS[_key]);
32+
}`,
33+
$NODERAWFS: {
4234
lookup(parent, name) {
4335
#if ASSERTIONS
4436
assert(parent)

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9753,6 +9753,11 @@ def test_noderawfs_access_abspath(self):
97539753
self.run_process([EMCC, 'access.c', '-sNODERAWFS'])
97549754
self.run_js('a.out.js', args=[os.path.abspath('foo')])
97559755

9756+
def test_noderawfs_readfile_prerun(self):
9757+
create_file('foo', 'bar')
9758+
self.add_pre_run("console.log(FS.readFile('foo', { encoding: 'utf8' }));")
9759+
self.do_runf('hello_world.c', 'bar', emcc_args=['-sNODERAWFS', '-sFORCE_FILESYSTEM'])
9760+
97569761
@disabled('https://github.com/nodejs/node/issues/18265')
97579762
def test_node_code_caching(self):
97589763
self.run_process([EMCC, test_file('hello_world.c'),

0 commit comments

Comments
 (0)