-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The following snippet throws an error instead of returning an error object:
Dart_Handle DartRuntimeHooks::GetCallbackFromHandle(int64_t handle) {
Dart_Handle result = DartCallbackCache::GetCallback(handle);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
return result;
}(Example combined from flutter/flutter#111243, flutter/engine#36032, and flutter_engine/lib/ui/dart_runtime_hooks.cc.)
We should consider automatically throwing when Dart_IsError is true so that this pattern would not be needed.
Dart_IsError is defined in terms of a number of predefined class ids:
- Error
- ApiError
- LanguageError
- UnhandledError
- UnwindError
Throwing these would make it impossible to return objects with these types through dart:ffi. (If we ever want to do that, we could wrap the object in another object. Or if we're really concerned about not allocating another object, we could add another boolean flag to @FfiNative and asFunction.)
This is a breaking change, as code which currently returns these 5 objects types by Dart_Handle in dart:ffi will start throwing instead of returning the error object, requiring a try-catch as migration. However, I believe it might be unlikely that many users are relying on this.