Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Unified Diff: test/cctest/wasm/test-wasm-stack.cc

Issue 1884593002: [wasm] Add a cctest for the stack on a wasm trap (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-throw-error
Patch Set: one more c++ style fix Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-wasm-stack.cc
diff --git a/test/cctest/wasm/test-wasm-stack.cc b/test/cctest/wasm/test-wasm-stack.cc
index e34c69703fd24f186237a7c4b4ffe0721a9326f1..3915e43c813d4b774fcb7d02971ac3a52f9be351 100644
--- a/test/cctest/wasm/test-wasm-stack.cc
+++ b/test/cctest/wasm/test-wasm-stack.cc
@@ -51,10 +51,10 @@ struct ExceptionInfo {
template <int N>
void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
const ExceptionInfo (&excInfos)[N]) {
- // check that it's indeed an Error object
+ // Check that it's indeed an Error object.
CHECK(Object::IsErrorObject(isolate, exc));
- // extract stack frame from exception
+ // Extract stack frame from the exception.
Local<v8::Value> localExc = Utils::ToLocal(exc);
v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(localExc);
PrintStackTrace(stack);
@@ -76,41 +76,83 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
TestSignatures sigs;
TestingModule module;
+ // Initialize WasmFunctionCompiler first, since it sets up the HandleScope.
WasmFunctionCompiler comp1(sigs.v_v(), &module);
- uint32_t jsThrowingIndex = module.AddJsFunction(
+ 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(jsThrowingIndex));
- uint32_t wasmIndex = comp1.CompileAndAdd();
+ BUILD(comp1, WASM_CALL_FUNCTION0(js_throwing_index));
+ uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler comp2(sigs.v_v(), &module);
- BUILD(comp2, WASM_CALL_FUNCTION0(wasmIndex));
- uint32_t wasmIndex2 = comp2.CompileAndAdd();
+ BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
+ uint32_t wasm_index_2 = comp2.CompileAndAdd();
- Handle<JSFunction> jsWasmWrapper = module.WrapCode(wasmIndex2);
+ Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
- Handle<JSFunction> jsTrampoline = Handle<JSFunction>::cast(
+ Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
CompileRun("(function callFn(fn) { fn(); })"))));
- Isolate* isolate = jsWasmWrapper->GetIsolate();
+ Isolate* isolate = js_wasm_wrapper->GetIsolate();
isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
v8::StackTrace::kOverview);
Handle<Object> global(isolate->context()->global_object(), isolate);
- MaybeHandle<Object> excMaybe;
- Handle<Object> args[] = {jsWasmWrapper};
+ MaybeHandle<Object> maybe_exc;
+ Handle<Object> args[] = {js_wasm_wrapper};
MaybeHandle<Object> returnObjMaybe =
- Execution::TryCall(isolate, jsTrampoline, global, 1, args, &excMaybe);
+ Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
- // line number is 1-based, with 0 == kNoLineNumberInfo
- ExceptionInfo expectedExceptions[] = {
- {"a", 3}, // comment to prevent clang-format complaints
+ // Line number is 1-based, with 0 == kNoLineNumberInfo.
+ ExceptionInfo expected_exceptions[] = {
+ {"a", 3}, // Comment to prevent clang-format complaints
{"js", 4}, // -
{"<WASM>", 0}, // -
{"<WASM>", 0}, // -
{"callFn", 1}};
- CheckExceptionInfos(isolate, excMaybe.ToHandleChecked(), expectedExceptions);
+ CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
+ expected_exceptions);
+}
+
+// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
+TEST(CollectDetailedWasmStack_WasmError) {
+ TestSignatures sigs;
+ TestingModule module;
+
+ WasmFunctionCompiler comp1(sigs.i_v(), &module, "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.i_v(), &module, "call_exec_unreachable");
+ 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_trampoline = Handle<JSFunction>::cast(
+ v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
+ CompileRun("(function callFn(fn) { fn(); })"))));
+
+ Isolate* isolate = js_wasm_wrapper->GetIsolate();
+ isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
+ v8::StackTrace::kOverview);
+ Handle<Object> global(isolate->context()->global_object(), isolate);
+ MaybeHandle<Object> maybe_exc;
+ Handle<Object> args[] = {js_wasm_wrapper};
+ MaybeHandle<Object> maybe_return_obj =
+ Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
+ CHECK(maybe_return_obj.is_null());
+
+ // Line number is 1-based, with 0 == kNoLineNumberInfo.
+ ExceptionInfo expected_exceptions[] = {
+ {"<WASM>", 0}, // Comment to prevent clang-format complaints.
+ {"<WASM>", 0},
+ {"callFn", 1}};
+ CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
+ expected_exceptions);
}
« no previous file with comments | « no previous file | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698