]> git.saurik.com Git - apple/javascriptcore.git/blob - kjs/JSGlobalObject.cpp
JavaScriptCore-466.1.6.tar.gz
[apple/javascriptcore.git] / 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 "Activation.h"
34 #include "array_object.h"
35 #include "bool_object.h"
36 #include "date_object.h"
37 #include "debugger.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"
46
47 #if HAVE(SYS_TIME_H)
48 #include <sys/time.h>
49 #endif
50
51 #if PLATFORM(WIN_OS)
52 #include <windows.h>
53 #endif
54
55 #if PLATFORM(QT)
56 #include <QDateTime>
57 #endif
58
59 namespace KJS {
60
61 // Default number of ticks before a timeout check should be done.
62 static const int initialTickCountThreshold = 255;
63
64 // Preferred number of milliseconds between each timeout check
65 static const int preferredScriptCheckTimeInterval = 1000;
66
67 static inline void markIfNeeded(JSValue* v)
68 {
69 if (v && !v->marked())
70 v->mark();
71 }
72
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()
77 {
78 #if HAVE(SYS_TIME_H)
79 struct timeval tv;
80 gettimeofday(&tv, 0);
81 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
82 #elif PLATFORM(QT)
83 QDateTime t = QDateTime::currentDateTime();
84 return t.toTime_t() * 1000 + t.time().msec();
85 #elif PLATFORM(WIN_OS)
86 return timeGetTime();
87 #else
88 #error Platform does not have getCurrentTime function
89 #endif
90 }
91
92 JSGlobalObject* JSGlobalObject::s_head = 0;
93
94 void JSGlobalObject::deleteActivationStack()
95 {
96 ActivationStackNode* prevNode = 0;
97 for (ActivationStackNode* currentNode = d()->activations; currentNode; currentNode = prevNode) {
98 prevNode = currentNode->prev;
99 delete currentNode;
100 }
101 }
102
103 JSGlobalObject::~JSGlobalObject()
104 {
105 ASSERT(JSLock::currentThreadIsHoldingLock());
106
107 if (d()->debugger)
108 d()->debugger->detach(this);
109
110 d()->next->d()->prev = d()->prev;
111 d()->prev->d()->next = d()->next;
112 s_head = d()->next;
113 if (s_head == this)
114 s_head = 0;
115
116 deleteActivationStack();
117
118 delete d();
119 }
120
121 void JSGlobalObject::init()
122 {
123 ASSERT(JSLock::currentThreadIsHoldingLock());
124
125 if (s_head) {
126 d()->prev = s_head;
127 d()->next = s_head->d()->next;
128 s_head->d()->next->d()->prev = this;
129 s_head->d()->next = this;
130 } else
131 s_head = d()->next = d()->prev = this;
132
133 d()->compatMode = NativeMode;
134
135 resetTimeoutCheck();
136 d()->timeoutTime = 0;
137 d()->timeoutCheckCount = 0;
138
139 d()->recursion = 0;
140 d()->debugger = 0;
141
142 ActivationStackNode* newStackNode = new ActivationStackNode;
143 newStackNode->prev = 0;
144 d()->activations = newStackNode;
145 d()->activationCount = 0;
146
147 reset(prototype());
148 }
149
150 bool JSGlobalObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
151 {
152 if (symbolTableGet(propertyName, slot))
153 return true;
154 return JSVariableObject::getOwnPropertySlot(exec, propertyName, slot);
155 }
156
157 void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
158 {
159 if (symbolTablePut(propertyName, value, !(attr & ~DontDelete)))
160 return;
161 return JSVariableObject::put(exec, propertyName, value, attr);
162 }
163
164 static inline JSObject* lastInPrototypeChain(JSObject* object)
165 {
166 JSObject* o = object;
167 while (o->prototype()->isObject())
168 o = static_cast<JSObject*>(o->prototype());
169 return o;
170 }
171
172 void JSGlobalObject::reset(JSValue* prototype)
173 {
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.)
177
178 _prop.clear();
179 localStorage().clear();
180 symbolTable().clear();
181
182 // Prototypes
183 d()->functionPrototype = 0;
184 d()->objectPrototype = 0;
185
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;
193
194 d()->evalErrorPrototype = 0;
195 d()->rangeErrorPrototype = 0;
196 d()->referenceErrorPrototype = 0;
197 d()->syntaxErrorPrototype = 0;
198 d()->typeErrorPrototype = 0;
199 d()->URIErrorPrototype = 0;
200
201 // Constructors
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;
211
212 d()->evalErrorConstructor = 0;
213 d()->rangeErrorConstructor = 0;
214 d()->referenceErrorConstructor = 0;
215 d()->syntaxErrorConstructor = 0;
216 d()->typeErrorConstructor = 0;
217 d()->URIErrorConstructor = 0;
218
219 ExecState* exec = &d()->globalExec;
220
221 // Prototypes
222 d()->functionPrototype = new FunctionPrototype(exec);
223 d()->objectPrototype = new ObjectPrototype(exec, d()->functionPrototype);
224 d()->functionPrototype->setPrototype(d()->objectPrototype);
225
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);
233
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");
240
241 // Constructors
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);
251
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);
258
259 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);
260
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);
276
277 // Set global constructors
278
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
281 // properties.
282
283 // FIXME: These properties should be handled by a static hash table.
284
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);
300
301 // Set global values.
302
303 putDirect("Math", new MathObjectImp(exec, d()->objectPrototype), DontEnum);
304
305 putDirect("NaN", jsNaN(), DontEnum | DontDelete);
306 putDirect("Infinity", jsNumber(Inf), DontEnum | DontDelete);
307 putDirect("undefined", jsUndefined(), DontEnum | DontDelete);
308
309 // Set global functions.
310
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);
322 #ifndef NDEBUG
323 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "kjsprint", globalFuncKJSPrint), DontEnum);
324 #endif
325
326 // Set prototype, and also insert the object prototype at the end of the chain.
327
328 setPrototype(prototype);
329 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
330 }
331
332 void JSGlobalObject::startTimeoutCheck()
333 {
334 if (!d()->timeoutCheckCount)
335 resetTimeoutCheck();
336
337 ++d()->timeoutCheckCount;
338 }
339
340 void JSGlobalObject::stopTimeoutCheck()
341 {
342 --d()->timeoutCheckCount;
343 }
344
345 void JSGlobalObject::resetTimeoutCheck()
346 {
347 d()->tickCount = 0;
348 d()->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
349 d()->timeAtLastCheckTimeout = 0;
350 d()->timeExecuting = 0;
351 }
352
353 bool JSGlobalObject::checkTimeout()
354 {
355 d()->tickCount = 0;
356
357 unsigned currentTime = getCurrentTime();
358
359 if (!d()->timeAtLastCheckTimeout) {
360 // Suspicious amount of looping in a script -- start timing it
361 d()->timeAtLastCheckTimeout = currentTime;
362 return false;
363 }
364
365 unsigned timeDiff = currentTime - d()->timeAtLastCheckTimeout;
366
367 if (timeDiff == 0)
368 timeDiff = 1;
369
370 d()->timeExecuting += timeDiff;
371 d()->timeAtLastCheckTimeout = currentTime;
372
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;
376
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;
381
382 if (shouldInterruptScriptBeforeTimeout())
383 return true;
384
385 if (d()->timeoutTime && d()->timeExecuting > d()->timeoutTime) {
386 if (shouldInterruptScript())
387 return true;
388
389 resetTimeoutCheck();
390 }
391
392 return false;
393 }
394
395 void JSGlobalObject::saveBuiltins(SavedBuiltins& builtins) const
396 {
397 if (!builtins._internal)
398 builtins._internal = new SavedBuiltinsInternal;
399
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;
415
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;
431 }
432
433 void JSGlobalObject::restoreBuiltins(const SavedBuiltins& builtins)
434 {
435 if (!builtins._internal)
436 return;
437
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;
453
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;
469 }
470
471 void JSGlobalObject::mark()
472 {
473 JSVariableObject::mark();
474
475 markIfNeeded(d()->globalExec.exception());
476
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);
492
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);
508 }
509
510 ExecState* JSGlobalObject::globalExec()
511 {
512 return &d()->globalExec;
513 }
514
515 ActivationImp* JSGlobalObject::pushActivation(ExecState* exec)
516 {
517 if (d()->activationCount == activationStackNodeSize) {
518 ActivationStackNode* newNode = new ActivationStackNode;
519 newNode->prev = d()->activations;
520 d()->activations = newNode;
521 d()->activationCount = 0;
522 }
523
524 StackActivation* stackEntry = &d()->activations->data[d()->activationCount++];
525 stackEntry->activationStorage.init(exec);
526 return &stackEntry->activationStorage;
527 }
528
529 inline void JSGlobalObject::checkActivationCount()
530 {
531 if (!d()->activationCount) {
532 ActivationStackNode* prev = d()->activations->prev;
533 ASSERT(prev);
534 delete d()->activations;
535 d()->activations = prev;
536 d()->activationCount = activationStackNodeSize;
537 }
538 }
539
540 void JSGlobalObject::popActivation()
541 {
542 checkActivationCount();
543 d()->activations->data[--d()->activationCount].activationDataStorage.localStorage.shrink(0);
544 }
545
546 void JSGlobalObject::tearOffActivation(ExecState* exec, bool leaveRelic)
547 {
548 ActivationImp* oldActivation = exec->activationObject();
549 if (!oldActivation || !oldActivation->isOnStack())
550 return;
551
552 ASSERT(exec->codeType() == FunctionCode);
553 ActivationImp* newActivation = new ActivationImp(*oldActivation->d(), leaveRelic);
554
555 if (!leaveRelic) {
556 checkActivationCount();
557 d()->activationCount--;
558 }
559
560 oldActivation->d()->localStorage.shrink(0);
561
562 exec->setActivationObject(newActivation);
563 exec->setVariableObject(newActivation);
564 exec->setLocalStorage(&newActivation->localStorage());
565 exec->replaceScopeChainTop(newActivation);
566 }
567
568 } // namespace KJS