2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
31 #include "JSGlobalObject.h"
33 #include "JSCallbackConstructor.h"
34 #include "JSCallbackFunction.h"
35 #include "JSCallbackObject.h"
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"
52 #include "Interpreter.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"
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"
73 ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject
);
75 // Default number of ticks before a timeout check should be done.
76 static const int initialTickCountThreshold
= 255;
78 // Preferred number of milliseconds between each timeout check
79 static const int preferredScriptCheckTimeInterval
= 1000;
81 static inline void markIfNeeded(JSValuePtr v
)
87 static inline void markIfNeeded(const RefPtr
<Structure
>& s
)
93 JSGlobalObject::~JSGlobalObject()
95 ASSERT(JSLock::currentThreadIsHoldingLock());
98 d()->debugger
->detach(this);
100 Profiler
** profiler
= Profiler::enabledProfilerReference();
101 if (UNLIKELY(*profiler
!= 0)) {
102 (*profiler
)->stopProfiling(globalExec(), UString());
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)
113 HashSet
<ProgramCodeBlock
*>::const_iterator end
= codeBlocks().end();
114 for (HashSet
<ProgramCodeBlock
*>::const_iterator it
= codeBlocks().begin(); it
!= end
; ++it
)
115 (*it
)->clearGlobalObject();
117 RegisterFile
& registerFile
= globalData()->interpreter
->registerFile();
118 if (registerFile
.globalObject() == this) {
119 registerFile
.setGlobalObject(0);
120 registerFile
.setNumGlobals(0);
125 void JSGlobalObject::init(JSObject
* thisValue
)
127 ASSERT(JSLock::currentThreadIsHoldingLock());
129 d()->globalData
= Heap::heap(this)->globalData();
130 d()->globalScopeChain
= ScopeChain(this, d()->globalData
.get(), thisValue
);
132 JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain
.node(), CallFrame::noCaller(), 0, 0, 0);
134 if (JSGlobalObject
*& headObject
= head()) {
135 d()->prev
= headObject
;
136 d()->next
= headObject
->d()->next
;
137 headObject
->d()->next
->d()->prev
= this;
138 headObject
->d()->next
= this;
140 headObject
= d()->next
= d()->prev
= this;
145 d()->profileGroup
= 0;
150 void JSGlobalObject::put(ExecState
* exec
, const Identifier
& propertyName
, JSValuePtr value
, PutPropertySlot
& slot
)
152 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(this));
154 if (symbolTablePut(propertyName
, value
))
156 JSVariableObject::put(exec
, propertyName
, value
, slot
);
159 void JSGlobalObject::putWithAttributes(ExecState
* exec
, const Identifier
& propertyName
, JSValuePtr value
, unsigned attributes
)
161 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(this));
163 if (symbolTablePutWithAttributes(propertyName
, value
, attributes
))
166 JSValuePtr valueBefore
= getDirect(propertyName
);
167 PutPropertySlot slot
;
168 JSVariableObject::put(exec
, propertyName
, value
, slot
);
170 JSValuePtr valueAfter
= getDirect(propertyName
);
172 putDirect(propertyName
, valueAfter
, attributes
);
176 void JSGlobalObject::defineGetter(ExecState
* exec
, const Identifier
& propertyName
, JSObject
* getterFunc
)
179 if (!symbolTableGet(propertyName
, slot
))
180 JSVariableObject::defineGetter(exec
, propertyName
, getterFunc
);
183 void JSGlobalObject::defineSetter(ExecState
* exec
, const Identifier
& propertyName
, JSObject
* setterFunc
)
186 if (!symbolTableGet(propertyName
, slot
))
187 JSVariableObject::defineSetter(exec
, propertyName
, setterFunc
);
190 static inline JSObject
* lastInPrototypeChain(JSObject
* object
)
192 JSObject
* o
= object
;
193 while (o
->prototype().isObject())
194 o
= asObject(o
->prototype());
198 void JSGlobalObject::reset(JSValuePtr prototype
)
200 ExecState
* exec
= JSGlobalObject::globalExec();
204 d()->functionPrototype
= new (exec
) FunctionPrototype(exec
, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created.
205 d()->prototypeFunctionStructure
= PrototypeFunction::createStructure(d()->functionPrototype
);
206 d()->functionPrototype
->addFunctionProperties(exec
, d()->prototypeFunctionStructure
.get());
207 d()->objectPrototype
= new (exec
) ObjectPrototype(exec
, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure
.get());
208 d()->functionPrototype
->structure()->setPrototypeWithoutTransition(d()->objectPrototype
);
210 d()->emptyObjectStructure
= d()->objectPrototype
->inheritorID();
212 d()->functionStructure
= JSFunction::createStructure(d()->functionPrototype
);
213 d()->callbackFunctionStructure
= JSCallbackFunction::createStructure(d()->functionPrototype
);
214 d()->argumentsStructure
= Arguments::createStructure(d()->objectPrototype
);
215 d()->callbackConstructorStructure
= JSCallbackConstructor::createStructure(d()->objectPrototype
);
216 d()->callbackObjectStructure
= JSCallbackObject
<JSObject
>::createStructure(d()->objectPrototype
);
218 d()->arrayPrototype
= new (exec
) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype
));
219 d()->arrayStructure
= JSArray::createStructure(d()->arrayPrototype
);
220 d()->regExpMatchesArrayStructure
= RegExpMatchesArray::createStructure(d()->arrayPrototype
);
222 d()->stringPrototype
= new (exec
) StringPrototype(exec
, StringPrototype::createStructure(d()->objectPrototype
));
223 d()->stringObjectStructure
= StringObject::createStructure(d()->stringPrototype
);
225 d()->booleanPrototype
= new (exec
) BooleanPrototype(exec
, BooleanPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
226 d()->booleanObjectStructure
= BooleanObject::createStructure(d()->booleanPrototype
);
228 d()->numberPrototype
= new (exec
) NumberPrototype(exec
, NumberPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
229 d()->numberObjectStructure
= NumberObject::createStructure(d()->numberPrototype
);
231 d()->datePrototype
= new (exec
) DatePrototype(exec
, DatePrototype::createStructure(d()->objectPrototype
));
232 d()->dateStructure
= DateInstance::createStructure(d()->datePrototype
);
234 d()->regExpPrototype
= new (exec
) RegExpPrototype(exec
, RegExpPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
235 d()->regExpStructure
= RegExpObject::createStructure(d()->regExpPrototype
);
237 ErrorPrototype
* errorPrototype
= new (exec
) ErrorPrototype(exec
, ErrorPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
238 d()->errorStructure
= ErrorInstance::createStructure(errorPrototype
);
240 RefPtr
<Structure
> nativeErrorPrototypeStructure
= NativeErrorPrototype::createStructure(errorPrototype
);
242 NativeErrorPrototype
* evalErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "EvalError", "EvalError");
243 NativeErrorPrototype
* rangeErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "RangeError", "RangeError");
244 NativeErrorPrototype
* referenceErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "ReferenceError", "ReferenceError");
245 NativeErrorPrototype
* syntaxErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "SyntaxError", "SyntaxError");
246 NativeErrorPrototype
* typeErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "TypeError", "TypeError");
247 NativeErrorPrototype
* URIErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "URIError", "URIError");
251 JSValuePtr objectConstructor
= new (exec
) ObjectConstructor(exec
, ObjectConstructor::createStructure(d()->functionPrototype
), d()->objectPrototype
);
252 JSValuePtr functionConstructor
= new (exec
) FunctionConstructor(exec
, FunctionConstructor::createStructure(d()->functionPrototype
), d()->functionPrototype
);
253 JSValuePtr arrayConstructor
= new (exec
) ArrayConstructor(exec
, ArrayConstructor::createStructure(d()->functionPrototype
), d()->arrayPrototype
);
254 JSValuePtr stringConstructor
= new (exec
) StringConstructor(exec
, StringConstructor::createStructure(d()->functionPrototype
), d()->prototypeFunctionStructure
.get(), d()->stringPrototype
);
255 JSValuePtr booleanConstructor
= new (exec
) BooleanConstructor(exec
, BooleanConstructor::createStructure(d()->functionPrototype
), d()->booleanPrototype
);
256 JSValuePtr numberConstructor
= new (exec
) NumberConstructor(exec
, NumberConstructor::createStructure(d()->functionPrototype
), d()->numberPrototype
);
257 JSValuePtr dateConstructor
= new (exec
) DateConstructor(exec
, DateConstructor::createStructure(d()->functionPrototype
), d()->prototypeFunctionStructure
.get(), d()->datePrototype
);
259 d()->regExpConstructor
= new (exec
) RegExpConstructor(exec
, RegExpConstructor::createStructure(d()->functionPrototype
), d()->regExpPrototype
);
261 d()->errorConstructor
= new (exec
) ErrorConstructor(exec
, ErrorConstructor::createStructure(d()->functionPrototype
), errorPrototype
);
263 RefPtr
<Structure
> nativeErrorStructure
= NativeErrorConstructor::createStructure(d()->functionPrototype
);
265 d()->evalErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, evalErrorPrototype
);
266 d()->rangeErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, rangeErrorPrototype
);
267 d()->referenceErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, referenceErrorPrototype
);
268 d()->syntaxErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, syntaxErrorPrototype
);
269 d()->typeErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, typeErrorPrototype
);
270 d()->URIErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, URIErrorPrototype
);
272 d()->objectPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, objectConstructor
, DontEnum
);
273 d()->functionPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, functionConstructor
, DontEnum
);
274 d()->arrayPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, arrayConstructor
, DontEnum
);
275 d()->booleanPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, booleanConstructor
, DontEnum
);
276 d()->stringPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, stringConstructor
, DontEnum
);
277 d()->numberPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, numberConstructor
, DontEnum
);
278 d()->datePrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, dateConstructor
, DontEnum
);
279 d()->regExpPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, d()->regExpConstructor
, DontEnum
);
280 errorPrototype
->putDirectWithoutTransition(exec
->propertyNames().constructor
, d()->errorConstructor
, DontEnum
);
282 evalErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->evalErrorConstructor
, DontEnum
);
283 rangeErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->rangeErrorConstructor
, DontEnum
);
284 referenceErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->referenceErrorConstructor
, DontEnum
);
285 syntaxErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->syntaxErrorConstructor
, DontEnum
);
286 typeErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->typeErrorConstructor
, DontEnum
);
287 URIErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->URIErrorConstructor
, DontEnum
);
289 // Set global constructors
291 // FIXME: These properties could be handled by a static hash table.
293 putDirectWithoutTransition(Identifier(exec
, "Object"), objectConstructor
, DontEnum
);
294 putDirectWithoutTransition(Identifier(exec
, "Function"), functionConstructor
, DontEnum
);
295 putDirectWithoutTransition(Identifier(exec
, "Array"), arrayConstructor
, DontEnum
);
296 putDirectWithoutTransition(Identifier(exec
, "Boolean"), booleanConstructor
, DontEnum
);
297 putDirectWithoutTransition(Identifier(exec
, "String"), stringConstructor
, DontEnum
);
298 putDirectWithoutTransition(Identifier(exec
, "Number"), numberConstructor
, DontEnum
);
299 putDirectWithoutTransition(Identifier(exec
, "Date"), dateConstructor
, DontEnum
);
300 putDirectWithoutTransition(Identifier(exec
, "RegExp"), d()->regExpConstructor
, DontEnum
);
301 putDirectWithoutTransition(Identifier(exec
, "Error"), d()->errorConstructor
, DontEnum
);
302 putDirectWithoutTransition(Identifier(exec
, "EvalError"), d()->evalErrorConstructor
);
303 putDirectWithoutTransition(Identifier(exec
, "RangeError"), d()->rangeErrorConstructor
);
304 putDirectWithoutTransition(Identifier(exec
, "ReferenceError"), d()->referenceErrorConstructor
);
305 putDirectWithoutTransition(Identifier(exec
, "SyntaxError"), d()->syntaxErrorConstructor
);
306 putDirectWithoutTransition(Identifier(exec
, "TypeError"), d()->typeErrorConstructor
);
307 putDirectWithoutTransition(Identifier(exec
, "URIError"), d()->URIErrorConstructor
);
309 // Set global values.
310 GlobalPropertyInfo staticGlobals
[] = {
311 GlobalPropertyInfo(Identifier(exec
, "Math"), new (exec
) MathObject(exec
, MathObject::createStructure(d()->objectPrototype
)), DontEnum
| DontDelete
),
312 GlobalPropertyInfo(Identifier(exec
, "NaN"), jsNaN(exec
), DontEnum
| DontDelete
),
313 GlobalPropertyInfo(Identifier(exec
, "Infinity"), jsNumber(exec
, Inf
), DontEnum
| DontDelete
),
314 GlobalPropertyInfo(Identifier(exec
, "undefined"), jsUndefined(), DontEnum
| DontDelete
)
317 addStaticGlobals(staticGlobals
, sizeof(staticGlobals
) / sizeof(GlobalPropertyInfo
));
319 // Set global functions.
321 d()->evalFunction
= new (exec
) GlobalEvalFunction(exec
, GlobalEvalFunction::createStructure(d()->functionPrototype
), 1, exec
->propertyNames().eval
, globalFuncEval
, this);
322 putDirectFunctionWithoutTransition(exec
, d()->evalFunction
, DontEnum
);
323 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 2, Identifier(exec
, "parseInt"), globalFuncParseInt
), DontEnum
);
324 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "parseFloat"), globalFuncParseFloat
), DontEnum
);
325 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "isNaN"), globalFuncIsNaN
), DontEnum
);
326 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "isFinite"), globalFuncIsFinite
), DontEnum
);
327 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "escape"), globalFuncEscape
), DontEnum
);
328 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "unescape"), globalFuncUnescape
), DontEnum
);
329 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "decodeURI"), globalFuncDecodeURI
), DontEnum
);
330 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "decodeURIComponent"), globalFuncDecodeURIComponent
), DontEnum
);
331 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "encodeURI"), globalFuncEncodeURI
), DontEnum
);
332 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "encodeURIComponent"), globalFuncEncodeURIComponent
), DontEnum
);
334 putDirectFunctionWithoutTransition(exec
, new (exec
) PrototypeFunction(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "jscprint"), globalFuncJSCPrint
), DontEnum
);
337 resetPrototype(prototype
);
340 // Set prototype, and also insert the object prototype at the end of the chain.
341 void JSGlobalObject::resetPrototype(JSValuePtr prototype
)
343 setPrototype(prototype
);
344 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype
);
347 void JSGlobalObject::setTimeoutTime(unsigned timeoutTime
)
349 globalData()->interpreter
->setTimeoutTime(timeoutTime
);
352 void JSGlobalObject::startTimeoutCheck()
354 globalData()->interpreter
->startTimeoutCheck();
357 void JSGlobalObject::stopTimeoutCheck()
359 globalData()->interpreter
->stopTimeoutCheck();
362 void JSGlobalObject::mark()
364 JSVariableObject::mark();
366 HashSet
<ProgramCodeBlock
*>::const_iterator end
= codeBlocks().end();
367 for (HashSet
<ProgramCodeBlock
*>::const_iterator it
= codeBlocks().begin(); it
!= end
; ++it
)
370 RegisterFile
& registerFile
= globalData()->interpreter
->registerFile();
371 if (registerFile
.globalObject() == this)
372 registerFile
.markGlobals(&globalData()->heap
);
374 markIfNeeded(d()->regExpConstructor
);
375 markIfNeeded(d()->errorConstructor
);
376 markIfNeeded(d()->evalErrorConstructor
);
377 markIfNeeded(d()->rangeErrorConstructor
);
378 markIfNeeded(d()->referenceErrorConstructor
);
379 markIfNeeded(d()->syntaxErrorConstructor
);
380 markIfNeeded(d()->typeErrorConstructor
);
381 markIfNeeded(d()->URIErrorConstructor
);
383 markIfNeeded(d()->evalFunction
);
385 markIfNeeded(d()->objectPrototype
);
386 markIfNeeded(d()->functionPrototype
);
387 markIfNeeded(d()->arrayPrototype
);
388 markIfNeeded(d()->booleanPrototype
);
389 markIfNeeded(d()->stringPrototype
);
390 markIfNeeded(d()->numberPrototype
);
391 markIfNeeded(d()->datePrototype
);
392 markIfNeeded(d()->regExpPrototype
);
394 markIfNeeded(d()->errorStructure
);
396 // No need to mark the other structures, because their prototypes are all
397 // guaranteed to be referenced elsewhere.
399 Register
* registerArray
= d()->registerArray
.get();
403 size_t size
= d()->registerArraySize
;
404 for (size_t i
= 0; i
< size
; ++i
) {
405 Register
& r
= registerArray
[i
];
411 ExecState
* JSGlobalObject::globalExec()
413 return CallFrame::create(d()->globalCallFrame
+ RegisterFile::CallFrameHeaderSize
);
416 bool JSGlobalObject::isDynamicScope() const
421 void JSGlobalObject::copyGlobalsFrom(RegisterFile
& registerFile
)
423 ASSERT(!d()->registerArray
);
424 ASSERT(!d()->registerArraySize
);
426 int numGlobals
= registerFile
.numGlobals();
432 Register
* registerArray
= copyRegisterArray(registerFile
.lastGlobal(), numGlobals
);
433 setRegisters(registerArray
+ numGlobals
, registerArray
, numGlobals
);
436 void JSGlobalObject::copyGlobalsTo(RegisterFile
& registerFile
)
438 JSGlobalObject
* lastGlobalObject
= registerFile
.globalObject();
439 if (lastGlobalObject
&& lastGlobalObject
!= this)
440 lastGlobalObject
->copyGlobalsFrom(registerFile
);
442 registerFile
.setGlobalObject(this);
443 registerFile
.setNumGlobals(symbolTable().size());
445 if (d()->registerArray
) {
446 memcpy(registerFile
.start() - d()->registerArraySize
, d()->registerArray
.get(), d()->registerArraySize
* sizeof(Register
));
447 setRegisters(registerFile
.start(), 0, 0);
451 void* JSGlobalObject::operator new(size_t size
, JSGlobalData
* globalData
)
453 #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
454 return globalData
->heap
.inlineAllocate(size
);
456 return globalData
->heap
.allocate(size
);