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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 CHECK_CSTREQ(excInfos[frameNr].func_name, *funName); | 55 CHECK_CSTREQ(excInfos[frameNr].func_name, *funName); |
56 CHECK_EQ(excInfos[frameNr].line_nr, frame->GetLineNumber()); | 56 CHECK_EQ(excInfos[frameNr].line_nr, frame->GetLineNumber()); |
57 CHECK_EQ(excInfos[frameNr].column, frame->GetColumn()); | 57 CHECK_EQ(excInfos[frameNr].column, frame->GetColumn()); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 // Trigger a trap for executing unreachable. | 63 // Trigger a trap for executing unreachable. |
64 TEST(Unreachable) { | 64 TEST(Unreachable) { |
| 65 WasmRunner<void> r(kExecuteCompiled); |
65 TestSignatures sigs; | 66 TestSignatures sigs; |
66 TestingModule module; | 67 // Set the execution context, such that a runtime error can be thrown. |
| 68 r.SetModuleContext(); |
67 | 69 |
68 WasmFunctionCompiler comp1(sigs.v_v(), &module, | 70 BUILD(r, WASM_UNREACHABLE); |
69 ArrayVector("exec_unreachable")); | 71 uint32_t wasm_index = r.function()->func_index; |
70 // Set the execution context, such that a runtime error can be thrown. | |
71 comp1.SetModuleContext(); | |
72 BUILD(comp1, WASM_UNREACHABLE); | |
73 uint32_t wasm_index = comp1.CompileAndAdd(); | |
74 | 72 |
75 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index); | 73 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index); |
76 | 74 |
77 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 75 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
78 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 76 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
79 CompileRun("(function callFn(fn) { fn(); })")))); | 77 CompileRun("(function callFn(fn) { fn(); })")))); |
80 | 78 |
81 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 79 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
82 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 80 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
83 v8::StackTrace::kOverview); | 81 v8::StackTrace::kOverview); |
84 Handle<Object> global(isolate->context()->global_object(), isolate); | 82 Handle<Object> global(isolate->context()->global_object(), isolate); |
85 MaybeHandle<Object> maybe_exc; | 83 MaybeHandle<Object> maybe_exc; |
86 Handle<Object> args[] = {js_wasm_wrapper}; | 84 Handle<Object> args[] = {js_wasm_wrapper}; |
87 MaybeHandle<Object> returnObjMaybe = | 85 MaybeHandle<Object> returnObjMaybe = |
88 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 86 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
89 CHECK(returnObjMaybe.is_null()); | 87 CHECK(returnObjMaybe.is_null()); |
90 | 88 |
91 // Line and column are 1-based, so add 1 for the expected wasm output. | 89 // Line and column are 1-based, so add 1 for the expected wasm output. |
92 ExceptionInfo expected_exceptions[] = { | 90 ExceptionInfo expected_exceptions[] = { |
93 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -- | 91 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -- |
94 {"callFn", 1, 24} // -- | 92 {"callFn", 1, 24} // -- |
95 }; | 93 }; |
96 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 94 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
97 } | 95 } |
98 | 96 |
99 // Trigger a trap for loading from out-of-bounds. | 97 // Trigger a trap for loading from out-of-bounds. |
100 TEST(IllegalLoad) { | 98 TEST(IllegalLoad) { |
| 99 WasmRunner<void> r(kExecuteCompiled); |
101 TestSignatures sigs; | 100 TestSignatures sigs; |
102 TestingModule module; | 101 // Set the execution context, such that a runtime error can be thrown. |
| 102 r.SetModuleContext(); |
103 | 103 |
104 WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob")); | 104 BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), |
105 // Set the execution context, such that a runtime error can be thrown. | 105 WASM_I32V_1(-3)), |
106 comp1.SetModuleContext(); | 106 WASM_DROP))); |
107 BUILD(comp1, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), | 107 uint32_t wasm_index_1 = r.function()->func_index; |
108 WASM_I32V_1(-3)), | |
109 WASM_DROP))); | |
110 uint32_t wasm_index = comp1.CompileAndAdd(); | |
111 | 108 |
112 WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob")); | 109 WasmFunctionCompiler& f2 = r.NewFunction<void>(); |
113 // Insert a NOP such that the position of the call is not one. | 110 // Insert a NOP such that the position of the call is not one. |
114 BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index)); | 111 BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1)); |
115 uint32_t wasm_index_2 = comp2.CompileAndAdd(); | 112 uint32_t wasm_index_2 = f2.function_index(); |
116 | 113 |
117 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); | 114 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); |
118 | 115 |
119 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 116 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
120 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 117 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
121 CompileRun("(function callFn(fn) { fn(); })")))); | 118 CompileRun("(function callFn(fn) { fn(); })")))); |
122 | 119 |
123 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 120 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
124 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 121 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
125 v8::StackTrace::kOverview); | 122 v8::StackTrace::kOverview); |
126 Handle<Object> global(isolate->context()->global_object(), isolate); | 123 Handle<Object> global(isolate->context()->global_object(), isolate); |
127 MaybeHandle<Object> maybe_exc; | 124 MaybeHandle<Object> maybe_exc; |
128 Handle<Object> args[] = {js_wasm_wrapper}; | 125 Handle<Object> args[] = {js_wasm_wrapper}; |
129 MaybeHandle<Object> returnObjMaybe = | 126 MaybeHandle<Object> returnObjMaybe = |
130 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 127 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
131 CHECK(returnObjMaybe.is_null()); | 128 CHECK(returnObjMaybe.is_null()); |
132 | 129 |
133 // Line and column are 1-based, so add 1 for the expected wasm output. | 130 // Line and column are 1-based, so add 1 for the expected wasm output. |
134 ExceptionInfo expected_exceptions[] = { | 131 ExceptionInfo expected_exceptions[] = { |
135 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 8}, // -- | 132 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 8}, // -- |
136 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // -- | 133 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // -- |
137 {"callFn", 1, 24} // -- | 134 {"callFn", 1, 24} // -- |
138 }; | 135 }; |
139 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 136 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
140 } | 137 } |
OLD | NEW |