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
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
);
26 ifUndefined_
.emplace(bce_
);
27 if (!ifUndefined_
->emitIf(Nothing())) {
31 if (!bce_
->emit1(JSOp::Dup
)) {
32 // [stack] VALUE VALUE
35 if (!bce_
->emit1(JSOp::Undefined
)) {
36 // [stack] VALUE VALUE UNDEFINED
39 if (!bce_
->emit1(JSOp::StrictEq
)) {
44 if (!ifUndefined_
->emitThen()) {
49 if (!bce_
->emit1(JSOp::Pop
)) {
55 state_
= State::Default
;
60 bool DefaultEmitter::emitEnd() {
61 MOZ_ASSERT(state_
== State::Default
);
63 // [stack] DEFAULTVALUE
65 if (!ifUndefined_
->emitEnd()) {
66 // [stack] VALUE/DEFAULTVALUE