1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
|
/*
* Copyright (c) 2005-2007 Henri Sivonen
* Copyright (c) 2007-2017 Mozilla Foundation
* Portions of comments Copyright 2004-2010 Apple Computer, Inc., Mozilla
* Foundation, and Opera Software ASA.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit Tokenizer.java instead and regenerate.
*/
#define nsHtml5Tokenizer_cpp__
#include "nsHtml5AttributeName.h"
#include "nsHtml5ElementName.h"
#include "nsHtml5TreeBuilder.h"
#include "nsHtml5StackNode.h"
#include "nsHtml5UTF16Buffer.h"
#include "nsHtml5StateSnapshot.h"
#include "nsHtml5Portability.h"
#include "nsHtml5Tokenizer.h"
char16_t nsHtml5Tokenizer::LT_GT[] = {'<', '>'};
char16_t nsHtml5Tokenizer::LT_SOLIDUS[] = {'<', '/'};
char16_t nsHtml5Tokenizer::RSQB_RSQB[] = {']', ']'};
char16_t nsHtml5Tokenizer::REPLACEMENT_CHARACTER[] = {0xfffd};
char16_t nsHtml5Tokenizer::LF[] = {'\n'};
char16_t nsHtml5Tokenizer::CDATA_LSQB[] = {'C', 'D', 'A', 'T', 'A', '['};
char16_t nsHtml5Tokenizer::OCTYPE[] = {'o', 'c', 't', 'y', 'p', 'e'};
char16_t nsHtml5Tokenizer::UBLIC[] = {'u', 'b', 'l', 'i', 'c'};
char16_t nsHtml5Tokenizer::YSTEM[] = {'y', 's', 't', 'e', 'm'};
static char16_t const TITLE_ARR_DATA[] = {'t', 'i', 't', 'l', 'e'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::TITLE_ARR = {
TITLE_ARR_DATA, std::size(TITLE_ARR_DATA)};
static char16_t const SCRIPT_ARR_DATA[] = {'s', 'c', 'r', 'i', 'p', 't'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::SCRIPT_ARR = {
SCRIPT_ARR_DATA, std::size(SCRIPT_ARR_DATA)};
static char16_t const STYLE_ARR_DATA[] = {'s', 't', 'y', 'l', 'e'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::STYLE_ARR = {
STYLE_ARR_DATA, std::size(STYLE_ARR_DATA)};
static char16_t const PLAINTEXT_ARR_DATA[] = {'p', 'l', 'a', 'i', 'n',
't', 'e', 'x', 't'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::PLAINTEXT_ARR = {
PLAINTEXT_ARR_DATA, std::size(PLAINTEXT_ARR_DATA)};
static char16_t const XMP_ARR_DATA[] = {'x', 'm', 'p'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::XMP_ARR = {
XMP_ARR_DATA, std::size(XMP_ARR_DATA)};
static char16_t const TEXTAREA_ARR_DATA[] = {'t', 'e', 'x', 't',
'a', 'r', 'e', 'a'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::TEXTAREA_ARR = {
TEXTAREA_ARR_DATA, std::size(TEXTAREA_ARR_DATA)};
static char16_t const IFRAME_ARR_DATA[] = {'i', 'f', 'r', 'a', 'm', 'e'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::IFRAME_ARR = {
IFRAME_ARR_DATA, std::size(IFRAME_ARR_DATA)};
static char16_t const NOEMBED_ARR_DATA[] = {'n', 'o', 'e', 'm', 'b', 'e', 'd'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::NOEMBED_ARR = {
NOEMBED_ARR_DATA, std::size(NOEMBED_ARR_DATA)};
static char16_t const NOSCRIPT_ARR_DATA[] = {'n', 'o', 's', 'c',
'r', 'i', 'p', 't'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::NOSCRIPT_ARR = {
NOSCRIPT_ARR_DATA, std::size(NOSCRIPT_ARR_DATA)};
static char16_t const NOFRAMES_ARR_DATA[] = {'n', 'o', 'f', 'r',
'a', 'm', 'e', 's'};
staticJArray<char16_t, int32_t> nsHtml5Tokenizer::NOFRAMES_ARR = {
NOFRAMES_ARR_DATA, std::size(NOFRAMES_ARR_DATA)};
nsHtml5Tokenizer::nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler,
bool viewingXmlSource)
: tokenHandler(tokenHandler),
encodingDeclarationHandler(nullptr),
lastCR(false),
stateSave(0),
returnStateSave(0),
index(0),
forceQuirks(false),
additional('\0'),
entCol(0),
firstCharKey(0),
lo(0),
hi(0),
candidate(0),
charRefBufMark(0),
value(0),
seenDigits(false),
suspendAfterCurrentNonTextToken(false),
cstart(0),
strBufLen(0),
charRefBuf(jArray<char16_t, int32_t>::newJArray(32)),
charRefBufLen(0),
bmpChar(jArray<char16_t, int32_t>::newJArray(1)),
astralChar(jArray<char16_t, int32_t>::newJArray(2)),
endTagExpectation(nullptr),
endTagExpectationAsArray(nullptr),
endTag(false),
containsHyphen(false),
tagName(nullptr),
nonInternedTagName(new nsHtml5ElementName()),
attributeName(nullptr),
nonInternedAttributeName(new nsHtml5AttributeName()),
doctypeName(nullptr),
publicIdentifier(nullptr),
systemIdentifier(nullptr),
attributes(tokenHandler->HasBuilder() ? new nsHtml5HtmlAttributes(0)
: nullptr),
newAttributesEachTime(!tokenHandler->HasBuilder()),
shouldSuspend(false),
keepBuffer(false),
confident(false),
line(0),
attributeLine(0),
interner(nullptr),
viewingXmlSource(viewingXmlSource) {
MOZ_COUNT_CTOR(nsHtml5Tokenizer);
}
void nsHtml5Tokenizer::setInterner(nsHtml5AtomTable* interner) {
this->interner = interner;
}
void nsHtml5Tokenizer::initLocation(nsHtml5String newPublicId,
nsHtml5String newSystemId) {
this->systemId = newSystemId;
this->publicId = newPublicId;
}
bool nsHtml5Tokenizer::isViewingXmlSource() { return viewingXmlSource; }
void nsHtml5Tokenizer::setKeepBuffer(bool keepBuffer) {
this->keepBuffer = keepBuffer;
}
bool nsHtml5Tokenizer::dropBufferIfLongerThan(int32_t length) {
if (strBuf.length > length) {
strBuf = nullptr;
return true;
}
return false;
}
void nsHtml5Tokenizer::setState(int32_t specialTokenizerState) {
this->stateSave = specialTokenizerState;
this->endTagExpectation = nullptr;
this->endTagExpectationAsArray = nullptr;
}
void nsHtml5Tokenizer::setStateAndEndTagExpectation(
int32_t specialTokenizerState, nsHtml5ElementName* endTagExpectation) {
this->stateSave = specialTokenizerState;
this->endTagExpectation = endTagExpectation;
endTagExpectationToArray();
}
void nsHtml5Tokenizer::endTagExpectationToArray() {
switch (endTagExpectation->getGroup()) {
case nsHtml5TreeBuilder::TITLE: {
endTagExpectationAsArray = TITLE_ARR;
return;
}
case nsHtml5TreeBuilder::SCRIPT: {
endTagExpectationAsArray = SCRIPT_ARR;
return;
}
case nsHtml5TreeBuilder::STYLE: {
endTagExpectationAsArray = STYLE_ARR;
return;
}
case nsHtml5TreeBuilder::PLAINTEXT: {
endTagExpectationAsArray = PLAINTEXT_ARR;
return;
}
case nsHtml5TreeBuilder::XMP: {
endTagExpectationAsArray = XMP_ARR;
return;
}
case nsHtml5TreeBuilder::TEXTAREA: {
endTagExpectationAsArray = TEXTAREA_ARR;
return;
}
case nsHtml5TreeBuilder::IFRAME: {
endTagExpectationAsArray = IFRAME_ARR;
return;
}
case nsHtml5TreeBuilder::NOEMBED: {
endTagExpectationAsArray = NOEMBED_ARR;
return;
}
case nsHtml5TreeBuilder::NOSCRIPT: {
endTagExpectationAsArray = NOSCRIPT_ARR;
return;
}
case nsHtml5TreeBuilder::NOFRAMES: {
endTagExpectationAsArray = NOFRAMES_ARR;
return;
}
default: {
MOZ_ASSERT(false, "Bad end tag expectation.");
return;
}
}
}
void nsHtml5Tokenizer::setLineNumber(int32_t line) {
this->attributeLine = line;
this->line = line;
}
void nsHtml5Tokenizer::appendCharRefBuf(char16_t c) {
MOZ_RELEASE_ASSERT(charRefBufLen < charRefBuf.length,
"Attempted to overrun charRefBuf!");
charRefBuf[charRefBufLen++] = c;
}
void nsHtml5Tokenizer::emitOrAppendCharRefBuf(int32_t returnState) {
if ((returnState & DATA_AND_RCDATA_MASK)) {
appendCharRefBufToStrBuf();
} else {
if (charRefBufLen > 0) {
tokenHandler->characters(charRefBuf, 0, charRefBufLen);
charRefBufLen = 0;
}
}
}
void nsHtml5Tokenizer::emitComment(int32_t provisionalHyphens, int32_t pos) {
RememberGt(pos);
tokenHandler->comment(strBuf, 0, strBufLen - provisionalHyphens);
clearStrBufAfterUse();
cstart = pos + 1;
suspendIfRequestedAfterCurrentNonTextToken();
}
void nsHtml5Tokenizer::flushChars(char16_t* buf, int32_t pos) {
if (pos > cstart) {
tokenHandler->characters(buf, cstart, pos - cstart);
}
cstart = INT32_MAX;
}
void nsHtml5Tokenizer::strBufToElementNameString() {
if (containsHyphen) {
nsAtom* annotationName = nsHtml5ElementName::ELT_ANNOTATION_XML->getName();
if (nsHtml5Portability::localEqualsBuffer(annotationName, strBuf,
strBufLen)) {
tagName = nsHtml5ElementName::ELT_ANNOTATION_XML;
} else {
nonInternedTagName->setNameForNonInterned(
nsHtml5Portability::newLocalNameFromBuffer(strBuf, strBufLen,
interner),
true);
tagName = nonInternedTagName;
}
} else {
tagName = nsHtml5ElementName::elementNameByBuffer(strBuf, strBufLen);
if (!tagName) {
nonInternedTagName->setNameForNonInterned(
nsHtml5Portability::newLocalNameFromBuffer(strBuf, strBufLen,
interner),
false);
tagName = nonInternedTagName;
}
}
containsHyphen = false;
clearStrBufAfterUse();
}
int32_t nsHtml5Tokenizer::emitCurrentTagToken(bool selfClosing, int32_t pos) {
RememberGt(pos);
cstart = pos + 1;
maybeErrSlashInEndTag(selfClosing);
stateSave = nsHtml5Tokenizer::DATA;
nsHtml5HtmlAttributes* attrs =
(!attributes ? nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES : attributes);
if (endTag) {
maybeErrAttributesOnEndTag(attrs);
if (!viewingXmlSource) {
tokenHandler->endTag(tagName);
}
if (newAttributesEachTime) {
delete attributes;
attributes = nullptr;
}
} else {
if (viewingXmlSource) {
MOZ_ASSERT(newAttributesEachTime);
delete attributes;
attributes = nullptr;
} else {
tokenHandler->startTag(tagName, attrs, selfClosing);
}
}
tagName = nullptr;
if (newAttributesEachTime) {
attributes = nullptr;
} else {
attributes->clear(0);
}
suspendIfRequestedAfterCurrentNonTextToken();
return stateSave;
}
void nsHtml5Tokenizer::attributeNameComplete() {
attributeName =
nsHtml5AttributeName::nameByBuffer(strBuf, strBufLen, interner);
if (!attributeName) {
nonInternedAttributeName->setNameForNonInterned(
nsHtml5Portability::newLocalNameFromBuffer(strBuf, strBufLen,
interner));
attributeName = nonInternedAttributeName;
}
clearStrBufAfterUse();
if (!attributes) {
attributes = new nsHtml5HtmlAttributes(0);
}
if (attributes->contains(attributeName)) {
errDuplicateAttribute();
attributeName = nullptr;
}
}
void nsHtml5Tokenizer::addAttributeWithoutValue() {
if (attributeName) {
attributes->addAttribute(
attributeName, nsHtml5Portability::newEmptyString(), attributeLine);
attributeName = nullptr;
} else {
clearStrBufAfterUse();
}
}
void nsHtml5Tokenizer::addAttributeWithValue() {
if (attributeName) {
nsHtml5String val = strBufToString();
if (mViewSource) {
mViewSource->MaybeLinkifyAttributeValue(attributeName, val);
}
attributes->addAttribute(attributeName, val, attributeLine);
attributeName = nullptr;
} else {
clearStrBufAfterUse();
}
}
void nsHtml5Tokenizer::start() {
initializeWithoutStarting();
tokenHandler->startTokenization(this);
if (mViewSource) {
line = 1;
col = -1;
nextCharOnNewLine = false;
} else if (tokenHandler->WantsLineAndColumn()) {
line = 0;
col = 1;
nextCharOnNewLine = true;
} else {
line = -1;
col = -1;
nextCharOnNewLine = false;
}
}
bool nsHtml5Tokenizer::tokenizeBuffer(nsHtml5UTF16Buffer* buffer) {
int32_t state = stateSave;
int32_t returnState = returnStateSave;
char16_t c = '\0';
shouldSuspend = false;
lastCR = false;
int32_t start = buffer->getStart();
int32_t end = buffer->getEnd();
int32_t pos = start - 1;
switch (state) {
case DATA:
case RCDATA:
case SCRIPT_DATA:
case PLAINTEXT:
case RAWTEXT:
case CDATA_SECTION:
case SCRIPT_DATA_ESCAPED:
case SCRIPT_DATA_ESCAPE_START:
case SCRIPT_DATA_ESCAPE_START_DASH:
case SCRIPT_DATA_ESCAPED_DASH:
case SCRIPT_DATA_ESCAPED_DASH_DASH:
case SCRIPT_DATA_DOUBLE_ESCAPE_START:
case SCRIPT_DATA_DOUBLE_ESCAPED:
case SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:
case SCRIPT_DATA_DOUBLE_ESCAPED_DASH:
case SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:
case SCRIPT_DATA_DOUBLE_ESCAPE_END: {
cstart = start;
break;
}
default: {
cstart = INT32_MAX;
break;
}
}
if (mViewSource) {
mViewSource->SetBuffer(buffer);
if (mozilla::htmlaccel::htmlaccelEnabled()) {
pos = StateLoopViewSourceSIMD(state, c, pos, buffer->getBuffer(), false,
returnState, buffer->getEnd());
} else {
pos = StateLoopViewSourceALU(state, c, pos, buffer->getBuffer(), false,
returnState, buffer->getEnd());
}
mViewSource->DropBuffer((pos == buffer->getEnd()) ? pos : pos + 1);
} else if (tokenHandler->WantsLineAndColumn()) {
if (mozilla::htmlaccel::htmlaccelEnabled()) {
pos = StateLoopLineColSIMD(state, c, pos, buffer->getBuffer(), false,
returnState, buffer->getEnd());
} else {
pos = StateLoopLineColALU(state, c, pos, buffer->getBuffer(), false,
returnState, buffer->getEnd());
}
} else if (mozilla::htmlaccel::htmlaccelEnabled()) {
pos = StateLoopFastestSIMD(state, c, pos, buffer->getBuffer(), false,
returnState, buffer->getEnd());
} else {
pos = StateLoopFastestALU(state, c, pos, buffer->getBuffer(), false,
returnState, buffer->getEnd());
}
if (pos == end) {
buffer->setStart(pos);
} else {
buffer->setStart(pos + 1);
}
return lastCR;
}
void nsHtml5Tokenizer::initDoctypeFields() {
clearStrBufAfterUse();
doctypeName = nullptr;
if (systemIdentifier) {
systemIdentifier.Release();
systemIdentifier = nullptr;
}
if (publicIdentifier) {
publicIdentifier.Release();
publicIdentifier = nullptr;
}
forceQuirks = false;
}
void nsHtml5Tokenizer::emitReplacementCharacter(char16_t* buf, int32_t pos) {
flushChars(buf, pos);
tokenHandler->zeroOriginatingReplacementCharacter();
cstart = pos + 1;
}
void nsHtml5Tokenizer::maybeEmitReplacementCharacter(char16_t* buf,
int32_t pos) {
flushChars(buf, pos);
tokenHandler->zeroOrReplacementCharacter();
cstart = pos + 1;
}
void nsHtml5Tokenizer::emitPlaintextReplacementCharacter(char16_t* buf,
int32_t pos) {
flushChars(buf, pos);
tokenHandler->characters(REPLACEMENT_CHARACTER, 0, 1);
cstart = pos + 1;
}
void nsHtml5Tokenizer::bogusDoctype() {
errBogusDoctype();
forceQuirks = true;
}
void nsHtml5Tokenizer::bogusDoctypeWithoutQuirks() {
errBogusDoctype();
forceQuirks = false;
}
void nsHtml5Tokenizer::handleNcrValue(int32_t returnState) {
if (value <= 0xFFFF) {
if (value >= 0x80 && value <= 0x9f) {
errNcrInC1Range();
char16_t* val = nsHtml5NamedCharacters::WINDOWS_1252[value - 0x80];
emitOrAppendOne(val, returnState);
} else if (value == 0x0) {
errNcrZero();
emitOrAppendOne(nsHtml5Tokenizer::REPLACEMENT_CHARACTER, returnState);
} else if ((value & 0xF800) == 0xD800) {
errNcrSurrogate();
emitOrAppendOne(nsHtml5Tokenizer::REPLACEMENT_CHARACTER, returnState);
} else {
char16_t ch = (char16_t)value;
bmpChar[0] = ch;
emitOrAppendOne(bmpChar, returnState);
}
} else if (value <= 0x10FFFF) {
astralChar[0] = (char16_t)(nsHtml5Tokenizer::LEAD_OFFSET + (value >> 10));
astralChar[1] = (char16_t)(0xDC00 + (value & 0x3FF));
emitOrAppendTwo(astralChar, returnState);
} else {
errNcrOutOfRange();
emitOrAppendOne(nsHtml5Tokenizer::REPLACEMENT_CHARACTER, returnState);
}
}
void nsHtml5Tokenizer::eof() {
int32_t state = stateSave;
int32_t returnState = returnStateSave;
eofloop:
for (;;) {
switch (state) {
case SCRIPT_DATA_LESS_THAN_SIGN:
case SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN: {
tokenHandler->characters(nsHtml5Tokenizer::LT_GT, 0, 1);
NS_HTML5_BREAK(eofloop);
}
case TAG_OPEN: {
errEofAfterLt();
tokenHandler->characters(nsHtml5Tokenizer::LT_GT, 0, 1);
NS_HTML5_BREAK(eofloop);
}
case RAWTEXT_RCDATA_LESS_THAN_SIGN: {
tokenHandler->characters(nsHtml5Tokenizer::LT_GT, 0, 1);
NS_HTML5_BREAK(eofloop);
}
case NON_DATA_END_TAG_NAME: {
tokenHandler->characters(nsHtml5Tokenizer::LT_SOLIDUS, 0, 2);
emitStrBuf();
NS_HTML5_BREAK(eofloop);
}
case CLOSE_TAG_OPEN: {
errEofAfterLt();
tokenHandler->characters(nsHtml5Tokenizer::LT_SOLIDUS, 0, 2);
NS_HTML5_BREAK(eofloop);
}
case TAG_NAME: {
errEofInTagName();
NS_HTML5_BREAK(eofloop);
}
case BEFORE_ATTRIBUTE_NAME:
case AFTER_ATTRIBUTE_VALUE_QUOTED:
case SELF_CLOSING_START_TAG: {
errEofWithoutGt();
NS_HTML5_BREAK(eofloop);
}
case ATTRIBUTE_NAME: {
errEofInAttributeName();
NS_HTML5_BREAK(eofloop);
}
case AFTER_ATTRIBUTE_NAME:
case BEFORE_ATTRIBUTE_VALUE: {
errEofWithoutGt();
NS_HTML5_BREAK(eofloop);
}
case ATTRIBUTE_VALUE_DOUBLE_QUOTED:
case ATTRIBUTE_VALUE_SINGLE_QUOTED:
case ATTRIBUTE_VALUE_UNQUOTED: {
errEofInAttributeValue();
NS_HTML5_BREAK(eofloop);
}
case BOGUS_COMMENT: {
emitComment(0, 0);
NS_HTML5_BREAK(eofloop);
}
case BOGUS_COMMENT_HYPHEN: {
emitComment(0, 0);
NS_HTML5_BREAK(eofloop);
}
case MARKUP_DECLARATION_OPEN: {
errBogusComment();
emitComment(0, 0);
NS_HTML5_BREAK(eofloop);
}
case MARKUP_DECLARATION_HYPHEN: {
errBogusComment();
emitComment(0, 0);
NS_HTML5_BREAK(eofloop);
}
case MARKUP_DECLARATION_OCTYPE: {
if (index < 6) {
errBogusComment();
emitComment(0, 0);
} else {
errEofInDoctype();
doctypeName = nullptr;
if (systemIdentifier) {
systemIdentifier.Release();
systemIdentifier = nullptr;
}
if (publicIdentifier) {
publicIdentifier.Release();
publicIdentifier = nullptr;
}
forceQuirks = true;
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
NS_HTML5_BREAK(eofloop);
}
case COMMENT_START:
case COMMENT:
case COMMENT_LESSTHAN:
case COMMENT_LESSTHAN_BANG: {
errEofInComment();
emitComment(0, 0);
NS_HTML5_BREAK(eofloop);
}
case COMMENT_END:
case COMMENT_LESSTHAN_BANG_DASH_DASH: {
errEofInComment();
emitComment(2, 0);
NS_HTML5_BREAK(eofloop);
}
case COMMENT_END_DASH:
case COMMENT_START_DASH:
case COMMENT_LESSTHAN_BANG_DASH: {
errEofInComment();
emitComment(1, 0);
NS_HTML5_BREAK(eofloop);
}
case COMMENT_END_BANG: {
errEofInComment();
emitComment(3, 0);
NS_HTML5_BREAK(eofloop);
}
case DOCTYPE:
case BEFORE_DOCTYPE_NAME: {
errEofInDoctype();
forceQuirks = true;
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case DOCTYPE_NAME: {
errEofInDoctype();
strBufToDoctypeName();
forceQuirks = true;
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case DOCTYPE_UBLIC:
case DOCTYPE_YSTEM:
case AFTER_DOCTYPE_NAME:
case AFTER_DOCTYPE_PUBLIC_KEYWORD:
case AFTER_DOCTYPE_SYSTEM_KEYWORD:
case BEFORE_DOCTYPE_PUBLIC_IDENTIFIER: {
errEofInDoctype();
forceQuirks = true;
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:
case DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED: {
errEofInPublicId();
forceQuirks = true;
publicIdentifier = strBufToString();
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case AFTER_DOCTYPE_PUBLIC_IDENTIFIER:
case BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:
case BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS: {
errEofInDoctype();
forceQuirks = true;
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:
case DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED: {
errEofInSystemId();
forceQuirks = true;
systemIdentifier = strBufToString();
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case AFTER_DOCTYPE_SYSTEM_IDENTIFIER: {
errEofInDoctype();
forceQuirks = true;
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case BOGUS_DOCTYPE: {
emitDoctypeToken(0);
NS_HTML5_BREAK(eofloop);
}
case CONSUME_CHARACTER_REFERENCE: {
emitOrAppendCharRefBuf(returnState);
state = returnState;
continue;
}
case CHARACTER_REFERENCE_HILO_LOOKUP: {
emitOrAppendCharRefBuf(returnState);
state = returnState;
continue;
}
case CHARACTER_REFERENCE_TAIL: {
for (;;) {
char16_t c = '\0';
entCol++;
for (;;) {
if (hi == -1) {
NS_HTML5_BREAK(hiloop);
}
if (entCol == nsHtml5NamedCharacters::NAMES[hi].length()) {
NS_HTML5_BREAK(hiloop);
}
if (entCol > nsHtml5NamedCharacters::NAMES[hi].length()) {
NS_HTML5_BREAK(outer);
} else if (c < nsHtml5NamedCharacters::NAMES[hi].charAt(entCol)) {
hi--;
} else {
NS_HTML5_BREAK(hiloop);
}
}
hiloop_end:;
for (;;) {
if (hi < lo) {
NS_HTML5_BREAK(outer);
}
if (entCol == nsHtml5NamedCharacters::NAMES[lo].length()) {
candidate = lo;
charRefBufMark = charRefBufLen;
lo++;
} else if (entCol > nsHtml5NamedCharacters::NAMES[lo].length()) {
NS_HTML5_BREAK(outer);
} else if (c > nsHtml5NamedCharacters::NAMES[lo].charAt(entCol)) {
lo++;
} else {
NS_HTML5_BREAK(loloop);
}
}
loloop_end:;
if (hi < lo) {
NS_HTML5_BREAK(outer);
}
continue;
}
outer_end:;
if (candidate == -1) {
emitOrAppendCharRefBuf(returnState);
state = returnState;
NS_HTML5_CONTINUE(eofloop);
} else {
const nsHtml5CharacterName& candidateName =
nsHtml5NamedCharacters::NAMES[candidate];
if (!candidateName.length() ||
candidateName.charAt(candidateName.length() - 1) != ';') {
if ((returnState & DATA_AND_RCDATA_MASK)) {
char16_t ch;
if (charRefBufMark == charRefBufLen) {
ch = '\0';
} else {
ch = charRefBuf[charRefBufMark];
}
if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') ||
(ch >= 'a' && ch <= 'z')) {
appendCharRefBufToStrBuf();
state = returnState;
NS_HTML5_CONTINUE(eofloop);
}
}
if ((returnState & DATA_AND_RCDATA_MASK)) {
errUnescapedAmpersandInterpretedAsCharacterReference();
} else {
errNotSemicolonTerminated();
}
}
const char16_t* val = nsHtml5NamedCharacters::VALUES[candidate];
if (!val[1]) {
emitOrAppendOne(val, returnState);
} else {
emitOrAppendTwo(val, returnState);
}
if (charRefBufMark < charRefBufLen) {
if ((returnState & DATA_AND_RCDATA_MASK)) {
appendStrBuf(charRefBuf, charRefBufMark,
charRefBufLen - charRefBufMark);
} else {
tokenHandler->characters(charRefBuf, charRefBufMark,
charRefBufLen - charRefBufMark);
}
}
charRefBufLen = 0;
state = returnState;
NS_HTML5_CONTINUE(eofloop);
}
}
case CONSUME_NCR:
case DECIMAL_NRC_LOOP:
case HEX_NCR_LOOP: {
if (!seenDigits) {
errNoDigitsInNCR();
emitOrAppendCharRefBuf(returnState);
state = returnState;
continue;
} else {
errCharRefLacksSemicolon();
}
handleNcrValue(returnState);
state = returnState;
continue;
}
case CDATA_RSQB: {
tokenHandler->characters(nsHtml5Tokenizer::RSQB_RSQB, 0, 1);
NS_HTML5_BREAK(eofloop);
}
case CDATA_RSQB_RSQB: {
tokenHandler->characters(nsHtml5Tokenizer::RSQB_RSQB, 0, 2);
NS_HTML5_BREAK(eofloop);
}
case DATA:
default: {
NS_HTML5_BREAK(eofloop);
}
}
}
eofloop_end:;
tokenHandler->eof();
return;
}
void nsHtml5Tokenizer::emitDoctypeToken(int32_t pos) {
RememberGt(pos);
cstart = pos + 1;
tokenHandler->doctype(doctypeName, publicIdentifier, systemIdentifier,
forceQuirks);
doctypeName = nullptr;
publicIdentifier.Release();
publicIdentifier = nullptr;
systemIdentifier.Release();
systemIdentifier = nullptr;
suspendIfRequestedAfterCurrentNonTextToken();
}
void nsHtml5Tokenizer::suspendAfterCurrentTokenIfNotInText() {
switch (stateSave) {
case DATA:
case RCDATA:
case SCRIPT_DATA:
case RAWTEXT:
case SCRIPT_DATA_ESCAPED:
case PLAINTEXT:
case NON_DATA_END_TAG_NAME:
case SCRIPT_DATA_LESS_THAN_SIGN:
case SCRIPT_DATA_ESCAPE_START:
case SCRIPT_DATA_ESCAPE_START_DASH:
case SCRIPT_DATA_ESCAPED_DASH:
case SCRIPT_DATA_ESCAPED_DASH_DASH:
case RAWTEXT_RCDATA_LESS_THAN_SIGN:
case SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:
case SCRIPT_DATA_DOUBLE_ESCAPE_START:
case SCRIPT_DATA_DOUBLE_ESCAPED:
case SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:
case SCRIPT_DATA_DOUBLE_ESCAPED_DASH:
case SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:
case SCRIPT_DATA_DOUBLE_ESCAPE_END: {
return;
}
case TAG_NAME:
case BEFORE_ATTRIBUTE_NAME:
case ATTRIBUTE_NAME:
case AFTER_ATTRIBUTE_NAME:
case BEFORE_ATTRIBUTE_VALUE:
case AFTER_ATTRIBUTE_VALUE_QUOTED:
case BOGUS_COMMENT:
case MARKUP_DECLARATION_OPEN:
case DOCTYPE:
case BEFORE_DOCTYPE_NAME:
case DOCTYPE_NAME:
case AFTER_DOCTYPE_NAME:
case BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:
case DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:
case DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:
case AFTER_DOCTYPE_PUBLIC_IDENTIFIER:
case BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:
case DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:
case DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:
case AFTER_DOCTYPE_SYSTEM_IDENTIFIER:
case BOGUS_DOCTYPE:
case COMMENT_START:
case COMMENT_START_DASH:
case COMMENT:
case COMMENT_END_DASH:
case COMMENT_END:
case COMMENT_END_BANG:
case TAG_OPEN:
case CLOSE_TAG_OPEN:
case MARKUP_DECLARATION_HYPHEN:
case MARKUP_DECLARATION_OCTYPE:
case DOCTYPE_UBLIC:
case DOCTYPE_YSTEM:
case AFTER_DOCTYPE_PUBLIC_KEYWORD:
case BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:
case AFTER_DOCTYPE_SYSTEM_KEYWORD:
case SELF_CLOSING_START_TAG:
case ATTRIBUTE_VALUE_DOUBLE_QUOTED:
case ATTRIBUTE_VALUE_SINGLE_QUOTED:
case ATTRIBUTE_VALUE_UNQUOTED:
case BOGUS_COMMENT_HYPHEN:
case COMMENT_LESSTHAN:
case COMMENT_LESSTHAN_BANG:
case COMMENT_LESSTHAN_BANG_DASH:
case COMMENT_LESSTHAN_BANG_DASH_DASH:
case CDATA_START:
case CDATA_SECTION:
case CDATA_RSQB:
case CDATA_RSQB_RSQB:
case PROCESSING_INSTRUCTION:
case PROCESSING_INSTRUCTION_QUESTION_MARK: {
break;
}
case CONSUME_CHARACTER_REFERENCE:
case CONSUME_NCR:
case CHARACTER_REFERENCE_TAIL:
case HEX_NCR_LOOP:
case DECIMAL_NRC_LOOP:
case HANDLE_NCR_VALUE:
case HANDLE_NCR_VALUE_RECONSUME:
case CHARACTER_REFERENCE_HILO_LOOKUP: {
if (returnStateSave == DATA || returnStateSave == RCDATA) {
return;
}
break;
}
default: {
MOZ_ASSERT(false, "Incomplete switch");
return;
}
}
suspendAfterCurrentNonTextToken = true;
}
bool nsHtml5Tokenizer::suspensionAfterCurrentNonTextTokenPending() {
return suspendAfterCurrentNonTextToken;
}
bool nsHtml5Tokenizer::internalEncodingDeclaration(
nsHtml5String internalCharset) {
if (encodingDeclarationHandler) {
return encodingDeclarationHandler->internalEncodingDeclaration(
internalCharset);
}
return false;
}
void nsHtml5Tokenizer::end() {
if (!keepBuffer) {
strBuf = nullptr;
}
doctypeName = nullptr;
if (systemIdentifier) {
systemIdentifier.Release();
systemIdentifier = nullptr;
}
if (publicIdentifier) {
publicIdentifier.Release();
publicIdentifier = nullptr;
}
tagName = nullptr;
nonInternedTagName->setNameForNonInterned(nullptr, false);
attributeName = nullptr;
nonInternedAttributeName->setNameForNonInterned(nullptr);
tokenHandler->endTokenization();
if (attributes) {
attributes->clear(0);
}
}
void nsHtml5Tokenizer::resetToDataState() {
clearStrBufAfterUse();
charRefBufLen = 0;
stateSave = nsHtml5Tokenizer::DATA;
lastCR = false;
index = 0;
forceQuirks = false;
additional = '\0';
entCol = -1;
firstCharKey = -1;
lo = 0;
hi = 0;
candidate = -1;
charRefBufMark = 0;
value = 0;
seenDigits = false;
suspendAfterCurrentNonTextToken = false;
endTag = false;
shouldSuspend = false;
initDoctypeFields();
containsHyphen = false;
tagName = nullptr;
attributeName = nullptr;
if (newAttributesEachTime) {
if (attributes) {
delete attributes;
attributes = nullptr;
}
}
}
void nsHtml5Tokenizer::loadState(nsHtml5Tokenizer* other) {
strBufLen = other->strBufLen;
if (strBufLen > strBuf.length) {
strBuf = jArray<char16_t, int32_t>::newJArray(strBufLen);
}
nsHtml5ArrayCopy::arraycopy(other->strBuf, strBuf, strBufLen);
charRefBufLen = other->charRefBufLen;
nsHtml5ArrayCopy::arraycopy(other->charRefBuf, charRefBuf, charRefBufLen);
stateSave = other->stateSave;
returnStateSave = other->returnStateSave;
endTagExpectation = other->endTagExpectation;
endTagExpectationAsArray = other->endTagExpectationAsArray;
lastCR = other->lastCR;
index = other->index;
forceQuirks = other->forceQuirks;
additional = other->additional;
entCol = other->entCol;
firstCharKey = other->firstCharKey;
lo = other->lo;
hi = other->hi;
candidate = other->candidate;
charRefBufMark = other->charRefBufMark;
value = other->value;
seenDigits = other->seenDigits;
endTag = other->endTag;
shouldSuspend = false;
suspendAfterCurrentNonTextToken = false;
doctypeName = other->doctypeName;
systemIdentifier.Release();
if (!other->systemIdentifier) {
systemIdentifier = nullptr;
} else {
systemIdentifier =
nsHtml5Portability::newStringFromString(other->systemIdentifier);
}
publicIdentifier.Release();
if (!other->publicIdentifier) {
publicIdentifier = nullptr;
} else {
publicIdentifier =
nsHtml5Portability::newStringFromString(other->publicIdentifier);
}
containsHyphen = other->containsHyphen;
if (!other->tagName) {
tagName = nullptr;
} else if (other->tagName->isInterned()) {
tagName = other->tagName;
} else {
nonInternedTagName->setNameForNonInterned(other->tagName->getName(),
other->tagName->isCustom());
tagName = nonInternedTagName;
}
if (!other->attributeName) {
attributeName = nullptr;
} else if (other->attributeName->isInterned()) {
attributeName = other->attributeName;
} else {
nonInternedAttributeName->setNameForNonInterned(
other->attributeName->getLocal(nsHtml5AttributeName::HTML));
attributeName = nonInternedAttributeName;
}
delete attributes;
if (!other->attributes) {
attributes = nullptr;
} else {
attributes = other->attributes->cloneAttributes();
}
}
void nsHtml5Tokenizer::initializeWithoutStarting() {
confident = false;
if (!keepBuffer) {
strBuf = nullptr;
}
line = 1;
attributeLine = 1;
resetToDataState();
}
void nsHtml5Tokenizer::setEncodingDeclarationHandler(
nsHtml5StreamParser* encodingDeclarationHandler) {
this->encodingDeclarationHandler = encodingDeclarationHandler;
}
nsHtml5Tokenizer::~nsHtml5Tokenizer() {
MOZ_COUNT_DTOR(nsHtml5Tokenizer);
delete nonInternedTagName;
nonInternedTagName = nullptr;
delete nonInternedAttributeName;
nonInternedAttributeName = nullptr;
delete attributes;
attributes = nullptr;
}
void nsHtml5Tokenizer::initializeStatics() {}
void nsHtml5Tokenizer::releaseStatics() {}
#include "nsHtml5TokenizerCppSupplement.h"
|