LabelEmitter.cpp (997B)
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/LabelEmitter.h" 8 9 #include "mozilla/Assertions.h" // MOZ_ASSERT 10 11 #include "frontend/BytecodeEmitter.h" // BytecodeEmitter 12 13 using namespace js; 14 using namespace js::frontend; 15 16 void LabelEmitter::emitLabel(TaggedParserAtomIndex name) { 17 MOZ_ASSERT(state_ == State::Start); 18 19 controlInfo_.emplace(bce_, name, bce_->bytecodeSection().offset()); 20 21 #ifdef DEBUG 22 state_ = State::Label; 23 #endif 24 } 25 26 bool LabelEmitter::emitEnd() { 27 MOZ_ASSERT(state_ == State::Label); 28 29 // Patch the break/continue to this label. 30 if (!controlInfo_->patchBreaks(bce_)) { 31 return false; 32 } 33 34 controlInfo_.reset(); 35 36 #ifdef DEBUG 37 state_ = State::End; 38 #endif 39 return true; 40 }