Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / jit / BaselineFrame-inl.h
blob4c203bc579d071f77768505004f8f2f64643e460
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 #ifndef jit_BaselineFrame_inl_h
8 #define jit_BaselineFrame_inl_h
10 #include "jit/BaselineFrame.h"
12 #include "jit/TrialInlining.h"
13 #include "jit/VMFunctions.h"
14 #include "vm/JSContext.h"
15 #include "vm/Realm.h"
17 #include "vm/EnvironmentObject-inl.h"
18 #include "vm/JSScript-inl.h"
19 #include "vm/NativeObject-inl.h" // js::NativeObject::initDenseElementsFromRange
21 namespace js {
22 namespace jit {
24 template <typename SpecificEnvironment>
25 inline void BaselineFrame::pushOnEnvironmentChain(SpecificEnvironment& env) {
26 MOZ_ASSERT(*environmentChain() == env.enclosingEnvironment());
27 envChain_ = &env;
28 if (IsFrameInitialEnvironment(this, env)) {
29 flags_ |= HAS_INITIAL_ENV;
33 template <typename SpecificEnvironment>
34 inline void BaselineFrame::popOffEnvironmentChain() {
35 MOZ_ASSERT(envChain_->is<SpecificEnvironment>());
36 envChain_ = &envChain_->as<SpecificEnvironment>().enclosingEnvironment();
39 inline void BaselineFrame::replaceInnermostEnvironment(EnvironmentObject& env) {
40 MOZ_ASSERT(env.enclosingEnvironment() ==
41 envChain_->as<EnvironmentObject>().enclosingEnvironment());
42 envChain_ = &env;
45 inline bool BaselineFrame::saveGeneratorSlots(JSContext* cx, unsigned nslots,
46 ArrayObject* dest) const {
47 // By convention, generator slots are stored in interpreter order,
48 // which is the reverse of BaselineFrame order.
50 MOZ_ASSERT(nslots == numValueSlots(debugFrameSize()) - 1);
51 const Value* end = reinterpret_cast<const Value*>(this);
52 mozilla::Span<const Value> span{end - nslots, end};
53 return dest->initDenseElementsFromRange(cx, span.rbegin(), span.rend());
56 inline bool BaselineFrame::pushLexicalEnvironment(JSContext* cx,
57 Handle<LexicalScope*> scope) {
58 BlockLexicalEnvironmentObject* env =
59 BlockLexicalEnvironmentObject::createForFrame(cx, scope, this);
60 if (!env) {
61 return false;
63 pushOnEnvironmentChain(*env);
65 return true;
68 inline bool BaselineFrame::pushClassBodyEnvironment(
69 JSContext* cx, Handle<ClassBodyScope*> scope) {
70 ClassBodyLexicalEnvironmentObject* env =
71 ClassBodyLexicalEnvironmentObject::createForFrame(cx, scope, this);
72 if (!env) {
73 return false;
75 pushOnEnvironmentChain(*env);
77 return true;
80 template <bool IsDebuggee>
81 inline bool BaselineFrame::freshenLexicalEnvironment(JSContext* cx,
82 const jsbytecode* pc) {
83 Rooted<BlockLexicalEnvironmentObject*> current(
84 cx, &envChain_->as<BlockLexicalEnvironmentObject>());
85 BlockLexicalEnvironmentObject* clone =
86 BlockLexicalEnvironmentObject::clone(cx, current);
87 if (!clone) {
88 return false;
91 if constexpr (IsDebuggee) {
92 MOZ_ASSERT(pc);
93 Rooted<BlockLexicalEnvironmentObject*> cloneRoot(cx, clone);
94 MOZ_ALWAYS_TRUE(DebugLeaveLexicalEnv(cx, this, pc));
95 clone = cloneRoot;
98 replaceInnermostEnvironment(*clone);
99 return true;
102 template <bool IsDebuggee>
103 inline bool BaselineFrame::recreateLexicalEnvironment(JSContext* cx,
104 const jsbytecode* pc) {
105 Rooted<BlockLexicalEnvironmentObject*> current(
106 cx, &envChain_->as<BlockLexicalEnvironmentObject>());
107 BlockLexicalEnvironmentObject* clone =
108 BlockLexicalEnvironmentObject::recreate(cx, current);
109 if (!clone) {
110 return false;
113 if constexpr (IsDebuggee) {
114 MOZ_ASSERT(pc);
115 Rooted<BlockLexicalEnvironmentObject*> cloneRoot(cx, clone);
116 MOZ_ALWAYS_TRUE(DebugLeaveLexicalEnv(cx, this, pc));
117 clone = cloneRoot;
120 replaceInnermostEnvironment(*clone);
121 return true;
124 inline CallObject& BaselineFrame::callObj() const {
125 MOZ_ASSERT(hasInitialEnvironment());
126 MOZ_ASSERT(callee()->needsCallObject());
128 JSObject* obj = environmentChain();
129 while (!obj->is<CallObject>()) {
130 obj = obj->enclosingEnvironment();
132 return obj->as<CallObject>();
135 inline JSScript* BaselineFrame::outerScript() const {
136 if (!icScript()->isInlined()) {
137 return script();
139 return icScript()->inliningRoot()->owningScript();
142 inline void BaselineFrame::unsetIsDebuggee() {
143 MOZ_ASSERT(!script()->isDebuggee());
144 flags_ &= ~DEBUGGEE;
147 } // namespace jit
148 } // namespace js
150 #endif /* jit_BaselineFrame_inl_h */