Skip to content

Commit 4321418

Browse files
jrpricemmarczell-graphisoft
authored andcommitted
Fix initialization of nodePath variable (emscripten-core#15805)
When running Emscripten-generated scripts via `node -e "<script>"`, the `fs` variable is already defined and so `nodePath` was never being initialized.
1 parent 4d59071 commit 4321418

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/node_shell_read.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
*/
66

77
requireNodeFS = function() {
8-
// We always initialize both of these together, so we can use
9-
// either one as the indicator for them not being initialized.
10-
if (!fs) {
8+
// Use nodePath as the indicator for these not being initialized,
9+
// since in some environments a global fs may have already been
10+
// created.
11+
if (!nodePath) {
1112
fs = require('fs');
1213
nodePath = require('path');
1314
}

tests/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8408,6 +8408,12 @@ def test_node_js_system(self):
84088408
ret = self.run_process(config.NODE_JS + ['a.js'], stdout=PIPE).stdout
84098409
self.assertContained('OK', ret)
84108410

8411+
def test_node_eval(self):
8412+
self.run_process([EMCC, '-sENVIRONMENT=node', test_file('hello_world.c'), '-o', 'a.js', '-O3'])
8413+
js = open('a.js').read()
8414+
ret = self.run_process(config.NODE_JS + ['-e', js], stdout=PIPE).stdout
8415+
self.assertContained('hello, world!', ret)
8416+
84118417
def test_is_bitcode(self):
84128418
fname = 'tmp.o'
84138419

0 commit comments

Comments
 (0)