| 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, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), | 107 BUILD(comp1, WASM_IF(WASM_ONE, |
| 108 WASM_I32V_1(-3)), | 108 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(-3)))); |
| 109 WASM_DROP))); | |
| 110 uint32_t wasm_index = comp1.CompileAndAdd(); | 109 uint32_t wasm_index = comp1.CompileAndAdd(); |
| 111 | 110 |
| 112 WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob")); | 111 WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob")); |
| 113 // Insert a NOP such that the position of the call is not one. | 112 // Insert a NOP such that the position of the call is not one. |
| 114 BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index)); | 113 BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index)); |
| 115 uint32_t wasm_index_2 = comp2.CompileAndAdd(); | 114 uint32_t wasm_index_2 = comp2.CompileAndAdd(); |
| 116 | 115 |
| 117 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); | 116 Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2); |
| 118 | 117 |
| 119 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 118 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
| 120 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 119 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 121 CompileRun("(function callFn(fn) { fn(); })")))); | 120 CompileRun("(function callFn(fn) { fn(); })")))); |
| 122 | 121 |
| 123 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 122 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
| 124 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 123 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
| 125 v8::StackTrace::kOverview); | 124 v8::StackTrace::kOverview); |
| 126 Handle<Object> global(isolate->context()->global_object(), isolate); | 125 Handle<Object> global(isolate->context()->global_object(), isolate); |
| 127 MaybeHandle<Object> maybe_exc; | 126 MaybeHandle<Object> maybe_exc; |
| 128 Handle<Object> args[] = {js_wasm_wrapper}; | 127 Handle<Object> args[] = {js_wasm_wrapper}; |
| 129 MaybeHandle<Object> returnObjMaybe = | 128 MaybeHandle<Object> returnObjMaybe = |
| 130 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 129 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
| 131 CHECK(returnObjMaybe.is_null()); | 130 CHECK(returnObjMaybe.is_null()); |
| 132 | 131 |
| 133 // The column is 1-based, so add 1 to the actual byte offset. | 132 // The column is 1-based, so add 1 to the actual byte offset. |
| 134 ExceptionInfo expected_exceptions[] = { | 133 ExceptionInfo expected_exceptions[] = { |
| 135 {"<WASM UNNAMED>", static_cast<int>(wasm_index), 8}, // -- | 134 {"<WASM UNNAMED>", static_cast<int>(wasm_index), 7}, // -- |
| 136 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // -- | 135 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // -- |
| 137 {"callFn", 1, 24} // -- | 136 {"callFn", 1, 24} // -- |
| 138 }; | 137 }; |
| 139 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 138 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
| 140 } | 139 } |
| OLD | NEW |