Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1613443002: [interpreter] Implement handling of try-finally constructs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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; };",
2066 factory->NewStringFromStaticChars("E42")),
2067 std::make_pair("var a = 1; for (var i = 10; i < 20; i += 5) {"
2068 " try { a = 2; break; } finally { a = 3; }"
2069 "} return a + i;",
2070 factory->NewStringFromStaticChars("R13")),
2071 std::make_pair("var a = 1; for (var i = 10; i < 20; i += 5) {"
2072 " try { a = 2; continue; } finally { a = 3; }"
2073 "} return a + i;",
2074 factory->NewStringFromStaticChars("R23")),
2075 };
2054 2076
2055 Handle<Object> return_val = callable().ToHandleChecked(); 2077 const char* try_wrapper =
2056 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); 2078 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()";
2079
2080 for (size_t i = 0; i < arraysize(finallies); i++) {
2081 std::string source(InterpreterTester::SourceForBody(finallies[i].first));
2082 InterpreterTester tester(handles.main_isolate(), source.c_str());
2083 tester.GetCallable<>();
2084 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
2085 CHECK(wrapped->SameValue(*finallies[i].second));
2086 }
2057 } 2087 }
2058 2088
2059 2089
2060 TEST(InterpreterThrow) { 2090 TEST(InterpreterThrow) {
2061 HandleAndZoneScope handles; 2091 HandleAndZoneScope handles;
2062 i::Isolate* isolate = handles.main_isolate(); 2092 i::Isolate* isolate = handles.main_isolate();
2063 i::Factory* factory = isolate->factory(); 2093 i::Factory* factory = isolate->factory();
2064 2094
2065 std::pair<const char*, Handle<Object>> throws[] = { 2095 std::pair<const char*, Handle<Object>> throws[] = {
2066 std::make_pair("throw undefined;\n", 2096 std::make_pair("throw undefined;\n",
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3530 auto callable = tester.GetCallable<>(); 3560 auto callable = tester.GetCallable<>();
3531 3561
3532 Handle<i::Object> return_value = callable().ToHandleChecked(); 3562 Handle<i::Object> return_value = callable().ToHandleChecked();
3533 CHECK(return_value->SameValue(*eval_func_decl[i].second)); 3563 CHECK(return_value->SameValue(*eval_func_decl[i].second));
3534 } 3564 }
3535 } 3565 }
3536 3566
3537 } // namespace interpreter 3567 } // namespace interpreter
3538 } // namespace internal 3568 } // namespace internal
3539 } // namespace v8 3569 } // namespace v8
OLDNEW
« src/interpreter/bytecode-generator.cc ('K') | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698