parser/html/nsHtml5TokenizerCppSupplement.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5TokenizerCppSupplement.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,530 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "mozilla/Likely.h"
     1.9 +
    1.10 +void
    1.11 +nsHtml5Tokenizer::StartPlainText()
    1.12 +{
    1.13 +  stateSave = NS_HTML5TOKENIZER_PLAINTEXT;
    1.14 +}
    1.15 +
    1.16 +void
    1.17 +nsHtml5Tokenizer::EnableViewSource(nsHtml5Highlighter* aHighlighter)
    1.18 +{
    1.19 +  mViewSource = aHighlighter;
    1.20 +}
    1.21 +
    1.22 +bool
    1.23 +nsHtml5Tokenizer::FlushViewSource()
    1.24 +{
    1.25 +  return mViewSource->FlushOps();
    1.26 +}
    1.27 +
    1.28 +void
    1.29 +nsHtml5Tokenizer::StartViewSource(const nsAutoString& aTitle)
    1.30 +{
    1.31 +  mViewSource->Start(aTitle);
    1.32 +}
    1.33 +
    1.34 +void
    1.35 +nsHtml5Tokenizer::EndViewSource()
    1.36 +{
    1.37 +  mViewSource->End();
    1.38 +}
    1.39 +
    1.40 +void
    1.41 +nsHtml5Tokenizer::errWarnLtSlashInRcdata()
    1.42 +{
    1.43 +}
    1.44 +
    1.45 +// The null checks below annotated MOZ_LIKELY are not actually necessary.
    1.46 +
    1.47 +void
    1.48 +nsHtml5Tokenizer::errUnquotedAttributeValOrNull(char16_t c)
    1.49 +{
    1.50 +  if (MOZ_LIKELY(mViewSource)) {
    1.51 +    switch (c) {
    1.52 +      case '<':
    1.53 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeLt");
    1.54 +        return;
    1.55 +      case '`':
    1.56 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeGrave");
    1.57 +        return;
    1.58 +      case '\'':
    1.59 +      case '"':
    1.60 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeQuote");
    1.61 +        return;
    1.62 +      case '=':
    1.63 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeEquals");
    1.64 +        return;
    1.65 +    }
    1.66 +  }
    1.67 +}
    1.68 +
    1.69 +void
    1.70 +nsHtml5Tokenizer::errLtOrEqualsOrGraveInUnquotedAttributeOrNull(char16_t c)
    1.71 +{
    1.72 +  if (MOZ_LIKELY(mViewSource)) {
    1.73 +    switch (c) {
    1.74 +      case '=':
    1.75 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeStartEquals");
    1.76 +        return;
    1.77 +      case '<':
    1.78 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeStartLt");
    1.79 +        return;
    1.80 +      case '`':
    1.81 +        mViewSource->AddErrorToCurrentNode("errUnquotedAttributeStartGrave");
    1.82 +        return;
    1.83 +    }
    1.84 +  }
    1.85 +}
    1.86 +
    1.87 +void
    1.88 +nsHtml5Tokenizer::errBadCharBeforeAttributeNameOrNull(char16_t c)
    1.89 +{
    1.90 +  if (MOZ_LIKELY(mViewSource)) {
    1.91 +    if (c == '<') {
    1.92 +      mViewSource->AddErrorToCurrentNode("errBadCharBeforeAttributeNameLt");
    1.93 +    } else if (c == '=') {
    1.94 +      errEqualsSignBeforeAttributeName();
    1.95 +    } else if (c != 0xFFFD) {
    1.96 +      errQuoteBeforeAttributeName(c);
    1.97 +    }
    1.98 +  }
    1.99 +}
   1.100 +
   1.101 +void
   1.102 +nsHtml5Tokenizer::errBadCharAfterLt(char16_t c)
   1.103 +{
   1.104 +  if (MOZ_LIKELY(mViewSource)) {
   1.105 +    mViewSource->AddErrorToCurrentNode("errBadCharAfterLt");
   1.106 +  }
   1.107 +}
   1.108 +
   1.109 +void
   1.110 +nsHtml5Tokenizer::errQuoteOrLtInAttributeNameOrNull(char16_t c)
   1.111 +{
   1.112 +  if (MOZ_LIKELY(mViewSource)) {
   1.113 +    if (c == '<') {
   1.114 +      mViewSource->AddErrorToCurrentNode("errLtInAttributeName");
   1.115 +    } else if (c != 0xFFFD) {
   1.116 +      mViewSource->AddErrorToCurrentNode("errQuoteInAttributeName");
   1.117 +    }
   1.118 +  }
   1.119 +}
   1.120 +
   1.121 +void
   1.122 +nsHtml5Tokenizer::maybeErrAttributesOnEndTag(nsHtml5HtmlAttributes* attrs)
   1.123 +{
   1.124 +  if (mViewSource && attrs->getLength() != 0) {
   1.125 +    /*
   1.126 +     * When an end tag token is emitted with attributes, that is a parse
   1.127 +     * error.
   1.128 +     */
   1.129 +    mViewSource->AddErrorToCurrentRun("maybeErrAttributesOnEndTag");
   1.130 +  }
   1.131 +}
   1.132 +
   1.133 +void
   1.134 +nsHtml5Tokenizer::maybeErrSlashInEndTag(bool selfClosing)
   1.135 +{
   1.136 +  if (mViewSource && selfClosing && endTag) {
   1.137 +    mViewSource->AddErrorToCurrentSlash("maybeErrSlashInEndTag");
   1.138 +  }
   1.139 +}
   1.140 +
   1.141 +char16_t
   1.142 +nsHtml5Tokenizer::errNcrNonCharacter(char16_t ch)
   1.143 +{
   1.144 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.145 +    mViewSource->AddErrorToCurrentNode("errNcrNonCharacter");
   1.146 +  }
   1.147 +  return ch;
   1.148 +}
   1.149 +
   1.150 +void
   1.151 +nsHtml5Tokenizer::errAstralNonCharacter(int32_t ch)
   1.152 +{
   1.153 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.154 +    mViewSource->AddErrorToCurrentNode("errNcrNonCharacter");
   1.155 +  }
   1.156 +}
   1.157 +
   1.158 +char16_t
   1.159 +nsHtml5Tokenizer::errNcrControlChar(char16_t ch)
   1.160 +{
   1.161 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.162 +    mViewSource->AddErrorToCurrentNode("errNcrControlChar");
   1.163 +  }
   1.164 +  return ch;
   1.165 +}
   1.166 +
   1.167 +void
   1.168 +nsHtml5Tokenizer::errGarbageAfterLtSlash()
   1.169 +{
   1.170 +  if (MOZ_LIKELY(mViewSource)) {
   1.171 +    mViewSource->AddErrorToCurrentNode("errGarbageAfterLtSlash");
   1.172 +  }
   1.173 +}
   1.174 +
   1.175 +void
   1.176 +nsHtml5Tokenizer::errLtSlashGt()
   1.177 +{
   1.178 +  if (MOZ_LIKELY(mViewSource)) {
   1.179 +    mViewSource->AddErrorToCurrentNode("errLtSlashGt");
   1.180 +  }
   1.181 +}
   1.182 +
   1.183 +void
   1.184 +nsHtml5Tokenizer::errCharRefLacksSemicolon()
   1.185 +{
   1.186 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.187 +    mViewSource->AddErrorToCurrentNode("errCharRefLacksSemicolon");
   1.188 +  }
   1.189 +}
   1.190 +
   1.191 +void
   1.192 +nsHtml5Tokenizer::errNoDigitsInNCR()
   1.193 +{
   1.194 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.195 +    mViewSource->AddErrorToCurrentNode("errNoDigitsInNCR");
   1.196 +  }
   1.197 +}
   1.198 +
   1.199 +void
   1.200 +nsHtml5Tokenizer::errGtInSystemId()
   1.201 +{
   1.202 +  if (MOZ_LIKELY(mViewSource)) {
   1.203 +    mViewSource->AddErrorToCurrentNode("errGtInSystemId");
   1.204 +  }
   1.205 +}
   1.206 +
   1.207 +void
   1.208 +nsHtml5Tokenizer::errGtInPublicId()
   1.209 +{
   1.210 +  if (MOZ_LIKELY(mViewSource)) {
   1.211 +    mViewSource->AddErrorToCurrentNode("errGtInPublicId");
   1.212 +  }
   1.213 +}
   1.214 +
   1.215 +void
   1.216 +nsHtml5Tokenizer::errNamelessDoctype()
   1.217 +{
   1.218 +  if (MOZ_LIKELY(mViewSource)) {
   1.219 +    mViewSource->AddErrorToCurrentNode("errNamelessDoctype");
   1.220 +  }
   1.221 +}
   1.222 +
   1.223 +void
   1.224 +nsHtml5Tokenizer::errConsecutiveHyphens()
   1.225 +{
   1.226 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.227 +    mViewSource->AddErrorToCurrentNode("errConsecutiveHyphens");
   1.228 +  }
   1.229 +}
   1.230 +
   1.231 +void
   1.232 +nsHtml5Tokenizer::errPrematureEndOfComment()
   1.233 +{
   1.234 +  if (MOZ_LIKELY(mViewSource)) {
   1.235 +    mViewSource->AddErrorToCurrentNode("errPrematureEndOfComment");
   1.236 +  }
   1.237 +}
   1.238 +
   1.239 +void
   1.240 +nsHtml5Tokenizer::errBogusComment()
   1.241 +{
   1.242 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.243 +    mViewSource->AddErrorToCurrentNode("errBogusComment");
   1.244 +  }
   1.245 +}
   1.246 +
   1.247 +void
   1.248 +nsHtml5Tokenizer::errSlashNotFollowedByGt()
   1.249 +{
   1.250 +  if (MOZ_LIKELY(mViewSource)) {
   1.251 +    mViewSource->AddErrorToCurrentSlash("errSlashNotFollowedByGt");
   1.252 +  }
   1.253 +}
   1.254 +
   1.255 +void
   1.256 +nsHtml5Tokenizer::errNoSpaceBetweenAttributes()
   1.257 +{
   1.258 +  if (MOZ_LIKELY(mViewSource)) {
   1.259 +    mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenAttributes");
   1.260 +  }
   1.261 +}
   1.262 +
   1.263 +void
   1.264 +nsHtml5Tokenizer::errAttributeValueMissing()
   1.265 +{
   1.266 +  if (MOZ_LIKELY(mViewSource)) {
   1.267 +    mViewSource->AddErrorToCurrentNode("errAttributeValueMissing");
   1.268 +  }
   1.269 +}
   1.270 +
   1.271 +void
   1.272 +nsHtml5Tokenizer::errEqualsSignBeforeAttributeName()
   1.273 +{
   1.274 +  if (MOZ_LIKELY(mViewSource)) {
   1.275 +    mViewSource->AddErrorToCurrentNode("errEqualsSignBeforeAttributeName");
   1.276 +  }
   1.277 +}
   1.278 +
   1.279 +void
   1.280 +nsHtml5Tokenizer::errLtGt()
   1.281 +{
   1.282 +  if (MOZ_LIKELY(mViewSource)) {
   1.283 +    mViewSource->AddErrorToCurrentNode("errLtGt");
   1.284 +  }
   1.285 +}
   1.286 +
   1.287 +void
   1.288 +nsHtml5Tokenizer::errProcessingInstruction()
   1.289 +{
   1.290 +  if (MOZ_LIKELY(mViewSource)) {
   1.291 +    mViewSource->AddErrorToCurrentNode("errProcessingInstruction");
   1.292 +  }
   1.293 +}
   1.294 +
   1.295 +void
   1.296 +nsHtml5Tokenizer::errUnescapedAmpersandInterpretedAsCharacterReference()
   1.297 +{
   1.298 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.299 +    mViewSource->AddErrorToCurrentAmpersand("errUnescapedAmpersandInterpretedAsCharacterReference");
   1.300 +  }
   1.301 +}
   1.302 +
   1.303 +void
   1.304 +nsHtml5Tokenizer::errNotSemicolonTerminated()
   1.305 +{
   1.306 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.307 +    mViewSource->AddErrorToCurrentNode("errNotSemicolonTerminated");
   1.308 +  }
   1.309 +}
   1.310 +
   1.311 +void
   1.312 +nsHtml5Tokenizer::errNoNamedCharacterMatch()
   1.313 +{
   1.314 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.315 +    mViewSource->AddErrorToCurrentAmpersand("errNoNamedCharacterMatch");
   1.316 +  }
   1.317 +}
   1.318 +
   1.319 +void
   1.320 +nsHtml5Tokenizer::errQuoteBeforeAttributeName(char16_t c)
   1.321 +{
   1.322 +  if (MOZ_LIKELY(mViewSource)) {
   1.323 +    mViewSource->AddErrorToCurrentNode("errQuoteBeforeAttributeName");
   1.324 +  }
   1.325 +}
   1.326 +
   1.327 +void
   1.328 +nsHtml5Tokenizer::errExpectedPublicId()
   1.329 +{
   1.330 +  if (MOZ_LIKELY(mViewSource)) {
   1.331 +    mViewSource->AddErrorToCurrentNode("errExpectedPublicId");
   1.332 +  }
   1.333 +}
   1.334 +
   1.335 +void
   1.336 +nsHtml5Tokenizer::errBogusDoctype()
   1.337 +{
   1.338 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.339 +    mViewSource->AddErrorToCurrentNode("errBogusDoctype");
   1.340 +  }
   1.341 +}
   1.342 +
   1.343 +void
   1.344 +nsHtml5Tokenizer::errNcrSurrogate()
   1.345 +{
   1.346 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.347 +    mViewSource->AddErrorToCurrentNode("errNcrSurrogate");
   1.348 +  }
   1.349 +}
   1.350 +
   1.351 +void
   1.352 +nsHtml5Tokenizer::errNcrCr()
   1.353 +{
   1.354 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.355 +    mViewSource->AddErrorToCurrentNode("errNcrCr");
   1.356 +  }
   1.357 +}
   1.358 +
   1.359 +void
   1.360 +nsHtml5Tokenizer::errNcrInC1Range()
   1.361 +{
   1.362 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.363 +    mViewSource->AddErrorToCurrentNode("errNcrInC1Range");
   1.364 +  }
   1.365 +}
   1.366 +
   1.367 +void
   1.368 +nsHtml5Tokenizer::errEofInPublicId()
   1.369 +{
   1.370 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.371 +    mViewSource->AddErrorToCurrentRun("errEofInPublicId");
   1.372 +  }
   1.373 +}
   1.374 +
   1.375 +void
   1.376 +nsHtml5Tokenizer::errEofInComment()
   1.377 +{
   1.378 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.379 +    mViewSource->AddErrorToCurrentRun("errEofInComment");
   1.380 +  }
   1.381 +}
   1.382 +
   1.383 +void
   1.384 +nsHtml5Tokenizer::errEofInDoctype()
   1.385 +{
   1.386 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.387 +    mViewSource->AddErrorToCurrentRun("errEofInDoctype");
   1.388 +  }
   1.389 +}
   1.390 +
   1.391 +void
   1.392 +nsHtml5Tokenizer::errEofInAttributeValue()
   1.393 +{
   1.394 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.395 +    mViewSource->AddErrorToCurrentRun("errEofInAttributeValue");
   1.396 +  }
   1.397 +}
   1.398 +
   1.399 +void
   1.400 +nsHtml5Tokenizer::errEofInAttributeName()
   1.401 +{
   1.402 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.403 +    mViewSource->AddErrorToCurrentRun("errEofInAttributeName");
   1.404 +  }
   1.405 +}
   1.406 +
   1.407 +void
   1.408 +nsHtml5Tokenizer::errEofWithoutGt()
   1.409 +{
   1.410 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.411 +    mViewSource->AddErrorToCurrentRun("errEofWithoutGt");
   1.412 +  }
   1.413 +}
   1.414 +
   1.415 +void
   1.416 +nsHtml5Tokenizer::errEofInTagName()
   1.417 +{
   1.418 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.419 +    mViewSource->AddErrorToCurrentRun("errEofInTagName");
   1.420 +  }
   1.421 +}
   1.422 +
   1.423 +void
   1.424 +nsHtml5Tokenizer::errEofInEndTag()
   1.425 +{
   1.426 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.427 +    mViewSource->AddErrorToCurrentRun("errEofInEndTag");
   1.428 +  }
   1.429 +}
   1.430 +
   1.431 +void
   1.432 +nsHtml5Tokenizer::errEofAfterLt()
   1.433 +{
   1.434 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.435 +    mViewSource->AddErrorToCurrentRun("errEofAfterLt");
   1.436 +  }
   1.437 +}
   1.438 +
   1.439 +void
   1.440 +nsHtml5Tokenizer::errNcrOutOfRange()
   1.441 +{
   1.442 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.443 +    mViewSource->AddErrorToCurrentNode("errNcrOutOfRange");
   1.444 +  }
   1.445 +}
   1.446 +
   1.447 +void
   1.448 +nsHtml5Tokenizer::errNcrUnassigned()
   1.449 +{
   1.450 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.451 +    mViewSource->AddErrorToCurrentNode("errNcrUnassigned");
   1.452 +  }
   1.453 +}
   1.454 +
   1.455 +void
   1.456 +nsHtml5Tokenizer::errDuplicateAttribute()
   1.457 +{
   1.458 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.459 +    mViewSource->AddErrorToCurrentNode("errDuplicateAttribute");
   1.460 +  }
   1.461 +}
   1.462 +
   1.463 +void
   1.464 +nsHtml5Tokenizer::errEofInSystemId()
   1.465 +{
   1.466 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.467 +    mViewSource->AddErrorToCurrentRun("errEofInSystemId");
   1.468 +  }
   1.469 +}
   1.470 +
   1.471 +void
   1.472 +nsHtml5Tokenizer::errExpectedSystemId()
   1.473 +{
   1.474 +  if (MOZ_LIKELY(mViewSource)) {
   1.475 +    mViewSource->AddErrorToCurrentNode("errExpectedSystemId");
   1.476 +  }
   1.477 +}
   1.478 +
   1.479 +void
   1.480 +nsHtml5Tokenizer::errMissingSpaceBeforeDoctypeName()
   1.481 +{
   1.482 +  if (MOZ_LIKELY(mViewSource)) {
   1.483 +    mViewSource->AddErrorToCurrentNode("errMissingSpaceBeforeDoctypeName");
   1.484 +  }
   1.485 +}
   1.486 +
   1.487 +void
   1.488 +nsHtml5Tokenizer::errHyphenHyphenBang()
   1.489 +{
   1.490 +  if (MOZ_LIKELY(mViewSource)) {
   1.491 +    mViewSource->AddErrorToCurrentNode("errHyphenHyphenBang");
   1.492 +  }
   1.493 +}
   1.494 +
   1.495 +void
   1.496 +nsHtml5Tokenizer::errNcrControlChar()
   1.497 +{
   1.498 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.499 +    mViewSource->AddErrorToCurrentNode("errNcrControlChar");
   1.500 +  }
   1.501 +}
   1.502 +
   1.503 +void
   1.504 +nsHtml5Tokenizer::errNcrZero()
   1.505 +{
   1.506 +  if (MOZ_UNLIKELY(mViewSource)) {
   1.507 +    mViewSource->AddErrorToCurrentNode("errNcrZero");
   1.508 +  }
   1.509 +}
   1.510 +
   1.511 +void
   1.512 +nsHtml5Tokenizer::errNoSpaceBetweenDoctypeSystemKeywordAndQuote()
   1.513 +{
   1.514 +  if (MOZ_LIKELY(mViewSource)) {
   1.515 +    mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenDoctypeSystemKeywordAndQuote");
   1.516 +  }
   1.517 +}
   1.518 +
   1.519 +void
   1.520 +nsHtml5Tokenizer::errNoSpaceBetweenPublicAndSystemIds()
   1.521 +{
   1.522 +  if (MOZ_LIKELY(mViewSource)) {
   1.523 +    mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenPublicAndSystemIds");
   1.524 +  }
   1.525 +}
   1.526 +
   1.527 +void
   1.528 +nsHtml5Tokenizer::errNoSpaceBetweenDoctypePublicKeywordAndQuote()
   1.529 +{
   1.530 +  if (MOZ_LIKELY(mViewSource)) {
   1.531 +    mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenDoctypePublicKeywordAndQuote");
   1.532 +  }
   1.533 +}

mercurial