|
1 /* |
|
2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. |
|
3 * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca) |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
15 * its contributors may be used to endorse or promote products derived |
|
16 * from this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 */ |
|
29 |
|
30 #include "config.h" |
|
31 #include "JSGlobalObject.h" |
|
32 |
|
33 #include "JSCallbackConstructor.h" |
|
34 #include "JSCallbackFunction.h" |
|
35 #include "JSCallbackObject.h" |
|
36 |
|
37 #include "Arguments.h" |
|
38 #include "ArrayConstructor.h" |
|
39 #include "ArrayPrototype.h" |
|
40 #include "BooleanConstructor.h" |
|
41 #include "BooleanPrototype.h" |
|
42 #include "CodeBlock.h" |
|
43 #include "DateConstructor.h" |
|
44 #include "DatePrototype.h" |
|
45 #include "ErrorConstructor.h" |
|
46 #include "ErrorPrototype.h" |
|
47 #include "FunctionConstructor.h" |
|
48 #include "FunctionPrototype.h" |
|
49 #include "GlobalEvalFunction.h" |
|
50 #include "JSFunction.h" |
|
51 #include "JSGlobalObjectFunctions.h" |
|
52 #include "JSLock.h" |
|
53 #include "JSONObject.h" |
|
54 #include "Interpreter.h" |
|
55 #include "MathObject.h" |
|
56 #include "NativeErrorConstructor.h" |
|
57 #include "NativeErrorPrototype.h" |
|
58 #include "NumberConstructor.h" |
|
59 #include "NumberPrototype.h" |
|
60 #include "ObjectConstructor.h" |
|
61 #include "ObjectPrototype.h" |
|
62 #include "Profiler.h" |
|
63 #include "PrototypeFunction.h" |
|
64 #include "RegExpConstructor.h" |
|
65 #include "RegExpMatchesArray.h" |
|
66 #include "RegExpObject.h" |
|
67 #include "RegExpPrototype.h" |
|
68 #include "ScopeChainMark.h" |
|
69 #include "StringConstructor.h" |
|
70 #include "StringPrototype.h" |
|
71 #include "Debugger.h" |
|
72 |
|
73 namespace JSC { |
|
74 |
|
75 ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject); |
|
76 |
|
77 // Default number of ticks before a timeout check should be done. |
|
78 static const int initialTickCountThreshold = 255; |
|
79 |
|
80 // Preferred number of milliseconds between each timeout check |
|
81 static const int preferredScriptCheckTimeInterval = 1000; |
|
82 |
|
83 static inline void markIfNeeded(MarkStack& markStack, JSValue v) |
|
84 { |
|
85 if (v) |
|
86 markStack.append(v); |
|
87 } |
|
88 |
|
89 static inline void markIfNeeded(MarkStack& markStack, const RefPtr<Structure>& s) |
|
90 { |
|
91 if (s) |
|
92 markIfNeeded(markStack, s->storedPrototype()); |
|
93 } |
|
94 |
|
95 JSGlobalObject::~JSGlobalObject() |
|
96 { |
|
97 ASSERT(JSLock::currentThreadIsHoldingLock()); |
|
98 |
|
99 if (d()->debugger) |
|
100 d()->debugger->detach(this); |
|
101 |
|
102 Profiler** profiler = Profiler::enabledProfilerReference(); |
|
103 if (UNLIKELY(*profiler != 0)) { |
|
104 (*profiler)->stopProfiling(globalExec(), UString()); |
|
105 } |
|
106 |
|
107 d()->next->d()->prev = d()->prev; |
|
108 d()->prev->d()->next = d()->next; |
|
109 JSGlobalObject*& headObject = head(); |
|
110 if (headObject == this) |
|
111 headObject = d()->next; |
|
112 if (headObject == this) |
|
113 headObject = 0; |
|
114 |
|
115 HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end(); |
|
116 for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it) |
|
117 (*it)->clearGlobalObject(); |
|
118 |
|
119 RegisterFile& registerFile = globalData()->interpreter->registerFile(); |
|
120 if (registerFile.clearGlobalObject(this)) |
|
121 registerFile.setNumGlobals(0); |
|
122 d()->destructor(d()); |
|
123 } |
|
124 |
|
125 void JSGlobalObject::init(JSObject* thisValue) |
|
126 { |
|
127 ASSERT(JSLock::currentThreadIsHoldingLock()); |
|
128 |
|
129 structure()->disableSpecificFunctionTracking(); |
|
130 |
|
131 d()->globalData = Heap::heap(this)->globalData(); |
|
132 d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), this, thisValue); |
|
133 |
|
134 JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0); |
|
135 |
|
136 if (JSGlobalObject*& headObject = head()) { |
|
137 d()->prev = headObject; |
|
138 d()->next = headObject->d()->next; |
|
139 headObject->d()->next->d()->prev = this; |
|
140 headObject->d()->next = this; |
|
141 } else |
|
142 headObject = d()->next = d()->prev = this; |
|
143 |
|
144 d()->recursion = 0; |
|
145 d()->debugger = 0; |
|
146 |
|
147 d()->profileGroup = 0; |
|
148 |
|
149 reset(prototype()); |
|
150 } |
|
151 |
|
152 void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) |
|
153 { |
|
154 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); |
|
155 |
|
156 if (symbolTablePut(propertyName, value)) |
|
157 return; |
|
158 JSVariableObject::put(exec, propertyName, value, slot); |
|
159 } |
|
160 |
|
161 void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes) |
|
162 { |
|
163 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); |
|
164 |
|
165 if (symbolTablePutWithAttributes(propertyName, value, attributes)) |
|
166 return; |
|
167 |
|
168 JSValue valueBefore = getDirect(propertyName); |
|
169 PutPropertySlot slot; |
|
170 JSVariableObject::put(exec, propertyName, value, slot); |
|
171 if (!valueBefore) { |
|
172 JSValue valueAfter = getDirect(propertyName); |
|
173 if (valueAfter) |
|
174 JSObject::putWithAttributes(exec, propertyName, valueAfter, attributes); |
|
175 } |
|
176 } |
|
177 |
|
178 void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes) |
|
179 { |
|
180 PropertySlot slot; |
|
181 if (!symbolTableGet(propertyName, slot)) |
|
182 JSVariableObject::defineGetter(exec, propertyName, getterFunc, attributes); |
|
183 } |
|
184 |
|
185 void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes) |
|
186 { |
|
187 PropertySlot slot; |
|
188 if (!symbolTableGet(propertyName, slot)) |
|
189 JSVariableObject::defineSetter(exec, propertyName, setterFunc, attributes); |
|
190 } |
|
191 |
|
192 static inline JSObject* lastInPrototypeChain(JSObject* object) |
|
193 { |
|
194 JSObject* o = object; |
|
195 while (o->prototype().isObject()) |
|
196 o = asObject(o->prototype()); |
|
197 return o; |
|
198 } |
|
199 |
|
200 void JSGlobalObject::reset(JSValue prototype) |
|
201 { |
|
202 ExecState* exec = JSGlobalObject::globalExec(); |
|
203 |
|
204 // Prototypes |
|
205 |
|
206 d()->functionPrototype = new (exec) FunctionPrototype(exec, this, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created. |
|
207 d()->prototypeFunctionStructure = PrototypeFunction::createStructure(d()->functionPrototype); |
|
208 NativeFunctionWrapper* callFunction = 0; |
|
209 NativeFunctionWrapper* applyFunction = 0; |
|
210 d()->functionPrototype->addFunctionProperties(exec, this, d()->prototypeFunctionStructure.get(), &callFunction, &applyFunction); |
|
211 d()->callFunction = callFunction; |
|
212 d()->applyFunction = applyFunction; |
|
213 d()->objectPrototype = new (exec) ObjectPrototype(exec, this, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get()); |
|
214 d()->functionPrototype->structure()->setPrototypeWithoutTransition(d()->objectPrototype); |
|
215 |
|
216 d()->emptyObjectStructure = d()->objectPrototype->inheritorID(); |
|
217 |
|
218 d()->functionStructure = JSFunction::createStructure(d()->functionPrototype); |
|
219 d()->callbackFunctionStructure = JSCallbackFunction::createStructure(d()->functionPrototype); |
|
220 d()->argumentsStructure = Arguments::createStructure(d()->objectPrototype); |
|
221 d()->callbackConstructorStructure = JSCallbackConstructor::createStructure(d()->objectPrototype); |
|
222 d()->callbackObjectStructure = JSCallbackObject<JSObjectWithGlobalObject>::createStructure(d()->objectPrototype); |
|
223 |
|
224 d()->arrayPrototype = new (exec) ArrayPrototype(this, ArrayPrototype::createStructure(d()->objectPrototype)); |
|
225 d()->arrayStructure = JSArray::createStructure(d()->arrayPrototype); |
|
226 d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructure(d()->arrayPrototype); |
|
227 |
|
228 d()->stringPrototype = new (exec) StringPrototype(exec, this, StringPrototype::createStructure(d()->objectPrototype)); |
|
229 d()->stringObjectStructure = StringObject::createStructure(d()->stringPrototype); |
|
230 |
|
231 d()->booleanPrototype = new (exec) BooleanPrototype(exec, this, BooleanPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); |
|
232 d()->booleanObjectStructure = BooleanObject::createStructure(d()->booleanPrototype); |
|
233 |
|
234 d()->numberPrototype = new (exec) NumberPrototype(exec, this, NumberPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); |
|
235 d()->numberObjectStructure = NumberObject::createStructure(d()->numberPrototype); |
|
236 |
|
237 d()->datePrototype = new (exec) DatePrototype(exec, this, DatePrototype::createStructure(d()->objectPrototype)); |
|
238 d()->dateStructure = DateInstance::createStructure(d()->datePrototype); |
|
239 |
|
240 d()->regExpPrototype = new (exec) RegExpPrototype(exec, this, RegExpPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); |
|
241 d()->regExpStructure = RegExpObject::createStructure(d()->regExpPrototype); |
|
242 |
|
243 d()->methodCallDummy = constructEmptyObject(exec); |
|
244 |
|
245 ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, this, ErrorPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); |
|
246 d()->errorStructure = ErrorInstance::createStructure(errorPrototype); |
|
247 |
|
248 // Constructors |
|
249 |
|
250 JSCell* objectConstructor = new (exec) ObjectConstructor(exec, this, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get()); |
|
251 JSCell* functionConstructor = new (exec) FunctionConstructor(exec, this, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype); |
|
252 JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, this, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype, d()->prototypeFunctionStructure.get()); |
|
253 JSCell* stringConstructor = new (exec) StringConstructor(exec, this, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype); |
|
254 JSCell* booleanConstructor = new (exec) BooleanConstructor(exec, this, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype); |
|
255 JSCell* numberConstructor = new (exec) NumberConstructor(exec, this, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype); |
|
256 JSCell* dateConstructor = new (exec) DateConstructor(exec, this, DateConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype); |
|
257 |
|
258 d()->regExpConstructor = new (exec) RegExpConstructor(exec, this, RegExpConstructor::createStructure(d()->functionPrototype), d()->regExpPrototype); |
|
259 |
|
260 d()->errorConstructor = new (exec) ErrorConstructor(exec, this, ErrorConstructor::createStructure(d()->functionPrototype), errorPrototype); |
|
261 |
|
262 RefPtr<Structure> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(errorPrototype); |
|
263 RefPtr<Structure> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype); |
|
264 d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "EvalError"); |
|
265 d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "RangeError"); |
|
266 d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "ReferenceError"); |
|
267 d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "SyntaxError"); |
|
268 d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "TypeError"); |
|
269 d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "URIError"); |
|
270 |
|
271 d()->objectPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, objectConstructor, DontEnum); |
|
272 d()->functionPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, functionConstructor, DontEnum); |
|
273 d()->arrayPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, arrayConstructor, DontEnum); |
|
274 d()->booleanPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, booleanConstructor, DontEnum); |
|
275 d()->stringPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, stringConstructor, DontEnum); |
|
276 d()->numberPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, numberConstructor, DontEnum); |
|
277 d()->datePrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, dateConstructor, DontEnum); |
|
278 d()->regExpPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum); |
|
279 errorPrototype->putDirectFunctionWithoutTransition(exec->propertyNames().constructor, d()->errorConstructor, DontEnum); |
|
280 |
|
281 // Set global constructors |
|
282 |
|
283 // FIXME: These properties could be handled by a static hash table. |
|
284 |
|
285 putDirectFunctionWithoutTransition(Identifier(exec, "Object"), objectConstructor, DontEnum); |
|
286 putDirectFunctionWithoutTransition(Identifier(exec, "Function"), functionConstructor, DontEnum); |
|
287 putDirectFunctionWithoutTransition(Identifier(exec, "Array"), arrayConstructor, DontEnum); |
|
288 putDirectFunctionWithoutTransition(Identifier(exec, "Boolean"), booleanConstructor, DontEnum); |
|
289 putDirectFunctionWithoutTransition(Identifier(exec, "String"), stringConstructor, DontEnum); |
|
290 putDirectFunctionWithoutTransition(Identifier(exec, "Number"), numberConstructor, DontEnum); |
|
291 putDirectFunctionWithoutTransition(Identifier(exec, "Date"), dateConstructor, DontEnum); |
|
292 putDirectFunctionWithoutTransition(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum); |
|
293 putDirectFunctionWithoutTransition(Identifier(exec, "Error"), d()->errorConstructor, DontEnum); |
|
294 putDirectFunctionWithoutTransition(Identifier(exec, "EvalError"), d()->evalErrorConstructor); |
|
295 putDirectFunctionWithoutTransition(Identifier(exec, "RangeError"), d()->rangeErrorConstructor); |
|
296 putDirectFunctionWithoutTransition(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor); |
|
297 putDirectFunctionWithoutTransition(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor); |
|
298 putDirectFunctionWithoutTransition(Identifier(exec, "TypeError"), d()->typeErrorConstructor); |
|
299 putDirectFunctionWithoutTransition(Identifier(exec, "URIError"), d()->URIErrorConstructor); |
|
300 |
|
301 // Set global values. |
|
302 GlobalPropertyInfo staticGlobals[] = { |
|
303 GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, this, MathObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete), |
|
304 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete | ReadOnly), |
|
305 GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete | ReadOnly), |
|
306 GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly), |
|
307 GlobalPropertyInfo(Identifier(exec, "JSON"), new (exec) JSONObject(this, JSONObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete) |
|
308 }; |
|
309 |
|
310 addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo)); |
|
311 |
|
312 // Set global functions. |
|
313 |
|
314 d()->evalFunction = new (exec) GlobalEvalFunction(exec, this, GlobalEvalFunction::createStructure(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this); |
|
315 putDirectFunctionWithoutTransition(exec, d()->evalFunction, DontEnum); |
|
316 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum); |
|
317 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum); |
|
318 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum); |
|
319 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum); |
|
320 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum); |
|
321 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum); |
|
322 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum); |
|
323 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum); |
|
324 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum); |
|
325 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum); |
|
326 #ifndef NDEBUG |
|
327 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, this, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "jscprint"), globalFuncJSCPrint), DontEnum); |
|
328 #endif |
|
329 |
|
330 resetPrototype(prototype); |
|
331 } |
|
332 |
|
333 // Set prototype, and also insert the object prototype at the end of the chain. |
|
334 void JSGlobalObject::resetPrototype(JSValue prototype) |
|
335 { |
|
336 setPrototype(prototype); |
|
337 |
|
338 JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this); |
|
339 JSObject* objectPrototype = d()->objectPrototype; |
|
340 if (oldLastInPrototypeChain != objectPrototype) |
|
341 oldLastInPrototypeChain->setPrototype(objectPrototype); |
|
342 } |
|
343 |
|
344 void JSGlobalObject::markChildren(MarkStack& markStack) |
|
345 { |
|
346 JSVariableObject::markChildren(markStack); |
|
347 |
|
348 HashSet<GlobalCodeBlock*>::const_iterator end = codeBlocks().end(); |
|
349 for (HashSet<GlobalCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it) |
|
350 (*it)->markAggregate(markStack); |
|
351 |
|
352 RegisterFile& registerFile = globalData()->interpreter->registerFile(); |
|
353 if (registerFile.globalObject() == this) |
|
354 registerFile.markGlobals(markStack, &globalData()->heap); |
|
355 |
|
356 markIfNeeded(markStack, d()->regExpConstructor); |
|
357 markIfNeeded(markStack, d()->errorConstructor); |
|
358 markIfNeeded(markStack, d()->evalErrorConstructor); |
|
359 markIfNeeded(markStack, d()->rangeErrorConstructor); |
|
360 markIfNeeded(markStack, d()->referenceErrorConstructor); |
|
361 markIfNeeded(markStack, d()->syntaxErrorConstructor); |
|
362 markIfNeeded(markStack, d()->typeErrorConstructor); |
|
363 markIfNeeded(markStack, d()->URIErrorConstructor); |
|
364 |
|
365 markIfNeeded(markStack, d()->evalFunction); |
|
366 markIfNeeded(markStack, d()->callFunction); |
|
367 markIfNeeded(markStack, d()->applyFunction); |
|
368 |
|
369 markIfNeeded(markStack, d()->objectPrototype); |
|
370 markIfNeeded(markStack, d()->functionPrototype); |
|
371 markIfNeeded(markStack, d()->arrayPrototype); |
|
372 markIfNeeded(markStack, d()->booleanPrototype); |
|
373 markIfNeeded(markStack, d()->stringPrototype); |
|
374 markIfNeeded(markStack, d()->numberPrototype); |
|
375 markIfNeeded(markStack, d()->datePrototype); |
|
376 markIfNeeded(markStack, d()->regExpPrototype); |
|
377 |
|
378 markIfNeeded(markStack, d()->methodCallDummy); |
|
379 |
|
380 markIfNeeded(markStack, d()->errorStructure); |
|
381 markIfNeeded(markStack, d()->argumentsStructure); |
|
382 markIfNeeded(markStack, d()->arrayStructure); |
|
383 markIfNeeded(markStack, d()->booleanObjectStructure); |
|
384 markIfNeeded(markStack, d()->callbackConstructorStructure); |
|
385 markIfNeeded(markStack, d()->callbackFunctionStructure); |
|
386 markIfNeeded(markStack, d()->callbackObjectStructure); |
|
387 markIfNeeded(markStack, d()->dateStructure); |
|
388 markIfNeeded(markStack, d()->emptyObjectStructure); |
|
389 markIfNeeded(markStack, d()->errorStructure); |
|
390 markIfNeeded(markStack, d()->functionStructure); |
|
391 markIfNeeded(markStack, d()->numberObjectStructure); |
|
392 markIfNeeded(markStack, d()->prototypeFunctionStructure); |
|
393 markIfNeeded(markStack, d()->regExpMatchesArrayStructure); |
|
394 markIfNeeded(markStack, d()->regExpStructure); |
|
395 markIfNeeded(markStack, d()->stringObjectStructure); |
|
396 |
|
397 // No need to mark the other structures, because their prototypes are all |
|
398 // guaranteed to be referenced elsewhere. |
|
399 |
|
400 Register* registerArray = d()->registerArray.get(); |
|
401 if (!registerArray) |
|
402 return; |
|
403 |
|
404 size_t size = d()->registerArraySize; |
|
405 markStack.appendValues(reinterpret_cast<JSValue*>(registerArray), size); |
|
406 } |
|
407 |
|
408 ExecState* JSGlobalObject::globalExec() |
|
409 { |
|
410 return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize); |
|
411 } |
|
412 |
|
413 bool JSGlobalObject::isDynamicScope(bool&) const |
|
414 { |
|
415 return true; |
|
416 } |
|
417 |
|
418 void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile) |
|
419 { |
|
420 ASSERT(!d()->registerArray); |
|
421 ASSERT(!d()->registerArraySize); |
|
422 |
|
423 int numGlobals = registerFile.numGlobals(); |
|
424 if (!numGlobals) { |
|
425 d()->registers = 0; |
|
426 return; |
|
427 } |
|
428 |
|
429 Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals); |
|
430 setRegisters(registerArray + numGlobals, registerArray, numGlobals); |
|
431 } |
|
432 |
|
433 void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile) |
|
434 { |
|
435 JSGlobalObject* lastGlobalObject = registerFile.globalObject(); |
|
436 if (lastGlobalObject && lastGlobalObject != this) |
|
437 lastGlobalObject->copyGlobalsFrom(registerFile); |
|
438 |
|
439 registerFile.setGlobalObject(this); |
|
440 registerFile.setNumGlobals(symbolTable().size()); |
|
441 |
|
442 if (d()->registerArray) { |
|
443 memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register)); |
|
444 setRegisters(registerFile.start(), 0, 0); |
|
445 } |
|
446 } |
|
447 |
|
448 void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData) |
|
449 { |
|
450 return globalData->heap.allocate(size); |
|
451 } |
|
452 |
|
453 void JSGlobalObject::destroyJSGlobalObjectData(void* jsGlobalObjectData) |
|
454 { |
|
455 delete static_cast<JSGlobalObjectData*>(jsGlobalObjectData); |
|
456 } |
|
457 |
|
458 } // namespace JSC |