d9f3ad5725a9498b46e057af485d6eb5b0d4f133
[WebKit-https.git] / JavaScriptCore / kjs / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007, 2008 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 "JSGlobalObjectFunctions.h"
51 #include "JSLock.h"
52 #include "Machine.h"
53 #include "MathObject.h"
54 #include "NativeErrorConstructor.h"
55 #include "NativeErrorPrototype.h"
56 #include "NumberConstructor.h"
57 #include "NumberPrototype.h"
58 #include "ObjectConstructor.h"
59 #include "ObjectPrototype.h"
60 #include "Profiler.h"
61 #include "PrototypeFunction.h"
62 #include "RegExpConstructor.h"
63 #include "RegExpMatchesArray.h"
64 #include "RegExpObject.h"
65 #include "RegExpPrototype.h"
66 #include "ScopeChainMark.h"
67 #include "StringConstructor.h"
68 #include "StringPrototype.h"
69 #include "debugger.h"
70
71 namespace JSC {
72
73 ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
74
75 // Default number of ticks before a timeout check should be done.
76 static const int initialTickCountThreshold = 255;
77
78 // Preferred number of milliseconds between each timeout check
79 static const int preferredScriptCheckTimeInterval = 1000;
80
81 static inline void markIfNeeded(JSValue* v)
82 {
83     if (v && !v->marked())
84         v->mark();
85 }
86
87 static inline void markIfNeeded(const RefPtr<StructureID>& s)
88 {
89     if (s)
90         s->mark();
91 }
92
93 JSGlobalObject::~JSGlobalObject()
94 {
95     ASSERT(JSLock::currentThreadIsHoldingLock());
96
97     if (d()->debugger)
98         d()->debugger->detach(this);
99
100     Profiler** profiler = Profiler::enabledProfilerReference();
101     if (UNLIKELY(*profiler != 0)) {
102         (*profiler)->stopProfiling(globalExec(), UString());
103     }
104
105     d()->next->d()->prev = d()->prev;
106     d()->prev->d()->next = d()->next;
107     JSGlobalObject*& headObject = head();
108     if (headObject == this)
109         headObject = d()->next;
110     if (headObject == this)
111         headObject = 0;
112
113     HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
114     for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
115         (*it)->globalObject = 0;
116         
117     RegisterFile& registerFile = globalData()->machine->registerFile();
118     if (registerFile.globalObject() == this) {
119         registerFile.setGlobalObject(0);
120         registerFile.setNumGlobals(0);
121     }
122     delete d();
123 }
124
125 void JSGlobalObject::init(JSObject* thisValue)
126 {
127     ASSERT(JSLock::currentThreadIsHoldingLock());
128
129     d()->globalData = Heap::heap(this)->globalData();
130
131     if (JSGlobalObject*& headObject = head()) {
132         d()->prev = headObject;
133         d()->next = headObject->d()->next;
134         headObject->d()->next->d()->prev = this;
135         headObject->d()->next = this;
136     } else
137         headObject = d()->next = d()->prev = this;
138
139     d()->recursion = 0;
140     d()->debugger = 0;
141     globalData()->machine->initTimeout();
142
143     d()->globalExec.set(new ExecState(this, thisValue, d()->globalScopeChain.node()));
144
145     d()->profileGroup = 0;
146
147     reset(prototype());
148 }
149
150 void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
151 {
152     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
153
154     if (symbolTablePut(propertyName, value))
155         return;
156     JSVariableObject::put(exec, propertyName, value, slot);
157 }
158
159 void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
160 {
161     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
162
163     if (symbolTablePutWithAttributes(propertyName, value, attributes))
164         return;
165
166     JSValue* valueBefore = getDirect(propertyName);
167     PutPropertySlot slot;
168     JSVariableObject::put(exec, propertyName, value, slot);
169     if (!valueBefore) {
170         if (JSValue* valueAfter = getDirect(propertyName))
171             putDirect(propertyName, valueAfter, attributes);
172     }
173 }
174
175 void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
176 {
177     PropertySlot slot;
178     if (!symbolTableGet(propertyName, slot))
179         JSVariableObject::defineGetter(exec, propertyName, getterFunc);
180 }
181
182 void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
183 {
184     PropertySlot slot;
185     if (!symbolTableGet(propertyName, slot))
186         JSVariableObject::defineSetter(exec, propertyName, setterFunc);
187 }
188
189 static inline JSObject* lastInPrototypeChain(JSObject* object)
190 {
191     JSObject* o = object;
192     while (o->prototype()->isObject())
193         o = static_cast<JSObject*>(o->prototype());
194     return o;
195 }
196
197 void JSGlobalObject::reset(JSValue* prototype)
198 {
199     // Clear before inititalizing, to avoid calling mark() on stale pointers --
200     // which would be wasteful -- or uninitialized pointers -- which would be
201     // dangerous. (The allocations below may cause a GC.)
202
203     ASSERT(!hasCustomProperties());
204     symbolTable().clear();
205     setRegisters(0, 0, 0);
206
207     ExecState* exec = d()->globalExec.get();
208
209     // Prototypes
210
211     d()->functionPrototype = new (exec) FunctionPrototype(exec);
212     d()->functionStructure = JSFunction::createStructureID(d()->functionPrototype);
213     d()->callbackFunctionStructure = JSCallbackFunction::createStructureID(d()->functionPrototype);
214     d()->prototypeFunctionStructure = PrototypeFunction::createStructureID(d()->functionPrototype);
215     d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get());
216     d()->objectPrototype = new (exec) ObjectPrototype(exec, d()->prototypeFunctionStructure.get());
217     d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
218     d()->functionPrototype->setPrototype(d()->objectPrototype);
219     d()->argumentsStructure = Arguments::createStructureID(d()->objectPrototype);
220     d()->callbackConstructorStructure = JSCallbackConstructor::createStructureID(d()->objectPrototype);
221     d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructureID(d()->objectPrototype);
222     d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructureID(d()->objectPrototype));
223     d()->arrayStructure = JSArray::createStructureID(d()->arrayPrototype);
224     d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructureID(d()->arrayPrototype);
225     d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructureID(d()->objectPrototype));
226     d()->stringObjectStructure = StringObject::createStructureID(d()->stringPrototype);
227     d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
228     d()->booleanObjectStructure = BooleanObject::createStructureID(d()->booleanPrototype);
229     d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
230     d()->numberObjectStructure = NumberObject::createStructureID(d()->numberPrototype);
231     d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructureID(d()->objectPrototype));
232     d()->dateStructure = DateInstance::createStructureID(d()->datePrototype);
233     d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
234     d()->regExpStructure = RegExpObject::createStructureID(d()->regExpPrototype);
235     ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
236     d()->errorStructure = ErrorInstance::createStructureID(errorPrototype);
237
238     RefPtr<StructureID> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructureID(errorPrototype);
239
240     NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError");
241     NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError");
242     NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError");
243     NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError");
244     NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError");
245     NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError");
246
247     // Constructors
248
249     JSValue* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructureID(d()->functionPrototype), d()->objectPrototype);
250     JSValue* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructureID(d()->functionPrototype), d()->functionPrototype);
251     JSValue* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructureID(d()->functionPrototype), d()->arrayPrototype);
252     JSValue* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructureID(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
253     JSValue* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructureID(d()->functionPrototype), d()->booleanPrototype);
254     JSValue* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructureID(d()->functionPrototype), d()->numberPrototype);
255     JSValue* dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructureID(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
256
257     d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructureID(d()->functionPrototype), d()->regExpPrototype);
258
259     d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructureID(d()->functionPrototype), errorPrototype);
260
261     RefPtr<StructureID> nativeErrorStructure = NativeErrorConstructor::createStructureID(d()->functionPrototype);
262
263     d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
264     d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
265     d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype);
266     d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype);
267     d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype);
268     d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype);
269     
270     d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
271
272     d()->objectPrototype->putDirect(exec->propertyNames().constructor, objectConstructor, DontEnum);
273     d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
274     d()->arrayPrototype->putDirect(exec->propertyNames().constructor, arrayConstructor, DontEnum);
275     d()->booleanPrototype->putDirect(exec->propertyNames().constructor, booleanConstructor, DontEnum);
276     d()->stringPrototype->putDirect(exec->propertyNames().constructor, stringConstructor, DontEnum);
277     d()->numberPrototype->putDirect(exec->propertyNames().constructor, numberConstructor, DontEnum);
278     d()->datePrototype->putDirect(exec->propertyNames().constructor, dateConstructor, DontEnum);
279     d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
280     errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
281     evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
282     rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
283     referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
284     syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
285     typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
286     URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
287
288     // Set global constructors
289
290     // FIXME: These properties could be handled by a static hash table.
291
292     putDirect(Identifier(exec, "Object"), objectConstructor, DontEnum);
293     putDirect(Identifier(exec, "Function"), functionConstructor, DontEnum);
294     putDirect(Identifier(exec, "Array"), arrayConstructor, DontEnum);
295     putDirect(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
296     putDirect(Identifier(exec, "String"), stringConstructor, DontEnum);
297     putDirect(Identifier(exec, "Number"), numberConstructor, DontEnum);
298     putDirect(Identifier(exec, "Date"), dateConstructor, DontEnum);
299     putDirect(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
300     putDirect(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
301     putDirect(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
302     putDirect(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
303     putDirect(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
304     putDirect(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
305     putDirect(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
306     putDirect(Identifier(exec, "URIError"), d()->URIErrorConstructor);
307
308     // Set global values.
309     GlobalPropertyInfo staticGlobals[] = {
310         GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructureID(d()->objectPrototype)), DontEnum | DontDelete),
311         GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
312         GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
313         GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
314     };
315
316     addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
317
318     // Set global functions.
319
320     d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructureID(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
321     putDirectFunction(exec, d()->evalFunction, DontEnum);
322     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
323     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
324     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
325     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
326     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
327     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
328     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
329     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
330     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
331     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
332 #ifndef NDEBUG
333     putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
334 #endif
335
336     resetPrototype(prototype);
337 }
338
339 // Set prototype, and also insert the object prototype at the end of the chain.
340 void JSGlobalObject::resetPrototype(JSValue* prototype)
341 {
342     setPrototype(prototype);
343     lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
344 }
345
346 void JSGlobalObject::setTimeoutTime(unsigned timeoutTime)
347 {
348     globalData()->machine->setTimeoutTime(timeoutTime);
349 }
350
351 void JSGlobalObject::startTimeoutCheck()
352 {
353     globalData()->machine->startTimeoutCheck();
354 }
355
356 void JSGlobalObject::stopTimeoutCheck()
357 {
358     globalData()->machine->stopTimeoutCheck();
359 }
360
361 void JSGlobalObject::mark()
362 {
363     JSVariableObject::mark();
364     
365     HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
366     for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
367         (*it)->mark();
368
369     RegisterFile& registerFile = globalData()->machine->registerFile();
370     if (registerFile.globalObject() == this)
371         registerFile.markGlobals(globalData()->heap);
372
373     markIfNeeded(d()->globalExec->exception());
374
375     markIfNeeded(d()->regExpConstructor);
376     markIfNeeded(d()->errorConstructor);
377     markIfNeeded(d()->evalErrorConstructor);
378     markIfNeeded(d()->rangeErrorConstructor);
379     markIfNeeded(d()->referenceErrorConstructor);
380     markIfNeeded(d()->syntaxErrorConstructor);
381     markIfNeeded(d()->typeErrorConstructor);
382     markIfNeeded(d()->URIErrorConstructor);
383
384     markIfNeeded(d()->evalFunction);
385
386     markIfNeeded(d()->objectPrototype);
387     markIfNeeded(d()->functionPrototype);
388     markIfNeeded(d()->arrayPrototype);
389     markIfNeeded(d()->booleanPrototype);
390     markIfNeeded(d()->stringPrototype);
391     markIfNeeded(d()->numberPrototype);
392     markIfNeeded(d()->datePrototype);
393     markIfNeeded(d()->regExpPrototype);
394
395     markIfNeeded(d()->errorStructure);
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     for (size_t i = 0; i < size; ++i) {
406         Register& r = registerArray[i];
407         if (!r.marked())
408             r.mark();
409     }
410 }
411
412 JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
413 {
414     return const_cast<JSGlobalObject*>(this);
415 }
416
417 ExecState* JSGlobalObject::globalExec()
418 {
419     return d()->globalExec.get();
420 }
421
422 bool JSGlobalObject::isDynamicScope() const
423 {
424     return true;
425 }
426
427 void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
428 {
429     ASSERT(!d()->registerArray);
430     ASSERT(!d()->registerArraySize);
431
432     int numGlobals = registerFile.numGlobals();
433     if (!numGlobals) {
434         d()->registers = 0;
435         return;
436     }
437     
438     Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals);
439     setRegisters(registerArray + numGlobals, registerArray, numGlobals);
440 }
441
442 void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
443 {
444     JSGlobalObject* lastGlobalObject = registerFile.globalObject();
445     if (lastGlobalObject && lastGlobalObject != this)
446         lastGlobalObject->copyGlobalsFrom(registerFile);
447
448     registerFile.setGlobalObject(this);
449     registerFile.setNumGlobals(symbolTable().size());
450
451     if (d()->registerArray) {
452         memcpy(registerFile.base() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
453         setRegisters(registerFile.base(), 0, 0);
454     }
455 }
456
457 void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
458 {
459 #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
460     return globalData->heap->inlineAllocate(size);
461 #else
462     return globalData->heap->allocate(size);
463 #endif
464 }
465
466 } // namespace JSC