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 "JSFunction.h"
51 #include "JSGlobalObjectFunctions.h"
53 #include "JSONObject.h"
54 #include "Interpreter.h"
55 #include "MathObject.h"
56 #include "NativeErrorConstructor.h"
57 #include "NativeErrorPrototype.h"
58 #include "NumberConstructor.h"
59 #include "NumberPrototype.h"
60 #include "ObjectConstructor.h"
61 #include "ObjectPrototype.h"
63 #include "PrototypeFunction.h"
64 #include "RegExpConstructor.h"
65 #include "RegExpMatchesArray.h"
66 #include "RegExpObject.h"
67 #include "RegExpPrototype.h"
68 #include "ScopeChainMark.h"
69 #include "StringConstructor.h"
70 #include "StringPrototype.h"
75 ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject
);
77 // Default number of ticks before a timeout check should be done.
78 static const int initialTickCountThreshold
= 255;
80 // Preferred number of milliseconds between each timeout check
81 static const int preferredScriptCheckTimeInterval
= 1000;
83 static inline void markIfNeeded(MarkStack
& markStack
, JSValue v
)
89 static inline void markIfNeeded(MarkStack
& markStack
, const RefPtr
<Structure
>& s
)
92 markIfNeeded(markStack
, s
->storedPrototype());
95 JSGlobalObject::~JSGlobalObject()
97 ASSERT(JSLock::currentThreadIsHoldingLock());
100 d()->debugger
->detach(this);
102 Profiler
** profiler
= Profiler::enabledProfilerReference();
103 if (UNLIKELY(*profiler
!= 0)) {
104 (*profiler
)->stopProfiling(globalExec(), UString());
107 d()->next
->d()->prev
= d()->prev
;
108 d()->prev
->d()->next
= d()->next
;
109 JSGlobalObject
*& headObject
= head();
110 if (headObject
== this)
111 headObject
= d()->next
;
112 if (headObject
== this)
115 HashSet
<GlobalCodeBlock
*>::const_iterator end
= codeBlocks().end();
116 for (HashSet
<GlobalCodeBlock
*>::const_iterator it
= codeBlocks().begin(); it
!= end
; ++it
)
117 (*it
)->clearGlobalObject();
119 RegisterFile
& registerFile
= globalData()->interpreter
->registerFile();
120 if (registerFile
.globalObject() == this) {
121 registerFile
.setGlobalObject(0);
122 registerFile
.setNumGlobals(0);
124 d()->destructor(d());
127 void JSGlobalObject::init(JSObject
* thisValue
)
129 ASSERT(JSLock::currentThreadIsHoldingLock());
131 structure()->disableSpecificFunctionTracking();
133 d()->globalData
= Heap::heap(this)->globalData();
134 d()->globalScopeChain
= ScopeChain(this, d()->globalData
.get(), this, thisValue
);
136 JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain
.node(), CallFrame::noCaller(), 0, 0, 0);
138 if (JSGlobalObject
*& headObject
= head()) {
139 d()->prev
= headObject
;
140 d()->next
= headObject
->d()->next
;
141 headObject
->d()->next
->d()->prev
= this;
142 headObject
->d()->next
= this;
144 headObject
= d()->next
= d()->prev
= this;
149 d()->profileGroup
= 0;
154 void JSGlobalObject::put(ExecState
* exec
, const Identifier
& propertyName
, JSValue value
, PutPropertySlot
& slot
)
156 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(this));
158 if (symbolTablePut(propertyName
, value
))
160 JSVariableObject::put(exec
, propertyName
, value
, slot
);
163 void JSGlobalObject::putWithAttributes(ExecState
* exec
, const Identifier
& propertyName
, JSValue value
, unsigned attributes
)
165 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(this));
167 if (symbolTablePutWithAttributes(propertyName
, value
, attributes
))
170 JSValue valueBefore
= getDirect(propertyName
);
171 PutPropertySlot slot
;
172 JSVariableObject::put(exec
, propertyName
, value
, slot
);
174 JSValue valueAfter
= getDirect(propertyName
);
176 JSObject::putWithAttributes(exec
, propertyName
, valueAfter
, attributes
);
180 void JSGlobalObject::defineGetter(ExecState
* exec
, const Identifier
& propertyName
, JSObject
* getterFunc
, unsigned attributes
)
183 if (!symbolTableGet(propertyName
, slot
))
184 JSVariableObject::defineGetter(exec
, propertyName
, getterFunc
, attributes
);
187 void JSGlobalObject::defineSetter(ExecState
* exec
, const Identifier
& propertyName
, JSObject
* setterFunc
, unsigned attributes
)
190 if (!symbolTableGet(propertyName
, slot
))
191 JSVariableObject::defineSetter(exec
, propertyName
, setterFunc
, attributes
);
194 static inline JSObject
* lastInPrototypeChain(JSObject
* object
)
196 JSObject
* o
= object
;
197 while (o
->prototype().isObject())
198 o
= asObject(o
->prototype());
202 void JSGlobalObject::reset(JSValue prototype
)
204 ExecState
* exec
= JSGlobalObject::globalExec();
208 d()->functionPrototype
= new (exec
) FunctionPrototype(exec
, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created.
209 d()->prototypeFunctionStructure
= PrototypeFunction::createStructure(d()->functionPrototype
);
210 NativeFunctionWrapper
* callFunction
= 0;
211 NativeFunctionWrapper
* applyFunction
= 0;
212 d()->functionPrototype
->addFunctionProperties(exec
, d()->prototypeFunctionStructure
.get(), &callFunction
, &applyFunction
);
213 d()->callFunction
= callFunction
;
214 d()->applyFunction
= applyFunction
;
215 d()->objectPrototype
= new (exec
) ObjectPrototype(exec
, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure
.get());
216 d()->functionPrototype
->structure()->setPrototypeWithoutTransition(d()->objectPrototype
);
218 d()->emptyObjectStructure
= d()->objectPrototype
->inheritorID();
220 d()->functionStructure
= JSFunction::createStructure(d()->functionPrototype
);
221 d()->callbackFunctionStructure
= JSCallbackFunction::createStructure(d()->functionPrototype
);
222 d()->argumentsStructure
= Arguments::createStructure(d()->objectPrototype
);
223 d()->callbackConstructorStructure
= JSCallbackConstructor::createStructure(d()->objectPrototype
);
224 d()->callbackObjectStructure
= JSCallbackObject
<JSObject
>::createStructure(d()->objectPrototype
);
226 d()->arrayPrototype
= new (exec
) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype
));
227 d()->arrayStructure
= JSArray::createStructure(d()->arrayPrototype
);
228 d()->regExpMatchesArrayStructure
= RegExpMatchesArray::createStructure(d()->arrayPrototype
);
230 d()->stringPrototype
= new (exec
) StringPrototype(exec
, StringPrototype::createStructure(d()->objectPrototype
));
231 d()->stringObjectStructure
= StringObject::createStructure(d()->stringPrototype
);
233 d()->booleanPrototype
= new (exec
) BooleanPrototype(exec
, BooleanPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
234 d()->booleanObjectStructure
= BooleanObject::createStructure(d()->booleanPrototype
);
236 d()->numberPrototype
= new (exec
) NumberPrototype(exec
, NumberPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
237 d()->numberObjectStructure
= NumberObject::createStructure(d()->numberPrototype
);
239 d()->datePrototype
= new (exec
) DatePrototype(exec
, DatePrototype::createStructure(d()->objectPrototype
));
240 d()->dateStructure
= DateInstance::createStructure(d()->datePrototype
);
242 d()->regExpPrototype
= new (exec
) RegExpPrototype(exec
, RegExpPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
243 d()->regExpStructure
= RegExpObject::createStructure(d()->regExpPrototype
);
245 d()->methodCallDummy
= constructEmptyObject(exec
);
247 ErrorPrototype
* errorPrototype
= new (exec
) ErrorPrototype(exec
, ErrorPrototype::createStructure(d()->objectPrototype
), d()->prototypeFunctionStructure
.get());
248 d()->errorStructure
= ErrorInstance::createStructure(errorPrototype
);
250 RefPtr
<Structure
> nativeErrorPrototypeStructure
= NativeErrorPrototype::createStructure(errorPrototype
);
252 NativeErrorPrototype
* evalErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "EvalError", "EvalError");
253 NativeErrorPrototype
* rangeErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "RangeError", "RangeError");
254 NativeErrorPrototype
* referenceErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "ReferenceError", "ReferenceError");
255 NativeErrorPrototype
* syntaxErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "SyntaxError", "SyntaxError");
256 NativeErrorPrototype
* typeErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "TypeError", "TypeError");
257 NativeErrorPrototype
* URIErrorPrototype
= new (exec
) NativeErrorPrototype(exec
, nativeErrorPrototypeStructure
, "URIError", "URIError");
261 JSCell
* objectConstructor
= new (exec
) ObjectConstructor(exec
, ObjectConstructor::createStructure(d()->functionPrototype
), d()->objectPrototype
, d()->prototypeFunctionStructure
.get());
262 JSCell
* functionConstructor
= new (exec
) FunctionConstructor(exec
, FunctionConstructor::createStructure(d()->functionPrototype
), d()->functionPrototype
);
263 JSCell
* arrayConstructor
= new (exec
) ArrayConstructor(exec
, ArrayConstructor::createStructure(d()->functionPrototype
), d()->arrayPrototype
, d()->prototypeFunctionStructure
.get());
264 JSCell
* stringConstructor
= new (exec
) StringConstructor(exec
, StringConstructor::createStructure(d()->functionPrototype
), d()->prototypeFunctionStructure
.get(), d()->stringPrototype
);
265 JSCell
* booleanConstructor
= new (exec
) BooleanConstructor(exec
, BooleanConstructor::createStructure(d()->functionPrototype
), d()->booleanPrototype
);
266 JSCell
* numberConstructor
= new (exec
) NumberConstructor(exec
, NumberConstructor::createStructure(d()->functionPrototype
), d()->numberPrototype
);
267 JSCell
* dateConstructor
= new (exec
) DateConstructor(exec
, DateConstructor::createStructure(d()->functionPrototype
), d()->prototypeFunctionStructure
.get(), d()->datePrototype
);
269 d()->regExpConstructor
= new (exec
) RegExpConstructor(exec
, RegExpConstructor::createStructure(d()->functionPrototype
), d()->regExpPrototype
);
271 d()->errorConstructor
= new (exec
) ErrorConstructor(exec
, ErrorConstructor::createStructure(d()->functionPrototype
), errorPrototype
);
273 RefPtr
<Structure
> nativeErrorStructure
= NativeErrorConstructor::createStructure(d()->functionPrototype
);
275 d()->evalErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, evalErrorPrototype
);
276 d()->rangeErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, rangeErrorPrototype
);
277 d()->referenceErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, referenceErrorPrototype
);
278 d()->syntaxErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, syntaxErrorPrototype
);
279 d()->typeErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, typeErrorPrototype
);
280 d()->URIErrorConstructor
= new (exec
) NativeErrorConstructor(exec
, nativeErrorStructure
, URIErrorPrototype
);
282 d()->objectPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, objectConstructor
, DontEnum
);
283 d()->functionPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, functionConstructor
, DontEnum
);
284 d()->arrayPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, arrayConstructor
, DontEnum
);
285 d()->booleanPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, booleanConstructor
, DontEnum
);
286 d()->stringPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, stringConstructor
, DontEnum
);
287 d()->numberPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, numberConstructor
, DontEnum
);
288 d()->datePrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, dateConstructor
, DontEnum
);
289 d()->regExpPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, d()->regExpConstructor
, DontEnum
);
290 errorPrototype
->putDirectFunctionWithoutTransition(exec
->propertyNames().constructor
, d()->errorConstructor
, DontEnum
);
292 evalErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->evalErrorConstructor
, DontEnum
);
293 rangeErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->rangeErrorConstructor
, DontEnum
);
294 referenceErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->referenceErrorConstructor
, DontEnum
);
295 syntaxErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->syntaxErrorConstructor
, DontEnum
);
296 typeErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->typeErrorConstructor
, DontEnum
);
297 URIErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->URIErrorConstructor
, DontEnum
);
299 // Set global constructors
301 // FIXME: These properties could be handled by a static hash table.
303 putDirectFunctionWithoutTransition(Identifier(exec
, "Object"), objectConstructor
, DontEnum
);
304 putDirectFunctionWithoutTransition(Identifier(exec
, "Function"), functionConstructor
, DontEnum
);
305 putDirectFunctionWithoutTransition(Identifier(exec
, "Array"), arrayConstructor
, DontEnum
);
306 putDirectFunctionWithoutTransition(Identifier(exec
, "Boolean"), booleanConstructor
, DontEnum
);
307 putDirectFunctionWithoutTransition(Identifier(exec
, "String"), stringConstructor
, DontEnum
);
308 putDirectFunctionWithoutTransition(Identifier(exec
, "Number"), numberConstructor
, DontEnum
);
309 putDirectFunctionWithoutTransition(Identifier(exec
, "Date"), dateConstructor
, DontEnum
);
310 putDirectFunctionWithoutTransition(Identifier(exec
, "RegExp"), d()->regExpConstructor
, DontEnum
);
311 putDirectFunctionWithoutTransition(Identifier(exec
, "Error"), d()->errorConstructor
, DontEnum
);
312 putDirectFunctionWithoutTransition(Identifier(exec
, "EvalError"), d()->evalErrorConstructor
);
313 putDirectFunctionWithoutTransition(Identifier(exec
, "RangeError"), d()->rangeErrorConstructor
);
314 putDirectFunctionWithoutTransition(Identifier(exec
, "ReferenceError"), d()->referenceErrorConstructor
);
315 putDirectFunctionWithoutTransition(Identifier(exec
, "SyntaxError"), d()->syntaxErrorConstructor
);
316 putDirectFunctionWithoutTransition(Identifier(exec
, "TypeError"), d()->typeErrorConstructor
);
317 putDirectFunctionWithoutTransition(Identifier(exec
, "URIError"), d()->URIErrorConstructor
);
319 // Set global values.
320 GlobalPropertyInfo staticGlobals
[] = {
321 GlobalPropertyInfo(Identifier(exec
, "Math"), new (exec
) MathObject(exec
, MathObject::createStructure(d()->objectPrototype
)), DontEnum
| DontDelete
),
322 GlobalPropertyInfo(Identifier(exec
, "NaN"), jsNaN(exec
), DontEnum
| DontDelete
),
323 GlobalPropertyInfo(Identifier(exec
, "Infinity"), jsNumber(exec
, Inf
), DontEnum
| DontDelete
),
324 GlobalPropertyInfo(Identifier(exec
, "undefined"), jsUndefined(), DontEnum
| DontDelete
),
325 GlobalPropertyInfo(Identifier(exec
, "JSON"), new (exec
) JSONObject(JSONObject::createStructure(d()->objectPrototype
)), DontEnum
| DontDelete
)
328 addStaticGlobals(staticGlobals
, sizeof(staticGlobals
) / sizeof(GlobalPropertyInfo
));
330 // Set global functions.
332 d()->evalFunction
= new (exec
) GlobalEvalFunction(exec
, GlobalEvalFunction::createStructure(d()->functionPrototype
), 1, exec
->propertyNames().eval
, globalFuncEval
, this);
333 putDirectFunctionWithoutTransition(exec
, d()->evalFunction
, DontEnum
);
334 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 2, Identifier(exec
, "parseInt"), globalFuncParseInt
), DontEnum
);
335 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "parseFloat"), globalFuncParseFloat
), DontEnum
);
336 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "isNaN"), globalFuncIsNaN
), DontEnum
);
337 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "isFinite"), globalFuncIsFinite
), DontEnum
);
338 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "escape"), globalFuncEscape
), DontEnum
);
339 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "unescape"), globalFuncUnescape
), DontEnum
);
340 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "decodeURI"), globalFuncDecodeURI
), DontEnum
);
341 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "decodeURIComponent"), globalFuncDecodeURIComponent
), DontEnum
);
342 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "encodeURI"), globalFuncEncodeURI
), DontEnum
);
343 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "encodeURIComponent"), globalFuncEncodeURIComponent
), DontEnum
);
345 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, d()->prototypeFunctionStructure
.get(), 1, Identifier(exec
, "jscprint"), globalFuncJSCPrint
), DontEnum
);
348 resetPrototype(prototype
);
351 // Set prototype, and also insert the object prototype at the end of the chain.
352 void JSGlobalObject::resetPrototype(JSValue prototype
)
354 setPrototype(prototype
);
356 JSObject
* oldLastInPrototypeChain
= lastInPrototypeChain(this);
357 JSObject
* objectPrototype
= d()->objectPrototype
;
358 if (oldLastInPrototypeChain
!= objectPrototype
)
359 oldLastInPrototypeChain
->setPrototype(objectPrototype
);
362 void JSGlobalObject::markChildren(MarkStack
& markStack
)
364 JSVariableObject::markChildren(markStack
);
366 HashSet
<GlobalCodeBlock
*>::const_iterator end
= codeBlocks().end();
367 for (HashSet
<GlobalCodeBlock
*>::const_iterator it
= codeBlocks().begin(); it
!= end
; ++it
)
368 (*it
)->markAggregate(markStack
);
370 RegisterFile
& registerFile
= globalData()->interpreter
->registerFile();
371 if (registerFile
.globalObject() == this)
372 registerFile
.markGlobals(markStack
, &globalData()->heap
);
374 markIfNeeded(markStack
, d()->regExpConstructor
);
375 markIfNeeded(markStack
, d()->errorConstructor
);
376 markIfNeeded(markStack
, d()->evalErrorConstructor
);
377 markIfNeeded(markStack
, d()->rangeErrorConstructor
);
378 markIfNeeded(markStack
, d()->referenceErrorConstructor
);
379 markIfNeeded(markStack
, d()->syntaxErrorConstructor
);
380 markIfNeeded(markStack
, d()->typeErrorConstructor
);
381 markIfNeeded(markStack
, d()->URIErrorConstructor
);
383 markIfNeeded(markStack
, d()->evalFunction
);
384 markIfNeeded(markStack
, d()->callFunction
);
385 markIfNeeded(markStack
, d()->applyFunction
);
387 markIfNeeded(markStack
, d()->objectPrototype
);
388 markIfNeeded(markStack
, d()->functionPrototype
);
389 markIfNeeded(markStack
, d()->arrayPrototype
);
390 markIfNeeded(markStack
, d()->booleanPrototype
);
391 markIfNeeded(markStack
, d()->stringPrototype
);
392 markIfNeeded(markStack
, d()->numberPrototype
);
393 markIfNeeded(markStack
, d()->datePrototype
);
394 markIfNeeded(markStack
, d()->regExpPrototype
);
396 markIfNeeded(markStack
, d()->methodCallDummy
);
398 markIfNeeded(markStack
, d()->errorStructure
);
399 markIfNeeded(markStack
, d()->argumentsStructure
);
400 markIfNeeded(markStack
, d()->arrayStructure
);
401 markIfNeeded(markStack
, d()->booleanObjectStructure
);
402 markIfNeeded(markStack
, d()->callbackConstructorStructure
);
403 markIfNeeded(markStack
, d()->callbackFunctionStructure
);
404 markIfNeeded(markStack
, d()->callbackObjectStructure
);
405 markIfNeeded(markStack
, d()->dateStructure
);
406 markIfNeeded(markStack
, d()->emptyObjectStructure
);
407 markIfNeeded(markStack
, d()->errorStructure
);
408 markIfNeeded(markStack
, d()->functionStructure
);
409 markIfNeeded(markStack
, d()->numberObjectStructure
);
410 markIfNeeded(markStack
, d()->prototypeFunctionStructure
);
411 markIfNeeded(markStack
, d()->regExpMatchesArrayStructure
);
412 markIfNeeded(markStack
, d()->regExpStructure
);
413 markIfNeeded(markStack
, d()->stringObjectStructure
);
415 // No need to mark the other structures, because their prototypes are all
416 // guaranteed to be referenced elsewhere.
418 Register
* registerArray
= d()->registerArray
.get();
422 size_t size
= d()->registerArraySize
;
423 markStack
.appendValues(reinterpret_cast<JSValue
*>(registerArray
), size
);
426 ExecState
* JSGlobalObject::globalExec()
428 return CallFrame::create(d()->globalCallFrame
+ RegisterFile::CallFrameHeaderSize
);
431 bool JSGlobalObject::isDynamicScope() const
436 void JSGlobalObject::copyGlobalsFrom(RegisterFile
& registerFile
)
438 ASSERT(!d()->registerArray
);
439 ASSERT(!d()->registerArraySize
);
441 int numGlobals
= registerFile
.numGlobals();
447 Register
* registerArray
= copyRegisterArray(registerFile
.lastGlobal(), numGlobals
);
448 setRegisters(registerArray
+ numGlobals
, registerArray
, numGlobals
);
451 void JSGlobalObject::copyGlobalsTo(RegisterFile
& registerFile
)
453 JSGlobalObject
* lastGlobalObject
= registerFile
.globalObject();
454 if (lastGlobalObject
&& lastGlobalObject
!= this)
455 lastGlobalObject
->copyGlobalsFrom(registerFile
);
457 registerFile
.setGlobalObject(this);
458 registerFile
.setNumGlobals(symbolTable().size());
460 if (d()->registerArray
) {
461 memcpy(registerFile
.start() - d()->registerArraySize
, d()->registerArray
.get(), d()->registerArraySize
* sizeof(Register
));
462 setRegisters(registerFile
.start(), 0, 0);
466 void* JSGlobalObject::operator new(size_t size
, JSGlobalData
* globalData
)
468 return globalData
->heap
.allocate(size
);
471 void JSGlobalObject::destroyJSGlobalObjectData(void* jsGlobalObjectData
)
473 delete static_cast<JSGlobalObjectData
*>(jsGlobalObjectData
);