Skip to content

Commit

Permalink
Fix ambiguity between print / printErr and out / err
Browse files Browse the repository at this point in the history
`print` / `printErr` are handlers that can be overridden by the user
on the incoming module (just like `onAbort`) and not runtime elements
that can be exported.
  • Loading branch information
kleisauke committed Sep 28, 2022
1 parent 4c5f84d commit f4bf880
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 2 additions & 6 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@ function exportRuntime() {
if (isFSPrefixed(exported)) {
// this is a filesystem value, FS.x exported as FS_x
exported = 'FS.' + exported.substr(3);
} else if (exported === 'print') {
exported = 'out';
} else if (exported === 'printErr') {
exported = 'err';
}
return `Module["${name}"] = ${exported};`;
}
Expand Down Expand Up @@ -361,8 +357,8 @@ function exportRuntime() {
'registerFunctions',
'prettyPrint',
'getCompilerSetting',
'print',
'printErr',
'out',
'err',
'callMain',
'abort',
'keepRuntimeAlive',
Expand Down
2 changes: 1 addition & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4904,7 +4904,7 @@ def test_unicode_html_shell(self):
# Tests the functionality of the emscripten_thread_sleep() function.
@requires_threads
def test_emscripten_thread_sleep(self):
self.btest_exit(test_file('pthread/emscripten_thread_sleep.c'), args=['-sUSE_PTHREADS', '-sEXPORTED_RUNTIME_METHODS=[print]'])
self.btest_exit(test_file('pthread/emscripten_thread_sleep.c'), args=['-sUSE_PTHREADS'])

# Tests that Emscripten-compiled applications can be run from a relative path in browser that is different than the address of the current page
def test_browser_run_from_different_directory(self):
Expand Down
12 changes: 6 additions & 6 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7131,7 +7131,7 @@ def test(contents):
self.run_process([EMXX, 'src.cpp', '-O2']) # optimized, so no assertions
self.assertNotContained(error, read_file('a.out.js'))

def test_warn_module_print_err(self):
def test_warn_module_out_err(self):
error = 'was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)'

def test(contents, expected, args=[], assert_returncode=0): # noqa
Expand All @@ -7146,13 +7146,13 @@ def test(contents, expected, args=[], assert_returncode=0): # noqa
self.assertContained(expected, self.run_js('a.out.js', assert_returncode=assert_returncode))

# error shown (when assertions are on)
test("Module.print('x')", error, assert_returncode=NON_ZERO)
test("Module['print']('x')", error, assert_returncode=NON_ZERO)
test("Module.printErr('x')", error, assert_returncode=NON_ZERO)
test("Module['printErr']('x')", error, assert_returncode=NON_ZERO)
test("Module.out('x')", error, assert_returncode=NON_ZERO)
test("Module['out']('x')", error, assert_returncode=NON_ZERO)
test("Module.err('x')", error, assert_returncode=NON_ZERO)
test("Module['err']('x')", error, assert_returncode=NON_ZERO)

# when exported, all good
test("Module['print']('print'); Module['printErr']('err'); ", 'print\nerr', ['-sEXPORTED_RUNTIME_METHODS=print,printErr'])
test("Module['out']('print'); Module['err']('err'); ", 'print\nerr', ['-sEXPORTED_RUNTIME_METHODS=out,err'])

def test_warn_unexported_main(self):
WARNING = 'main() is in the input files, but "_main" is not in EXPORTED_FUNCTIONS, which means it may be eliminated as dead code. Export it if you want main() to run.'
Expand Down

0 comments on commit f4bf880

Please sign in to comment.