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/. */
7 #include "frontend/DoWhileEmitter.h"
9 #include "frontend/BytecodeEmitter.h"
10 #include "vm/Opcodes.h"
11 #include "vm/StencilEnums.h" // TryNoteKind
14 using namespace js::frontend
;
16 DoWhileEmitter::DoWhileEmitter(BytecodeEmitter
* bce
) : bce_(bce
) {}
18 bool DoWhileEmitter::emitBody(uint32_t doPos
, uint32_t bodyPos
) {
19 MOZ_ASSERT(state_
== State::Start
);
21 // Ensure that the column of the 'do' is set properly.
22 if (!bce_
->updateSourceCoordNotes(doPos
)) {
26 // We need a nop here to make it possible to set a breakpoint on `do`.
27 if (!bce_
->emit1(JSOp::Nop
)) {
31 loopInfo_
.emplace(bce_
, StatementKind::DoLoop
);
33 if (!loopInfo_
->emitLoopHead(bce_
, mozilla::Some(bodyPos
))) {
43 bool DoWhileEmitter::emitCond() {
44 MOZ_ASSERT(state_
== State::Body
);
46 if (!loopInfo_
->emitContinueTarget(bce_
)) {
56 bool DoWhileEmitter::emitEnd() {
57 MOZ_ASSERT(state_
== State::Cond
);
59 if (!loopInfo_
->emitLoopEnd(bce_
, JSOp::JumpIfTrue
, TryNoteKind::Loop
)) {