Skip to content

Test + fix for recent main() change #5871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ function run(args) {

#if HAS_MAIN
if (Module['_main'] && shouldRunNow) Module['callMain'](args);
#else
#if ASSERTIONS
assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
#endif // ASSERTIONS
#endif // HAS_MAIN

postRun();
Expand Down
8 changes: 0 additions & 8 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2131,13 +2131,6 @@ def test_runtime_misuse(self):
}, 1000);
'''

open('pre_main.js', 'w').write(r'''
Module._main = function(){
myJSCallback();
return 0;
};
''')

open('pre_runtime.js', 'w').write(r'''
Module.onRuntimeInitialized = function(){
myJSCallback();
Expand All @@ -2146,7 +2139,6 @@ def test_runtime_misuse(self):

for filename, extra_args, second_code in [
('runtime_misuse.cpp', [], 600),
('runtime_misuse_2.cpp', ['--pre-js', 'pre_main.js'], 600),
('runtime_misuse_2.cpp', ['--pre-js', 'pre_runtime.js'], 601) # 601, because no main means we *do* run another call after exit()
]:
for mode in [[], ['-s', 'WASM=1']]:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4684,6 +4684,20 @@ def test_bad_locale(self):
self.assertContained('locale set to waka: waka;waka;waka;waka;waka;waka',
run_js('a.out.js', args=['waka']))

def test_js_main(self):
# try to add a main() from JS, at runtime. this is not supported (the
# compiler needs to know at compile time about main).
open('pre_main.js', 'w').write(r'''
var Module = {
'_main': function() {
}
};
''')
open('src.cpp', 'w').write('')
subprocess.check_call([PYTHON, EMCC, 'src.cpp', '--pre-js', 'pre_main.js'])
self.assertContained('compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]',
run_js('a.out.js', assert_returncode=None, stderr=PIPE))

def test_js_malloc(self):
open('src.cpp', 'w').write(r'''
#include <stdio.h>
Expand Down