JavaScriptInvocationParams constructor

JavaScriptInvocationParams({
  1. required String functionBody,
  2. Map<String, Object?> arguments = const <String, Object?>{},
  3. Duration timeout = const Duration(seconds: 30),
})

Creates parameters for an asynchronous JavaScript invocation.

Implementation

JavaScriptInvocationParams({
  required this.functionBody,
  Map<String, Object?> arguments = const <String, Object?>{},
  this.timeout = const Duration(seconds: 30),
}) : arguments = UnmodifiableMapView<String, Object?>(
       arguments.map<String, Object?>((String key, Object? value) {
         if (!_javaScriptIdentifierPattern.hasMatch(key)) {
           throw ArgumentError.value(
             key,
             'arguments',
             'JavaScript argument names must be valid identifiers.',
           );
         }
         if (_reservedJavaScriptIdentifiers.contains(key)) {
           throw ArgumentError.value(
             key,
             'arguments',
             'JavaScript argument names must not be reserved words.',
           );
         }
         return MapEntry<String, Object?>(key, _freezeJsonValue(value));
       }),
     ) {
  if (functionBody.trim().isEmpty) {
    throw ArgumentError.value(
      functionBody,
      'functionBody',
      'The JavaScript function body must not be empty.',
    );
  }
  if (timeout <= Duration.zero) {
    throw ArgumentError.value(
      timeout,
      'timeout',
      'The JavaScript timeout must be greater than zero.',
    );
  }
}