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

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: rebase 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') | test/cctest/wasm/wasm-run-utils.h » ('J')
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 jsThrowingIndex = 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(jsThrowingIndex));
86 uint32_t wasmIndex = comp1.CompileAndAdd(); 87 uint32_t wasmIndex = comp1.CompileAndAdd();
87 88
88 WasmFunctionCompiler comp2(sigs.v_v(), &module); 89 WasmFunctionCompiler comp2(sigs.v_v(), &module);
(...skipping 18 matching lines...) Expand all
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 expectedExceptions[] = {
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, excMaybe.ToHandleChecked(), expectedExceptions);
116 } 117 }
118
119 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM
120 TEST(CollectDetailedWasmStack_WasmError) {
121 TestSignatures sigs;
122 TestingModule module;
123
124 WasmFunctionCompiler comp1(sigs.i_v(), &module, "exec_unreachable");
125 // set the execution context, such that a runtime error can be thrown
126 comp1.SetModuleContext();
127 BUILD(comp1, WASM_UNREACHABLE);
128 uint32_t wasmIndex = comp1.CompileAndAdd();
129
130 WasmFunctionCompiler comp2(sigs.i_v(), &module, "call_exec_unreachable");
131 BUILD(comp2, WASM_CALL_FUNCTION0(wasmIndex));
132 uint32_t wasmIndex2 = comp2.CompileAndAdd();
133
134 Handle<JSFunction> jsWasmWrapper = module.WrapCode(wasmIndex2);
135
136 Handle<JSFunction> jsTrampoline = Handle<JSFunction>::cast(
137 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
138 CompileRun("(function callFn(fn) { fn(); })"))));
139
140 Isolate* isolate = jsWasmWrapper->GetIsolate();
141 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10,
142 v8::StackTrace::kOverview);
143 Handle<Object> global(isolate->context()->global_object(), isolate);
144 MaybeHandle<Object> excMaybe;
145 Handle<Object> args[] = {jsWasmWrapper};
146 MaybeHandle<Object> returnObjMaybe =
147 Execution::TryCall(isolate, jsTrampoline, global, 1, args, &excMaybe);
148 CHECK(returnObjMaybe.is_null());
149
150 // line number is 1-based, with 0 == kNoLineNumberInfo
151 ExceptionInfo expectedExceptions[] = {
152 {"<WASM>", 0}, // comment to prevent clang-format complaints
153 {"<WASM>", 0}, // -
154 {"callFn", 1}};
155 CheckExceptionInfos(isolate, excMaybe.ToHandleChecked(), expectedExceptions);
156 }
OLDNEW
« no previous file with comments | « no previous file | test/cctest/wasm/wasm-run-utils.h » ('j') | test/cctest/wasm/wasm-run-utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698