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 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2038 auto callable = tester.GetCallable<>(); | 2038 auto callable = tester.GetCallable<>(); |
2039 | 2039 |
2040 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2040 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2041 CHECK(return_value->SameValue(*catches[i].second)); | 2041 CHECK(return_value->SameValue(*catches[i].second)); |
2042 } | 2042 } |
2043 } | 2043 } |
2044 | 2044 |
2045 | 2045 |
2046 TEST(InterpreterTryFinally) { | 2046 TEST(InterpreterTryFinally) { |
2047 HandleAndZoneScope handles; | 2047 HandleAndZoneScope handles; |
2048 i::Isolate* isolate = handles.main_isolate(); | |
2049 i::Factory* factory = isolate->factory(); | |
2048 | 2050 |
2049 // TODO(rmcilroy): modify tests when we have real try finally support. | 2051 std::pair<const char*, Handle<Object>> finallies[] = { |
2050 std::string source(InterpreterTester::SourceForBody( | 2052 std::make_pair( |
2051 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); | 2053 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", |
2052 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2054 factory->NewStringFromStaticChars("R4")), |
2053 auto callable = tester.GetCallable<>(); | 2055 std::make_pair( |
2056 "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", | |
2057 factory->NewStringFromStaticChars("R23")), | |
2058 std::make_pair( | |
2059 "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", | |
2060 factory->NewStringFromStaticChars("E23")), | |
2061 std::make_pair( | |
2062 "var a = 1; try { a = 2; throw 23; } finally { return a; };", | |
2063 factory->NewStringFromStaticChars("R2")), | |
2064 std::make_pair( | |
2065 "var a = 1; try { a = 2; throw 23; } finally { throw 42; };", | |
rmcilroy
2016/01/21 14:30:49
Could you add some tests for break / continue as w
Michael Starzinger
2016/01/22 10:18:11
Done.
| |
2066 factory->NewStringFromStaticChars("E42")), | |
2067 }; | |
2054 | 2068 |
2055 Handle<Object> return_val = callable().ToHandleChecked(); | 2069 const char* try_wrapper = |
2056 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); | 2070 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()"; |
2071 | |
2072 for (size_t i = 0; i < arraysize(finallies); i++) { | |
2073 std::string source(InterpreterTester::SourceForBody(finallies[i].first)); | |
2074 InterpreterTester tester(handles.main_isolate(), source.c_str()); | |
2075 tester.GetCallable<>(); | |
2076 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | |
2077 CHECK(wrapped->SameValue(*finallies[i].second)); | |
2078 } | |
2057 } | 2079 } |
2058 | 2080 |
2059 | 2081 |
2060 TEST(InterpreterThrow) { | 2082 TEST(InterpreterThrow) { |
2061 HandleAndZoneScope handles; | 2083 HandleAndZoneScope handles; |
2062 i::Isolate* isolate = handles.main_isolate(); | 2084 i::Isolate* isolate = handles.main_isolate(); |
2063 i::Factory* factory = isolate->factory(); | 2085 i::Factory* factory = isolate->factory(); |
2064 | 2086 |
2065 std::pair<const char*, Handle<Object>> throws[] = { | 2087 std::pair<const char*, Handle<Object>> throws[] = { |
2066 std::make_pair("throw undefined;\n", | 2088 std::make_pair("throw undefined;\n", |
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3530 auto callable = tester.GetCallable<>(); | 3552 auto callable = tester.GetCallable<>(); |
3531 | 3553 |
3532 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3554 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3533 CHECK(return_value->SameValue(*eval_func_decl[i].second)); | 3555 CHECK(return_value->SameValue(*eval_func_decl[i].second)); |
3534 } | 3556 } |
3535 } | 3557 } |
3536 | 3558 |
3537 } // namespace interpreter | 3559 } // namespace interpreter |
3538 } // namespace internal | 3560 } // namespace internal |
3539 } // namespace v8 | 3561 } // namespace v8 |
OLD | NEW |