asFunction<DF extends Function> method Null safety

DF asFunction<DF extends Function>()

Convert to Dart function, automatically marshalling the arguments and return value.

There are several rules that apply for the return type of DF, see the list of allowed return types. If marshalling failes, a MarshallingException is thrown.

If this is called on a pointer that does not point to a function, a ArgumentError is thrown.

Implementation

DF asFunction<DF extends Function>() {
  WasmSymbol symbol = symbolByAddress(boundMemory, address);
  if (symbol is FunctionDescription) {
    return marshall<NF, DF>(symbol.function, boundMemory);
  } else {
    throw ArgumentError(
        'No function at address $address was found (but a global symbol)!');
  }
}