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/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 // Trigger a trap for loading from out-of-bounds. | 99 // Trigger a trap for loading from out-of-bounds. |
100 TEST(IllegalLoad) { | 100 TEST(IllegalLoad) { |
101 TestSignatures sigs; | 101 TestSignatures sigs; |
102 TestingModule module; | 102 TestingModule module; |
103 | 103 |
104 WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob")); | 104 WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob")); |
105 // Set the execution context, such that a runtime error can be thrown. | 105 // Set the execution context, such that a runtime error can be thrown. |
106 comp1.SetModuleContext(); | 106 comp1.SetModuleContext(); |
107 BUILD(comp1, WASM_IF(WASM_ONE, | 107 BUILD(comp1, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), |
108 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(-3)))); | 108 WASM_I32V_1(-3)), |
| 109 WASM_DROP))); |
109 uint32_t wasm_index = comp1.CompileAndAdd(); | 110 uint32_t wasm_index = comp1.CompileAndAdd(); |
110 | 111 |
111 WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob")); | 112 WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob")); |
112 // Insert a NOP such that the position of the call is not one. | 113 // Insert a NOP such that the position of the call is not one. |
113 BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index)); | 114 BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index)); |
114 uint32_t wasm_index_2 = comp2.CompileAndAdd(); | 115 uint32_t wasm_index_2 = comp2.CompileAndAdd(); |
115 | 116 |
116 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); | 117 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); |
117 | 118 |
118 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 119 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
119 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 120 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
120 CompileRun("(function callFn(fn) { fn(); })")))); | 121 CompileRun("(function callFn(fn) { fn(); })")))); |
121 | 122 |
122 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 123 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
123 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 124 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
124 v8::StackTrace::kOverview); | 125 v8::StackTrace::kOverview); |
125 Handle<Object> global(isolate->context()->global_object(), isolate); | 126 Handle<Object> global(isolate->context()->global_object(), isolate); |
126 MaybeHandle<Object> maybe_exc; | 127 MaybeHandle<Object> maybe_exc; |
127 Handle<Object> args[] = {js_wasm_wrapper}; | 128 Handle<Object> args[] = {js_wasm_wrapper}; |
128 MaybeHandle<Object> returnObjMaybe = | 129 MaybeHandle<Object> returnObjMaybe = |
129 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 130 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
130 CHECK(returnObjMaybe.is_null()); | 131 CHECK(returnObjMaybe.is_null()); |
131 | 132 |
132 // The column is 1-based, so add 1 to the actual byte offset. | 133 // The column is 1-based, so add 1 to the actual byte offset. |
133 ExceptionInfo expected_exceptions[] = { | 134 ExceptionInfo expected_exceptions[] = { |
134 {"<WASM UNNAMED>", static_cast<int>(wasm_index), 7}, // -- | 135 {"<WASM UNNAMED>", static_cast<int>(wasm_index), 8}, // -- |
135 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // -- | 136 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // -- |
136 {"callFn", 1, 24} // -- | 137 {"callFn", 1, 24} // -- |
137 }; | 138 }; |
138 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 139 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
139 } | 140 } |
OLD | NEW |