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..9a91305b3b9475f074b643b1c8afbc48bdcd2ab9 100644 |
| --- a/test/cctest/compiler/test-run-bytecode-graph-builder.cc |
| +++ b/test/cctest/compiler/test-run-bytecode-graph-builder.cc |
| @@ -88,6 +88,18 @@ class BytecodeGraphTester { |
| return BytecodeGraphCallable<A...>(isolate_, GetFunction()); |
| } |
| + Local<Message> CheckThrowsReturnMessage() { |
| + TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate_)); |
| + auto callable = GetCallable<>(); |
| + MaybeHandle<Object> no_result = callable(); |
| + CHECK(isolate_->has_pending_exception()); |
| + CHECK(try_catch.HasCaught()); |
| + CHECK(no_result.is_null()); |
| + isolate_->OptionalRescheduleException(true); |
| + CHECK(!try_catch.Message().IsEmpty()); |
| + return try_catch.Message(); |
| + } |
| + |
| static Handle<Object> NewObject(const char* script) { |
| return v8::Utils::OpenHandle(*CompileRun(script)); |
| } |
| @@ -154,16 +166,14 @@ class BytecodeGraphTester { |
| REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__ |
| -template <int N> |
| +template <int N, typename T = Handle<Object>> |
| struct ExpectedSnippet { |
| const char* code_snippet; |
| - Handle<Object> return_value_and_parameters[N + 1]; |
| + T return_value_and_parameters[N + 1]; |
| - inline Handle<Object> return_value() const { |
| - return return_value_and_parameters[0]; |
| - } |
| + inline T return_value() const { return return_value_and_parameters[0]; } |
| - inline Handle<Object> parameter(int i) const { |
| + inline T parameter(int i) const { |
| DCHECK_GE(i, 0); |
| DCHECK_LT(i, N); |
| return return_value_and_parameters[1 + i]; |
| @@ -951,6 +961,39 @@ 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(); |
| + |
| + // TODO(mythria): Add more tests when real try-catch and deoptimization |
| + // information are supported. |
| + ExpectedSnippet<0, const char*> snippets[] = { |
| + {"throw undefined;", {"undefined"}}, |
|
mythria
2015/11/27 14:54:47
I tried to add tests that throw an Error object. i
Michael Starzinger
2015/11/27 15:09:19
Acknowledged. Yes, sounds about right. The constru
|
| + {"throw 1;", {"1"}}, |
| + {"throw 'Error';", {"Error"}}, |
| + {"throw 'Error1'; throw 'Error2'", {"Error1"}}, |
| + // TODO(mythria): Enable these tests when JumpIfTrue is supported. |
| + // {"var a = true; if (a) { throw 'Error'; }", {"Error"}}, |
| + }; |
| + |
| + 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()); |
| + v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
| + std::string str("Uncaught "); |
|
Michael Starzinger
2015/11/27 15:09:19
nit: I would just make the "Uncaught " prefix part
mythria
2015/11/27 15:40:44
Done.
|
| + str += snippets[i].return_value(); |
| + v8::Local<v8::String> expected_string = v8_str(str.c_str()); |
| + CHECK( |
| + message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
| + .FromJust()); |
| + } |
| +} |
| + |
| } // namespace compiler |
| } // namespace internal |
| } // namespace v8 |