Return null instead of throwing if an instance method is passed to PluginUtilities.getCallbackHandle (flutter/engine#6260)

This commit is contained in:
Jason Simmons
2018-09-18 17:07:03 -07:00
committed by GitHub
parent 1dda09338c
commit 56fdcb7dbd

View File

@@ -32,7 +32,7 @@ abstract class PluginUtilities {
// This class is only a namespace, and should not be instantiated or
// extended directly.
factory PluginUtilities._() => null;
static Map<Function, CallbackHandle> _forwardCache =
<Function, CallbackHandle>{};
static Map<CallbackHandle, Function> _backwardCache =
@@ -49,8 +49,10 @@ abstract class PluginUtilities {
/// null is returned.
static CallbackHandle getCallbackHandle(Function callback) {
assert(callback != null, "'callback' must not be null.");
return _forwardCache.putIfAbsent(callback,
() => new CallbackHandle.fromRawHandle(_getCallbackHandle(callback)));
return _forwardCache.putIfAbsent(callback, () {
final int handle = _getCallbackHandle(callback);
return handle != null ? new CallbackHandle.fromRawHandle(handle) : null;
});
}
/// Get a tear-off of a named top-level or static callback represented by a