injectFunction method

Future<void> injectFunction(
  1. String name,
  2. FutureOr<Object?> callback(
    1. List<Object?> args
    )
)

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);
}