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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 TestSignatures sigs; | 80 TestSignatures sigs; |
81 | 81 |
82 uint32_t js_throwing_index = r.module().AddJsFunction( | 82 uint32_t js_throwing_index = r.module().AddJsFunction( |
83 sigs.v_v(), | 83 sigs.v_v(), |
84 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); | 84 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); |
85 | 85 |
86 // Add a nop such that we don't always get position 1. | 86 // Add a nop such that we don't always get position 1. |
87 BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); | 87 BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); |
88 uint32_t wasm_index_1 = r.function()->func_index; | 88 uint32_t wasm_index_1 = r.function()->func_index; |
89 | 89 |
90 WasmFunctionCompiler& f2 = r.NewFunction<void>(); | 90 WasmFunctionCompiler& f2 = r.NewFunction<void>("call_main"); |
91 BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1)); | 91 BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1)); |
92 uint32_t wasm_index_2 = f2.function_index(); | 92 uint32_t wasm_index_2 = f2.function_index(); |
93 | 93 |
94 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); | 94 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); |
95 | 95 |
96 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 96 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
97 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 97 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
98 CompileRun("(function callFn(fn) { fn(); })")))); | 98 CompileRun("(function callFn(fn) { fn(); })")))); |
99 | 99 |
100 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 100 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
101 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 101 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
102 v8::StackTrace::kOverview); | 102 v8::StackTrace::kOverview); |
103 Handle<Object> global(isolate->context()->global_object(), isolate); | 103 Handle<Object> global(isolate->context()->global_object(), isolate); |
104 MaybeHandle<Object> maybe_exc; | 104 MaybeHandle<Object> maybe_exc; |
105 Handle<Object> args[] = {js_wasm_wrapper}; | 105 Handle<Object> args[] = {js_wasm_wrapper}; |
106 MaybeHandle<Object> returnObjMaybe = | 106 MaybeHandle<Object> returnObjMaybe = |
107 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 107 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
108 CHECK(returnObjMaybe.is_null()); | 108 CHECK(returnObjMaybe.is_null()); |
109 | 109 |
110 // Line and column are 1-based, so add 1 for the expected wasm output. | 110 // Line and column are 1-based, so add 1 for the expected wasm output. |
111 ExceptionInfo expected_exceptions[] = { | 111 ExceptionInfo expected_exceptions[] = { |
112 {"a", 3, 8}, // - | 112 {"a", 3, 8}, // - |
113 {"js", 4, 2}, // - | 113 {"js", 4, 2}, // - |
114 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 3}, // - | 114 {"main", static_cast<int>(wasm_index_1) + 1, 3}, // - |
115 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - | 115 {"call_main", static_cast<int>(wasm_index_2) + 1, 2}, // - |
116 {"callFn", 1, 24} // - | 116 {"callFn", 1, 24} // - |
117 }; | 117 }; |
118 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 118 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
119 } | 119 } |
120 | 120 |
121 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM. | 121 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM. |
122 TEST(CollectDetailedWasmStack_WasmError) { | 122 TEST(CollectDetailedWasmStack_WasmError) { |
123 TestSignatures sigs; | 123 TestSignatures sigs; |
124 WasmRunner<int> r(kExecuteCompiled); | 124 WasmRunner<int> r(kExecuteCompiled); |
125 // Set the execution context, such that a runtime error can be thrown. | 125 // Set the execution context, such that a runtime error can be thrown. |
126 r.SetModuleContext(); | 126 r.SetModuleContext(); |
127 | 127 |
128 BUILD(r, WASM_UNREACHABLE); | 128 BUILD(r, WASM_UNREACHABLE); |
129 uint32_t wasm_index_1 = r.function()->func_index; | 129 uint32_t wasm_index_1 = r.function()->func_index; |
130 | 130 |
131 WasmFunctionCompiler& f2 = r.NewFunction<int>(); | 131 WasmFunctionCompiler& f2 = r.NewFunction<int>("call_main"); |
132 BUILD(f2, WASM_CALL_FUNCTION0(0)); | 132 BUILD(f2, WASM_CALL_FUNCTION0(0)); |
133 uint32_t wasm_index_2 = f2.function_index(); | 133 uint32_t wasm_index_2 = f2.function_index(); |
134 | 134 |
135 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); | 135 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); |
136 | 136 |
137 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 137 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
138 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 138 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
139 CompileRun("(function callFn(fn) { fn(); })")))); | 139 CompileRun("(function callFn(fn) { fn(); })")))); |
140 | 140 |
141 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 141 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
142 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 142 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
143 v8::StackTrace::kOverview); | 143 v8::StackTrace::kOverview); |
144 Handle<Object> global(isolate->context()->global_object(), isolate); | 144 Handle<Object> global(isolate->context()->global_object(), isolate); |
145 MaybeHandle<Object> maybe_exc; | 145 MaybeHandle<Object> maybe_exc; |
146 Handle<Object> args[] = {js_wasm_wrapper}; | 146 Handle<Object> args[] = {js_wasm_wrapper}; |
147 MaybeHandle<Object> maybe_return_obj = | 147 MaybeHandle<Object> maybe_return_obj = |
148 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 148 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
149 CHECK(maybe_return_obj.is_null()); | 149 CHECK(maybe_return_obj.is_null()); |
150 | 150 |
151 // Line and column are 1-based, so add 1 for the expected wasm output. | 151 // Line and column are 1-based, so add 1 for the expected wasm output. |
152 ExceptionInfo expected_exceptions[] = { | 152 ExceptionInfo expected_exceptions[] = { |
153 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 2}, // - | 153 {"main", static_cast<int>(wasm_index_1) + 1, 2}, // - |
154 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - | 154 {"call_main", static_cast<int>(wasm_index_2) + 1, 2}, // - |
155 {"callFn", 1, 24} //- | 155 {"callFn", 1, 24} //- |
156 }; | 156 }; |
157 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 157 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
158 } | 158 } |
OLD | NEW |