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

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: Rebased. 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
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 auto callable = tester.GetCallable<>(); 2041 auto callable = tester.GetCallable<>();
2042 2042
2043 Handle<i::Object> return_value = callable().ToHandleChecked(); 2043 Handle<i::Object> return_value = callable().ToHandleChecked();
2044 CHECK(return_value->SameValue(*catches[i].second)); 2044 CHECK(return_value->SameValue(*catches[i].second));
2045 } 2045 }
2046 } 2046 }
2047 2047
2048 2048
2049 TEST(InterpreterTryFinally) { 2049 TEST(InterpreterTryFinally) {
2050 HandleAndZoneScope handles; 2050 HandleAndZoneScope handles;
2051 i::Isolate* isolate = handles.main_isolate();
2052 i::Factory* factory = isolate->factory();
2051 2053
2052 // TODO(rmcilroy): modify tests when we have real try finally support. 2054 std::pair<const char*, Handle<Object>> finallies[] = {
2053 std::string source(InterpreterTester::SourceForBody( 2055 std::make_pair(
2054 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); 2056 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;",
2055 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2057 factory->NewStringFromStaticChars("R4")),
2056 auto callable = tester.GetCallable<>(); 2058 std::make_pair(
2059 "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;",
2060 factory->NewStringFromStaticChars("R23")),
2061 std::make_pair(
2062 "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;",
2063 factory->NewStringFromStaticChars("E23")),
2064 std::make_pair(
2065 "var a = 1; try { a = 2; throw 23; } finally { return a; };",
2066 factory->NewStringFromStaticChars("R2")),
2067 std::make_pair(
2068 "var a = 1; try { a = 2; throw 23; } finally { throw 42; };",
2069 factory->NewStringFromStaticChars("E42")),
2070 std::make_pair("var a = 1; for (var i = 10; i < 20; i += 5) {"
2071 " try { a = 2; break; } finally { a = 3; }"
2072 "} return a + i;",
2073 factory->NewStringFromStaticChars("R13")),
2074 std::make_pair("var a = 1; for (var i = 10; i < 20; i += 5) {"
2075 " try { a = 2; continue; } finally { a = 3; }"
2076 "} return a + i;",
2077 factory->NewStringFromStaticChars("R23")),
2078 };
2057 2079
2058 Handle<Object> return_val = callable().ToHandleChecked(); 2080 const char* try_wrapper =
2059 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); 2081 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()";
2082
2083 for (size_t i = 0; i < arraysize(finallies); i++) {
2084 std::string source(InterpreterTester::SourceForBody(finallies[i].first));
2085 InterpreterTester tester(handles.main_isolate(), source.c_str());
2086 tester.GetCallable<>();
2087 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
2088 CHECK(wrapped->SameValue(*finallies[i].second));
2089 }
2060 } 2090 }
2061 2091
2062 2092
2063 TEST(InterpreterThrow) { 2093 TEST(InterpreterThrow) {
2064 HandleAndZoneScope handles; 2094 HandleAndZoneScope handles;
2065 i::Isolate* isolate = handles.main_isolate(); 2095 i::Isolate* isolate = handles.main_isolate();
2066 i::Factory* factory = isolate->factory(); 2096 i::Factory* factory = isolate->factory();
2067 2097
2068 std::pair<const char*, Handle<Object>> throws[] = { 2098 std::pair<const char*, Handle<Object>> throws[] = {
2069 std::make_pair("throw undefined;\n", 2099 std::make_pair("throw undefined;\n",
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3533 auto callable = tester.GetCallable<>(); 3563 auto callable = tester.GetCallable<>();
3534 3564
3535 Handle<i::Object> return_value = callable().ToHandleChecked(); 3565 Handle<i::Object> return_value = callable().ToHandleChecked();
3536 CHECK(return_value->SameValue(*eval_func_decl[i].second)); 3566 CHECK(return_value->SameValue(*eval_func_decl[i].second));
3537 } 3567 }
3538 } 3568 }
3539 3569
3540 } // namespace interpreter 3570 } // namespace interpreter
3541 } // namespace internal 3571 } // namespace internal
3542 } // namespace v8 3572 } // namespace v8
OLDNEW
« no previous file with comments | « 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