call method

  1. @override
Object? call(
  1. Interpreter interpreter,
  2. List<Object?> arguments,
  3. Map<Symbol, Object?> namedArguments
)
override

Implementation

@override
Object? call(Interpreter interpreter, List<Object?> arguments,
    Map<Symbol, Object?> namedArguments) {
  var name = namedArguments[const Symbol('name')];
  if (name == null) {
    throw "parameter name is required";
  }
  var onMessageReceived = namedArguments[const Symbol('onMessageReceived')];
  if (onMessageReceived == null) {
    throw "parameter onMessageReceived is required";
  }
  return JavascriptChannel(
      name: name as String,
      onMessageReceived: (JavascriptMessage message) {
        var msgIns = JavascriptMessageIns(message.message);
        (onMessageReceived as LoxFunction).call(interpreter, [msgIns], {});
      });
}