2 * Copyright (C) 2007, 2008 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 "Activation.h"
34 #include "array_object.h"
35 #include "bool_object.h"
36 #include "date_object.h"
38 #include "error_object.h"
39 #include "function_object.h"
40 #include "math_object.h"
41 #include "number_object.h"
42 #include "object_object.h"
43 #include "regexp_object.h"
44 #include "SavedBuiltins.h"
45 #include "string_object.h"
61 // Default number of ticks before a timeout check should be done.
62 static const int initialTickCountThreshold
= 255;
64 // Preferred number of milliseconds between each timeout check
65 static const int preferredScriptCheckTimeInterval
= 1000;
67 static inline void markIfNeeded(JSValue
* v
)
69 if (v
&& !v
->marked())
73 // Returns the current time in milliseconds
74 // It doesn't matter what "current time" is here, just as long as
75 // it's possible to measure the time difference correctly.
76 static inline unsigned getCurrentTime()
81 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
83 QDateTime t
= QDateTime::currentDateTime();
84 return t
.toTime_t() * 1000 + t
.time().msec();
85 #elif PLATFORM(WIN_OS)
88 #error Platform does not have getCurrentTime function
92 JSGlobalObject
* JSGlobalObject::s_head
= 0;
94 void JSGlobalObject::deleteActivationStack()
96 ActivationStackNode
* prevNode
= 0;
97 for (ActivationStackNode
* currentNode
= d()->activations
; currentNode
; currentNode
= prevNode
) {
98 prevNode
= currentNode
->prev
;
103 JSGlobalObject::~JSGlobalObject()
105 ASSERT(JSLock::currentThreadIsHoldingLock());
108 d()->debugger
->detach(this);
110 d()->next
->d()->prev
= d()->prev
;
111 d()->prev
->d()->next
= d()->next
;
116 deleteActivationStack();
121 void JSGlobalObject::init()
123 ASSERT(JSLock::currentThreadIsHoldingLock());
127 d()->next
= s_head
->d()->next
;
128 s_head
->d()->next
->d()->prev
= this;
129 s_head
->d()->next
= this;
131 s_head
= d()->next
= d()->prev
= this;
133 d()->compatMode
= NativeMode
;
136 d()->timeoutTime
= 0;
137 d()->timeoutCheckCount
= 0;
142 ActivationStackNode
* newStackNode
= new ActivationStackNode
;
143 newStackNode
->prev
= 0;
144 d()->activations
= newStackNode
;
145 d()->activationCount
= 0;
150 bool JSGlobalObject::getOwnPropertySlot(ExecState
* exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
152 if (symbolTableGet(propertyName
, slot
))
154 return JSVariableObject::getOwnPropertySlot(exec
, propertyName
, slot
);
157 void JSGlobalObject::put(ExecState
* exec
, const Identifier
& propertyName
, JSValue
* value
, int attr
)
159 if (symbolTablePut(propertyName
, value
, !(attr
& ~DontDelete
)))
161 return JSVariableObject::put(exec
, propertyName
, value
, attr
);
164 static inline JSObject
* lastInPrototypeChain(JSObject
* object
)
166 JSObject
* o
= object
;
167 while (o
->prototype()->isObject())
168 o
= static_cast<JSObject
*>(o
->prototype());
172 void JSGlobalObject::reset(JSValue
* prototype
)
174 // Clear before inititalizing, to avoid calling mark() on stale pointers --
175 // which would be wasteful -- or uninitialized pointers -- which would be
176 // dangerous. (The allocations below may cause a GC.)
179 localStorage().clear();
180 symbolTable().clear();
183 d()->functionPrototype
= 0;
184 d()->objectPrototype
= 0;
186 d()->arrayPrototype
= 0;
187 d()->stringPrototype
= 0;
188 d()->booleanPrototype
= 0;
189 d()->numberPrototype
= 0;
190 d()->datePrototype
= 0;
191 d()->regExpPrototype
= 0;
192 d()->errorPrototype
= 0;
194 d()->evalErrorPrototype
= 0;
195 d()->rangeErrorPrototype
= 0;
196 d()->referenceErrorPrototype
= 0;
197 d()->syntaxErrorPrototype
= 0;
198 d()->typeErrorPrototype
= 0;
199 d()->URIErrorPrototype
= 0;
202 d()->objectConstructor
= 0;
203 d()->functionConstructor
= 0;
204 d()->arrayConstructor
= 0;
205 d()->stringConstructor
= 0;
206 d()->booleanConstructor
= 0;
207 d()->numberConstructor
= 0;
208 d()->dateConstructor
= 0;
209 d()->regExpConstructor
= 0;
210 d()->errorConstructor
= 0;
212 d()->evalErrorConstructor
= 0;
213 d()->rangeErrorConstructor
= 0;
214 d()->referenceErrorConstructor
= 0;
215 d()->syntaxErrorConstructor
= 0;
216 d()->typeErrorConstructor
= 0;
217 d()->URIErrorConstructor
= 0;
219 ExecState
* exec
= &d()->globalExec
;
222 d()->functionPrototype
= new FunctionPrototype(exec
);
223 d()->objectPrototype
= new ObjectPrototype(exec
, d()->functionPrototype
);
224 d()->functionPrototype
->setPrototype(d()->objectPrototype
);
226 d()->arrayPrototype
= new ArrayPrototype(exec
, d()->objectPrototype
);
227 d()->stringPrototype
= new StringPrototype(exec
, d()->objectPrototype
);
228 d()->booleanPrototype
= new BooleanPrototype(exec
, d()->objectPrototype
, d()->functionPrototype
);
229 d()->numberPrototype
= new NumberPrototype(exec
, d()->objectPrototype
, d()->functionPrototype
);
230 d()->datePrototype
= new DatePrototype(exec
, d()->objectPrototype
);
231 d()->regExpPrototype
= new RegExpPrototype(exec
, d()->objectPrototype
, d()->functionPrototype
);
232 d()->errorPrototype
= new ErrorPrototype(exec
, d()->objectPrototype
, d()->functionPrototype
);
234 d()->evalErrorPrototype
= new NativeErrorPrototype(exec
, d()->errorPrototype
, "EvalError", "EvalError");
235 d()->rangeErrorPrototype
= new NativeErrorPrototype(exec
, d()->errorPrototype
, "RangeError", "RangeError");
236 d()->referenceErrorPrototype
= new NativeErrorPrototype(exec
, d()->errorPrototype
, "ReferenceError", "ReferenceError");
237 d()->syntaxErrorPrototype
= new NativeErrorPrototype(exec
, d()->errorPrototype
, "SyntaxError", "SyntaxError");
238 d()->typeErrorPrototype
= new NativeErrorPrototype(exec
, d()->errorPrototype
, "TypeError", "TypeError");
239 d()->URIErrorPrototype
= new NativeErrorPrototype(exec
, d()->errorPrototype
, "URIError", "URIError");
242 d()->objectConstructor
= new ObjectObjectImp(exec
, d()->objectPrototype
, d()->functionPrototype
);
243 d()->functionConstructor
= new FunctionObjectImp(exec
, d()->functionPrototype
);
244 d()->arrayConstructor
= new ArrayObjectImp(exec
, d()->functionPrototype
, d()->arrayPrototype
);
245 d()->stringConstructor
= new StringObjectImp(exec
, d()->functionPrototype
, d()->stringPrototype
);
246 d()->booleanConstructor
= new BooleanObjectImp(exec
, d()->functionPrototype
, d()->booleanPrototype
);
247 d()->numberConstructor
= new NumberObjectImp(exec
, d()->functionPrototype
, d()->numberPrototype
);
248 d()->dateConstructor
= new DateObjectImp(exec
, d()->functionPrototype
, d()->datePrototype
);
249 d()->regExpConstructor
= new RegExpObjectImp(exec
, d()->functionPrototype
, d()->regExpPrototype
);
250 d()->errorConstructor
= new ErrorObjectImp(exec
, d()->functionPrototype
, d()->errorPrototype
);
252 d()->evalErrorConstructor
= new NativeErrorImp(exec
, d()->functionPrototype
, d()->evalErrorPrototype
);
253 d()->rangeErrorConstructor
= new NativeErrorImp(exec
, d()->functionPrototype
, d()->rangeErrorPrototype
);
254 d()->referenceErrorConstructor
= new NativeErrorImp(exec
, d()->functionPrototype
, d()->referenceErrorPrototype
);
255 d()->syntaxErrorConstructor
= new NativeErrorImp(exec
, d()->functionPrototype
, d()->syntaxErrorPrototype
);
256 d()->typeErrorConstructor
= new NativeErrorImp(exec
, d()->functionPrototype
, d()->typeErrorPrototype
);
257 d()->URIErrorConstructor
= new NativeErrorImp(exec
, d()->functionPrototype
, d()->URIErrorPrototype
);
259 d()->functionPrototype
->putDirect(exec
->propertyNames().constructor
, d()->functionConstructor
, DontEnum
);
261 d()->objectPrototype
->putDirect(exec
->propertyNames().constructor
, d()->objectConstructor
, DontEnum
| DontDelete
| ReadOnly
);
262 d()->functionPrototype
->putDirect(exec
->propertyNames().constructor
, d()->functionConstructor
, DontEnum
| DontDelete
| ReadOnly
);
263 d()->arrayPrototype
->putDirect(exec
->propertyNames().constructor
, d()->arrayConstructor
, DontEnum
| DontDelete
| ReadOnly
);
264 d()->booleanPrototype
->putDirect(exec
->propertyNames().constructor
, d()->booleanConstructor
, DontEnum
| DontDelete
| ReadOnly
);
265 d()->stringPrototype
->putDirect(exec
->propertyNames().constructor
, d()->stringConstructor
, DontEnum
| DontDelete
| ReadOnly
);
266 d()->numberPrototype
->putDirect(exec
->propertyNames().constructor
, d()->numberConstructor
, DontEnum
| DontDelete
| ReadOnly
);
267 d()->datePrototype
->putDirect(exec
->propertyNames().constructor
, d()->dateConstructor
, DontEnum
| DontDelete
| ReadOnly
);
268 d()->regExpPrototype
->putDirect(exec
->propertyNames().constructor
, d()->regExpConstructor
, DontEnum
| DontDelete
| ReadOnly
);
269 d()->errorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->errorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
270 d()->evalErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->evalErrorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
271 d()->rangeErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->rangeErrorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
272 d()->referenceErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->referenceErrorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
273 d()->syntaxErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->syntaxErrorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
274 d()->typeErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->typeErrorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
275 d()->URIErrorPrototype
->putDirect(exec
->propertyNames().constructor
, d()->URIErrorConstructor
, DontEnum
| DontDelete
| ReadOnly
);
277 // Set global constructors
279 // FIXME: kjs_window.cpp checks Internal/DontEnum as a performance hack, to
280 // see that these values can be put directly without a check for override
283 // FIXME: These properties should be handled by a static hash table.
285 putDirect("Object", d()->objectConstructor
, DontEnum
);
286 putDirect("Function", d()->functionConstructor
, DontEnum
);
287 putDirect("Array", d()->arrayConstructor
, DontEnum
);
288 putDirect("Boolean", d()->booleanConstructor
, DontEnum
);
289 putDirect("String", d()->stringConstructor
, DontEnum
);
290 putDirect("Number", d()->numberConstructor
, DontEnum
);
291 putDirect("Date", d()->dateConstructor
, DontEnum
);
292 putDirect("RegExp", d()->regExpConstructor
, DontEnum
);
293 putDirect("Error", d()->errorConstructor
, DontEnum
);
294 putDirect("EvalError", d()->evalErrorConstructor
, Internal
);
295 putDirect("RangeError", d()->rangeErrorConstructor
, Internal
);
296 putDirect("ReferenceError", d()->referenceErrorConstructor
, Internal
);
297 putDirect("SyntaxError", d()->syntaxErrorConstructor
, Internal
);
298 putDirect("TypeError", d()->typeErrorConstructor
, Internal
);
299 putDirect("URIError", d()->URIErrorConstructor
, Internal
);
301 // Set global values.
303 putDirect("Math", new MathObjectImp(exec
, d()->objectPrototype
), DontEnum
);
305 putDirect("NaN", jsNaN(), DontEnum
| DontDelete
);
306 putDirect("Infinity", jsNumber(Inf
), DontEnum
| DontDelete
);
307 putDirect("undefined", jsUndefined(), DontEnum
| DontDelete
);
309 // Set global functions.
311 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "eval", globalFuncEval
), DontEnum
);
312 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 2, "parseInt", globalFuncParseInt
), DontEnum
);
313 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "parseFloat", globalFuncParseFloat
), DontEnum
);
314 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "isNaN", globalFuncIsNaN
), DontEnum
);
315 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "isFinite", globalFuncIsFinite
), DontEnum
);
316 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "escape", globalFuncEscape
), DontEnum
);
317 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "unescape", globalFuncUnescape
), DontEnum
);
318 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "decodeURI", globalFuncDecodeURI
), DontEnum
);
319 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "decodeURIComponent", globalFuncDecodeURIComponent
), DontEnum
);
320 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "encodeURI", globalFuncEncodeURI
), DontEnum
);
321 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "encodeURIComponent", globalFuncEncodeURIComponent
), DontEnum
);
323 putDirectFunction(new PrototypeFunction(exec
, d()->functionPrototype
, 1, "kjsprint", globalFuncKJSPrint
), DontEnum
);
326 // Set prototype, and also insert the object prototype at the end of the chain.
328 setPrototype(prototype
);
329 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype
);
332 void JSGlobalObject::startTimeoutCheck()
334 if (!d()->timeoutCheckCount
)
337 ++d()->timeoutCheckCount
;
340 void JSGlobalObject::stopTimeoutCheck()
342 --d()->timeoutCheckCount
;
345 void JSGlobalObject::resetTimeoutCheck()
348 d()->ticksUntilNextTimeoutCheck
= initialTickCountThreshold
;
349 d()->timeAtLastCheckTimeout
= 0;
350 d()->timeExecuting
= 0;
353 bool JSGlobalObject::checkTimeout()
357 unsigned currentTime
= getCurrentTime();
359 if (!d()->timeAtLastCheckTimeout
) {
360 // Suspicious amount of looping in a script -- start timing it
361 d()->timeAtLastCheckTimeout
= currentTime
;
365 unsigned timeDiff
= currentTime
- d()->timeAtLastCheckTimeout
;
370 d()->timeExecuting
+= timeDiff
;
371 d()->timeAtLastCheckTimeout
= currentTime
;
373 // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in
374 // preferredScriptCheckTimeInterval
375 d()->ticksUntilNextTimeoutCheck
= (unsigned)((float)preferredScriptCheckTimeInterval
/ timeDiff
) * d()->ticksUntilNextTimeoutCheck
;
377 // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
378 // preferred script check time interval.
379 if (d()->ticksUntilNextTimeoutCheck
== 0)
380 d()->ticksUntilNextTimeoutCheck
= initialTickCountThreshold
;
382 if (shouldInterruptScriptBeforeTimeout())
385 if (d()->timeoutTime
&& d()->timeExecuting
> d()->timeoutTime
) {
386 if (shouldInterruptScript())
395 void JSGlobalObject::saveBuiltins(SavedBuiltins
& builtins
) const
397 if (!builtins
._internal
)
398 builtins
._internal
= new SavedBuiltinsInternal
;
400 builtins
._internal
->objectConstructor
= d()->objectConstructor
;
401 builtins
._internal
->functionConstructor
= d()->functionConstructor
;
402 builtins
._internal
->arrayConstructor
= d()->arrayConstructor
;
403 builtins
._internal
->booleanConstructor
= d()->booleanConstructor
;
404 builtins
._internal
->stringConstructor
= d()->stringConstructor
;
405 builtins
._internal
->numberConstructor
= d()->numberConstructor
;
406 builtins
._internal
->dateConstructor
= d()->dateConstructor
;
407 builtins
._internal
->regExpConstructor
= d()->regExpConstructor
;
408 builtins
._internal
->errorConstructor
= d()->errorConstructor
;
409 builtins
._internal
->evalErrorConstructor
= d()->evalErrorConstructor
;
410 builtins
._internal
->rangeErrorConstructor
= d()->rangeErrorConstructor
;
411 builtins
._internal
->referenceErrorConstructor
= d()->referenceErrorConstructor
;
412 builtins
._internal
->syntaxErrorConstructor
= d()->syntaxErrorConstructor
;
413 builtins
._internal
->typeErrorConstructor
= d()->typeErrorConstructor
;
414 builtins
._internal
->URIErrorConstructor
= d()->URIErrorConstructor
;
416 builtins
._internal
->objectPrototype
= d()->objectPrototype
;
417 builtins
._internal
->functionPrototype
= d()->functionPrototype
;
418 builtins
._internal
->arrayPrototype
= d()->arrayPrototype
;
419 builtins
._internal
->booleanPrototype
= d()->booleanPrototype
;
420 builtins
._internal
->stringPrototype
= d()->stringPrototype
;
421 builtins
._internal
->numberPrototype
= d()->numberPrototype
;
422 builtins
._internal
->datePrototype
= d()->datePrototype
;
423 builtins
._internal
->regExpPrototype
= d()->regExpPrototype
;
424 builtins
._internal
->errorPrototype
= d()->errorPrototype
;
425 builtins
._internal
->evalErrorPrototype
= d()->evalErrorPrototype
;
426 builtins
._internal
->rangeErrorPrototype
= d()->rangeErrorPrototype
;
427 builtins
._internal
->referenceErrorPrototype
= d()->referenceErrorPrototype
;
428 builtins
._internal
->syntaxErrorPrototype
= d()->syntaxErrorPrototype
;
429 builtins
._internal
->typeErrorPrototype
= d()->typeErrorPrototype
;
430 builtins
._internal
->URIErrorPrototype
= d()->URIErrorPrototype
;
433 void JSGlobalObject::restoreBuiltins(const SavedBuiltins
& builtins
)
435 if (!builtins
._internal
)
438 d()->objectConstructor
= builtins
._internal
->objectConstructor
;
439 d()->functionConstructor
= builtins
._internal
->functionConstructor
;
440 d()->arrayConstructor
= builtins
._internal
->arrayConstructor
;
441 d()->booleanConstructor
= builtins
._internal
->booleanConstructor
;
442 d()->stringConstructor
= builtins
._internal
->stringConstructor
;
443 d()->numberConstructor
= builtins
._internal
->numberConstructor
;
444 d()->dateConstructor
= builtins
._internal
->dateConstructor
;
445 d()->regExpConstructor
= builtins
._internal
->regExpConstructor
;
446 d()->errorConstructor
= builtins
._internal
->errorConstructor
;
447 d()->evalErrorConstructor
= builtins
._internal
->evalErrorConstructor
;
448 d()->rangeErrorConstructor
= builtins
._internal
->rangeErrorConstructor
;
449 d()->referenceErrorConstructor
= builtins
._internal
->referenceErrorConstructor
;
450 d()->syntaxErrorConstructor
= builtins
._internal
->syntaxErrorConstructor
;
451 d()->typeErrorConstructor
= builtins
._internal
->typeErrorConstructor
;
452 d()->URIErrorConstructor
= builtins
._internal
->URIErrorConstructor
;
454 d()->objectPrototype
= builtins
._internal
->objectPrototype
;
455 d()->functionPrototype
= builtins
._internal
->functionPrototype
;
456 d()->arrayPrototype
= builtins
._internal
->arrayPrototype
;
457 d()->booleanPrototype
= builtins
._internal
->booleanPrototype
;
458 d()->stringPrototype
= builtins
._internal
->stringPrototype
;
459 d()->numberPrototype
= builtins
._internal
->numberPrototype
;
460 d()->datePrototype
= builtins
._internal
->datePrototype
;
461 d()->regExpPrototype
= builtins
._internal
->regExpPrototype
;
462 d()->errorPrototype
= builtins
._internal
->errorPrototype
;
463 d()->evalErrorPrototype
= builtins
._internal
->evalErrorPrototype
;
464 d()->rangeErrorPrototype
= builtins
._internal
->rangeErrorPrototype
;
465 d()->referenceErrorPrototype
= builtins
._internal
->referenceErrorPrototype
;
466 d()->syntaxErrorPrototype
= builtins
._internal
->syntaxErrorPrototype
;
467 d()->typeErrorPrototype
= builtins
._internal
->typeErrorPrototype
;
468 d()->URIErrorPrototype
= builtins
._internal
->URIErrorPrototype
;
471 void JSGlobalObject::mark()
473 JSVariableObject::mark();
475 markIfNeeded(d()->globalExec
.exception());
477 markIfNeeded(d()->objectConstructor
);
478 markIfNeeded(d()->functionConstructor
);
479 markIfNeeded(d()->arrayConstructor
);
480 markIfNeeded(d()->booleanConstructor
);
481 markIfNeeded(d()->stringConstructor
);
482 markIfNeeded(d()->numberConstructor
);
483 markIfNeeded(d()->dateConstructor
);
484 markIfNeeded(d()->regExpConstructor
);
485 markIfNeeded(d()->errorConstructor
);
486 markIfNeeded(d()->evalErrorConstructor
);
487 markIfNeeded(d()->rangeErrorConstructor
);
488 markIfNeeded(d()->referenceErrorConstructor
);
489 markIfNeeded(d()->syntaxErrorConstructor
);
490 markIfNeeded(d()->typeErrorConstructor
);
491 markIfNeeded(d()->URIErrorConstructor
);
493 markIfNeeded(d()->objectPrototype
);
494 markIfNeeded(d()->functionPrototype
);
495 markIfNeeded(d()->arrayPrototype
);
496 markIfNeeded(d()->booleanPrototype
);
497 markIfNeeded(d()->stringPrototype
);
498 markIfNeeded(d()->numberPrototype
);
499 markIfNeeded(d()->datePrototype
);
500 markIfNeeded(d()->regExpPrototype
);
501 markIfNeeded(d()->errorPrototype
);
502 markIfNeeded(d()->evalErrorPrototype
);
503 markIfNeeded(d()->rangeErrorPrototype
);
504 markIfNeeded(d()->referenceErrorPrototype
);
505 markIfNeeded(d()->syntaxErrorPrototype
);
506 markIfNeeded(d()->typeErrorPrototype
);
507 markIfNeeded(d()->URIErrorPrototype
);
510 ExecState
* JSGlobalObject::globalExec()
512 return &d()->globalExec
;
515 ActivationImp
* JSGlobalObject::pushActivation(ExecState
* exec
)
517 if (d()->activationCount
== activationStackNodeSize
) {
518 ActivationStackNode
* newNode
= new ActivationStackNode
;
519 newNode
->prev
= d()->activations
;
520 d()->activations
= newNode
;
521 d()->activationCount
= 0;
524 StackActivation
* stackEntry
= &d()->activations
->data
[d()->activationCount
++];
525 stackEntry
->activationStorage
.init(exec
);
526 return &stackEntry
->activationStorage
;
529 inline void JSGlobalObject::checkActivationCount()
531 if (!d()->activationCount
) {
532 ActivationStackNode
* prev
= d()->activations
->prev
;
534 delete d()->activations
;
535 d()->activations
= prev
;
536 d()->activationCount
= activationStackNodeSize
;
540 void JSGlobalObject::popActivation()
542 checkActivationCount();
543 d()->activations
->data
[--d()->activationCount
].activationDataStorage
.localStorage
.shrink(0);
546 void JSGlobalObject::tearOffActivation(ExecState
* exec
, bool leaveRelic
)
548 ActivationImp
* oldActivation
= exec
->activationObject();
549 if (!oldActivation
|| !oldActivation
->isOnStack())
552 ASSERT(exec
->codeType() == FunctionCode
);
553 ActivationImp
* newActivation
= new ActivationImp(*oldActivation
->d(), leaveRelic
);
556 checkActivationCount();
557 d()->activationCount
--;
560 oldActivation
->d()->localStorage
.shrink(0);
562 exec
->setActivationObject(newActivation
);
563 exec
->setVariableObject(newActivation
);
564 exec
->setLocalStorage(&newActivation
->localStorage());
565 exec
->replaceScopeChainTop(newActivation
);