Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "crypto/random.h" | 10 #include "crypto/random.h" |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 bool DartController::vmIsInitialized = false; | 364 bool DartController::vmIsInitialized = false; |
| 365 void DartController::InitVmIfNeeded(Dart_EntropySource entropy, | 365 void DartController::InitVmIfNeeded(Dart_EntropySource entropy, |
| 366 const char** arguments, | 366 const char** arguments, |
| 367 int arguments_count) { | 367 int arguments_count) { |
| 368 // TODO(zra): If runDartScript can be called from multiple threads | 368 // TODO(zra): If runDartScript can be called from multiple threads |
| 369 // concurrently, then vmIsInitialized will need to be protected by a lock. | 369 // concurrently, then vmIsInitialized will need to be protected by a lock. |
| 370 if (vmIsInitialized) { | 370 if (vmIsInitialized) { |
| 371 return; | 371 return; |
| 372 } | 372 } |
| 373 | 373 |
| 374 const int kNumArgs = arguments_count + 1; | 374 const int kNumArgs = arguments_count + 2; |
| 375 const char* args[kNumArgs]; | 375 const char* args[kNumArgs]; |
| 376 | 376 |
| 377 // TODO(zra): Fix Dart VM Shutdown race. | 377 // TODO(zra): Fix Dart VM Shutdown race. |
| 378 // There is a bug in Dart VM shutdown which causes its thread pool threads | 378 // There is a bug in Dart VM shutdown which causes its thread pool threads |
| 379 // to potentially fail to exit when the rest of the VM is going down. This | 379 // to potentially fail to exit when the rest of the VM is going down. This |
| 380 // results in a segfault if they begin running again after the Dart | 380 // results in a segfault if they begin running again after the Dart |
| 381 // embedder has been unloaded. Setting this flag to 0 ensures that these | 381 // embedder has been unloaded. Setting this flag to 0 ensures that these |
| 382 // threads sleep forever instead of waking up and trying to run code | 382 // threads sleep forever instead of waking up and trying to run code |
| 383 // that isn't there anymore. | 383 // that isn't there anymore. |
| 384 args[0] = "--worker-timeout-millis=0"; | 384 args[0] = "--worker-timeout-millis=0"; |
| 385 | 385 |
| 386 args[1] = "--print-stacktrace-at-throw"; | |
| 387 | |
| 386 for (int i = 0; i < arguments_count; ++i) { | 388 for (int i = 0; i < arguments_count; ++i) { |
| 387 args[i + 1] = arguments[i]; | 389 args[i + 2] = arguments[i]; |
| 388 } | 390 } |
| 389 | 391 |
| 390 bool result = Dart_SetVMFlags(kNumArgs, args); | 392 bool result = Dart_SetVMFlags(kNumArgs, args); |
| 391 CHECK(result); | 393 CHECK(result); |
| 392 | 394 |
| 393 result = Dart_Initialize(IsolateCreateCallback, | 395 result = Dart_Initialize(IsolateCreateCallback, |
| 394 nullptr, // Isolate interrupt callback. | 396 nullptr, // Isolate interrupt callback. |
| 395 UnhandledExceptionCallback, | 397 UnhandledExceptionCallback, |
| 396 IsolateShutdownCallback, | 398 IsolateShutdownCallback, |
| 397 // File IO callbacks. | 399 // File IO callbacks. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 413 config.package_root, | 415 config.package_root, |
| 414 config.error); | 416 config.error); |
| 415 if (isolate == nullptr) { | 417 if (isolate == nullptr) { |
| 416 return false; | 418 return false; |
| 417 } | 419 } |
| 418 | 420 |
| 419 Dart_EnterIsolate(isolate); | 421 Dart_EnterIsolate(isolate); |
| 420 Dart_Handle result; | 422 Dart_Handle result; |
| 421 Dart_EnterScope(); | 423 Dart_EnterScope(); |
| 422 | 424 |
| 423 Dart_Handle root_lib = Dart_RootLibrary(); | 425 // Start the MojoHandleWatcher. |
| 424 DART_CHECK_VALID(root_lib); | |
| 425 | |
| 426 Dart_Handle builtin_lib = | |
| 427 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 428 DART_CHECK_VALID(builtin_lib); | |
| 429 Dart_Handle mojo_core_lib = | 426 Dart_Handle mojo_core_lib = |
| 430 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); | 427 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); |
| 431 DART_CHECK_VALID(mojo_core_lib); | 428 DART_CHECK_VALID(mojo_core_lib); |
| 432 | |
| 433 // Start the MojoHandleWatcher. | |
| 434 Dart_Handle handle_watcher_type = Dart_GetType( | 429 Dart_Handle handle_watcher_type = Dart_GetType( |
| 435 mojo_core_lib, | 430 mojo_core_lib, |
| 436 Dart_NewStringFromCString("MojoHandleWatcher"), | 431 Dart_NewStringFromCString("MojoHandleWatcher"), |
| 437 0, | 432 0, |
| 438 nullptr); | 433 nullptr); |
| 439 DART_CHECK_VALID(handle_watcher_type); | 434 DART_CHECK_VALID(handle_watcher_type); |
| 440 result = Dart_Invoke( | 435 result = Dart_Invoke( |
| 441 handle_watcher_type, | 436 handle_watcher_type, |
| 442 Dart_NewStringFromCString("Start"), | 437 Dart_NewStringFromCString("Start"), |
| 443 0, | 438 0, |
| 444 nullptr); | 439 nullptr); |
| 445 DART_CHECK_VALID(result); | 440 DART_CHECK_VALID(result); |
| 446 | 441 |
| 447 // RunLoop until the handle watcher isolate is spun-up. | 442 // RunLoop until the handle watcher isolate is spun-up. |
| 448 result = Dart_RunLoop(); | 443 result = Dart_RunLoop(); |
| 449 DART_CHECK_VALID(result); | 444 DART_CHECK_VALID(result); |
| 450 | 445 |
| 446 // Load the root library into the builtin library so that main can be found. | |
| 447 Dart_Handle builtin_lib = | |
| 448 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
| 449 DART_CHECK_VALID(builtin_lib); | |
| 450 Dart_Handle root_lib = Dart_RootLibrary(); | |
| 451 DART_CHECK_VALID(root_lib); | |
| 451 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); | 452 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); |
| 452 DART_CHECK_VALID(result); | 453 DART_CHECK_VALID(result); |
| 453 | 454 |
| 454 if (config.compile_all) { | 455 if (config.compile_all) { |
| 455 result = Dart_CompileAll(); | 456 result = Dart_CompileAll(); |
| 456 DART_CHECK_VALID(result); | 457 DART_CHECK_VALID(result); |
| 457 } | 458 } |
| 458 | 459 |
| 459 Dart_Handle main_closure = Dart_Invoke( | 460 Dart_Handle main_closure = Dart_Invoke( |
| 460 builtin_lib, | 461 builtin_lib, |
| 461 Dart_NewStringFromCString("_getMainClosure"), | 462 Dart_NewStringFromCString("_getMainClosure"), |
| 462 0, | 463 0, |
| 463 nullptr); | 464 nullptr); |
| 464 DART_CHECK_VALID(main_closure); | 465 DART_CHECK_VALID(main_closure); |
| 465 | 466 |
| 466 // Call _startIsolate in the isolate library to enable dispatching the | 467 // Call _startIsolate in the isolate library to enable dispatching the |
| 467 // initial startup message. | 468 // initial startup message. |
| 468 const intptr_t kNumIsolateArgs = 2; | 469 const intptr_t kNumIsolateArgs = 2; |
| 469 Dart_Handle isolate_args[kNumIsolateArgs]; | 470 Dart_Handle isolate_args[kNumIsolateArgs]; |
| 470 isolate_args[0] = main_closure; // entryPoint | 471 isolate_args[0] = main_closure; // entryPoint |
| 471 isolate_args[1] = Dart_NewList(1); // args | 472 isolate_args[1] = Dart_NewList(2); // args |
| 472 DART_CHECK_VALID(isolate_args[1]); | 473 DART_CHECK_VALID(isolate_args[1]); |
| 474 | |
| 475 Dart_Handle script_uri = Dart_NewStringFromUTF8( | |
| 476 reinterpret_cast<const uint8_t*>(config.script_uri.data()), | |
| 477 config.script_uri.length()); | |
| 473 Dart_ListSetAt(isolate_args[1], 0, Dart_NewInteger(config.handle)); | 478 Dart_ListSetAt(isolate_args[1], 0, Dart_NewInteger(config.handle)); |
| 479 Dart_ListSetAt(isolate_args[1], 1, script_uri); | |
|
abarth-chromium
2015/01/16 05:43:43
We need a better way to solve this problem, but th
zra
2015/01/16 17:54:51
Acknowledged.
| |
| 474 | 480 |
| 475 Dart_Handle isolate_lib = | 481 Dart_Handle isolate_lib = |
| 476 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); | 482 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); |
| 477 DART_CHECK_VALID(isolate_lib); | 483 DART_CHECK_VALID(isolate_lib); |
| 478 | 484 |
| 479 result = Dart_Invoke(isolate_lib, | 485 result = Dart_Invoke(isolate_lib, |
| 480 Dart_NewStringFromCString("_startMainIsolate"), | 486 Dart_NewStringFromCString("_startMainIsolate"), |
| 481 kNumIsolateArgs, | 487 kNumIsolateArgs, |
| 482 isolate_args); | 488 isolate_args); |
| 483 DART_CHECK_VALID(result); | 489 DART_CHECK_VALID(result); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 497 DART_CHECK_VALID(result); | 503 DART_CHECK_VALID(result); |
| 498 | 504 |
| 499 Dart_ExitScope(); | 505 Dart_ExitScope(); |
| 500 Dart_ShutdownIsolate(); | 506 Dart_ShutdownIsolate(); |
| 501 Dart_Cleanup(); | 507 Dart_Cleanup(); |
| 502 return true; | 508 return true; |
| 503 } | 509 } |
| 504 | 510 |
| 505 } // namespace apps | 511 } // namespace apps |
| 506 } // namespace mojo | 512 } // namespace mojo |
| OLD | NEW |