Future _collectAsyncFrames()

in dwds/lib/src/debugging/frame_computer.dart [81:130]


  Future<void> _collectAsyncFrames({int limit}) async {
    if (_asyncStackTrace == null) return;

    while (_asyncStackTrace != null) {
      if (limit != null && _computedFrames.length == limit) {
        return;
      }

      // We are processing a new set of async frames, add a suspension marker.
      if (_asyncFramesToProcess == null) {
        if (_computedFrames.isNotEmpty &&
            _computedFrames.last.kind != FrameKind.kAsyncSuspensionMarker) {
          _computedFrames.add(Frame(
              index: _frameIndex++, kind: FrameKind.kAsyncSuspensionMarker));
        }
        _asyncFramesToProcess = _asyncStackTrace.callFrames;
      } else {
        // Process a single async frame.
        if (_asyncFramesToProcess.isNotEmpty) {
          var callFrame = _asyncFramesToProcess.removeAt(0);
          var location = WipLocation.fromValues(
              callFrame.scriptId, callFrame.lineNumber,
              columnNumber: callFrame.columnNumber);
          var tempWipFrame = WipCallFrame({
            'url': callFrame.url,
            'functionName': callFrame.functionName,
            'location': location.json,
            'scopeChain': [],
          });

          var frame = await debugger.calculateDartFrameFor(
            tempWipFrame,
            _frameIndex++,
            populateVariables: false,
          );
          if (frame != null) {
            frame.kind = FrameKind.kAsyncCausal;
            _computedFrames.add(frame);
          }
        }
      }

      // Async frames are no longer on the stack - we don't have local variable
      // information for them.
      if (_asyncFramesToProcess.isEmpty) {
        _asyncStackTrace = _asyncStackTrace.parent;
        _asyncFramesToProcess = null;
      }
    }
  }