tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DoWhileEmitter.cpp (1602B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "frontend/DoWhileEmitter.h"
      8 
      9 #include "frontend/BytecodeEmitter.h"
     10 #include "vm/Opcodes.h"
     11 #include "vm/StencilEnums.h"  // TryNoteKind
     12 
     13 using namespace js;
     14 using namespace js::frontend;
     15 
     16 DoWhileEmitter::DoWhileEmitter(BytecodeEmitter* bce) : bce_(bce) {}
     17 
     18 bool DoWhileEmitter::emitBody(uint32_t doPos, uint32_t bodyPos) {
     19  MOZ_ASSERT(state_ == State::Start);
     20 
     21  // Ensure that the column of the 'do' is set properly.
     22  if (!bce_->updateSourceCoordNotes(doPos)) {
     23    return false;
     24  }
     25 
     26  // We need a nop here to make it possible to set a breakpoint on `do`.
     27  if (!bce_->emit1(JSOp::Nop)) {
     28    return false;
     29  }
     30 
     31  loopInfo_.emplace(bce_, StatementKind::DoLoop);
     32 
     33  if (!loopInfo_->emitLoopHead(bce_, mozilla::Some(bodyPos))) {
     34    return false;
     35  }
     36 
     37 #ifdef DEBUG
     38  state_ = State::Body;
     39 #endif
     40  return true;
     41 }
     42 
     43 bool DoWhileEmitter::emitCond() {
     44  MOZ_ASSERT(state_ == State::Body);
     45 
     46  if (!loopInfo_->emitContinueTarget(bce_)) {
     47    return false;
     48  }
     49 
     50 #ifdef DEBUG
     51  state_ = State::Cond;
     52 #endif
     53  return true;
     54 }
     55 
     56 bool DoWhileEmitter::emitEnd() {
     57  MOZ_ASSERT(state_ == State::Cond);
     58 
     59  if (!loopInfo_->emitLoopEnd(bce_, JSOp::JumpIfTrue, TryNoteKind::Loop)) {
     60    return false;
     61  }
     62 
     63  loopInfo_.reset();
     64 
     65 #ifdef DEBUG
     66  state_ = State::End;
     67 #endif
     68  return true;
     69 }