From fe91fa32dbf0e57fcd7f28864fc2f7c3e8e0d9fa Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Wed, 24 Jun 2009 10:56:40 +0300 Subject: [PATCH] Add comments to the HTML5 parser explaining buffer chain key holders --- content/html/parser/src/nsHtml5Parser.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/html/parser/src/nsHtml5Parser.cpp b/content/html/parser/src/nsHtml5Parser.cpp index 7409b5de6de2..bd8dc16a8cd9 100644 --- a/content/html/parser/src/nsHtml5Parser.cpp +++ b/content/html/parser/src/nsHtml5Parser.cpp @@ -432,11 +432,22 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, } } if (buffer->hasMore()) { + // If we got here, the buffer wasn't parse synchronously to completion + // and it's tail needs to go into the chain of pending buffers. + // The script is identified by aKey. If there's nothing in the buffer + // chain for that key, we'll insert at the head of the queue. + // When the script leaves something in the queue, a zero-length + // key-holder "buffer" is inserted in the queue. If the same script + // leaves something in the chain again, it will be inserted immediately + // before the old key holder belonging to the same script. nsHtml5UTF16Buffer* prevSearchBuf = nsnull; nsHtml5UTF16Buffer* searchBuf = mFirstBuffer; if (aKey) { // after document.open, the first level of document.write has null key while (searchBuf != mLastBuffer) { if (searchBuf->key == aKey) { + // found a key holder + // now insert the new buffer between the previous buffer + // and the key holder. buffer->next = searchBuf; if (prevSearchBuf) { prevSearchBuf->next = buffer;