| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 v8::StackTrace::kOverview); | 81 v8::StackTrace::kOverview); |
| 82 Handle<Object> global(isolate->context()->global_object(), isolate); | 82 Handle<Object> global(isolate->context()->global_object(), isolate); |
| 83 MaybeHandle<Object> maybe_exc; | 83 MaybeHandle<Object> maybe_exc; |
| 84 Handle<Object> args[] = {js_wasm_wrapper}; | 84 Handle<Object> args[] = {js_wasm_wrapper}; |
| 85 MaybeHandle<Object> returnObjMaybe = | 85 MaybeHandle<Object> returnObjMaybe = |
| 86 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 86 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
| 87 CHECK(returnObjMaybe.is_null()); | 87 CHECK(returnObjMaybe.is_null()); |
| 88 | 88 |
| 89 // 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. |
| 90 ExceptionInfo expected_exceptions[] = { | 90 ExceptionInfo expected_exceptions[] = { |
| 91 {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -- | 91 {"main", static_cast<int>(wasm_index) + 1, 2}, // -- |
| 92 {"callFn", 1, 24} // -- | 92 {"callFn", 1, 24} // -- |
| 93 }; | 93 }; |
| 94 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 94 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Trigger a trap for loading from out-of-bounds. | 97 // Trigger a trap for loading from out-of-bounds. |
| 98 TEST(IllegalLoad) { | 98 TEST(IllegalLoad) { |
| 99 WasmRunner<void> r(kExecuteCompiled); | 99 WasmRunner<void> r(kExecuteCompiled); |
| 100 TestSignatures sigs; | 100 TestSignatures sigs; |
| 101 // Set the execution context, such that a runtime error can be thrown. | 101 // Set the execution context, such that a runtime error can be thrown. |
| 102 r.SetModuleContext(); | 102 r.SetModuleContext(); |
| 103 | 103 |
| 104 BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), | 104 BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), |
| 105 WASM_I32V_1(-3)), | 105 WASM_I32V_1(-3)), |
| 106 WASM_DROP))); | 106 WASM_DROP))); |
| 107 uint32_t wasm_index_1 = r.function()->func_index; | 107 uint32_t wasm_index_1 = r.function()->func_index; |
| 108 | 108 |
| 109 WasmFunctionCompiler& f2 = r.NewFunction<void>(); | 109 WasmFunctionCompiler& f2 = r.NewFunction<void>("call_main"); |
| 110 // 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. |
| 111 BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1)); | 111 BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1)); |
| 112 uint32_t wasm_index_2 = f2.function_index(); | 112 uint32_t wasm_index_2 = f2.function_index(); |
| 113 | 113 |
| 114 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); | 114 Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); |
| 115 | 115 |
| 116 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( | 116 Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( |
| 117 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 117 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 118 CompileRun("(function callFn(fn) { fn(); })")))); | 118 CompileRun("(function callFn(fn) { fn(); })")))); |
| 119 | 119 |
| 120 Isolate* isolate = js_wasm_wrapper->GetIsolate(); | 120 Isolate* isolate = js_wasm_wrapper->GetIsolate(); |
| 121 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, | 121 isolate->SetCaptureStackTraceForUncaughtExceptions(true, 10, |
| 122 v8::StackTrace::kOverview); | 122 v8::StackTrace::kOverview); |
| 123 Handle<Object> global(isolate->context()->global_object(), isolate); | 123 Handle<Object> global(isolate->context()->global_object(), isolate); |
| 124 MaybeHandle<Object> maybe_exc; | 124 MaybeHandle<Object> maybe_exc; |
| 125 Handle<Object> args[] = {js_wasm_wrapper}; | 125 Handle<Object> args[] = {js_wasm_wrapper}; |
| 126 MaybeHandle<Object> returnObjMaybe = | 126 MaybeHandle<Object> returnObjMaybe = |
| 127 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); | 127 Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc); |
| 128 CHECK(returnObjMaybe.is_null()); | 128 CHECK(returnObjMaybe.is_null()); |
| 129 | 129 |
| 130 // 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. |
| 131 ExceptionInfo expected_exceptions[] = { | 131 ExceptionInfo expected_exceptions[] = { |
| 132 {"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 8}, // -- | 132 {"main", static_cast<int>(wasm_index_1) + 1, 8}, // -- |
| 133 {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // -- | 133 {"call_main", static_cast<int>(wasm_index_2) + 1, 3}, // -- |
| 134 {"callFn", 1, 24} // -- | 134 {"callFn", 1, 24} // -- |
| 135 }; | 135 }; |
| 136 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); | 136 CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions); |
| 137 } | 137 } |
| OLD | NEW |