| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/core/script/dart_controller.h" | 6 #include "sky/engine/core/script/dart_controller.h" |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 if (IsServiceIsolateURL(script_uri)) { | 240 if (IsServiceIsolateURL(script_uri)) { |
| 241 CHECK(kDartIsolateSnapshotBuffer); | 241 CHECK(kDartIsolateSnapshotBuffer); |
| 242 DartState* dart_state = new DartState(); | 242 DartState* dart_state = new DartState(); |
| 243 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, | 243 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, |
| 244 "main", | 244 "main", |
| 245 kDartIsolateSnapshotBuffer, | 245 kDartIsolateSnapshotBuffer, |
| 246 nullptr, | 246 nullptr, |
| 247 error); | 247 error); |
| 248 CHECK(isolate) << error; | 248 CHECK(isolate) << error; |
| 249 dart_state->set_isolate(isolate); | 249 dart_state->SetIsolate(isolate); |
| 250 CHECK(Dart_IsServiceIsolate(isolate)); | 250 CHECK(Dart_IsServiceIsolate(isolate)); |
| 251 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 251 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 252 { | 252 { |
| 253 DartApiScope apiScope; | 253 DartApiScope apiScope; |
| 254 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 254 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 255 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); | 255 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); |
| 256 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 256 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 257 BuiltinNatives::Init(BuiltinNatives::DartIOIsolate); | 257 BuiltinNatives::Init(BuiltinNatives::DartIOIsolate); |
| 258 // Start the handle watcher from the service isolate so it isn't available | 258 // Start the handle watcher from the service isolate so it isn't available |
| 259 // for debugging or general Observatory interaction. | 259 // for debugging or general Observatory interaction. |
| 260 EnsureHandleWatcherStarted(); | 260 EnsureHandleWatcherStarted(); |
| 261 if (RuntimeEnabledFeatures::observatoryEnabled()) { | 261 if (RuntimeEnabledFeatures::observatoryEnabled()) { |
| 262 std::string ip = "127.0.0.1"; | 262 std::string ip = "127.0.0.1"; |
| 263 const intptr_t port = 8181; | 263 const intptr_t port = 8181; |
| 264 const bool service_isolate_booted = | 264 const bool service_isolate_booted = |
| 265 DartServiceIsolate::Startup(ip, port, LibraryTagHandler, error); | 265 DartServiceIsolate::Startup(ip, port, LibraryTagHandler, error); |
| 266 CHECK(service_isolate_booted) << error; | 266 CHECK(service_isolate_booted) << error; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 Dart_ExitIsolate(); | 269 Dart_ExitIsolate(); |
| 270 return isolate; | 270 return isolate; |
| 271 } | 271 } |
| 272 | 272 |
| 273 // Create & start the handle watcher isolate | 273 // Create & start the handle watcher isolate |
| 274 CHECK(kDartIsolateSnapshotBuffer); | 274 CHECK(kDartIsolateSnapshotBuffer); |
| 275 DartState* dart_state = new DartState(); | 275 DartState* dart_state = new DartState(); |
| 276 Dart_Isolate isolate = Dart_CreateIsolate("sky:handle_watcher", "", | 276 Dart_Isolate isolate = Dart_CreateIsolate("sky:handle_watcher", "", |
| 277 kDartIsolateSnapshotBuffer, dart_state, error); | 277 kDartIsolateSnapshotBuffer, dart_state, error); |
| 278 CHECK(isolate) << error; | 278 CHECK(isolate) << error; |
| 279 dart_state->set_isolate(isolate); | 279 dart_state->SetIsolate(isolate); |
| 280 | 280 |
| 281 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 281 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 282 | 282 |
| 283 { | 283 { |
| 284 DartApiScope apiScope; | 284 DartApiScope apiScope; |
| 285 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 285 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 286 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); | 286 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); |
| 287 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 287 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 288 | 288 |
| 289 // Ensure the isolate has a root library. | 289 // Ensure the isolate has a root library. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 317 void DartController::CreateIsolateFor(PassOwnPtr<DOMDartState> state) { | 317 void DartController::CreateIsolateFor(PassOwnPtr<DOMDartState> state) { |
| 318 CHECK(kDartIsolateSnapshotBuffer); | 318 CHECK(kDartIsolateSnapshotBuffer); |
| 319 char* error = nullptr; | 319 char* error = nullptr; |
| 320 dom_dart_state_ = state; | 320 dom_dart_state_ = state; |
| 321 Dart_Isolate isolate = Dart_CreateIsolate( | 321 Dart_Isolate isolate = Dart_CreateIsolate( |
| 322 dom_dart_state_->url().string().utf8().data(), "main", | 322 dom_dart_state_->url().string().utf8().data(), "main", |
| 323 kDartIsolateSnapshotBuffer, | 323 kDartIsolateSnapshotBuffer, |
| 324 static_cast<DartState*>(dom_dart_state_.get()), &error); | 324 static_cast<DartState*>(dom_dart_state_.get()), &error); |
| 325 Dart_SetMessageNotifyCallback(MessageNotifyCallback); | 325 Dart_SetMessageNotifyCallback(MessageNotifyCallback); |
| 326 CHECK(isolate) << error; | 326 CHECK(isolate) << error; |
| 327 dom_dart_state_->set_isolate(isolate); | 327 dom_dart_state_->SetIsolate(isolate); |
| 328 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); | 328 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); |
| 329 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 329 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 330 | 330 |
| 331 { | 331 { |
| 332 DartApiScope apiScope; | 332 DartApiScope apiScope; |
| 333 | 333 |
| 334 // Ensure the isolate has a root library. | 334 // Ensure the isolate has a root library. |
| 335 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"), | 335 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"), |
| 336 Dart_NewStringFromCString(""), 0, 0); | 336 Dart_NewStringFromCString(""), 0, 0); |
| 337 | 337 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 355 DartIsolateScope isolate_scope(dart_state()->isolate()); | 355 DartIsolateScope isolate_scope(dart_state()->isolate()); |
| 356 DartApiScope dart_api_scope; | 356 DartApiScope dart_api_scope; |
| 357 | 357 |
| 358 builtin_sky_->InstallView(view); | 358 builtin_sky_->InstallView(view); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void DartController::ClearForClose() { | 361 void DartController::ClearForClose() { |
| 362 // Don't use a DartIsolateScope here since we never exit the isolate. | 362 // Don't use a DartIsolateScope here since we never exit the isolate. |
| 363 Dart_EnterIsolate(dom_dart_state_->isolate()); | 363 Dart_EnterIsolate(dom_dart_state_->isolate()); |
| 364 Dart_ShutdownIsolate(); | 364 Dart_ShutdownIsolate(); |
| 365 dom_dart_state_->SetIsolate(nullptr); |
| 365 dom_dart_state_.clear(); | 366 dom_dart_state_.clear(); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void DartController::InitVM() { | 369 void DartController::InitVM() { |
| 369 int argc = 0; | 370 int argc = 0; |
| 370 const char** argv = nullptr; | 371 const char** argv = nullptr; |
| 371 | 372 |
| 372 #if ENABLE(DART_STRICT) | 373 #if ENABLE(DART_STRICT) |
| 373 argc = arraysize(kCheckedModeArgs); | 374 argc = arraysize(kCheckedModeArgs); |
| 374 argv = kCheckedModeArgs; | 375 argv = kCheckedModeArgs; |
| 375 #endif | 376 #endif |
| 376 | 377 |
| 377 dart::bin::BootstrapDartIo(); | 378 dart::bin::BootstrapDartIo(); |
| 378 | 379 |
| 379 CHECK(Dart_SetVMFlags(argc, argv)); | 380 CHECK(Dart_SetVMFlags(argc, argv)); |
| 380 // This should be called before calling Dart_Initialize. | 381 // This should be called before calling Dart_Initialize. |
| 381 DartDebugger::InitDebugger(); | 382 DartDebugger::InitDebugger(); |
| 382 CHECK(Dart_Initialize(kDartVmIsolateSnapshotBuffer, | 383 CHECK(Dart_Initialize(kDartVmIsolateSnapshotBuffer, |
| 383 IsolateCreateCallback, | 384 IsolateCreateCallback, |
| 384 nullptr, // Isolate interrupt callback. | 385 nullptr, // Isolate interrupt callback. |
| 385 UnhandledExceptionCallback, IsolateShutdownCallback, | 386 UnhandledExceptionCallback, IsolateShutdownCallback, |
| 386 // File IO callbacks. | 387 // File IO callbacks. |
| 387 nullptr, nullptr, nullptr, nullptr, nullptr)); | 388 nullptr, nullptr, nullptr, nullptr, nullptr)); |
| 388 // Wait for load port- ensures handle watcher and service isolates are | 389 // Wait for load port- ensures handle watcher and service isolates are |
| 389 // running. | 390 // running. |
| 390 Dart_ServiceWaitForLoadPort(); | 391 Dart_ServiceWaitForLoadPort(); |
| 391 } | 392 } |
| 392 | 393 |
| 393 } // namespace blink | 394 } // namespace blink |
| OLD | NEW |