call method

  1. @override
Object? call(
  1. Interpreter interpreter,
  2. List<Object?> positionalArgs,
  3. Map<String, Object?> keywordArgs
)

Executes the wrapped native Dart function.

Passes the interpreter, positionalArgs, and keywordArgs directly to the underlying _function. Catches potential exceptions thrown by the Dart function and wraps them in a RuntimeError if they are not already one.

Implementation

@override
Object? call(
  Interpreter interpreter,
  List<Object?> positionalArgs,
  Map<String, Object?> keywordArgs,
) {
  // Native functions now need to handle positional and keyword args themselves.
  try {
    // Directly call the wrapped Dart function, passing the structures
    return _function(interpreter, positionalArgs, keywordArgs);
  } catch (e) {
    // Catch errors from the Dart function and wrap them
    // Provide a dummy token for location info
    Token dummyToken = Token(TokenType.IDENTIFIER, '<native>', null, 0, 0);
    if (e is RuntimeError) {
      // Allow native funcs to throw RuntimeError
      rethrow;
    }
    throw RuntimeError(dummyToken, "Error executing native function: $e");
  }
}