Created
May 14, 2018 22:10
-
-
Save fictitious/a2548e8699a7b51f58d3d1972eb38e42 to your computer and use it in GitHub Desktop.
testcase for emscripten with async callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <emscripten.h> | |
extern "C" { | |
void call_async_operation() { | |
EM_ASM({AsyncOperation.start()}); | |
while (!EM_ASM_INT({return AsyncOperation.done})) { | |
emscripten_sleep(200); | |
} | |
} | |
// remove throw() => no crash | |
static void nothrow_func() throw() | |
{ | |
call_async_operation(); | |
// remove the following line => no crash | |
std::cout << "async operation OK" << std::endl; | |
} | |
void async_callback_test() { | |
nothrow_func(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p out | |
em++ -Wall -O0 -std=c++0x -fPIC -fPIC -c -o out/async_callback_test.o async_callback_test.cpp | |
emar rcvs out/libasync_callback_test.a out/async_callback_test.o | |
emcc out/libasync_callback_test.a -o out/libasync_callback_test.js \ | |
-O0 \ | |
-s EXPORTED_FUNCTIONS="['_async_callback_test']" \ | |
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall"]' \ | |
-s DISABLE_EXCEPTION_CATCHING=0 \ | |
-s ALLOW_MEMORY_GROWTH=1 \ | |
-s EMTERPRETIFY=1 \ | |
-s EMTERPRETIFY_ASYNC=1 \ | |
-s ASSERTIONS=2 \ | |
-s SAFE_HEAP=1 \ | |
-s DEMANGLE_SUPPORT=1 \ | |
--profiling-funcs \ | |
--minify 0 \ | |
--memory-init-file 0 | |
cat out/libasync_callback_test.js use.js > out/run.js | |
node out/run.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsyncOperation = { | |
done: false, | |
start() { | |
// this.done = true; // uncomment this line => no crash | |
Promise.resolve().then(() => this.done = true); | |
} | |
}; | |
Module.ccall('async_callback_test', null, [], [], { async: true }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment