Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / frontend / DoWhileEmitter.cpp
blobacdd8074b65a717d5310f0bcfca52f7f8af9ee15
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
13 using namespace js;
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)) {
23 return false;
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;
31 loopInfo_.emplace(bce_, StatementKind::DoLoop);
33 if (!loopInfo_->emitLoopHead(bce_, mozilla::Some(bodyPos))) {
34 return false;
37 #ifdef DEBUG
38 state_ = State::Body;
39 #endif
40 return true;
43 bool DoWhileEmitter::emitCond() {
44 MOZ_ASSERT(state_ == State::Body);
46 if (!loopInfo_->emitContinueTarget(bce_)) {
47 return false;
50 #ifdef DEBUG
51 state_ = State::Cond;
52 #endif
53 return true;
56 bool DoWhileEmitter::emitEnd() {
57 MOZ_ASSERT(state_ == State::Cond);
59 if (!loopInfo_->emitLoopEnd(bce_, JSOp::JumpIfTrue, TryNoteKind::Loop)) {
60 return false;
63 loopInfo_.reset();
65 #ifdef DEBUG
66 state_ = State::End;
67 #endif
68 return true;