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)
 Initializes Dart bindings for the Fuchsia application model. More...
 

Function Documentation

◆ Initialize()

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

Initializes Dart bindings for the Fuchsia application model.

Definition at line 103 of file fuchsia.cc.

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

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

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  // V2 components do not use the environment.
121  if (environment) {
122  result = Dart_SetField(
123  library, ToDart("_environment"),
124  ToDart(zircon::dart::Handle::Create(environment.TakeChannel())));
125  FML_CHECK(!tonic::LogIfError(result));
126  }
127 
128  if (directory_request) {
129  result = Dart_SetField(
130  library, ToDart("_outgoingServices"),
131  ToDart(zircon::dart::Handle::Create(std::move(directory_request))));
132  FML_CHECK(!tonic::LogIfError(result));
133  }
134 
135  if (view_ref) {
136  result = Dart_SetField(
137  library, ToDart("_viewRef"),
138  ToDart(zircon::dart::Handle::Create((*view_ref).release())));
139  FML_CHECK(!tonic::LogIfError(result));
140  }
141 }
static DartState * Current()
Definition: dart_state.cc:56
GAsyncResult * result
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
#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:68