From 470f1e550ea9f3e37e28e692e09d27643108a867 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 28 Jul 2021 16:03:34 +1000 Subject: [PATCH] Simplify stack unwinding logic --- html/worker.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/html/worker.js b/html/worker.js index c1b291e..eff16a3 100644 --- a/html/worker.js +++ b/html/worker.js @@ -84,7 +84,7 @@ function resumeCount() { for (;; stageNum++) { let isDone = wasm['count_one_stage_' + numbers](state, opts); - if (unwindingStack) { + if (wasmRaw.asyncify_get_state() !== 0) { // This stage caused a stack unwind in get_user_input so ignore the result // We will resume execution when a userInput message is received return; @@ -102,7 +102,6 @@ function resumeCount() { postMessage({'type': 'finalResultSummary', 'summary': wasm['final_result_summary_' + numbers](state, opts)}); } -var unwindingStack = false; var userInputBuffer = null; function get_user_input(message) { @@ -111,13 +110,11 @@ function get_user_input(message) { // Record the current state of the stack wasmRaw.asyncify_start_unwind(DATA_ADDR); - unwindingStack = true; // No further WebAssembly will be executed and control will return to resumeCount return null; } else { // We have reached the point the stack was originally unwound, so resume normal execution - unwindingStack = false; wasmRaw.asyncify_stop_rewind(); // Return the correct result to WebAssembly