nsHtml5TokenizerHSupplement.h (5510B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 friend struct nsHtml5ViewSourcePolicySIMD; 6 friend struct nsHtml5ViewSourcePolicyALU; 7 friend struct nsHtml5LineColPolicySIMD; 8 friend struct nsHtml5LineColPolicyALU; 9 friend struct nsHtml5FastestPolicySIMD; 10 friend struct nsHtml5FastestPolicyALU; 11 12 private: 13 int32_t col; 14 bool nextCharOnNewLine; 15 16 // These functions are wrappers for template parametrized stateLoop and 17 // stateLoopCompilerWorkaround so that the instantiations can go into 18 // separate compilation units both to allow different compiler flags 19 // and to make LLVM perform LICM on SIMD constants in functions whose size 20 // isn't too large for LLVM to perform LICM before LLVM looks for inlining 21 // opportunities. 22 23 int32_t StateLoopFastestSIMD(int32_t state, char16_t c, int32_t pos, 24 char16_t* buf, bool reconsume, int32_t returnState, 25 int32_t endPos); 26 27 int32_t StateLoopFastestALU(int32_t state, char16_t c, int32_t pos, 28 char16_t* buf, bool reconsume, int32_t returnState, 29 int32_t endPos); 30 31 int32_t StateLoopLineColSIMD(int32_t state, char16_t c, int32_t pos, 32 char16_t* buf, bool reconsume, int32_t returnState, 33 int32_t endPos); 34 35 int32_t StateLoopLineColALU(int32_t state, char16_t c, int32_t pos, 36 char16_t* buf, bool reconsume, int32_t returnState, 37 int32_t endPos); 38 39 int32_t StateLoopViewSourceSIMD(int32_t state, char16_t c, int32_t pos, 40 char16_t* buf, bool reconsume, 41 int32_t returnState, int32_t endPos); 42 43 int32_t StateLoopViewSourceALU(int32_t state, char16_t c, int32_t pos, 44 char16_t* buf, bool reconsume, 45 int32_t returnState, int32_t endPos); 46 47 public: 48 inline int32_t getColumnNumber() { return col; } 49 50 inline void setColumnNumberAndResetNextLine(int32_t aCol) { 51 col = aCol; 52 // The restored position only ever points to the position of 53 // script tag's > character, so we can unconditionally use 54 // `false` below. 55 nextCharOnNewLine = false; 56 } 57 58 inline nsHtml5HtmlAttributes* GetAttributes() { return attributes; } 59 60 /** 61 * Makes sure the buffers are large enough to be able to tokenize aLength 62 * UTF-16 code units before having to make the buffers larger. 63 * 64 * @param aLength the number of UTF-16 code units to be tokenized before the 65 * next call to this method. 66 * @return true if successful; false if out of memory 67 */ 68 bool EnsureBufferSpace(int32_t aLength); 69 70 MOZ_COLD MOZ_NEVER_INLINE void EnsureBufferSpaceShouldNeverHappen( 71 int32_t aLength); 72 73 nsHtml5String TryAtomizeForSingleDigit(); 74 75 bool TemplatePushedOrHeadPopped(); 76 77 void RememberGt(int32_t aPos); 78 79 void AtKilobyteBoundary() { suspendAfterCurrentTokenIfNotInText(); } 80 81 bool IsInTokenStartedAtKilobyteBoundary() { 82 return suspensionAfterCurrentNonTextTokenPending(); 83 } 84 85 mozilla::UniquePtr<nsHtml5Highlighter> mViewSource; 86 87 /** 88 * Starts handling text/plain. This is a one-way initialization. There is 89 * no corresponding EndPlainText() call. 90 */ 91 void StartPlainText(); 92 93 void EnableViewSource(nsHtml5Highlighter* aHighlighter); 94 95 bool ShouldFlushViewSource(); 96 97 mozilla::Result<bool, nsresult> FlushViewSource(); 98 99 void StartViewSource(const nsAutoString& aTitle); 100 101 void StartViewSourceBodyContents(); 102 103 [[nodiscard]] bool EndViewSource(); 104 105 void RewindViewSource(); 106 107 void SetViewSourceOpSink(nsAHtml5TreeOpSink* aOpSink); 108 109 void errGarbageAfterLtSlash(); 110 111 void errLtSlashGt(); 112 113 void errWarnLtSlashInRcdata(); 114 115 void errCharRefLacksSemicolon(); 116 117 void errNoDigitsInNCR(); 118 119 void errGtInSystemId(); 120 121 void errGtInPublicId(); 122 123 void errNamelessDoctype(); 124 125 void errConsecutiveHyphens(); 126 127 void errPrematureEndOfComment(); 128 129 void errBogusComment(); 130 131 void errUnquotedAttributeValOrNull(char16_t c); 132 133 void errSlashNotFollowedByGt(); 134 135 void errNoSpaceBetweenAttributes(); 136 137 void errLtOrEqualsOrGraveInUnquotedAttributeOrNull(char16_t c); 138 139 void errAttributeValueMissing(); 140 141 void errBadCharBeforeAttributeNameOrNull(char16_t c); 142 143 void errEqualsSignBeforeAttributeName(); 144 145 void errBadCharAfterLt(char16_t c); 146 147 void errLtGt(); 148 149 void errProcessingInstruction(); 150 151 void errUnescapedAmpersandInterpretedAsCharacterReference(); 152 153 void errNotSemicolonTerminated(); 154 155 void errNoNamedCharacterMatch(); 156 157 void errQuoteBeforeAttributeName(char16_t c); 158 159 void errQuoteOrLtInAttributeNameOrNull(char16_t c); 160 161 void errExpectedPublicId(); 162 163 void errBogusDoctype(); 164 165 void maybeErrAttributesOnEndTag(nsHtml5HtmlAttributes* attrs); 166 167 void maybeErrSlashInEndTag(bool selfClosing); 168 169 void errNcrSurrogate(); 170 171 void errNcrInC1Range(); 172 173 void errEofInPublicId(); 174 175 void errEofInComment(); 176 177 void errEofInDoctype(); 178 179 void errEofInAttributeValue(); 180 181 void errEofInAttributeName(); 182 183 void errEofWithoutGt(); 184 185 void errEofInTagName(); 186 187 void errEofInEndTag(); 188 189 void errEofAfterLt(); 190 191 void errNcrOutOfRange(); 192 193 void errNcrUnassigned(); 194 195 void errDuplicateAttribute(); 196 197 void errEofInSystemId(); 198 199 void errExpectedSystemId(); 200 201 void errMissingSpaceBeforeDoctypeName(); 202 203 void errNestedComment(); 204 205 void errNcrZero(); 206 207 void errNoSpaceBetweenDoctypeSystemKeywordAndQuote(); 208 209 void errNoSpaceBetweenPublicAndSystemIds(); 210 211 void errNoSpaceBetweenDoctypePublicKeywordAndQuote();