| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/execution.h" | 7 #include "src/execution.h" |
| 8 #include "src/handles.h" | 8 #include "src/handles.h" |
| 9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 public: | 58 public: |
| 59 InterpreterTester(Isolate* isolate, const char* source, | 59 InterpreterTester(Isolate* isolate, const char* source, |
| 60 MaybeHandle<BytecodeArray> bytecode, | 60 MaybeHandle<BytecodeArray> bytecode, |
| 61 MaybeHandle<TypeFeedbackVector> feedback_vector) | 61 MaybeHandle<TypeFeedbackVector> feedback_vector) |
| 62 : isolate_(isolate), | 62 : isolate_(isolate), |
| 63 source_(source), | 63 source_(source), |
| 64 bytecode_(bytecode), | 64 bytecode_(bytecode), |
| 65 feedback_vector_(feedback_vector) { | 65 feedback_vector_(feedback_vector) { |
| 66 i::FLAG_vector_stores = true; | 66 i::FLAG_vector_stores = true; |
| 67 i::FLAG_ignition = true; | 67 i::FLAG_ignition = true; |
| 68 i::FLAG_ignition_fake_try_catch = true; |
| 68 i::FLAG_always_opt = false; | 69 i::FLAG_always_opt = false; |
| 69 // Set ignition filter flag via SetFlagsFromString to avoid double-free | 70 // Set ignition filter flag via SetFlagsFromString to avoid double-free |
| 70 // (or potential leak with StrDup() based on ownership confusion). | 71 // (or potential leak with StrDup() based on ownership confusion). |
| 71 ScopedVector<char> ignition_filter(64); | 72 ScopedVector<char> ignition_filter(64); |
| 72 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); | 73 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); |
| 73 FlagList::SetFlagsFromString(ignition_filter.start(), | 74 FlagList::SetFlagsFromString(ignition_filter.start(), |
| 74 ignition_filter.length()); | 75 ignition_filter.length()); |
| 75 // Ensure handler table is generated. | 76 // Ensure handler table is generated. |
| 76 isolate->interpreter()->Initialize(); | 77 isolate->interpreter()->Initialize(); |
| 77 } | 78 } |
| (...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 | 1666 |
| 1666 for (size_t i = 0; i < arraysize(literals); i++) { | 1667 for (size_t i = 0; i < arraysize(literals); i++) { |
| 1667 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1668 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
| 1668 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1669 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1669 auto callable = tester.GetCallable<>(); | 1670 auto callable = tester.GetCallable<>(); |
| 1670 | 1671 |
| 1671 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1672 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 1672 CHECK(return_value->SameValue(*literals[i].second)); | 1673 CHECK(return_value->SameValue(*literals[i].second)); |
| 1673 } | 1674 } |
| 1674 } | 1675 } |
| 1676 |
| 1677 |
| 1678 TEST(InterpreterTryCatch) { |
| 1679 HandleAndZoneScope handles; |
| 1680 |
| 1681 // TODO(rmcilroy): modify tests when we have real try catch support. |
| 1682 std::string source(InterpreterTester::SourceForBody( |
| 1683 "var a = 1; try { a = a + 1; } catch(e) { a = a + 2; }; return a;")); |
| 1684 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1685 auto callable = tester.GetCallable<>(); |
| 1686 |
| 1687 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1688 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(2)); |
| 1689 } |
| 1690 |
| 1691 |
| 1692 TEST(InterpreterTryFinally) { |
| 1693 HandleAndZoneScope handles; |
| 1694 |
| 1695 // TODO(rmcilroy): modify tests when we have real try finally support. |
| 1696 std::string source(InterpreterTester::SourceForBody( |
| 1697 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); |
| 1698 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1699 auto callable = tester.GetCallable<>(); |
| 1700 |
| 1701 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1702 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); |
| 1703 } |
| OLD | NEW |