Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / frontend / DefaultEmitter.cpp
blob1377e4b7adec01b611a5c0f674b694fe08792fad
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/DefaultEmitter.h"
9 #include "mozilla/Assertions.h" // MOZ_ASSERT
11 #include "frontend/BytecodeEmitter.h" // BytecodeEmitter
12 #include "vm/Opcodes.h" // JSOp
14 using namespace js;
15 using namespace js::frontend;
17 using mozilla::Nothing;
19 DefaultEmitter::DefaultEmitter(BytecodeEmitter* bce) : bce_(bce) {}
21 bool DefaultEmitter::prepareForDefault() {
22 MOZ_ASSERT(state_ == State::Start);
24 // [stack] VALUE
26 ifUndefined_.emplace(bce_);
27 if (!ifUndefined_->emitIf(Nothing())) {
28 return false;
31 if (!bce_->emit1(JSOp::Dup)) {
32 // [stack] VALUE VALUE
33 return false;
35 if (!bce_->emit1(JSOp::Undefined)) {
36 // [stack] VALUE VALUE UNDEFINED
37 return false;
39 if (!bce_->emit1(JSOp::StrictEq)) {
40 // [stack] VALUE EQ?
41 return false;
44 if (!ifUndefined_->emitThen()) {
45 // [stack] VALUE
46 return false;
49 if (!bce_->emit1(JSOp::Pop)) {
50 // [stack]
51 return false;
54 #ifdef DEBUG
55 state_ = State::Default;
56 #endif
57 return true;
60 bool DefaultEmitter::emitEnd() {
61 MOZ_ASSERT(state_ == State::Default);
63 // [stack] DEFAULTVALUE
65 if (!ifUndefined_->emitEnd()) {
66 // [stack] VALUE/DEFAULTVALUE
67 return false;
69 ifUndefined_.reset();
71 #ifdef DEBUG
72 state_ = State::End;
73 #endif
74 return true;