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

Unified 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: Add interpreter tests. 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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index ea28cc95b250f25423b83262d7ddcb0032d59018..f62009523892d0c0f26d3af99765252f00454298 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -2045,15 +2045,37 @@ TEST(InterpreterTryCatch) {
TEST(InterpreterTryFinally) {
HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
- // TODO(rmcilroy): modify tests when we have real try finally support.
- std::string source(InterpreterTester::SourceForBody(
- "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;"));
- InterpreterTester tester(handles.main_isolate(), source.c_str());
- auto callable = tester.GetCallable<>();
+ std::pair<const char*, Handle<Object>> finallies[] = {
+ std::make_pair(
+ "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;",
+ factory->NewStringFromStaticChars("R4")),
+ std::make_pair(
+ "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;",
+ factory->NewStringFromStaticChars("R23")),
+ std::make_pair(
+ "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;",
+ factory->NewStringFromStaticChars("E23")),
+ std::make_pair(
+ "var a = 1; try { a = 2; throw 23; } finally { return a; };",
+ factory->NewStringFromStaticChars("R2")),
+ std::make_pair(
+ "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.
+ factory->NewStringFromStaticChars("E42")),
+ };
- Handle<Object> return_val = callable().ToHandleChecked();
- CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4));
+ const char* try_wrapper =
+ "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()";
+
+ for (size_t i = 0; i < arraysize(finallies); i++) {
+ std::string source(InterpreterTester::SourceForBody(finallies[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ tester.GetCallable<>();
+ Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
+ CHECK(wrapped->SameValue(*finallies[i].second));
+ }
}
« src/interpreter/bytecode-generator.cc ('K') | « src/interpreter/control-flow-builders.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698