eval method

Future<EvalResult> eval(
  1. String expression,
  2. EvalOptions? options
)

Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. The eval function can report either a DevTools-side error or a JavaScript exception that occurs during evaluation. In either case, the result parameter of the callback is undefined. In the case of a DevTools-side error, the isException parameter is non-null and has isError set to true and code set to an error code. In the case of a JavaScript error, isException is set to true and value is set to the string value of thrown object. expression An expression to evaluate. options The options parameter can contain one or more options. returns A function called when evaluation completes.

Implementation

Future<EvalResult> eval(
  String expression,
  EvalOptions? options,
) {
  var $completer = Completer<EvalResult>();
  $js.chrome.devtools.inspectedWindow.eval(
    expression,
    options?.toJS,
    (
      JSAny result,
      $js.EvalExceptionInfo exceptionInfo,
    ) {
      if (checkRuntimeLastError($completer)) {
        $completer.complete(EvalResult(
          result: result.toDartMap(),
          exceptionInfo: EvalExceptionInfo.fromJS(exceptionInfo),
        ));
      }
    }.toJS,
  );
  return $completer.future;
}