2 * Copyright (c) 2005-2007 Henri Sivonen
3 * Copyright (c) 2007-2017 Mozilla Foundation
4 * Portions of comments Copyright 2004-2010 Apple Computer, Inc., Mozilla
5 * Foundation, and Opera Software ASA.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
27 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
28 * Please edit Tokenizer.java instead and regenerate.
31 #define nsHtml5Tokenizer_cpp__
33 #include "nsHtml5AttributeName.h"
34 #include "nsHtml5ElementName.h"
35 #include "nsHtml5TreeBuilder.h"
36 #include "nsHtml5StackNode.h"
37 #include "nsHtml5UTF16Buffer.h"
38 #include "nsHtml5StateSnapshot.h"
39 #include "nsHtml5Portability.h"
41 #include "nsHtml5Tokenizer.h"
43 #include "nsHtml5TokenizerLoopPolicies.h"
45 char16_t
nsHtml5Tokenizer::LT_GT
[] = {'<', '>'};
46 char16_t
nsHtml5Tokenizer::LT_SOLIDUS
[] = {'<', '/'};
47 char16_t
nsHtml5Tokenizer::RSQB_RSQB
[] = {']', ']'};
48 char16_t
nsHtml5Tokenizer::REPLACEMENT_CHARACTER
[] = {0xfffd};
49 char16_t
nsHtml5Tokenizer::LF
[] = {'\n'};
50 char16_t
nsHtml5Tokenizer::CDATA_LSQB
[] = {'C', 'D', 'A', 'T', 'A', '['};
51 char16_t
nsHtml5Tokenizer::OCTYPE
[] = {'o', 'c', 't', 'y', 'p', 'e'};
52 char16_t
nsHtml5Tokenizer::UBLIC
[] = {'u', 'b', 'l', 'i', 'c'};
53 char16_t
nsHtml5Tokenizer::YSTEM
[] = {'y', 's', 't', 'e', 'm'};
54 static char16_t
const TITLE_ARR_DATA
[] = {'t', 'i', 't', 'l', 'e'};
55 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::TITLE_ARR
= {
56 TITLE_ARR_DATA
, std::size(TITLE_ARR_DATA
)};
57 static char16_t
const SCRIPT_ARR_DATA
[] = {'s', 'c', 'r', 'i', 'p', 't'};
58 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::SCRIPT_ARR
= {
59 SCRIPT_ARR_DATA
, std::size(SCRIPT_ARR_DATA
)};
60 static char16_t
const STYLE_ARR_DATA
[] = {'s', 't', 'y', 'l', 'e'};
61 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::STYLE_ARR
= {
62 STYLE_ARR_DATA
, std::size(STYLE_ARR_DATA
)};
63 static char16_t
const PLAINTEXT_ARR_DATA
[] = {'p', 'l', 'a', 'i', 'n',
65 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::PLAINTEXT_ARR
= {
66 PLAINTEXT_ARR_DATA
, std::size(PLAINTEXT_ARR_DATA
)};
67 static char16_t
const XMP_ARR_DATA
[] = {'x', 'm', 'p'};
68 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::XMP_ARR
= {
69 XMP_ARR_DATA
, std::size(XMP_ARR_DATA
)};
70 static char16_t
const TEXTAREA_ARR_DATA
[] = {'t', 'e', 'x', 't',
72 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::TEXTAREA_ARR
= {
73 TEXTAREA_ARR_DATA
, std::size(TEXTAREA_ARR_DATA
)};
74 static char16_t
const IFRAME_ARR_DATA
[] = {'i', 'f', 'r', 'a', 'm', 'e'};
75 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::IFRAME_ARR
= {
76 IFRAME_ARR_DATA
, std::size(IFRAME_ARR_DATA
)};
77 static char16_t
const NOEMBED_ARR_DATA
[] = {'n', 'o', 'e', 'm', 'b', 'e', 'd'};
78 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::NOEMBED_ARR
= {
79 NOEMBED_ARR_DATA
, std::size(NOEMBED_ARR_DATA
)};
80 static char16_t
const NOSCRIPT_ARR_DATA
[] = {'n', 'o', 's', 'c',
82 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::NOSCRIPT_ARR
= {
83 NOSCRIPT_ARR_DATA
, std::size(NOSCRIPT_ARR_DATA
)};
84 static char16_t
const NOFRAMES_ARR_DATA
[] = {'n', 'o', 'f', 'r',
86 staticJArray
<char16_t
, int32_t> nsHtml5Tokenizer::NOFRAMES_ARR
= {
87 NOFRAMES_ARR_DATA
, std::size(NOFRAMES_ARR_DATA
)};
89 nsHtml5Tokenizer::nsHtml5Tokenizer(nsHtml5TreeBuilder
* tokenHandler
,
90 bool viewingXmlSource
)
91 : tokenHandler(tokenHandler
),
92 encodingDeclarationHandler(nullptr),
107 suspendAfterCurrentNonTextToken(false),
110 charRefBuf(jArray
<char16_t
, int32_t>::newJArray(32)),
112 bmpChar(jArray
<char16_t
, int32_t>::newJArray(1)),
113 astralChar(jArray
<char16_t
, int32_t>::newJArray(2)),
114 endTagExpectation(nullptr),
115 endTagExpectationAsArray(nullptr),
117 containsHyphen(false),
119 nonInternedTagName(new nsHtml5ElementName()),
120 attributeName(nullptr),
121 nonInternedAttributeName(new nsHtml5AttributeName()),
122 doctypeName(nullptr),
123 publicIdentifier(nullptr),
124 systemIdentifier(nullptr),
125 attributes(tokenHandler
->HasBuilder() ? new nsHtml5HtmlAttributes(0)
127 newAttributesEachTime(!tokenHandler
->HasBuilder()),
128 shouldSuspend(false),
134 viewingXmlSource(viewingXmlSource
) {
135 MOZ_COUNT_CTOR(nsHtml5Tokenizer
);
138 void nsHtml5Tokenizer::setInterner(nsHtml5AtomTable
* interner
) {
139 this->interner
= interner
;
142 void nsHtml5Tokenizer::initLocation(nsHtml5String newPublicId
,
143 nsHtml5String newSystemId
) {
144 this->systemId
= newSystemId
;
145 this->publicId
= newPublicId
;
148 bool nsHtml5Tokenizer::isViewingXmlSource() { return viewingXmlSource
; }
150 void nsHtml5Tokenizer::setKeepBuffer(bool keepBuffer
) {
151 this->keepBuffer
= keepBuffer
;
154 bool nsHtml5Tokenizer::dropBufferIfLongerThan(int32_t length
) {
155 if (strBuf
.length
> length
) {
162 void nsHtml5Tokenizer::setState(int32_t specialTokenizerState
) {
163 this->stateSave
= specialTokenizerState
;
164 this->endTagExpectation
= nullptr;
165 this->endTagExpectationAsArray
= nullptr;
168 void nsHtml5Tokenizer::setStateAndEndTagExpectation(
169 int32_t specialTokenizerState
, nsHtml5ElementName
* endTagExpectation
) {
170 this->stateSave
= specialTokenizerState
;
171 this->endTagExpectation
= endTagExpectation
;
172 endTagExpectationToArray();
175 void nsHtml5Tokenizer::endTagExpectationToArray() {
176 switch (endTagExpectation
->getGroup()) {
177 case nsHtml5TreeBuilder::TITLE
: {
178 endTagExpectationAsArray
= TITLE_ARR
;
181 case nsHtml5TreeBuilder::SCRIPT
: {
182 endTagExpectationAsArray
= SCRIPT_ARR
;
185 case nsHtml5TreeBuilder::STYLE
: {
186 endTagExpectationAsArray
= STYLE_ARR
;
189 case nsHtml5TreeBuilder::PLAINTEXT
: {
190 endTagExpectationAsArray
= PLAINTEXT_ARR
;
193 case nsHtml5TreeBuilder::XMP
: {
194 endTagExpectationAsArray
= XMP_ARR
;
197 case nsHtml5TreeBuilder::TEXTAREA
: {
198 endTagExpectationAsArray
= TEXTAREA_ARR
;
201 case nsHtml5TreeBuilder::IFRAME
: {
202 endTagExpectationAsArray
= IFRAME_ARR
;
205 case nsHtml5TreeBuilder::NOEMBED
: {
206 endTagExpectationAsArray
= NOEMBED_ARR
;
209 case nsHtml5TreeBuilder::NOSCRIPT
: {
210 endTagExpectationAsArray
= NOSCRIPT_ARR
;
213 case nsHtml5TreeBuilder::NOFRAMES
: {
214 endTagExpectationAsArray
= NOFRAMES_ARR
;
218 MOZ_ASSERT(false, "Bad end tag expectation.");
224 void nsHtml5Tokenizer::setLineNumber(int32_t line
) {
225 this->attributeLine
= line
;
229 nsHtml5HtmlAttributes
* nsHtml5Tokenizer::emptyAttributes() {
230 return nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES
;
233 void nsHtml5Tokenizer::emitOrAppendCharRefBuf(int32_t returnState
) {
234 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
235 appendCharRefBufToStrBuf();
237 if (charRefBufLen
> 0) {
238 tokenHandler
->characters(charRefBuf
, 0, charRefBufLen
);
244 nsHtml5String
nsHtml5Tokenizer::strBufToString() {
245 nsHtml5String str
= nsHtml5Portability::newStringFromBuffer(
246 strBuf
, 0, strBufLen
, tokenHandler
,
247 !newAttributesEachTime
&&
248 attributeName
== nsHtml5AttributeName::ATTR_CLASS
);
249 clearStrBufAfterUse();
253 void nsHtml5Tokenizer::strBufToDoctypeName() {
255 nsHtml5Portability::newLocalNameFromBuffer(strBuf
, strBufLen
, interner
);
256 clearStrBufAfterUse();
259 void nsHtml5Tokenizer::emitStrBuf() {
261 tokenHandler
->characters(strBuf
, 0, strBufLen
);
262 clearStrBufAfterUse();
266 void nsHtml5Tokenizer::appendStrBuf(char16_t
* buffer
, int32_t offset
,
268 int32_t newLen
= nsHtml5Portability::checkedAdd(strBufLen
, length
);
269 MOZ_ASSERT(newLen
<= strBuf
.length
, "Previous buffer length insufficient.");
270 if (MOZ_UNLIKELY(strBuf
.length
< newLen
)) {
271 if (MOZ_UNLIKELY(!EnsureBufferSpace(length
))) {
272 MOZ_CRASH("Unable to recover from buffer reallocation failure");
275 nsHtml5ArrayCopy::arraycopy(buffer
, offset
, strBuf
, strBufLen
, length
);
279 void nsHtml5Tokenizer::emitComment(int32_t provisionalHyphens
, int32_t pos
) {
281 tokenHandler
->comment(strBuf
, 0, strBufLen
- provisionalHyphens
);
282 clearStrBufAfterUse();
284 suspendIfRequestedAfterCurrentNonTextToken();
287 void nsHtml5Tokenizer::flushChars(char16_t
* buf
, int32_t pos
) {
289 tokenHandler
->characters(buf
, cstart
, pos
- cstart
);
294 void nsHtml5Tokenizer::strBufToElementNameString() {
295 if (containsHyphen
) {
296 nsAtom
* annotationName
= nsHtml5ElementName::ELT_ANNOTATION_XML
->getName();
297 if (nsHtml5Portability::localEqualsBuffer(annotationName
, strBuf
,
299 tagName
= nsHtml5ElementName::ELT_ANNOTATION_XML
;
301 nonInternedTagName
->setNameForNonInterned(
302 nsHtml5Portability::newLocalNameFromBuffer(strBuf
, strBufLen
,
305 tagName
= nonInternedTagName
;
308 tagName
= nsHtml5ElementName::elementNameByBuffer(strBuf
, strBufLen
);
310 nonInternedTagName
->setNameForNonInterned(
311 nsHtml5Portability::newLocalNameFromBuffer(strBuf
, strBufLen
,
314 tagName
= nonInternedTagName
;
317 containsHyphen
= false;
318 clearStrBufAfterUse();
321 int32_t nsHtml5Tokenizer::emitCurrentTagToken(bool selfClosing
, int32_t pos
) {
324 maybeErrSlashInEndTag(selfClosing
);
325 stateSave
= nsHtml5Tokenizer::DATA
;
326 nsHtml5HtmlAttributes
* attrs
=
327 (!attributes
? nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES
: attributes
);
329 maybeErrAttributesOnEndTag(attrs
);
330 if (!viewingXmlSource
) {
331 tokenHandler
->endTag(tagName
);
333 if (newAttributesEachTime
) {
335 attributes
= nullptr;
338 if (viewingXmlSource
) {
339 MOZ_ASSERT(newAttributesEachTime
);
341 attributes
= nullptr;
343 tokenHandler
->startTag(tagName
, attrs
, selfClosing
);
347 if (newAttributesEachTime
) {
348 attributes
= nullptr;
350 attributes
->clear(0);
352 suspendIfRequestedAfterCurrentNonTextToken();
356 void nsHtml5Tokenizer::attributeNameComplete() {
358 nsHtml5AttributeName::nameByBuffer(strBuf
, strBufLen
, interner
);
359 if (!attributeName
) {
360 nonInternedAttributeName
->setNameForNonInterned(
361 nsHtml5Portability::newLocalNameFromBuffer(strBuf
, strBufLen
,
363 attributeName
= nonInternedAttributeName
;
365 clearStrBufAfterUse();
367 attributes
= new nsHtml5HtmlAttributes(0);
369 if (attributes
->contains(attributeName
)) {
370 errDuplicateAttribute();
371 attributeName
= nullptr;
375 void nsHtml5Tokenizer::addAttributeWithoutValue() {
377 attributes
->addAttribute(
378 attributeName
, nsHtml5Portability::newEmptyString(), attributeLine
);
379 attributeName
= nullptr;
381 clearStrBufAfterUse();
385 void nsHtml5Tokenizer::addAttributeWithValue() {
387 nsHtml5String val
= strBufToString();
389 mViewSource
->MaybeLinkifyAttributeValue(attributeName
, val
);
391 attributes
->addAttribute(attributeName
, val
, attributeLine
);
392 attributeName
= nullptr;
394 clearStrBufAfterUse();
398 void nsHtml5Tokenizer::start() {
399 initializeWithoutStarting();
400 tokenHandler
->startTokenization(this);
404 nextCharOnNewLine
= false;
405 } else if (tokenHandler
->WantsLineAndColumn()) {
408 nextCharOnNewLine
= true;
412 nextCharOnNewLine
= false;
416 bool nsHtml5Tokenizer::tokenizeBuffer(nsHtml5UTF16Buffer
* buffer
) {
417 int32_t state
= stateSave
;
418 int32_t returnState
= returnStateSave
;
420 shouldSuspend
= false;
422 int32_t start
= buffer
->getStart();
423 int32_t end
= buffer
->getEnd();
424 int32_t pos
= start
- 1;
432 case SCRIPT_DATA_ESCAPED
:
433 case SCRIPT_DATA_ESCAPE_START
:
434 case SCRIPT_DATA_ESCAPE_START_DASH
:
435 case SCRIPT_DATA_ESCAPED_DASH
:
436 case SCRIPT_DATA_ESCAPED_DASH_DASH
:
437 case SCRIPT_DATA_DOUBLE_ESCAPE_START
:
438 case SCRIPT_DATA_DOUBLE_ESCAPED
:
439 case SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN
:
440 case SCRIPT_DATA_DOUBLE_ESCAPED_DASH
:
441 case SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH
:
442 case SCRIPT_DATA_DOUBLE_ESCAPE_END
: {
452 mViewSource
->SetBuffer(buffer
);
453 pos
= stateLoop
<nsHtml5ViewSourcePolicy
>(state
, c
, pos
, buffer
->getBuffer(),
456 mViewSource
->DropBuffer((pos
== buffer
->getEnd()) ? pos
: pos
+ 1);
457 } else if (tokenHandler
->WantsLineAndColumn()) {
458 pos
= stateLoop
<nsHtml5LineColPolicy
>(state
, c
, pos
, buffer
->getBuffer(),
459 false, returnState
, buffer
->getEnd());
461 pos
= stateLoop
<nsHtml5FastestPolicy
>(state
, c
, pos
, buffer
->getBuffer(),
462 false, returnState
, buffer
->getEnd());
465 buffer
->setStart(pos
);
467 buffer
->setStart(pos
+ 1);
473 int32_t nsHtml5Tokenizer::stateLoop(int32_t state
, char16_t c
, int32_t pos
,
474 char16_t
* buf
, bool reconsume
,
475 int32_t returnState
, int32_t endPos
) {
476 bool reportedConsecutiveHyphens
= false;
485 if (++pos
== endPos
) {
486 NS_HTML5_BREAK(stateloop
);
488 c
= P::checkChar(this, buf
, pos
);
492 flushChars(buf
, pos
);
493 MOZ_ASSERT(!charRefBufLen
,
494 "charRefBufLen not reset after previous use!");
496 setAdditionalAndRememberAmpersandLocation('\0');
499 P::transition(mViewSource
.get(),
500 nsHtml5Tokenizer::CONSUME_CHARACTER_REFERENCE
,
502 NS_HTML5_CONTINUE(stateloop
);
505 flushChars(buf
, pos
);
506 state
= P::transition(mViewSource
.get(),
507 nsHtml5Tokenizer::TAG_OPEN
, reconsume
, pos
);
508 NS_HTML5_BREAK(dataloop
);
511 maybeEmitReplacementCharacter(buf
, pos
);
515 emitCarriageReturn
<P
>(buf
, pos
);
516 NS_HTML5_BREAK(stateloop
);
519 P::silentLineFeed(this);
532 if (++pos
== endPos
) {
533 NS_HTML5_BREAK(stateloop
);
535 c
= P::checkChar(this, buf
, pos
);
536 if (c
>= 'A' && c
<= 'Z') {
538 clearStrBufBeforeUse();
539 appendStrBuf((char16_t
)(c
+ 0x20));
540 containsHyphen
= false;
541 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::TAG_NAME
,
543 NS_HTML5_BREAK(tagopenloop
);
544 } else if (c
>= 'a' && c
<= 'z') {
546 clearStrBufBeforeUse();
548 containsHyphen
= false;
549 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::TAG_NAME
,
551 NS_HTML5_BREAK(tagopenloop
);
555 state
= P::transition(mViewSource
.get(),
556 nsHtml5Tokenizer::MARKUP_DECLARATION_OPEN
,
558 NS_HTML5_CONTINUE(stateloop
);
561 state
= P::transition(mViewSource
.get(),
562 nsHtml5Tokenizer::CLOSE_TAG_OPEN
, reconsume
,
564 NS_HTML5_CONTINUE(stateloop
);
567 if (viewingXmlSource
) {
568 state
= P::transition(mViewSource
.get(),
569 nsHtml5Tokenizer::PROCESSING_INSTRUCTION
,
571 NS_HTML5_CONTINUE(stateloop
);
573 if (P::reportErrors
) {
574 errProcessingInstruction();
576 clearStrBufBeforeUse();
578 state
= P::transition(mViewSource
.get(),
579 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
581 NS_HTML5_CONTINUE(stateloop
);
584 if (P::reportErrors
) {
587 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 2);
589 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
591 NS_HTML5_CONTINUE(stateloop
);
594 if (P::reportErrors
) {
595 errBadCharAfterLt(c
);
597 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
600 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
602 NS_HTML5_CONTINUE(stateloop
);
611 if (++pos
== endPos
) {
612 NS_HTML5_BREAK(stateloop
);
614 c
= P::checkChar(this, buf
, pos
);
617 P::silentCarriageReturn(this);
618 strBufToElementNameString();
619 state
= P::transition(mViewSource
.get(),
620 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
622 NS_HTML5_BREAK(stateloop
);
625 P::silentLineFeed(this);
631 strBufToElementNameString();
632 state
= P::transition(mViewSource
.get(),
633 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
635 NS_HTML5_BREAK(tagnameloop
);
638 strBufToElementNameString();
639 state
= P::transition(mViewSource
.get(),
640 nsHtml5Tokenizer::SELF_CLOSING_START_TAG
,
642 NS_HTML5_CONTINUE(stateloop
);
645 strBufToElementNameString();
646 state
= P::transition(mViewSource
.get(),
647 emitCurrentTagToken(false, pos
), reconsume
,
650 NS_HTML5_BREAK(stateloop
);
652 NS_HTML5_CONTINUE(stateloop
);
659 if (c
>= 'A' && c
<= 'Z') {
661 } else if (c
== '-') {
662 containsHyphen
= true;
672 case BEFORE_ATTRIBUTE_NAME
: {
677 if (++pos
== endPos
) {
678 NS_HTML5_BREAK(stateloop
);
680 c
= P::checkChar(this, buf
, pos
);
684 P::silentCarriageReturn(this);
685 NS_HTML5_BREAK(stateloop
);
688 P::silentLineFeed(this);
697 state
= P::transition(mViewSource
.get(),
698 nsHtml5Tokenizer::SELF_CLOSING_START_TAG
,
700 NS_HTML5_CONTINUE(stateloop
);
703 state
= P::transition(mViewSource
.get(),
704 emitCurrentTagToken(false, pos
), reconsume
,
707 NS_HTML5_BREAK(stateloop
);
709 NS_HTML5_CONTINUE(stateloop
);
719 if (P::reportErrors
) {
720 errBadCharBeforeAttributeNameOrNull(c
);
725 if (c
>= 'A' && c
<= 'Z') {
728 attributeLine
= line
;
729 clearStrBufBeforeUse();
731 state
= P::transition(mViewSource
.get(),
732 nsHtml5Tokenizer::ATTRIBUTE_NAME
, reconsume
,
734 NS_HTML5_BREAK(beforeattributenameloop
);
738 beforeattributenameloop_end
:;
741 case ATTRIBUTE_NAME
: {
743 if (++pos
== endPos
) {
744 NS_HTML5_BREAK(stateloop
);
746 c
= P::checkChar(this, buf
, pos
);
749 P::silentCarriageReturn(this);
750 attributeNameComplete();
751 state
= P::transition(mViewSource
.get(),
752 nsHtml5Tokenizer::AFTER_ATTRIBUTE_NAME
,
754 NS_HTML5_BREAK(stateloop
);
757 P::silentLineFeed(this);
763 attributeNameComplete();
764 state
= P::transition(mViewSource
.get(),
765 nsHtml5Tokenizer::AFTER_ATTRIBUTE_NAME
,
767 NS_HTML5_CONTINUE(stateloop
);
770 attributeNameComplete();
771 addAttributeWithoutValue();
772 state
= P::transition(mViewSource
.get(),
773 nsHtml5Tokenizer::SELF_CLOSING_START_TAG
,
775 NS_HTML5_CONTINUE(stateloop
);
778 attributeNameComplete();
779 state
= P::transition(mViewSource
.get(),
780 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_VALUE
,
782 NS_HTML5_BREAK(attributenameloop
);
785 attributeNameComplete();
786 addAttributeWithoutValue();
787 state
= P::transition(mViewSource
.get(),
788 emitCurrentTagToken(false, pos
), reconsume
,
791 NS_HTML5_BREAK(stateloop
);
793 NS_HTML5_CONTINUE(stateloop
);
802 if (P::reportErrors
) {
803 errQuoteOrLtInAttributeNameOrNull(c
);
808 if (c
>= 'A' && c
<= 'Z') {
816 attributenameloop_end
:;
819 case BEFORE_ATTRIBUTE_VALUE
: {
821 if (++pos
== endPos
) {
822 NS_HTML5_BREAK(stateloop
);
824 c
= P::checkChar(this, buf
, pos
);
827 P::silentCarriageReturn(this);
828 NS_HTML5_BREAK(stateloop
);
831 P::silentLineFeed(this);
840 attributeLine
= line
;
841 clearStrBufBeforeUse();
843 P::transition(mViewSource
.get(),
844 nsHtml5Tokenizer::ATTRIBUTE_VALUE_DOUBLE_QUOTED
,
846 NS_HTML5_BREAK(beforeattributevalueloop
);
849 attributeLine
= line
;
850 clearStrBufBeforeUse();
852 state
= P::transition(mViewSource
.get(),
853 nsHtml5Tokenizer::ATTRIBUTE_VALUE_UNQUOTED
,
856 NS_HTML5_CONTINUE(stateloop
);
859 attributeLine
= line
;
860 clearStrBufBeforeUse();
862 P::transition(mViewSource
.get(),
863 nsHtml5Tokenizer::ATTRIBUTE_VALUE_SINGLE_QUOTED
,
865 NS_HTML5_CONTINUE(stateloop
);
868 if (P::reportErrors
) {
869 errAttributeValueMissing();
871 addAttributeWithoutValue();
872 state
= P::transition(mViewSource
.get(),
873 emitCurrentTagToken(false, pos
), reconsume
,
876 NS_HTML5_BREAK(stateloop
);
878 NS_HTML5_CONTINUE(stateloop
);
887 if (P::reportErrors
) {
888 errLtOrEqualsOrGraveInUnquotedAttributeOrNull(c
);
893 attributeLine
= line
;
894 clearStrBufBeforeUse();
896 state
= P::transition(mViewSource
.get(),
897 nsHtml5Tokenizer::ATTRIBUTE_VALUE_UNQUOTED
,
900 NS_HTML5_CONTINUE(stateloop
);
904 beforeattributevalueloop_end
:;
907 case ATTRIBUTE_VALUE_DOUBLE_QUOTED
: {
912 if (++pos
== endPos
) {
913 NS_HTML5_BREAK(stateloop
);
915 c
= P::checkChar(this, buf
, pos
);
919 addAttributeWithValue();
921 P::transition(mViewSource
.get(),
922 nsHtml5Tokenizer::AFTER_ATTRIBUTE_VALUE_QUOTED
,
924 NS_HTML5_BREAK(attributevaluedoublequotedloop
);
927 MOZ_ASSERT(!charRefBufLen
,
928 "charRefBufLen not reset after previous use!");
930 setAdditionalAndRememberAmpersandLocation('\"');
933 P::transition(mViewSource
.get(),
934 nsHtml5Tokenizer::CONSUME_CHARACTER_REFERENCE
,
936 NS_HTML5_CONTINUE(stateloop
);
939 appendStrBufCarriageReturn
<P
>();
940 NS_HTML5_BREAK(stateloop
);
943 appendStrBufLineFeed
<P
>();
956 attributevaluedoublequotedloop_end
:;
959 case AFTER_ATTRIBUTE_VALUE_QUOTED
: {
961 if (++pos
== endPos
) {
962 NS_HTML5_BREAK(stateloop
);
964 c
= P::checkChar(this, buf
, pos
);
967 P::silentCarriageReturn(this);
968 state
= P::transition(mViewSource
.get(),
969 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
971 NS_HTML5_BREAK(stateloop
);
974 P::silentLineFeed(this);
980 state
= P::transition(mViewSource
.get(),
981 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
983 NS_HTML5_CONTINUE(stateloop
);
986 state
= P::transition(mViewSource
.get(),
987 nsHtml5Tokenizer::SELF_CLOSING_START_TAG
,
989 NS_HTML5_BREAK(afterattributevaluequotedloop
);
992 state
= P::transition(mViewSource
.get(),
993 emitCurrentTagToken(false, pos
), reconsume
,
996 NS_HTML5_BREAK(stateloop
);
998 NS_HTML5_CONTINUE(stateloop
);
1001 if (P::reportErrors
) {
1002 errNoSpaceBetweenAttributes();
1005 state
= P::transition(mViewSource
.get(),
1006 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
1008 NS_HTML5_CONTINUE(stateloop
);
1012 afterattributevaluequotedloop_end
:;
1015 case SELF_CLOSING_START_TAG
: {
1016 if (++pos
== endPos
) {
1017 NS_HTML5_BREAK(stateloop
);
1019 c
= P::checkChar(this, buf
, pos
);
1023 P::transition(mViewSource
.get(), emitCurrentTagToken(true, pos
),
1025 if (shouldSuspend
) {
1026 NS_HTML5_BREAK(stateloop
);
1028 NS_HTML5_CONTINUE(stateloop
);
1031 if (P::reportErrors
) {
1032 errSlashNotFollowedByGt();
1035 state
= P::transition(mViewSource
.get(),
1036 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
1038 NS_HTML5_CONTINUE(stateloop
);
1042 case ATTRIBUTE_VALUE_UNQUOTED
: {
1047 if (++pos
== endPos
) {
1048 NS_HTML5_BREAK(stateloop
);
1050 c
= P::checkChar(this, buf
, pos
);
1054 P::silentCarriageReturn(this);
1055 addAttributeWithValue();
1056 state
= P::transition(mViewSource
.get(),
1057 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
1059 NS_HTML5_BREAK(stateloop
);
1062 P::silentLineFeed(this);
1068 addAttributeWithValue();
1069 state
= P::transition(mViewSource
.get(),
1070 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
1072 NS_HTML5_CONTINUE(stateloop
);
1075 MOZ_ASSERT(!charRefBufLen
,
1076 "charRefBufLen not reset after previous use!");
1077 appendCharRefBuf(c
);
1078 setAdditionalAndRememberAmpersandLocation('>');
1079 returnState
= state
;
1081 P::transition(mViewSource
.get(),
1082 nsHtml5Tokenizer::CONSUME_CHARACTER_REFERENCE
,
1084 NS_HTML5_CONTINUE(stateloop
);
1087 addAttributeWithValue();
1088 state
= P::transition(mViewSource
.get(),
1089 emitCurrentTagToken(false, pos
), reconsume
,
1091 if (shouldSuspend
) {
1092 NS_HTML5_BREAK(stateloop
);
1094 NS_HTML5_CONTINUE(stateloop
);
1105 if (P::reportErrors
) {
1106 errUnquotedAttributeValOrNull(c
);
1117 case AFTER_ATTRIBUTE_NAME
: {
1119 if (++pos
== endPos
) {
1120 NS_HTML5_BREAK(stateloop
);
1122 c
= P::checkChar(this, buf
, pos
);
1125 P::silentCarriageReturn(this);
1126 NS_HTML5_BREAK(stateloop
);
1129 P::silentLineFeed(this);
1138 addAttributeWithoutValue();
1139 state
= P::transition(mViewSource
.get(),
1140 nsHtml5Tokenizer::SELF_CLOSING_START_TAG
,
1142 NS_HTML5_CONTINUE(stateloop
);
1145 state
= P::transition(mViewSource
.get(),
1146 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_VALUE
,
1148 NS_HTML5_CONTINUE(stateloop
);
1151 addAttributeWithoutValue();
1152 state
= P::transition(mViewSource
.get(),
1153 emitCurrentTagToken(false, pos
), reconsume
,
1155 if (shouldSuspend
) {
1156 NS_HTML5_BREAK(stateloop
);
1158 NS_HTML5_CONTINUE(stateloop
);
1167 if (P::reportErrors
) {
1168 errQuoteOrLtInAttributeNameOrNull(c
);
1173 addAttributeWithoutValue();
1174 if (c
>= 'A' && c
<= 'Z') {
1177 clearStrBufBeforeUse();
1179 state
= P::transition(mViewSource
.get(),
1180 nsHtml5Tokenizer::ATTRIBUTE_NAME
, reconsume
,
1182 NS_HTML5_CONTINUE(stateloop
);
1187 case MARKUP_DECLARATION_OPEN
: {
1189 if (++pos
== endPos
) {
1190 NS_HTML5_BREAK(stateloop
);
1192 c
= P::checkChar(this, buf
, pos
);
1195 clearStrBufBeforeUse();
1197 state
= P::transition(mViewSource
.get(),
1198 nsHtml5Tokenizer::MARKUP_DECLARATION_HYPHEN
,
1200 NS_HTML5_BREAK(markupdeclarationopenloop
);
1204 clearStrBufBeforeUse();
1207 state
= P::transition(mViewSource
.get(),
1208 nsHtml5Tokenizer::MARKUP_DECLARATION_OCTYPE
,
1210 NS_HTML5_CONTINUE(stateloop
);
1213 if (tokenHandler
->cdataSectionAllowed()) {
1214 clearStrBufBeforeUse();
1217 state
= P::transition(mViewSource
.get(),
1218 nsHtml5Tokenizer::CDATA_START
, reconsume
,
1220 NS_HTML5_CONTINUE(stateloop
);
1225 if (P::reportErrors
) {
1228 clearStrBufBeforeUse();
1230 state
= P::transition(mViewSource
.get(),
1231 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
1233 NS_HTML5_CONTINUE(stateloop
);
1237 markupdeclarationopenloop_end
:;
1240 case MARKUP_DECLARATION_HYPHEN
: {
1242 if (++pos
== endPos
) {
1243 NS_HTML5_BREAK(stateloop
);
1245 c
= P::checkChar(this, buf
, pos
);
1248 clearStrBufAfterOneHyphen();
1249 state
= P::transition(mViewSource
.get(),
1250 nsHtml5Tokenizer::COMMENT_START
, reconsume
,
1252 NS_HTML5_BREAK(markupdeclarationhyphenloop
);
1255 if (P::reportErrors
) {
1259 state
= P::transition(mViewSource
.get(),
1260 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
1262 NS_HTML5_CONTINUE(stateloop
);
1266 markupdeclarationhyphenloop_end
:;
1269 case COMMENT_START
: {
1270 reportedConsecutiveHyphens
= false;
1272 if (++pos
== endPos
) {
1273 NS_HTML5_BREAK(stateloop
);
1275 c
= P::checkChar(this, buf
, pos
);
1279 state
= P::transition(mViewSource
.get(),
1280 nsHtml5Tokenizer::COMMENT_START_DASH
,
1282 NS_HTML5_CONTINUE(stateloop
);
1285 if (P::reportErrors
) {
1286 errPrematureEndOfComment();
1288 emitComment(0, pos
);
1289 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
1291 if (shouldSuspend
) {
1292 NS_HTML5_BREAK(stateloop
);
1294 NS_HTML5_CONTINUE(stateloop
);
1298 state
= P::transition(mViewSource
.get(),
1299 nsHtml5Tokenizer::COMMENT_LESSTHAN
,
1301 NS_HTML5_CONTINUE(stateloop
);
1304 appendStrBufCarriageReturn
<P
>();
1305 state
= P::transition(mViewSource
.get(),
1306 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1307 NS_HTML5_BREAK(stateloop
);
1310 appendStrBufLineFeed
<P
>();
1311 state
= P::transition(mViewSource
.get(),
1312 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1313 NS_HTML5_BREAK(commentstartloop
);
1321 state
= P::transition(mViewSource
.get(),
1322 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1323 NS_HTML5_BREAK(commentstartloop
);
1327 commentstartloop_end
:;
1332 if (++pos
== endPos
) {
1333 NS_HTML5_BREAK(stateloop
);
1335 c
= P::checkChar(this, buf
, pos
);
1339 state
= P::transition(mViewSource
.get(),
1340 nsHtml5Tokenizer::COMMENT_END_DASH
,
1342 NS_HTML5_BREAK(commentloop
);
1346 state
= P::transition(mViewSource
.get(),
1347 nsHtml5Tokenizer::COMMENT_LESSTHAN
,
1349 NS_HTML5_CONTINUE(stateloop
);
1352 appendStrBufCarriageReturn
<P
>();
1353 NS_HTML5_BREAK(stateloop
);
1356 appendStrBufLineFeed
<P
>();
1372 case COMMENT_END_DASH
: {
1374 if (++pos
== endPos
) {
1375 NS_HTML5_BREAK(stateloop
);
1377 c
= P::checkChar(this, buf
, pos
);
1382 P::transition(mViewSource
.get(),
1383 nsHtml5Tokenizer::COMMENT_END
, reconsume
, pos
);
1384 NS_HTML5_BREAK(commentenddashloop
);
1388 state
= P::transition(mViewSource
.get(),
1389 nsHtml5Tokenizer::COMMENT_LESSTHAN
,
1391 NS_HTML5_CONTINUE(stateloop
);
1394 appendStrBufCarriageReturn
<P
>();
1395 state
= P::transition(mViewSource
.get(),
1396 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1397 NS_HTML5_BREAK(stateloop
);
1400 appendStrBufLineFeed
<P
>();
1401 state
= P::transition(mViewSource
.get(),
1402 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1403 NS_HTML5_CONTINUE(stateloop
);
1411 state
= P::transition(mViewSource
.get(),
1412 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1413 NS_HTML5_CONTINUE(stateloop
);
1417 commentenddashloop_end
:;
1422 if (++pos
== endPos
) {
1423 NS_HTML5_BREAK(stateloop
);
1425 c
= P::checkChar(this, buf
, pos
);
1428 emitComment(2, pos
);
1429 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
1431 if (shouldSuspend
) {
1432 NS_HTML5_BREAK(stateloop
);
1434 NS_HTML5_CONTINUE(stateloop
);
1437 adjustDoubleHyphenAndAppendToStrBufAndErr(
1438 c
, reportedConsecutiveHyphens
);
1439 reportedConsecutiveHyphens
= true;
1444 state
= P::transition(mViewSource
.get(),
1445 nsHtml5Tokenizer::COMMENT_LESSTHAN
,
1447 NS_HTML5_CONTINUE(stateloop
);
1450 adjustDoubleHyphenAndAppendToStrBufCarriageReturn
<P
>();
1451 state
= P::transition(mViewSource
.get(),
1452 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1453 NS_HTML5_BREAK(stateloop
);
1456 adjustDoubleHyphenAndAppendToStrBufLineFeed
<P
>();
1457 state
= P::transition(mViewSource
.get(),
1458 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1459 NS_HTML5_CONTINUE(stateloop
);
1463 state
= P::transition(mViewSource
.get(),
1464 nsHtml5Tokenizer::COMMENT_END_BANG
,
1466 NS_HTML5_BREAK(commentendloop
);
1473 adjustDoubleHyphenAndAppendToStrBufAndErr(
1474 c
, reportedConsecutiveHyphens
);
1475 reportedConsecutiveHyphens
= true;
1476 state
= P::transition(mViewSource
.get(),
1477 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1478 NS_HTML5_CONTINUE(stateloop
);
1482 commentendloop_end
:;
1485 case COMMENT_END_BANG
: {
1487 if (++pos
== endPos
) {
1488 NS_HTML5_BREAK(stateloop
);
1490 c
= P::checkChar(this, buf
, pos
);
1493 emitComment(3, pos
);
1494 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
1496 if (shouldSuspend
) {
1497 NS_HTML5_BREAK(stateloop
);
1499 NS_HTML5_CONTINUE(stateloop
);
1503 state
= P::transition(mViewSource
.get(),
1504 nsHtml5Tokenizer::COMMENT_END_DASH
,
1506 NS_HTML5_CONTINUE(stateloop
);
1509 appendStrBufCarriageReturn
<P
>();
1510 state
= P::transition(mViewSource
.get(),
1511 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1512 NS_HTML5_BREAK(stateloop
);
1515 appendStrBufLineFeed
<P
>();
1516 state
= P::transition(mViewSource
.get(),
1517 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1518 NS_HTML5_CONTINUE(stateloop
);
1526 state
= P::transition(mViewSource
.get(),
1527 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1528 NS_HTML5_CONTINUE(stateloop
);
1533 case COMMENT_LESSTHAN
: {
1535 if (++pos
== endPos
) {
1536 NS_HTML5_BREAK(stateloop
);
1538 c
= P::checkChar(this, buf
, pos
);
1542 state
= P::transition(mViewSource
.get(),
1543 nsHtml5Tokenizer::COMMENT_LESSTHAN_BANG
,
1545 NS_HTML5_BREAK(commentlessthanloop
);
1553 state
= P::transition(mViewSource
.get(),
1554 nsHtml5Tokenizer::COMMENT_END_DASH
,
1556 NS_HTML5_CONTINUE(stateloop
);
1559 appendStrBufCarriageReturn
<P
>();
1560 state
= P::transition(mViewSource
.get(),
1561 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1562 NS_HTML5_BREAK(stateloop
);
1565 appendStrBufLineFeed
<P
>();
1566 state
= P::transition(mViewSource
.get(),
1567 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1568 NS_HTML5_CONTINUE(stateloop
);
1576 state
= P::transition(mViewSource
.get(),
1577 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1578 NS_HTML5_CONTINUE(stateloop
);
1582 commentlessthanloop_end
:;
1585 case COMMENT_LESSTHAN_BANG
: {
1587 if (++pos
== endPos
) {
1588 NS_HTML5_BREAK(stateloop
);
1590 c
= P::checkChar(this, buf
, pos
);
1594 state
= P::transition(
1596 nsHtml5Tokenizer::COMMENT_LESSTHAN_BANG_DASH
, reconsume
, pos
);
1597 NS_HTML5_BREAK(commentlessthanbangloop
);
1601 state
= P::transition(mViewSource
.get(),
1602 nsHtml5Tokenizer::COMMENT_LESSTHAN
,
1604 NS_HTML5_CONTINUE(stateloop
);
1607 appendStrBufCarriageReturn
<P
>();
1608 state
= P::transition(mViewSource
.get(),
1609 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1610 NS_HTML5_BREAK(stateloop
);
1613 appendStrBufLineFeed
<P
>();
1614 state
= P::transition(mViewSource
.get(),
1615 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1616 NS_HTML5_CONTINUE(stateloop
);
1624 state
= P::transition(mViewSource
.get(),
1625 nsHtml5Tokenizer::COMMENT
, reconsume
, pos
);
1626 NS_HTML5_CONTINUE(stateloop
);
1630 commentlessthanbangloop_end
:;
1633 case COMMENT_LESSTHAN_BANG_DASH
: {
1634 if (++pos
== endPos
) {
1635 NS_HTML5_BREAK(stateloop
);
1637 c
= P::checkChar(this, buf
, pos
);
1642 P::transition(mViewSource
.get(),
1643 nsHtml5Tokenizer::COMMENT_LESSTHAN_BANG_DASH_DASH
,
1649 state
= P::transition(mViewSource
.get(),
1650 nsHtml5Tokenizer::COMMENT_LESSTHAN
, reconsume
,
1652 NS_HTML5_CONTINUE(stateloop
);
1655 appendStrBufCarriageReturn
<P
>();
1656 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1658 NS_HTML5_BREAK(stateloop
);
1661 appendStrBufLineFeed
<P
>();
1662 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1664 NS_HTML5_CONTINUE(stateloop
);
1672 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1674 NS_HTML5_CONTINUE(stateloop
);
1679 case COMMENT_LESSTHAN_BANG_DASH_DASH
: {
1680 if (++pos
== endPos
) {
1681 NS_HTML5_BREAK(stateloop
);
1683 c
= P::checkChar(this, buf
, pos
);
1687 emitComment(3, pos
);
1688 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
1690 if (shouldSuspend
) {
1691 NS_HTML5_BREAK(stateloop
);
1693 NS_HTML5_CONTINUE(stateloop
);
1696 if (P::reportErrors
) {
1699 adjustDoubleHyphenAndAppendToStrBufAndErr(
1700 c
, reportedConsecutiveHyphens
);
1701 reportedConsecutiveHyphens
= true;
1703 P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT_END
,
1705 NS_HTML5_CONTINUE(stateloop
);
1709 P::silentCarriageReturn(this);
1710 if (P::reportErrors
) {
1713 adjustDoubleHyphenAndAppendToStrBufAndErr(
1714 c
, reportedConsecutiveHyphens
);
1715 reportedConsecutiveHyphens
= true;
1716 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1718 NS_HTML5_BREAK(stateloop
);
1721 P::silentLineFeed(this);
1722 if (P::reportErrors
) {
1725 adjustDoubleHyphenAndAppendToStrBufAndErr(
1726 c
, reportedConsecutiveHyphens
);
1727 reportedConsecutiveHyphens
= true;
1728 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1730 NS_HTML5_CONTINUE(stateloop
);
1733 if (P::reportErrors
) {
1736 adjustDoubleHyphenAndAppendToStrBufAndErr(
1737 c
, reportedConsecutiveHyphens
);
1738 reportedConsecutiveHyphens
= true;
1739 state
= P::transition(mViewSource
.get(),
1740 nsHtml5Tokenizer::COMMENT_END_BANG
, reconsume
,
1742 NS_HTML5_CONTINUE(stateloop
);
1749 if (P::reportErrors
) {
1752 adjustDoubleHyphenAndAppendToStrBufAndErr(
1753 c
, reportedConsecutiveHyphens
);
1754 reportedConsecutiveHyphens
= true;
1755 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1757 NS_HTML5_CONTINUE(stateloop
);
1761 case COMMENT_START_DASH
: {
1762 if (++pos
== endPos
) {
1763 NS_HTML5_BREAK(stateloop
);
1765 c
= P::checkChar(this, buf
, pos
);
1770 P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT_END
,
1772 NS_HTML5_CONTINUE(stateloop
);
1775 if (P::reportErrors
) {
1776 errPrematureEndOfComment();
1778 emitComment(1, pos
);
1779 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
1781 if (shouldSuspend
) {
1782 NS_HTML5_BREAK(stateloop
);
1784 NS_HTML5_CONTINUE(stateloop
);
1788 state
= P::transition(mViewSource
.get(),
1789 nsHtml5Tokenizer::COMMENT_LESSTHAN
, reconsume
,
1791 NS_HTML5_CONTINUE(stateloop
);
1794 appendStrBufCarriageReturn
<P
>();
1795 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1797 NS_HTML5_BREAK(stateloop
);
1800 appendStrBufLineFeed
<P
>();
1801 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1803 NS_HTML5_CONTINUE(stateloop
);
1811 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::COMMENT
,
1813 NS_HTML5_CONTINUE(stateloop
);
1819 if (++pos
== endPos
) {
1820 NS_HTML5_BREAK(stateloop
);
1822 c
= P::checkChar(this, buf
, pos
);
1824 if (c
== nsHtml5Tokenizer::CDATA_LSQB
[index
]) {
1827 if (P::reportErrors
) {
1831 state
= P::transition(mViewSource
.get(),
1832 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
1834 NS_HTML5_CONTINUE(stateloop
);
1839 clearStrBufAfterUse();
1843 P::transition(mViewSource
.get(),
1844 nsHtml5Tokenizer::CDATA_SECTION
, reconsume
, pos
);
1850 case CDATA_SECTION
: {
1855 if (++pos
== endPos
) {
1856 NS_HTML5_BREAK(stateloop
);
1858 c
= P::checkChar(this, buf
, pos
);
1862 flushChars(buf
, pos
);
1864 P::transition(mViewSource
.get(), nsHtml5Tokenizer::CDATA_RSQB
,
1866 NS_HTML5_BREAK(cdatasectionloop
);
1869 maybeEmitReplacementCharacter(buf
, pos
);
1873 emitCarriageReturn
<P
>(buf
, pos
);
1874 NS_HTML5_BREAK(stateloop
);
1877 P::silentLineFeed(this);
1885 cdatasectionloop_end
:;
1889 if (++pos
== endPos
) {
1890 NS_HTML5_BREAK(stateloop
);
1892 c
= P::checkChar(this, buf
, pos
);
1895 state
= P::transition(mViewSource
.get(),
1896 nsHtml5Tokenizer::CDATA_RSQB_RSQB
, reconsume
,
1901 tokenHandler
->characters(nsHtml5Tokenizer::RSQB_RSQB
, 0, 1);
1905 P::transition(mViewSource
.get(),
1906 nsHtml5Tokenizer::CDATA_SECTION
, reconsume
, pos
);
1907 NS_HTML5_CONTINUE(stateloop
);
1912 case CDATA_RSQB_RSQB
: {
1914 if (++pos
== endPos
) {
1915 NS_HTML5_BREAK(stateloop
);
1917 c
= P::checkChar(this, buf
, pos
);
1920 tokenHandler
->characters(nsHtml5Tokenizer::RSQB_RSQB
, 0, 1);
1925 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
1927 suspendIfRequestedAfterCurrentNonTextToken();
1928 if (shouldSuspend
) {
1929 NS_HTML5_BREAK(stateloop
);
1931 NS_HTML5_CONTINUE(stateloop
);
1934 tokenHandler
->characters(nsHtml5Tokenizer::RSQB_RSQB
, 0, 2);
1937 state
= P::transition(mViewSource
.get(),
1938 nsHtml5Tokenizer::CDATA_SECTION
, reconsume
,
1940 NS_HTML5_CONTINUE(stateloop
);
1945 case ATTRIBUTE_VALUE_SINGLE_QUOTED
: {
1950 if (++pos
== endPos
) {
1951 NS_HTML5_BREAK(stateloop
);
1953 c
= P::checkChar(this, buf
, pos
);
1957 addAttributeWithValue();
1959 P::transition(mViewSource
.get(),
1960 nsHtml5Tokenizer::AFTER_ATTRIBUTE_VALUE_QUOTED
,
1962 NS_HTML5_CONTINUE(stateloop
);
1965 MOZ_ASSERT(!charRefBufLen
,
1966 "charRefBufLen not reset after previous use!");
1967 appendCharRefBuf(c
);
1968 setAdditionalAndRememberAmpersandLocation('\'');
1969 returnState
= state
;
1971 P::transition(mViewSource
.get(),
1972 nsHtml5Tokenizer::CONSUME_CHARACTER_REFERENCE
,
1974 NS_HTML5_BREAK(attributevaluesinglequotedloop
);
1977 appendStrBufCarriageReturn
<P
>();
1978 NS_HTML5_BREAK(stateloop
);
1981 appendStrBufLineFeed
<P
>();
1994 attributevaluesinglequotedloop_end
:;
1997 case CONSUME_CHARACTER_REFERENCE
: {
1998 if (++pos
== endPos
) {
1999 NS_HTML5_BREAK(stateloop
);
2001 c
= P::checkChar(this, buf
, pos
);
2012 emitOrAppendCharRefBuf(returnState
);
2013 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2018 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2019 NS_HTML5_CONTINUE(stateloop
);
2022 appendCharRefBuf('#');
2024 P::transition(mViewSource
.get(), nsHtml5Tokenizer::CONSUME_NCR
,
2026 NS_HTML5_CONTINUE(stateloop
);
2029 if (c
== additional
) {
2030 emitOrAppendCharRefBuf(returnState
);
2033 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2034 NS_HTML5_CONTINUE(stateloop
);
2036 if (c
>= 'a' && c
<= 'z') {
2037 firstCharKey
= c
- 'a' + 26;
2038 } else if (c
>= 'A' && c
<= 'Z') {
2039 firstCharKey
= c
- 'A';
2042 if (P::reportErrors
) {
2043 errNoNamedCharacterMatch();
2046 emitOrAppendCharRefBuf(returnState
);
2047 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2052 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2053 NS_HTML5_CONTINUE(stateloop
);
2055 appendCharRefBuf(c
);
2057 P::transition(mViewSource
.get(),
2058 nsHtml5Tokenizer::CHARACTER_REFERENCE_HILO_LOOKUP
,
2065 case CHARACTER_REFERENCE_HILO_LOOKUP
: {
2067 if (++pos
== endPos
) {
2068 NS_HTML5_BREAK(stateloop
);
2070 c
= P::checkChar(this, buf
, pos
);
2073 const int32_t* row
= nsHtml5NamedCharactersAccel::HILO_ACCEL
[c
];
2075 hilo
= row
[firstCharKey
];
2080 if (P::reportErrors
) {
2081 errNoNamedCharacterMatch();
2084 emitOrAppendCharRefBuf(returnState
);
2085 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2090 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2091 NS_HTML5_CONTINUE(stateloop
);
2093 appendCharRefBuf(c
);
2099 state
= P::transition(mViewSource
.get(),
2100 nsHtml5Tokenizer::CHARACTER_REFERENCE_TAIL
,
2105 case CHARACTER_REFERENCE_TAIL
: {
2107 if (++pos
== endPos
) {
2108 NS_HTML5_BREAK(stateloop
);
2110 c
= P::checkChar(this, buf
, pos
);
2114 NS_HTML5_BREAK(outer
);
2116 if (entCol
== nsHtml5NamedCharacters::NAMES
[lo
].length()) {
2118 charRefBufMark
= charRefBufLen
;
2120 } else if (entCol
> nsHtml5NamedCharacters::NAMES
[lo
].length()) {
2121 NS_HTML5_BREAK(outer
);
2122 } else if (c
> nsHtml5NamedCharacters::NAMES
[lo
].charAt(entCol
)) {
2125 NS_HTML5_BREAK(loloop
);
2131 NS_HTML5_BREAK(outer
);
2133 if (entCol
== nsHtml5NamedCharacters::NAMES
[hi
].length()) {
2134 NS_HTML5_BREAK(hiloop
);
2136 if (entCol
> nsHtml5NamedCharacters::NAMES
[hi
].length()) {
2137 NS_HTML5_BREAK(outer
);
2138 } else if (c
< nsHtml5NamedCharacters::NAMES
[hi
].charAt(entCol
)) {
2141 NS_HTML5_BREAK(hiloop
);
2146 if (entCol
+ 1 == nsHtml5NamedCharacters::NAMES
[lo
].length()) {
2148 charRefBufMark
= charRefBufLen
;
2150 NS_HTML5_BREAK(outer
);
2153 NS_HTML5_BREAK(outer
);
2155 appendCharRefBuf(c
);
2159 if (candidate
== -1) {
2161 if (P::reportErrors
) {
2162 errNoNamedCharacterMatch();
2165 emitOrAppendCharRefBuf(returnState
);
2166 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2170 state
= P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2171 NS_HTML5_CONTINUE(stateloop
);
2173 const nsHtml5CharacterName
& candidateName
=
2174 nsHtml5NamedCharacters::NAMES
[candidate
];
2175 if (!candidateName
.length() ||
2176 candidateName
.charAt(candidateName
.length() - 1) != ';') {
2177 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
2179 if (charRefBufMark
== charRefBufLen
) {
2182 ch
= charRefBuf
[charRefBufMark
];
2184 if (ch
== '=' || (ch
>= '0' && ch
<= '9') ||
2185 (ch
>= 'A' && ch
<= 'Z') || (ch
>= 'a' && ch
<= 'z')) {
2187 if (P::reportErrors
) {
2188 errNoNamedCharacterMatch();
2191 appendCharRefBufToStrBuf();
2193 state
= P::transition(mViewSource
.get(), returnState
, reconsume
,
2195 NS_HTML5_CONTINUE(stateloop
);
2198 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
2199 if (P::reportErrors
) {
2200 errUnescapedAmpersandInterpretedAsCharacterReference();
2203 if (P::reportErrors
) {
2204 errNotSemicolonTerminated();
2208 P::completedNamedCharacterReference(mViewSource
.get());
2209 const char16_t
* val
= nsHtml5NamedCharacters::VALUES
[candidate
];
2211 emitOrAppendOne(val
, returnState
);
2213 emitOrAppendTwo(val
, returnState
);
2215 if (charRefBufMark
< charRefBufLen
) {
2216 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
2217 appendStrBuf(charRefBuf
, charRefBufMark
,
2218 charRefBufLen
- charRefBufMark
);
2220 tokenHandler
->characters(charRefBuf
, charRefBufMark
,
2221 charRefBufLen
- charRefBufMark
);
2224 bool earlyBreak
= (c
== ';' && charRefBufMark
== charRefBufLen
);
2226 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2227 cstart
= earlyBreak
? pos
+ 1 : pos
;
2229 reconsume
= !earlyBreak
;
2230 state
= P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2231 NS_HTML5_CONTINUE(stateloop
);
2235 if (++pos
== endPos
) {
2236 NS_HTML5_BREAK(stateloop
);
2238 c
= P::checkChar(this, buf
, pos
);
2244 appendCharRefBuf(c
);
2246 P::transition(mViewSource
.get(), nsHtml5Tokenizer::HEX_NCR_LOOP
,
2248 NS_HTML5_CONTINUE(stateloop
);
2252 state
= P::transition(mViewSource
.get(),
2253 nsHtml5Tokenizer::DECIMAL_NRC_LOOP
, reconsume
,
2260 case DECIMAL_NRC_LOOP
: {
2265 if (++pos
== endPos
) {
2266 NS_HTML5_BREAK(stateloop
);
2268 c
= P::checkChar(this, buf
, pos
);
2270 MOZ_ASSERT(value
>= 0, "value must not become negative.");
2271 if (c
>= '0' && c
<= '9') {
2273 if (value
<= 0x10FFFF) {
2278 } else if (c
== ';') {
2280 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2283 state
= P::transition(mViewSource
.get(),
2284 nsHtml5Tokenizer::HANDLE_NCR_VALUE
,
2286 NS_HTML5_BREAK(decimalloop
);
2288 if (P::reportErrors
) {
2291 appendCharRefBuf(';');
2292 emitOrAppendCharRefBuf(returnState
);
2293 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2297 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2298 NS_HTML5_CONTINUE(stateloop
);
2302 if (P::reportErrors
) {
2305 emitOrAppendCharRefBuf(returnState
);
2306 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2311 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2312 NS_HTML5_CONTINUE(stateloop
);
2314 if (P::reportErrors
) {
2315 errCharRefLacksSemicolon();
2317 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2321 state
= P::transition(mViewSource
.get(),
2322 nsHtml5Tokenizer::HANDLE_NCR_VALUE
,
2324 NS_HTML5_BREAK(decimalloop
);
2331 case HANDLE_NCR_VALUE
: {
2333 handleNcrValue(returnState
);
2334 state
= P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2335 NS_HTML5_CONTINUE(stateloop
);
2337 case HEX_NCR_LOOP
: {
2339 if (++pos
== endPos
) {
2340 NS_HTML5_BREAK(stateloop
);
2342 c
= P::checkChar(this, buf
, pos
);
2343 MOZ_ASSERT(value
>= 0, "value must not become negative.");
2344 if (c
>= '0' && c
<= '9') {
2346 if (value
<= 0x10FFFF) {
2351 } else if (c
>= 'A' && c
<= 'F') {
2353 if (value
<= 0x10FFFF) {
2355 value
+= c
- 'A' + 10;
2358 } else if (c
>= 'a' && c
<= 'f') {
2360 if (value
<= 0x10FFFF) {
2362 value
+= c
- 'a' + 10;
2365 } else if (c
== ';') {
2367 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2370 state
= P::transition(mViewSource
.get(),
2371 nsHtml5Tokenizer::HANDLE_NCR_VALUE
,
2373 NS_HTML5_CONTINUE(stateloop
);
2375 if (P::reportErrors
) {
2378 appendCharRefBuf(';');
2379 emitOrAppendCharRefBuf(returnState
);
2380 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2384 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2385 NS_HTML5_CONTINUE(stateloop
);
2389 if (P::reportErrors
) {
2392 emitOrAppendCharRefBuf(returnState
);
2393 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2398 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2399 NS_HTML5_CONTINUE(stateloop
);
2401 if (P::reportErrors
) {
2402 errCharRefLacksSemicolon();
2404 if (!(returnState
& DATA_AND_RCDATA_MASK
)) {
2408 state
= P::transition(mViewSource
.get(),
2409 nsHtml5Tokenizer::HANDLE_NCR_VALUE
,
2411 NS_HTML5_CONTINUE(stateloop
);
2421 if (++pos
== endPos
) {
2422 NS_HTML5_BREAK(stateloop
);
2424 c
= P::checkChar(this, buf
, pos
);
2428 emitPlaintextReplacementCharacter(buf
, pos
);
2432 emitCarriageReturn
<P
>(buf
, pos
);
2433 NS_HTML5_BREAK(stateloop
);
2436 P::silentLineFeed(this);
2445 case CLOSE_TAG_OPEN
: {
2446 if (++pos
== endPos
) {
2447 NS_HTML5_BREAK(stateloop
);
2449 c
= P::checkChar(this, buf
, pos
);
2452 if (P::reportErrors
) {
2456 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
2458 NS_HTML5_CONTINUE(stateloop
);
2461 P::silentCarriageReturn(this);
2462 if (P::reportErrors
) {
2463 errGarbageAfterLtSlash();
2465 clearStrBufBeforeUse();
2468 P::transition(mViewSource
.get(),
2469 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
, pos
);
2470 NS_HTML5_BREAK(stateloop
);
2473 P::silentLineFeed(this);
2474 if (P::reportErrors
) {
2475 errGarbageAfterLtSlash();
2477 clearStrBufBeforeUse();
2480 P::transition(mViewSource
.get(),
2481 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
, pos
);
2482 NS_HTML5_CONTINUE(stateloop
);
2489 if (c
>= 'A' && c
<= 'Z') {
2492 if (c
>= 'a' && c
<= 'z') {
2494 clearStrBufBeforeUse();
2496 containsHyphen
= false;
2497 state
= P::transition(mViewSource
.get(),
2498 nsHtml5Tokenizer::TAG_NAME
, reconsume
, pos
);
2499 NS_HTML5_CONTINUE(stateloop
);
2501 if (P::reportErrors
) {
2502 errGarbageAfterLtSlash();
2504 clearStrBufBeforeUse();
2506 state
= P::transition(mViewSource
.get(),
2507 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
2509 NS_HTML5_CONTINUE(stateloop
);
2519 if (++pos
== endPos
) {
2520 NS_HTML5_BREAK(stateloop
);
2522 c
= P::checkChar(this, buf
, pos
);
2526 flushChars(buf
, pos
);
2527 MOZ_ASSERT(!charRefBufLen
,
2528 "charRefBufLen not reset after previous use!");
2529 appendCharRefBuf(c
);
2530 setAdditionalAndRememberAmpersandLocation('\0');
2531 returnState
= state
;
2533 P::transition(mViewSource
.get(),
2534 nsHtml5Tokenizer::CONSUME_CHARACTER_REFERENCE
,
2536 NS_HTML5_CONTINUE(stateloop
);
2539 flushChars(buf
, pos
);
2540 returnState
= state
;
2542 P::transition(mViewSource
.get(),
2543 nsHtml5Tokenizer::RAWTEXT_RCDATA_LESS_THAN_SIGN
,
2545 NS_HTML5_CONTINUE(stateloop
);
2548 emitReplacementCharacter(buf
, pos
);
2552 emitCarriageReturn
<P
>(buf
, pos
);
2553 NS_HTML5_BREAK(stateloop
);
2556 P::silentLineFeed(this);
2570 if (++pos
== endPos
) {
2571 NS_HTML5_BREAK(stateloop
);
2573 c
= P::checkChar(this, buf
, pos
);
2577 flushChars(buf
, pos
);
2578 returnState
= state
;
2580 P::transition(mViewSource
.get(),
2581 nsHtml5Tokenizer::RAWTEXT_RCDATA_LESS_THAN_SIGN
,
2583 NS_HTML5_BREAK(rawtextloop
);
2586 emitReplacementCharacter(buf
, pos
);
2590 emitCarriageReturn
<P
>(buf
, pos
);
2591 NS_HTML5_BREAK(stateloop
);
2594 P::silentLineFeed(this);
2605 case RAWTEXT_RCDATA_LESS_THAN_SIGN
: {
2607 if (++pos
== endPos
) {
2608 NS_HTML5_BREAK(stateloop
);
2610 c
= P::checkChar(this, buf
, pos
);
2614 clearStrBufBeforeUse();
2615 state
= P::transition(mViewSource
.get(),
2616 nsHtml5Tokenizer::NON_DATA_END_TAG_NAME
,
2618 NS_HTML5_BREAK(rawtextrcdatalessthansignloop
);
2621 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
2625 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2626 NS_HTML5_CONTINUE(stateloop
);
2630 rawtextrcdatalessthansignloop_end
:;
2633 case NON_DATA_END_TAG_NAME
: {
2635 if (++pos
== endPos
) {
2636 NS_HTML5_BREAK(stateloop
);
2638 c
= P::checkChar(this, buf
, pos
);
2639 if (!endTagExpectationAsArray
) {
2640 tokenHandler
->characters(nsHtml5Tokenizer::LT_SOLIDUS
, 0, 2);
2644 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2645 NS_HTML5_CONTINUE(stateloop
);
2646 } else if (index
< endTagExpectationAsArray
.length
) {
2647 char16_t e
= endTagExpectationAsArray
[index
];
2648 char16_t folded
= c
;
2649 if (c
>= 'A' && c
<= 'Z') {
2653 tokenHandler
->characters(nsHtml5Tokenizer::LT_SOLIDUS
, 0, 2);
2658 P::transition(mViewSource
.get(), returnState
, reconsume
, pos
);
2659 NS_HTML5_CONTINUE(stateloop
);
2666 tagName
= endTagExpectation
;
2669 P::silentCarriageReturn(this);
2670 clearStrBufAfterUse();
2671 state
= P::transition(mViewSource
.get(),
2672 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
2674 NS_HTML5_BREAK(stateloop
);
2677 P::silentLineFeed(this);
2683 clearStrBufAfterUse();
2684 state
= P::transition(mViewSource
.get(),
2685 nsHtml5Tokenizer::BEFORE_ATTRIBUTE_NAME
,
2687 NS_HTML5_CONTINUE(stateloop
);
2690 clearStrBufAfterUse();
2691 state
= P::transition(mViewSource
.get(),
2692 nsHtml5Tokenizer::SELF_CLOSING_START_TAG
,
2694 NS_HTML5_CONTINUE(stateloop
);
2697 clearStrBufAfterUse();
2698 state
= P::transition(mViewSource
.get(),
2699 emitCurrentTagToken(false, pos
),
2701 if (shouldSuspend
) {
2702 NS_HTML5_BREAK(stateloop
);
2704 NS_HTML5_CONTINUE(stateloop
);
2707 tokenHandler
->characters(nsHtml5Tokenizer::LT_SOLIDUS
, 0, 2);
2711 state
= P::transition(mViewSource
.get(), returnState
, reconsume
,
2713 NS_HTML5_CONTINUE(stateloop
);
2719 case BOGUS_COMMENT
: {
2724 if (++pos
== endPos
) {
2725 NS_HTML5_BREAK(stateloop
);
2727 c
= P::checkChar(this, buf
, pos
);
2731 emitComment(0, pos
);
2732 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
2734 if (shouldSuspend
) {
2735 NS_HTML5_BREAK(stateloop
);
2737 NS_HTML5_CONTINUE(stateloop
);
2741 state
= P::transition(mViewSource
.get(),
2742 nsHtml5Tokenizer::BOGUS_COMMENT_HYPHEN
,
2744 NS_HTML5_BREAK(boguscommentloop
);
2747 appendStrBufCarriageReturn
<P
>();
2748 NS_HTML5_BREAK(stateloop
);
2751 appendStrBufLineFeed
<P
>();
2764 boguscommentloop_end
:;
2767 case BOGUS_COMMENT_HYPHEN
: {
2768 boguscommenthyphenloop
:
2770 if (++pos
== endPos
) {
2771 NS_HTML5_BREAK(stateloop
);
2773 c
= P::checkChar(this, buf
, pos
);
2776 emitComment(0, pos
);
2777 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
2779 if (shouldSuspend
) {
2780 NS_HTML5_BREAK(stateloop
);
2782 NS_HTML5_CONTINUE(stateloop
);
2785 appendSecondHyphenToBogusComment();
2786 NS_HTML5_CONTINUE(boguscommenthyphenloop
);
2789 appendStrBufCarriageReturn
<P
>();
2790 state
= P::transition(mViewSource
.get(),
2791 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
2793 NS_HTML5_BREAK(stateloop
);
2796 appendStrBufLineFeed
<P
>();
2797 state
= P::transition(mViewSource
.get(),
2798 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
2800 NS_HTML5_CONTINUE(stateloop
);
2808 state
= P::transition(mViewSource
.get(),
2809 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
2811 NS_HTML5_CONTINUE(stateloop
);
2821 if (++pos
== endPos
) {
2822 NS_HTML5_BREAK(stateloop
);
2824 c
= P::checkChar(this, buf
, pos
);
2828 flushChars(buf
, pos
);
2829 returnState
= state
;
2830 state
= P::transition(
2832 nsHtml5Tokenizer::SCRIPT_DATA_LESS_THAN_SIGN
, reconsume
, pos
);
2833 NS_HTML5_BREAK(scriptdataloop
);
2836 emitReplacementCharacter(buf
, pos
);
2840 emitCarriageReturn
<P
>(buf
, pos
);
2841 NS_HTML5_BREAK(stateloop
);
2844 P::silentLineFeed(this);
2852 scriptdataloop_end
:;
2855 case SCRIPT_DATA_LESS_THAN_SIGN
: {
2857 if (++pos
== endPos
) {
2858 NS_HTML5_BREAK(stateloop
);
2860 c
= P::checkChar(this, buf
, pos
);
2864 clearStrBufBeforeUse();
2865 state
= P::transition(mViewSource
.get(),
2866 nsHtml5Tokenizer::NON_DATA_END_TAG_NAME
,
2868 NS_HTML5_CONTINUE(stateloop
);
2871 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
2873 state
= P::transition(mViewSource
.get(),
2874 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPE_START
,
2876 NS_HTML5_BREAK(scriptdatalessthansignloop
);
2879 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
2883 P::transition(mViewSource
.get(),
2884 nsHtml5Tokenizer::SCRIPT_DATA
, reconsume
, pos
);
2885 NS_HTML5_CONTINUE(stateloop
);
2889 scriptdatalessthansignloop_end
:;
2892 case SCRIPT_DATA_ESCAPE_START
: {
2894 if (++pos
== endPos
) {
2895 NS_HTML5_BREAK(stateloop
);
2897 c
= P::checkChar(this, buf
, pos
);
2901 P::transition(mViewSource
.get(),
2902 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPE_START_DASH
,
2904 NS_HTML5_BREAK(scriptdataescapestartloop
);
2909 P::transition(mViewSource
.get(),
2910 nsHtml5Tokenizer::SCRIPT_DATA
, reconsume
, pos
);
2911 NS_HTML5_CONTINUE(stateloop
);
2915 scriptdataescapestartloop_end
:;
2918 case SCRIPT_DATA_ESCAPE_START_DASH
: {
2920 if (++pos
== endPos
) {
2921 NS_HTML5_BREAK(stateloop
);
2923 c
= P::checkChar(this, buf
, pos
);
2927 P::transition(mViewSource
.get(),
2928 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED_DASH_DASH
,
2930 NS_HTML5_BREAK(scriptdataescapestartdashloop
);
2935 P::transition(mViewSource
.get(),
2936 nsHtml5Tokenizer::SCRIPT_DATA
, reconsume
, pos
);
2937 NS_HTML5_CONTINUE(stateloop
);
2941 scriptdataescapestartdashloop_end
:;
2944 case SCRIPT_DATA_ESCAPED_DASH_DASH
: {
2946 if (++pos
== endPos
) {
2947 NS_HTML5_BREAK(stateloop
);
2949 c
= P::checkChar(this, buf
, pos
);
2955 flushChars(buf
, pos
);
2956 state
= P::transition(
2958 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN
,
2960 NS_HTML5_CONTINUE(stateloop
);
2964 P::transition(mViewSource
.get(),
2965 nsHtml5Tokenizer::SCRIPT_DATA
, reconsume
, pos
);
2966 NS_HTML5_CONTINUE(stateloop
);
2969 emitReplacementCharacter(buf
, pos
);
2970 state
= P::transition(mViewSource
.get(),
2971 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
2973 NS_HTML5_BREAK(scriptdataescapeddashdashloop
);
2976 emitCarriageReturn
<P
>(buf
, pos
);
2977 state
= P::transition(mViewSource
.get(),
2978 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
2980 NS_HTML5_BREAK(stateloop
);
2983 P::silentLineFeed(this);
2987 state
= P::transition(mViewSource
.get(),
2988 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
2990 NS_HTML5_BREAK(scriptdataescapeddashdashloop
);
2994 scriptdataescapeddashdashloop_end
:;
2997 case SCRIPT_DATA_ESCAPED
: {
3002 if (++pos
== endPos
) {
3003 NS_HTML5_BREAK(stateloop
);
3005 c
= P::checkChar(this, buf
, pos
);
3009 state
= P::transition(mViewSource
.get(),
3010 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED_DASH
,
3012 NS_HTML5_BREAK(scriptdataescapedloop
);
3015 flushChars(buf
, pos
);
3016 state
= P::transition(
3018 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN
,
3020 NS_HTML5_CONTINUE(stateloop
);
3023 emitReplacementCharacter(buf
, pos
);
3027 emitCarriageReturn
<P
>(buf
, pos
);
3028 NS_HTML5_BREAK(stateloop
);
3031 P::silentLineFeed(this);
3039 scriptdataescapedloop_end
:;
3042 case SCRIPT_DATA_ESCAPED_DASH
: {
3044 if (++pos
== endPos
) {
3045 NS_HTML5_BREAK(stateloop
);
3047 c
= P::checkChar(this, buf
, pos
);
3051 P::transition(mViewSource
.get(),
3052 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED_DASH_DASH
,
3054 NS_HTML5_CONTINUE(stateloop
);
3057 flushChars(buf
, pos
);
3058 state
= P::transition(
3060 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN
,
3062 NS_HTML5_BREAK(scriptdataescapeddashloop
);
3065 emitReplacementCharacter(buf
, pos
);
3066 state
= P::transition(mViewSource
.get(),
3067 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3069 NS_HTML5_CONTINUE(stateloop
);
3072 emitCarriageReturn
<P
>(buf
, pos
);
3073 state
= P::transition(mViewSource
.get(),
3074 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3076 NS_HTML5_BREAK(stateloop
);
3079 P::silentLineFeed(this);
3083 state
= P::transition(mViewSource
.get(),
3084 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3086 NS_HTML5_CONTINUE(stateloop
);
3090 scriptdataescapeddashloop_end
:;
3093 case SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN
: {
3095 if (++pos
== endPos
) {
3096 NS_HTML5_BREAK(stateloop
);
3098 c
= P::checkChar(this, buf
, pos
);
3102 clearStrBufBeforeUse();
3103 returnState
= nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
;
3104 state
= P::transition(mViewSource
.get(),
3105 nsHtml5Tokenizer::NON_DATA_END_TAG_NAME
,
3107 NS_HTML5_CONTINUE(stateloop
);
3111 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
3114 state
= P::transition(
3116 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPE_START
, reconsume
,
3118 NS_HTML5_BREAK(scriptdataescapedlessthanloop
);
3121 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
3124 state
= P::transition(mViewSource
.get(),
3125 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3127 NS_HTML5_CONTINUE(stateloop
);
3131 scriptdataescapedlessthanloop_end
:;
3134 case SCRIPT_DATA_DOUBLE_ESCAPE_START
: {
3136 if (++pos
== endPos
) {
3137 NS_HTML5_BREAK(stateloop
);
3139 c
= P::checkChar(this, buf
, pos
);
3140 MOZ_ASSERT(index
> 0);
3142 char16_t folded
= c
;
3143 if (c
>= 'A' && c
<= 'Z') {
3146 if (folded
!= nsHtml5Tokenizer::SCRIPT_ARR
[index
]) {
3148 state
= P::transition(mViewSource
.get(),
3149 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3151 NS_HTML5_CONTINUE(stateloop
);
3158 emitCarriageReturn
<P
>(buf
, pos
);
3159 state
= P::transition(
3161 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3162 NS_HTML5_BREAK(stateloop
);
3165 P::silentLineFeed(this);
3173 state
= P::transition(
3175 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3176 NS_HTML5_BREAK(scriptdatadoubleescapestartloop
);
3180 state
= P::transition(mViewSource
.get(),
3181 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3183 NS_HTML5_CONTINUE(stateloop
);
3187 scriptdatadoubleescapestartloop_end
:;
3190 case SCRIPT_DATA_DOUBLE_ESCAPED
: {
3195 if (++pos
== endPos
) {
3196 NS_HTML5_BREAK(stateloop
);
3198 c
= P::checkChar(this, buf
, pos
);
3202 state
= P::transition(
3204 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED_DASH
, reconsume
,
3206 NS_HTML5_BREAK(scriptdatadoubleescapedloop
);
3209 state
= P::transition(
3211 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN
,
3213 NS_HTML5_CONTINUE(stateloop
);
3216 emitReplacementCharacter(buf
, pos
);
3220 emitCarriageReturn
<P
>(buf
, pos
);
3221 NS_HTML5_BREAK(stateloop
);
3224 P::silentLineFeed(this);
3232 scriptdatadoubleescapedloop_end
:;
3235 case SCRIPT_DATA_DOUBLE_ESCAPED_DASH
: {
3237 if (++pos
== endPos
) {
3238 NS_HTML5_BREAK(stateloop
);
3240 c
= P::checkChar(this, buf
, pos
);
3243 state
= P::transition(
3245 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH
,
3247 NS_HTML5_BREAK(scriptdatadoubleescapeddashloop
);
3250 state
= P::transition(
3252 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN
,
3254 NS_HTML5_CONTINUE(stateloop
);
3257 emitReplacementCharacter(buf
, pos
);
3258 state
= P::transition(
3260 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3261 NS_HTML5_CONTINUE(stateloop
);
3264 emitCarriageReturn
<P
>(buf
, pos
);
3265 state
= P::transition(
3267 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3268 NS_HTML5_BREAK(stateloop
);
3271 P::silentLineFeed(this);
3275 state
= P::transition(
3277 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3278 NS_HTML5_CONTINUE(stateloop
);
3282 scriptdatadoubleescapeddashloop_end
:;
3285 case SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH
: {
3287 if (++pos
== endPos
) {
3288 NS_HTML5_BREAK(stateloop
);
3290 c
= P::checkChar(this, buf
, pos
);
3296 state
= P::transition(
3298 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN
,
3300 NS_HTML5_BREAK(scriptdatadoubleescapeddashdashloop
);
3304 P::transition(mViewSource
.get(),
3305 nsHtml5Tokenizer::SCRIPT_DATA
, reconsume
, pos
);
3306 NS_HTML5_CONTINUE(stateloop
);
3309 emitReplacementCharacter(buf
, pos
);
3310 state
= P::transition(
3312 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3313 NS_HTML5_CONTINUE(stateloop
);
3316 emitCarriageReturn
<P
>(buf
, pos
);
3317 state
= P::transition(
3319 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3320 NS_HTML5_BREAK(stateloop
);
3323 P::silentLineFeed(this);
3327 state
= P::transition(
3329 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3330 NS_HTML5_CONTINUE(stateloop
);
3334 scriptdatadoubleescapeddashdashloop_end
:;
3337 case SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN
: {
3339 if (++pos
== endPos
) {
3340 NS_HTML5_BREAK(stateloop
);
3342 c
= P::checkChar(this, buf
, pos
);
3347 P::transition(mViewSource
.get(),
3348 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPE_END
,
3350 NS_HTML5_BREAK(scriptdatadoubleescapedlessthanloop
);
3354 state
= P::transition(
3356 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3357 NS_HTML5_CONTINUE(stateloop
);
3361 scriptdatadoubleescapedlessthanloop_end
:;
3364 case SCRIPT_DATA_DOUBLE_ESCAPE_END
: {
3366 if (++pos
== endPos
) {
3367 NS_HTML5_BREAK(stateloop
);
3369 c
= P::checkChar(this, buf
, pos
);
3371 char16_t folded
= c
;
3372 if (c
>= 'A' && c
<= 'Z') {
3375 if (folded
!= nsHtml5Tokenizer::SCRIPT_ARR
[index
]) {
3377 state
= P::transition(
3379 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3380 NS_HTML5_CONTINUE(stateloop
);
3387 emitCarriageReturn
<P
>(buf
, pos
);
3388 state
= P::transition(mViewSource
.get(),
3389 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3391 NS_HTML5_BREAK(stateloop
);
3394 P::silentLineFeed(this);
3402 state
= P::transition(mViewSource
.get(),
3403 nsHtml5Tokenizer::SCRIPT_DATA_ESCAPED
,
3405 NS_HTML5_CONTINUE(stateloop
);
3409 state
= P::transition(
3411 nsHtml5Tokenizer::SCRIPT_DATA_DOUBLE_ESCAPED
, reconsume
, pos
);
3412 NS_HTML5_CONTINUE(stateloop
);
3417 case MARKUP_DECLARATION_OCTYPE
: {
3419 if (++pos
== endPos
) {
3420 NS_HTML5_BREAK(stateloop
);
3422 c
= P::checkChar(this, buf
, pos
);
3424 char16_t folded
= c
;
3425 if (c
>= 'A' && c
<= 'Z') {
3428 if (folded
== nsHtml5Tokenizer::OCTYPE
[index
]) {
3431 if (P::reportErrors
) {
3435 state
= P::transition(mViewSource
.get(),
3436 nsHtml5Tokenizer::BOGUS_COMMENT
, reconsume
,
3438 NS_HTML5_CONTINUE(stateloop
);
3444 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DOCTYPE
,
3446 NS_HTML5_BREAK(markupdeclarationdoctypeloop
);
3449 markupdeclarationdoctypeloop_end
:;
3457 if (++pos
== endPos
) {
3458 NS_HTML5_BREAK(stateloop
);
3460 c
= P::checkChar(this, buf
, pos
);
3462 initDoctypeFields();
3465 P::silentCarriageReturn(this);
3466 state
= P::transition(mViewSource
.get(),
3467 nsHtml5Tokenizer::BEFORE_DOCTYPE_NAME
,
3469 NS_HTML5_BREAK(stateloop
);
3472 P::silentLineFeed(this);
3478 state
= P::transition(mViewSource
.get(),
3479 nsHtml5Tokenizer::BEFORE_DOCTYPE_NAME
,
3481 NS_HTML5_BREAK(doctypeloop
);
3484 if (P::reportErrors
) {
3485 errMissingSpaceBeforeDoctypeName();
3488 state
= P::transition(mViewSource
.get(),
3489 nsHtml5Tokenizer::BEFORE_DOCTYPE_NAME
,
3491 NS_HTML5_BREAK(doctypeloop
);
3498 case BEFORE_DOCTYPE_NAME
: {
3503 if (++pos
== endPos
) {
3504 NS_HTML5_BREAK(stateloop
);
3506 c
= P::checkChar(this, buf
, pos
);
3510 P::silentCarriageReturn(this);
3511 NS_HTML5_BREAK(stateloop
);
3514 P::silentLineFeed(this);
3523 if (P::reportErrors
) {
3524 errNamelessDoctype();
3527 emitDoctypeToken(pos
);
3528 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3530 if (shouldSuspend
) {
3531 NS_HTML5_BREAK(stateloop
);
3533 NS_HTML5_CONTINUE(stateloop
);
3540 if (c
>= 'A' && c
<= 'Z') {
3543 clearStrBufBeforeUse();
3546 P::transition(mViewSource
.get(),
3547 nsHtml5Tokenizer::DOCTYPE_NAME
, reconsume
, pos
);
3548 NS_HTML5_BREAK(beforedoctypenameloop
);
3552 beforedoctypenameloop_end
:;
3555 case DOCTYPE_NAME
: {
3557 if (++pos
== endPos
) {
3558 NS_HTML5_BREAK(stateloop
);
3560 c
= P::checkChar(this, buf
, pos
);
3563 P::silentCarriageReturn(this);
3564 strBufToDoctypeName();
3565 state
= P::transition(mViewSource
.get(),
3566 nsHtml5Tokenizer::AFTER_DOCTYPE_NAME
,
3568 NS_HTML5_BREAK(stateloop
);
3571 P::silentLineFeed(this);
3577 strBufToDoctypeName();
3578 state
= P::transition(mViewSource
.get(),
3579 nsHtml5Tokenizer::AFTER_DOCTYPE_NAME
,
3581 NS_HTML5_BREAK(doctypenameloop
);
3584 strBufToDoctypeName();
3585 emitDoctypeToken(pos
);
3586 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3588 if (shouldSuspend
) {
3589 NS_HTML5_BREAK(stateloop
);
3591 NS_HTML5_CONTINUE(stateloop
);
3598 if (c
>= 'A' && c
<= 'Z') {
3606 doctypenameloop_end
:;
3609 case AFTER_DOCTYPE_NAME
: {
3611 if (++pos
== endPos
) {
3612 NS_HTML5_BREAK(stateloop
);
3614 c
= P::checkChar(this, buf
, pos
);
3617 P::silentCarriageReturn(this);
3618 NS_HTML5_BREAK(stateloop
);
3621 P::silentLineFeed(this);
3630 emitDoctypeToken(pos
);
3631 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3633 if (shouldSuspend
) {
3634 NS_HTML5_BREAK(stateloop
);
3636 NS_HTML5_CONTINUE(stateloop
);
3641 state
= P::transition(mViewSource
.get(),
3642 nsHtml5Tokenizer::DOCTYPE_UBLIC
, reconsume
,
3644 NS_HTML5_BREAK(afterdoctypenameloop
);
3649 state
= P::transition(mViewSource
.get(),
3650 nsHtml5Tokenizer::DOCTYPE_YSTEM
, reconsume
,
3652 NS_HTML5_CONTINUE(stateloop
);
3656 state
= P::transition(mViewSource
.get(),
3657 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
3659 NS_HTML5_CONTINUE(stateloop
);
3663 afterdoctypenameloop_end
:;
3666 case DOCTYPE_UBLIC
: {
3668 if (++pos
== endPos
) {
3669 NS_HTML5_BREAK(stateloop
);
3671 c
= P::checkChar(this, buf
, pos
);
3673 char16_t folded
= c
;
3674 if (c
>= 'A' && c
<= 'Z') {
3677 if (folded
!= nsHtml5Tokenizer::UBLIC
[index
]) {
3680 state
= P::transition(mViewSource
.get(),
3681 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
3683 NS_HTML5_CONTINUE(stateloop
);
3689 state
= P::transition(
3691 nsHtml5Tokenizer::AFTER_DOCTYPE_PUBLIC_KEYWORD
, reconsume
, pos
);
3692 NS_HTML5_BREAK(doctypeublicloop
);
3695 doctypeublicloop_end
:;
3698 case AFTER_DOCTYPE_PUBLIC_KEYWORD
: {
3703 if (++pos
== endPos
) {
3704 NS_HTML5_BREAK(stateloop
);
3706 c
= P::checkChar(this, buf
, pos
);
3710 P::silentCarriageReturn(this);
3711 state
= P::transition(
3713 nsHtml5Tokenizer::BEFORE_DOCTYPE_PUBLIC_IDENTIFIER
, reconsume
,
3715 NS_HTML5_BREAK(stateloop
);
3718 P::silentLineFeed(this);
3724 state
= P::transition(
3726 nsHtml5Tokenizer::BEFORE_DOCTYPE_PUBLIC_IDENTIFIER
, reconsume
,
3728 NS_HTML5_BREAK(afterdoctypepublickeywordloop
);
3731 if (P::reportErrors
) {
3732 errNoSpaceBetweenDoctypePublicKeywordAndQuote();
3734 clearStrBufBeforeUse();
3735 state
= P::transition(
3737 nsHtml5Tokenizer::DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED
,
3739 NS_HTML5_CONTINUE(stateloop
);
3742 if (P::reportErrors
) {
3743 errNoSpaceBetweenDoctypePublicKeywordAndQuote();
3745 clearStrBufBeforeUse();
3746 state
= P::transition(
3748 nsHtml5Tokenizer::DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED
,
3750 NS_HTML5_CONTINUE(stateloop
);
3753 if (P::reportErrors
) {
3754 errExpectedPublicId();
3757 emitDoctypeToken(pos
);
3758 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3760 if (shouldSuspend
) {
3761 NS_HTML5_BREAK(stateloop
);
3763 NS_HTML5_CONTINUE(stateloop
);
3767 state
= P::transition(mViewSource
.get(),
3768 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
3770 NS_HTML5_CONTINUE(stateloop
);
3774 afterdoctypepublickeywordloop_end
:;
3777 case BEFORE_DOCTYPE_PUBLIC_IDENTIFIER
: {
3779 if (++pos
== endPos
) {
3780 NS_HTML5_BREAK(stateloop
);
3782 c
= P::checkChar(this, buf
, pos
);
3785 P::silentCarriageReturn(this);
3786 NS_HTML5_BREAK(stateloop
);
3789 P::silentLineFeed(this);
3798 clearStrBufBeforeUse();
3799 state
= P::transition(
3801 nsHtml5Tokenizer::DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED
,
3803 NS_HTML5_BREAK(beforedoctypepublicidentifierloop
);
3806 clearStrBufBeforeUse();
3807 state
= P::transition(
3809 nsHtml5Tokenizer::DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED
,
3811 NS_HTML5_CONTINUE(stateloop
);
3814 if (P::reportErrors
) {
3815 errExpectedPublicId();
3818 emitDoctypeToken(pos
);
3819 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3821 if (shouldSuspend
) {
3822 NS_HTML5_BREAK(stateloop
);
3824 NS_HTML5_CONTINUE(stateloop
);
3828 state
= P::transition(mViewSource
.get(),
3829 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
3831 NS_HTML5_CONTINUE(stateloop
);
3835 beforedoctypepublicidentifierloop_end
:;
3838 case DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED
: {
3840 if (++pos
== endPos
) {
3841 NS_HTML5_BREAK(stateloop
);
3843 c
= P::checkChar(this, buf
, pos
);
3846 publicIdentifier
= strBufToString();
3847 state
= P::transition(
3849 nsHtml5Tokenizer::AFTER_DOCTYPE_PUBLIC_IDENTIFIER
, reconsume
,
3851 NS_HTML5_BREAK(doctypepublicidentifierdoublequotedloop
);
3854 if (P::reportErrors
) {
3858 publicIdentifier
= strBufToString();
3859 emitDoctypeToken(pos
);
3860 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3862 if (shouldSuspend
) {
3863 NS_HTML5_BREAK(stateloop
);
3865 NS_HTML5_CONTINUE(stateloop
);
3868 appendStrBufCarriageReturn
<P
>();
3869 NS_HTML5_BREAK(stateloop
);
3872 appendStrBufLineFeed
<P
>();
3885 doctypepublicidentifierdoublequotedloop_end
:;
3888 case AFTER_DOCTYPE_PUBLIC_IDENTIFIER
: {
3890 if (++pos
== endPos
) {
3891 NS_HTML5_BREAK(stateloop
);
3893 c
= P::checkChar(this, buf
, pos
);
3896 P::silentCarriageReturn(this);
3897 state
= P::transition(
3900 BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS
,
3902 NS_HTML5_BREAK(stateloop
);
3905 P::silentLineFeed(this);
3911 state
= P::transition(
3914 BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS
,
3916 NS_HTML5_BREAK(afterdoctypepublicidentifierloop
);
3919 emitDoctypeToken(pos
);
3920 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3922 if (shouldSuspend
) {
3923 NS_HTML5_BREAK(stateloop
);
3925 NS_HTML5_CONTINUE(stateloop
);
3928 if (P::reportErrors
) {
3929 errNoSpaceBetweenPublicAndSystemIds();
3931 clearStrBufBeforeUse();
3932 state
= P::transition(
3934 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
,
3936 NS_HTML5_CONTINUE(stateloop
);
3939 if (P::reportErrors
) {
3940 errNoSpaceBetweenPublicAndSystemIds();
3942 clearStrBufBeforeUse();
3943 state
= P::transition(
3945 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
,
3947 NS_HTML5_CONTINUE(stateloop
);
3951 state
= P::transition(mViewSource
.get(),
3952 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
3954 NS_HTML5_CONTINUE(stateloop
);
3958 afterdoctypepublicidentifierloop_end
:;
3961 case BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS
: {
3963 if (++pos
== endPos
) {
3964 NS_HTML5_BREAK(stateloop
);
3966 c
= P::checkChar(this, buf
, pos
);
3969 P::silentCarriageReturn(this);
3970 NS_HTML5_BREAK(stateloop
);
3973 P::silentLineFeed(this);
3982 emitDoctypeToken(pos
);
3983 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
3985 if (shouldSuspend
) {
3986 NS_HTML5_BREAK(stateloop
);
3988 NS_HTML5_CONTINUE(stateloop
);
3991 clearStrBufBeforeUse();
3992 state
= P::transition(
3994 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
,
3996 NS_HTML5_BREAK(betweendoctypepublicandsystemidentifiersloop
);
3999 clearStrBufBeforeUse();
4000 state
= P::transition(
4002 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
,
4004 NS_HTML5_CONTINUE(stateloop
);
4008 state
= P::transition(mViewSource
.get(),
4009 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
4011 NS_HTML5_CONTINUE(stateloop
);
4015 betweendoctypepublicandsystemidentifiersloop_end
:;
4018 case DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
: {
4020 if (++pos
== endPos
) {
4021 NS_HTML5_BREAK(stateloop
);
4023 c
= P::checkChar(this, buf
, pos
);
4026 systemIdentifier
= strBufToString();
4027 state
= P::transition(
4029 nsHtml5Tokenizer::AFTER_DOCTYPE_SYSTEM_IDENTIFIER
, reconsume
,
4031 NS_HTML5_BREAK(doctypesystemidentifierdoublequotedloop
);
4034 if (P::reportErrors
) {
4038 systemIdentifier
= strBufToString();
4039 emitDoctypeToken(pos
);
4040 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4042 if (shouldSuspend
) {
4043 NS_HTML5_BREAK(stateloop
);
4045 NS_HTML5_CONTINUE(stateloop
);
4048 appendStrBufCarriageReturn
<P
>();
4049 NS_HTML5_BREAK(stateloop
);
4052 appendStrBufLineFeed
<P
>();
4065 doctypesystemidentifierdoublequotedloop_end
:;
4068 case AFTER_DOCTYPE_SYSTEM_IDENTIFIER
: {
4070 if (++pos
== endPos
) {
4071 NS_HTML5_BREAK(stateloop
);
4073 c
= P::checkChar(this, buf
, pos
);
4076 P::silentCarriageReturn(this);
4077 NS_HTML5_BREAK(stateloop
);
4080 P::silentLineFeed(this);
4089 emitDoctypeToken(pos
);
4090 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4092 if (shouldSuspend
) {
4093 NS_HTML5_BREAK(stateloop
);
4095 NS_HTML5_CONTINUE(stateloop
);
4098 bogusDoctypeWithoutQuirks();
4099 state
= P::transition(mViewSource
.get(),
4100 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
4102 NS_HTML5_BREAK(afterdoctypesystemidentifierloop
);
4106 afterdoctypesystemidentifierloop_end
:;
4109 case BOGUS_DOCTYPE
: {
4114 if (++pos
== endPos
) {
4115 NS_HTML5_BREAK(stateloop
);
4117 c
= P::checkChar(this, buf
, pos
);
4121 emitDoctypeToken(pos
);
4122 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4124 if (shouldSuspend
) {
4125 NS_HTML5_BREAK(stateloop
);
4127 NS_HTML5_CONTINUE(stateloop
);
4130 P::silentCarriageReturn(this);
4131 NS_HTML5_BREAK(stateloop
);
4134 P::silentLineFeed(this);
4143 case DOCTYPE_YSTEM
: {
4145 if (++pos
== endPos
) {
4146 NS_HTML5_BREAK(stateloop
);
4148 c
= P::checkChar(this, buf
, pos
);
4150 char16_t folded
= c
;
4151 if (c
>= 'A' && c
<= 'Z') {
4154 if (folded
!= nsHtml5Tokenizer::YSTEM
[index
]) {
4157 state
= P::transition(mViewSource
.get(),
4158 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
4160 NS_HTML5_CONTINUE(stateloop
);
4163 NS_HTML5_CONTINUE(stateloop
);
4166 state
= P::transition(
4168 nsHtml5Tokenizer::AFTER_DOCTYPE_SYSTEM_KEYWORD
, reconsume
, pos
);
4169 NS_HTML5_BREAK(doctypeystemloop
);
4172 doctypeystemloop_end
:;
4175 case AFTER_DOCTYPE_SYSTEM_KEYWORD
: {
4180 if (++pos
== endPos
) {
4181 NS_HTML5_BREAK(stateloop
);
4183 c
= P::checkChar(this, buf
, pos
);
4187 P::silentCarriageReturn(this);
4188 state
= P::transition(
4190 nsHtml5Tokenizer::BEFORE_DOCTYPE_SYSTEM_IDENTIFIER
, reconsume
,
4192 NS_HTML5_BREAK(stateloop
);
4195 P::silentLineFeed(this);
4201 state
= P::transition(
4203 nsHtml5Tokenizer::BEFORE_DOCTYPE_SYSTEM_IDENTIFIER
, reconsume
,
4205 NS_HTML5_BREAK(afterdoctypesystemkeywordloop
);
4208 if (P::reportErrors
) {
4209 errNoSpaceBetweenDoctypeSystemKeywordAndQuote();
4211 clearStrBufBeforeUse();
4212 state
= P::transition(
4214 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
,
4216 NS_HTML5_CONTINUE(stateloop
);
4219 if (P::reportErrors
) {
4220 errNoSpaceBetweenDoctypeSystemKeywordAndQuote();
4222 clearStrBufBeforeUse();
4223 state
= P::transition(
4225 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
,
4227 NS_HTML5_CONTINUE(stateloop
);
4230 if (P::reportErrors
) {
4231 errExpectedPublicId();
4234 emitDoctypeToken(pos
);
4235 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4237 if (shouldSuspend
) {
4238 NS_HTML5_BREAK(stateloop
);
4240 NS_HTML5_CONTINUE(stateloop
);
4244 state
= P::transition(mViewSource
.get(),
4245 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
4247 NS_HTML5_CONTINUE(stateloop
);
4251 afterdoctypesystemkeywordloop_end
:;
4254 case BEFORE_DOCTYPE_SYSTEM_IDENTIFIER
: {
4256 if (++pos
== endPos
) {
4257 NS_HTML5_BREAK(stateloop
);
4259 c
= P::checkChar(this, buf
, pos
);
4262 P::silentCarriageReturn(this);
4263 NS_HTML5_BREAK(stateloop
);
4266 P::silentLineFeed(this);
4275 clearStrBufBeforeUse();
4276 state
= P::transition(
4278 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
,
4280 NS_HTML5_CONTINUE(stateloop
);
4283 clearStrBufBeforeUse();
4284 state
= P::transition(
4286 nsHtml5Tokenizer::DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
,
4288 NS_HTML5_BREAK(beforedoctypesystemidentifierloop
);
4291 if (P::reportErrors
) {
4292 errExpectedSystemId();
4295 emitDoctypeToken(pos
);
4296 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4298 if (shouldSuspend
) {
4299 NS_HTML5_BREAK(stateloop
);
4301 NS_HTML5_CONTINUE(stateloop
);
4305 state
= P::transition(mViewSource
.get(),
4306 nsHtml5Tokenizer::BOGUS_DOCTYPE
, reconsume
,
4308 NS_HTML5_CONTINUE(stateloop
);
4312 beforedoctypesystemidentifierloop_end
:;
4315 case DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
: {
4317 if (++pos
== endPos
) {
4318 NS_HTML5_BREAK(stateloop
);
4320 c
= P::checkChar(this, buf
, pos
);
4323 systemIdentifier
= strBufToString();
4324 state
= P::transition(
4326 nsHtml5Tokenizer::AFTER_DOCTYPE_SYSTEM_IDENTIFIER
, reconsume
,
4328 NS_HTML5_CONTINUE(stateloop
);
4331 if (P::reportErrors
) {
4335 systemIdentifier
= strBufToString();
4336 emitDoctypeToken(pos
);
4337 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4339 if (shouldSuspend
) {
4340 NS_HTML5_BREAK(stateloop
);
4342 NS_HTML5_CONTINUE(stateloop
);
4345 appendStrBufCarriageReturn
<P
>();
4346 NS_HTML5_BREAK(stateloop
);
4349 appendStrBufLineFeed
<P
>();
4363 case DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED
: {
4365 if (++pos
== endPos
) {
4366 NS_HTML5_BREAK(stateloop
);
4368 c
= P::checkChar(this, buf
, pos
);
4371 publicIdentifier
= strBufToString();
4372 state
= P::transition(
4374 nsHtml5Tokenizer::AFTER_DOCTYPE_PUBLIC_IDENTIFIER
, reconsume
,
4376 NS_HTML5_CONTINUE(stateloop
);
4379 if (P::reportErrors
) {
4383 publicIdentifier
= strBufToString();
4384 emitDoctypeToken(pos
);
4385 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4387 if (shouldSuspend
) {
4388 NS_HTML5_BREAK(stateloop
);
4390 NS_HTML5_CONTINUE(stateloop
);
4393 appendStrBufCarriageReturn
<P
>();
4394 NS_HTML5_BREAK(stateloop
);
4397 appendStrBufLineFeed
<P
>();
4411 case PROCESSING_INSTRUCTION
: {
4413 if (++pos
== endPos
) {
4414 NS_HTML5_BREAK(stateloop
);
4416 c
= P::checkChar(this, buf
, pos
);
4419 state
= P::transition(
4421 nsHtml5Tokenizer::PROCESSING_INSTRUCTION_QUESTION_MARK
,
4423 NS_HTML5_BREAK(processinginstructionloop
);
4430 processinginstructionloop_end
:;
4433 case PROCESSING_INSTRUCTION_QUESTION_MARK
: {
4434 if (++pos
== endPos
) {
4435 NS_HTML5_BREAK(stateloop
);
4437 c
= P::checkChar(this, buf
, pos
);
4440 state
= P::transition(mViewSource
.get(), nsHtml5Tokenizer::DATA
,
4442 suspendIfRequestedAfterCurrentNonTextToken();
4443 if (shouldSuspend
) {
4444 NS_HTML5_BREAK(stateloop
);
4446 NS_HTML5_CONTINUE(stateloop
);
4449 state
= P::transition(mViewSource
.get(),
4450 nsHtml5Tokenizer::PROCESSING_INSTRUCTION
,
4452 NS_HTML5_CONTINUE(stateloop
);
4459 flushChars(buf
, pos
);
4461 returnStateSave
= returnState
;
4465 void nsHtml5Tokenizer::initDoctypeFields() {
4466 clearStrBufAfterUse();
4467 doctypeName
= nullptr;
4468 if (systemIdentifier
) {
4469 systemIdentifier
.Release();
4470 systemIdentifier
= nullptr;
4472 if (publicIdentifier
) {
4473 publicIdentifier
.Release();
4474 publicIdentifier
= nullptr;
4476 forceQuirks
= false;
4480 void nsHtml5Tokenizer::adjustDoubleHyphenAndAppendToStrBufCarriageReturn() {
4481 P::silentCarriageReturn(this);
4482 adjustDoubleHyphenAndAppendToStrBufAndErr('\n', false);
4486 void nsHtml5Tokenizer::adjustDoubleHyphenAndAppendToStrBufLineFeed() {
4487 P::silentLineFeed(this);
4488 adjustDoubleHyphenAndAppendToStrBufAndErr('\n', false);
4492 void nsHtml5Tokenizer::appendStrBufLineFeed() {
4493 P::silentLineFeed(this);
4498 void nsHtml5Tokenizer::appendStrBufCarriageReturn() {
4499 P::silentCarriageReturn(this);
4504 void nsHtml5Tokenizer::emitCarriageReturn(char16_t
* buf
, int32_t pos
) {
4505 P::silentCarriageReturn(this);
4506 flushChars(buf
, pos
);
4507 tokenHandler
->characters(nsHtml5Tokenizer::LF
, 0, 1);
4511 void nsHtml5Tokenizer::emitReplacementCharacter(char16_t
* buf
, int32_t pos
) {
4512 flushChars(buf
, pos
);
4513 tokenHandler
->zeroOriginatingReplacementCharacter();
4517 void nsHtml5Tokenizer::maybeEmitReplacementCharacter(char16_t
* buf
,
4519 flushChars(buf
, pos
);
4520 tokenHandler
->zeroOrReplacementCharacter();
4524 void nsHtml5Tokenizer::emitPlaintextReplacementCharacter(char16_t
* buf
,
4526 flushChars(buf
, pos
);
4527 tokenHandler
->characters(REPLACEMENT_CHARACTER
, 0, 1);
4531 void nsHtml5Tokenizer::setAdditionalAndRememberAmpersandLocation(char16_t add
) {
4535 void nsHtml5Tokenizer::bogusDoctype() {
4540 void nsHtml5Tokenizer::bogusDoctypeWithoutQuirks() {
4542 forceQuirks
= false;
4545 void nsHtml5Tokenizer::handleNcrValue(int32_t returnState
) {
4546 if (value
<= 0xFFFF) {
4547 if (value
>= 0x80 && value
<= 0x9f) {
4549 char16_t
* val
= nsHtml5NamedCharacters::WINDOWS_1252
[value
- 0x80];
4550 emitOrAppendOne(val
, returnState
);
4551 } else if (value
== 0x0) {
4553 emitOrAppendOne(nsHtml5Tokenizer::REPLACEMENT_CHARACTER
, returnState
);
4554 } else if ((value
& 0xF800) == 0xD800) {
4556 emitOrAppendOne(nsHtml5Tokenizer::REPLACEMENT_CHARACTER
, returnState
);
4558 char16_t ch
= (char16_t
)value
;
4560 emitOrAppendOne(bmpChar
, returnState
);
4562 } else if (value
<= 0x10FFFF) {
4563 astralChar
[0] = (char16_t
)(nsHtml5Tokenizer::LEAD_OFFSET
+ (value
>> 10));
4564 astralChar
[1] = (char16_t
)(0xDC00 + (value
& 0x3FF));
4565 emitOrAppendTwo(astralChar
, returnState
);
4568 emitOrAppendOne(nsHtml5Tokenizer::REPLACEMENT_CHARACTER
, returnState
);
4572 void nsHtml5Tokenizer::eof() {
4573 int32_t state
= stateSave
;
4574 int32_t returnState
= returnStateSave
;
4578 case SCRIPT_DATA_LESS_THAN_SIGN
:
4579 case SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN
: {
4580 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
4581 NS_HTML5_BREAK(eofloop
);
4585 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
4586 NS_HTML5_BREAK(eofloop
);
4588 case RAWTEXT_RCDATA_LESS_THAN_SIGN
: {
4589 tokenHandler
->characters(nsHtml5Tokenizer::LT_GT
, 0, 1);
4590 NS_HTML5_BREAK(eofloop
);
4592 case NON_DATA_END_TAG_NAME
: {
4593 tokenHandler
->characters(nsHtml5Tokenizer::LT_SOLIDUS
, 0, 2);
4595 NS_HTML5_BREAK(eofloop
);
4597 case CLOSE_TAG_OPEN
: {
4599 tokenHandler
->characters(nsHtml5Tokenizer::LT_SOLIDUS
, 0, 2);
4600 NS_HTML5_BREAK(eofloop
);
4604 NS_HTML5_BREAK(eofloop
);
4606 case BEFORE_ATTRIBUTE_NAME
:
4607 case AFTER_ATTRIBUTE_VALUE_QUOTED
:
4608 case SELF_CLOSING_START_TAG
: {
4610 NS_HTML5_BREAK(eofloop
);
4612 case ATTRIBUTE_NAME
: {
4613 errEofInAttributeName();
4614 NS_HTML5_BREAK(eofloop
);
4616 case AFTER_ATTRIBUTE_NAME
:
4617 case BEFORE_ATTRIBUTE_VALUE
: {
4619 NS_HTML5_BREAK(eofloop
);
4621 case ATTRIBUTE_VALUE_DOUBLE_QUOTED
:
4622 case ATTRIBUTE_VALUE_SINGLE_QUOTED
:
4623 case ATTRIBUTE_VALUE_UNQUOTED
: {
4624 errEofInAttributeValue();
4625 NS_HTML5_BREAK(eofloop
);
4627 case BOGUS_COMMENT
: {
4629 NS_HTML5_BREAK(eofloop
);
4631 case BOGUS_COMMENT_HYPHEN
: {
4633 NS_HTML5_BREAK(eofloop
);
4635 case MARKUP_DECLARATION_OPEN
: {
4638 NS_HTML5_BREAK(eofloop
);
4640 case MARKUP_DECLARATION_HYPHEN
: {
4643 NS_HTML5_BREAK(eofloop
);
4645 case MARKUP_DECLARATION_OCTYPE
: {
4651 doctypeName
= nullptr;
4652 if (systemIdentifier
) {
4653 systemIdentifier
.Release();
4654 systemIdentifier
= nullptr;
4656 if (publicIdentifier
) {
4657 publicIdentifier
.Release();
4658 publicIdentifier
= nullptr;
4661 emitDoctypeToken(0);
4662 NS_HTML5_BREAK(eofloop
);
4664 NS_HTML5_BREAK(eofloop
);
4668 case COMMENT_LESSTHAN
:
4669 case COMMENT_LESSTHAN_BANG
: {
4672 NS_HTML5_BREAK(eofloop
);
4675 case COMMENT_LESSTHAN_BANG_DASH_DASH
: {
4678 NS_HTML5_BREAK(eofloop
);
4680 case COMMENT_END_DASH
:
4681 case COMMENT_START_DASH
:
4682 case COMMENT_LESSTHAN_BANG_DASH
: {
4685 NS_HTML5_BREAK(eofloop
);
4687 case COMMENT_END_BANG
: {
4690 NS_HTML5_BREAK(eofloop
);
4693 case BEFORE_DOCTYPE_NAME
: {
4696 emitDoctypeToken(0);
4697 NS_HTML5_BREAK(eofloop
);
4699 case DOCTYPE_NAME
: {
4701 strBufToDoctypeName();
4703 emitDoctypeToken(0);
4704 NS_HTML5_BREAK(eofloop
);
4708 case AFTER_DOCTYPE_NAME
:
4709 case AFTER_DOCTYPE_PUBLIC_KEYWORD
:
4710 case AFTER_DOCTYPE_SYSTEM_KEYWORD
:
4711 case BEFORE_DOCTYPE_PUBLIC_IDENTIFIER
: {
4714 emitDoctypeToken(0);
4715 NS_HTML5_BREAK(eofloop
);
4717 case DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED
:
4718 case DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED
: {
4721 publicIdentifier
= strBufToString();
4722 emitDoctypeToken(0);
4723 NS_HTML5_BREAK(eofloop
);
4725 case AFTER_DOCTYPE_PUBLIC_IDENTIFIER
:
4726 case BEFORE_DOCTYPE_SYSTEM_IDENTIFIER
:
4727 case BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS
: {
4730 emitDoctypeToken(0);
4731 NS_HTML5_BREAK(eofloop
);
4733 case DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
:
4734 case DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
: {
4737 systemIdentifier
= strBufToString();
4738 emitDoctypeToken(0);
4739 NS_HTML5_BREAK(eofloop
);
4741 case AFTER_DOCTYPE_SYSTEM_IDENTIFIER
: {
4744 emitDoctypeToken(0);
4745 NS_HTML5_BREAK(eofloop
);
4747 case BOGUS_DOCTYPE
: {
4748 emitDoctypeToken(0);
4749 NS_HTML5_BREAK(eofloop
);
4751 case CONSUME_CHARACTER_REFERENCE
: {
4752 emitOrAppendCharRefBuf(returnState
);
4753 state
= returnState
;
4756 case CHARACTER_REFERENCE_HILO_LOOKUP
: {
4757 emitOrAppendCharRefBuf(returnState
);
4758 state
= returnState
;
4761 case CHARACTER_REFERENCE_TAIL
: {
4767 NS_HTML5_BREAK(hiloop
);
4769 if (entCol
== nsHtml5NamedCharacters::NAMES
[hi
].length()) {
4770 NS_HTML5_BREAK(hiloop
);
4772 if (entCol
> nsHtml5NamedCharacters::NAMES
[hi
].length()) {
4773 NS_HTML5_BREAK(outer
);
4774 } else if (c
< nsHtml5NamedCharacters::NAMES
[hi
].charAt(entCol
)) {
4777 NS_HTML5_BREAK(hiloop
);
4783 NS_HTML5_BREAK(outer
);
4785 if (entCol
== nsHtml5NamedCharacters::NAMES
[lo
].length()) {
4787 charRefBufMark
= charRefBufLen
;
4789 } else if (entCol
> nsHtml5NamedCharacters::NAMES
[lo
].length()) {
4790 NS_HTML5_BREAK(outer
);
4791 } else if (c
> nsHtml5NamedCharacters::NAMES
[lo
].charAt(entCol
)) {
4794 NS_HTML5_BREAK(loloop
);
4799 NS_HTML5_BREAK(outer
);
4804 if (candidate
== -1) {
4805 emitOrAppendCharRefBuf(returnState
);
4806 state
= returnState
;
4807 NS_HTML5_CONTINUE(eofloop
);
4809 const nsHtml5CharacterName
& candidateName
=
4810 nsHtml5NamedCharacters::NAMES
[candidate
];
4811 if (!candidateName
.length() ||
4812 candidateName
.charAt(candidateName
.length() - 1) != ';') {
4813 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
4815 if (charRefBufMark
== charRefBufLen
) {
4818 ch
= charRefBuf
[charRefBufMark
];
4820 if ((ch
>= '0' && ch
<= '9') || (ch
>= 'A' && ch
<= 'Z') ||
4821 (ch
>= 'a' && ch
<= 'z')) {
4822 appendCharRefBufToStrBuf();
4823 state
= returnState
;
4824 NS_HTML5_CONTINUE(eofloop
);
4827 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
4828 errUnescapedAmpersandInterpretedAsCharacterReference();
4830 errNotSemicolonTerminated();
4833 const char16_t
* val
= nsHtml5NamedCharacters::VALUES
[candidate
];
4835 emitOrAppendOne(val
, returnState
);
4837 emitOrAppendTwo(val
, returnState
);
4839 if (charRefBufMark
< charRefBufLen
) {
4840 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
4841 appendStrBuf(charRefBuf
, charRefBufMark
,
4842 charRefBufLen
- charRefBufMark
);
4844 tokenHandler
->characters(charRefBuf
, charRefBufMark
,
4845 charRefBufLen
- charRefBufMark
);
4849 state
= returnState
;
4850 NS_HTML5_CONTINUE(eofloop
);
4854 case DECIMAL_NRC_LOOP
:
4855 case HEX_NCR_LOOP
: {
4858 emitOrAppendCharRefBuf(returnState
);
4859 state
= returnState
;
4862 errCharRefLacksSemicolon();
4864 handleNcrValue(returnState
);
4865 state
= returnState
;
4869 tokenHandler
->characters(nsHtml5Tokenizer::RSQB_RSQB
, 0, 1);
4870 NS_HTML5_BREAK(eofloop
);
4872 case CDATA_RSQB_RSQB
: {
4873 tokenHandler
->characters(nsHtml5Tokenizer::RSQB_RSQB
, 0, 2);
4874 NS_HTML5_BREAK(eofloop
);
4878 NS_HTML5_BREAK(eofloop
);
4883 tokenHandler
->eof();
4887 void nsHtml5Tokenizer::emitDoctypeToken(int32_t pos
) {
4890 tokenHandler
->doctype(doctypeName
, publicIdentifier
, systemIdentifier
,
4892 doctypeName
= nullptr;
4893 publicIdentifier
.Release();
4894 publicIdentifier
= nullptr;
4895 systemIdentifier
.Release();
4896 systemIdentifier
= nullptr;
4897 suspendIfRequestedAfterCurrentNonTextToken();
4900 void nsHtml5Tokenizer::suspendIfRequestedAfterCurrentNonTextToken() {
4901 if (suspendAfterCurrentNonTextToken
) {
4902 suspendAfterCurrentNonTextToken
= false;
4903 shouldSuspend
= true;
4907 void nsHtml5Tokenizer::suspendAfterCurrentTokenIfNotInText() {
4908 switch (stateSave
) {
4913 case SCRIPT_DATA_ESCAPED
:
4915 case NON_DATA_END_TAG_NAME
:
4916 case SCRIPT_DATA_LESS_THAN_SIGN
:
4917 case SCRIPT_DATA_ESCAPE_START
:
4918 case SCRIPT_DATA_ESCAPE_START_DASH
:
4919 case SCRIPT_DATA_ESCAPED_DASH
:
4920 case SCRIPT_DATA_ESCAPED_DASH_DASH
:
4921 case RAWTEXT_RCDATA_LESS_THAN_SIGN
:
4922 case SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN
:
4923 case SCRIPT_DATA_DOUBLE_ESCAPE_START
:
4924 case SCRIPT_DATA_DOUBLE_ESCAPED
:
4925 case SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN
:
4926 case SCRIPT_DATA_DOUBLE_ESCAPED_DASH
:
4927 case SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH
:
4928 case SCRIPT_DATA_DOUBLE_ESCAPE_END
: {
4932 case BEFORE_ATTRIBUTE_NAME
:
4933 case ATTRIBUTE_NAME
:
4934 case AFTER_ATTRIBUTE_NAME
:
4935 case BEFORE_ATTRIBUTE_VALUE
:
4936 case AFTER_ATTRIBUTE_VALUE_QUOTED
:
4938 case MARKUP_DECLARATION_OPEN
:
4940 case BEFORE_DOCTYPE_NAME
:
4942 case AFTER_DOCTYPE_NAME
:
4943 case BEFORE_DOCTYPE_PUBLIC_IDENTIFIER
:
4944 case DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED
:
4945 case DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED
:
4946 case AFTER_DOCTYPE_PUBLIC_IDENTIFIER
:
4947 case BEFORE_DOCTYPE_SYSTEM_IDENTIFIER
:
4948 case DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED
:
4949 case DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED
:
4950 case AFTER_DOCTYPE_SYSTEM_IDENTIFIER
:
4953 case COMMENT_START_DASH
:
4955 case COMMENT_END_DASH
:
4957 case COMMENT_END_BANG
:
4959 case CLOSE_TAG_OPEN
:
4960 case MARKUP_DECLARATION_HYPHEN
:
4961 case MARKUP_DECLARATION_OCTYPE
:
4964 case AFTER_DOCTYPE_PUBLIC_KEYWORD
:
4965 case BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS
:
4966 case AFTER_DOCTYPE_SYSTEM_KEYWORD
:
4967 case SELF_CLOSING_START_TAG
:
4968 case ATTRIBUTE_VALUE_DOUBLE_QUOTED
:
4969 case ATTRIBUTE_VALUE_SINGLE_QUOTED
:
4970 case ATTRIBUTE_VALUE_UNQUOTED
:
4971 case BOGUS_COMMENT_HYPHEN
:
4972 case COMMENT_LESSTHAN
:
4973 case COMMENT_LESSTHAN_BANG
:
4974 case COMMENT_LESSTHAN_BANG_DASH
:
4975 case COMMENT_LESSTHAN_BANG_DASH_DASH
:
4979 case CDATA_RSQB_RSQB
:
4980 case PROCESSING_INSTRUCTION
:
4981 case PROCESSING_INSTRUCTION_QUESTION_MARK
: {
4984 case CONSUME_CHARACTER_REFERENCE
:
4986 case CHARACTER_REFERENCE_TAIL
:
4988 case DECIMAL_NRC_LOOP
:
4989 case HANDLE_NCR_VALUE
:
4990 case HANDLE_NCR_VALUE_RECONSUME
:
4991 case CHARACTER_REFERENCE_HILO_LOOKUP
: {
4992 if (returnStateSave
== DATA
|| returnStateSave
== RCDATA
) {
4998 MOZ_ASSERT(false, "Incomplete switch");
5002 suspendAfterCurrentNonTextToken
= true;
5005 bool nsHtml5Tokenizer::suspensionAfterCurrentNonTextTokenPending() {
5006 return suspendAfterCurrentNonTextToken
;
5009 bool nsHtml5Tokenizer::internalEncodingDeclaration(
5010 nsHtml5String internalCharset
) {
5011 if (encodingDeclarationHandler
) {
5012 return encodingDeclarationHandler
->internalEncodingDeclaration(
5018 void nsHtml5Tokenizer::emitOrAppendTwo(const char16_t
* val
,
5019 int32_t returnState
) {
5020 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
5021 appendStrBuf(val
[0]);
5022 appendStrBuf(val
[1]);
5024 tokenHandler
->characters(val
, 0, 2);
5028 void nsHtml5Tokenizer::emitOrAppendOne(const char16_t
* val
,
5029 int32_t returnState
) {
5030 if ((returnState
& DATA_AND_RCDATA_MASK
)) {
5031 appendStrBuf(val
[0]);
5033 tokenHandler
->characters(val
, 0, 1);
5037 void nsHtml5Tokenizer::end() {
5041 doctypeName
= nullptr;
5042 if (systemIdentifier
) {
5043 systemIdentifier
.Release();
5044 systemIdentifier
= nullptr;
5046 if (publicIdentifier
) {
5047 publicIdentifier
.Release();
5048 publicIdentifier
= nullptr;
5051 nonInternedTagName
->setNameForNonInterned(nullptr, false);
5052 attributeName
= nullptr;
5053 nonInternedAttributeName
->setNameForNonInterned(nullptr);
5054 tokenHandler
->endTokenization();
5056 attributes
->clear(0);
5060 void nsHtml5Tokenizer::requestSuspension() { shouldSuspend
= true; }
5062 bool nsHtml5Tokenizer::isInDataState() { return (stateSave
== DATA
); }
5064 void nsHtml5Tokenizer::resetToDataState() {
5065 clearStrBufAfterUse();
5067 stateSave
= nsHtml5Tokenizer::DATA
;
5070 forceQuirks
= false;
5080 suspendAfterCurrentNonTextToken
= false;
5082 shouldSuspend
= false;
5083 initDoctypeFields();
5084 containsHyphen
= false;
5086 attributeName
= nullptr;
5087 if (newAttributesEachTime
) {
5090 attributes
= nullptr;
5095 void nsHtml5Tokenizer::loadState(nsHtml5Tokenizer
* other
) {
5096 strBufLen
= other
->strBufLen
;
5097 if (strBufLen
> strBuf
.length
) {
5098 strBuf
= jArray
<char16_t
, int32_t>::newJArray(strBufLen
);
5100 nsHtml5ArrayCopy::arraycopy(other
->strBuf
, strBuf
, strBufLen
);
5101 charRefBufLen
= other
->charRefBufLen
;
5102 nsHtml5ArrayCopy::arraycopy(other
->charRefBuf
, charRefBuf
, charRefBufLen
);
5103 stateSave
= other
->stateSave
;
5104 returnStateSave
= other
->returnStateSave
;
5105 endTagExpectation
= other
->endTagExpectation
;
5106 endTagExpectationAsArray
= other
->endTagExpectationAsArray
;
5107 lastCR
= other
->lastCR
;
5108 index
= other
->index
;
5109 forceQuirks
= other
->forceQuirks
;
5110 additional
= other
->additional
;
5111 entCol
= other
->entCol
;
5112 firstCharKey
= other
->firstCharKey
;
5115 candidate
= other
->candidate
;
5116 charRefBufMark
= other
->charRefBufMark
;
5117 value
= other
->value
;
5118 seenDigits
= other
->seenDigits
;
5119 endTag
= other
->endTag
;
5120 shouldSuspend
= false;
5121 suspendAfterCurrentNonTextToken
= false;
5122 doctypeName
= other
->doctypeName
;
5123 systemIdentifier
.Release();
5124 if (!other
->systemIdentifier
) {
5125 systemIdentifier
= nullptr;
5128 nsHtml5Portability::newStringFromString(other
->systemIdentifier
);
5130 publicIdentifier
.Release();
5131 if (!other
->publicIdentifier
) {
5132 publicIdentifier
= nullptr;
5135 nsHtml5Portability::newStringFromString(other
->publicIdentifier
);
5137 containsHyphen
= other
->containsHyphen
;
5138 if (!other
->tagName
) {
5140 } else if (other
->tagName
->isInterned()) {
5141 tagName
= other
->tagName
;
5143 nonInternedTagName
->setNameForNonInterned(other
->tagName
->getName(),
5144 other
->tagName
->isCustom());
5145 tagName
= nonInternedTagName
;
5147 if (!other
->attributeName
) {
5148 attributeName
= nullptr;
5149 } else if (other
->attributeName
->isInterned()) {
5150 attributeName
= other
->attributeName
;
5152 nonInternedAttributeName
->setNameForNonInterned(
5153 other
->attributeName
->getLocal(nsHtml5AttributeName::HTML
));
5154 attributeName
= nonInternedAttributeName
;
5157 if (!other
->attributes
) {
5158 attributes
= nullptr;
5160 attributes
= other
->attributes
->cloneAttributes();
5164 void nsHtml5Tokenizer::initializeWithoutStarting() {
5174 void nsHtml5Tokenizer::setEncodingDeclarationHandler(
5175 nsHtml5StreamParser
* encodingDeclarationHandler
) {
5176 this->encodingDeclarationHandler
= encodingDeclarationHandler
;
5179 nsHtml5Tokenizer::~nsHtml5Tokenizer() {
5180 MOZ_COUNT_DTOR(nsHtml5Tokenizer
);
5181 delete nonInternedTagName
;
5182 nonInternedTagName
= nullptr;
5183 delete nonInternedAttributeName
;
5184 nonInternedAttributeName
= nullptr;
5186 attributes
= nullptr;
5189 void nsHtml5Tokenizer::initializeStatics() {}
5191 void nsHtml5Tokenizer::releaseStatics() {}
5193 #include "nsHtml5TokenizerCppSupplement.h"