asFunction<DF extends Function> method

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 fails, 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>() {
  // ignore: prefer_final_locals
  WasmSymbol symbol = symbolByAddress(boundMemory, address);
  if (symbol is FunctionDescription && symbol.function.isA<JSFunction>()) {
    // ignore: invalid_runtime_check_with_js_interop_types
    return marshall<NF, DF>(symbol.function as Function, boundMemory);
  } else {
    throw ArgumentError(
      'No function at address $address was found (but a global symbol)!',
    );
  }
}