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

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: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | mojo/dart/embedder/mojo_dart_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); 252 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL));
253 DART_CHECK_VALID(isolate_lib); 253 DART_CHECK_VALID(isolate_lib);
254 254
255 result = Dart_Invoke(isolate_lib, 255 result = Dart_Invoke(isolate_lib,
256 Dart_NewStringFromCString("_startMainIsolate"), 256 Dart_NewStringFromCString("_startMainIsolate"),
257 kStartIsolateArgumentsLength, 257 kStartIsolateArgumentsLength,
258 start_isolate_args); 258 start_isolate_args);
259 DART_CHECK_VALID(result); 259 DART_CHECK_VALID(result);
260 260
261 result = Dart_RunLoop(); 261 result = Dart_RunLoop();
262
263 // Here we log the error, but we don't do DART_CHECK_VALID because we don't
264 // want to bring the whole process down due to an error in application code,
265 // whereas above we do want to bring the whole process down for a bug in
266 // library or generated code.
262 tonic::LogIfError(result); 267 tonic::LogIfError(result);
263 DART_CHECK_VALID(result);
264 } 268 }
265 269
266 Dart_Handle DartController::LibraryTagHandler(Dart_LibraryTag tag, 270 Dart_Handle DartController::LibraryTagHandler(Dart_LibraryTag tag,
267 Dart_Handle library, 271 Dart_Handle library,
268 Dart_Handle url) { 272 Dart_Handle url) {
269 if (tag == Dart_kCanonicalizeUrl) { 273 if (tag == Dart_kCanonicalizeUrl) {
270 std::string string = tonic::StdStringFromDart(url); 274 std::string string = tonic::StdStringFromDart(url);
271 if (StartsWithASCII(string, "dart:", true)) 275 if (StartsWithASCII(string, "dart:", true))
272 return url; 276 return url;
273 } 277 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 { 442 {
439 tonic::DartApiScope api_scope; 443 tonic::DartApiScope api_scope;
440 ShutdownDartMojoIo(); 444 ShutdownDartMojoIo();
441 } 445 }
442 446
443 auto isolate_data = MojoDartState::Cast(callback_data); 447 auto isolate_data = MojoDartState::Cast(callback_data);
444 delete isolate_data; 448 delete isolate_data;
445 } 449 }
446 450
447 void DartController::UnhandledExceptionCallback(Dart_Handle error) { 451 void DartController::UnhandledExceptionCallback(Dart_Handle error) {
452 Dart_Handle mojo_core_lib =
453 Builtin::GetLibrary(Builtin::kMojoInternalLibrary);
454 DART_CHECK_VALID(mojo_core_lib);
455 Dart_Handle handle_natives_type =
456 Dart_GetType(mojo_core_lib,
457 Dart_NewStringFromCString("MojoHandleNatives"), 0, nullptr);
458 DART_CHECK_VALID(handle_natives_type);
459 Dart_Handle method_name = Dart_NewStringFromCString("_closeUnclosedHandles");
460 CHECK(!Dart_IsError(method_name));
461 Dart_Handle result =
462 Dart_Invoke(handle_natives_type, method_name, 0, nullptr);
463 DART_CHECK_VALID(result);
464
448 auto isolate_data = MojoDartState::Current(); 465 auto isolate_data = MojoDartState::Current();
449 if (!isolate_data->callbacks().exception.is_null()) { 466 if (!isolate_data->callbacks().exception.is_null()) {
450 // TODO(zra): Instead of passing an error handle, it may make life easier 467 int64_t handles_closed = 0;
451 // for clients if we pass any error string here instead. 468 Dart_Handle int_result = Dart_IntegerToInt64(result, &handles_closed);
452 isolate_data->callbacks().exception.Run(error); 469 DART_CHECK_VALID(int_result);
470 isolate_data->callbacks().exception.Run(error, handles_closed);
453 } 471 }
454
455 // Close handles generated by the isolate.
456 std::set<MojoHandle>& handles = isolate_data->unclosed_handles();
457 for (auto it = handles.begin(); it != handles.end(); ++it) {
458 MojoClose((*it));
459 }
460 handles.clear();
461 } 472 }
462 473
463 474
464 bool DartController::initialized_ = false; 475 bool DartController::initialized_ = false;
465 bool DartController::service_isolate_running_ = false; 476 bool DartController::service_isolate_running_ = false;
466 bool DartController::service_isolate_spawned_ = false; 477 bool DartController::service_isolate_spawned_ = false;
467 bool DartController::strict_compilation_ = false; 478 bool DartController::strict_compilation_ = false;
468 DartControllerServiceConnector* DartController::service_connector_ = nullptr; 479 DartControllerServiceConnector* DartController::service_connector_ = nullptr;
469 base::Lock DartController::lock_; 480 base::Lock DartController::lock_;
470 481
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 769 }
759 BlockForServiceIsolateLocked(); 770 BlockForServiceIsolateLocked();
760 StopHandleWatcherIsolate(); 771 StopHandleWatcherIsolate();
761 Dart_Cleanup(); 772 Dart_Cleanup();
762 service_isolate_running_ = false; 773 service_isolate_running_ = false;
763 initialized_ = false; 774 initialized_ = false;
764 } 775 }
765 776
766 } // namespace apps 777 } // namespace apps
767 } // namespace mojo 778 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/dart/embedder/mojo_dart_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698