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

Side by Side Diff: mojo/dart/embedder/dart_controller.cc

Issue 1411843005: Dart: Removes C++ set for closing handles on an unhandled exception. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Format Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); 251 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL));
252 DART_CHECK_VALID(isolate_lib); 252 DART_CHECK_VALID(isolate_lib);
253 253
254 result = Dart_Invoke(isolate_lib, 254 result = Dart_Invoke(isolate_lib,
255 Dart_NewStringFromCString("_startMainIsolate"), 255 Dart_NewStringFromCString("_startMainIsolate"),
256 kStartIsolateArgumentsLength, 256 kStartIsolateArgumentsLength,
257 start_isolate_args); 257 start_isolate_args);
258 DART_CHECK_VALID(result); 258 DART_CHECK_VALID(result);
259 259
260 result = Dart_RunLoop(); 260 result = Dart_RunLoop();
261
262 // Here we log the error, but we don't do DART_CHECK_VALID because we don't
263 // want to bring the whole process down due to an error in application code,
264 // whereas above we do want to bring the whole process down for a bug in
265 // library or generated code.
261 tonic::LogIfError(result); 266 tonic::LogIfError(result);
262 DART_CHECK_VALID(result);
263 } 267 }
264 268
265 Dart_Handle DartController::LibraryTagHandler(Dart_LibraryTag tag, 269 Dart_Handle DartController::LibraryTagHandler(Dart_LibraryTag tag,
266 Dart_Handle library, 270 Dart_Handle library,
267 Dart_Handle url) { 271 Dart_Handle url) {
268 if (tag == Dart_kCanonicalizeUrl) { 272 if (tag == Dart_kCanonicalizeUrl) {
269 std::string string = tonic::StdStringFromDart(url); 273 std::string string = tonic::StdStringFromDart(url);
270 if (StartsWithASCII(string, "dart:", true)) 274 if (StartsWithASCII(string, "dart:", true))
271 return url; 275 return url;
272 } 276 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 { 441 {
438 tonic::DartApiScope api_scope; 442 tonic::DartApiScope api_scope;
439 ShutdownDartMojoIo(); 443 ShutdownDartMojoIo();
440 } 444 }
441 445
442 auto isolate_data = MojoDartState::Cast(callback_data); 446 auto isolate_data = MojoDartState::Cast(callback_data);
443 delete isolate_data; 447 delete isolate_data;
444 } 448 }
445 449
446 void DartController::UnhandledExceptionCallback(Dart_Handle error) { 450 void DartController::UnhandledExceptionCallback(Dart_Handle error) {
451 Dart_Handle mojo_core_lib =
452 Builtin::GetLibrary(Builtin::kMojoInternalLibrary);
453 DART_CHECK_VALID(mojo_core_lib);
454 Dart_Handle handle_natives_type =
455 Dart_GetType(mojo_core_lib,
456 Dart_NewStringFromCString("MojoHandleNatives"), 0, nullptr);
457 DART_CHECK_VALID(handle_natives_type);
458 Dart_Handle method_name = Dart_NewStringFromCString("_closeUnclosedHandles");
459 CHECK(!Dart_IsError(method_name));
460 Dart_Handle result =
461 Dart_Invoke(handle_natives_type, method_name, 0, nullptr);
462 DART_CHECK_VALID(result);
463
447 auto isolate_data = MojoDartState::Current(); 464 auto isolate_data = MojoDartState::Current();
448 if (!isolate_data->callbacks().exception.is_null()) { 465 if (!isolate_data->callbacks().exception.is_null()) {
466 int64_t handles_closed = 0;
467 Dart_Handle int_result = Dart_IntegerToInt64(result, &handles_closed);
468 DART_CHECK_VALID(int_result);
469
449 // TODO(zra): Instead of passing an error handle, it may make life easier 470 // TODO(zra): Instead of passing an error handle, it may make life easier
Cutch 2015/10/26 17:10:03 Is this TODO still relevant?
zra 2015/10/26 17:53:54 No. Removed.
450 // for clients if we pass any error string here instead. 471 // for clients if we pass any error string here instead.
451 isolate_data->callbacks().exception.Run(error); 472 isolate_data->callbacks().exception.Run(error, handles_closed);
452 } 473 }
453
454 // Close handles generated by the isolate.
455 std::set<MojoHandle>& handles = isolate_data->unclosed_handles();
456 for (auto it = handles.begin(); it != handles.end(); ++it) {
457 MojoClose((*it));
458 }
459 handles.clear();
460 } 474 }
461 475
462 476
463 bool DartController::initialized_ = false; 477 bool DartController::initialized_ = false;
464 bool DartController::service_isolate_running_ = false; 478 bool DartController::service_isolate_running_ = false;
465 bool DartController::service_isolate_spawned_ = false; 479 bool DartController::service_isolate_spawned_ = false;
466 bool DartController::strict_compilation_ = false; 480 bool DartController::strict_compilation_ = false;
467 DartControllerServiceConnector* DartController::service_connector_ = nullptr; 481 DartControllerServiceConnector* DartController::service_connector_ = nullptr;
468 base::Lock DartController::lock_; 482 base::Lock DartController::lock_;
469 483
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 742 }
729 BlockForServiceIsolateLocked(); 743 BlockForServiceIsolateLocked();
730 StopHandleWatcherIsolate(); 744 StopHandleWatcherIsolate();
731 Dart_Cleanup(); 745 Dart_Cleanup();
732 service_isolate_running_ = false; 746 service_isolate_running_ = false;
733 initialized_ = false; 747 initialized_ = false;
734 } 748 }
735 749
736 } // namespace apps 750 } // namespace apps
737 } // namespace mojo 751 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/dart/embedder/mojo_dart_state.h » ('j') | mojo/dart/embedder/test/run_dart_tests.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698