LexicalScopeEmitter.cpp (1653B)
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/LexicalScopeEmitter.h" 8 9 using namespace js; 10 using namespace js::frontend; 11 12 LexicalScopeEmitter::LexicalScopeEmitter(BytecodeEmitter* bce) : bce_(bce) {} 13 14 bool LexicalScopeEmitter::emitScope(ScopeKind kind, 15 LexicalScope::ParserData* bindings 16 #ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT 17 , 18 BlockKind blockKind 19 #endif 20 ) { 21 MOZ_ASSERT(state_ == State::Start); 22 MOZ_ASSERT(bindings); 23 24 tdzCache_.emplace(bce_); 25 emitterScope_.emplace(bce_); 26 if (!emitterScope_->enterLexical(bce_, kind, bindings 27 #ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT 28 , 29 blockKind 30 #endif 31 )) { 32 return false; 33 } 34 35 #ifdef DEBUG 36 state_ = State::Scope; 37 #endif 38 return true; 39 } 40 41 bool LexicalScopeEmitter::emitEmptyScope() { 42 MOZ_ASSERT(state_ == State::Start); 43 44 tdzCache_.emplace(bce_); 45 46 #ifdef DEBUG 47 state_ = State::Scope; 48 #endif 49 return true; 50 } 51 52 bool LexicalScopeEmitter::emitEnd() { 53 MOZ_ASSERT(state_ == State::Scope); 54 55 if (emitterScope_) { 56 if (!emitterScope_->leave(bce_)) { 57 return false; 58 } 59 emitterScope_.reset(); 60 } 61 tdzCache_.reset(); 62 63 #ifdef DEBUG 64 state_ = State::End; 65 #endif 66 return true; 67 }