OLD | NEW |
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/wasm-run-utils.h" | 9 #include "test/cctest/wasm/wasm-run-utils.h" |
10 #include "test/common/wasm/test-signatures.h" | 10 #include "test/common/wasm/test-signatures.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 CHECK_CSTREQ(excInfos[frameNr].func_name, *funName); | 69 CHECK_CSTREQ(excInfos[frameNr].func_name, *funName); |
70 CHECK_EQ(excInfos[frameNr].line_nr, frame->GetLineNumber()); | 70 CHECK_EQ(excInfos[frameNr].line_nr, frame->GetLineNumber()); |
71 CHECK_EQ(excInfos[frameNr].column, frame->GetColumn()); | 71 CHECK_EQ(excInfos[frameNr].column, frame->GetColumn()); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 // Call from JS to WASM to JS and throw an Error from JS. | 77 // Call from JS to WASM to JS and throw an Error from JS. |
78 TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { | 78 TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { |
79 WasmRunner<void> r(kExecuteCompiled); | |
80 TestSignatures sigs; | 79 TestSignatures sigs; |
| 80 TestingModule module; |
81 | 81 |
82 uint32_t js_throwing_index = r.module().AddJsFunction( | 82 // Initialize WasmFunctionCompiler first, since it sets up the HandleScope. |
| 83 WasmFunctionCompiler comp1(sigs.v_v(), &module); |
| 84 |
| 85 uint32_t js_throwing_index = module.AddJsFunction( |
83 sigs.v_v(), | 86 sigs.v_v(), |
84 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); | 87 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); |
85 | 88 |
86 // Add a nop such that we don't always get position 1. | 89 // Add a nop such that we don't always get position 1. |
87 BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); | 90 BUILD(comp1, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); |
88 uint32_t wasm_index_1 = r.function()->func_index; | 91 uint32_t wasm_index = comp1.CompileAndAdd(); |
89 | 92 |
90 WasmFunctionCompiler& f2 = r.NewFunction<void>(); | 93 WasmFunctionCompiler comp2(sigs.v_v(), &module); |
91 BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1)); | 94 BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index)); |
92 uint32_t wasm_index_2 = f2.function_index(); | 95 uint32_t wasm_index_2 = comp2.CompileAndAdd(); |
93 | 96 |
94 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); | 97 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); |
95 | 98 |
96 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 99 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
97 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 100 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
98 CompileRun("(function callFn(fn) { fn(); })")))); | 101 CompileRun("(function callFn(fn) { fn(); })")))); |
99 | 102 |
100 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 103 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
101 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 104 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
102 v8::StackTrace::kOverview); | 105 v8::StackTrace::kOverview); |
103 Handle<Object> global(isolate->context()->global_object(), isolate); | 106 Handle<Object> global(isolate->context()->global_object(), isolate); |
104 MaybeHandle<Object> maybe_exc; | 107 MaybeHandle<Object> maybe_exc; |
105 Handle<Object> args[] = {js_wasm_wrapper}; | 108 Handle<Object> args[] = {js_wasm_wrapper}; |
106 MaybeHandle<Object> returnObjMaybe = | 109 MaybeHandle<Object> returnObjMaybe = |
107 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 110 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
108 CHECK(returnObjMaybe.is_null()); | 111 CHECK(returnObjMaybe.is_null()); |
109 | 112 |
110 // Line and column are 1-based, so add 1 for the expected wasm output. | 113 // Line and column are 1-based, so add 1 for the expected wasm output. |
111 ExceptionInfo expected_exceptions[] = { | 114 ExceptionInfo expected_exceptions[] = { |
112 {"a", 3, 8}, // - | 115 {"a", 3, 8}, // - |
113 {"js", 4, 2}, // - | 116 {"js", 4, 2}, // - |
114 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 3}, // - | 117 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 3}, // - |
115 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - | 118 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - |
116 {"callFn", 1, 24} // - | 119 {"callFn", 1, 24} // - |
117 }; | 120 }; |
118 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 121 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
119 } | 122 } |
120 | 123 |
121 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM. | 124 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM. |
122 TEST(CollectDetailedWasmStack_WasmError) { | 125 TEST(CollectDetailedWasmStack_WasmError) { |
123 TestSignatures sigs; | 126 TestSignatures sigs; |
124 WasmRunner<int> r(kExecuteCompiled); | 127 TestingModule module; |
| 128 |
| 129 WasmFunctionCompiler comp1(sigs.i_v(), &module, |
| 130 ArrayVector("exec_unreachable")); |
125 // Set the execution context, such that a runtime error can be thrown. | 131 // Set the execution context, such that a runtime error can be thrown. |
126 r.SetModuleContext(); | 132 comp1.SetModuleContext(); |
| 133 BUILD(comp1, WASM_UNREACHABLE); |
| 134 uint32_t wasm_index = comp1.CompileAndAdd(); |
127 | 135 |
128 BUILD(r, WASM_UNREACHABLE); | 136 WasmFunctionCompiler comp2(sigs.i_v(), &module, |
129 uint32_t wasm_index_1 = r.function()->func_index; | 137 ArrayVector("call_exec_unreachable")); |
| 138 BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index)); |
| 139 uint32_t wasm_index_2 = comp2.CompileAndAdd(); |
130 | 140 |
131 WasmFunctionCompiler& f2 = r.NewFunction<int>(); | 141 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); |
132 BUILD(f2, WASM_CALL_FUNCTION0(0)); | |
133 uint32_t wasm_index_2 = f2.function_index(); | |
134 | |
135 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); | |
136 | 142 |
137 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 143 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
138 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 144 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
139 CompileRun("(function callFn(fn) { fn(); })")))); | 145 CompileRun("(function callFn(fn) { fn(); })")))); |
140 | 146 |
141 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 147 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
142 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 148 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
143 v8::StackTrace::kOverview); | 149 v8::StackTrace::kOverview); |
144 Handle<Object> global(isolate->context()->global_object(), isolate); | 150 Handle<Object> global(isolate->context()->global_object(), isolate); |
145 MaybeHandle<Object> maybe_exc; | 151 MaybeHandle<Object> maybe_exc; |
146 Handle<Object> args[] = {js_wasm_wrapper}; | 152 Handle<Object> args[] = {js_wasm_wrapper}; |
147 MaybeHandle<Object> maybe_return_obj = | 153 MaybeHandle<Object> maybe_return_obj = |
148 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 154 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
149 CHECK(maybe_return_obj.is_null()); | 155 CHECK(maybe_return_obj.is_null()); |
150 | 156 |
151 // Line and column are 1-based, so add 1 for the expected wasm output. | 157 // Line and column are 1-based, so add 1 for the expected wasm output. |
152 ExceptionInfo expected_exceptions[] = { | 158 ExceptionInfo expected_exceptions[] = { |
153 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 2}, // - | 159 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // - |
154 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - | 160 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - |
155 {"callFn", 1, 24} //- | 161 {"callFn", 1, 24} //- |
156 }; | 162 }; |
157 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 163 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
158 } | 164 } |
OLD | NEW |