De-virtualize JSVariableObject::isDynamicScope
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
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 "Error.h"
46 #include "ErrorConstructor.h"
47 #include "ErrorPrototype.h"
48 #include "FunctionConstructor.h"
49 #include "FunctionPrototype.h"
50 #include "GetterSetter.h"
51 #include "JSBoundFunction.h"
52 #include "JSFunction.h"
53 #include "JSGlobalObjectFunctions.h"
54 #include "JSLock.h"
55 #include "JSONObject.h"
56 #include "Interpreter.h"
57 #include "Lookup.h"
58 #include "MathObject.h"
59 #include "NativeErrorConstructor.h"
60 #include "NativeErrorPrototype.h"
61 #include "NumberConstructor.h"
62 #include "NumberPrototype.h"
63 #include "ObjectConstructor.h"
64 #include "ObjectPrototype.h"
65 #include "Profiler.h"
66 #include "RegExpConstructor.h"
67 #include "RegExpMatchesArray.h"
68 #include "RegExpObject.h"
69 #include "RegExpPrototype.h"
70 #include "ScopeChainMark.h"
71 #include "StringConstructor.h"
72 #include "StringPrototype.h"
73 #include "Debugger.h"
74
75 #include "JSGlobalObject.lut.h"
76
77 namespace JSC {
78
79 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &JSVariableObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
80
81 /* Source for JSGlobalObject.lut.h
82 @begin globalObjectTable
83   parseInt              globalFuncParseInt              DontEnum|Function 2
84   parseFloat            globalFuncParseFloat            DontEnum|Function 1
85   isNaN                 globalFuncIsNaN                 DontEnum|Function 1
86   isFinite              globalFuncIsFinite              DontEnum|Function 1
87   escape                globalFuncEscape                DontEnum|Function 1
88   unescape              globalFuncUnescape              DontEnum|Function 1
89   decodeURI             globalFuncDecodeURI             DontEnum|Function 1
90   decodeURIComponent    globalFuncDecodeURIComponent    DontEnum|Function 1
91   encodeURI             globalFuncEncodeURI             DontEnum|Function 1
92   encodeURIComponent    globalFuncEncodeURIComponent    DontEnum|Function 1
93 @end
94 */
95
96 ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
97
98 // Default number of ticks before a timeout check should be done.
99 static const int initialTickCountThreshold = 255;
100
101 // Preferred number of milliseconds between each timeout check
102 static const int preferredScriptCheckTimeInterval = 1000;
103
104 template <typename T> static inline void visitIfNeeded(SlotVisitor& visitor, WriteBarrier<T>* v)
105 {
106     if (*v)
107         visitor.append(v);
108 }
109
110 JSGlobalObject::~JSGlobalObject()
111 {
112     ASSERT(JSLock::currentThreadIsHoldingLock());
113
114     if (m_debugger)
115         m_debugger->detach(this);
116
117     Profiler** profiler = Profiler::enabledProfilerReference();
118     if (UNLIKELY(*profiler != 0)) {
119         (*profiler)->stopProfiling(this);
120     }
121 }
122
123 void JSGlobalObject::init(JSObject* thisValue)
124 {
125     ASSERT(JSLock::currentThreadIsHoldingLock());
126     
127     structure()->disableSpecificFunctionTracking();
128
129     m_globalData = Heap::heap(this)->globalData();
130     m_globalScopeChain.set(*m_globalData, this, ScopeChainNode::create(0, this, m_globalData.get(), this, thisValue));
131
132     JSGlobalObject::globalExec()->init(0, 0, m_globalScopeChain.get(), CallFrame::noCaller(), 0, 0);
133
134     m_debugger = 0;
135
136     reset(prototype());
137 }
138
139 void JSGlobalObject::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
140 {
141     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(cell);
142     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
143
144     if (thisObject->symbolTablePut(exec->globalData(), propertyName, value))
145         return;
146     JSVariableObject::put(thisObject, exec, propertyName, value, slot);
147 }
148
149 void JSGlobalObject::putWithAttributes(JSObject* object, ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
150 {
151     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(object);
152     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
153
154     if (thisObject->symbolTablePutWithAttributes(exec->globalData(), propertyName, value, attributes))
155         return;
156
157     JSValue valueBefore = thisObject->getDirect(exec->globalData(), propertyName);
158     PutPropertySlot slot;
159     JSVariableObject::put(thisObject, exec, propertyName, value, slot);
160     if (!valueBefore) {
161         JSValue valueAfter = thisObject->getDirect(exec->globalData(), propertyName);
162         if (valueAfter)
163             JSObject::putWithAttributes(thisObject, exec, propertyName, valueAfter, attributes);
164     }
165 }
166
167 void JSGlobalObject::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes)
168 {
169     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(object);
170     PropertySlot slot;
171     if (!thisObject->symbolTableGet(propertyName, slot))
172         JSVariableObject::defineGetter(thisObject, exec, propertyName, getterFunc, attributes);
173 }
174
175 void JSGlobalObject::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes)
176 {
177     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(object);
178     PropertySlot slot;
179     if (!thisObject->symbolTableGet(propertyName, slot))
180         JSVariableObject::defineSetter(thisObject, exec, propertyName, setterFunc, attributes);
181 }
182
183 static inline JSObject* lastInPrototypeChain(JSObject* object)
184 {
185     JSObject* o = object;
186     while (o->prototype().isObject())
187         o = asObject(o->prototype());
188     return o;
189 }
190
191 void JSGlobalObject::reset(JSValue prototype)
192 {
193     ExecState* exec = JSGlobalObject::globalExec();
194
195     m_functionPrototype.set(exec->globalData(), this, FunctionPrototype::create(exec, this, FunctionPrototype::createStructure(exec->globalData(), this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
196     m_functionStructure.set(exec->globalData(), this, JSFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
197     m_boundFunctionStructure.set(exec->globalData(), this, JSBoundFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
198     m_namedFunctionStructure.set(exec->globalData(), this, Structure::addPropertyTransition(exec->globalData(), m_functionStructure.get(), exec->globalData().propertyNames->name, DontDelete | ReadOnly | DontEnum, 0, m_functionNameOffset));
199     m_internalFunctionStructure.set(exec->globalData(), this, InternalFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
200     m_strictModeTypeErrorFunctionStructure.set(exec->globalData(), this, StrictModeTypeErrorFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
201     JSFunction* callFunction = 0;
202     JSFunction* applyFunction = 0;
203     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
204     m_callFunction.set(exec->globalData(), this, callFunction);
205     m_applyFunction.set(exec->globalData(), this, applyFunction);
206     m_objectPrototype.set(exec->globalData(), this, ObjectPrototype::create(exec, this, ObjectPrototype::createStructure(exec->globalData(), this, jsNull())));
207     m_functionPrototype->structure()->setPrototypeWithoutTransition(exec->globalData(), m_objectPrototype.get());
208
209     m_emptyObjectStructure.set(exec->globalData(), this, m_objectPrototype->inheritorID(exec->globalData()));
210     m_nullPrototypeObjectStructure.set(exec->globalData(), this, createEmptyObjectStructure(exec->globalData(), this, jsNull()));
211
212     m_callbackFunctionStructure.set(exec->globalData(), this, JSCallbackFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
213     m_argumentsStructure.set(exec->globalData(), this, Arguments::createStructure(exec->globalData(), this, m_objectPrototype.get()));
214     m_callbackConstructorStructure.set(exec->globalData(), this, JSCallbackConstructor::createStructure(exec->globalData(), this, m_objectPrototype.get()));
215     m_callbackObjectStructure.set(exec->globalData(), this, JSCallbackObject<JSNonFinalObject>::createStructure(exec->globalData(), this, m_objectPrototype.get()));
216
217     m_arrayPrototype.set(exec->globalData(), this, ArrayPrototype::create(exec, this, ArrayPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
218     m_arrayStructure.set(exec->globalData(), this, JSArray::createStructure(exec->globalData(), this, m_arrayPrototype.get()));
219     m_regExpMatchesArrayStructure.set(exec->globalData(), this, RegExpMatchesArray::createStructure(exec->globalData(), this, m_arrayPrototype.get()));
220
221     m_stringPrototype.set(exec->globalData(), this, StringPrototype::create(exec, this, StringPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
222     m_stringObjectStructure.set(exec->globalData(), this, StringObject::createStructure(exec->globalData(), this, m_stringPrototype.get()));
223
224     m_booleanPrototype.set(exec->globalData(), this, BooleanPrototype::create(exec, this, BooleanPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
225     m_booleanObjectStructure.set(exec->globalData(), this, BooleanObject::createStructure(exec->globalData(), this, m_booleanPrototype.get()));
226
227     m_numberPrototype.set(exec->globalData(), this, NumberPrototype::create(exec, this, NumberPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
228     m_numberObjectStructure.set(exec->globalData(), this, NumberObject::createStructure(exec->globalData(), this, m_numberPrototype.get()));
229
230     m_datePrototype.set(exec->globalData(), this, DatePrototype::create(exec, this, DatePrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
231     m_dateStructure.set(exec->globalData(), this, DateInstance::createStructure(exec->globalData(), this, m_datePrototype.get()));
232
233     RegExp* emptyRegex = RegExp::create(exec->globalData(), "", NoFlags);
234     
235     m_regExpPrototype.set(exec->globalData(), this, RegExpPrototype::create(exec, this, RegExpPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get()), emptyRegex));
236     m_regExpStructure.set(exec->globalData(), this, RegExpObject::createStructure(exec->globalData(), this, m_regExpPrototype.get()));
237
238     m_methodCallDummy.set(exec->globalData(), this, constructEmptyObject(exec));
239
240     ErrorPrototype* errorPrototype = ErrorPrototype::create(exec, this, ErrorPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get()));
241     m_errorStructure.set(exec->globalData(), this, ErrorInstance::createStructure(exec->globalData(), this, errorPrototype));
242
243     // Constructors
244
245     JSCell* objectConstructor = ObjectConstructor::create(exec, this, ObjectConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_objectPrototype.get());
246     JSCell* functionConstructor = FunctionConstructor::create(exec, this, FunctionConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_functionPrototype.get());
247     JSCell* arrayConstructor = ArrayConstructor::create(exec, this, ArrayConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_arrayPrototype.get());
248     JSCell* stringConstructor = StringConstructor::create(exec, this, StringConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_stringPrototype.get());
249     JSCell* booleanConstructor = BooleanConstructor::create(exec, this, BooleanConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_booleanPrototype.get());
250     JSCell* numberConstructor = NumberConstructor::create(exec, this, NumberConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_numberPrototype.get());
251     JSCell* dateConstructor = DateConstructor::create(exec, this, DateConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_datePrototype.get());
252
253     m_regExpConstructor.set(exec->globalData(), this, RegExpConstructor::create(exec, this, RegExpConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_regExpPrototype.get()));
254
255     m_errorConstructor.set(exec->globalData(), this, ErrorConstructor::create(exec, this, ErrorConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), errorPrototype));
256
257     Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(exec->globalData(), this, errorPrototype);
258     Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get());
259     m_evalErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "EvalError"));
260     m_rangeErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "RangeError"));
261     m_referenceErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "ReferenceError"));
262     m_syntaxErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "SyntaxError"));
263     m_typeErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "TypeError"));
264     m_URIErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "URIError"));
265
266     m_objectPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, objectConstructor, DontEnum);
267     m_functionPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, functionConstructor, DontEnum);
268     m_arrayPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, arrayConstructor, DontEnum);
269     m_booleanPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, booleanConstructor, DontEnum);
270     m_stringPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, stringConstructor, DontEnum);
271     m_numberPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, numberConstructor, DontEnum);
272     m_datePrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, dateConstructor, DontEnum);
273     m_regExpPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_regExpConstructor.get(), DontEnum);
274     errorPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_errorConstructor.get(), DontEnum);
275
276     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Object"), objectConstructor, DontEnum);
277     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Function"), functionConstructor, DontEnum);
278     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Array"), arrayConstructor, DontEnum);
279     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
280     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "String"), stringConstructor, DontEnum);
281     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Number"), numberConstructor, DontEnum);
282     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Date"), dateConstructor, DontEnum);
283     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "RegExp"), m_regExpConstructor.get(), DontEnum);
284     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Error"), m_errorConstructor.get(), DontEnum);
285     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "EvalError"), m_evalErrorConstructor.get(), DontEnum);
286     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "RangeError"), m_rangeErrorConstructor.get(), DontEnum);
287     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "ReferenceError"), m_referenceErrorConstructor.get(), DontEnum);
288     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "SyntaxError"), m_syntaxErrorConstructor.get(), DontEnum);
289     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "TypeError"), m_typeErrorConstructor.get(), DontEnum);
290     putDirectWithoutTransition(exec->globalData(), Identifier(exec, "URIError"), m_URIErrorConstructor.get(), DontEnum);
291
292     m_evalFunction.set(exec->globalData(), this, JSFunction::create(exec, this, 1, exec->propertyNames().eval, globalFuncEval));
293     putDirectWithoutTransition(exec->globalData(), exec->propertyNames().eval, m_evalFunction.get(), DontEnum);
294
295     GlobalPropertyInfo staticGlobals[] = {
296         GlobalPropertyInfo(Identifier(exec, "Math"), MathObject::create(exec, this, MathObject::createStructure(exec->globalData(), this, m_objectPrototype.get())), DontEnum | DontDelete),
297         GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(), DontEnum | DontDelete | ReadOnly),
298         GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
299         GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly),
300         GlobalPropertyInfo(Identifier(exec, "JSON"), JSONObject::create(exec, this, JSONObject::createStructure(exec->globalData(), this, m_objectPrototype.get())), DontEnum | DontDelete)
301     };
302     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
303
304     resetPrototype(exec->globalData(), prototype);
305 }
306
307 void JSGlobalObject::createThrowTypeError(ExecState* exec)
308 {
309     JSFunction* thrower = JSFunction::create(exec, this, 0, Identifier(), globalFuncThrowTypeError);
310     GetterSetter* getterSetter = GetterSetter::create(exec);
311     getterSetter->setGetter(exec->globalData(), thrower);
312     getterSetter->setSetter(exec->globalData(), thrower);
313     m_throwTypeErrorGetterSetter.set(exec->globalData(), this, getterSetter);
314 }
315
316 // Set prototype, and also insert the object prototype at the end of the chain.
317 void JSGlobalObject::resetPrototype(JSGlobalData& globalData, JSValue prototype)
318 {
319     setPrototype(globalData, prototype);
320
321     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
322     JSObject* objectPrototype = m_objectPrototype.get();
323     if (oldLastInPrototypeChain != objectPrototype)
324         oldLastInPrototypeChain->setPrototype(globalData, objectPrototype);
325 }
326
327 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
328
329     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(cell);
330     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
331     COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
332     ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
333     JSVariableObject::visitChildren(thisObject, visitor);
334
335     visitIfNeeded(visitor, &thisObject->m_globalScopeChain);
336     visitIfNeeded(visitor, &thisObject->m_methodCallDummy);
337
338     visitIfNeeded(visitor, &thisObject->m_regExpConstructor);
339     visitIfNeeded(visitor, &thisObject->m_errorConstructor);
340     visitIfNeeded(visitor, &thisObject->m_evalErrorConstructor);
341     visitIfNeeded(visitor, &thisObject->m_rangeErrorConstructor);
342     visitIfNeeded(visitor, &thisObject->m_referenceErrorConstructor);
343     visitIfNeeded(visitor, &thisObject->m_syntaxErrorConstructor);
344     visitIfNeeded(visitor, &thisObject->m_typeErrorConstructor);
345     visitIfNeeded(visitor, &thisObject->m_URIErrorConstructor);
346
347     visitIfNeeded(visitor, &thisObject->m_evalFunction);
348     visitIfNeeded(visitor, &thisObject->m_callFunction);
349     visitIfNeeded(visitor, &thisObject->m_applyFunction);
350     visitIfNeeded(visitor, &thisObject->m_throwTypeErrorGetterSetter);
351
352     visitIfNeeded(visitor, &thisObject->m_objectPrototype);
353     visitIfNeeded(visitor, &thisObject->m_functionPrototype);
354     visitIfNeeded(visitor, &thisObject->m_arrayPrototype);
355     visitIfNeeded(visitor, &thisObject->m_booleanPrototype);
356     visitIfNeeded(visitor, &thisObject->m_stringPrototype);
357     visitIfNeeded(visitor, &thisObject->m_numberPrototype);
358     visitIfNeeded(visitor, &thisObject->m_datePrototype);
359     visitIfNeeded(visitor, &thisObject->m_regExpPrototype);
360
361     visitIfNeeded(visitor, &thisObject->m_argumentsStructure);
362     visitIfNeeded(visitor, &thisObject->m_arrayStructure);
363     visitIfNeeded(visitor, &thisObject->m_booleanObjectStructure);
364     visitIfNeeded(visitor, &thisObject->m_callbackConstructorStructure);
365     visitIfNeeded(visitor, &thisObject->m_callbackFunctionStructure);
366     visitIfNeeded(visitor, &thisObject->m_callbackObjectStructure);
367     visitIfNeeded(visitor, &thisObject->m_dateStructure);
368     visitIfNeeded(visitor, &thisObject->m_emptyObjectStructure);
369     visitIfNeeded(visitor, &thisObject->m_nullPrototypeObjectStructure);
370     visitIfNeeded(visitor, &thisObject->m_errorStructure);
371     visitIfNeeded(visitor, &thisObject->m_functionStructure);
372     visitIfNeeded(visitor, &thisObject->m_boundFunctionStructure);
373     visitIfNeeded(visitor, &thisObject->m_namedFunctionStructure);
374     visitIfNeeded(visitor, &thisObject->m_numberObjectStructure);
375     visitIfNeeded(visitor, &thisObject->m_regExpMatchesArrayStructure);
376     visitIfNeeded(visitor, &thisObject->m_regExpStructure);
377     visitIfNeeded(visitor, &thisObject->m_stringObjectStructure);
378     visitIfNeeded(visitor, &thisObject->m_internalFunctionStructure);
379     visitIfNeeded(visitor, &thisObject->m_strictModeTypeErrorFunctionStructure);
380
381     if (thisObject->m_registerArray) {
382         // Outside the execution of global code, when our variables are torn off,
383         // we can mark the torn-off array.
384         visitor.appendValues(thisObject->m_registerArray.get(), thisObject->m_registerArraySize);
385     } else if (thisObject->m_registers) {
386         // During execution of global code, when our variables are in the register file,
387         // the symbol table tells us how many variables there are, and registers
388         // points to where they end, and the registers used for execution begin.
389         visitor.appendValues(thisObject->m_registers - thisObject->symbolTable().size(), thisObject->symbolTable().size());
390     }
391 }
392
393 ExecState* JSGlobalObject::globalExec()
394 {
395     return CallFrame::create(m_globalCallFrame + RegisterFile::CallFrameHeaderSize);
396 }
397
398 void JSGlobalObject::resizeRegisters(size_t newSize)
399 {
400     // Previous duplicate symbols may have created spare capacity in m_registerArray.
401     if (newSize <= m_registerArraySize)
402         return;
403
404     size_t oldSize = m_registerArraySize;
405     OwnArrayPtr<WriteBarrier<Unknown> > registerArray = adoptArrayPtr(new WriteBarrier<Unknown>[newSize]);
406     for (size_t i = 0; i < oldSize; ++i)
407         registerArray[i].set(globalData(), this, m_registerArray[i].get());
408     for (size_t i = oldSize; i < newSize; ++i)
409         registerArray[i].setUndefined();
410
411     WriteBarrier<Unknown>* registers = registerArray.get();
412     setRegisters(registers, registerArray.release(), newSize);
413 }
414
415 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
416 {
417     resizeRegisters(symbolTable().size() + count);
418
419     for (int i = 0; i < count; ++i) {
420         GlobalPropertyInfo& global = globals[i];
421         ASSERT(global.attributes & DontDelete);
422         
423         int index = symbolTable().size();
424         SymbolTableEntry newEntry(index, global.attributes);
425         symbolTable().add(global.identifier.impl(), newEntry);
426         registerAt(index).set(globalData(), this, global.value);
427     }
428 }
429
430 bool JSGlobalObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
431 {
432     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(cell);
433     if (getStaticFunctionSlot<JSVariableObject>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, slot))
434         return true;
435     return thisObject->symbolTableGet(propertyName, slot);
436 }
437
438 bool JSGlobalObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
439 {
440     JSGlobalObject* thisObject = static_cast<JSGlobalObject*>(object);
441     if (getStaticFunctionDescriptor<JSVariableObject>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, descriptor))
442         return true;
443     return thisObject->symbolTableGet(propertyName, descriptor);
444 }
445
446 void JSGlobalObject::clearRareData(JSCell* cell)
447 {
448     static_cast<JSGlobalObject*>(cell)->m_rareData.clear();
449 }
450
451 DynamicGlobalObjectScope::DynamicGlobalObjectScope(JSGlobalData& globalData, JSGlobalObject* dynamicGlobalObject)
452     : m_dynamicGlobalObjectSlot(globalData.dynamicGlobalObject)
453     , m_savedDynamicGlobalObject(m_dynamicGlobalObjectSlot)
454 {
455     if (!m_dynamicGlobalObjectSlot) {
456 #if ENABLE(ASSEMBLER)
457         if (ExecutableAllocator::underMemoryPressure())
458             globalData.recompileAllJSFunctions();
459 #endif
460
461         m_dynamicGlobalObjectSlot = dynamicGlobalObject;
462
463         // Reset the date cache between JS invocations to force the VM
464         // to observe time zone changes.
465         globalData.resetDateCache();
466     }
467 }
468
469 void slowValidateCell(JSGlobalObject* globalObject)
470 {
471     if (!globalObject->isGlobalObject())
472         CRASH();
473     ASSERT_GC_OBJECT_INHERITS(globalObject, &JSGlobalObject::s_info);
474 }
475
476 } // namespace JSC