| Index: test/cctest/wasm/wasm-run-utils.h
|
| diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h
|
| index 7eef59c515ed1965adf63edc0d002bbe781be612..31f98f4ce63bd7b7bce221257c5e73d385f32564 100644
|
| --- a/test/cctest/wasm/wasm-run-utils.h
|
| +++ b/test/cctest/wasm/wasm-run-utils.h
|
| @@ -741,9 +741,9 @@ class WasmRunnerBase : public HandleAndZoneScope {
|
| bool interpret() { return module_.execution_mode() == kExecuteInterpreted; }
|
|
|
| public:
|
| - // This field has to be static. Otherwise, gcc complains about the using in
|
| + // This field has to be static. Otherwise, gcc complains about the use in
|
| // the lambda context below.
|
| - static jmp_buf jump_buffer;
|
| + static bool trap_happened;
|
| };
|
|
|
| template <typename ReturnType, typename... ParamTypes>
|
| @@ -762,15 +762,24 @@ class WasmRunner : public WasmRunnerBase {
|
| DCHECK(compiled_);
|
| if (interpret()) return CallInterpreter(p...);
|
|
|
| - // Use setjmp/longjmp to deal with traps in WebAssembly code.
|
| ReturnType return_value = static_cast<ReturnType>(0xdeadbeefdeadbeef);
|
| - static int setjmp_ret;
|
| - setjmp_ret = setjmp(WasmRunnerBase::jump_buffer);
|
| - // setjmp returns 0 on the first return, 1 (passed to longjmp) after trap.
|
| - if (setjmp_ret == 0) {
|
| - DoCall(static_cast<void*>(&p)..., static_cast<void*>(&return_value));
|
| - }
|
| - return return_value;
|
| + WasmRunnerBase::trap_happened = false;
|
| + auto trap_callback = []() -> void {
|
| + WasmRunnerBase::trap_happened = true;
|
| + set_trap_callback_for_testing(nullptr);
|
| + };
|
| + set_trap_callback_for_testing(trap_callback);
|
| +
|
| + wrapper_.SetInnerCode(
|
| + module_.GetFunctionCode(functions_[0]->function_index()));
|
| + CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
|
| + wrapper_.GetWrapperCode(), wrapper_.signature());
|
| + int32_t result = runner.Call(static_cast<void*>(&p)...,
|
| + static_cast<void*>(&return_value));
|
| + CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
|
| + return WasmRunnerBase::trap_happened
|
| + ? static_cast<ReturnType>(0xdeadbeefdeadbeef)
|
| + : return_value;
|
| }
|
|
|
| ReturnType CallInterpreter(ParamTypes... p) {
|
| @@ -791,30 +800,10 @@ class WasmRunner : public WasmRunnerBase {
|
| return ReturnType{0};
|
| }
|
| }
|
| -
|
| - private:
|
| - // Don't inline this function. The setjmp above should be followed immediately
|
| - // by a call.
|
| - template <typename... Ptrs>
|
| - V8_NOINLINE void DoCall(Ptrs... ptrs) {
|
| - auto trap_callback = []() -> void {
|
| - set_trap_callback_for_testing(nullptr);
|
| - longjmp(WasmRunnerBase::jump_buffer, 1);
|
| - };
|
| - set_trap_callback_for_testing(trap_callback);
|
| -
|
| - wrapper_.SetInnerCode(
|
| - module_.GetFunctionCode(functions_[0]->function_index()));
|
| - CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
|
| - wrapper_.GetWrapperCode(), wrapper_.signature());
|
| - int32_t result = runner.Call(ptrs...);
|
| - // If we arrive here, no trap happened.
|
| - CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
|
| - }
|
| };
|
|
|
| // Declare static variable.
|
| -jmp_buf WasmRunnerBase::jump_buffer;
|
| +bool WasmRunnerBase::trap_happened;
|
|
|
| // A macro to define tests that run in different engine configurations.
|
| #define WASM_EXEC_TEST(name) \
|
|
|