tor-browser

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

DefaultEmitter.cpp (1807B)


      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/DefaultEmitter.h"
      8 
      9 #include "mozilla/Assertions.h"  // MOZ_ASSERT
     10 
     11 #include "frontend/BytecodeEmitter.h"   // BytecodeEmitter
     12 #include "vm/ConstantCompareOperand.h"  // ConstantCompareOperand
     13 #include "vm/Opcodes.h"                 // JSOp
     14 
     15 using namespace js;
     16 using namespace js::frontend;
     17 
     18 using mozilla::Nothing;
     19 
     20 DefaultEmitter::DefaultEmitter(BytecodeEmitter* bce) : bce_(bce) {}
     21 
     22 bool DefaultEmitter::prepareForDefault() {
     23  MOZ_ASSERT(state_ == State::Start);
     24 
     25  //                [stack] VALUE
     26 
     27  ifUndefined_.emplace(bce_);
     28  if (!ifUndefined_->emitIf(Nothing())) {
     29    return false;
     30  }
     31 
     32  if (!bce_->emit1(JSOp::Dup)) {
     33    //              [stack] VALUE VALUE
     34    return false;
     35  }
     36 
     37  ConstantCompareOperand operand(
     38      ConstantCompareOperand::EncodedType::Undefined);
     39  if (!bce_->emitUint16Operand(JSOp::StrictConstantEq, operand.rawValue())) {
     40    //              [stack] VALUE EQ?
     41    return false;
     42  }
     43 
     44  if (!ifUndefined_->emitThen()) {
     45    //              [stack] VALUE
     46    return false;
     47  }
     48 
     49  if (!bce_->emit1(JSOp::Pop)) {
     50    //              [stack]
     51    return false;
     52  }
     53 
     54 #ifdef DEBUG
     55  state_ = State::Default;
     56 #endif
     57  return true;
     58 }
     59 
     60 bool DefaultEmitter::emitEnd() {
     61  MOZ_ASSERT(state_ == State::Default);
     62 
     63  //                [stack] DEFAULTVALUE
     64 
     65  if (!ifUndefined_->emitEnd()) {
     66    //              [stack] VALUE/DEFAULTVALUE
     67    return false;
     68  }
     69  ifUndefined_.reset();
     70 
     71 #ifdef DEBUG
     72  state_ = State::End;
     73 #endif
     74  return true;
     75 }