From 54b81419aa8643ff8bee5740887977ba0a8388ac Mon Sep 17 00:00:00 2001 From: John McCutchan Date: Tue, 1 Nov 2016 21:28:41 +0100 Subject: [PATCH] Fix profile and release mode isolate spawning (#3191) Fixes #6496 --- runtime/dart_init.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/runtime/dart_init.cc b/runtime/dart_init.cc index e4caf78de..2cdfd538c 100644 --- a/runtime/dart_init.cc +++ b/runtime/dart_init.cc @@ -258,22 +258,25 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, return ServiceIsolateCreateCallback(script_uri, error); } - // Assert that entry script URI starts with file:// std::string entry_uri = script_uri; - FTL_CHECK(entry_uri.find(kFileUriPrefix) == 0u); - // Entry script path (file:// is stripped). - std::string entry_path(script_uri + strlen(kFileUriPrefix)); - // Are we running a .dart source file? - const bool running_from_source = StringEndsWith(entry_path, ".dart"); + // Are we running from a Dart source file? + const bool running_from_source = StringEndsWith(entry_uri, ".dart"); std::vector snapshot_data; - if (!IsRunningPrecompiledCode() && !running_from_source) { - // Attempt to copy the snapshot from the asset bundle. - const std::string& bundle_path = entry_path; - ftl::RefPtr zip_asset_store = - ftl::MakeRefCounted( - GetUnzipperProviderForPath(std::move(bundle_path))); - zip_asset_store->GetAsBuffer(kSnapshotAssetKey, &snapshot_data); + std::string entry_path; + if (!IsRunningPrecompiledCode()) { + // Assert that entry script URI starts with file:// + FTL_CHECK(entry_uri.find(kFileUriPrefix) == 0u); + // Entry script path (file:// is stripped). + entry_path = std::string(script_uri + strlen(kFileUriPrefix)); + if (!running_from_source) { + // Attempt to copy the snapshot from the asset bundle. + const std::string& bundle_path = entry_path; + ftl::RefPtr zip_asset_store = + ftl::MakeRefCounted( + GetUnzipperProviderForPath(std::move(bundle_path))); + zip_asset_store->GetAsBuffer(kSnapshotAssetKey, &snapshot_data); + } } UIDartState* parent_dart_state = static_cast(callback_data); @@ -311,7 +314,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, // We are running from a script snapshot. FTL_CHECK(!LogIfError(Dart_LoadScriptFromSnapshot(snapshot_data.data(), snapshot_data.size()))); - } else { + } else if (running_from_source) { + // We are running from source. // Forward the .packages configuration from the parent isolate to the // child isolate. tonic::FileLoader& parent_loader = parent_dart_state->file_loader(); @@ -320,7 +324,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, if (!packages.empty() && !loader.LoadPackagesMap(packages)) { FTL_LOG(WARNING) << "Failed to load package map: " << packages; } - // We are running from source. + // Load the script. FTL_CHECK(!LogIfError(loader.LoadScript(entry_path))); } -- GitLab