void BackgroundHTMLInputStream::rewindTo(HTMLInputCheckpoint checkpointIndex,
                                         const String& unparsedInput) {
  ASSERT(checkpointIndex <
         m_checkpoints
             .size());  // If this ASSERT fires, checkpointIndex is invalid.
  const Checkpoint& checkpoint = m_checkpoints[checkpointIndex];
  ASSERT(!checkpoint.isNull());

  bool isClosed = m_current.isClosed();

  m_current = checkpoint.input;

  for (size_t i = checkpoint.numberOfSegmentsAlreadyAppended;
       i < m_segments.size(); ++i) {
    ASSERT(!m_segments[i].isNull());
    m_current.append(SegmentedString(m_segments[i]));
  }

  if (!unparsedInput.isEmpty()) {
    m_current.prepend(SegmentedString(unparsedInput),
                      SegmentedString::PrependType::NewInput);
  }

  if (isClosed && !m_current.isClosed())
    m_current.close();

  ASSERT(m_current.isClosed() == isClosed);

  m_segments.clear();
  m_checkpoints.clear();
  m_firstValidCheckpointIndex = 0;
  m_firstValidSegmentIndex = 0;

  updateTotalCheckpointTokenCount();
}
Esempio n. 2
0
void BackgroundHTMLInputStream::rewindTo(HTMLInputCheckpoint checkpointIndex, const String& unparsedInput)
{
    ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, checkpointIndex is invalid.
    const Checkpoint& checkpoint = m_checkpoints[checkpointIndex];

    bool isClosed = m_current.isClosed();

    m_current = checkpoint.input;

    for (size_t i = checkpoint.numberOfSegmentsAlreadyAppended; i < m_segments.size(); ++i)
        m_current.append(SegmentedString(m_segments[i]));

    if (!unparsedInput.isEmpty())
        m_current.prepend(SegmentedString(unparsedInput));

    if (isClosed && !m_current.isClosed())
        m_current.close();

    m_segments.clear();
    m_checkpoints.clear();
}
Esempio n. 3
0
void SegmentedString::push(UChar c) {
  ASSERT(c);

  // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring,
  // however it will fail if the SegmentedSubstring is empty, or
  // when we prepended some text while consuming a SegmentedSubstring by
  // document.write().
  if (m_currentString.pushIfPossible(c)) {
    m_currentChar = c;
    return;
  }

  prepend(SegmentedString(String(&c, 1)), PrependType::Unconsume);
}
void BackgroundHTMLInputStream::append(const String& input) {
  m_current.append(SegmentedString(input));
  m_segments.append(input);
}