]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | // -*- c-basic-offset: 4 -*- |
2 | /* | |
3 | * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | |
4 | * Copyright (C) 2007 Apple Inc. All rights reserved. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Library General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Library General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Library General Public License | |
17 | * along with this library; see the file COPYING.LIB. If not, write to | |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 | * Boston, MA 02110-1301, USA. | |
20 | * | |
21 | */ | |
22 | ||
23 | #ifndef KJS_GlobalObject_h | |
24 | #define KJS_GlobalObject_h | |
25 | ||
26 | #include "JSVariableObject.h" | |
27 | ||
28 | namespace KJS { | |
29 | ||
30 | class ActivationImp; | |
31 | class ArrayObjectImp; | |
32 | class ArrayPrototype; | |
33 | class BooleanObjectImp; | |
34 | class BooleanPrototype; | |
35 | class DateObjectImp; | |
36 | class DatePrototype; | |
37 | class Debugger; | |
38 | class ErrorObjectImp; | |
39 | class ErrorPrototype; | |
40 | class EvalError; | |
41 | class EvalErrorPrototype; | |
42 | class FunctionObjectImp; | |
43 | class FunctionPrototype; | |
44 | class JSGlobalObject; | |
45 | class NativeErrorImp; | |
46 | class NativeErrorPrototype; | |
47 | class NumberObjectImp; | |
48 | class NumberPrototype; | |
49 | class ObjectObjectImp; | |
50 | class ObjectPrototype; | |
51 | class RangeError; | |
52 | class RangeErrorPrototype; | |
53 | class ReferenceError; | |
54 | class ReferenceError; | |
55 | class ReferenceErrorPrototype; | |
56 | class RegExpObjectImp; | |
57 | class RegExpPrototype; | |
58 | class RuntimeMethod; | |
59 | class SavedBuiltins; | |
60 | class ScopeChain; | |
61 | class StringObjectImp; | |
62 | class StringPrototype; | |
63 | class SyntaxErrorPrototype; | |
64 | class TypeError; | |
65 | class TypeErrorPrototype; | |
66 | class UriError; | |
67 | class UriErrorPrototype; | |
68 | struct ActivationStackNode; | |
69 | ||
70 | enum CompatMode { NativeMode, IECompat, NetscapeCompat }; | |
71 | ||
72 | class JSGlobalObject : public JSVariableObject { | |
73 | protected: | |
74 | using JSVariableObject::JSVariableObjectData; | |
75 | ||
76 | struct JSGlobalObjectData : public JSVariableObjectData { | |
77 | JSGlobalObjectData(JSGlobalObject* globalObject) | |
78 | : JSVariableObjectData(&inlineSymbolTable) | |
79 | , globalExec(globalObject) | |
80 | { | |
81 | } | |
82 | ||
83 | JSGlobalObject* next; | |
84 | JSGlobalObject* prev; | |
85 | ||
86 | Debugger* debugger; | |
87 | CompatMode compatMode; | |
88 | ||
89 | GlobalExecState globalExec; | |
90 | int recursion; | |
91 | ||
92 | unsigned timeoutTime; | |
93 | unsigned timeAtLastCheckTimeout; | |
94 | unsigned timeExecuting; | |
95 | unsigned timeoutCheckCount; | |
96 | unsigned tickCount; | |
97 | unsigned ticksUntilNextTimeoutCheck; | |
98 | ||
99 | ObjectObjectImp* objectConstructor; | |
100 | FunctionObjectImp* functionConstructor; | |
101 | ArrayObjectImp* arrayConstructor; | |
102 | BooleanObjectImp* booleanConstructor; | |
103 | StringObjectImp* stringConstructor; | |
104 | NumberObjectImp* numberConstructor; | |
105 | DateObjectImp* dateConstructor; | |
106 | RegExpObjectImp* regExpConstructor; | |
107 | ErrorObjectImp* errorConstructor; | |
108 | NativeErrorImp* evalErrorConstructor; | |
109 | NativeErrorImp* rangeErrorConstructor; | |
110 | NativeErrorImp* referenceErrorConstructor; | |
111 | NativeErrorImp* syntaxErrorConstructor; | |
112 | NativeErrorImp* typeErrorConstructor; | |
113 | NativeErrorImp* URIErrorConstructor; | |
114 | ||
115 | ObjectPrototype* objectPrototype; | |
116 | FunctionPrototype* functionPrototype; | |
117 | ArrayPrototype* arrayPrototype; | |
118 | BooleanPrototype* booleanPrototype; | |
119 | StringPrototype* stringPrototype; | |
120 | NumberPrototype* numberPrototype; | |
121 | DatePrototype* datePrototype; | |
122 | RegExpPrototype* regExpPrototype; | |
123 | ErrorPrototype* errorPrototype; | |
124 | NativeErrorPrototype* evalErrorPrototype; | |
125 | NativeErrorPrototype* rangeErrorPrototype; | |
126 | NativeErrorPrototype* referenceErrorPrototype; | |
127 | NativeErrorPrototype* syntaxErrorPrototype; | |
128 | NativeErrorPrototype* typeErrorPrototype; | |
129 | NativeErrorPrototype* URIErrorPrototype; | |
130 | ||
131 | SymbolTable inlineSymbolTable; | |
132 | ||
133 | ActivationStackNode* activations; | |
134 | size_t activationCount; | |
135 | }; | |
136 | ||
137 | public: | |
138 | JSGlobalObject() | |
139 | : JSVariableObject(new JSGlobalObjectData(this)) | |
140 | { | |
141 | init(); | |
142 | } | |
143 | ||
144 | protected: | |
145 | JSGlobalObject(JSValue* proto) | |
146 | : JSVariableObject(proto, new JSGlobalObjectData(this)) | |
147 | { | |
148 | init(); | |
149 | } | |
150 | ||
151 | public: | |
152 | virtual ~JSGlobalObject(); | |
153 | ||
154 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); | |
155 | virtual void put(ExecState*, const Identifier&, JSValue*, int attr = None); | |
156 | ||
157 | // Linked list of all global objects. | |
158 | static JSGlobalObject* head() { return s_head; } | |
159 | JSGlobalObject* next() { return d()->next; } | |
160 | ||
161 | // Resets the global object to contain only built-in properties, sets | |
162 | // the global object's prototype to "prototype," then adds the | |
163 | // default object prototype to the tail of the global object's | |
164 | // prototype chain. | |
165 | void reset(JSValue* prototype); | |
166 | ||
167 | // The following accessors return pristine values, even if a script | |
168 | // replaces the global object's associated property. | |
169 | ||
170 | ObjectObjectImp* objectConstructor() const { return d()->objectConstructor; } | |
171 | FunctionObjectImp* functionConstructor() const { return d()->functionConstructor; } | |
172 | ArrayObjectImp* arrayConstructor() const { return d()->arrayConstructor; } | |
173 | BooleanObjectImp* booleanConstructor() const { return d()->booleanConstructor; } | |
174 | StringObjectImp* stringConstructor() const{ return d()->stringConstructor; } | |
175 | NumberObjectImp* numberConstructor() const{ return d()->numberConstructor; } | |
176 | DateObjectImp* dateConstructor() const{ return d()->dateConstructor; } | |
177 | RegExpObjectImp* regExpConstructor() const { return d()->regExpConstructor; } | |
178 | ErrorObjectImp* errorConstructor() const { return d()->errorConstructor; } | |
179 | NativeErrorImp* evalErrorConstructor() const { return d()->evalErrorConstructor; } | |
180 | NativeErrorImp* rangeErrorConstructor() const { return d()->rangeErrorConstructor; } | |
181 | NativeErrorImp* referenceErrorConstructor() const { return d()->referenceErrorConstructor; } | |
182 | NativeErrorImp* syntaxErrorConstructor() const { return d()->syntaxErrorConstructor; } | |
183 | NativeErrorImp* typeErrorConstructor() const { return d()->typeErrorConstructor; } | |
184 | NativeErrorImp* URIErrorConstructor() const { return d()->URIErrorConstructor; } | |
185 | ||
186 | ObjectPrototype* objectPrototype() const { return d()->objectPrototype; } | |
187 | FunctionPrototype* functionPrototype() const { return d()->functionPrototype; } | |
188 | ArrayPrototype* arrayPrototype() const { return d()->arrayPrototype; } | |
189 | BooleanPrototype* booleanPrototype() const { return d()->booleanPrototype; } | |
190 | StringPrototype* stringPrototype() const { return d()->stringPrototype; } | |
191 | NumberPrototype* numberPrototype() const { return d()->numberPrototype; } | |
192 | DatePrototype* datePrototype() const { return d()->datePrototype; } | |
193 | RegExpPrototype* regExpPrototype() const { return d()->regExpPrototype; } | |
194 | ErrorPrototype* errorPrototype() const { return d()->errorPrototype; } | |
195 | NativeErrorPrototype* evalErrorPrototype() const { return d()->evalErrorPrototype; } | |
196 | NativeErrorPrototype* rangeErrorPrototype() const { return d()->rangeErrorPrototype; } | |
197 | NativeErrorPrototype* referenceErrorPrototype() const { return d()->referenceErrorPrototype; } | |
198 | NativeErrorPrototype* syntaxErrorPrototype() const { return d()->syntaxErrorPrototype; } | |
199 | NativeErrorPrototype* typeErrorPrototype() const { return d()->typeErrorPrototype; } | |
200 | NativeErrorPrototype* URIErrorPrototype() const { return d()->URIErrorPrototype; } | |
201 | ||
202 | void saveBuiltins(SavedBuiltins&) const; | |
203 | void restoreBuiltins(const SavedBuiltins&); | |
204 | ||
205 | void setTimeoutTime(unsigned timeoutTime) { d()->timeoutTime = timeoutTime; } | |
206 | void startTimeoutCheck(); | |
207 | void stopTimeoutCheck(); | |
208 | bool timedOut(); | |
209 | ||
210 | Debugger* debugger() const { return d()->debugger; } | |
211 | void setDebugger(Debugger* debugger) { d()->debugger = debugger; } | |
212 | ||
213 | // FIXME: Let's just pick one compatible behavior and go with it. | |
214 | void setCompatMode(CompatMode mode) { d()->compatMode = mode; } | |
215 | CompatMode compatMode() const { return d()->compatMode; } | |
216 | ||
217 | int recursion() { return d()->recursion; } | |
218 | void incRecursion() { ++d()->recursion; } | |
219 | void decRecursion() { --d()->recursion; } | |
220 | ||
221 | virtual void mark(); | |
222 | ||
223 | virtual bool isGlobalObject() const { return true; } | |
224 | ||
225 | virtual ExecState* globalExec(); | |
226 | ||
227 | virtual bool shouldInterruptScriptBeforeTimeout() const { return false; } | |
228 | virtual bool shouldInterruptScript() const { return true; } | |
229 | ||
230 | virtual bool allowsAccessFrom(const JSGlobalObject*) const { return true; } | |
231 | ||
232 | ActivationImp* pushActivation(ExecState*); | |
233 | void popActivation(); | |
234 | void tearOffActivation(ExecState*, bool markAsRelic = false); | |
235 | ||
236 | private: | |
237 | void init(); | |
238 | ||
239 | JSGlobalObjectData* d() const { return static_cast<JSGlobalObjectData*>(JSVariableObject::d); } | |
240 | ||
241 | bool checkTimeout(); | |
242 | void resetTimeoutCheck(); | |
243 | ||
244 | void deleteActivationStack(); | |
245 | void checkActivationCount(); | |
246 | ||
247 | static JSGlobalObject* s_head; | |
248 | }; | |
249 | ||
250 | inline bool JSGlobalObject::timedOut() | |
251 | { | |
252 | d()->tickCount++; | |
253 | ||
254 | if (d()->tickCount != d()->ticksUntilNextTimeoutCheck) | |
255 | return false; | |
256 | ||
257 | return checkTimeout(); | |
258 | } | |
259 | ||
260 | } // namespace KJS | |
261 | ||
262 | #endif // KJS_GlobalObject_h |