Index: test/cctest/wasm/test-wasm-trap-position.cc |
diff --git a/test/cctest/wasm/test-wasm-stack.cc b/test/cctest/wasm/test-wasm-trap-position.cc |
similarity index 64% |
copy from test/cctest/wasm/test-wasm-stack.cc |
copy to test/cctest/wasm/test-wasm-trap-position.cc |
index b36b2c309acd8b9f984615a52ea3858d670ae49e..cd165745db1d3928a81faaab45f3b5d5eb6a188e 100644 |
--- a/test/cctest/wasm/test-wasm-stack.cc |
+++ b/test/cctest/wasm/test-wasm-trap-position.cc |
@@ -31,28 +31,10 @@ namespace { |
} \ |
} while (0) |
-void PrintStackTrace(v8::Local<v8::StackTrace> stack) { |
- printf("Stack Trace (length %d):\n", stack->GetFrameCount()); |
- for (int i = 0, e = stack->GetFrameCount(); i != e; ++i) { |
- v8::Local<v8::StackFrame> frame = stack->GetFrame(i); |
- v8::Local<v8::String> func = frame->GetFunctionName(); |
- if (frame->IsWasm()) { |
- printf("[%d] (<WASM>) %s:%d\n", i, |
- func.IsEmpty() ? "<null>" : *v8::String::Utf8Value(func), |
- frame->GetWasmByteOffset()); |
- } else { |
- v8::Local<v8::String> script = frame->GetScriptName(); |
- printf("[%d] (%s) %s:%d:%d\n", i, |
- script.IsEmpty() ? "<null>" : *v8::String::Utf8Value(script), |
- func.IsEmpty() ? "<null>" : *v8::String::Utf8Value(func), |
- frame->GetLineNumber(), frame->GetColumn()); |
- } |
- } |
-} |
- |
struct ExceptionInfo { |
- const char* funcName; |
- int lineNr; |
+ const char* func_name_; |
+ bool is_wasm_; |
+ int position_; |
}; |
template <int N> |
@@ -64,40 +46,37 @@ void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc, |
// Extract stack frame from the exception. |
Local<v8::Value> localExc = Utils::ToLocal(exc); |
v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(localExc); |
- PrintStackTrace(stack); |
CHECK(!stack.IsEmpty()); |
CHECK_EQ(N, stack->GetFrameCount()); |
for (int frameNr = 0; frameNr < N; ++frameNr) { |
v8::Local<v8::StackFrame> frame = stack->GetFrame(frameNr); |
v8::String::Utf8Value funName(frame->GetFunctionName()); |
- CHECK_CSTREQ(excInfos[frameNr].funcName, *funName); |
- CHECK_EQ(excInfos[frameNr].lineNr, frame->GetLineNumber()); |
+ CHECK_CSTREQ(excInfos[frameNr].func_name_, *funName); |
+ CHECK_EQ(excInfos[frameNr].is_wasm_, frame->IsWasm()); |
+ if (excInfos[frameNr].is_wasm_) { |
+ CHECK_EQ(excInfos[frameNr].position_, frame->GetWasmByteOffset()); |
+ } else { |
+ CHECK_EQ(excInfos[frameNr].position_, frame->GetLineNumber()); |
+ } |
} |
} |
} // namespace |
-// Call from JS to WASM to JS and throw an Error from JS. |
-TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { |
+// Trigger a trap for executing unreachable. |
+TEST(Unreachable) { |
TestSignatures sigs; |
TestingModule module; |
- // Initialize WasmFunctionCompiler first, since it sets up the HandleScope. |
- WasmFunctionCompiler comp1(sigs.v_v(), &module); |
- |
- uint32_t js_throwing_index = module.AddJsFunction( |
- sigs.v_v(), |
- "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); |
- |
- BUILD(comp1, WASM_CALL_FUNCTION0(js_throwing_index)); |
+ WasmFunctionCompiler comp1(sigs.v_v(), &module, |
+ ArrayVector("exec_unreachable")); |
+ // Set the execution context, such that a runtime error can be thrown. |
+ comp1.SetModuleContext(); |
+ BUILD(comp1, WASM_UNREACHABLE); |
uint32_t wasm_index = comp1.CompileAndAdd(); |
- WasmFunctionCompiler comp2(sigs.v_v(), &module); |
- BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index)); |
- uint32_t wasm_index_2 = comp2.CompileAndAdd(); |
- |
- Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); |
+ Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index); |
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
@@ -113,32 +92,28 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { |
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
CHECK(returnObjMaybe.is_null()); |
- // Line number is 1-based, with 0 == kNoLineNumberInfo. |
ExceptionInfo expected_exceptions[] = { |
- {"a", 3}, // Prevent clang-format changes. |
- {"js", 4}, // - |
- {"<WASM UNNAMED>", 0}, // - |
- {"<WASM UNNAMED>", 0}, // - |
- {"callFn", 1}}; |
+ {"exec_unreachable", true, 1}, // Prevent clang-format changes. |
titzer
2016/04/28 12:07:59
We usually just do // --
and then // --
for the ne
Clemens Hammacher
2016/04/28 12:32:12
OK, changed it anyway.
|
+ {"callFn", false, 1}}; |
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(), |
expected_exceptions); |
} |
-// Trigger a trap in WASM, stack should be JS -> WASM -> WASM. |
-TEST(CollectDetailedWasmStack_WasmError) { |
+// Trigger a trap for loading from out-of-bounds. |
+TEST(IllegalLoad) { |
TestSignatures sigs; |
TestingModule module; |
- WasmFunctionCompiler comp1(sigs.i_v(), &module, |
- ArrayVector("exec_unreachable")); |
+ WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob")); |
// Set the execution context, such that a runtime error can be thrown. |
comp1.SetModuleContext(); |
- BUILD(comp1, WASM_UNREACHABLE); |
+ BUILD(comp1, WASM_IF(WASM_ONE, |
+ WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(-3)))); |
uint32_t wasm_index = comp1.CompileAndAdd(); |
- WasmFunctionCompiler comp2(sigs.i_v(), &module, |
- ArrayVector("call_exec_unreachable")); |
- BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index)); |
+ WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob")); |
+ // Insert a NOP such that the position of the call is not one. |
+ BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index)); |
uint32_t wasm_index_2 = comp2.CompileAndAdd(); |
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); |
@@ -153,15 +128,15 @@ TEST(CollectDetailedWasmStack_WasmError) { |
Handle<Object> global(isolate->context()->global_object(), isolate); |
MaybeHandle<Object> maybe_exc; |
Handle<Object> args[] = {js_wasm_wrapper}; |
- MaybeHandle<Object> maybe_return_obj = |
+ MaybeHandle<Object> returnObjMaybe = |
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
- CHECK(maybe_return_obj.is_null()); |
+ CHECK(returnObjMaybe.is_null()); |
// Line number is 1-based, with 0 == kNoLineNumberInfo. |
ExceptionInfo expected_exceptions[] = { |
- {"exec_unreachable", 0}, // Prevent clang-format changes. |
- {"call_exec_unreachable", 0}, // - |
- {"callFn", 1}}; |
+ {"mem_oob", true, 4}, // Prevent clang-format changes. |
+ {"call_mem_oob", true, 2}, // - |
+ {"callFn", false, 1}}; |
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(), |
expected_exceptions); |
} |