Bug 1467336 - Invert SourceUnits::hasRawChars's meaning and rename it to SourceUnits::atEnd. r=arai
authorJeff Walden <jwalden@mit.edu>
Fri, 08 Jun 2018 11:46:17 -0700
changeset 476723 03e60a8119191f315216a7a5a0b0431264ae5467
parent 476722 3d10297c43844a8941879a91b9574000fb3f6f8a
child 476724 673d93f7c030c02f2ed3d70d77a7a2ba9e017312
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1467336
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1467336 - Invert SourceUnits::hasRawChars's meaning and rename it to SourceUnits::atEnd. r=arai
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -495,32 +495,32 @@ TokenStreamAnyChars::updateFlagsForEOL()
 // unit, normalizing EOL sequences to '\n', also updating line/column info as
 // needed.
 template<class AnyCharsAccess>
 bool
 TokenStreamChars<char16_t, AnyCharsAccess>::getCodePoint(int32_t* cp)
 {
     TokenStreamAnyChars& anyChars = anyCharsAccess();
 
-    if (MOZ_UNLIKELY(!sourceUnits.hasRawChars())) {
+    if (MOZ_UNLIKELY(sourceUnits.atEnd())) {
         anyChars.flags.isEOF = true;
         *cp = EOF;
         return true;
     }
 
     int32_t c = sourceUnits.getCodeUnit();
 
     do {
         // Normalize the char16_t if it was a newline.
         if (MOZ_UNLIKELY(c == '\n'))
             break;
 
         if (MOZ_UNLIKELY(c == '\r')) {
             // If it's a \r\n sequence: treat as a single EOL, skip over the \n.
-            if (MOZ_LIKELY(sourceUnits.hasRawChars()))
+            if (MOZ_LIKELY(!sourceUnits.atEnd()))
                 sourceUnits.matchCodeUnit('\n');
 
             break;
         }
 
         if (MOZ_UNLIKELY(c == unicode::LINE_SEPARATOR || c == unicode::PARA_SEPARATOR))
             break;
 
@@ -566,17 +566,17 @@ TokenStreamChars<char16_t, AnyCharsAcces
             MOZ_ASSERT(!SourceUnits::isRawEOLChar(*codePoint));
         }
 
         return true;
     }
 
     // If there are no more units, or the next unit isn't a trailing surrogate,
     // it's also a "code point".
-    if (MOZ_UNLIKELY(!sourceUnits.hasRawChars() ||
+    if (MOZ_UNLIKELY(sourceUnits.atEnd() ||
                      !unicode::IsTrailSurrogate(sourceUnits.peekCodeUnit())))
     {
         MOZ_ASSERT(!SourceUnits::isRawEOLChar(*codePoint));
         return true;
     }
 
     // Otherwise we have a multi-unit code point.
     *codePoint = unicode::UTF16Decode(lead, sourceUnits.getCodeUnit());
@@ -592,17 +592,17 @@ TokenStreamChars<char16_t, AnyCharsAcces
 //
 // Only use this if (a) the resulting code unit is guaranteed to be ungotten
 // (by ungetCodeUnit()) if it's an EOL, and (b) the line-related state (lineno,
 // linebase) is not used before it's ungotten.
 template<typename CharT, class AnyCharsAccess>
 int32_t
 GeneralTokenStreamChars<CharT, AnyCharsAccess>::getCodeUnit()
 {
-    if (MOZ_LIKELY(sourceUnits.hasRawChars()))
+    if (MOZ_LIKELY(!sourceUnits.atEnd()))
         return sourceUnits.getCodeUnit();
 
     anyCharsAccess().flags.isEOF = true;
     return EOF;
 }
 
 template<typename CharT, class AnyCharsAccess>
 void
@@ -1801,17 +1801,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
     // Check if in the middle of a template string. Have to get this out of
     // the way first.
     if (MOZ_UNLIKELY(modifier == TemplateTail))
         return getStringOrTemplateToken('`', modifier, ttp);
 
     // This loop runs more than once only when whitespace or comments are
     // encountered.
     do {
-        if (MOZ_UNLIKELY(!sourceUnits.hasRawChars())) {
+        if (MOZ_UNLIKELY(sourceUnits.atEnd())) {
             anyCharsAccess().flags.isEOF = true;
             TokenStart start(sourceUnits, 0);
             newSimpleToken(TokenKind::Eof, start, modifier, ttp);
             return true;
         }
 
         int c = sourceUnits.getCodeUnit();
         MOZ_ASSERT(c != EOF);
@@ -1914,17 +1914,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
         //
         if (c1kind == String)
             return getStringOrTemplateToken(static_cast<char>(c), modifier, ttp);
 
         // Skip over EOL chars, updating line state along the way.
         //
         if (c1kind == EOL) {
             // If it's a \r\n sequence, consume it as a single EOL.
-            if (c == '\r' && sourceUnits.hasRawChars())
+            if (c == '\r' && !sourceUnits.atEnd())
                 sourceUnits.matchCodeUnit('\n');
 
             if (!updateLineInfoForEOL())
                 return badToken();
 
             anyCharsAccess().updateFlagsForEOL();
             continue;
         }
@@ -2302,17 +2302,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
     // one success-case.
     auto noteBadToken = MakeScopeExit([this]() {
         this->badToken();
     });
 
     auto ReportPrematureEndOfLiteral = [this, untilChar](unsigned errnum) {
         // Unicode separators aren't end-of-line in template or (as of
         // recently) string literals, so this assertion doesn't allow them.
-        MOZ_ASSERT(!this->sourceUnits.hasRawChars() ||
+        MOZ_ASSERT(this->sourceUnits.atEnd() ||
                    this->sourceUnits.peekCodeUnit() == '\r' ||
                    this->sourceUnits.peekCodeUnit() == '\n',
                    "must be parked at EOF or EOL to call this function");
 
         // The various errors reported here include language like "in a ''
         // literal" or similar, with '' being '', "", or `` as appropriate.
         const char delimiters[] = { untilChar, untilChar, '\0' };
 
@@ -2611,17 +2611,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
                 ReportPrematureEndOfLiteral(JSMSG_EOL_BEFORE_END_OF_STRING);
                 return false;
             }
 
             if (unit == '\r') {
                 unit = '\n';
 
                 // If it's a \r\n sequence: treat as a single EOL, skip over the \n.
-                if (sourceUnits.hasRawChars())
+                if (!sourceUnits.atEnd())
                     sourceUnits.matchCodeUnit('\n');
             }
 
             if (!updateLineInfoForEOL())
                 return false;
 
             anyCharsAccess().updateFlagsForEOL();
         } else if (parsingTemplate && unit == '$' && matchCodeUnit('{')) {
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -904,18 +904,19 @@ class SourceUnits
   public:
     SourceUnits(const CharT* buf, size_t length, size_t startOffset)
       : base_(buf),
         startOffset_(startOffset),
         limit_(buf + length),
         ptr(buf)
     { }
 
-    bool hasRawChars() const {
-        return ptr < limit_;
+    bool atEnd() const {
+        MOZ_ASSERT(ptr <= limit_, "shouldn't have overrun");
+        return ptr >= limit_;
     }
 
     bool atStart() const {
         return offset() == 0;
     }
 
     size_t startOffset() const {
         return startOffset_;
@@ -1052,27 +1053,27 @@ class TokenStreamCharsBase
     using SourceUnits = frontend::SourceUnits<CharT>;
 
     MOZ_MUST_USE bool appendCodePointToTokenbuf(uint32_t codePoint);
 
     // |expect| cannot be an EOL char.
     bool matchCodeUnit(int32_t expect) {
         MOZ_ASSERT(expect != EOF, "shouldn't be matching EOFs");
         MOZ_ASSERT(!SourceUnits::isRawEOLChar(expect));
-        return MOZ_LIKELY(sourceUnits.hasRawChars()) && sourceUnits.matchCodeUnit(expect);
+        return MOZ_LIKELY(!sourceUnits.atEnd()) && sourceUnits.matchCodeUnit(expect);
     }
 
   protected:
     int32_t peekCodeUnit() {
-        return MOZ_LIKELY(sourceUnits.hasRawChars()) ? sourceUnits.peekCodeUnit() : EOF;
+        return MOZ_LIKELY(!sourceUnits.atEnd()) ? sourceUnits.peekCodeUnit() : EOF;
     }
 
     void consumeKnownCodeUnit(int32_t unit) {
         MOZ_ASSERT(unit != EOF, "shouldn't be matching EOF");
-        MOZ_ASSERT(sourceUnits.hasRawChars(), "must have units to consume");
+        MOZ_ASSERT(!sourceUnits.atEnd(), "must have units to consume");
 #ifdef DEBUG
         CharT next =
 #endif
             sourceUnits.getCodeUnit();
         MOZ_ASSERT(next == unit, "must be consuming the correct unit");
     }
 
     MOZ_MUST_USE bool
@@ -1334,17 +1335,17 @@ class TokenStreamChars<char16_t, AnyChar
      */
     MOZ_MUST_USE bool getFullAsciiCodePoint(char16_t lead, int32_t* codePoint) {
         MOZ_ASSERT(isAsciiCodePoint(lead),
                    "non-ASCII code units must be handled separately");
         MOZ_ASSERT(lead == sourceUnits.previousCodeUnit(),
                    "getFullAsciiCodePoint called incorrectly");
 
         if (MOZ_UNLIKELY(lead == '\r')) {
-            if (MOZ_LIKELY(sourceUnits.hasRawChars()))
+            if (MOZ_LIKELY(!sourceUnits.atEnd()))
                 sourceUnits.matchCodeUnit('\n');
         } else if (MOZ_LIKELY(lead != '\n')) {
             *codePoint = lead;
             return true;
         }
 
         *codePoint = '\n';
         bool ok = updateLineInfoForEOL();
@@ -1857,17 +1858,17 @@ class MOZ_STACK_CLASS TokenStreamSpecifi
         if (!getChar(c))
             return false;
         ungetChar(*c);
         return true;
     }
 
     void skipChars(uint32_t n) {
         while (n-- > 0) {
-            MOZ_ASSERT(sourceUnits.hasRawChars());
+            MOZ_ASSERT(!sourceUnits.atEnd());
             mozilla::DebugOnly<int32_t> c = getCodeUnit();
             MOZ_ASSERT(!SourceUnits::isRawEOLChar(c));
         }
     }
 };
 
 // It's preferable to define this in TokenStream.cpp, but its template-ness
 // means we'd then have to *instantiate* this constructor for all possible