Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / frontend / ExpressionStatementEmitter.cpp
blobbb00c831b13653728e2745bf06ebb7fdee89de09
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/ExpressionStatementEmitter.h"
9 #include "frontend/BytecodeEmitter.h"
10 #include "vm/Opcodes.h"
12 using namespace js;
13 using namespace js::frontend;
15 using mozilla::Maybe;
17 ExpressionStatementEmitter::ExpressionStatementEmitter(BytecodeEmitter* bce,
18 ValueUsage valueUsage)
19 : bce_(bce), valueUsage_(valueUsage) {}
21 bool ExpressionStatementEmitter::prepareForExpr(uint32_t beginPos) {
22 MOZ_ASSERT(state_ == State::Start);
24 if (!bce_->updateSourceCoordNotes(beginPos)) {
25 return false;
28 #ifdef DEBUG
29 depth_ = bce_->bytecodeSection().stackDepth();
30 state_ = State::Expr;
31 #endif
32 return true;
35 bool ExpressionStatementEmitter::emitEnd() {
36 MOZ_ASSERT(state_ == State::Expr);
37 MOZ_ASSERT(bce_->bytecodeSection().stackDepth() == depth_ + 1);
39 // [stack] VAL
41 JSOp op = valueUsage_ == ValueUsage::WantValue ? JSOp::SetRval : JSOp::Pop;
42 if (!bce_->emit1(op)) {
43 // [stack] # if WantValue
44 // [stack] VAL
45 // [stack] # otherwise
46 // [stack]
47 return false;
50 #ifdef DEBUG
51 state_ = State::End;
52 #endif
53 return true;