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 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 auto callable = tester.GetCallable<>(); | 2014 auto callable = tester.GetCallable<>(); |
2015 | 2015 |
2016 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2016 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2017 CHECK(return_value->SameValue(*literals[i].second)); | 2017 CHECK(return_value->SameValue(*literals[i].second)); |
2018 } | 2018 } |
2019 } | 2019 } |
2020 | 2020 |
2021 | 2021 |
2022 TEST(InterpreterTryCatch) { | 2022 TEST(InterpreterTryCatch) { |
2023 HandleAndZoneScope handles; | 2023 HandleAndZoneScope handles; |
| 2024 i::Isolate* isolate = handles.main_isolate(); |
2024 | 2025 |
2025 // TODO(rmcilroy): modify tests when we have real try catch support. | 2026 std::pair<const char*, Handle<Object>> catches[] = { |
2026 std::string source(InterpreterTester::SourceForBody( | 2027 std::make_pair("var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", |
2027 "var a = 1; try { a = a + 1; } catch(e) { a = a + 2; }; return a;")); | 2028 handle(Smi::FromInt(2), isolate)), |
2028 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2029 std::make_pair("var a; try { undef.x } catch(e) { a = 2 }; return a;", |
2029 auto callable = tester.GetCallable<>(); | 2030 handle(Smi::FromInt(2), isolate)), |
| 2031 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", |
| 2032 handle(Smi::FromInt(3), isolate)), |
| 2033 }; |
2030 | 2034 |
2031 Handle<Object> return_val = callable().ToHandleChecked(); | 2035 for (size_t i = 0; i < arraysize(catches); i++) { |
2032 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(2)); | 2036 std::string source(InterpreterTester::SourceForBody(catches[i].first)); |
| 2037 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 2038 auto callable = tester.GetCallable<>(); |
| 2039 |
| 2040 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 2041 CHECK(return_value->SameValue(*catches[i].second)); |
| 2042 } |
2033 } | 2043 } |
2034 | 2044 |
2035 | 2045 |
2036 TEST(InterpreterTryFinally) { | 2046 TEST(InterpreterTryFinally) { |
2037 HandleAndZoneScope handles; | 2047 HandleAndZoneScope handles; |
2038 | 2048 |
2039 // TODO(rmcilroy): modify tests when we have real try finally support. | 2049 // TODO(rmcilroy): modify tests when we have real try finally support. |
2040 std::string source(InterpreterTester::SourceForBody( | 2050 std::string source(InterpreterTester::SourceForBody( |
2041 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); | 2051 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); |
2042 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2052 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
2043 auto callable = tester.GetCallable<>(); | 2053 auto callable = tester.GetCallable<>(); |
2044 | 2054 |
2045 Handle<Object> return_val = callable().ToHandleChecked(); | 2055 Handle<Object> return_val = callable().ToHandleChecked(); |
2046 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); | 2056 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); |
2047 } | 2057 } |
2048 | 2058 |
2049 | 2059 |
2050 TEST(InterpreterThrow) { | 2060 TEST(InterpreterThrow) { |
2051 HandleAndZoneScope handles; | 2061 HandleAndZoneScope handles; |
2052 i::Isolate* isolate = handles.main_isolate(); | 2062 i::Isolate* isolate = handles.main_isolate(); |
2053 i::Factory* factory = isolate->factory(); | 2063 i::Factory* factory = isolate->factory(); |
2054 | 2064 |
2055 // TODO(rmcilroy): modify tests when we have real try catch support. | |
2056 std::pair<const char*, Handle<Object>> throws[] = { | 2065 std::pair<const char*, Handle<Object>> throws[] = { |
2057 std::make_pair("throw undefined;\n", | 2066 std::make_pair("throw undefined;\n", |
2058 factory->undefined_value()), | 2067 factory->undefined_value()), |
2059 std::make_pair("throw 1;\n", | 2068 std::make_pair("throw 1;\n", |
2060 handle(Smi::FromInt(1), isolate)), | 2069 handle(Smi::FromInt(1), isolate)), |
2061 std::make_pair("throw 'Error';\n", | 2070 std::make_pair("throw 'Error';\n", |
2062 factory->NewStringFromStaticChars("Error")), | 2071 factory->NewStringFromStaticChars("Error")), |
2063 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", | 2072 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", |
2064 factory->NewStringFromStaticChars("Error")), | 2073 factory->NewStringFromStaticChars("Error")), |
2065 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", | 2074 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", |
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3521 auto callable = tester.GetCallable<>(); | 3530 auto callable = tester.GetCallable<>(); |
3522 | 3531 |
3523 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3532 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3524 CHECK(return_value->SameValue(*eval_func_decl[i].second)); | 3533 CHECK(return_value->SameValue(*eval_func_decl[i].second)); |
3525 } | 3534 } |
3526 } | 3535 } |
3527 | 3536 |
3528 } // namespace interpreter | 3537 } // namespace interpreter |
3529 } // namespace internal | 3538 } // namespace internal |
3530 } // namespace v8 | 3539 } // namespace v8 |
OLD | NEW |