Bug 1185106 - Part 4: Add AutoAwaitIsKeyword class to set TokenStream.awaitIsKeyword. r=till
authorTooru Fujisawa <arai_a@mac.com>
Sun, 28 Aug 2016 20:42:39 +0900
changeset 346916 549055084ab012587dafa202e07888074071ce6b
parent 346915 86663fbc0899abb7782e39266df269df45eb0a21
child 346917 1557532c15d1d8642115d3f1c2ac1c4685c3a48f
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1185106
milestone52.0a1
Bug 1185106 - Part 4: Add AutoAwaitIsKeyword class to set TokenStream.awaitIsKeyword. r=till MozReview-Commit-ID: FeFWbzjrxYR
js/src/frontend/TokenStream.h
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -27,16 +27,18 @@
 #include "js/Vector.h"
 #include "vm/RegExpObject.h"
 
 struct KeywordInfo;
 
 namespace js {
 namespace frontend {
 
+class AutoAwaitIsKeyword;
+
 struct TokenPos {
     uint32_t    begin;  // Offset of the token's first char.
     uint32_t    end;    // Offset of 1 past the token's last char.
 
     TokenPos() {}
     TokenPos(uint32_t begin, uint32_t end) : begin(begin), end(end) {}
 
     // Return a TokenPos that covers left, right, and anything in between.
@@ -426,16 +428,17 @@ class MOZ_STACK_CLASS TokenStream
         bool hitOOM:1;          // Hit OOM.
 
         Flags()
           : isEOF(), isDirtyLine(), sawOctalEscape(), hadError(), hitOOM()
         {}
     };
 
     bool awaitIsKeyword = false;
+    friend class AutoAwaitIsKeyword;
 
   public:
     typedef Token::Modifier Modifier;
     static constexpr Modifier None = Token::None;
     static constexpr Modifier Operand = Token::Operand;
     static constexpr Modifier KeywordIsName = Token::KeywordIsName;
     static constexpr Modifier TemplateTail = Token::TemplateTail;
 
@@ -1012,16 +1015,35 @@ class MOZ_STACK_CLASS TokenStream
     UniqueTwoByteChars  sourceMapURL_;      // source map's filename or null
     CharBuffer          tokenbuf;           // current token string buffer
     uint8_t             isExprEnding[TOK_LIMIT];// which tokens definitely terminate exprs?
     ExclusiveContext*   const cx;
     bool                mutedErrors;
     StrictModeGetter*   strictModeGetter;  // used to test for strict mode
 };
 
+class MOZ_STACK_CLASS AutoAwaitIsKeyword
+{
+private:
+    TokenStream* ts_;
+    bool oldAwaitIsKeyword_;
+
+public:
+    AutoAwaitIsKeyword(TokenStream* ts, bool awaitIsKeyword) {
+        ts_ = ts;
+        oldAwaitIsKeyword_ = ts_->awaitIsKeyword;
+        ts_->awaitIsKeyword = awaitIsKeyword;
+    }
+
+    ~AutoAwaitIsKeyword() {
+        ts_->awaitIsKeyword = oldAwaitIsKeyword_;
+        ts_ = nullptr;
+    }
+};
+
 extern const char*
 TokenKindToDesc(TokenKind tt);
 
 } // namespace frontend
 } // namespace js
 
 extern JS_FRIEND_API(int)
 js_fgets(char* buf, int size, FILE* file);