提交 54b81419 编写于 作者: J John McCutchan 提交者: GitHub

Fix profile and release mode isolate spawning (#3191)

Fixes #6496
上级 cdd7db26
...@@ -258,22 +258,25 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, ...@@ -258,22 +258,25 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
return ServiceIsolateCreateCallback(script_uri, error); return ServiceIsolateCreateCallback(script_uri, error);
} }
// Assert that entry script URI starts with file://
std::string entry_uri = script_uri; std::string entry_uri = script_uri;
FTL_CHECK(entry_uri.find(kFileUriPrefix) == 0u); // Are we running from a Dart source file?
// Entry script path (file:// is stripped). const bool running_from_source = StringEndsWith(entry_uri, ".dart");
std::string entry_path(script_uri + strlen(kFileUriPrefix));
// Are we running a .dart source file?
const bool running_from_source = StringEndsWith(entry_path, ".dart");
std::vector<uint8_t> snapshot_data; std::vector<uint8_t> snapshot_data;
if (!IsRunningPrecompiledCode() && !running_from_source) { std::string entry_path;
// Attempt to copy the snapshot from the asset bundle. if (!IsRunningPrecompiledCode()) {
const std::string& bundle_path = entry_path; // Assert that entry script URI starts with file://
ftl::RefPtr<ZipAssetStore> zip_asset_store = FTL_CHECK(entry_uri.find(kFileUriPrefix) == 0u);
ftl::MakeRefCounted<ZipAssetStore>( // Entry script path (file:// is stripped).
GetUnzipperProviderForPath(std::move(bundle_path))); entry_path = std::string(script_uri + strlen(kFileUriPrefix));
zip_asset_store->GetAsBuffer(kSnapshotAssetKey, &snapshot_data); if (!running_from_source) {
// Attempt to copy the snapshot from the asset bundle.
const std::string& bundle_path = entry_path;
ftl::RefPtr<ZipAssetStore> zip_asset_store =
ftl::MakeRefCounted<ZipAssetStore>(
GetUnzipperProviderForPath(std::move(bundle_path)));
zip_asset_store->GetAsBuffer(kSnapshotAssetKey, &snapshot_data);
}
} }
UIDartState* parent_dart_state = static_cast<UIDartState*>(callback_data); UIDartState* parent_dart_state = static_cast<UIDartState*>(callback_data);
...@@ -311,7 +314,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, ...@@ -311,7 +314,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
// We are running from a script snapshot. // We are running from a script snapshot.
FTL_CHECK(!LogIfError(Dart_LoadScriptFromSnapshot(snapshot_data.data(), FTL_CHECK(!LogIfError(Dart_LoadScriptFromSnapshot(snapshot_data.data(),
snapshot_data.size()))); snapshot_data.size())));
} else { } else if (running_from_source) {
// We are running from source.
// Forward the .packages configuration from the parent isolate to the // Forward the .packages configuration from the parent isolate to the
// child isolate. // child isolate.
tonic::FileLoader& parent_loader = parent_dart_state->file_loader(); tonic::FileLoader& parent_loader = parent_dart_state->file_loader();
...@@ -320,7 +324,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, ...@@ -320,7 +324,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
if (!packages.empty() && !loader.LoadPackagesMap(packages)) { if (!packages.empty() && !loader.LoadPackagesMap(packages)) {
FTL_LOG(WARNING) << "Failed to load package map: " << 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))); FTL_CHECK(!LogIfError(loader.LoadScript(entry_path)));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册