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

Unified Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1481763002: [Interpreter] Adds support for throw to bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/compiler/test-run-bytecode-graph-builder.cc
diff --git a/test/cctest/compiler/test-run-bytecode-graph-builder.cc b/test/cctest/compiler/test-run-bytecode-graph-builder.cc
index 248ff4b7ea19b4b78044af45b3e51d05f270aa33..bf44c34da03a882056d406f4a9559c3174592852 100644
--- a/test/cctest/compiler/test-run-bytecode-graph-builder.cc
+++ b/test/cctest/compiler/test-run-bytecode-graph-builder.cc
@@ -951,6 +951,42 @@ TEST(BytecodeGraphBuilderTestInstanceOf) {
// TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported.
}
+
+TEST(BytecodeGraphBuilderThrow) {
+ HandleAndZoneScope scope;
+ Isolate* isolate = scope.main_isolate();
+ Zone* zone = scope.main_zone();
+ Factory* factory = isolate->factory();
+
+ // TODO(mythria): modify these tests when real try-catch is supported.
+ ExpectedSnippet<0> snippets[] = {
+ {"throw undefined;", {factory->undefined_value()}},
+ {"throw 1;", {factory->NewNumberFromInt(1)}},
+ {"throw 'Error';", {factory->NewStringFromStaticChars("Error")}},
+ {"throw 'Error1'; throw 'Error2'",
+ {factory->NewStringFromStaticChars("Error1")}},
+ // TODO(mythria): Enable these tests when JumpIfTrue is supported.
+ // {"var a = true; if (a) { throw 'Error'; }",
+ // {factory->NewStringFromStaticChars("Error")}},
+ // {"var a = false; if (a) { throw 'Error'; }",
+ // {factory->undefined_value()}},
+ };
+
+ const char* try_wrapper =
+ "(function() { try { f(); } catch(e) { return e; }})()";
+
+ size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
+ for (size_t i = 0; i < num_snippets; i++) {
+ ScopedVector<char> script(1024);
+ SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
+ snippets[i].code_snippet, kFunctionName);
+ BytecodeGraphTester tester(isolate, zone, script.start());
+ tester.GetCallable<>();
+ Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
Michael Starzinger 2015/11/26 17:27:45 suggestion: We could also use a v8::TryCatch scope
mythria 2015/11/27 14:54:47 Thanks, I changed it to TryCatch scope. Done.
+ CHECK(thrown_obj->SameValue(*snippets[i].return_value()));
+ }
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« src/compiler/bytecode-graph-builder.cc ('K') | « src/compiler/bytecode-graph-builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698