modify RunFrom<X> methods to return error code rather than call exit (flutter/engine#3428)

This commit is contained in:
Dan Rubel
2017-02-21 11:31:27 -05:00
committed by GitHub
parent 3e7ecdc1e7
commit 92767a3d58
2 changed files with 26 additions and 14 deletions

View File

@@ -105,26 +105,38 @@ bool DartController::SendStartMessage(Dart_Handle root_library) {
return LogIfError(result);
}
void DartController::RunFromKernel(const uint8_t* buffer, size_t size) {
tonic::DartErrorHandleType DartController::RunFromKernel(
const uint8_t* buffer, size_t size) {
tonic::DartState::Scope scope(dart_state());
LogIfError(Dart_LoadKernel(Dart_ReadKernelBinary(buffer, size)));
if (SendStartMessage(Dart_RootLibrary()))
exit(1);
Dart_Handle result = Dart_LoadKernel(Dart_ReadKernelBinary(buffer, size));
LogIfError(result);
tonic::DartErrorHandleType error = tonic::GetErrorHandleType(result);
if (SendStartMessage(Dart_RootLibrary())) {
return tonic::kUnknownErrorType;
}
return error;
}
void DartController::RunFromPrecompiledSnapshot() {
tonic::DartErrorHandleType DartController::RunFromPrecompiledSnapshot() {
TRACE_EVENT0("flutter", "DartController::RunFromPrecompiledSnapshot");
FTL_DCHECK(Dart_CurrentIsolate() == nullptr);
tonic::DartState::Scope scope(dart_state());
if (SendStartMessage(Dart_RootLibrary()))
exit(1);
if (SendStartMessage(Dart_RootLibrary())) {
return tonic::kUnknownErrorType;
}
return tonic::kNoError;
}
void DartController::RunFromSnapshot(const uint8_t* buffer, size_t size) {
tonic::DartErrorHandleType DartController::RunFromSnapshot(
const uint8_t* buffer, size_t size) {
tonic::DartState::Scope scope(dart_state());
LogIfError(Dart_LoadScriptFromSnapshot(buffer, size));
if (SendStartMessage(Dart_RootLibrary()))
exit(1);
Dart_Handle result = Dart_LoadScriptFromSnapshot(buffer, size);
LogIfError(result);
tonic::DartErrorHandleType error = tonic::GetErrorHandleType(result);
if (SendStartMessage(Dart_RootLibrary())) {
return tonic::kUnknownErrorType;
}
return error;
}
tonic::DartErrorHandleType DartController::RunFromSource(

View File

@@ -19,9 +19,9 @@ class DartController {
DartController();
~DartController();
void RunFromKernel(const uint8_t* buffer, size_t size);
void RunFromPrecompiledSnapshot();
void RunFromSnapshot(const uint8_t* buffer, size_t size);
tonic::DartErrorHandleType RunFromKernel(const uint8_t* buffer, size_t size);
tonic::DartErrorHandleType RunFromPrecompiledSnapshot();
tonic::DartErrorHandleType RunFromSnapshot(const uint8_t* buffer, size_t size);
tonic::DartErrorHandleType RunFromSource(const std::string& main,
const std::string& packages);