Skip to content

Commit

Permalink
Remove use of DART_CHECK_VALID. (flutter#8417)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak-google authored Apr 3, 2019
1 parent 309d078 commit 64fc583
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 48 deletions.
9 changes: 6 additions & 3 deletions lib/io/dart_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
70 changes: 36 additions & 34 deletions lib/ui/dart_runtime_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,45 +60,52 @@ 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) {
Dart_Handle print = GetFunction(builtin_library, "_getPrintClosure");

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) {
Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand All @@ -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)) {
Expand All @@ -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 "";
Expand All @@ -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)) {
Expand All @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 15 additions & 6 deletions lib/ui/plugins/callback_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,43 @@ 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()) {
library = Dart_RootLibrary();
} 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;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/ui/window/platform_message_response_dart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 64fc583

Please sign in to comment.