diff --git a/sky/engine/core/script/dart_controller.cc b/sky/engine/core/script/dart_controller.cc index 8f75e7307f8..0835697fe4f 100644 --- a/sky/engine/core/script/dart_controller.cc +++ b/sky/engine/core/script/dart_controller.cc @@ -141,8 +141,7 @@ void DartController::CreateIsolateFor(std::unique_ptr state) { dom_dart_state_ = std::move(state); Dart_Isolate isolate = Dart_CreateIsolate( dom_dart_state_->url().utf8().data(), "main", - reinterpret_cast( - DartSymbolLookup(kDartIsolateSnapshotBufferName)), + reinterpret_cast(DART_SYMBOL(kDartIsolateSnapshotBuffer)), nullptr, static_cast(dom_dart_state_.get()), &error); Dart_SetMessageNotifyCallback(MessageNotifyCallback); CHECK(isolate) << error; diff --git a/sky/engine/core/script/dart_init.cc b/sky/engine/core/script/dart_init.cc index 6d73dea93fc..56bd73a7273 100644 --- a/sky/engine/core/script/dart_init.cc +++ b/sky/engine/core/script/dart_init.cc @@ -106,15 +106,6 @@ bool IsServiceIsolateURL(const char* url_name) { String(url_name) == DART_VM_SERVICE_ISOLATE_NAME; } -static const uint8_t* PrecompiledInstructionsSymbolIfPresent() { - return reinterpret_cast( - DartSymbolLookup(kInstructionsSnapshotName)); -} - -static bool IsRunningPrecompiledCode() { - return PrecompiledInstructionsSymbolIfPresent() != nullptr; -} - // TODO(rafaelw): Right now this only supports the creation of the handle // watcher isolate and the service isolate. Presumably, we'll want application // isolates to spawn their own isolates. @@ -128,8 +119,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, if (IsServiceIsolateURL(script_uri)) { DartState* dart_state = new DartState(); Dart_Isolate isolate = Dart_CreateIsolate( - script_uri, "main", reinterpret_cast(DartSymbolLookup( - kDartIsolateSnapshotBufferName)), + script_uri, "main", reinterpret_cast( + DART_SYMBOL(kDartIsolateSnapshotBuffer)), nullptr, nullptr, error); CHECK(isolate) << error; dart_state->SetIsolate(isolate); @@ -160,8 +151,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, // TODO(abarth): Who deletes this DartState instance? DartState* dart_state = new DartState(); Dart_Isolate isolate = Dart_CreateIsolate( - "sky:handle_watcher", "", reinterpret_cast(DartSymbolLookup( - kDartIsolateSnapshotBufferName)), + "sky:handle_watcher", "", + reinterpret_cast(DART_SYMBOL(kDartIsolateSnapshotBuffer)), nullptr, dart_state, error); CHECK(isolate) << error; dart_state->SetIsolate(isolate); @@ -186,6 +177,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, } // namespace +#if DART_ALLOW_DYNAMIC_LOADING + const char* kDartVmIsolateSnapshotBufferName = "kDartVmIsolateSnapshotBuffer"; const char* kDartIsolateSnapshotBufferName = "kDartIsolateSnapshotBuffer"; const char* kInstructionsSnapshotName = "kInstructionsSnapshot"; @@ -207,7 +200,7 @@ static void* DartLookupSymbolInLibrary(const char* symbol_name, return dlerror() != nullptr ? nullptr : sym; } -void* DartSymbolLookup(const char* symbol_name) { +void* _DartSymbolLookup(const char* symbol_name) { if (symbol_name == nullptr) { return nullptr; } @@ -226,6 +219,26 @@ void* DartSymbolLookup(const char* symbol_name) { return DartLookupSymbolInLibrary(symbol_name, nullptr); } +static const uint8_t* PrecompiledInstructionsSymbolIfPresent() { + return reinterpret_cast(DART_SYMBOL(kInstructionsSnapshot)); +} + +bool IsRunningPrecompiledCode() { + return PrecompiledInstructionsSymbolIfPresent() != nullptr; +} + +#else // DART_ALLOW_DYNAMIC_LOADING + +static const uint8_t* PrecompiledInstructionsSymbolIfPresent() { + return nullptr; +} + +bool IsRunningPrecompiledCode() { + return false; +} + +#endif // DART_ALLOW_DYNAMIC_LOADING + void InitDartVM() { dart::bin::BootstrapDartIo(); @@ -246,18 +259,18 @@ void InitDartVM() { CHECK(Dart_SetVMFlags(args.size(), args.data())); // This should be called before calling Dart_Initialize. DartDebugger::InitDebugger(); - CHECK(Dart_Initialize(reinterpret_cast( - DartSymbolLookup(kDartVmIsolateSnapshotBufferName)), - PrecompiledInstructionsSymbolIfPresent(), - IsolateCreateCallback, - nullptr, // Isolate interrupt callback. - UnhandledExceptionCallback, IsolateShutdownCallback, - // File IO callbacks. - nullptr, nullptr, nullptr, nullptr, - // Entroy source - nullptr, - // VM service assets archive - nullptr) == nullptr); + CHECK( + Dart_Initialize( + reinterpret_cast(DART_SYMBOL(kDartVmIsolateSnapshotBuffer)), + PrecompiledInstructionsSymbolIfPresent(), IsolateCreateCallback, + nullptr, // Isolate interrupt callback. + UnhandledExceptionCallback, IsolateShutdownCallback, + // File IO callbacks. + nullptr, nullptr, nullptr, nullptr, + // Entroy source + nullptr, + // VM service assets archive + nullptr) == nullptr); // Wait for load port- ensures handle watcher and service isolates are // running. Dart_ServiceWaitForLoadPort(); diff --git a/sky/engine/core/script/dart_init.h b/sky/engine/core/script/dart_init.h index 6c7c8c90c77..1378484ea1e 100644 --- a/sky/engine/core/script/dart_init.h +++ b/sky/engine/core/script/dart_init.h @@ -6,21 +6,40 @@ #define SKY_ENGINE_CORE_SCRIPT_DART_INIT_H_ #include "dart/runtime/include/dart_api.h" +#include "sky/engine/wtf/OperatingSystem.h" namespace blink { +#define DART_ALLOW_DYNAMIC_LOADING (WTF_OS_IOS || WTF_OS_MACOSX) + +#if DART_ALLOW_DYNAMIC_LOADING + extern const char* kDartVmIsolateSnapshotBufferName; extern const char* kDartIsolateSnapshotBufferName; extern const char* kInstructionsSnapshotName; -void* DartSymbolLookup(const char* symbol_name); +void* _DartSymbolLookup(const char* symbol_name); + +#define DART_SYMBOL(symbol) _DartSymbolLookup(symbol##Name) + +#else // DART_ALLOW_DYNAMIC_LOADING + +extern "C" { +extern uint8_t* kDartVmIsolateSnapshotBuffer; +extern uint8_t* kDartIsolateSnapshotBuffer; +} + +#define DART_SYMBOL(symbol) (symbol) + +#endif // DART_ALLOW_DYNAMIC_LOADING + +bool IsRunningPrecompiledCode(); void InitDartVM(); Dart_Handle DartLibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url); void EnsureHandleWatcherStarted(); +} // namespace blink -} - -#endif // SKY_ENGINE_CORE_SCRIPT_DART_INIT_H_ +#endif // SKY_ENGINE_CORE_SCRIPT_DART_INIT_H_