diff --git a/ChangeLog.md b/ChangeLog.md index 3c9a8490379eb..b27be81e226fb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,7 @@ Current Trunk - Only MEMFS is included by default, others (NODEFS, IDBFS, WORKERFS, PROXYFS) must be linked in explicitly, using `-lnodefs.js`, `-lidbfs.js`', `-lworkerfs.js`, `-lproxyfs.js`. See #9645 + - New function emscripten_has_asyncify() v1.39.0: 10/18/2019 ------------------- diff --git a/site/source/docs/api_reference/emscripten.h.rst b/site/source/docs/api_reference/emscripten.h.rst index 55c9a1cd792ed..b3e3efe984e60 100644 --- a/site/source/docs/api_reference/emscripten.h.rst +++ b/site/source/docs/api_reference/emscripten.h.rst @@ -992,6 +992,13 @@ Functions :returns: The value of the specified setting. Note that for values other than an integer, a string is returned (cast the ``int`` return value to a ``char*``). :rtype: int +.. c:function:: int emscripten_has_asyncify() + + Returns whether pseudo-synchronous functions can be used. + + :rtype: int + :returns: 1 if program was compiled with ASYNCIFY=1 or EMTERPRETER_ASYNC=1, 0 otherwise. + .. c:function:: void emscripten_debugger() diff --git a/src/library.js b/src/library.js index e278e9455c35f..236b604b4e8df 100644 --- a/src/library.js +++ b/src/library.js @@ -4258,6 +4258,10 @@ LibraryManager.library = { return cache[fullname] = allocate(intArrayFromString(ret + ''), 'i8', ALLOC_NORMAL); }, + emscripten_has_asyncify: function() { + return {{{ ASYNCIFY || EMTERPRETIFY_ASYNC }}}; + }, + emscripten_debugger: function() { debugger; }, diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index 389810f81de6a..99a012df644ad 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -228,6 +228,7 @@ int emscripten_get_worker_queue_size(worker_handle worker); // misc. int emscripten_get_compiler_setting(const char *name); +int emscripten_has_asyncify(); void emscripten_debugger(void); diff --git a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE.sent b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE.sent index 45dd728cea071..4807ca43c3916 100644 --- a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE.sent +++ b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE.sent @@ -887,6 +887,7 @@ _emscripten_gluOrtho2D _emscripten_gluPerspective _emscripten_gluProject _emscripten_gluUnProject +_emscripten_has_asyncify _emscripten_hide_mouse _emscripten_html5_remove_all_event_listeners _emscripten_idb_async_delete diff --git a/tests/test_core.py b/tests/test_core.py index f79efeebada3e..e9b2ca1821c85 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1758,6 +1758,22 @@ def test_emscripten_get_compiler_setting(self): self.set_setting('RETAIN_COMPILER_SETTINGS', 1) self.do_run(open(src).read(), open(output).read().replace('waka', shared.EMSCRIPTEN_VERSION)) + @no_fastcomp('ASYNCIFY has been removed from fastcomp') + def test_emscripten_has_asyncify(self): + src = r''' + #include + #include + + int main() { + printf("%d\n", emscripten_has_asyncify()); + return 0; + } + ''' + self.set_setting('ASYNCIFY', 0) + self.do_run(src, '0') + self.set_setting('ASYNCIFY', 1) + self.do_run(src, '1') + # TODO: test only worked in non-fastcomp def test_inlinejs(self): self.skipTest('non-fastcomp is deprecated and fails in 3.5') # only supports EM_ASM diff --git a/tests/test_other.py b/tests/test_other.py index e625880b09fc7..91a9593e58329 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8113,7 +8113,7 @@ def test_metadce_hello(self, *args): 4, [], [], 8, 0, 0, 0), # noqa; totally empty! # we don't metadce with linkable code! other modules may want stuff # don't compare the # of functions in a main module, which changes a lot - 'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 1600, [], [], 226403, None, 107, None), # noqa + 'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 1601, [], [], 226403, None, 107, None), # noqa 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 20), # noqa }) @no_wasm_backend()