| 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 // Stacktraces for exceptions thrown during await statements are NYI. |
| 387 // TODO(zra): Remove this flag when fixed. |
| 388 args[1] = "--print-stacktrace-at-throw"; |
| 389 |
| 386 for (int i = 0; i < arguments_count; ++i) { | 390 for (int i = 0; i < arguments_count; ++i) { |
| 387 args[i + 1] = arguments[i]; | 391 args[i + 2] = arguments[i]; |
| 388 } | 392 } |
| 389 | 393 |
| 390 bool result = Dart_SetVMFlags(kNumArgs, args); | 394 bool result = Dart_SetVMFlags(kNumArgs, args); |
| 391 CHECK(result); | 395 CHECK(result); |
| 392 | 396 |
| 393 result = Dart_Initialize(IsolateCreateCallback, | 397 result = Dart_Initialize(IsolateCreateCallback, |
| 394 nullptr, // Isolate interrupt callback. | 398 nullptr, // Isolate interrupt callback. |
| 395 UnhandledExceptionCallback, | 399 UnhandledExceptionCallback, |
| 396 IsolateShutdownCallback, | 400 IsolateShutdownCallback, |
| 397 // File IO callbacks. | 401 // File IO callbacks. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 413 config.package_root, | 417 config.package_root, |
| 414 config.error); | 418 config.error); |
| 415 if (isolate == nullptr) { | 419 if (isolate == nullptr) { |
| 416 return false; | 420 return false; |
| 417 } | 421 } |
| 418 | 422 |
| 419 Dart_EnterIsolate(isolate); | 423 Dart_EnterIsolate(isolate); |
| 420 Dart_Handle result; | 424 Dart_Handle result; |
| 421 Dart_EnterScope(); | 425 Dart_EnterScope(); |
| 422 | 426 |
| 423 Dart_Handle root_lib = Dart_RootLibrary(); | 427 // 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 = | 428 Dart_Handle mojo_core_lib = |
| 430 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); | 429 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); |
| 431 DART_CHECK_VALID(mojo_core_lib); | 430 DART_CHECK_VALID(mojo_core_lib); |
| 432 | |
| 433 // Start the MojoHandleWatcher. | |
| 434 Dart_Handle handle_watcher_type = Dart_GetType( | 431 Dart_Handle handle_watcher_type = Dart_GetType( |
| 435 mojo_core_lib, | 432 mojo_core_lib, |
| 436 Dart_NewStringFromCString("MojoHandleWatcher"), | 433 Dart_NewStringFromCString("MojoHandleWatcher"), |
| 437 0, | 434 0, |
| 438 nullptr); | 435 nullptr); |
| 439 DART_CHECK_VALID(handle_watcher_type); | 436 DART_CHECK_VALID(handle_watcher_type); |
| 440 result = Dart_Invoke( | 437 result = Dart_Invoke( |
| 441 handle_watcher_type, | 438 handle_watcher_type, |
| 442 Dart_NewStringFromCString("Start"), | 439 Dart_NewStringFromCString("Start"), |
| 443 0, | 440 0, |
| 444 nullptr); | 441 nullptr); |
| 445 DART_CHECK_VALID(result); | 442 DART_CHECK_VALID(result); |
| 446 | 443 |
| 447 // RunLoop until the handle watcher isolate is spun-up. | 444 // RunLoop until the handle watcher isolate is spun-up. |
| 448 result = Dart_RunLoop(); | 445 result = Dart_RunLoop(); |
| 449 DART_CHECK_VALID(result); | 446 DART_CHECK_VALID(result); |
| 450 | 447 |
| 448 // Load the root library into the builtin library so that main can be found. |
| 449 Dart_Handle builtin_lib = |
| 450 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 451 DART_CHECK_VALID(builtin_lib); |
| 452 Dart_Handle root_lib = Dart_RootLibrary(); |
| 453 DART_CHECK_VALID(root_lib); |
| 451 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); | 454 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); |
| 452 DART_CHECK_VALID(result); | 455 DART_CHECK_VALID(result); |
| 453 | 456 |
| 454 if (config.compile_all) { | 457 if (config.compile_all) { |
| 455 result = Dart_CompileAll(); | 458 result = Dart_CompileAll(); |
| 456 DART_CHECK_VALID(result); | 459 DART_CHECK_VALID(result); |
| 457 } | 460 } |
| 458 | 461 |
| 459 Dart_Handle main_closure = Dart_Invoke( | 462 Dart_Handle main_closure = Dart_Invoke( |
| 460 builtin_lib, | 463 builtin_lib, |
| 461 Dart_NewStringFromCString("_getMainClosure"), | 464 Dart_NewStringFromCString("_getMainClosure"), |
| 462 0, | 465 0, |
| 463 nullptr); | 466 nullptr); |
| 464 DART_CHECK_VALID(main_closure); | 467 DART_CHECK_VALID(main_closure); |
| 465 | 468 |
| 466 // Call _startIsolate in the isolate library to enable dispatching the | 469 // Call _startIsolate in the isolate library to enable dispatching the |
| 467 // initial startup message. | 470 // initial startup message. |
| 468 const intptr_t kNumIsolateArgs = 2; | 471 const intptr_t kNumIsolateArgs = 2; |
| 469 Dart_Handle isolate_args[kNumIsolateArgs]; | 472 Dart_Handle isolate_args[kNumIsolateArgs]; |
| 470 isolate_args[0] = main_closure; // entryPoint | 473 isolate_args[0] = main_closure; // entryPoint |
| 471 isolate_args[1] = Dart_NewList(1); // args | 474 isolate_args[1] = Dart_NewList(2); // args |
| 472 DART_CHECK_VALID(isolate_args[1]); | 475 DART_CHECK_VALID(isolate_args[1]); |
| 476 |
| 477 Dart_Handle script_uri = Dart_NewStringFromUTF8( |
| 478 reinterpret_cast<const uint8_t*>(config.script_uri.data()), |
| 479 config.script_uri.length()); |
| 473 Dart_ListSetAt(isolate_args[1], 0, Dart_NewInteger(config.handle)); | 480 Dart_ListSetAt(isolate_args[1], 0, Dart_NewInteger(config.handle)); |
| 481 Dart_ListSetAt(isolate_args[1], 1, script_uri); |
| 474 | 482 |
| 475 Dart_Handle isolate_lib = | 483 Dart_Handle isolate_lib = |
| 476 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); | 484 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); |
| 477 DART_CHECK_VALID(isolate_lib); | 485 DART_CHECK_VALID(isolate_lib); |
| 478 | 486 |
| 479 result = Dart_Invoke(isolate_lib, | 487 result = Dart_Invoke(isolate_lib, |
| 480 Dart_NewStringFromCString("_startMainIsolate"), | 488 Dart_NewStringFromCString("_startMainIsolate"), |
| 481 kNumIsolateArgs, | 489 kNumIsolateArgs, |
| 482 isolate_args); | 490 isolate_args); |
| 483 DART_CHECK_VALID(result); | 491 DART_CHECK_VALID(result); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 497 DART_CHECK_VALID(result); | 505 DART_CHECK_VALID(result); |
| 498 | 506 |
| 499 Dart_ExitScope(); | 507 Dart_ExitScope(); |
| 500 Dart_ShutdownIsolate(); | 508 Dart_ShutdownIsolate(); |
| 501 Dart_Cleanup(); | 509 Dart_Cleanup(); |
| 502 return true; | 510 return true; |
| 503 } | 511 } |
| 504 | 512 |
| 505 } // namespace apps | 513 } // namespace apps |
| 506 } // namespace mojo | 514 } // namespace mojo |
| OLD | NEW |