Flutter Engine
fuchsia::dart Namespace Reference

Functions

void Initialize (fidl::InterfaceHandle< fuchsia::sys::Environment > environment, zx::channel directory_request, std::optional< zx::eventpair > view_ref)
 

Function Documentation

◆ Initialize()

void fuchsia::dart::Initialize ( fidl::InterfaceHandle< fuchsia::sys::Environment >  environment,
zx::channel  directory_request,
std::optional< zx::eventpair >  view_ref 
)

Definition at line 103 of file fuchsia.cc.

References zircon::dart::Handle::Create(), tonic::DartState::Current(), FML_CHECK, zircon::dart::Initialize(), tonic::LogIfError(), and tonic::ToDart().

Referenced by flutter_runner::IsolateConfigurator::ConfigureCurrentIsolate(), FlutterEngineGetProcAddresses(), dart_runner::InitBuiltinLibrariesForIsolate(), benchmarking::Main(), and main().

105  {
107 
108  Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia"));
109  FML_CHECK(!tonic::LogIfError(library));
110  Dart_Handle result = Dart_SetNativeResolver(
111  library, fuchsia::dart::NativeLookup, fuchsia::dart::NativeSymbol);
112  FML_CHECK(!tonic::LogIfError(result));
113 
114  auto dart_state = tonic::DartState::Current();
115  std::unique_ptr<tonic::DartClassProvider> fuchsia_class_provider(
116  new tonic::DartClassProvider(dart_state, "dart:fuchsia"));
117  dart_state->class_library().add_provider("fuchsia",
118  std::move(fuchsia_class_provider));
119 
120  result = Dart_SetField(
121  library, ToDart("_environment"),
122  ToDart(zircon::dart::Handle::Create(environment.TakeChannel())));
123  FML_CHECK(!tonic::LogIfError(result));
124 
125  if (directory_request) {
126  result = Dart_SetField(
127  library, ToDart("_outgoingServices"),
128  ToDart(zircon::dart::Handle::Create(std::move(directory_request))));
129  FML_CHECK(!tonic::LogIfError(result));
130  }
131 
132  if (view_ref) {
133  result = Dart_SetField(
134  library, ToDart("_viewRef"),
135  ToDart(zircon::dart::Handle::Create((*view_ref).release())));
136  FML_CHECK(!tonic::LogIfError(result));
137  }
138 }
static DartState * Current()
Definition: dart_state.cc:55
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:50
#define FML_CHECK(condition)
Definition: logging.h:68
Dart_Handle ToDart(const T &object)
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15
void Initialize()
Definition: natives.cc:66