Bug 1460126 - Part 1: Make TryEmitter::Kind and TryEmitter::State enum classes. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Thu, 31 May 2018 15:15:50 +0900
changeset 420670 0ad0b4d1b0f34ca4a8059b2f814be317ea5865d5
parent 420669 0710b2d9b60efc8459449111bc2b511a83da50df
child 420671 e2aabb9c50162fc250cabbbfe9c6c69ecdede6b9
push id34077
push usernerli@mozilla.com
push dateThu, 31 May 2018 21:51:59 +0000
treeherdermozilla-central@42880a726964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1460126
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 1460126 - Part 1: Make TryEmitter::Kind and TryEmitter::State enum classes. r=jwalden
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -1502,46 +1502,46 @@ BytecodeEmitter::TDZCheckCache::noteTDZC
     return true;
 }
 
 // Class for emitting bytecode for blocks like try-catch-finally.
 //
 // Usage: (check for the return value is omitted for simplicity)
 //
 //   `try { try_block } catch (ex) { catch_block }`
-//     TryEmitter tryCatch(this, TryEmitter::TryCatch);
+//     TryEmitter tryCatch(this, TryEmitter::Kind::TryCatch);
 //     tryCatch.emitTry();
 //     emit(try_block);
 //     tryCatch.emitCatch();
 //     emit(ex and catch_block); // use JSOP_EXCEPTION to get exception
 //     tryCatch.emitEnd();
 //
 //   `try { try_block } finally { finally_block }`
-//     TryEmitter tryCatch(this, TryEmitter::TryFinally);
+//     TryEmitter tryCatch(this, TryEmitter::Kind::TryFinally);
 //     tryCatch.emitTry();
 //     emit(try_block);
 //     // finally_pos: The "{" character's position in the source code text.
 //     tryCatch.emitFinally(Some(finally_pos));
 //     emit(finally_block);
 //     tryCatch.emitEnd();
 //
 //   `try { try_block } catch (ex) {catch_block} finally { finally_block }`
-//     TryEmitter tryCatch(this, TryEmitter::TryCatchFinally);
+//     TryEmitter tryCatch(this, TryEmitter::Kind::TryCatchFinally);
 //     tryCatch.emitTry();
 //     emit(try_block);
 //     tryCatch.emitCatch();
 //     emit(ex and catch_block);
 //     tryCatch.emitFinally(Some(finally_pos));
 //     emit(finally_block);
 //     tryCatch.emitEnd();
 //
 class MOZ_STACK_CLASS TryEmitter
 {
   public:
-    enum Kind {
+    enum class Kind {
         TryCatch,
         TryCatchFinally,
         TryFinally
     };
 
     // Whether the catch and finally blocks handle the frame's return value.
     // If UseRetVal is specified, the bytecode marked with "*" are emitted
     // to clear return value with `undefined` before the catch block and the
@@ -1648,17 +1648,17 @@ class MOZ_STACK_CLASS TryEmitter
     // | Start |-------->| Try |-+---------->| Catch |-+->+--------->| End |
     // +-------+         +-----+ |           +-------+ |  ^          +-----+
     //                           |                     |  |
     //                           |  +------------------+  +----+
     //                           |  |                          |
     //                           |  v emitFinally +---------+  |
     //                           +->+------------>| Finally |--+
     //                                            +---------+
-    enum State {
+    enum class State {
         // The initial state.
         Start,
 
         // After calling emitTry.
         Try,
 
         // After calling emitCatch.
         Catch,
@@ -1667,48 +1667,48 @@ class MOZ_STACK_CLASS TryEmitter
         Finally,
 
         // After calling emitEnd.
         End
     };
     State state_;
 
     bool hasCatch() const {
-        return kind_ == TryCatch || kind_ == TryCatchFinally;
+        return kind_ == Kind::TryCatch || kind_ == Kind::TryCatchFinally;
     }
     bool hasFinally() const {
-        return kind_ == TryCatchFinally || kind_ == TryFinally;
+        return kind_ == Kind::TryCatchFinally || kind_ == Kind::TryFinally;
     }
 
   public:
     TryEmitter(BytecodeEmitter* bce, Kind kind, ShouldUseRetVal retValKind = UseRetVal,
                ShouldUseControl controlKind = UseControl)
       : bce_(bce),
         kind_(kind),
         retValKind_(retValKind),
         depth_(0),
         noteIndex_(0),
         tryStart_(0),
-        state_(Start)
+        state_(State::Start)
     {
         if (controlKind == UseControl)
             controlInfo_.emplace(bce_, hasFinally() ? StatementKind::Finally : StatementKind::Try);
         finallyStart_.offset = 0;
     }
 
     // Emits JSOP_GOTO to the end of try-catch-finally.
     // Used in `yield*`.
     bool emitJumpOverCatchAndFinally() {
         if (!bce_->emitJump(JSOP_GOTO, &catchAndFinallyJump_))
             return false;
         return true;
     }
 
     bool emitTry() {
-        MOZ_ASSERT(state_ == Start);
+        MOZ_ASSERT(state_ == State::Start);
 
         // Since an exception can be thrown at any place inside the try block,
         // we need to restore the stack and the scope chain before we transfer
         // the control to the exception handler.
         //
         // For that we store in a try note associated with the catch or
         // finally block the stack depth upon the try entry. The interpreter
         // uses this depth to properly unwind the stack and the scope chain.
@@ -1716,23 +1716,23 @@ class MOZ_STACK_CLASS TryEmitter
 
         // Record the try location, then emit the try block.
         if (!bce_->newSrcNote(SRC_TRY, &noteIndex_))
             return false;
         if (!bce_->emit1(JSOP_TRY))
             return false;
         tryStart_ = bce_->offset();
 
-        state_ = Try;
+        state_ = State::Try;
         return true;
     }
 
   private:
     bool emitTryEnd() {
-        MOZ_ASSERT(state_ == Try);
+        MOZ_ASSERT(state_ == State::Try);
         MOZ_ASSERT(depth_ == bce_->stackDepth);
 
         // GOSUB to finally, if present.
         if (hasFinally() && controlInfo_) {
             if (!bce_->emitJump(JSOP_GOSUB, &controlInfo_->gosubs))
                 return false;
         }
 
@@ -1747,40 +1747,40 @@ class MOZ_STACK_CLASS TryEmitter
         if (!bce_->emitJumpTarget(&tryEnd_))
             return false;
 
         return true;
     }
 
   public:
     bool emitCatch() {
-        MOZ_ASSERT(state_ == Try);
+        MOZ_ASSERT(state_ == State::Try);
         if (!emitTryEnd())
             return false;
 
         MOZ_ASSERT(bce_->stackDepth == depth_);
 
         if (retValKind_ == UseRetVal) {
             // Clear the frame's return value that might have been set by the
             // try block:
             //
             //   eval("try { 1; throw 2 } catch(e) {}"); // undefined, not 1
             if (!bce_->emit1(JSOP_UNDEFINED))
                 return false;
             if (!bce_->emit1(JSOP_SETRVAL))
                 return false;
         }
 
-        state_ = Catch;
+        state_ = State::Catch;
         return true;
     }
 
   private:
     bool emitCatchEnd() {
-        MOZ_ASSERT(state_ == Catch);
+        MOZ_ASSERT(state_ == State::Catch);
 
         if (!controlInfo_)
             return true;
 
         // gosub <finally>, if required.
         if (hasFinally()) {
             if (!bce_->emitJump(JSOP_GOSUB, &controlInfo_->gosubs))
                 return false;
@@ -1801,27 +1801,27 @@ class MOZ_STACK_CLASS TryEmitter
     // For non-syntactic try-catch-finally, `finallyPos` can be omitted.
     bool emitFinally(const Maybe<uint32_t>& finallyPos = Nothing()) {
         // If we are using controlInfo_ (i.e., emitting a syntactic try
         // blocks), we must have specified up front if there will be a finally
         // close. For internal try blocks, like those emitted for yield* and
         // IteratorClose inside for-of loops, we can emitFinally even without
         // specifying up front, since the internal try blocks emit no GOSUBs.
         if (!controlInfo_) {
-            if (kind_ == TryCatch)
-                kind_ = TryCatchFinally;
+            if (kind_ == Kind::TryCatch)
+                kind_ = Kind::TryCatchFinally;
         } else {
             MOZ_ASSERT(hasFinally());
         }
 
-        if (state_ == Try) {
+        if (state_ == State::Try) {
             if (!emitTryEnd())
                 return false;
         } else {
-            MOZ_ASSERT(state_ == Catch);
+            MOZ_ASSERT(state_ == State::Catch);
             if (!emitCatchEnd())
                 return false;
         }
 
         MOZ_ASSERT(bce_->stackDepth == depth_);
 
         if (!bce_->emitJumpTarget(&finallyStart_))
             return false;
@@ -1850,44 +1850,44 @@ class MOZ_STACK_CLASS TryEmitter
             //
             //   eval("x: try { 1 } finally { break x; }"); // undefined, not 1
             if (!bce_->emit1(JSOP_UNDEFINED))
                 return false;
             if (!bce_->emit1(JSOP_SETRVAL))
                 return false;
         }
 
-        state_ = Finally;
+        state_ = State::Finally;
         return true;
     }
 
   private:
     bool emitFinallyEnd() {
-        MOZ_ASSERT(state_ == Finally);
+        MOZ_ASSERT(state_ == State::Finally);
 
         if (retValKind_ == UseRetVal) {
             if (!bce_->emit1(JSOP_SETRVAL))
                 return false;
         }
 
         if (!bce_->emit1(JSOP_RETSUB))
             return false;
 
         bce_->hasTryFinally = true;
         return true;
     }
 
   public:
     bool emitEnd() {
-        if (state_ == Catch) {
+        if (state_ == State::Catch) {
             MOZ_ASSERT(!hasFinally());
             if (!emitCatchEnd())
                 return false;
         } else {
-            MOZ_ASSERT(state_ == Finally);
+            MOZ_ASSERT(state_ == State::Finally);
             MOZ_ASSERT(hasFinally());
             if (!emitFinallyEnd())
                 return false;
         }
 
         MOZ_ASSERT(bce_->stackDepth == depth_);
 
         // ReconstructPCStack needs a NOP here to mark the end of the last
@@ -1909,17 +1909,17 @@ class MOZ_STACK_CLASS TryEmitter
         // If we've got a finally, mark try+catch region with additional
         // trynote to catch exceptions (re)thrown from a catch block or
         // for the try{}finally{} case.
         if (hasFinally()) {
             if (!bce_->tryNoteList.append(JSTRY_FINALLY, depth_, tryStart_, finallyStart_.offset))
                 return false;
         }
 
-        state_ = End;
+        state_ = State::End;
         return true;
     }
 };
 
 // Class for emitting bytecode for blocks like if-then-else.
 //
 // This class can be used to emit single if-then-else block, or cascading
 // else-if blocks.
@@ -2258,17 +2258,17 @@ class ForOfLoopControl : public LoopCont
         iterDepth_(iterDepth),
         numYieldsAtBeginCodeNeedingIterClose_(UINT32_MAX),
         allowSelfHosted_(allowSelfHosted),
         iterKind_(iterKind)
     {
     }
 
     bool emitBeginCodeNeedingIteratorClose(BytecodeEmitter* bce) {
-        tryCatch_.emplace(bce, TryEmitter::TryCatch, TryEmitter::DontUseRetVal,
+        tryCatch_.emplace(bce, TryEmitter::Kind::TryCatch, TryEmitter::DontUseRetVal,
                           TryEmitter::DontUseControl);
 
         if (!tryCatch_->emitTry())
             return false;
 
         MOZ_ASSERT(numYieldsAtBeginCodeNeedingIterClose_ == UINT32_MAX);
         numYieldsAtBeginCodeNeedingIterClose_ = bce->yieldAndAwaitOffsetList.numYields;
 
@@ -5531,17 +5531,17 @@ BytecodeEmitter::emitIteratorCloseInScop
     // Call "return" if it is not undefined or null, and check that it returns
     // an Object.
     if (!emit1(JSOP_SWAP))                                // ... RET ITER
         return false;
 
     Maybe<TryEmitter> tryCatch;
 
     if (completionKind == CompletionKind::Throw) {
-        tryCatch.emplace(this, TryEmitter::TryCatch, TryEmitter::DontUseRetVal,
+        tryCatch.emplace(this, TryEmitter::Kind::TryCatch, TryEmitter::DontUseRetVal,
                          TryEmitter::DontUseControl);
 
         // Mutate stack to balance stack for try-catch.
         if (!emit1(JSOP_UNDEFINED))                       // ... RET ITER UNDEF
             return false;
         if (!tryCatch->emitTry())                         // ... RET ITER UNDEF
             return false;
         if (!emitDupAt(2))                                // ... RET ITER UNDEF RET
@@ -6860,22 +6860,22 @@ MOZ_NEVER_INLINE bool
 BytecodeEmitter::emitTry(ParseNode* pn)
 {
     ParseNode* catchScope = pn->pn_kid2;
     ParseNode* finallyNode = pn->pn_kid3;
 
     TryEmitter::Kind kind;
     if (catchScope) {
         if (finallyNode)
-            kind = TryEmitter::TryCatchFinally;
+            kind = TryEmitter::Kind::TryCatchFinally;
         else
-            kind = TryEmitter::TryCatch;
+            kind = TryEmitter::Kind::TryCatch;
     } else {
         MOZ_ASSERT(finallyNode);
-        kind = TryEmitter::TryFinally;
+        kind = TryEmitter::Kind::TryFinally;
     }
     TryEmitter tryCatch(this, kind);
 
     if (!tryCatch.emitTry())
         return false;
 
     if (!emitTree(pn->pn_kid1))
         return false;
@@ -8613,17 +8613,17 @@ BytecodeEmitter::emitYieldStar(ParseNode
     // Initial send value is undefined.
     if (!emit1(JSOP_UNDEFINED))                           // NEXT ITER RECEIVED
         return false;
 
     int32_t savedDepthTemp;
     int32_t startDepth = stackDepth;
     MOZ_ASSERT(startDepth >= 3);
 
-    TryEmitter tryCatch(this, TryEmitter::TryCatchFinally, TryEmitter::DontUseRetVal,
+    TryEmitter tryCatch(this, TryEmitter::Kind::TryCatchFinally, TryEmitter::DontUseRetVal,
                         TryEmitter::DontUseControl);
     if (!tryCatch.emitJumpOverCatchAndFinally())          // NEXT ITER RESULT
         return false;
 
     JumpTarget tryStart{ offset() };
     if (!tryCatch.emitTry())                              // NEXT ITER RESULT
         return false;