callFunctionOn method
Calls function with given declaration on the given object. Object group of the result is inherited from the target object.
Each element in arguments
must be either a RemoteObject or a primitive
object (int, String, double, bool).
Implementation
Future<RemoteObject> callFunctionOn(
String functionDeclaration, {
String? objectId,
List<dynamic>? arguments,
bool? returnByValue,
int? executionContextId,
}) async {
Map<String, dynamic> params = {
'functionDeclaration': functionDeclaration,
};
if (objectId != null) {
params['objectId'] = objectId;
}
if (returnByValue != null) {
params['returnByValue'] = returnByValue;
}
if (executionContextId != null) {
params['executionContextId'] = executionContextId;
}
if (arguments != null) {
// Convert a list of RemoteObjects and primitive values to CallArguments.
params['arguments'] = arguments.map((dynamic value) {
if (value is RemoteObject) {
return {'objectId': value.objectId};
} else {
return {'value': value};
}
}).toList();
}
final WipResponse response =
await sendCommand('Runtime.callFunctionOn', params: params);
if (response.result!.containsKey('exceptionDetails')) {
throw ExceptionDetails(
response.result!['exceptionDetails'] as Map<String, dynamic>);
} else {
return RemoteObject(response.result!['result'] as Map<String, dynamic>);
}
}