From 92767a3d58fdb789091e2c72821e7194f0fe80df Mon Sep 17 00:00:00 2001 From: Dan Rubel Date: Tue, 21 Feb 2017 11:31:27 -0500 Subject: [PATCH] modify RunFrom methods to return error code rather than call exit (flutter/engine#3428) --- engine/src/flutter/runtime/dart_controller.cc | 34 +++++++++++++------ engine/src/flutter/runtime/dart_controller.h | 6 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/runtime/dart_controller.cc b/engine/src/flutter/runtime/dart_controller.cc index 4dd1075d72..5720bbf8c8 100644 --- a/engine/src/flutter/runtime/dart_controller.cc +++ b/engine/src/flutter/runtime/dart_controller.cc @@ -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( diff --git a/engine/src/flutter/runtime/dart_controller.h b/engine/src/flutter/runtime/dart_controller.h index f299b688ea..0c9c9048ff 100644 --- a/engine/src/flutter/runtime/dart_controller.h +++ b/engine/src/flutter/runtime/dart_controller.h @@ -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);