| 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); |
| 79 TestSignatures sigs; | 80 TestSignatures sigs; |
| 80 TestingModule module; | |
| 81 | 81 |
| 82 // Initialize WasmFunctionCompiler first, since it sets up the HandleScope. | 82 uint32_t js_throwing_index = r.module().AddJsFunction( |
| 83 WasmFunctionCompiler comp1(sigs.v_v(), &module); | |
| 84 | |
| 85 uint32_t js_throwing_index = module.AddJsFunction( | |
| 86 sigs.v_v(), | 83 sigs.v_v(), |
| 87 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); | 84 "(function js() {\n function a() {\n throw new Error(); };\n a(); })"); |
| 88 | 85 |
| 89 // 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. |
| 90 BUILD(comp1, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); | 87 BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); |
| 91 uint32_t wasm_index = comp1.CompileAndAdd(); | 88 uint32_t wasm_index_1 = r.function()->func_index; |
| 92 | 89 |
| 93 WasmFunctionCompiler comp2(sigs.v_v(), &module); | 90 WasmFunctionCompiler& f2 = r.NewFunction<void>(); |
| 94 BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index)); | 91 BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1)); |
| 95 uint32_t wasm_index_2 = comp2.CompileAndAdd(); | 92 uint32_t wasm_index_2 = f2.function_index(); |
| 96 | 93 |
| 97 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); | 94 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); |
| 98 | 95 |
| 99 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 96 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
| 100 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 97 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 101 CompileRun("(function callFn(fn) { fn(); })")))); | 98 CompileRun("(function callFn(fn) { fn(); })")))); |
| 102 | 99 |
| 103 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 100 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
| 104 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 101 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
| 105 v8::StackTrace::kOverview); | 102 v8::StackTrace::kOverview); |
| 106 Handle<Object> global(isolate->context()->global_object(), isolate); | 103 Handle<Object> global(isolate->context()->global_object(), isolate); |
| 107 MaybeHandle<Object> maybe_exc; | 104 MaybeHandle<Object> maybe_exc; |
| 108 Handle<Object> args[] = {js_wasm_wrapper}; | 105 Handle<Object> args[] = {js_wasm_wrapper}; |
| 109 MaybeHandle<Object> returnObjMaybe = | 106 MaybeHandle<Object> returnObjMaybe = |
| 110 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 107 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
| 111 CHECK(returnObjMaybe.is_null()); | 108 CHECK(returnObjMaybe.is_null()); |
| 112 | 109 |
| 113 // 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. |
| 114 ExceptionInfo expected_exceptions[] = { | 111 ExceptionInfo expected_exceptions[] = { |
| 115 {"a", 3, 8}, // - | 112 {"a", 3, 8}, // - |
| 116 {"js", 4, 2}, // - | 113 {"js", 4, 2}, // - |
| 117 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 3}, // - | 114 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 3}, // - |
| 118 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - | 115 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - |
| 119 {"callFn", 1, 24} // - | 116 {"callFn", 1, 24} // - |
| 120 }; | 117 }; |
| 121 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 118 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
| 122 } | 119 } |
| 123 | 120 |
| 124 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM. | 121 // Trigger a trap in WASM, stack should be JS -> WASM -> WASM. |
| 125 TEST(CollectDetailedWasmStack_WasmError) { | 122 TEST(CollectDetailedWasmStack_WasmError) { |
| 126 TestSignatures sigs; | 123 TestSignatures sigs; |
| 127 TestingModule module; | 124 WasmRunner<int> r(kExecuteCompiled); |
| 125 // Set the execution context, such that a runtime error can be thrown. |
| 126 r.SetModuleContext(); |
| 128 | 127 |
| 129 WasmFunctionCompiler comp1(sigs.i_v(), &module, | 128 BUILD(r, WASM_UNREACHABLE); |
| 130 ArrayVector("exec_unreachable")); | 129 uint32_t wasm_index_1 = r.function()->func_index; |
| 131 // Set the execution context, such that a runtime error can be thrown. | |
| 132 comp1.SetModuleContext(); | |
| 133 BUILD(comp1, WASM_UNREACHABLE); | |
| 134 uint32_t wasm_index = comp1.CompileAndAdd(); | |
| 135 | 130 |
| 136 WasmFunctionCompiler comp2(sigs.i_v(), &module, | 131 WasmFunctionCompiler& f2 = r.NewFunction<int>(); |
| 137 ArrayVector("call_exec_unreachable")); | 132 BUILD(f2, WASM_CALL_FUNCTION0(0)); |
| 138 BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index)); | 133 uint32_t wasm_index_2 = f2.function_index(); |
| 139 uint32_t wasm_index_2 = comp2.CompileAndAdd(); | |
| 140 | 134 |
| 141 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); | 135 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); |
| 142 | 136 |
| 143 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 137 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
| 144 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 138 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 145 CompileRun("(function callFn(fn) { fn(); })")))); | 139 CompileRun("(function callFn(fn) { fn(); })")))); |
| 146 | 140 |
| 147 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 141 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
| 148 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 142 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
| 149 v8::StackTrace::kOverview); | 143 v8::StackTrace::kOverview); |
| 150 Handle<Object> global(isolate->context()->global_object(), isolate); | 144 Handle<Object> global(isolate->context()->global_object(), isolate); |
| 151 MaybeHandle<Object> maybe_exc; | 145 MaybeHandle<Object> maybe_exc; |
| 152 Handle<Object> args[] = {js_wasm_wrapper}; | 146 Handle<Object> args[] = {js_wasm_wrapper}; |
| 153 MaybeHandle<Object> maybe_return_obj = | 147 MaybeHandle<Object> maybe_return_obj = |
| 154 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 148 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
| 155 CHECK(maybe_return_obj.is_null()); | 149 CHECK(maybe_return_obj.is_null()); |
| 156 | 150 |
| 157 // 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. |
| 158 ExceptionInfo expected_exceptions[] = { | 152 ExceptionInfo expected_exceptions[] = { |
| 159 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // - | 153 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 2}, // - |
| 160 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - | 154 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - |
| 161 {"callFn", 1, 24} //- | 155 {"callFn", 1, 24} //- |
| 162 }; | 156 }; |
| 163 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 157 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
| 164 } | 158 } |
| OLD | NEW |