Chromium Code Reviews| 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 |