source: webkit/trunk/JavaScriptCore/runtime/ScopeChain.h@ 38137

Last change on this file since 38137 was 38087, checked in by [email protected], 17 years ago

2008-11-03 Cameron Zwarich <[email protected]>

Rubber-stamped by Maciej Stachowiak.

Move more files into the runtime subdirectory of JavaScriptCore.

JavaScriptCore:

  • API/JSBase.cpp:
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackFunction.cpp:
  • API/JSClassRef.cpp:
  • API/OpaqueJSString.cpp:
  • GNUmakefile.am:
  • JavaScriptCore.pri:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • kjs/AllInOneFile.cpp:
  • kjs/ArgList.cpp: Removed.
  • kjs/ArgList.h: Removed.
  • kjs/Arguments.cpp: Removed.
  • kjs/Arguments.h: Removed.
  • kjs/BatchedTransitionOptimizer.h: Removed.
  • kjs/CollectorHeapIterator.h: Removed.
  • kjs/CommonIdentifiers.cpp: Removed.
  • kjs/CommonIdentifiers.h: Removed.
  • kjs/ExecState.cpp: Removed.
  • kjs/ExecState.h: Removed.
  • kjs/GetterSetter.cpp: Removed.
  • kjs/GetterSetter.h: Removed.
  • kjs/InitializeThreading.cpp: Removed.
  • kjs/InitializeThreading.h: Removed.
  • kjs/JSActivation.cpp: Removed.
  • kjs/JSActivation.h: Removed.
  • kjs/JSGlobalData.cpp: Removed.
  • kjs/JSGlobalData.h: Removed.
  • kjs/JSLock.cpp: Removed.
  • kjs/JSLock.h: Removed.
  • kjs/JSStaticScopeObject.cpp: Removed.
  • kjs/JSStaticScopeObject.h: Removed.
  • kjs/JSType.h: Removed.
  • kjs/PropertyNameArray.cpp: Removed.
  • kjs/PropertyNameArray.h: Removed.
  • kjs/ScopeChain.cpp: Removed.
  • kjs/ScopeChain.h: Removed.
  • kjs/ScopeChainMark.h: Removed.
  • kjs/SymbolTable.h: Removed.
  • kjs/Tracing.d: Removed.
  • kjs/Tracing.h: Removed.
  • runtime/ArgList.cpp: Copied from kjs/ArgList.cpp.
  • runtime/ArgList.h: Copied from kjs/ArgList.h.
  • runtime/Arguments.cpp: Copied from kjs/Arguments.cpp.
  • runtime/Arguments.h: Copied from kjs/Arguments.h.
  • runtime/BatchedTransitionOptimizer.h: Copied from kjs/BatchedTransitionOptimizer.h.
  • runtime/CollectorHeapIterator.h: Copied from kjs/CollectorHeapIterator.h.
  • runtime/CommonIdentifiers.cpp: Copied from kjs/CommonIdentifiers.cpp.
  • runtime/CommonIdentifiers.h: Copied from kjs/CommonIdentifiers.h.
  • runtime/ExecState.cpp: Copied from kjs/ExecState.cpp.
  • runtime/ExecState.h: Copied from kjs/ExecState.h.
  • runtime/GetterSetter.cpp: Copied from kjs/GetterSetter.cpp.
  • runtime/GetterSetter.h: Copied from kjs/GetterSetter.h.
  • runtime/InitializeThreading.cpp: Copied from kjs/InitializeThreading.cpp.
  • runtime/InitializeThreading.h: Copied from kjs/InitializeThreading.h.
  • runtime/JSActivation.cpp: Copied from kjs/JSActivation.cpp.
  • runtime/JSActivation.h: Copied from kjs/JSActivation.h.
  • runtime/JSGlobalData.cpp: Copied from kjs/JSGlobalData.cpp.
  • runtime/JSGlobalData.h: Copied from kjs/JSGlobalData.h.
  • runtime/JSLock.cpp: Copied from kjs/JSLock.cpp.
  • runtime/JSLock.h: Copied from kjs/JSLock.h.
  • runtime/JSStaticScopeObject.cpp: Copied from kjs/JSStaticScopeObject.cpp.
  • runtime/JSStaticScopeObject.h: Copied from kjs/JSStaticScopeObject.h.
  • runtime/JSType.h: Copied from kjs/JSType.h.
  • runtime/PropertyNameArray.cpp: Copied from kjs/PropertyNameArray.cpp.
  • runtime/PropertyNameArray.h: Copied from kjs/PropertyNameArray.h.
  • runtime/ScopeChain.cpp: Copied from kjs/ScopeChain.cpp.
  • runtime/ScopeChain.h: Copied from kjs/ScopeChain.h.
  • runtime/ScopeChainMark.h: Copied from kjs/ScopeChainMark.h.
  • runtime/SymbolTable.h: Copied from kjs/SymbolTable.h.
  • runtime/Tracing.d: Copied from kjs/Tracing.d.
  • runtime/Tracing.h: Copied from kjs/Tracing.h.

WebCore:

  • ForwardingHeaders/kjs/ArgList.h: Removed.
  • ForwardingHeaders/kjs/CollectorHeapIterator.h: Removed.
  • ForwardingHeaders/kjs/ExecState.h: Removed.
  • ForwardingHeaders/kjs/InitializeThreading.h: Removed.
  • ForwardingHeaders/kjs/JSGlobalData.h: Removed.
  • ForwardingHeaders/kjs/JSLock.h: Removed.
  • ForwardingHeaders/kjs/SymbolTable.h: Removed.
  • ForwardingHeaders/runtime/ArgList.h: Copied from ForwardingHeaders/kjs/ArgList.h.
  • ForwardingHeaders/runtime/CollectorHeapIterator.h: Copied from ForwardingHeaders/kjs/CollectorHeapIterator.h.
  • ForwardingHeaders/runtime/ExecState.h: Copied from ForwardingHeaders/kjs/ExecState.h.
  • ForwardingHeaders/runtime/InitializeThreading.h: Copied from ForwardingHeaders/kjs/InitializeThreading.h.
  • ForwardingHeaders/runtime/JSGlobalData.h: Copied from ForwardingHeaders/kjs/JSGlobalData.h.
  • ForwardingHeaders/runtime/JSLock.h: Copied from ForwardingHeaders/kjs/JSLock.h.
  • ForwardingHeaders/runtime/SymbolTable.h: Copied from ForwardingHeaders/kjs/SymbolTable.h.
  • bindings/js/GCController.cpp:
  • bindings/js/JSCustomPositionCallback.cpp:
  • bindings/js/JSCustomPositionErrorCallback.cpp:
  • bindings/js/JSCustomSQLStatementCallback.cpp:
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp:
  • bindings/js/JSCustomSQLTransactionCallback.cpp:
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
  • bindings/js/JSCustomVoidCallback.cpp:
  • bindings/js/JSCustomXPathNSResolver.cpp:
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSNodeFilterCondition.cpp:
  • bindings/js/ScheduledAction.cpp:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptControllerMac.mm:
  • bindings/objc/WebScriptObject.mm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_class.cpp:
  • bridge/c/c_instance.cpp:
  • bridge/c/c_runtime.cpp:
  • bridge/c/c_utility.cpp:
  • bridge/jni/jni_class.cpp:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_jsobject.mm:
  • bridge/jni/jni_objc.mm:
  • bridge/jni/jni_runtime.cpp:
  • bridge/jni/jni_runtime.h:
  • bridge/jni/jni_utility.cpp:
  • bridge/npruntime.cpp:
  • bridge/objc/objc_instance.mm:
  • bridge/objc/objc_runtime.mm:
  • bridge/objc/objc_utility.mm:
  • bridge/runtime.cpp:
  • dom/Document.cpp:
  • dom/Node.cpp:
  • dom/NodeFilter.cpp:
  • dom/NodeIterator.cpp:
  • dom/TreeWalker.cpp:
  • history/CachedPage.cpp:
  • inspector/InspectorController.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/JavaScriptCallFrame.h:
  • inspector/JavaScriptDebugServer.cpp:
  • inspector/JavaScriptProfileNode.cpp:
  • loader/FrameLoader.cpp:
  • loader/icon/IconDatabase.cpp:
  • page/Console.cpp:
  • page/Page.cpp:
  • page/mac/FrameMac.mm:
  • plugins/PluginView.cpp:
  • plugins/gtk/PluginViewGtk.cpp:
  • plugins/qt/PluginViewQt.cpp:
  • plugins/win/PluginViewWin.cpp:
  • storage/Database.cpp:
  • xml/XMLHttpRequest.cpp:

WebKit/gtk:

  • webkit/webkitprivate.cpp:

WebKit/mac:

  • ForwardingHeaders/kjs/JSLock.h: Removed.
  • ForwardingHeaders/kjs/SymbolTable.h: Removed.
  • ForwardingHeaders/runtime/JSLock.h: Copied from ForwardingHeaders/kjs/JSLock.h.
  • ForwardingHeaders/runtime/SymbolTable.h: Copied from ForwardingHeaders/kjs/SymbolTable.h.
  • Misc/WebCoreStatistics.mm:
  • Plugins/WebBaseNetscapePluginStream.mm:
  • Plugins/WebBaseNetscapePluginView.mm:
  • Plugins/WebPluginController.mm:
  • WebView/WebFrame.mm:
  • WebView/WebScriptDebugDelegate.mm:
  • WebView/WebView.mm:

WebKit/qt:

  • Api/qwebpage.cpp:

WebKit/win:

  • WebJavaScriptCollector.cpp:
  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1/*
2 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
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
24#include <wtf/Assertions.h>
25
26namespace JSC {
27
28 class JSGlobalData;
29 class JSGlobalObject;
30 class JSObject;
31 class ScopeChainIterator;
32
33 class ScopeChainNode {
34 public:
35 ScopeChainNode(ScopeChainNode* next, JSObject* object, JSGlobalData* globalData, JSObject* globalThis)
36 : next(next)
37 , object(object)
38 , globalData(globalData)
39 , globalThis(globalThis)
40 , refCount(1)
41 {
42 ASSERT(globalData);
43 }
44
45 ScopeChainNode* next;
46 JSObject* object;
47 JSGlobalData* globalData;
48 JSObject* globalThis;
49 int refCount;
50
51 void deref() { if (--refCount == 0) release(); }
52 void ref() { ++refCount; }
53 void release();
54
55 // Before calling "push" on a bare ScopeChainNode, a client should
56 // logically "copy" the node. Later, the client can "deref" the head
57 // of its chain of ScopeChainNodes to reclaim all the nodes it added
58 // after the logical copy, leaving nodes added before the logical copy
59 // (nodes shared with other clients) untouched.
60 ScopeChainNode* copy()
61 {
62 ref();
63 return this;
64 }
65
66 ScopeChainNode* push(JSObject*);
67 ScopeChainNode* pop();
68
69 ScopeChainIterator begin() const;
70 ScopeChainIterator end() const;
71
72 JSGlobalObject* globalObject() const; // defined in JSGlobalObject.h
73 JSObject* globalThisObject() const { return globalThis; }
74
75#ifndef NDEBUG
76 void print() const;
77#endif
78 };
79
80 inline ScopeChainNode* ScopeChainNode::push(JSObject* o)
81 {
82 ASSERT(o);
83 return new ScopeChainNode(this, o, globalData, globalThis);
84 }
85
86 inline ScopeChainNode* ScopeChainNode::pop()
87 {
88 ASSERT(next);
89 ScopeChainNode* result = next;
90
91 if (--refCount != 0)
92 ++result->refCount;
93 else
94 delete this;
95
96 return result;
97 }
98
99 inline void ScopeChainNode::release()
100 {
101 // This function is only called by deref(),
102 // Deref ensures these conditions are true.
103 ASSERT(refCount == 0);
104 ScopeChainNode* n = this;
105 do {
106 ScopeChainNode* next = n->next;
107 delete n;
108 n = next;
109 } while (n && --n->refCount == 0);
110 }
111
112 class ScopeChainIterator {
113 public:
114 ScopeChainIterator(const ScopeChainNode* node)
115 : m_node(node)
116 {
117 }
118
119 JSObject* const & operator*() const { return m_node->object; }
120 JSObject* const * operator->() const { return &(operator*()); }
121
122 ScopeChainIterator& operator++() { m_node = m_node->next; return *this; }
123
124 // postfix ++ intentionally omitted
125
126 bool operator==(const ScopeChainIterator& other) const { return m_node == other.m_node; }
127 bool operator!=(const ScopeChainIterator& other) const { return m_node != other.m_node; }
128
129 private:
130 const ScopeChainNode* m_node;
131 };
132
133 inline ScopeChainIterator ScopeChainNode::begin() const
134 {
135 return ScopeChainIterator(this);
136 }
137
138 inline ScopeChainIterator ScopeChainNode::end() const
139 {
140 return ScopeChainIterator(0);
141 }
142
143 class NoScopeChain {};
144
145 class ScopeChain {
146 friend class CTI;
147 public:
148 ScopeChain(NoScopeChain)
149 : m_node(0)
150 {
151 }
152
153 ScopeChain(JSObject* o, JSGlobalData* globalData, JSObject* globalThis)
154 : m_node(new ScopeChainNode(0, o, globalData, globalThis))
155 {
156 }
157
158 ScopeChain(const ScopeChain& c)
159 : m_node(c.m_node->copy())
160 {
161 }
162
163 ScopeChain& operator=(const ScopeChain& c);
164
165 explicit ScopeChain(ScopeChainNode* node)
166 : m_node(node->copy())
167 {
168 }
169
170 ~ScopeChain()
171 {
172 if (m_node)
173 m_node->deref();
174 }
175
176 void swap(ScopeChain&);
177
178 ScopeChainNode* node() const { return m_node; }
179
180 JSObject* top() const { return m_node->object; }
181
182 ScopeChainIterator begin() const { return m_node->begin(); }
183 ScopeChainIterator end() const { return m_node->end(); }
184
185 void push(JSObject* o) { m_node = m_node->push(o); }
186
187 void pop() { m_node = m_node->pop(); }
188 void clear() { m_node->deref(); m_node = 0; }
189
190 JSGlobalObject* globalObject() const { return m_node->globalObject(); }
191
192 void mark() const;
193
194#ifndef NDEBUG
195 void print() const { m_node->print(); }
196#endif
197
198 private:
199 ScopeChainNode* m_node;
200 };
201
202 inline void ScopeChain::swap(ScopeChain& o)
203 {
204 ScopeChainNode* tmp = m_node;
205 m_node = o.m_node;
206 o.m_node = tmp;
207 }
208
209 inline ScopeChain& ScopeChain::operator=(const ScopeChain& c)
210 {
211 ScopeChain tmp(c);
212 swap(tmp);
213 return *this;
214 }
215
216} // namespace JSC
217
218#endif // ScopeChain_h
Note: See TracBrowser for help on using the repository browser.