js/src/vm/ScopeObject-inl.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:282c20d5a9b3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
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_ScopeObject_inl_h
8 #define vm_ScopeObject_inl_h
9
10 #include "vm/ScopeObject.h"
11
12 #include "jsinferinlines.h"
13
14 namespace js {
15
16 inline void
17 ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v)
18 {
19 JS_ASSERT(is<CallObject>() || is<ClonedBlockObject>());
20 JS_STATIC_ASSERT(CallObject::RESERVED_SLOTS == BlockObject::RESERVED_SLOTS);
21
22 setSlot(sc.slot(), v);
23
24 // name may be null if we don't need to track side effects on the object.
25 if (hasSingletonType() && !hasLazyType()) {
26 JS_ASSERT(name);
27 types::AddTypePropertyId(cx, this, NameToId(name), v);
28 }
29 }
30
31 inline void
32 CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v)
33 {
34 JS_ASSERT(name == fi->name());
35 setSlot(fi.scopeSlot(), v);
36 if (hasSingletonType())
37 types::AddTypePropertyId(cx, this, NameToId(name), v);
38 }
39
40 inline void
41 CallObject::setAliasedVarFromArguments(JSContext *cx, const Value &argsValue, jsid id, const Value &v)
42 {
43 setSlot(argsValue.magicUint32(), v);
44 if (hasSingletonType())
45 types::AddTypePropertyId(cx, this, id, v);
46 }
47
48 template <AllowGC allowGC>
49 inline bool
50 StaticScopeIter<allowGC>::done() const
51 {
52 return !obj;
53 }
54
55 template <AllowGC allowGC>
56 inline void
57 StaticScopeIter<allowGC>::operator++(int)
58 {
59 if (obj->template is<NestedScopeObject>()) {
60 obj = obj->template as<NestedScopeObject>().enclosingScopeForStaticScopeIter();
61 } else if (onNamedLambda || !obj->template as<JSFunction>().isNamedLambda()) {
62 onNamedLambda = false;
63 obj = obj->template as<JSFunction>().nonLazyScript()->enclosingStaticScope();
64 } else {
65 onNamedLambda = true;
66 }
67 JS_ASSERT_IF(obj, obj->template is<NestedScopeObject>() || obj->template is<JSFunction>());
68 JS_ASSERT_IF(onNamedLambda, obj->template is<JSFunction>());
69 }
70
71 template <AllowGC allowGC>
72 inline bool
73 StaticScopeIter<allowGC>::hasDynamicScopeObject() const
74 {
75 return obj->template is<StaticBlockObject>()
76 ? obj->template as<StaticBlockObject>().needsClone()
77 : (obj->template is<StaticWithObject>() ||
78 obj->template as<JSFunction>().isHeavyweight());
79 }
80
81 template <AllowGC allowGC>
82 inline Shape *
83 StaticScopeIter<allowGC>::scopeShape() const
84 {
85 JS_ASSERT(hasDynamicScopeObject());
86 JS_ASSERT(type() != NAMED_LAMBDA);
87 if (type() == BLOCK)
88 return block().lastProperty();
89 return funScript()->callObjShape();
90 }
91
92 template <AllowGC allowGC>
93 inline typename StaticScopeIter<allowGC>::Type
94 StaticScopeIter<allowGC>::type() const
95 {
96 if (onNamedLambda)
97 return NAMED_LAMBDA;
98 return obj->template is<StaticBlockObject>()
99 ? BLOCK
100 : (obj->template is<StaticWithObject>() ? WITH : FUNCTION);
101 }
102
103 template <AllowGC allowGC>
104 inline StaticBlockObject &
105 StaticScopeIter<allowGC>::block() const
106 {
107 JS_ASSERT(type() == BLOCK);
108 return obj->template as<StaticBlockObject>();
109 }
110
111 template <AllowGC allowGC>
112 inline StaticWithObject &
113 StaticScopeIter<allowGC>::staticWith() const
114 {
115 JS_ASSERT(type() == WITH);
116 return obj->template as<StaticWithObject>();
117 }
118
119 template <AllowGC allowGC>
120 inline JSScript *
121 StaticScopeIter<allowGC>::funScript() const
122 {
123 JS_ASSERT(type() == FUNCTION);
124 return obj->template as<JSFunction>().nonLazyScript();
125 }
126
127 } /* namespace js */
128
129 #endif /* vm_ScopeObject_inl_h */

mercurial