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