From 62aace5b04b3897f23cd17a6a01b55e47755f16d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 24 Aug 2019 15:29:39 -0700 Subject: [PATCH 1/6] Only look for Module.onExit|Abort if asked to, and don't export Module.abort if not asked to --- src/modules.js | 1 + src/postamble.js | 4 ++++ tests/test_browser.py | 2 +- tests/test_other.py | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules.js b/src/modules.js index 9fdbcdc2dfc9e..85b954cb72e14 100644 --- a/src/modules.js +++ b/src/modules.js @@ -443,6 +443,7 @@ function exportRuntime() { 'getTempRet0', 'setTempRet0', 'callMain', + 'abort', ]; if (!MINIMAL_RUNTIME) { diff --git a/src/postamble.js b/src/postamble.js index e1cea4f895cf3..02f4ce365c0d2 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -415,7 +415,9 @@ function exit(status, implicit) { exitRuntime(); +#if expectToReceiveOnModule('onExit') if (Module['onExit']) Module['onExit'](status); +#endif } quit_(status, new ExitStatus(status)); @@ -424,9 +426,11 @@ function exit(status, implicit) { var abortDecorators = []; function abort(what) { +#if expectToReceiveOnModule('onAbort') if (Module['onAbort']) { Module['onAbort'](what); } +#endif #if USE_PTHREADS if (ENVIRONMENT_IS_PTHREAD) console.error('Pthread aborting at ' + new Error().stack); diff --git a/tests/test_browser.py b/tests/test_browser.py index d1457a81a0790..45e5564e74cff 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -4174,7 +4174,7 @@ def test_small_js_flags(self): size = os.path.getsize('test.js') print('size:', size) # Note that this size includes test harness additions (for reporting the result, etc.). - self.assertLess(abs(size - 6098), 100) + self.assertLess(abs(size - 6044), 100) # Tests that it is possible to initialize and render WebGL content in a pthread by using OffscreenCanvas. # -DTEST_CHAINED_WEBGL_CONTEXT_PASSING: Tests that it is possible to transfer WebGL canvas in a chain from main thread -> thread 1 -> thread 2 and then init and render WebGL content there. diff --git a/tests/test_other.py b/tests/test_other.py index 6f5099d23f191..8224a55679b65 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -9579,7 +9579,7 @@ def test(args): # Changing this option to [] should decrease code size. self.assertLess(changed, normal) # Check an absolute code size as well, with some slack. - self.assertLess(abs(changed - 6279), 100) + self.assertLess(abs(changed - 6224), 100) def test_llvm_includes(self): self.build('#include ', self.get_dir(), 'atomics.c') From 39fbe8754e9feb658dfe2997a2010c499b68310a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 24 Aug 2019 15:30:55 -0700 Subject: [PATCH 2/6] properly --- src/postamble.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/postamble.js b/src/postamble.js index 02f4ce365c0d2..5ec66c6ac641d 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -455,7 +455,6 @@ function abort(what) { throw output; #endif // ASSERTIONS } -Module['abort'] = abort; #if expectToReceiveOnModule('preInit') if (Module['preInit']) { From 11678a837f198b54df77c896ec66f38801431660 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 24 Aug 2019 15:31:32 -0700 Subject: [PATCH 3/6] update tests --- tests/test_browser.py | 2 +- tests/test_other.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_browser.py b/tests/test_browser.py index 45e5564e74cff..1b21554c56141 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -4174,7 +4174,7 @@ def test_small_js_flags(self): size = os.path.getsize('test.js') print('size:', size) # Note that this size includes test harness additions (for reporting the result, etc.). - self.assertLess(abs(size - 6044), 100) + self.assertLess(abs(size - 6034), 100) # Tests that it is possible to initialize and render WebGL content in a pthread by using OffscreenCanvas. # -DTEST_CHAINED_WEBGL_CONTEXT_PASSING: Tests that it is possible to transfer WebGL canvas in a chain from main thread -> thread 1 -> thread 2 and then init and render WebGL content there. diff --git a/tests/test_other.py b/tests/test_other.py index 8224a55679b65..14e24f91664e6 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -9579,7 +9579,7 @@ def test(args): # Changing this option to [] should decrease code size. self.assertLess(changed, normal) # Check an absolute code size as well, with some slack. - self.assertLess(abs(changed - 6224), 100) + self.assertLess(abs(changed - 6214), 100) def test_llvm_includes(self): self.build('#include ', self.get_dir(), 'atomics.c') From cb374dec6107cfee424b6fb3d896863c4ee088d5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 25 Aug 2019 09:45:33 -0700 Subject: [PATCH 4/6] why is this larger? [ci skip] --- ChangeLog.md | 3 +++ src/postamble.js | 33 --------------------------------- src/preamble.js | 35 +++++++++++++++++++++++++++++++++++ tests/test_browser.py | 2 +- tests/test_other.py | 2 +- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2b1ee0c52415c..7abee7b71d8a2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -18,6 +18,9 @@ See docs/process.md for how version tagging works. Current Trunk ------------- + - Module.abort is no longer exported by default. It can be exported in the normal + way using `EXTRA_EXPORTED_RUNTIME_METHODS`, and as with other such changes in + the past, forgetting to export it with show a clear error in `ASSERTIONS` mode. v.1.38.42: 08/19/2019 ---------------------- diff --git a/src/postamble.js b/src/postamble.js index 5ec66c6ac641d..af94146e813af 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -423,39 +423,6 @@ function exit(status, implicit) { quit_(status, new ExitStatus(status)); } -var abortDecorators = []; - -function abort(what) { -#if expectToReceiveOnModule('onAbort') - if (Module['onAbort']) { - Module['onAbort'](what); - } -#endif - -#if USE_PTHREADS - if (ENVIRONMENT_IS_PTHREAD) console.error('Pthread aborting at ' + new Error().stack); -#endif - what += ''; - out(what); - err(what); - - ABORT = true; - EXITSTATUS = 1; - -#if ASSERTIONS == 0 - throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.'; -#else - var extra = ''; - var output = 'abort(' + what + ') at ' + stackTrace() + extra; - if (abortDecorators) { - abortDecorators.forEach(function(decorator) { - output = decorator(output, what); - }); - } - throw output; -#endif // ASSERTIONS -} - #if expectToReceiveOnModule('preInit') if (Module['preInit']) { if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']]; diff --git a/src/preamble.js b/src/preamble.js index 6d3d30259834a..e6cfa1f3fba04 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -590,6 +590,41 @@ function addOnPostRun(cb) { __ATPOSTRUN__.unshift(cb); } +#if EMTERPRETIFY_ASYNC && ASSERTIONS +var abortDecorators = []; +#endif + +function abort(what) { +#if expectToReceiveOnModule('onAbort') + if (Module['onAbort']) { + Module['onAbort'](what); + } +#endif + +#if USE_PTHREADS + if (ENVIRONMENT_IS_PTHREAD) console.error('Pthread aborting at ' + new Error().stack); +#endif + what += ''; + out(what); + err(what); + + ABORT = true; + EXITSTATUS = 1; + +#if ASSERTIONS == 0 + throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.'; +#else + var extra = ''; + var output = 'abort(' + what + ') at ' + stackTrace() + extra; +#if EMTERPRETIFY_ASYNC + abortDecorators.forEach(function(decorator) { + output = decorator(output, what); + }); +#endif + throw output; +#endif // ASSERTIONS +} + {{{ unSign }}} {{{ reSign }}} diff --git a/tests/test_browser.py b/tests/test_browser.py index 1b21554c56141..342c3c41842a2 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -4174,7 +4174,7 @@ def test_small_js_flags(self): size = os.path.getsize('test.js') print('size:', size) # Note that this size includes test harness additions (for reporting the result, etc.). - self.assertLess(abs(size - 6034), 100) + self.assertLess(abs(size - 6039), 100) # Tests that it is possible to initialize and render WebGL content in a pthread by using OffscreenCanvas. # -DTEST_CHAINED_WEBGL_CONTEXT_PASSING: Tests that it is possible to transfer WebGL canvas in a chain from main thread -> thread 1 -> thread 2 and then init and render WebGL content there. diff --git a/tests/test_other.py b/tests/test_other.py index 14e24f91664e6..721f8a2804f9c 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -9579,7 +9579,7 @@ def test(args): # Changing this option to [] should decrease code size. self.assertLess(changed, normal) # Check an absolute code size as well, with some slack. - self.assertLess(abs(changed - 6214), 100) + self.assertLess(abs(changed - 6218), 100) def test_llvm_includes(self): self.build('#include ', self.get_dir(), 'atomics.c') From 169e0b614efc08b5d7929024175473ad72904d9b Mon Sep 17 00:00:00 2001 From: "Alon Zakai (kripken)" Date: Sun, 25 Aug 2019 16:34:17 -0700 Subject: [PATCH 5/6] smaller --- src/preamble.js | 70 +++++++++++++++++++++---------------------- tests/test_browser.py | 2 +- tests/test_other.py | 2 +- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index e6cfa1f3fba04..1aa739e493558 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -590,41 +590,6 @@ function addOnPostRun(cb) { __ATPOSTRUN__.unshift(cb); } -#if EMTERPRETIFY_ASYNC && ASSERTIONS -var abortDecorators = []; -#endif - -function abort(what) { -#if expectToReceiveOnModule('onAbort') - if (Module['onAbort']) { - Module['onAbort'](what); - } -#endif - -#if USE_PTHREADS - if (ENVIRONMENT_IS_PTHREAD) console.error('Pthread aborting at ' + new Error().stack); -#endif - what += ''; - out(what); - err(what); - - ABORT = true; - EXITSTATUS = 1; - -#if ASSERTIONS == 0 - throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.'; -#else - var extra = ''; - var output = 'abort(' + what + ') at ' + stackTrace() + extra; -#if EMTERPRETIFY_ASYNC - abortDecorators.forEach(function(decorator) { - output = decorator(output, what); - }); -#endif - throw output; -#endif // ASSERTIONS -} - {{{ unSign }}} {{{ reSign }}} @@ -736,6 +701,41 @@ Module["preloadedAudios"] = {}; // maps url to audio data Module["preloadedWasm"] = {}; // maps url to wasm instance exports #endif +#if EMTERPRETIFY_ASYNC && ASSERTIONS +var abortDecorators = []; +#endif + +function abort(what) { +#if expectToReceiveOnModule('onAbort') + if (Module['onAbort']) { + Module['onAbort'](what); + } +#endif + +#if USE_PTHREADS + if (ENVIRONMENT_IS_PTHREAD) console.error('Pthread aborting at ' + new Error().stack); +#endif + what += ''; + out(what); + err(what); + + ABORT = true; + EXITSTATUS = 1; + +#if ASSERTIONS == 0 + throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.'; +#else + var extra = ''; + var output = 'abort(' + what + ') at ' + stackTrace() + extra; +#if EMTERPRETIFY_ASYNC + abortDecorators.forEach(function(decorator) { + output = decorator(output, what); + }); +#endif + throw output; +#endif // ASSERTIONS +} + #if RELOCATABLE {{{ (function() { diff --git a/tests/test_browser.py b/tests/test_browser.py index 342c3c41842a2..3e6a55583d3bb 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -4174,7 +4174,7 @@ def test_small_js_flags(self): size = os.path.getsize('test.js') print('size:', size) # Note that this size includes test harness additions (for reporting the result, etc.). - self.assertLess(abs(size - 6039), 100) + self.assertLess(abs(size - 6035), 100) # Tests that it is possible to initialize and render WebGL content in a pthread by using OffscreenCanvas. # -DTEST_CHAINED_WEBGL_CONTEXT_PASSING: Tests that it is possible to transfer WebGL canvas in a chain from main thread -> thread 1 -> thread 2 and then init and render WebGL content there. diff --git a/tests/test_other.py b/tests/test_other.py index 721f8a2804f9c..14e24f91664e6 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -9579,7 +9579,7 @@ def test(args): # Changing this option to [] should decrease code size. self.assertLess(changed, normal) # Check an absolute code size as well, with some slack. - self.assertLess(abs(changed - 6218), 100) + self.assertLess(abs(changed - 6214), 100) def test_llvm_includes(self): self.build('#include ', self.get_dir(), 'atomics.c') From 078e79a2d77de74647c4b76db63e096bca65e375 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 26 Aug 2019 10:04:02 -0700 Subject: [PATCH 6/6] fix --- src/library.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library.js b/src/library.js index fc4caed133ff7..f33e8541fa052 100644 --- a/src/library.js +++ b/src/library.js @@ -875,7 +875,7 @@ LibraryManager.library = { // In MINIMAL_RUNTIME the module object does not exist, so its behavior to abort is to throw directly. throw 'abort'; #else - Module['abort'](); + abort(); #endif },