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

Unified Diff: test/cctest/test-code-stub-assembler.cc

Issue 2247353005: [builtins] support exception handling in TFJ builtins (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months 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
« src/isolate.cc ('K') | « src/isolate.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« src/isolate.cc ('K') | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698