nsHtml5TokenizerLoopPoliciesALU.h (10046B)
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 #ifndef nsHtml5TokenizerLoopPoliciesALU_h 6 #define nsHtml5TokenizerLoopPoliciesALU_h 7 8 /** 9 * This policy does not report tokenizer transitions anywhere and does not 10 * track line and column numbers. To be used for innerHTML. Non-SIMD version. 11 */ 12 struct nsHtml5FastestPolicyALU { 13 static const bool reportErrors = false; 14 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t transition( 15 nsHtml5Highlighter* aHighlighter, int32_t aState, bool aReconsume, 16 int32_t aPos) { 17 return aState; 18 } 19 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void completedNamedCharacterReference( 20 nsHtml5Highlighter* aHighlighter) {} 21 22 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementData( 23 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 24 int32_t endPos) { 25 return 0; 26 } 27 28 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementRawtext( 29 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 30 int32_t endPos) { 31 return 0; 32 } 33 34 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 35 accelerateAdvancementScriptDataEscaped(nsHtml5Tokenizer* aTokenizer, 36 char16_t* buf, int32_t pos, 37 int32_t endPos) { 38 return 0; 39 } 40 41 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementComment( 42 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 43 int32_t endPos) { 44 return 0; 45 } 46 47 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 48 accelerateAdvancementAttributeValueSingleQuoted(nsHtml5Tokenizer* aTokenizer, 49 char16_t* buf, int32_t pos, 50 int32_t endPos) { 51 return 0; 52 } 53 54 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 55 accelerateAdvancementAttributeValueDoubleQuoted(nsHtml5Tokenizer* aTokenizer, 56 char16_t* buf, int32_t pos, 57 int32_t endPos) { 58 return 0; 59 } 60 61 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementCdataSection( 62 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 63 int32_t endPos) { 64 return 0; 65 } 66 67 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementPlaintext( 68 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 69 int32_t endPos) { 70 return 0; 71 } 72 73 MOZ_ALWAYS_INLINE_EVEN_DEBUG static char16_t checkChar( 74 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos) { 75 return buf[pos]; 76 } 77 78 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void silentCarriageReturn( 79 nsHtml5Tokenizer* aTokenizer) { 80 aTokenizer->lastCR = true; 81 } 82 83 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void silentLineFeed( 84 nsHtml5Tokenizer* aTokenizer) {} 85 }; 86 87 /** 88 * This policy does not report tokenizer transitions anywhere. To be used 89 * when _not_ viewing source and when not parsing innerHTML (or other 90 * script execution-preventing fragment). 91 */ 92 struct nsHtml5LineColPolicyALU { 93 static const bool reportErrors = false; 94 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t transition( 95 nsHtml5Highlighter* aHighlighter, int32_t aState, bool aReconsume, 96 int32_t aPos) { 97 return aState; 98 } 99 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void completedNamedCharacterReference( 100 nsHtml5Highlighter* aHighlighter) {} 101 102 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementData( 103 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 104 int32_t endPos) { 105 return 0; 106 } 107 108 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementRawtext( 109 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 110 int32_t endPos) { 111 return 0; 112 } 113 114 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 115 accelerateAdvancementScriptDataEscaped(nsHtml5Tokenizer* aTokenizer, 116 char16_t* buf, int32_t pos, 117 int32_t endPos) { 118 return 0; 119 } 120 121 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementComment( 122 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 123 int32_t endPos) { 124 return 0; 125 } 126 127 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 128 accelerateAdvancementAttributeValueSingleQuoted(nsHtml5Tokenizer* aTokenizer, 129 char16_t* buf, int32_t pos, 130 int32_t endPos) { 131 return 0; 132 } 133 134 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 135 accelerateAdvancementAttributeValueDoubleQuoted(nsHtml5Tokenizer* aTokenizer, 136 char16_t* buf, int32_t pos, 137 int32_t endPos) { 138 return 0; 139 } 140 141 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementCdataSection( 142 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 143 int32_t endPos) { 144 return 0; 145 } 146 147 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementPlaintext( 148 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 149 int32_t endPos) { 150 return 0; 151 } 152 153 MOZ_ALWAYS_INLINE_EVEN_DEBUG static char16_t checkChar( 154 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos) { 155 // The name of this method comes from the validator. 156 // We aren't checking a char here. We read the next 157 // UTF-16 code unit and, before returning it, adjust 158 // the line and column numbers. 159 char16_t c = buf[pos]; 160 if (MOZ_UNLIKELY(aTokenizer->nextCharOnNewLine)) { 161 // By changing the line and column here instead 162 // of doing so eagerly when seeing the line break 163 // causes the line break itself to be considered 164 // column-wise at the end of a line. 165 aTokenizer->line++; 166 aTokenizer->col = 1; 167 aTokenizer->nextCharOnNewLine = false; 168 } else if (MOZ_LIKELY(!NS_IS_LOW_SURROGATE(c))) { 169 // SpiderMonkey wants to count scalar values 170 // instead of UTF-16 code units. We omit low 171 // surrogates from the count so that only the 172 // high surrogate increments the count for 173 // two-code-unit scalar values. 174 // 175 // It's somewhat questionable from the performance 176 // perspective to make the human-perceivable column 177 // count correct for non-BMP characters in the case 178 // where there is a single scalar value per extended 179 // grapheme cluster when even on the BMP there are 180 // various cases where the scalar count doesn't make 181 // much sense as a human-perceived "column count" due 182 // to extended grapheme clusters consisting of more 183 // than one scalar value. 184 aTokenizer->col++; 185 } 186 return c; 187 } 188 189 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void silentCarriageReturn( 190 nsHtml5Tokenizer* aTokenizer) { 191 aTokenizer->nextCharOnNewLine = true; 192 aTokenizer->lastCR = true; 193 } 194 195 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void silentLineFeed( 196 nsHtml5Tokenizer* aTokenizer) { 197 aTokenizer->nextCharOnNewLine = true; 198 } 199 }; 200 201 /** 202 * This policy reports the tokenizer transitions to a highlighter. To be used 203 * when viewing source. 204 */ 205 struct nsHtml5ViewSourcePolicyALU { 206 static const bool reportErrors = true; 207 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t transition( 208 nsHtml5Highlighter* aHighlighter, int32_t aState, bool aReconsume, 209 int32_t aPos) { 210 return aHighlighter->Transition(aState, aReconsume, aPos); 211 } 212 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void completedNamedCharacterReference( 213 nsHtml5Highlighter* aHighlighter) { 214 aHighlighter->CompletedNamedCharacterReference(); 215 } 216 217 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementData( 218 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 219 int32_t endPos) { 220 return 0; 221 } 222 223 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementRawtext( 224 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 225 int32_t endPos) { 226 return 0; 227 } 228 229 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 230 accelerateAdvancementScriptDataEscaped(nsHtml5Tokenizer* aTokenizer, 231 char16_t* buf, int32_t pos, 232 int32_t endPos) { 233 return 0; 234 } 235 236 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementComment( 237 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 238 int32_t endPos) { 239 return 0; 240 } 241 242 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 243 accelerateAdvancementAttributeValueSingleQuoted(nsHtml5Tokenizer* aTokenizer, 244 char16_t* buf, int32_t pos, 245 int32_t endPos) { 246 return 0; 247 } 248 249 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t 250 accelerateAdvancementAttributeValueDoubleQuoted(nsHtml5Tokenizer* aTokenizer, 251 char16_t* buf, int32_t pos, 252 int32_t endPos) { 253 return 0; 254 } 255 256 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementCdataSection( 257 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 258 int32_t endPos) { 259 return 0; 260 } 261 262 MOZ_ALWAYS_INLINE_EVEN_DEBUG static int32_t accelerateAdvancementPlaintext( 263 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos, 264 int32_t endPos) { 265 return 0; 266 } 267 268 MOZ_ALWAYS_INLINE_EVEN_DEBUG static char16_t checkChar( 269 nsHtml5Tokenizer* aTokenizer, char16_t* buf, int32_t pos) { 270 return buf[pos]; 271 } 272 273 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void silentCarriageReturn( 274 nsHtml5Tokenizer* aTokenizer) { 275 aTokenizer->line++; 276 aTokenizer->lastCR = true; 277 } 278 279 MOZ_ALWAYS_INLINE_EVEN_DEBUG static void silentLineFeed( 280 nsHtml5Tokenizer* aTokenizer) { 281 aTokenizer->line++; 282 } 283 }; 284 285 #endif // nsHtml5TokenizerLoopPoliciesALU_h