Chromium Code Reviews| Index: test/cctest/test-code-stub-assembler.cc |
| diff --git a/test/cctest/test-code-stub-assembler.cc b/test/cctest/test-code-stub-assembler.cc |
| index 597bdfe000ba0d2729ca3a41f4a04a23c9be2f0f..cdb616e46fb9ec4f5285ed10891b43667aff7a5f 100644 |
| --- a/test/cctest/test-code-stub-assembler.cc |
| +++ b/test/cctest/test-code-stub-assembler.cc |
| @@ -1340,5 +1340,77 @@ TEST(TryProbeStubCache) { |
| CHECK(queried_existing && queried_non_existing); |
| } |
| +TEST(BranchIfException) { |
| + typedef CodeStubAssembler::Label Label; |
| + // typedef CodeStubAssembler::Variable Variable; |
| + Isolate* isolate(CcTest::InitIsolateOnce()); |
| + |
| + VoidDescriptor descriptor(isolate); |
| + CodeStubAssemblerTester m(isolate, descriptor); |
| + |
| + Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); |
| + Node* to_string_tag = |
| + m.HeapConstant(isolate->factory()->to_string_tag_symbol()); |
| + |
| + Label exception_handler(&m); |
| + Callable to_string = CodeFactory::ToString(isolate); |
| + Node* string = m.CallStub(to_string, context, to_string_tag); |
| + m.BranchIfException(string, &exception_handler); |
| + m.Return(string); |
| + |
| + m.Bind(&exception_handler); |
| + m.Return(m.SmiConstant(Smi::FromInt(-1))); |
| + |
| + Handle<Code> code = m.GenerateCode(); |
| + CHECK(!code.is_null()); |
| + |
| + // Emulate TFJ builtin |
| + code->set_flags(Code::ComputeFlags(Code::BUILTIN)); |
| + |
| + FunctionTester ft(code, 0); |
| + MaybeHandle<Object> result = ft.Call(); |
| + CHECK_EQ(-1, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
| +} |
| + |
| +TEST(BranchIfException2) { |
| + typedef CodeStubAssembler::Label Label; |
| + // typedef CodeStubAssembler::Variable Variable; |
| + Isolate* isolate(CcTest::InitIsolateOnce()); |
| + |
| + VoidDescriptor descriptor(isolate); |
| + CodeStubAssemblerTester m(isolate, descriptor); |
| + |
| + Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); |
| + Node* to_string_tag = |
| + m.HeapConstant(isolate->factory()->to_string_tag_symbol()); |
| + |
| + Label exception_handler(&m); |
| + Callable to_string = CodeFactory::ToString(isolate); |
| + Node* string = m.CallStub(to_string, context, to_string_tag); |
| + m.BranchIfException(string, &exception_handler); |
| + m.Return(string); |
| + |
| + m.Bind(&exception_handler); |
| + m.Return(string); |
|
caitp
2016/08/18 03:08:57
The fact that this test passes is very surprising
|
| + |
| + Handle<Code> code = m.GenerateCode(); |
| + CHECK(!code.is_null()); |
| + |
| + // Emulate TFJ builtin |
| + code->set_flags(Code::ComputeFlags(Code::BUILTIN)); |
| + |
| + FunctionTester ft(code, 0); |
| + Handle<Object> result = ft.Call().ToHandleChecked(); |
| + |
| + // Should be a TypeError |
| + CHECK(result->IsJSObject()); |
| + |
| + Handle<Object> constructor = |
| + Object::GetPropertyOrElement(result, |
| + isolate->factory()->constructor_string()) |
| + .ToHandleChecked(); |
| + CHECK(constructor->SameValue(*isolate->type_error_function())); |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |