Remove use of DART_CHECK_VALID. (flutter/engine#8417)

Bug: https://github.com/flutter/flutter/issues/30407
This commit is contained in:
Ryan Macnak
2019-04-03 10:01:57 -07:00
committed by GitHub
parent ea5fb8a1b8
commit 16e6a62464
5 changed files with 63 additions and 48 deletions

View File

@@ -13,9 +13,12 @@ using tonic::ToDart;
namespace blink {
void DartIO::InitForIsolate() {
DART_CHECK_VALID(Dart_SetNativeResolver(Dart_LookupLibrary(ToDart("dart:io")),
dart::bin::LookupIONative,
dart::bin::LookupIONativeSymbol));
Dart_Handle result = Dart_SetNativeResolver(
Dart_LookupLibrary(ToDart("dart:io")), dart::bin::LookupIONative,
dart::bin::LookupIONativeSymbol);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
}
bool DartIO::EntropySource(uint8_t* buffer, intptr_t length) {

View File

@@ -60,11 +60,15 @@ void DartRuntimeHooks::RegisterNatives(tonic::DartLibraryNatives* natives) {
natives->Register({BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)});
}
static void PropagateIfError(Dart_Handle result) {
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
}
static Dart_Handle GetFunction(Dart_Handle builtin_library, const char* name) {
Dart_Handle getter_name = ToDart(name);
Dart_Handle closure = Dart_Invoke(builtin_library, getter_name, 0, nullptr);
DART_CHECK_VALID(closure);
return closure;
return Dart_Invoke(builtin_library, getter_name, 0, nullptr);
}
static void InitDartInternal(Dart_Handle builtin_library, bool is_ui_isolate) {
@@ -72,24 +76,26 @@ static void InitDartInternal(Dart_Handle builtin_library, bool is_ui_isolate) {
Dart_Handle internal_library = Dart_LookupLibrary(ToDart("dart:_internal"));
DART_CHECK_VALID(
Dart_SetField(internal_library, ToDart("_printClosure"), print));
Dart_Handle result =
Dart_SetField(internal_library, ToDart("_printClosure"), print);
PropagateIfError(result);
if (is_ui_isolate) {
// Call |_setupHooks| to configure |VMLibraryHooks|.
Dart_Handle method_name = Dart_NewStringFromCString("_setupHooks");
DART_CHECK_VALID(Dart_Invoke(builtin_library, method_name, 0, NULL))
result = Dart_Invoke(builtin_library, method_name, 0, NULL);
PropagateIfError(result);
}
Dart_Handle setup_hooks = Dart_NewStringFromCString("_setupHooks");
Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
DART_CHECK_VALID(io_lib);
DART_CHECK_VALID(Dart_Invoke(io_lib, setup_hooks, 0, NULL));
result = Dart_Invoke(io_lib, setup_hooks, 0, NULL);
PropagateIfError(result);
Dart_Handle isolate_lib = Dart_LookupLibrary(ToDart("dart:isolate"));
DART_CHECK_VALID(isolate_lib);
DART_CHECK_VALID(Dart_Invoke(isolate_lib, setup_hooks, 0, NULL));
result = Dart_Invoke(isolate_lib, setup_hooks, 0, NULL);
PropagateIfError(result);
}
static void InitDartCore(Dart_Handle builtin, const std::string& script_uri) {
@@ -97,8 +103,9 @@ static void InitDartCore(Dart_Handle builtin, const std::string& script_uri) {
Dart_Handle get_base_url =
Dart_Invoke(io_lib, ToDart("_getUriBaseClosure"), 0, NULL);
Dart_Handle core_library = Dart_LookupLibrary(ToDart("dart:core"));
DART_CHECK_VALID(
Dart_SetField(core_library, ToDart("_uriBaseClosure"), get_base_url));
Dart_Handle result =
Dart_SetField(core_library, ToDart("_uriBaseClosure"), get_base_url);
PropagateIfError(result);
}
static void InitDartAsync(Dart_Handle builtin_library, bool is_ui_isolate) {
@@ -114,31 +121,31 @@ static void InitDartAsync(Dart_Handle builtin_library, bool is_ui_isolate) {
}
Dart_Handle async_library = Dart_LookupLibrary(ToDart("dart:async"));
Dart_Handle set_schedule_microtask = ToDart("_setScheduleImmediateClosure");
DART_CHECK_VALID(Dart_Invoke(async_library, set_schedule_microtask, 1,
&schedule_microtask));
Dart_Handle result = Dart_Invoke(async_library, set_schedule_microtask, 1,
&schedule_microtask);
PropagateIfError(result);
}
static void InitDartIO(Dart_Handle builtin_library,
const std::string& script_uri) {
Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
DART_CHECK_VALID(io_lib);
Dart_Handle platform_type =
Dart_GetType(io_lib, ToDart("_Platform"), 0, nullptr);
DART_CHECK_VALID(platform_type);
if (!script_uri.empty()) {
DART_CHECK_VALID(Dart_SetField(platform_type, ToDart("_nativeScript"),
ToDart(script_uri)));
Dart_Handle result = Dart_SetField(platform_type, ToDart("_nativeScript"),
ToDart(script_uri));
PropagateIfError(result);
}
Dart_Handle locale_closure =
GetFunction(builtin_library, "_getLocaleClosure");
DART_CHECK_VALID(
Dart_SetField(platform_type, ToDart("_localeClosure"), locale_closure));
Dart_Handle result =
Dart_SetField(platform_type, ToDart("_localeClosure"), locale_closure);
PropagateIfError(result);
}
void DartRuntimeHooks::Install(bool is_ui_isolate,
const std::string& script_uri) {
Dart_Handle builtin = Dart_LookupLibrary(ToDart("dart:ui"));
DART_CHECK_VALID(builtin);
InitDartInternal(builtin, is_ui_isolate);
InitDartCore(builtin, script_uri);
InitDartAsync(builtin, is_ui_isolate);
@@ -242,7 +249,7 @@ void ScheduleMicrotask(Dart_NativeArguments args) {
static std::string GetFunctionLibraryUrl(Dart_Handle closure) {
if (Dart_IsClosure(closure)) {
closure = Dart_ClosureFunction(closure);
DART_CHECK_VALID(closure);
PropagateIfError(closure);
}
if (!Dart_IsFunction(closure)) {
@@ -256,7 +263,7 @@ static std::string GetFunctionLibraryUrl(Dart_Handle closure) {
}
if (Dart_IsLibrary(owner)) {
url = Dart_LibraryUrl(owner);
DART_CHECK_VALID(url);
PropagateIfError(url);
}
return DartConverter<std::string>::FromDart(url);
}
@@ -266,7 +273,7 @@ static std::string GetFunctionClassName(Dart_Handle closure) {
if (Dart_IsClosure(closure)) {
closure = Dart_ClosureFunction(closure);
DART_CHECK_VALID(closure);
PropagateIfError(closure);
}
if (!Dart_IsFunction(closure)) {
@@ -275,13 +282,13 @@ static std::string GetFunctionClassName(Dart_Handle closure) {
bool is_static = false;
result = Dart_FunctionIsStatic(closure, &is_static);
DART_CHECK_VALID(result);
PropagateIfError(result);
if (!is_static) {
return "";
}
result = Dart_FunctionOwner(closure);
DART_CHECK_VALID(result);
PropagateIfError(result);
if (Dart_IsLibrary(result) || !Dart_IsInstance(result)) {
return "";
@@ -290,11 +297,9 @@ static std::string GetFunctionClassName(Dart_Handle closure) {
}
static std::string GetFunctionName(Dart_Handle func) {
DART_CHECK_VALID(func);
if (Dart_IsClosure(func)) {
func = Dart_ClosureFunction(func);
DART_CHECK_VALID(func);
PropagateIfError(func);
}
if (!Dart_IsFunction(func)) {
@@ -303,16 +308,13 @@ static std::string GetFunctionName(Dart_Handle func) {
bool is_static = false;
Dart_Handle result = Dart_FunctionIsStatic(func, &is_static);
DART_CHECK_VALID(result);
PropagateIfError(result);
if (!is_static) {
return "";
}
result = Dart_FunctionName(func);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
return "";
}
PropagateIfError(result);
return DartConverter<std::string>::FromDart(result);
}

View File

@@ -104,8 +104,11 @@ void DartUI::InitForIsolate(bool is_root_isolate) {
auto get_native_function =
is_root_isolate ? GetNativeFunction : GetNativeFunctionSecondary;
auto get_symbol = is_root_isolate ? GetSymbol : GetSymbolSecondary;
DART_CHECK_VALID(Dart_SetNativeResolver(Dart_LookupLibrary(ToDart("dart:ui")),
get_native_function, get_symbol));
Dart_Handle result = Dart_SetNativeResolver(
Dart_LookupLibrary(ToDart("dart:ui")), get_native_function, get_symbol);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
}
} // namespace blink

View File

@@ -152,12 +152,18 @@ Dart_Handle DartCallbackCache::LookupDartClosure(
const std::string& class_name,
const std::string& library_path) {
Dart_Handle closure_name = ToDart(name);
if (Dart_IsError(closure_name)) {
return closure_name;
}
Dart_Handle library_name =
library_path.empty() ? Dart_Null() : ToDart(library_path);
if (Dart_IsError(library_name)) {
return library_name;
}
Dart_Handle cls_name = class_name.empty() ? Dart_Null() : ToDart(class_name);
DART_CHECK_VALID(closure_name);
DART_CHECK_VALID(library_name);
DART_CHECK_VALID(cls_name);
if (Dart_IsError(cls_name)) {
return cls_name;
}
Dart_Handle library;
if (library_name == Dart_Null()) {
@@ -165,21 +171,24 @@ Dart_Handle DartCallbackCache::LookupDartClosure(
} else {
library = Dart_LookupLibrary(library_name);
}
DART_CHECK_VALID(library);
if (Dart_IsError(library)) {
return library;
}
Dart_Handle closure;
if (Dart_IsNull(cls_name)) {
closure = Dart_GetField(library, closure_name);
} else {
Dart_Handle cls = Dart_GetClass(library, cls_name);
DART_CHECK_VALID(cls);
if (Dart_IsError(cls)) {
return cls;
}
if (Dart_IsNull(cls)) {
closure = Dart_Null();
} else {
closure = Dart_GetStaticMethodClosure(library, cls, closure_name);
}
}
DART_CHECK_VALID(closure);
return closure;
}

View File

@@ -31,11 +31,9 @@ Dart_Handle WrapByteData(std::vector<uint8_t> data) {
return ToByteData(data);
} else {
std::vector<uint8_t>* heap_data = new std::vector<uint8_t>(std::move(data));
Dart_Handle data_handle = Dart_NewExternalTypedDataWithFinalizer(
return Dart_NewExternalTypedDataWithFinalizer(
Dart_TypedData_kByteData, heap_data->data(), heap_data->size(),
heap_data, heap_data->size(), MessageDataFinalizer);
DART_CHECK_VALID(data_handle);
return data_handle;
}
}