Flutter Engine
The Flutter Engine
natives.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "natives.h"
6
7#include <zircon/syscalls.h>
8
9#include <cstring>
10#include <memory>
11#include <vector>
12
13#include "handle.h"
14#include "handle_disposition.h"
15#include "handle_waiter.h"
16#include "system.h"
17#include "third_party/dart/runtime/include/dart_api.h"
25
26using tonic::ToDart;
27
28namespace zircon {
29namespace dart {
30namespace {
31
32static tonic::DartLibraryNatives* g_natives;
33
34tonic::DartLibraryNatives* InitNatives() {
40
41 return natives;
42}
43
46 bool* auto_setup_scope) {
47 const char* function_name = nullptr;
49 if (Dart_IsError(result)) {
51 }
52 FML_DCHECK(function_name != nullptr);
53 FML_DCHECK(auto_setup_scope != nullptr);
54 *auto_setup_scope = true;
55 if (!g_natives)
56 g_natives = InitNatives();
57 return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
58}
59
60const uint8_t* NativeSymbol(Dart_NativeFunction native_function) {
61 if (!g_natives)
62 g_natives = InitNatives();
63 return g_natives->GetSymbol(native_function);
64}
65
66} // namespace
67
68void Initialize() {
69 Dart_Handle library = Dart_LookupLibrary(ToDart("dart:zircon"));
72 library, zircon::dart::NativeLookup, zircon::dart::NativeSymbol);
74
75 auto dart_state = tonic::DartState::Current();
76 std::unique_ptr<tonic::DartClassProvider> zircon_class_provider(
77 new tonic::DartClassProvider(dart_state, "dart:zircon"));
78 dart_state->class_library().add_provider("zircon",
79 std::move(zircon_class_provider));
80}
81
82} // namespace dart
83} // namespace zircon
const uint8_t * GetSymbol(Dart_NativeFunction native_function)
Dart_NativeFunction GetNativeFunction(Dart_Handle name, int argument_count, bool *auto_setup_scope)
static DartState * Current()
Definition: dart_state.cc:56
static void RegisterNatives(tonic::DartLibraryNatives *natives)
static void RegisterNatives(tonic::DartLibraryNatives *natives)
static void RegisterNatives(tonic::DartLibraryNatives *natives)
Definition: handle.cc:132
static void RegisterNatives(tonic::DartLibraryNatives *natives)
Definition: system.cc:606
DART_EXPORT Dart_Handle Dart_SetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver resolver, Dart_NativeEntrySymbol symbol)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, const char **cstr)
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
GAsyncResult * result
#define FML_CHECK(condition)
Definition: logging.h:85
#define FML_DCHECK(condition)
Definition: logging.h:103
int argument_count
Definition: fuchsia.cc:52
Definition: dart_vm.cc:33
static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc, bool *auto_setup_scope)
const char *const function_name
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
Definition: dart_error.cc:33
void Initialize()
Definition: natives.cc:68
Definition: handle.cc:14