Debian Codegraph @

js/src/vm/EnvironmentObject-inl.h

raw
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/. */
6
7 #ifndef vm_EnvironmentObject_inl_h
8 #define vm_EnvironmentObject_inl_h
9
10 #include "vm/EnvironmentObject.h"
11
12 #include "vm/JSObject-inl.h"
13
14 namespace js {
15
16 inline ExtensibleLexicalEnvironmentObject&
17 NearestEnclosingExtensibleLexicalEnvironment(JSObject* env) {
18 MOZ_ASSERT(env);
19 while (!env->is<ExtensibleLexicalEnvironmentObject>()) {
20 env = env->enclosingEnvironment();
21 MOZ_ASSERT(env);
22 }
23 return env->as<ExtensibleLexicalEnvironmentObject>();
24 }
25
26 // Returns the innermost "qualified var object" on the environment chain.
27 // See the JSObject::isQualifiedVarObj comment for more info.
28 inline JSObject& GetVariablesObject(JSObject* envChain) {
29 while (!envChain->isQualifiedVarObj()) {
30 envChain = envChain->enclosingEnvironment();
31 }
32 MOZ_ASSERT(envChain);
33 return *envChain;
34 }
35
36 inline const Value& EnvironmentObject::aliasedBinding(
37 EnvironmentCoordinate ec) {
38 MOZ_ASSERT(!is<ExtensibleLexicalEnvironmentObject>());
39 MOZ_ASSERT(nonExtensibleIsFixedSlot(ec) ==
40 NativeObject::isFixedSlot(ec.slot()));
41 return getSlot(ec.slot());
42 }
43
44 inline void EnvironmentObject::setAliasedBinding(uint32_t slot,
45 const Value& v) {
46 setSlot(slot, v);
47 }
48
49 inline void EnvironmentObject::setAliasedBinding(EnvironmentCoordinate ec,
50 const Value& v) {
51 MOZ_ASSERT(!is<ExtensibleLexicalEnvironmentObject>());
52 MOZ_ASSERT(nonExtensibleIsFixedSlot(ec) ==
53 NativeObject::isFixedSlot(ec.slot()));
54 setAliasedBinding(ec.slot(), v);
55 }
56
57 inline void EnvironmentObject::setAliasedBinding(const BindingIter& bi,
58 const Value& v) {
59 MOZ_ASSERT(bi.location().kind() == BindingLocation::Kind::Environment);
60 setAliasedBinding(bi.location().slot(), v);
61 }
62
63 inline void CallObject::setAliasedFormalFromArguments(const Value& argsValue,
64 const Value& v) {
65 setSlot(ArgumentsObject::SlotFromMagicScopeSlotValue(argsValue), v);
66 }
67
68 } /* namespace js */
69
70 inline JSObject* JSObject::enclosingEnvironment() const {
71 if (is<js::EnvironmentObject>()) {
72 return &as<js::EnvironmentObject>().enclosingEnvironment();
73 }
74
75 if (is<js::DebugEnvironmentProxy>()) {
76 return &as<js::DebugEnvironmentProxy>().enclosingEnvironment();
77 }
78
79 if (is<js::GlobalObject>()) {
80 return nullptr;
81 }
82
83 MOZ_ASSERT_IF(is<JSFunction>(), as<JSFunction>().isInterpreted());
84 return &nonCCWGlobal();
85 }
86
87 #endif /* vm_EnvironmentObject_inl_h */