1 | // -*- c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2007 Eric Seidel <[email protected]>
|
---|
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 PrototypeReflexiveFunction;
|
---|
52 | class RangeError;
|
---|
53 | class RangeErrorPrototype;
|
---|
54 | class ReferenceError;
|
---|
55 | class ReferenceError;
|
---|
56 | class ReferenceErrorPrototype;
|
---|
57 | class RegExpObjectImp;
|
---|
58 | class RegExpPrototype;
|
---|
59 | class RuntimeMethod;
|
---|
60 | class SavedBuiltins;
|
---|
61 | class ScopeChain;
|
---|
62 | class StringObjectImp;
|
---|
63 | class StringPrototype;
|
---|
64 | class SyntaxErrorPrototype;
|
---|
65 | class TypeError;
|
---|
66 | class TypeErrorPrototype;
|
---|
67 | class UriError;
|
---|
68 | class UriErrorPrototype;
|
---|
69 | struct ActivationStackNode;
|
---|
70 |
|
---|
71 | class JSGlobalObject : public JSVariableObject {
|
---|
72 | protected:
|
---|
73 | using JSVariableObject::JSVariableObjectData;
|
---|
74 |
|
---|
75 | struct JSGlobalObjectData : public JSVariableObjectData {
|
---|
76 | JSGlobalObjectData(JSGlobalObject* globalObject)
|
---|
77 | : JSVariableObjectData(&inlineSymbolTable)
|
---|
78 | , globalExec(globalObject)
|
---|
79 | {
|
---|
80 | }
|
---|
81 |
|
---|
82 | JSGlobalObject* next;
|
---|
83 | JSGlobalObject* prev;
|
---|
84 |
|
---|
85 | Debugger* debugger;
|
---|
86 |
|
---|
87 | GlobalExecState globalExec;
|
---|
88 | int recursion;
|
---|
89 |
|
---|
90 | unsigned timeoutTime;
|
---|
91 | unsigned timeAtLastCheckTimeout;
|
---|
92 | unsigned timeExecuting;
|
---|
93 | unsigned timeoutCheckCount;
|
---|
94 | unsigned tickCount;
|
---|
95 | unsigned ticksUntilNextTimeoutCheck;
|
---|
96 |
|
---|
97 | ObjectObjectImp* objectConstructor;
|
---|
98 | FunctionObjectImp* functionConstructor;
|
---|
99 | ArrayObjectImp* arrayConstructor;
|
---|
100 | BooleanObjectImp* booleanConstructor;
|
---|
101 | StringObjectImp* stringConstructor;
|
---|
102 | NumberObjectImp* numberConstructor;
|
---|
103 | DateObjectImp* dateConstructor;
|
---|
104 | RegExpObjectImp* regExpConstructor;
|
---|
105 | ErrorObjectImp* errorConstructor;
|
---|
106 | NativeErrorImp* evalErrorConstructor;
|
---|
107 | NativeErrorImp* rangeErrorConstructor;
|
---|
108 | NativeErrorImp* referenceErrorConstructor;
|
---|
109 | NativeErrorImp* syntaxErrorConstructor;
|
---|
110 | NativeErrorImp* typeErrorConstructor;
|
---|
111 | NativeErrorImp* URIErrorConstructor;
|
---|
112 |
|
---|
113 | PrototypeReflexiveFunction* evalFunction;
|
---|
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*);
|
---|
156 | virtual void initializeVariable(ExecState*, const Identifier&, JSValue*, unsigned attributes);
|
---|
157 |
|
---|
158 | // Linked list of all global objects.
|
---|
159 | static JSGlobalObject* head() { return s_head; }
|
---|
160 | JSGlobalObject* next() { return d()->next; }
|
---|
161 |
|
---|
162 | // Resets the global object to contain only built-in properties, sets
|
---|
163 | // the global object's prototype to "prototype," then adds the
|
---|
164 | // default object prototype to the tail of the global object's
|
---|
165 | // prototype chain.
|
---|
166 | void reset(JSValue* prototype);
|
---|
167 |
|
---|
168 | // The following accessors return pristine values, even if a script
|
---|
169 | // replaces the global object's associated property.
|
---|
170 |
|
---|
171 | ObjectObjectImp* objectConstructor() const { return d()->objectConstructor; }
|
---|
172 | FunctionObjectImp* functionConstructor() const { return d()->functionConstructor; }
|
---|
173 | ArrayObjectImp* arrayConstructor() const { return d()->arrayConstructor; }
|
---|
174 | BooleanObjectImp* booleanConstructor() const { return d()->booleanConstructor; }
|
---|
175 | StringObjectImp* stringConstructor() const{ return d()->stringConstructor; }
|
---|
176 | NumberObjectImp* numberConstructor() const{ return d()->numberConstructor; }
|
---|
177 | DateObjectImp* dateConstructor() const{ return d()->dateConstructor; }
|
---|
178 | RegExpObjectImp* regExpConstructor() const { return d()->regExpConstructor; }
|
---|
179 | ErrorObjectImp* errorConstructor() const { return d()->errorConstructor; }
|
---|
180 | NativeErrorImp* evalErrorConstructor() const { return d()->evalErrorConstructor; }
|
---|
181 | NativeErrorImp* rangeErrorConstructor() const { return d()->rangeErrorConstructor; }
|
---|
182 | NativeErrorImp* referenceErrorConstructor() const { return d()->referenceErrorConstructor; }
|
---|
183 | NativeErrorImp* syntaxErrorConstructor() const { return d()->syntaxErrorConstructor; }
|
---|
184 | NativeErrorImp* typeErrorConstructor() const { return d()->typeErrorConstructor; }
|
---|
185 | NativeErrorImp* URIErrorConstructor() const { return d()->URIErrorConstructor; }
|
---|
186 |
|
---|
187 | PrototypeReflexiveFunction* evalFunction() const { return d()->evalFunction; }
|
---|
188 |
|
---|
189 | ObjectPrototype* objectPrototype() const { return d()->objectPrototype; }
|
---|
190 | FunctionPrototype* functionPrototype() const { return d()->functionPrototype; }
|
---|
191 | ArrayPrototype* arrayPrototype() const { return d()->arrayPrototype; }
|
---|
192 | BooleanPrototype* booleanPrototype() const { return d()->booleanPrototype; }
|
---|
193 | StringPrototype* stringPrototype() const { return d()->stringPrototype; }
|
---|
194 | NumberPrototype* numberPrototype() const { return d()->numberPrototype; }
|
---|
195 | DatePrototype* datePrototype() const { return d()->datePrototype; }
|
---|
196 | RegExpPrototype* regExpPrototype() const { return d()->regExpPrototype; }
|
---|
197 | ErrorPrototype* errorPrototype() const { return d()->errorPrototype; }
|
---|
198 | NativeErrorPrototype* evalErrorPrototype() const { return d()->evalErrorPrototype; }
|
---|
199 | NativeErrorPrototype* rangeErrorPrototype() const { return d()->rangeErrorPrototype; }
|
---|
200 | NativeErrorPrototype* referenceErrorPrototype() const { return d()->referenceErrorPrototype; }
|
---|
201 | NativeErrorPrototype* syntaxErrorPrototype() const { return d()->syntaxErrorPrototype; }
|
---|
202 | NativeErrorPrototype* typeErrorPrototype() const { return d()->typeErrorPrototype; }
|
---|
203 | NativeErrorPrototype* URIErrorPrototype() const { return d()->URIErrorPrototype; }
|
---|
204 |
|
---|
205 | void saveBuiltins(SavedBuiltins&) const;
|
---|
206 | void restoreBuiltins(const SavedBuiltins&);
|
---|
207 |
|
---|
208 | void setTimeoutTime(unsigned timeoutTime) { d()->timeoutTime = timeoutTime; }
|
---|
209 | void startTimeoutCheck();
|
---|
210 | void stopTimeoutCheck();
|
---|
211 | bool timedOut();
|
---|
212 |
|
---|
213 | Debugger* debugger() const { return d()->debugger; }
|
---|
214 | void setDebugger(Debugger* debugger) { d()->debugger = debugger; }
|
---|
215 |
|
---|
216 | int recursion() { return d()->recursion; }
|
---|
217 | void incRecursion() { ++d()->recursion; }
|
---|
218 | void decRecursion() { --d()->recursion; }
|
---|
219 |
|
---|
220 | virtual void mark();
|
---|
221 |
|
---|
222 | virtual bool isGlobalObject() const { return true; }
|
---|
223 |
|
---|
224 | virtual ExecState* globalExec();
|
---|
225 |
|
---|
226 | virtual bool shouldInterruptScript() const { return true; }
|
---|
227 |
|
---|
228 | virtual bool allowsAccessFrom(const JSGlobalObject*) const { return true; }
|
---|
229 |
|
---|
230 | ActivationImp* pushActivation(ExecState*);
|
---|
231 | void popActivation();
|
---|
232 | void tearOffActivation(ExecState*, bool markAsRelic = false);
|
---|
233 |
|
---|
234 | virtual bool isDynamicScope() const;
|
---|
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
|
---|