callInterpretedToString function

Object? callInterpretedToString(
  1. InterpretedFunction method,
  2. RuntimeValue target,
  3. InterpreterVisitor visitor
)

Calls an interpreted toString and returns what it produced, unwrapping the ReturnException a block-bodied one throws.

The STRICT half: nothing is caught, so a throwing toString propagates and toString() => '$this' overflows the stack. That is Dart's behaviour and it is what InterpreterVisitor.stringify needs, because stringify renders interpolation INSIDE a script. renderInterpretedToString wraps this for the host-facing path, which needs the opposite.

Implementation

Object? callInterpretedToString(
  InterpretedFunction method,
  RuntimeValue target,
  InterpreterVisitor visitor,
) {
  try {
    return method
        .bind(target)
        .call(visitor, const <Object?>[], const <String, Object?>{});
  } on ReturnException catch (e) {
    return e.value;
  }
}