diff options
Diffstat (limited to 'tests/emscripten_api_browser.cpp')
-rw-r--r-- | tests/emscripten_api_browser.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/emscripten_api_browser.cpp b/tests/emscripten_api_browser.cpp index 37ffbdd6..20e2dbb5 100644 --- a/tests/emscripten_api_browser.cpp +++ b/tests/emscripten_api_browser.cpp @@ -1,5 +1,6 @@ #include<stdio.h> #include<math.h> +#include<stdlib.h> #include<SDL.h> #include<emscripten.h> #include<assert.h> @@ -8,12 +9,34 @@ int last = 0; extern "C" { -void third() { +bool fived = false; +void five() { + fived = true; + emscripten_resume_main_loop(); +} + +void mainey() { + static int counter = 0; + printf("mainey: %d\n", counter++); + if (counter == 20) { + emscripten_pause_main_loop(); + emscripten_async_call(five, 1000); + } else if (counter == 22) { // very soon after 20, so without pausing we fail + int result = fived; + REPORT_RESULT(); + } +} + +void four() { + printf("four!\n"); + emscripten_set_main_loop(mainey, 0); +} + +void __attribute__((used)) third() { int now = SDL_GetTicks(); printf("thard! %d\n", now); assert(fabs(now - last - 1000) < 500); - int result = 1; - REPORT_RESULT(); + emscripten_async_call(four, -1); // triggers requestAnimationFrame } void second() { @@ -21,16 +44,23 @@ void second() { printf("sacond! %d\n", now); assert(fabs(now - last - 500) < 250); last = now; - emscripten_async_call(third, 1000); + emscripten_async_run_script("_third()", 1000); } } +void never() { + int result = 0; + REPORT_RESULT(); +} + int main() { SDL_Init(0); last = SDL_GetTicks(); printf("frist! %d\n", last); + atexit(never); // should never be called - it is wrong to exit the runtime orderly if we have async calls! + emscripten_async_call(second, 500); return 1; |