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

Unified Diff: test/cctest/test-debug.cc

Issue 607913002: Report promise reject with no handler (behind a flag). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: more comments Created 6 years, 3 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
« no previous file with comments | « test/cctest/test-api.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-debug.cc
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index 2f0674a34d98b94c6183ad10ed7ed4347c4c02ff..adf9ba99b2db880d32d7104c081ca580dbc35abd 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -7518,3 +7518,75 @@ TEST(DebugBreakOffThreadTerminate) {
CompileRun("while (true);");
CHECK(try_catch.HasTerminated());
}
+
+
+static void DebugEventExpectNoException(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ CHECK_NE(v8::Exception, event);
+}
+
+
+static void TryCatchWrappedThrowCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::TryCatch try_catch;
+ CompileRun("throw 'rejection';");
+ CHECK(try_catch.HasCaught());
+}
+
+
+TEST(DebugPromiseInterceptedByTryCatch) {
+ DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Debug::SetDebugEventListener(&DebugEventExpectNoException);
+ ChangeBreakOnException(false, true);
+
+ v8::Handle<v8::FunctionTemplate> fun =
+ v8::FunctionTemplate::New(isolate, TryCatchWrappedThrowCallback);
+ env->Global()->Set(v8_str("fun"), fun->GetFunction());
+
+ CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });");
+ CompileRun(
+ "var r;"
+ "p.chain(function() { r = 'resolved'; },"
+ " function() { r = 'rejected'; });");
+ CHECK(CompileRun("r")->Equals(v8_str("resolved")));
+}
+
+
+static int exception_event_counter = 0;
+
+
+static void DebugEventCountException(
+ const v8::Debug::EventDetails& event_details) {
+ v8::DebugEvent event = event_details.GetEvent();
+ if (event == v8::Exception) exception_event_counter++;
+}
+
+
+static void ThrowCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CompileRun("throw 'rejection';");
+}
+
+
+TEST(DebugPromiseRejectedByCallback) {
+ DebugLocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+ v8::Debug::SetDebugEventListener(&DebugEventCountException);
+ ChangeBreakOnException(false, true);
+ exception_event_counter = 0;
+
+ v8::Handle<v8::FunctionTemplate> fun =
+ v8::FunctionTemplate::New(isolate, ThrowCallback);
+ env->Global()->Set(v8_str("fun"), fun->GetFunction());
+
+ CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });");
+ CompileRun(
+ "var r;"
+ "p.chain(function() { r = 'resolved'; },"
+ " function(e) { r = 'rejected' + e; });");
+ CHECK(CompileRun("r")->Equals(v8_str("rejectedrejection")));
+ CHECK_EQ(1, exception_event_counter);
+}
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698