OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7511 v8::Isolate* isolate = env->GetIsolate(); | 7511 v8::Isolate* isolate = env->GetIsolate(); |
7512 v8::HandleScope scope(isolate); | 7512 v8::HandleScope scope(isolate); |
7513 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); | 7513 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); |
7514 TerminationThread terminator(isolate); | 7514 TerminationThread terminator(isolate); |
7515 terminator.Start(); | 7515 terminator.Start(); |
7516 v8::TryCatch try_catch; | 7516 v8::TryCatch try_catch; |
7517 v8::Debug::DebugBreak(isolate); | 7517 v8::Debug::DebugBreak(isolate); |
7518 CompileRun("while (true);"); | 7518 CompileRun("while (true);"); |
7519 CHECK(try_catch.HasTerminated()); | 7519 CHECK(try_catch.HasTerminated()); |
7520 } | 7520 } |
| 7521 |
| 7522 |
| 7523 static void DebugEventExpectNoException( |
| 7524 const v8::Debug::EventDetails& event_details) { |
| 7525 v8::DebugEvent event = event_details.GetEvent(); |
| 7526 CHECK_NE(v8::Exception, event); |
| 7527 } |
| 7528 |
| 7529 |
| 7530 static void TryCatchWrappedThrowCallback( |
| 7531 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 7532 v8::TryCatch try_catch; |
| 7533 CompileRun("throw 'rejection';"); |
| 7534 CHECK(try_catch.HasCaught()); |
| 7535 } |
| 7536 |
| 7537 |
| 7538 TEST(DebugPromiseInterceptedByTryCatch) { |
| 7539 DebugLocalContext env; |
| 7540 v8::Isolate* isolate = env->GetIsolate(); |
| 7541 v8::HandleScope scope(isolate); |
| 7542 v8::Debug::SetDebugEventListener(&DebugEventExpectNoException); |
| 7543 ChangeBreakOnException(false, true); |
| 7544 |
| 7545 v8::Handle<v8::FunctionTemplate> fun = |
| 7546 v8::FunctionTemplate::New(isolate, TryCatchWrappedThrowCallback); |
| 7547 env->Global()->Set(v8_str("fun"), fun->GetFunction()); |
| 7548 |
| 7549 CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });"); |
| 7550 CompileRun( |
| 7551 "var r;" |
| 7552 "p.chain(function() { r = 'resolved'; }," |
| 7553 " function() { r = 'rejected'; });"); |
| 7554 CHECK(CompileRun("r")->Equals(v8_str("resolved"))); |
| 7555 } |
| 7556 |
| 7557 |
| 7558 static int exception_event_counter = 0; |
| 7559 |
| 7560 |
| 7561 static void DebugEventCountException( |
| 7562 const v8::Debug::EventDetails& event_details) { |
| 7563 v8::DebugEvent event = event_details.GetEvent(); |
| 7564 if (event == v8::Exception) exception_event_counter++; |
| 7565 } |
| 7566 |
| 7567 |
| 7568 static void ThrowCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 7569 CompileRun("throw 'rejection';"); |
| 7570 } |
| 7571 |
| 7572 |
| 7573 TEST(DebugPromiseRejectedByCallback) { |
| 7574 DebugLocalContext env; |
| 7575 v8::Isolate* isolate = env->GetIsolate(); |
| 7576 v8::HandleScope scope(isolate); |
| 7577 v8::Debug::SetDebugEventListener(&DebugEventCountException); |
| 7578 ChangeBreakOnException(false, true); |
| 7579 exception_event_counter = 0; |
| 7580 |
| 7581 v8::Handle<v8::FunctionTemplate> fun = |
| 7582 v8::FunctionTemplate::New(isolate, ThrowCallback); |
| 7583 env->Global()->Set(v8_str("fun"), fun->GetFunction()); |
| 7584 |
| 7585 CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });"); |
| 7586 CompileRun( |
| 7587 "var r;" |
| 7588 "p.chain(function() { r = 'resolved'; }," |
| 7589 " function(e) { r = 'rejected' + e; });"); |
| 7590 CHECK(CompileRun("r")->Equals(v8_str("rejectedrejection"))); |
| 7591 CHECK_EQ(1, exception_event_counter); |
| 7592 } |
OLD | NEW |