aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc1
-rw-r--r--src/emrun_prejs.js5
-rw-r--r--tests/hello_world_exit.c8
-rw-r--r--tests/test_browser.py4
4 files changed, 16 insertions, 2 deletions
diff --git a/emcc b/emcc
index 914765d6..96d961dc 100755
--- a/emcc
+++ b/emcc
@@ -990,6 +990,7 @@ try:
newargs = newargs + [default_cxx_std]
if emrun:
+ pre_js += open(shared.path_from_root('src', 'emrun_prejs.js')).read() + '\n'
post_js += open(shared.path_from_root('src', 'emrun_postjs.js')).read() + '\n'
if js_opts is None: js_opts = opt_level >= 2
diff --git a/src/emrun_prejs.js b/src/emrun_prejs.js
new file mode 100644
index 00000000..14613c5d
--- /dev/null
+++ b/src/emrun_prejs.js
@@ -0,0 +1,5 @@
+// Route URL GET parameters to argc+argv
+Module['arguments'] = window.location.search.substr(1).trim().split('&');
+// If no args were passed arguments = [''], in which case kill the single empty string.
+if (!Module['arguments'][0])
+ Module['arguments'] = [];
diff --git a/tests/hello_world_exit.c b/tests/hello_world_exit.c
index febecc65..8932caf2 100644
--- a/tests/hello_world_exit.c
+++ b/tests/hello_world_exit.c
@@ -1,7 +1,13 @@
#include<stdio.h>
#include<stdlib.h>
-int main() {
+int main(int argc, char **argv) {
+ printf("argc: %d\n", argc);
+ for(int i = 0; i < argc; ++i) {
+ printf("argv[%d]: %s\n", i, argv[i]);
+ }
+ if (argc <= 1)
+ exit(1);
printf("hello, world!\n");
fprintf(stderr, "hello, error stream!\n");
exit(100);
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 55bab05b..dbc09b32 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -1697,8 +1697,10 @@ keydown(100);keyup(100); // trigger the end
# and the browser will not close as part of the test, pinning down the cwd on Windows and it wouldn't be possible to delete it. Therefore switch away from that directory
# before launching.
os.chdir(path_from_root())
- process = subprocess.Popen([PYTHON, path_from_root('emrun'), '--timeout', '30', '--verbose', os.path.join(outdir, 'hello_world.html')], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ process = subprocess.Popen([PYTHON, path_from_root('emrun'), '--timeout', '30', '--verbose', os.path.join(outdir, 'hello_world.html'), '1', '2', '3'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = process.communicate()
assert process.returncode == 100
+ assert 'argc: 4' in stdout
+ assert 'argv[3]: 3' in stdout
assert 'hello, world!' in stdout
assert 'hello, error stream!' in stderr