diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-17 13:48:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-17 13:48:39 -0700 |
commit | d54f3a7b86e2b266cc86341b6e06096dc7f04d5e (patch) | |
tree | 62c01ecce139b654f0a84060238aec9d130d0be7 | |
parent | 95404d0d0ebb71d323fad135e9a9bb9981c12808 (diff) |
support argv[0] containing the script node is running; fixes #2431
-rw-r--r-- | src/postamble.js | 2 | ||||
-rw-r--r-- | src/shell.js | 1 | ||||
-rw-r--r-- | tests/test_other.py | 12 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/postamble.js b/src/postamble.js index b90049bc..94b88d4e 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -56,7 +56,7 @@ Module['callMain'] = Module.callMain = function callMain(args) { argv.push(0); } } - var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL) ]; + var argv = [allocate(intArrayFromString(Module['thisProgram'] || '/bin/this.program'), 'i8', ALLOC_NORMAL) ]; pad(); for (var i = 0; i < argc-1; i = i + 1) { argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_NORMAL)); diff --git a/src/shell.js b/src/shell.js index 279a3461..85b13337 100644 --- a/src/shell.js +++ b/src/shell.js @@ -70,6 +70,7 @@ if (ENVIRONMENT_IS_NODE) { globalEval(read(f)); }; + Module['thisProgram'] = process['argv'][1]; Module['arguments'] = process['argv'].slice(2); module['exports'] = Module; diff --git a/tests/test_other.py b/tests/test_other.py index 14c3f00b..5e631b41 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2892,3 +2892,15 @@ int main(int argc, char **argv) { Popen([PYTHON, EMCC, 'src.cpp']).communicate() self.assertContained('read: 0\nfile size is 104\n', run_js('a.out.js')) + def test_argv0_node(self): + open('code.cpp', 'w').write(r''' +#include <stdio.h> +int main(int argc, char **argv) { + printf("I am %s.\n", argv[0]); + return 0; +} +''') + + Popen([PYTHON, EMCC, 'code.cpp']).communicate() + self.assertContained('I am ' + self.get_dir() + '/a.out.js', run_js('a.out.js', engine=NODE_JS)) + |