Bug 256180 parser part - Insert elements as siblings instead of children at the Blink-defined magic depth for compatibility. r=smaug

MozReview-Commit-ID: K8fgv3rgklt

--HG--
extra : rebase_source : 3ad91a01805afcd1aeac89a5f2d5ac38dac1797b
This commit is contained in:
Henri Sivonen 2017-09-12 16:57:05 +03:00
Родитель ef3dabbc29
Коммит b245e01efe
19 изменённых файлов: 6405 добавлений и 208 удалений

Просмотреть файл

@ -83,6 +83,7 @@ errNoSpaceBetweenPublicAndSystemIds=No space between the doctype public and syst
errNoSpaceBetweenDoctypePublicKeywordAndQuote=No space between the doctype “PUBLIC” keyword and the quote.
# Tree builder errors
errDeepTree=The document tree is too deep. The tree will be flattened to be 513 elements deep.
errStrayStartTag2=Stray start tag “%1$S”.
errStrayEndTag=Stray end tag “%1$S”.
errUnclosedElements=End tag “%1$S” seen, but there were open elements.

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -53,6 +53,8 @@ skip-if(isDebugBuild||Android||AddressSanitizer||(winWidget&&(!is64Bit))) == 256
# Debug builds have larger stack frames, so skipped.
# Making Android on aarch64 not crash is bug 1400811.
skip-if(isDebugBuild||(Android&&is64Bit)) == 256180-4.html 256180-4-ref.html
skip-if(isDebugBuild||(Android&&is64Bit)) == 256180-5.html 256180-5-ref.html
skip-if(isDebugBuild||(Android&&is64Bit)) == 256180-6.html 256180-6-ref.html
== 25888-1l.html 25888-1l-ref.html
!= 25888-1l.html 25888-1l-notref.html
== 25888-1r.html 25888-1r-ref.html

Просмотреть файл

@ -1,22 +1,22 @@
/*
* Copyright (c) 2009-2010 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@ -37,12 +37,10 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
private final T headPointer;
private final T deepTreeSurrogateParent;
private final int mode;
private final int originalMode;
private final boolean framesetOk;
private final boolean needToDropLF;
@ -55,7 +53,6 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
* @param templateModeStack
* @param formPointer
* @param headPointer
* @param deepTreeSurrogateParent
* @param mode
* @param originalMode
* @param framesetOk
@ -64,21 +61,20 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
*/
StateSnapshot(StackNode<T>[] stack,
StackNode<T>[] listOfActiveFormattingElements, int[] templateModeStack, T formPointer,
T headPointer, T deepTreeSurrogateParent, int mode, int originalMode,
T headPointer, int mode, int originalMode,
boolean framesetOk, boolean needToDropLF, boolean quirks) {
this.stack = stack;
this.listOfActiveFormattingElements = listOfActiveFormattingElements;
this.templateModeStack = templateModeStack;
this.formPointer = formPointer;
this.headPointer = headPointer;
this.deepTreeSurrogateParent = deepTreeSurrogateParent;
this.mode = mode;
this.originalMode = originalMode;
this.framesetOk = framesetOk;
this.needToDropLF = needToDropLF;
this.quirks = quirks;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getStack()
*/
@ -109,25 +105,16 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
/**
* Returns the headPointer.
*
*
* @return the headPointer
*/
public T getHeadPointer() {
return headPointer;
}
/**
* Returns the deepTreeSurrogateParent.
*
* @return the deepTreeSurrogateParent
*/
public T getDeepTreeSurrogateParent() {
return deepTreeSurrogateParent;
}
/**
* Returns the mode.
*
*
* @return the mode
*/
public int getMode() {
@ -136,7 +123,7 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
/**
* Returns the originalMode.
*
*
* @return the originalMode
*/
public int getOriginalMode() {
@ -145,7 +132,7 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
/**
* Returns the framesetOk.
*
*
* @return the framesetOk
*/
public boolean isFramesetOk() {
@ -154,7 +141,7 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
/**
* Returns the needToDropLF.
*
*
* @return the needToDropLF
*/
public boolean isNeedToDropLF() {
@ -163,13 +150,13 @@ public class StateSnapshot<T> implements TreeBuilderState<T> {
/**
* Returns the quirks.
*
*
* @return the quirks
*/
public boolean isQuirks() {
return quirks;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElementsLength()
*/

Просмотреть файл

@ -444,11 +444,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
private T headPointer;
/**
* Used to work around Gecko limitations. Not used in Java.
*/
private T deepTreeSurrogateParent;
protected @Auto char[] charBuffer;
protected int charBufferLen = 0;
@ -615,7 +610,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
listPtr = -1;
formPointer = null;
headPointer = null;
deepTreeSurrogateParent = null;
// [NOCPP[
html4 = false;
idLocations.clear();
@ -1642,7 +1636,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
public final void endTokenization() throws SAXException {
formPointer = null;
headPointer = null;
deepTreeSurrogateParent = null;
templateModeStack = null;
if (stack != null) {
while (currentPtr > -1) {
@ -4718,7 +4711,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
removeFromListOfActiveFormattingElements(formattingEltListPos);
return true;
}
// commonAncestor is used for running the algorithm and
// insertionCommonAncestor is used for the actual insertions to
// keep them depth-limited.
StackNode<T> commonAncestor = stack[formattingEltStackPos - 1]; // weak ref
T insertionCommonAncestor = nodeFromStackWithBlinkCompat(formattingEltStackPos - 1); // weak ref
StackNode<T> furthestBlock = stack[furthestBlockPos]; // weak ref
// detachFromParent(furthestBlock.node); XXX AAA CHANGE
int bookmark = formattingEltListPos;
@ -4766,7 +4763,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
assert node == listOfActiveFormattingElements[nodeListPos];
assert node == stack[nodePos];
T clone = createElement("http://www.w3.org/1999/xhtml",
node.name, node.attributes.cloneAttributes(null), commonAncestor.node
node.name, node.attributes.cloneAttributes(null), insertionCommonAncestor
// CPPONLY: , htmlCreator(node.getHtmlCreator())
);
StackNode<T> newNode = createStackNode(node.getFlags(), node.ns,
@ -4785,16 +4782,18 @@ public abstract class TreeBuilder<T> implements TokenHandler,
node = newNode;
// } XXX AAA CHANGE
detachFromParent(lastNode.node);
appendElement(lastNode.node, node.node);
appendElement(lastNode.node, nodeFromStackWithBlinkCompat(nodePos));
lastNode = node;
}
// If we insert into a foster parent, for simplicity, we insert
// accoding to the spec without Blink's depth limit.
if (commonAncestor.isFosterParenting()) {
fatal();
detachFromParent(lastNode.node);
insertIntoFosterParent(lastNode.node);
} else {
detachFromParent(lastNode.node);
appendElement(lastNode.node, commonAncestor.node);
appendElement(lastNode.node, insertionCommonAncestor);
}
T clone = createElement("http://www.w3.org/1999/xhtml",
formattingElt.name,
@ -4980,20 +4979,21 @@ public abstract class TreeBuilder<T> implements TokenHandler,
while (entryPos < listPtr) {
entryPos++;
StackNode<T> entry = listOfActiveFormattingElements[entryPos];
StackNode<T> currentNode = stack[currentPtr];
StackNode<T> current = stack[currentPtr];
T clone;
if (currentNode.isFosterParenting()) {
if (current.isFosterParenting()) {
clone = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", entry.name,
entry.attributes.cloneAttributes(null)
// CPPONLY: , htmlCreator(entry.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
clone = createElement("http://www.w3.org/1999/xhtml", entry.name,
entry.attributes.cloneAttributes(null), currentNode.node
entry.attributes.cloneAttributes(null), currentNode
// CPPONLY: , htmlCreator(entry.getHtmlCreator())
);
appendElement(clone, currentNode.node);
appendElement(clone, currentNode);
}
StackNode<T> entryClone = createStackNode(entry.getFlags(),
@ -5336,7 +5336,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
T currentNode = stack[currentPtr].node;
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", "head", attributes, currentNode
/*
* head uses NS_NewHTMLSharedElement creator
@ -5378,10 +5378,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(NS_NewHTMLFormElement)
);
} else {
elt = createElement("http://www.w3.org/1999/xhtml", "form", attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", "form", attributes, currentNode
// CPPONLY: , htmlCreator(NS_NewHTMLFormElement)
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
if (!isTemplateContents()) {
@ -5415,10 +5416,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(), attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(), attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt, clone
// [NOCPP[
@ -5437,7 +5439,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// This method can't be called for custom elements
T currentNode = stack[currentPtr].node;
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(), attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
@ -5471,10 +5473,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
elt = createElement("http://www.w3.org/1999/xhtml", popName, attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", popName, attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt, popName
// [NOCPP[
@ -5509,10 +5512,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(null)
);
} else {
elt = createElement("http://www.w3.org/1998/Math/MathML", popName, attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1998/Math/MathML", popName, attributes, currentNode
// CPPONLY: , htmlCreator(null)
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt, popName,
markAsHtmlIntegrationPoint
@ -5562,10 +5566,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
} else {
elt = createElement("http://www.w3.org/2000/svg", popName, attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/2000/svg", popName, attributes, currentNode
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, popName, elt
// [NOCPP[
@ -5592,11 +5597,12 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(),
attributes, formOwner, current.node
attributes, formOwner, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt
// [NOCPP[
@ -5623,11 +5629,12 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", name,
attributes, formOwner, current.node
attributes, formOwner, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/1999/xhtml", name, elt);
elementPopped("http://www.w3.org/1999/xhtml", name, elt);
@ -5651,10 +5658,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
elt = createElement("http://www.w3.org/1999/xhtml", popName, attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", popName, attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/1999/xhtml", popName, elt);
elementPopped("http://www.w3.org/1999/xhtml", popName, elt);
@ -5678,10 +5686,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
} else {
elt = createElement("http://www.w3.org/2000/svg", popName, attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/2000/svg", popName, attributes, currentNode
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/2000/svg", popName, elt);
elementPopped("http://www.w3.org/2000/svg", popName, elt);
@ -5705,10 +5714,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// CPPONLY: , htmlCreator(null)
);
} else {
elt = createElement("http://www.w3.org/1998/Math/MathML", popName, attributes, current.node
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1998/Math/MathML", popName, attributes, currentNode
// CPPONLY: , htmlCreator(null)
);
appendElement(elt, current.node);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/1998/Math/MathML", popName, elt);
elementPopped("http://www.w3.org/1998/Math/MathML", popName, elt);
@ -5719,7 +5729,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// Can't be called for custom elements
T currentNode = stack[currentPtr].node;
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", "input", attributes,
form == null || fragment || isTemplateContents() ? null : form, currentNode
// CPPONLY: , htmlCreator(NS_NewHTMLInputElement)
@ -5733,7 +5743,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
T currentNode = stack[currentPtr].node;
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", "form",
attributes, currentNode
// CPPONLY: , htmlCreator(NS_NewHTMLFormElement)
@ -6145,7 +6155,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
System.arraycopy(templateModeStack, 0, templateModeStackCopy, 0,
templateModeStackCopy.length);
return new StateSnapshot<T>(stackCopy, listCopy, templateModeStackCopy, formPointer,
headPointer, deepTreeSurrogateParent, mode, originalMode, framesetOk,
headPointer, mode, originalMode, framesetOk,
needToDropLF, quirks);
}
@ -6162,7 +6172,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
|| templateModeStackLen != templateModePtr + 1
|| formPointer != snapshot.getFormPointer()
|| headPointer != snapshot.getHeadPointer()
|| deepTreeSurrogateParent != snapshot.getDeepTreeSurrogateParent()
|| mode != snapshot.getMode()
|| originalMode != snapshot.getOriginalMode()
|| framesetOk != snapshot.isFramesetOk()
@ -6268,7 +6277,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
System.arraycopy(templateModeStackCopy, 0, templateModeStack, 0, templateModeStackLen);
formPointer = snapshot.getFormPointer();
headPointer = snapshot.getHeadPointer();
deepTreeSurrogateParent = snapshot.getDeepTreeSurrogateParent();
mode = snapshot.getMode();
originalMode = snapshot.getOriginalMode();
framesetOk = snapshot.isFramesetOk();
@ -6285,6 +6293,33 @@ public abstract class TreeBuilder<T> implements TokenHandler,
return -1;
}
/**
* Returns <code>stack[stackPos].node</code> if <code>stackPos</code> is
* smaller than Blink's magic limit or the node at Blink's magic limit
* otherwise.
*
* In order to get Blink-compatible handling of excessive deeply-nested
* markup, this method must be used to obtain the node that is used as the
* parent node of an insertion.
*
* Blink's magic number is 512, but our counting is off by one compared to
* Blink's way of counting, so in order to get the same
* externally-observable outcome, we use 511 as our magic number.
*
* @param stackPos the stack position to attempt to read
* @return node at the position capped to Blink's magic number
* @throws SAXException
*/
private T nodeFromStackWithBlinkCompat(int stackPos) throws SAXException {
// Magic number if off by one relative to Blink's magic number, but the
// outcome is the same, because the counting is different by one.
if (stackPos > 511) {
errDeepTree();
return stack[511].node;
}
return stack[stackPos].node;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getFormPointer()
*/
@ -6301,15 +6336,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
return headPointer;
}
/**
* Returns the deepTreeSurrogateParent.
*
* @return the deepTreeSurrogateParent
*/
public T getDeepTreeSurrogateParent() {
return deepTreeSurrogateParent;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElements()
*/
@ -6397,6 +6423,16 @@ public abstract class TreeBuilder<T> implements TokenHandler,
return templateModePtr + 1;
}
/**
* Complains about an over-deep tree. Theoretically this should just be
* a warning, but in practice authors should take this as an error.
*
* @throws SAXException
*/
private void errDeepTree() throws SAXException {
err("The document tree is more than 513 elements deep, which causes Firefox and Chrome flatten the tree.");
}
/**
* Reports a stray start tag.
* @param name the name of the stray tag

Просмотреть файл

@ -31,8 +31,6 @@ class nsAHtml5TreeBuilderState {
virtual nsIContentHandle* getHeadPointer() = 0;
virtual nsIContentHandle* getDeepTreeSurrogateParent() = 0;
virtual int32_t getMode() = 0;
virtual int32_t getOriginalMode() = 0;

Просмотреть файл

@ -1,22 +1,22 @@
/*
* Copyright (c) 2009-2010 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@ -54,19 +54,27 @@
#include "nsHtml5StateSnapshot.h"
nsHtml5StateSnapshot::nsHtml5StateSnapshot(jArray<nsHtml5StackNode*,int32_t> stack, jArray<nsHtml5StackNode*,int32_t> listOfActiveFormattingElements, jArray<int32_t,int32_t> templateModeStack, nsIContentHandle* formPointer, nsIContentHandle* headPointer, nsIContentHandle* deepTreeSurrogateParent, int32_t mode, int32_t originalMode, bool framesetOk, bool needToDropLF, bool quirks)
: stack(stack),
listOfActiveFormattingElements(listOfActiveFormattingElements),
templateModeStack(templateModeStack),
formPointer(formPointer),
headPointer(headPointer),
deepTreeSurrogateParent(deepTreeSurrogateParent),
mode(mode),
originalMode(originalMode),
framesetOk(framesetOk),
needToDropLF(needToDropLF),
quirks(quirks)
nsHtml5StateSnapshot::nsHtml5StateSnapshot(
jArray<nsHtml5StackNode*, int32_t> stack,
jArray<nsHtml5StackNode*, int32_t> listOfActiveFormattingElements,
jArray<int32_t, int32_t> templateModeStack,
nsIContentHandle* formPointer,
nsIContentHandle* headPointer,
int32_t mode,
int32_t originalMode,
bool framesetOk,
bool needToDropLF,
bool quirks)
: stack(stack)
, listOfActiveFormattingElements(listOfActiveFormattingElements)
, templateModeStack(templateModeStack)
, formPointer(formPointer)
, headPointer(headPointer)
, mode(mode)
, originalMode(originalMode)
, framesetOk(framesetOk)
, needToDropLF(needToDropLF)
, quirks(quirks)
{
MOZ_COUNT_CTOR(nsHtml5StateSnapshot);
}
@ -101,12 +109,6 @@ nsHtml5StateSnapshot::getHeadPointer()
return headPointer;
}
nsIContentHandle*
nsHtml5StateSnapshot::getDeepTreeSurrogateParent()
{
return deepTreeSurrogateParent;
}
int32_t
nsHtml5StateSnapshot::getMode()
{

Просмотреть файл

@ -1,22 +1,22 @@
/*
* Copyright (c) 2009-2010 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@ -63,20 +63,28 @@ class nsHtml5StateSnapshot : public nsAHtml5TreeBuilderState
autoJArray<int32_t,int32_t> templateModeStack;
nsIContentHandle* formPointer;
nsIContentHandle* headPointer;
nsIContentHandle* deepTreeSurrogateParent;
int32_t mode;
int32_t originalMode;
bool framesetOk;
bool needToDropLF;
bool quirks;
public:
nsHtml5StateSnapshot(jArray<nsHtml5StackNode*,int32_t> stack, jArray<nsHtml5StackNode*,int32_t> listOfActiveFormattingElements, jArray<int32_t,int32_t> templateModeStack, nsIContentHandle* formPointer, nsIContentHandle* headPointer, nsIContentHandle* deepTreeSurrogateParent, int32_t mode, int32_t originalMode, bool framesetOk, bool needToDropLF, bool quirks);
nsHtml5StateSnapshot(
jArray<nsHtml5StackNode*, int32_t> stack,
jArray<nsHtml5StackNode*, int32_t> listOfActiveFormattingElements,
jArray<int32_t, int32_t> templateModeStack,
nsIContentHandle* formPointer,
nsIContentHandle* headPointer,
int32_t mode,
int32_t originalMode,
bool framesetOk,
bool needToDropLF,
bool quirks);
jArray<nsHtml5StackNode*,int32_t> getStack();
jArray<int32_t,int32_t> getTemplateModeStack();
jArray<nsHtml5StackNode*,int32_t> getListOfActiveFormattingElements();
nsIContentHandle* getFormPointer();
nsIContentHandle* getHeadPointer();
nsIContentHandle* getDeepTreeSurrogateParent();
int32_t getMode();
int32_t getOriginalMode();
bool isFramesetOk();

Просмотреть файл

@ -87,7 +87,6 @@ nsHtml5TreeBuilder::startTokenization(nsHtml5Tokenizer* self)
listPtr = -1;
formPointer = nullptr;
headPointer = nullptr;
deepTreeSurrogateParent = nullptr;
start(fragment);
charBufferLen = 0;
charBuffer = nullptr;
@ -609,7 +608,6 @@ nsHtml5TreeBuilder::endTokenization()
{
formPointer = nullptr;
headPointer = nullptr;
deepTreeSurrogateParent = nullptr;
templateModeStack = nullptr;
if (stack) {
while (currentPtr > -1) {
@ -3675,6 +3673,8 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
return true;
}
nsHtml5StackNode* commonAncestor = stack[formattingEltStackPos - 1];
nsIContentHandle* insertionCommonAncestor =
nodeFromStackWithBlinkCompat(formattingEltStackPos - 1);
nsHtml5StackNode* furthestBlock = stack[furthestBlockPos];
int32_t bookmark = formattingEltListPos;
int32_t nodePos = furthestBlockPos;
@ -3715,7 +3715,7 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
createElement(kNameSpaceID_XHTML,
node->name,
node->attributes->cloneAttributes(nullptr),
commonAncestor->node,
insertionCommonAncestor,
htmlCreator(node->getHtmlCreator()));
nsHtml5StackNode* newNode = createStackNode(node->getFlags(),
node->ns,
@ -3732,7 +3732,7 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
node->release(this);
node = newNode;
detachFromParent(lastNode->node);
appendElement(lastNode->node, node->node);
appendElement(lastNode->node, nodeFromStackWithBlinkCompat(nodePos));
lastNode = node;
}
if (commonAncestor->isFosterParenting()) {
@ -3741,7 +3741,7 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
insertIntoFosterParent(lastNode->node);
} else {
detachFromParent(lastNode->node);
appendElement(lastNode->node, commonAncestor->node);
appendElement(lastNode->node, insertionCommonAncestor);
}
nsIContentHandle* clone =
createElement(kNameSpaceID_XHTML,
@ -3916,21 +3916,22 @@ nsHtml5TreeBuilder::reconstructTheActiveFormattingElements()
while (entryPos < listPtr) {
entryPos++;
nsHtml5StackNode* entry = listOfActiveFormattingElements[entryPos];
nsHtml5StackNode* currentNode = stack[currentPtr];
nsHtml5StackNode* current = stack[currentPtr];
nsIContentHandle* clone;
if (currentNode->isFosterParenting()) {
if (current->isFosterParenting()) {
clone = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML,
entry->name,
entry->attributes->cloneAttributes(nullptr),
htmlCreator(entry->getHtmlCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
clone = createElement(kNameSpaceID_XHTML,
entry->name,
entry->attributes->cloneAttributes(nullptr),
currentNode->node,
currentNode,
htmlCreator(entry->getHtmlCreator()));
appendElement(clone, currentNode->node);
appendElement(clone, currentNode);
}
nsHtml5StackNode* entryClone = createStackNode(entry->getFlags(),
entry->ns,
@ -4152,7 +4153,7 @@ nsHtml5TreeBuilder::appendHtmlElementToDocumentAndPush()
void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes* attributes)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
nsIContentHandle* elt = createElement(kNameSpaceID_XHTML,
nsGkAtoms::head,
attributes,
@ -4189,12 +4190,13 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAt
attributes,
htmlCreator(NS_NewHTMLFormElement));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_XHTML,
nsGkAtoms::form,
attributes,
current->node,
currentNode,
htmlCreator(NS_NewHTMLFormElement));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
if (!isTemplateContents()) {
formPointer = elt;
@ -4217,12 +4219,13 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormattingElementMayFoster(nsHtml5
attributes,
htmlCreator(elementName->getHtmlCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_XHTML,
elementName->getName(),
attributes,
current->node,
currentNode,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
nsHtml5StackNode* node = createStackNode(elementName, elt, clone);
push(node);
@ -4233,7 +4236,7 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormattingElementMayFoster(nsHtml5
void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushElement(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
nsIContentHandle* elt =
createElement(kNameSpaceID_XHTML,
elementName->getName(),
@ -4262,12 +4265,13 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementNam
attributes,
htmlCreator(elementName->getHtmlCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_XHTML,
popName,
attributes,
current->node,
currentNode,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
nsHtml5StackNode* node = createStackNode(elementName, elt, popName);
push(node);
@ -4288,12 +4292,13 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterMathML(nsHtml5Elem
elt = createAndInsertFosterParentedElement(
kNameSpaceID_MathML, popName, attributes, htmlCreator(nullptr));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_MathML,
popName,
attributes,
current->node,
currentNode,
htmlCreator(nullptr));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
nsHtml5StackNode* node =
createStackNode(elementName, elt, popName, markAsHtmlIntegrationPoint);
@ -4325,12 +4330,13 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterSVG(nsHtml5Element
attributes,
svgCreator(elementName->getSvgCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_SVG,
popName,
attributes,
current->node,
currentNode,
svgCreator(elementName->getSvgCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
nsHtml5StackNode* node = createStackNode(elementName, popName, elt);
push(node);
@ -4351,13 +4357,14 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementNam
formOwner,
htmlCreator(elementName->getHtmlCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_XHTML,
elementName->getName(),
attributes,
formOwner,
current->node,
currentNode,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
nsHtml5StackNode* node = createStackNode(elementName, elt);
push(node);
@ -4382,13 +4389,14 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(
formOwner,
htmlCreator(elementName->getHtmlCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_XHTML,
name,
attributes,
formOwner,
current->node,
currentNode,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
elementPushed(kNameSpaceID_XHTML, name, elt);
elementPopped(kNameSpaceID_XHTML, name, elt);
@ -4408,12 +4416,13 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(nsHtml5ElementName* elem
attributes,
htmlCreator(elementName->getHtmlCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_XHTML,
popName,
attributes,
current->node,
currentNode,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
elementPushed(kNameSpaceID_XHTML, popName, elt);
elementPopped(kNameSpaceID_XHTML, popName, elt);
@ -4433,12 +4442,13 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterSVG(nsHtml5ElementName* e
attributes,
svgCreator(elementName->getSvgCreator()));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_SVG,
popName,
attributes,
current->node,
currentNode,
svgCreator(elementName->getSvgCreator()));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
elementPushed(kNameSpaceID_SVG, popName, elt);
elementPopped(kNameSpaceID_SVG, popName, elt);
@ -4455,12 +4465,13 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterMathML(nsHtml5ElementName
elt = createAndInsertFosterParentedElement(
kNameSpaceID_MathML, popName, attributes, htmlCreator(nullptr));
} else {
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement(kNameSpaceID_MathML,
popName,
attributes,
current->node,
currentNode,
htmlCreator(nullptr));
appendElement(elt, current->node);
appendElement(elt, currentNode);
}
elementPushed(kNameSpaceID_MathML, popName, elt);
elementPopped(kNameSpaceID_MathML, popName, elt);
@ -4470,7 +4481,7 @@ void
nsHtml5TreeBuilder::appendVoidInputToCurrent(nsHtml5HtmlAttributes* attributes,
nsIContentHandle* form)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
nsIContentHandle* elt =
createElement(kNameSpaceID_XHTML,
nsGkAtoms::input,
@ -4486,7 +4497,7 @@ nsHtml5TreeBuilder::appendVoidInputToCurrent(nsHtml5HtmlAttributes* attributes,
void
nsHtml5TreeBuilder::appendVoidFormToCurrent(nsHtml5HtmlAttributes* attributes)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* currentNode = nodeFromStackWithBlinkCompat(currentPtr);
nsIContentHandle* elt = createElement(kNameSpaceID_XHTML,
nsGkAtoms::form,
attributes,
@ -4644,7 +4655,16 @@ nsHtml5TreeBuilder::newSnapshot()
}
jArray<int32_t,int32_t> templateModeStackCopy = jArray<int32_t,int32_t>::newJArray(templateModePtr + 1);
nsHtml5ArrayCopy::arraycopy(templateModeStack, templateModeStackCopy, templateModeStackCopy.length);
return new nsHtml5StateSnapshot(stackCopy, listCopy, templateModeStackCopy, formPointer, headPointer, deepTreeSurrogateParent, mode, originalMode, framesetOk, needToDropLF, quirks);
return new nsHtml5StateSnapshot(stackCopy,
listCopy,
templateModeStackCopy,
formPointer,
headPointer,
mode,
originalMode,
framesetOk,
needToDropLF,
quirks);
}
bool
@ -4656,7 +4676,15 @@ nsHtml5TreeBuilder::snapshotMatches(nsAHtml5TreeBuilderState* snapshot)
int32_t listLen = snapshot->getListOfActiveFormattingElementsLength();
jArray<int32_t,int32_t> templateModeStackCopy = snapshot->getTemplateModeStack();
int32_t templateModeStackLen = snapshot->getTemplateModeStackLength();
if (stackLen != currentPtr + 1 || listLen != listPtr + 1 || templateModeStackLen != templateModePtr + 1 || formPointer != snapshot->getFormPointer() || headPointer != snapshot->getHeadPointer() || deepTreeSurrogateParent != snapshot->getDeepTreeSurrogateParent() || mode != snapshot->getMode() || originalMode != snapshot->getOriginalMode() || framesetOk != snapshot->isFramesetOk() || needToDropLF != snapshot->isNeedToDropLF() || quirks != snapshot->isQuirks()) {
if (stackLen != currentPtr + 1 || listLen != listPtr + 1 ||
templateModeStackLen != templateModePtr + 1 ||
formPointer != snapshot->getFormPointer() ||
headPointer != snapshot->getHeadPointer() ||
mode != snapshot->getMode() ||
originalMode != snapshot->getOriginalMode() ||
framesetOk != snapshot->isFramesetOk() ||
needToDropLF != snapshot->isNeedToDropLF() ||
quirks != snapshot->isQuirks()) {
return false;
}
for (int32_t i = listLen - 1; i >= 0; i--) {
@ -4748,7 +4776,6 @@ nsHtml5TreeBuilder::loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTab
nsHtml5ArrayCopy::arraycopy(templateModeStackCopy, templateModeStack, templateModeStackLen);
formPointer = snapshot->getFormPointer();
headPointer = snapshot->getHeadPointer();
deepTreeSurrogateParent = snapshot->getDeepTreeSurrogateParent();
mode = snapshot->getMode();
originalMode = snapshot->getOriginalMode();
framesetOk = snapshot->isFramesetOk();
@ -4767,24 +4794,28 @@ nsHtml5TreeBuilder::findInArray(nsHtml5StackNode* node, jArray<nsHtml5StackNode*
return -1;
}
nsIContentHandle*
nsIContentHandle*
nsHtml5TreeBuilder::nodeFromStackWithBlinkCompat(int32_t stackPos)
{
if (stackPos > 511) {
errDeepTree();
return stack[511]->node;
}
return stack[stackPos]->node;
}
nsIContentHandle*
nsHtml5TreeBuilder::getFormPointer()
{
return formPointer;
}
nsIContentHandle*
nsIContentHandle*
nsHtml5TreeBuilder::getHeadPointer()
{
return headPointer;
}
nsIContentHandle*
nsHtml5TreeBuilder::getDeepTreeSurrogateParent()
{
return deepTreeSurrogateParent;
}
jArray<nsHtml5StackNode*,int32_t>
nsHtml5TreeBuilder::getListOfActiveFormattingElements()
{

Просмотреть файл

@ -308,7 +308,6 @@ class nsHtml5TreeBuilder : public nsAHtml5TreeBuilderState
int32_t listPtr;
nsIContentHandle* formPointer;
nsIContentHandle* headPointer;
nsIContentHandle* deepTreeSurrogateParent;
protected:
autoJArray<char16_t,int32_t> charBuffer;
int32_t charBufferLen;
@ -551,10 +550,10 @@ class nsHtml5TreeBuilder : public nsAHtml5TreeBuilderState
void loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTable* interner);
private:
int32_t findInArray(nsHtml5StackNode* node, jArray<nsHtml5StackNode*,int32_t> arr);
nsIContentHandle* nodeFromStackWithBlinkCompat(int32_t stackPos);
public:
nsIContentHandle* getFormPointer();
nsIContentHandle* getHeadPointer();
nsIContentHandle* getDeepTreeSurrogateParent();
jArray<nsHtml5StackNode*,int32_t> getListOfActiveFormattingElements();
jArray<nsHtml5StackNode*,int32_t> getStack();
jArray<int32_t,int32_t> getTemplateModeStack();

Просмотреть файл

@ -7,7 +7,6 @@
#include "nsError.h"
#include "nsIPresShell.h"
#include "nsNodeUtils.h"
#include "nsIFrame.h"
#include "mozilla/Likely.h"
#include "mozilla/UniquePtr.h"
@ -484,10 +483,6 @@ nsHtml5TreeBuilder::appendElement(nsIContentHandle* aChild, nsIContentHandle* aP
{
NS_PRECONDITION(aChild, "Null child");
NS_PRECONDITION(aParent, "Null parent");
if (deepTreeSurrogateParent) {
return;
}
if (mBuilder) {
nsresult rv = nsHtml5TreeOperation::Append(static_cast<nsIContent*>(aChild),
static_cast<nsIContent*>(aParent),
@ -594,12 +589,11 @@ nsHtml5TreeBuilder::appendCharacters(nsIContentHandle* aParent, char16_t* aBuffe
MOZ_ASSERT(!aStart, "aStart must always be zero.");
if (mBuilder) {
nsresult rv = nsHtml5TreeOperation::AppendText(
aBuffer, // XXX aStart always ignored???
aLength,
static_cast<nsIContent*>(deepTreeSurrogateParent ?
deepTreeSurrogateParent : aParent),
mBuilder);
nsresult rv =
nsHtml5TreeOperation::AppendText(aBuffer, // XXX aStart always ignored???
aLength,
static_cast<nsIContent*>(aParent),
mBuilder);
if (NS_FAILED(rv)) {
MarkAsBrokenAndRequestSuspension(rv);
}
@ -619,8 +613,7 @@ nsHtml5TreeBuilder::appendCharacters(nsIContentHandle* aParent, char16_t* aBuffe
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed.");
treeOp->Init(eTreeOpAppendText, bufferCopy, aLength,
deepTreeSurrogateParent ? deepTreeSurrogateParent : aParent);
treeOp->Init(eTreeOpAppendText, bufferCopy, aLength, aParent);
}
void
@ -630,10 +623,6 @@ nsHtml5TreeBuilder::appendComment(nsIContentHandle* aParent, char16_t* aBuffer,
NS_PRECONDITION(aParent, "Null parent");
MOZ_ASSERT(!aStart, "aStart must always be zero.");
if (deepTreeSurrogateParent) {
return;
}
if (mBuilder) {
nsresult rv = nsHtml5TreeOperation::AppendComment(
static_cast<nsIContent*>(aParent),
@ -743,7 +732,6 @@ void
nsHtml5TreeBuilder::start(bool fragment)
{
mCurrentHtmlScriptIsAsyncOrDefer = false;
deepTreeSurrogateParent = nullptr;
#ifdef DEBUG
mActive = true;
#endif
@ -810,13 +798,6 @@ nsHtml5TreeBuilder::elementPushed(int32_t aNamespace, nsIAtom* aName, nsIContent
* table elements shouldn't be used as surrogate parents for user experience
* reasons.
*/
if (!deepTreeSurrogateParent && currentPtr >= MAX_REFLOW_DEPTH &&
!(aName == nsGkAtoms::script || aName == nsGkAtoms::table ||
aName == nsGkAtoms::thead || aName == nsGkAtoms::tfoot ||
aName == nsGkAtoms::tbody || aName == nsGkAtoms::tr ||
aName == nsGkAtoms::colgroup || aName == nsGkAtoms::style)) {
deepTreeSurrogateParent = aElement;
}
if (aNamespace != kNameSpaceID_XHTML) {
return;
}
@ -862,9 +843,6 @@ nsHtml5TreeBuilder::elementPopped(int32_t aNamespace, nsIAtom* aName, nsIContent
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML || aNamespace == kNameSpaceID_SVG || aNamespace == kNameSpaceID_MathML, "Element isn't HTML, SVG or MathML!");
NS_ASSERTION(aName, "Element doesn't have local name!");
NS_ASSERTION(aElement, "No element!");
if (deepTreeSurrogateParent && currentPtr <= MAX_REFLOW_DEPTH) {
deepTreeSurrogateParent = nullptr;
}
if (aNamespace == kNameSpaceID_MathML) {
return;
}
@ -1312,6 +1290,18 @@ nsHtml5TreeBuilder::EnableViewSource(nsHtml5Highlighter* aHighlighter)
mViewSource = aHighlighter;
}
void
nsHtml5TreeBuilder::errDeepTree()
{
if (MOZ_UNLIKELY(mViewSource)) {
mViewSource->AddErrorToCurrentRun("errDeepTree");
} else if (!mBuilder) {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
MOZ_ASSERT(treeOp, "Tree op allocation failed.");
treeOp->InitDeepTree(tokenizer->getLineNumber());
}
}
void
nsHtml5TreeBuilder::errStrayStartTag(nsIAtom* aName)
{

Просмотреть файл

@ -145,6 +145,9 @@
void EnableViewSource(nsHtml5Highlighter* aHighlighter);
void
errDeepTree();
void errStrayStartTag(nsIAtom* aName);
void errStrayEndTag(nsIAtom* aName);

Просмотреть файл

@ -65,12 +65,13 @@ nsHtml5TreeOpExecutor::nsHtml5TreeOpExecutor()
, mSuppressEOF(false)
, mReadingFromStage(false)
, mStreamParser(nullptr)
, mPreloadedURLs(23) // Mean # of preloadable resources per page on dmoz
, mPreloadedURLs(23) // Mean # of preloadable resources per page on dmoz
, mSpeculationReferrerPolicy(mozilla::net::RP_Unset)
, mStarted(false)
, mRunFlushLoopOnStack(false)
, mCallContinueInterruptedParsingIfEnabled(false)
, mAlreadyComplainedAboutCharset(false)
, mAlreadyComplainedAboutDeepTree(false)
{
}
@ -815,6 +816,25 @@ nsHtml5TreeOpExecutor::ComplainAboutBogusProtocolCharset(nsIDocument* aDoc)
"EncProtocolUnsupported");
}
void
nsHtml5TreeOpExecutor::MaybeComplainAboutDeepTree(uint32_t aLineNumber)
{
if (mAlreadyComplainedAboutDeepTree) {
return;
}
mAlreadyComplainedAboutDeepTree = true;
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
NS_LITERAL_CSTRING("HTML parser"),
mDocument,
nsContentUtils::eHTMLPARSER_PROPERTIES,
"errDeepTree",
nullptr,
0,
nullptr,
EmptyString(),
aLineNumber);
}
nsHtml5Parser*
nsHtml5TreeOpExecutor::GetParser()
{

Просмотреть файл

@ -92,6 +92,12 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder,
*/
bool mAlreadyComplainedAboutCharset;
/**
* Whether this executor has already complained about the tree being too
* deep.
*/
bool mAlreadyComplainedAboutDeepTree;
public:
nsHtml5TreeOpExecutor();
@ -196,6 +202,8 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder,
void ComplainAboutBogusProtocolCharset(nsIDocument* aDoc);
void MaybeComplainAboutDeepTree(uint32_t aLineNumber);
bool IsComplete()
{
return !mParser;

Просмотреть файл

@ -1011,6 +1011,11 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
aBuilder->MaybeComplainAboutCharset(msgId, error, (uint32_t)lineNumber);
return NS_OK;
}
case eTreeOpMaybeComplainAboutDeepTree: {
int32_t lineNumber = mOne.integer;
aBuilder->MaybeComplainAboutDeepTree((uint32_t)lineNumber);
return NS_OK;
}
case eTreeOpAddClass: {
nsIContent* node = *(mOne.node);
char16_t* str = mTwo.unicharPtr;

Просмотреть файл

@ -59,6 +59,7 @@ enum eHtml5TreeOperation
eTreeOpSetScriptLineNumberAndFreeze,
eTreeOpSvgLoad,
eTreeOpMaybeComplainAboutCharset,
eTreeOpMaybeComplainAboutDeepTree,
eTreeOpAddClass,
eTreeOpAddViewSourceHref,
eTreeOpAddViewSourceBase,
@ -465,6 +466,14 @@ class nsHtml5TreeOperation final {
mThree.integer = aLineNumber;
}
inline void InitDeepTree(int32_t aLineNumber)
{
MOZ_ASSERT(mOpCode == eTreeOpUninitialized,
"Op code must be uninitialized when initializing.");
mOpCode = eTreeOpMaybeComplainAboutDeepTree;
mOne.integer = aLineNumber;
}
inline void Init(eHtml5TreeOperation aOpCode, const nsAString& aString)
{
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,