Backed out 2 changesets (bug 1926824) from beta for causing Bug 1927404

Backed out changeset 46d6710781aa (bug 1926824)
Backed out changeset 7b4d4dd97112 (bug 1926824)
This commit is contained in:
donal meehan 2024-10-28 09:51:21 -04:00
parent bf6b8778c1
commit 9729a56bc4
7 changed files with 36 additions and 108 deletions

View File

@ -52,12 +52,12 @@ void nsHtml5Highlighter::Rewind() {
mCurrentRun = nullptr;
mAmpersand = nullptr;
mSlash = nullptr;
mSeenBase = false;
// Pop until we have two elements on the stack: html and body.
while (mStack.Length() > 2) {
// Pop until we have three elements on the stack:
// html, body, and pre.
while (mStack.Length() > 3) {
Pop();
}
mSeenBase = false;
}
void nsHtml5Highlighter::Start(const nsAutoString& aTitle) {
@ -103,8 +103,14 @@ void nsHtml5Highlighter::Start(const nsAutoString& aTitle) {
Push(nsGkAtoms::body, nsHtml5ViewSourceUtils::NewBodyAttributes(),
NS_NewHTMLBodyElement);
// Don't call StartBodyContents here in order to be able to put it in a
// speculation.
nsHtml5HtmlAttributes* preAttrs = new nsHtml5HtmlAttributes(0);
nsHtml5String preId = nsHtml5Portability::newStringFromLiteral("line1");
preAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, preId, -1);
Push(nsGkAtoms::pre, preAttrs, NS_NewHTMLPreElement);
// Don't call StartCharacters here in order to be able to put it in
// a speculation.
mOpQueue.AppendElement()->Init(mozilla::AsVariant(opStartLayout()));
}
@ -498,12 +504,6 @@ void nsHtml5Highlighter::EndSpanOrA() {
--mInlinesOpen;
}
void nsHtml5Highlighter::StartBodyContents() {
MOZ_ASSERT(mLineNumber == 1);
PushCurrentLinePre();
StartCharacters();
}
void nsHtml5Highlighter::StartCharacters() {
MOZ_ASSERT(!mInCharacters, "Already in characters!");
FlushChars();
@ -561,7 +561,13 @@ void nsHtml5Highlighter::FlushChars() {
AppendCharacters(buf, mCStart, len);
mCStart = i;
}
NewLine();
++mLineNumber;
Push(nsGkAtoms::span, nullptr, NS_NewHTMLSpanElement);
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed.");
opAddLineNumberId operation(CurrentNode(), mLineNumber);
treeOp->Init(mozilla::AsVariant(operation));
Pop();
break;
}
default:
@ -577,43 +583,6 @@ void nsHtml5Highlighter::FlushChars() {
}
}
void nsHtml5Highlighter::PushCurrentLinePre() {
Push(nsGkAtoms::pre, nullptr, NS_NewHTMLPreElement);
mOpQueue.AppendElement()->Init(
mozilla::AsVariant(opAddLineNumberId(CurrentNode(), mLineNumber)));
}
// NOTE(emilio): It's important that nothing here ends up calling FlushChars(),
// since we're in the middle of a flush.
void nsHtml5Highlighter::NewLine() {
++mLineNumber;
AutoTArray<nsIContent**, 8> handleStack;
const bool wasInCharacters = mInCharacters;
if (mInCharacters) {
Pop();
mInCharacters = false;
}
while (mInlinesOpen) {
handleStack.AppendElement(CurrentNode());
Pop();
mInlinesOpen--;
}
Pop(); // Pop the <pre>
PushCurrentLinePre();
for (nsIContent** handle : Reversed(handleStack)) {
nsIContent** dest = AllocateContentHandle();
mOpQueue.AppendElement()->Init(mozilla::AsVariant(opShallowCloneInto(
handle, dest, CurrentNode(), mozilla::dom::FROM_PARSER_NETWORK)));
mStack.AppendElement(dest);
++mInlinesOpen;
}
if (wasInCharacters) {
Push(nsGkAtoms::span, nullptr, NS_NewHTMLSpanElement);
mCurrentRun = CurrentNode();
mInCharacters = true;
}
}
void nsHtml5Highlighter::FlushCurrent() {
mPos++;
FlushChars();
@ -682,14 +651,14 @@ nsIContent** nsHtml5Highlighter::CreateElement(
}
nsIContent** nsHtml5Highlighter::CurrentNode() {
MOZ_ASSERT(!mStack.IsEmpty(), "Must have something on stack.");
return mStack.LastElement();
MOZ_ASSERT(mStack.Length() >= 1, "Must have something on stack.");
return mStack[mStack.Length() - 1];
}
void nsHtml5Highlighter::Push(
nsAtom* aName, nsHtml5HtmlAttributes* aAttributes,
mozilla::dom::HTMLContentCreatorFunction aCreator) {
MOZ_ASSERT(!mStack.IsEmpty(), "Pushing without root.");
MOZ_ASSERT(mStack.Length() >= 1, "Pushing without root.");
nsIContent** elt = CreateElement(aName, aAttributes, CurrentNode(),
aCreator); // Don't inline below!
opAppend operation(elt, CurrentNode(), mozilla::dom::FROM_PARSER_NETWORK);

View File

@ -173,15 +173,12 @@ class nsHtml5Highlighter {
*/
void AddBase(nsHtml5String aValue);
/** Starts the body */
void StartBodyContents();
private:
/**
* Starts a wrapper around a run of characters.
*/
void StartCharacters();
private:
/**
* Starts a span with no class.
*/
@ -200,7 +197,9 @@ class nsHtml5Highlighter {
*/
void EndSpanOrA();
/** Ends a wrapper around a run of characters. */
/**
* Ends a wrapper around a run of characters.
*/
void EndCharactersAndStartMarkupRun();
/**
@ -277,15 +276,6 @@ class nsHtml5Highlighter {
void Push(nsAtom* aName, nsHtml5HtmlAttributes* aAttributes,
mozilla::dom::HTMLContentCreatorFunction aCreator);
/** Pushes a <pre id="line<lineno>"> */
void PushCurrentLinePre();
/**
* Pops all inlines from the stack, pushes a pre, and pushes all inlines back
* with the same attributes.
*/
void NewLine();
/**
* Pops the current node off the stack.
*/

View File

@ -443,7 +443,7 @@ void nsHtml5StreamParser::SetupDecodingFromBom(
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource, false);
mBomState = BOM_SNIFFING_OVER;
if (mMode == VIEW_SOURCE_HTML) {
mTokenizer->StartViewSourceBodyContents();
mTokenizer->StartViewSourceCharacters();
}
}
@ -460,7 +460,7 @@ void nsHtml5StreamParser::SetupDecodingFromUtf16BogoXml(
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource, false);
mBomState = BOM_SNIFFING_OVER;
if (mMode == VIEW_SOURCE_HTML) {
mTokenizer->StartViewSourceBodyContents();
mTokenizer->StartViewSourceCharacters();
}
auto dst = mLastBuffer->TailAsSpan(READ_BUFFER_SIZE);
dst[0] = '<';
@ -782,7 +782,7 @@ nsresult nsHtml5StreamParser::SniffStreamBytes(Span<const uint8_t> aFromSegment,
MOZ_ASSERT(!mFlushTimerArmed, "How did we end up arming the timer?");
if (mMode == VIEW_SOURCE_HTML) {
mTokenizer->SetViewSourceOpSink(speculation);
mTokenizer->StartViewSourceBodyContents();
mTokenizer->StartViewSourceCharacters();
} else {
MOZ_ASSERT(mMode != VIEW_SOURCE_XML);
mTreeBuilder->SetOpSink(speculation);
@ -794,7 +794,7 @@ nsresult nsHtml5StreamParser::SniffStreamBytes(Span<const uint8_t> aFromSegment,
mBufferingBytes = false;
mDecodingLocalFileWithoutTokenizing = false;
if (mMode == VIEW_SOURCE_HTML) {
mTokenizer->StartViewSourceBodyContents();
mTokenizer->StartViewSourceCharacters();
}
}
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource, false);
@ -1149,7 +1149,7 @@ nsresult nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest) {
// pre element start.
mTokenizer->StartViewSource(NS_ConvertUTF8toUTF16(mViewSourceTitle));
if (mMode == VIEW_SOURCE_XML) {
mTokenizer->StartViewSourceBodyContents();
mTokenizer->StartViewSourceCharacters();
}
// Flush the ops to put them where ContinueAfterScriptsOrEncodingCommitment
// can find them.
@ -2019,7 +2019,7 @@ void nsHtml5StreamParser::DiscardMetaSpeculation() {
MOZ_ASSERT(!mFlushTimerArmed, "How did we end up arming the timer?");
if (mMode == VIEW_SOURCE_HTML) {
mTokenizer->SetViewSourceOpSink(speculation);
mTokenizer->StartViewSourceBodyContents();
mTokenizer->StartViewSourceCharacters();
} else {
MOZ_ASSERT(mMode != VIEW_SOURCE_XML);
mTreeBuilder->SetOpSink(speculation);

View File

@ -94,8 +94,8 @@ void nsHtml5Tokenizer::StartViewSource(const nsAutoString& aTitle) {
mViewSource->Start(aTitle);
}
void nsHtml5Tokenizer::StartViewSourceBodyContents() {
mViewSource->StartBodyContents();
void nsHtml5Tokenizer::StartViewSourceCharacters() {
mViewSource->StartCharacters();
}
[[nodiscard]] bool nsHtml5Tokenizer::EndViewSource() {

View File

@ -59,7 +59,7 @@ mozilla::Result<bool, nsresult> FlushViewSource();
void StartViewSource(const nsAutoString& aTitle);
void StartViewSourceBodyContents();
void StartViewSourceCharacters();
[[nodiscard]] bool EndViewSource();

View File

@ -203,8 +203,6 @@ nsHtml5TreeOperation::~nsHtml5TreeOperation() {
void operator()(const opAddLineNumberId& aOperation) {}
void operator()(const opShallowCloneInto& aOperation) {}
void operator()(const opStartLayout& aOperation) {}
void operator()(const opEnableEncodingMenu& aOperation) {}
@ -1209,19 +1207,6 @@ nsresult nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
return NS_OK;
}
nsresult operator()(const opShallowCloneInto& aOperation) {
nsIContent* src = *aOperation.mSrc;
ErrorResult rv;
RefPtr<nsINode> clone = src->CloneNode(false, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
*aOperation.mDst = clone->AsContent();
mBuilder->HoldElement(clone.forget().downcast<nsIContent>());
return Append(*aOperation.mDst, *aOperation.mIntendedParent,
aOperation.mFromParser, mBuilder);
}
nsresult operator()(const opStartLayout& aOperation) {
mBuilder->StartLayout(
mInterrupted); // this causes a notification flush anyway

View File

@ -511,22 +511,6 @@ struct opAddErrorType {
};
};
struct opShallowCloneInto {
nsIContent** mSrc;
nsIContent** mDst;
nsIContent** mIntendedParent;
mozilla::dom::FromParser mFromParser;
opShallowCloneInto(nsIContentHandle* aSrc, nsIContentHandle* aDst,
nsIContentHandle* aIntendedParent,
mozilla::dom::FromParser aFromParser)
: mFromParser(aFromParser) {
mSrc = static_cast<nsIContent**>(aSrc);
mDst = static_cast<nsIContent**>(aDst);
mIntendedParent = static_cast<nsIContent**>(aIntendedParent);
};
};
struct opAddLineNumberId {
nsIContent** mElement;
int32_t mLineNumber;
@ -560,7 +544,7 @@ typedef mozilla::Variant<
opSetScriptLineAndColumnNumberAndFreeze, opSvgLoad,
opMaybeComplainAboutCharset, opMaybeComplainAboutDeepTree, opAddClass,
opAddViewSourceHref, opAddViewSourceBase, opAddErrorType, opAddLineNumberId,
opStartLayout, opEnableEncodingMenu, opShallowCloneInto>
opStartLayout, opEnableEncodingMenu>
treeOperation;
class nsHtml5TreeOperation final {