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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-macro-gen.h" 5 #include "src/wasm/wasm-macro-gen.h"
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 #include "test/cctest/compiler/value-helper.h" 8 #include "test/cctest/compiler/value-helper.h"
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 #include "test/cctest/wasm/wasm-run-utils.h" 10 #include "test/cctest/wasm/wasm-run-utils.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 struct ExceptionInfo { 46 struct ExceptionInfo {
47 const char* funcName; 47 const char* funcName;
48 int lineNr; 48 int lineNr;
49 }; 49 };
50 50
51 template <int N> 51 template <int N>
52 void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc, 52 void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
53 const ExceptionInfo (&excInfos)[N]) { 53 const ExceptionInfo (&excInfos)[N]) {
54 // check that it's indeed an Error object 54 // Check that it's indeed an Error object.
55 CHECK(Object::IsErrorObject(isolate, exc)); 55 CHECK(Object::IsErrorObject(isolate, exc));
56 56
57 // extract stack frame from exception 57 // Extract stack frame from the exception.
58 Local<v8::Value> localExc = Utils::ToLocal(exc); 58 Local<v8::Value> localExc = Utils::ToLocal(exc);
59 v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(localExc); 59 v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(localExc);
60 PrintStackTrace(stack); 60 PrintStackTrace(stack);
61 CHECK(!stack.IsEmpty()); 61 CHECK(!stack.IsEmpty());
62 CHECK_EQ(N, stack->GetFrameCount()); 62 CHECK_EQ(N, stack->GetFrameCount());
63 63
64 for (int frameNr = 0; frameNr < N; ++frameNr) { 64 for (int frameNr = 0; frameNr < N; ++frameNr) {
65 v8::Local<v8::StackFrame> frame = stack->GetFrame(frameNr); 65 v8::Local<v8::StackFrame> frame = stack->GetFrame(frameNr);
66 v8::String::Utf8Value funName(frame->GetFunctionName()); 66 v8::String::Utf8Value funName(frame->GetFunctionName());
67 CHECK_CSTREQ(excInfos[frameNr].funcName, *funName); 67 CHECK_CSTREQ(excInfos[frameNr].funcName, *funName);
68 CHECK_EQ(excInfos[frameNr].lineNr, frame->GetLineNumber()); 68 CHECK_EQ(excInfos[frameNr].lineNr, frame->GetLineNumber());
69 } 69 }
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 // Call from JS to WASM to JS and throw an Error from JS. 74 // Call from JS to WASM to JS and throw an Error from JS.
75 TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { 75 TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
76 TestSignatures sigs; 76 TestSignatures sigs;
77 TestingModule module; 77 TestingModule module;
78 78
79 // Initialize WasmFunctionCompiler first, since it sets up the HandleScope.
79 WasmFunctionCompiler comp1(sigs.v_v(), &module); 80 WasmFunctionCompiler comp1(sigs.v_v(), &module);
80 81
81 uint32_t jsThrowingIndex = module.AddJsFunction( 82 uint32_t js_throwing_index = module.AddJsFunction(
82 sigs.v_v(), 83 sigs.v_v(),
83 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); 84 "(function js() {\n function a() {\n throw new Error(); };\n a(); })");
84 85
85 BUILD(comp1, WASM_CALL_FUNCTION0(jsThrowingIndex)); 86 BUILD(comp1, WASM_CALL_FUNCTION0(js_throwing_index));
86 uint32_t wasmIndex = comp1.CompileAndAdd(); 87 uint32_t wasm_index = comp1.CompileAndAdd();
87 88
88 WasmFunctionCompiler comp2(sigs.v_v(), &module); 89 WasmFunctionCompiler comp2(sigs.v_v(), &module);
89 BUILD(comp2, WASM_CALL_FUNCTION0(wasmIndex)); 90 BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
90 uint32_t wasmIndex2 = comp2.CompileAndAdd(); 91 uint32_t wasm_index_2 = comp2.CompileAndAdd();
91 92
92 Handle<JSFunction> jsWasmWrapper = module.WrapCode(wasmIndex2); 93 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
93 94
94 Handle<JSFunction> jsTrampoline = Handle<JSFunction>::cast( 95 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
95 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 96 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
96 CompileRun("(function callFn(fn) { fn(); })")))); 97 CompileRun("(function callFn(fn) { fn(); })"))));
97 98
98 Isolate* isolate = jsWasmWrapper->GetIsolate(); 99 Isolate* isolate = js_wasm_wrapper->GetIsolate();
99 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, 100 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
100 v8::StackTrace::kOverview); 101 v8::StackTrace::kOverview);
101 Handle<Object> global(isolate->context()->global_object(), isolate); 102 Handle<Object> global(isolate->context()->global_object(), isolate);
102 MaybeHandle<Object> excMaybe; 103 MaybeHandle<Object> maybe_exc;
103 Handle<Object> args[] = {jsWasmWrapper}; 104 Handle<Object> args[] = {js_wasm_wrapper};
104 MaybeHandle<Object> returnObjMaybe = 105 MaybeHandle<Object> returnObjMaybe =
105 Execution::TryCall(isolate, jsTrampoline, global, 1, args, &excMaybe); 106 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
106 CHECK(returnObjMaybe.is_null()); 107 CHECK(returnObjMaybe.is_null());
107 108
108 // line number is 1-based, with 0 == kNoLineNumberInfo 109 // Line number is 1-based, with 0 == kNoLineNumberInfo.
109 ExceptionInfo expectedExceptions[] = { 110 ExceptionInfo expected_exceptions[] = {
110 {"a", 3}, // comment to prevent clang-format complaints 111 {"a", 3}, // Comment to prevent clang-format complaints
111 {"js", 4}, // - 112 {"js", 4}, // -
112 {"<WASM>", 0}, // - 113 {"<WASM>", 0}, // -
113 {"<WASM>", 0}, // - 114 {"<WASM>", 0}, // -
114 {"callFn", 1}}; 115 {"callFn", 1}};
115 CheckExceptionInfos(isolate, excMaybe.ToHandleChecked(), expectedExceptions); 116 CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
117 expected_exceptions);
116 } 118 }
119
120 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
121 TEST(CollectDetailedWasmStack_WasmError) {
122 TestSignatures sigs;
123 TestingModule module;
124
125 WasmFunctionCompiler comp1(sigs.i_v(), &module, "exec_unreachable");
126 // Set the execution context, such that a runtime error can be thrown.
127 comp1.SetModuleContext();
128 BUILD(comp1, WASM_UNREACHABLE);
129 uint32_t wasm_index = comp1.CompileAndAdd();
130
131 WasmFunctionCompiler comp2(sigs.i_v(), &module, "call_exec_unreachable");
132 BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
133 uint32_t wasm_index_2 = comp2.CompileAndAdd();
134
135 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
136
137 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
138 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
139 CompileRun("(function callFn(fn) { fn(); })"))));
140
141 Isolate* isolate = js_wasm_wrapper->GetIsolate();
142 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
143 v8::StackTrace::kOverview);
144 Handle<Object> global(isolate->context()->global_object(), isolate);
145 MaybeHandle<Object> maybe_exc;
146 Handle<Object> args[] = {js_wasm_wrapper};
147 MaybeHandle<Object> maybe_return_obj =
148 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
149 CHECK(maybe_return_obj.is_null());
150
151 // Line number is 1-based, with 0 == kNoLineNumberInfo.
152 ExceptionInfo expected_exceptions[] = {
153 {"<WASM>", 0}, // Comment to prevent clang-format complaints.
154 {"<WASM>", 0},
155 {"callFn", 1}};
156 CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
157 expected_exceptions);
158 }
OLDNEW
« 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