Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h

Issue 2382523002: Revert of Revert r403630 which broke parsing on some sites. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h b/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h
index 3b0f3749eec13250c6ae6615e4225b9c4b606c50..1d4d898b03dffd9cfa45d9777589daa763e7976e 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h
+++ b/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.h
@@ -26,6 +26,7 @@
#ifndef HTMLTreeBuilderSimulator_h
#define HTMLTreeBuilderSimulator_h
+#include "core/CoreExport.h"
#include "core/html/parser/HTMLParserOptions.h"
#include "wtf/Vector.h"
@@ -35,13 +36,23 @@
class HTMLTokenizer;
class HTMLTreeBuilder;
-class HTMLTreeBuilderSimulator {
+class CORE_EXPORT HTMLTreeBuilderSimulator {
USING_FAST_MALLOC(HTMLTreeBuilderSimulator);
private:
enum Namespace {
HTML,
SVG,
MathML
+ };
+
+ struct StateFlags {
+ unsigned ns : 2; // Namespace
+ unsigned isHTMLIntegrationPoint : 1;
+
+ bool operator==(const StateFlags& other) const
+ {
+ return ns == other.ns && isHTMLIntegrationPoint == other.isHTMLIntegrationPoint;
+ }
};
public:
@@ -51,24 +62,35 @@
OtherToken
};
- typedef Vector<Namespace, 1> State;
+ // The state of the tree builder simulator is an abbreviated stack
+ // of open elements that only contains entries for namespace
+ // changes, or elements which may change whether the current node
+ // is a HTML integration point.
+ typedef Vector<StateFlags, 1> State;
explicit HTMLTreeBuilderSimulator(const HTMLParserOptions&);
static State stateFor(HTMLTreeBuilder*);
- const State& state() const { return m_namespaceStack; }
- void setState(const State& state) { m_namespaceStack = state; }
+ const State& state() const { return m_stack; }
+ void setState(const State& state) { m_stack = state; }
SimulatedToken simulate(const CompactHTMLToken&, HTMLTokenizer*);
private:
- explicit HTMLTreeBuilderSimulator(HTMLTreeBuilder*);
-
- bool inForeignContent() const { return m_namespaceStack.last() != HTML; }
+ bool inForeignContent() const { return currentNamespace() != HTML; }
+ Namespace currentNamespace() const { return static_cast<Namespace>(m_stack.last().ns); }
+ bool stackContainsNamespace(Namespace namespaceOfInterest) const
+ {
+ for (const auto& entry : m_stack) {
+ if (static_cast<Namespace>(entry.ns) == namespaceOfInterest)
+ return true;
+ }
+ return false;
+ }
HTMLParserOptions m_options;
- State m_namespaceStack;
+ State m_stack;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698