evaluate method
Evaluate js script.
Implementation
Future<dynamic> evaluate(
String command, {
String? name,
int? evalFlags,
}) async {
_ensureEngine();
final evaluatePort = ReceivePort();
final sendPort = await _sendPort!;
final msg = {
#type: #evaluate,
#command: command,
#name: name,
#flag: evalFlags,
#port: evaluatePort.sendPort,
};
// Inject host functions once, on the first evaluate that follows
// setHostFunctions. Encoded as IsolateFunction refs (id + handle port).
if (_hostFunctions.isNotEmpty && !_hostFunctionsBound) {
msg[#functions] = _encodeData(_hostFunctions);
_hostFunctionsBound = true;
}
sendPort.send(msg);
final result = await evaluatePort.first;
evaluatePort.close();
if (result is Map && result.containsKey(#error)) {
throw _decodeData(result[#error]);
}
return _decodeData(result);
}