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

Unified Diff: tonic/dart_message_handler.cc

Issue 1688793002: Fix shutdown race when running Dart on the message loop (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « tonic/dart_message_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tonic/dart_message_handler.cc
diff --git a/tonic/dart_message_handler.cc b/tonic/dart_message_handler.cc
index 60cd5028705661eef40d3e938ee532085b584b54..85565e6f7bf9839bd486aa4e07ccb3a2a73cfaa9 100644
--- a/tonic/dart_message_handler.cc
+++ b/tonic/dart_message_handler.cc
@@ -15,6 +15,9 @@ namespace tonic {
DartMessageHandler::DartMessageHandler()
: handled_first_message_(false),
+ quit_message_loop_when_isolate_exits_(true),
+ isolate_exited_(false),
+ isolate_had_uncaught_exception_error_(false),
task_runner_(nullptr) {
}
@@ -43,6 +46,8 @@ void DartMessageHandler::OnHandleMessage(DartState* dart_state) {
DartIsolateScope scope(dart_state->isolate());
DartApiScope dart_api_scope;
+ bool error = false;
+
// On the first message, check if we should pause on isolate start.
if (!handled_first_message()) {
set_handled_first_message(true);
@@ -62,7 +67,7 @@ void DartMessageHandler::OnHandleMessage(DartState* dart_state) {
}
Dart_SetPausedOnStart(false);
// We've resumed, handle *all* normal messages that are in the queue.
- LogIfError(Dart_HandleMessages());
+ error = LogIfError(Dart_HandleMessages());
}
} else if (Dart_IsPausedOnExit()) {
// We are paused on isolate exit. Only handle service messages until we are
@@ -76,17 +81,25 @@ void DartMessageHandler::OnHandleMessage(DartState* dart_state) {
}
} else {
// We are processing messages normally.
- LogIfError(Dart_HandleMessage());
+ error = LogIfError(Dart_HandleMessage());
+ }
+
+ if (error) {
+ // Remember that we had an uncaught exception error.
+ isolate_had_uncaught_exception_error_ = true;
}
- if (!Dart_HasLivePorts()) {
+ if (error || !Dart_HasLivePorts()) {
// The isolate has no live ports and would like to exit.
if (Dart_ShouldPauseOnExit()) {
// Mark that we are paused on exit.
Dart_SetPausedOnExit(true);
} else {
- // Quit.
- base::MessageLoop::current()->QuitWhenIdle();
+ isolate_exited_ = true;
+ if (quit_message_loop_when_isolate_exits()) {
+ // Quit.
+ base::MessageLoop::current()->QuitWhenIdle();
+ }
}
}
}
« no previous file with comments | « tonic/dart_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698