injectFunction method
Temporarily injects a Promise-returning Dart function into this context.
Reusing name replaces and releases the previous callback. The function
remains available until the context is disposed.
Implementation
Future<void> injectFunction(
String name,
FutureOr<Object?> Function(List<Object?> args) callback,
) async {
_ensureOpen();
if (!RegExp(r'^[A-Za-z_$][A-Za-z0-9_$]*$').hasMatch(name)) {
throw ArgumentError.value(
name,
'name',
'must be a JavaScript identifier',
);
}
await _engine.injectFunction(name, callback);
}