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..7f6e26ea0625a936f0964c25bb4c7ac3800089a9 100644 |
| --- a/test/cctest/test-code-stub-assembler.cc |
| +++ b/test/cctest/test-code-stub-assembler.cc |
| @@ -1340,5 +1340,126 @@ TEST(TryProbeStubCache) { |
| CHECK(queried_existing && queried_non_existing); |
| } |
| +TEST(GotoIfException) { |
| + 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()); |
| + Variable exception(&m, MachineRepresentation::kTagged); |
| + |
| + Label exception_handler(&m); |
| + Callable to_string = CodeFactory::ToString(isolate); |
| + Node* string = m.CallStub(to_string, context, to_string_tag); |
| + m.GotoIfException(string, &exception_handler, &exception); |
| + m.Return(string); |
| + |
| + m.Bind(&exception_handler); |
| + m.Return(exception.value()); |
| + |
| + 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())); |
| +} |
| + |
| +TEST(GotoIfExceptionMultiple) { |
| + 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); |
| + Label exception_handler2(&m); |
| + Variable return_value(&m, MachineRepresentation::kWord32); |
| + |
| + return_value.Bind(m.Int32Constant(0)); |
| + |
| + Callable to_string = CodeFactory::ToString(isolate); |
| + Node* string = m.CallStub(to_string, context, to_string_tag); |
| + m.GotoIfException(string, &exception_handler); |
| + m.Return(string); |
| + |
| + m.Bind(&exception_handler); |
| + m.DebugBreak(); |
| + return_value.Bind(m.Int32Constant(7)); |
| + |
| + string = m.CallStub(to_string, context, to_string_tag); |
| + m.GotoIfException(string, &exception_handler2); |
|
caitp
2016/08/18 16:59:20
There's something weird with the latest refactorin
|
| + m.Return(m.SmiFromWord32(return_value.value())); |
| + |
| + m.Bind(&exception_handler2); |
| + // Return returnValue & ~2 |
| + m.DebugBreak(); |
| + m.Return(m.SmiFromWord32( |
| + m.Word32And(return_value.value(), |
| + m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1))))); |
| + |
| + Handle<Code> code = m.GenerateCode(); |
| + CHECK(!code.is_null()); |
| + |
| + // Emulate TFJ builtin |
| + code->set_flags(Code::ComputeFlags(Code::BUILTIN)); |
| + |
| + FunctionTester ft(code, 0); |
| + CHECK_EQ(7 & ~2, Smi::cast(*ft.Call().ToHandleChecked())->value()); |
| +} |
| + |
| +TEST(GotoIfExceptionNoException) { |
| + 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* undefined = m.HeapConstant(isolate->factory()->undefined_value()); |
| + Variable exception(&m, MachineRepresentation::kTagged); |
| + |
| + Label exception_handler(&m); |
| + Callable to_string = CodeFactory::ToString(isolate); |
| + Node* string = m.CallRuntime(Runtime::kToString, context, undefined); |
| + m.GotoIfException(string, &exception_handler, &exception); |
| + 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); |
| + Handle<String> result = Handle<String>::cast(ft.Call().ToHandleChecked()); |
| + CHECK(result->IsOneByteEqualTo(OneByteVector("undefined"))); |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |