]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
f9bf01c6 | 2 | * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. |
9dae56ea A |
3 | * |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Library General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Library General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Library General Public License | |
15 | * along with this library; see the file COPYING.LIB. If not, write to | |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 | * Boston, MA 02110-1301, USA. | |
18 | * | |
19 | */ | |
20 | ||
21 | #ifndef ScopeChain_h | |
22 | #define ScopeChain_h | |
23 | ||
14957cd0 A |
24 | #include "JSCell.h" |
25 | #include "Structure.h" | |
26 | #include <wtf/FastAllocBase.h> | |
9dae56ea A |
27 | |
28 | namespace JSC { | |
29 | ||
30 | class JSGlobalData; | |
31 | class JSGlobalObject; | |
32 | class JSObject; | |
f9bf01c6 | 33 | class MarkStack; |
9dae56ea | 34 | class ScopeChainIterator; |
14957cd0 | 35 | typedef MarkStack SlotVisitor; |
9dae56ea | 36 | |
14957cd0 | 37 | class ScopeChainNode : public JSCell { |
9dae56ea | 38 | public: |
f9bf01c6 | 39 | ScopeChainNode(ScopeChainNode* next, JSObject* object, JSGlobalData* globalData, JSGlobalObject* globalObject, JSObject* globalThis) |
14957cd0 | 40 | : JSCell(*globalData, globalData->scopeChainNodeStructure.get()) |
9dae56ea | 41 | , globalData(globalData) |
14957cd0 A |
42 | , next(*globalData, this, next, WriteBarrier<ScopeChainNode>::MayBeNull) |
43 | , object(*globalData, this, object) | |
44 | , globalObject(*globalData, this, globalObject) | |
45 | , globalThis(*globalData, this, globalThis) | |
9dae56ea A |
46 | { |
47 | ASSERT(globalData); | |
f9bf01c6 | 48 | ASSERT(globalObject); |
9dae56ea A |
49 | } |
50 | ||
9dae56ea | 51 | JSGlobalData* globalData; |
14957cd0 A |
52 | WriteBarrier<ScopeChainNode> next; |
53 | WriteBarrier<JSObject> object; | |
54 | WriteBarrier<JSGlobalObject> globalObject; | |
55 | WriteBarrier<JSObject> globalThis; | |
9dae56ea A |
56 | |
57 | ScopeChainNode* push(JSObject*); | |
58 | ScopeChainNode* pop(); | |
59 | ||
14957cd0 A |
60 | ScopeChainIterator begin(); |
61 | ScopeChainIterator end(); | |
62 | ||
63 | int localDepth(); | |
9dae56ea | 64 | |
9dae56ea | 65 | #ifndef NDEBUG |
14957cd0 | 66 | void print(); |
9dae56ea | 67 | #endif |
14957cd0 A |
68 | |
69 | static Structure* createStructure(JSGlobalData& globalData, JSValue proto) { return Structure::create(globalData, proto, TypeInfo(CompoundType, StructureFlags), AnonymousSlotCount, &s_info); } | |
70 | virtual void visitChildren(SlotVisitor&); | |
71 | static JS_EXPORTDATA const ClassInfo s_info; | |
72 | ||
73 | private: | |
74 | static const unsigned StructureFlags = OverridesVisitChildren; | |
9dae56ea A |
75 | }; |
76 | ||
77 | inline ScopeChainNode* ScopeChainNode::push(JSObject* o) | |
78 | { | |
79 | ASSERT(o); | |
14957cd0 | 80 | return new (globalData) ScopeChainNode(this, o, globalData, globalObject.get(), globalThis.get()); |
9dae56ea A |
81 | } |
82 | ||
83 | inline ScopeChainNode* ScopeChainNode::pop() | |
84 | { | |
85 | ASSERT(next); | |
14957cd0 | 86 | return next.get(); |
9dae56ea A |
87 | } |
88 | ||
89 | class ScopeChainIterator { | |
90 | public: | |
14957cd0 | 91 | ScopeChainIterator(ScopeChainNode* node) |
9dae56ea A |
92 | : m_node(node) |
93 | { | |
94 | } | |
95 | ||
14957cd0 A |
96 | WriteBarrier<JSObject> const & operator*() const { return m_node->object; } |
97 | WriteBarrier<JSObject> const * operator->() const { return &(operator*()); } | |
9dae56ea | 98 | |
14957cd0 | 99 | ScopeChainIterator& operator++() { m_node = m_node->next.get(); return *this; } |
9dae56ea A |
100 | |
101 | // postfix ++ intentionally omitted | |
102 | ||
103 | bool operator==(const ScopeChainIterator& other) const { return m_node == other.m_node; } | |
104 | bool operator!=(const ScopeChainIterator& other) const { return m_node != other.m_node; } | |
105 | ||
106 | private: | |
14957cd0 | 107 | ScopeChainNode* m_node; |
9dae56ea A |
108 | }; |
109 | ||
14957cd0 | 110 | inline ScopeChainIterator ScopeChainNode::begin() |
9dae56ea A |
111 | { |
112 | return ScopeChainIterator(this); | |
113 | } | |
114 | ||
14957cd0 | 115 | inline ScopeChainIterator ScopeChainNode::end() |
9dae56ea A |
116 | { |
117 | return ScopeChainIterator(0); | |
118 | } | |
119 | ||
14957cd0 | 120 | ALWAYS_INLINE JSGlobalData& ExecState::globalData() const |
9dae56ea | 121 | { |
14957cd0 A |
122 | ASSERT(scopeChain()->globalData); |
123 | return *scopeChain()->globalData; | |
9dae56ea A |
124 | } |
125 | ||
14957cd0 A |
126 | ALWAYS_INLINE JSGlobalObject* ExecState::lexicalGlobalObject() const |
127 | { | |
128 | return scopeChain()->globalObject.get(); | |
129 | } | |
130 | ||
131 | ALWAYS_INLINE JSObject* ExecState::globalThisValue() const | |
132 | { | |
133 | return scopeChain()->globalThis.get(); | |
134 | } | |
135 | ||
136 | ALWAYS_INLINE ScopeChainNode* Register::scopeChain() const | |
137 | { | |
138 | return static_cast<ScopeChainNode*>(jsValue().asCell()); | |
139 | } | |
140 | ||
141 | ALWAYS_INLINE Register& Register::operator=(ScopeChainNode* scopeChain) | |
9dae56ea | 142 | { |
14957cd0 | 143 | *this = JSValue(scopeChain); |
9dae56ea A |
144 | return *this; |
145 | } | |
146 | ||
147 | } // namespace JSC | |
148 | ||
149 | #endif // ScopeChain_h |