source: webkit/trunk/JavaScriptCore/kjs/JSGlobalObject.cpp@ 34582

Last change on this file since 34582 was 34582, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-06-15 Darin Adler <Darin Adler>

  • API/JSCallbackFunction.cpp:
  • API/JSObjectRef.cpp:
  • DerivedSources.make:
  • GNUmakefile.am:
  • JavaScriptCore.exp:
  • JavaScriptCore.pri:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • VM/Machine.cpp:
  • kjs/AllInOneFile.cpp:
  • kjs/ArrayPrototype.cpp: Copied from JavaScriptCore/kjs/array_object.cpp.
  • kjs/ArrayPrototype.h: Copied from JavaScriptCore/kjs/array_object.h.
  • kjs/BooleanObject.cpp: Copied from JavaScriptCore/kjs/bool_object.cpp.
  • kjs/BooleanObject.h: Copied from JavaScriptCore/kjs/bool_object.h.
  • kjs/ExecState.cpp:
  • kjs/ExecState.h:
  • kjs/FunctionPrototype.cpp: Copied from JavaScriptCore/kjs/function_object.cpp.
  • kjs/FunctionPrototype.h: Copied from JavaScriptCore/kjs/function_object.h.
  • kjs/JSArray.cpp: Copied from JavaScriptCore/kjs/array_instance.cpp.
  • kjs/JSArray.h: Copied from JavaScriptCore/kjs/array_instance.h.
  • kjs/JSFunction.cpp:
  • kjs/JSFunction.h:
  • kjs/JSGlobalObject.cpp:
  • kjs/JSImmediate.cpp:
  • kjs/JSObject.h:
  • kjs/JSString.h:
  • kjs/JSValue.h:
  • kjs/JSVariableObject.cpp:
  • kjs/MathObject.cpp: Copied from JavaScriptCore/kjs/math_object.cpp.
  • kjs/MathObject.h: Copied from JavaScriptCore/kjs/math_object.h.
  • kjs/NumberObject.cpp: Copied from JavaScriptCore/kjs/number_object.cpp.
  • kjs/NumberObject.h: Copied from JavaScriptCore/kjs/number_object.h.
  • kjs/PropertyMap.cpp: Copied from JavaScriptCore/kjs/property_map.cpp.
  • kjs/PropertyMap.h: Copied from JavaScriptCore/kjs/property_map.h.
  • kjs/PropertySlot.cpp: Copied from JavaScriptCore/kjs/property_slot.cpp.
  • kjs/PropertySlot.h: Copied from JavaScriptCore/kjs/property_slot.h.
  • kjs/RegExpObject.cpp: Copied from JavaScriptCore/kjs/regexp_object.cpp.
  • kjs/RegExpObject.h: Copied from JavaScriptCore/kjs/regexp_object.h.
  • kjs/ScopeChain.cpp: Copied from JavaScriptCore/kjs/scope_chain.cpp.
  • kjs/ScopeChain.h: Copied from JavaScriptCore/kjs/scope_chain.h.
  • kjs/ScopeChainMark.h: Copied from JavaScriptCore/kjs/scope_chain_mark.h.
  • kjs/Shell.cpp:
  • kjs/array_instance.cpp: Removed.
  • kjs/array_instance.h: Removed.
  • kjs/array_object.cpp: Removed.
  • kjs/array_object.h: Removed.
  • kjs/bool_object.cpp: Removed.
  • kjs/bool_object.h: Removed.
  • kjs/error_object.h:
  • kjs/function_object.cpp: Removed.
  • kjs/function_object.h: Removed.
  • kjs/internal.cpp:
  • kjs/math_object.cpp: Removed.
  • kjs/math_object.h: Removed.
  • kjs/nodes.cpp:
  • kjs/number_object.cpp: Removed.
  • kjs/number_object.h: Removed.
  • kjs/object_object.cpp:
  • kjs/property_map.cpp: Removed.
  • kjs/property_map.h: Removed.
  • kjs/property_slot.cpp: Removed.
  • kjs/property_slot.h: Removed.
  • kjs/regexp_object.cpp: Removed.
  • kjs/regexp_object.h: Removed.
  • kjs/scope_chain.cpp: Removed.
  • kjs/scope_chain.h: Removed.
  • kjs/scope_chain_mark.h: Removed.
  • kjs/string_object.cpp:
  • kjs/string_object.h:

WebCore:

2008-06-15 Darin Adler <Darin Adler>

  • ForwardingHeaders/kjs/ArrayPrototype.h: Copied from WebCore/ForwardingHeaders/kjs/array_object.h.
  • ForwardingHeaders/kjs/BooleanObject.h: Copied from WebCore/ForwardingHeaders/kjs/bool_object.h.
  • ForwardingHeaders/kjs/FunctionPrototype.h: Copied from WebCore/ForwardingHeaders/kjs/function_object.h.
  • ForwardingHeaders/kjs/JSArray.h: Copied from WebCore/ForwardingHeaders/kjs/array_instance.h.
  • ForwardingHeaders/kjs/PropertyMap.h: Copied from WebCore/ForwardingHeaders/kjs/property_map.h.
  • ForwardingHeaders/kjs/array_instance.h: Removed.
  • ForwardingHeaders/kjs/array_object.h: Removed.
  • ForwardingHeaders/kjs/bool_object.h: Removed.
  • ForwardingHeaders/kjs/function_object.h: Removed.
  • ForwardingHeaders/kjs/property_map.h: Removed.
  • WebCore.vcproj/WebCore.vcproj:
  • bindings/js/JSClipboardCustom.cpp:
  • bindings/js/JSDatabaseCustom.cpp:
  • bindings/js/JSJavaScriptCallFrameCustom.cpp:
  • bindings/js/kjs_events.cpp:
  • bridge/jni/jni_utility.cpp:
  • bridge/qt/qt_runtime.cpp:
  • bridge/runtime_array.cpp:

WebKit/mac:

2008-06-15 Darin Adler <Darin Adler>

  • WebView/WebView.mm:

WebKit/qt:

2008-06-15 Darin Adler <Darin Adler>

  • WebKit_pch.h:

WebKitTools:

2008-06-15 Darin Adler <Darin Adler>

  • Scripts/do-file-rename: Updated.
  • Scripts/do-webcore-rename: Updated for the latest round of renaming.
  • Property svn:eol-style set to native
File size: 18.6 KB
Line 
1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich ([email protected])
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 "CodeBlock.h"
34#include "ArrayPrototype.h"
35#include "BooleanObject.h"
36#include "date_object.h"
37#include "debugger.h"
38#include "error_object.h"
39#include "FunctionPrototype.h"
40#include "MathObject.h"
41#include "NumberObject.h"
42#include "object_object.h"
43#include "RegExpObject.h"
44#include "ScopeChainMark.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
59namespace KJS {
60
61// Default number of ticks before a timeout check should be done.
62static const int initialTickCountThreshold = 255;
63
64// Preferred number of milliseconds between each timeout check
65static const int preferredScriptCheckTimeInterval = 1000;
66
67static 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.
76static 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
92JSGlobalObject* JSGlobalObject::s_head = 0;
93
94JSGlobalObject::~JSGlobalObject()
95{
96 ASSERT(JSLock::currentThreadIsHoldingLock());
97
98 if (d()->debugger)
99 d()->debugger->detach(this);
100
101 d()->next->d()->prev = d()->prev;
102 d()->prev->d()->next = d()->next;
103 s_head = d()->next;
104 if (s_head == this)
105 s_head = 0;
106
107 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
108 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
109 (*it)->globalObject = 0;
110
111 delete d();
112}
113
114void JSGlobalObject::init(JSObject* thisValue)
115{
116 ASSERT(JSLock::currentThreadIsHoldingLock());
117
118 if (s_head) {
119 d()->prev = s_head;
120 d()->next = s_head->d()->next;
121 s_head->d()->next->d()->prev = this;
122 s_head->d()->next = this;
123 } else
124 s_head = d()->next = d()->prev = this;
125
126 resetTimeoutCheck();
127 d()->timeoutTime = 0;
128 d()->timeoutCheckCount = 0;
129
130 d()->recursion = 0;
131 d()->debugger = 0;
132
133 d()->globalData = &JSGlobalData::threadInstance();
134
135 d()->globalExec.set(new ExecState(this, thisValue, d()->globalScopeChain.node()));
136
137 d()->pageGroupIdentifier = 0;
138
139 reset(prototype());
140}
141
142void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
143{
144 if (symbolTablePut(propertyName, value))
145 return;
146 return JSVariableObject::put(exec, propertyName, value);
147}
148
149void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
150{
151 if (symbolTablePutWithAttributes(propertyName, value, attributes))
152 return;
153
154 JSValue* valueBefore = getDirect(propertyName);
155 JSVariableObject::put(exec, propertyName, value);
156 if (!valueBefore) {
157 if (JSValue* valueAfter = getDirect(propertyName))
158 putDirect(propertyName, valueAfter, attributes);
159 }
160}
161
162void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
163{
164 PropertySlot slot;
165 if (!symbolTableGet(propertyName, slot))
166 JSVariableObject::defineGetter(exec, propertyName, getterFunc);
167}
168
169void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
170{
171 PropertySlot slot;
172 if (!symbolTableGet(propertyName, slot))
173 JSVariableObject::defineSetter(exec, propertyName, setterFunc);
174}
175
176static inline JSObject* lastInPrototypeChain(JSObject* object)
177{
178 JSObject* o = object;
179 while (o->prototype()->isObject())
180 o = static_cast<JSObject*>(o->prototype());
181 return o;
182}
183
184void JSGlobalObject::reset(JSValue* prototype)
185{
186 // Clear before inititalizing, to avoid calling mark() on stale pointers --
187 // which would be wasteful -- or uninitialized pointers -- which would be
188 // dangerous. (The allocations below may cause a GC.)
189
190 _prop.clear();
191 registerFileStack().current()->clear();
192 registerFileStack().current()->addGlobalSlots(1);
193 symbolTable().clear();
194
195 // Prototypes
196 d()->functionPrototype = 0;
197 d()->objectPrototype = 0;
198
199 d()->arrayPrototype = 0;
200 d()->stringPrototype = 0;
201 d()->booleanPrototype = 0;
202 d()->numberPrototype = 0;
203 d()->datePrototype = 0;
204 d()->regExpPrototype = 0;
205 d()->errorPrototype = 0;
206
207 d()->evalErrorPrototype = 0;
208 d()->rangeErrorPrototype = 0;
209 d()->referenceErrorPrototype = 0;
210 d()->syntaxErrorPrototype = 0;
211 d()->typeErrorPrototype = 0;
212 d()->URIErrorPrototype = 0;
213
214 // Constructors
215 d()->objectConstructor = 0;
216 d()->functionConstructor = 0;
217 d()->arrayConstructor = 0;
218 d()->stringConstructor = 0;
219 d()->booleanConstructor = 0;
220 d()->numberConstructor = 0;
221 d()->dateConstructor = 0;
222 d()->regExpConstructor = 0;
223 d()->errorConstructor = 0;
224
225 d()->evalErrorConstructor = 0;
226 d()->rangeErrorConstructor = 0;
227 d()->referenceErrorConstructor = 0;
228 d()->syntaxErrorConstructor = 0;
229 d()->typeErrorConstructor = 0;
230 d()->URIErrorConstructor = 0;
231
232 d()->evalFunction = 0;
233
234 ExecState* exec = d()->globalExec.get();
235
236 // Prototypes
237 d()->functionPrototype = new FunctionPrototype(exec);
238 d()->objectPrototype = new ObjectPrototype(exec, d()->functionPrototype);
239 d()->functionPrototype->setPrototype(d()->objectPrototype);
240
241 d()->arrayPrototype = new ArrayPrototype(exec, d()->objectPrototype);
242 d()->stringPrototype = new StringPrototype(exec, d()->objectPrototype);
243 d()->booleanPrototype = new BooleanPrototype(exec, d()->objectPrototype, d()->functionPrototype);
244 d()->numberPrototype = new NumberPrototype(exec, d()->objectPrototype, d()->functionPrototype);
245 d()->datePrototype = new DatePrototype(exec, d()->objectPrototype);
246 d()->regExpPrototype = new RegExpPrototype(exec, d()->objectPrototype, d()->functionPrototype);
247 d()->errorPrototype = new ErrorPrototype(exec, d()->objectPrototype, d()->functionPrototype);
248
249 d()->evalErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "EvalError", "EvalError");
250 d()->rangeErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "RangeError", "RangeError");
251 d()->referenceErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "ReferenceError", "ReferenceError");
252 d()->syntaxErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "SyntaxError", "SyntaxError");
253 d()->typeErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "TypeError", "TypeError");
254 d()->URIErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "URIError", "URIError");
255
256 // Constructors
257 d()->objectConstructor = new ObjectConstructor(exec, d()->objectPrototype, d()->functionPrototype);
258 d()->functionConstructor = new FunctionConstructor(exec, d()->functionPrototype);
259 d()->arrayConstructor = new ArrayConstructor(exec, d()->functionPrototype, d()->arrayPrototype);
260 d()->stringConstructor = new StringConstructor(exec, d()->functionPrototype, d()->stringPrototype);
261 d()->booleanConstructor = new BooleanConstructor(exec, d()->functionPrototype, d()->booleanPrototype);
262 d()->numberConstructor = new NumberConstructor(exec, d()->functionPrototype, d()->numberPrototype);
263 d()->dateConstructor = new DateConstructor(exec, d()->functionPrototype, d()->datePrototype);
264 d()->regExpConstructor = new RegExpConstructor(exec, d()->functionPrototype, d()->regExpPrototype);
265 d()->errorConstructor = new ErrorConstructor(exec, d()->functionPrototype, d()->errorPrototype);
266
267 d()->evalErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->evalErrorPrototype);
268 d()->rangeErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->rangeErrorPrototype);
269 d()->referenceErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->referenceErrorPrototype);
270 d()->syntaxErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->syntaxErrorPrototype);
271 d()->typeErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->typeErrorPrototype);
272 d()->URIErrorConstructor = new NativeErrorConstructor(exec, d()->functionPrototype, d()->URIErrorPrototype);
273
274 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);
275
276 d()->objectPrototype->putDirect(exec->propertyNames().constructor, d()->objectConstructor, DontEnum);
277 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);
278 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, d()->arrayConstructor, DontEnum);
279 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, d()->booleanConstructor, DontEnum);
280 d()->stringPrototype->putDirect(exec->propertyNames().constructor, d()->stringConstructor, DontEnum);
281 d()->numberPrototype->putDirect(exec->propertyNames().constructor, d()->numberConstructor, DontEnum);
282 d()->datePrototype->putDirect(exec->propertyNames().constructor, d()->dateConstructor, DontEnum);
283 d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
284 d()->errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
285 d()->evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
286 d()->rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
287 d()->referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
288 d()->syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
289 d()->typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
290 d()->URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
291
292 // Set global constructors
293
294 // FIXME: These properties could be handled by a static hash table.
295
296 putDirect("Object", d()->objectConstructor, DontEnum);
297 putDirect("Function", d()->functionConstructor, DontEnum);
298 putDirect("Array", d()->arrayConstructor, DontEnum);
299 putDirect("Boolean", d()->booleanConstructor, DontEnum);
300 putDirect("String", d()->stringConstructor, DontEnum);
301 putDirect("Number", d()->numberConstructor, DontEnum);
302 putDirect("Date", d()->dateConstructor, DontEnum);
303 putDirect("RegExp", d()->regExpConstructor, DontEnum);
304 putDirect("Error", d()->errorConstructor, DontEnum);
305 putDirect("EvalError", d()->evalErrorConstructor);
306 putDirect("RangeError", d()->rangeErrorConstructor);
307 putDirect("ReferenceError", d()->referenceErrorConstructor);
308 putDirect("SyntaxError", d()->syntaxErrorConstructor);
309 putDirect("TypeError", d()->typeErrorConstructor);
310 putDirect("URIError", d()->URIErrorConstructor);
311
312 // Set global values.
313 GlobalPropertyInfo staticGlobals[] = {
314 GlobalPropertyInfo("Math", new MathObject(exec, d()->objectPrototype), DontEnum | DontDelete),
315 GlobalPropertyInfo("NaN", jsNaN(), DontEnum | DontDelete),
316 GlobalPropertyInfo("Infinity", jsNumber(Inf), DontEnum | DontDelete),
317 GlobalPropertyInfo("undefined", jsUndefined(), DontEnum | DontDelete)
318 };
319
320 addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
321
322 // Set global functions.
323
324 d()->evalFunction = new PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval, this);
325 putDirectFunction(d()->evalFunction, DontEnum);
326 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 2, "parseInt", globalFuncParseInt), DontEnum);
327 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "parseFloat", globalFuncParseFloat), DontEnum);
328 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "isNaN", globalFuncIsNaN), DontEnum);
329 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "isFinite", globalFuncIsFinite), DontEnum);
330 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "escape", globalFuncEscape), DontEnum);
331 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "unescape", globalFuncUnescape), DontEnum);
332 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "decodeURI", globalFuncDecodeURI), DontEnum);
333 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "decodeURIComponent", globalFuncDecodeURIComponent), DontEnum);
334 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "encodeURI", globalFuncEncodeURI), DontEnum);
335 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "encodeURIComponent", globalFuncEncodeURIComponent), DontEnum);
336#ifndef NDEBUG
337 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "kjsprint", globalFuncKJSPrint), DontEnum);
338#endif
339
340 // Set prototype, and also insert the object prototype at the end of the chain.
341
342 setPrototype(prototype);
343 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
344}
345
346void JSGlobalObject::startTimeoutCheck()
347{
348 if (!d()->timeoutCheckCount)
349 resetTimeoutCheck();
350
351 ++d()->timeoutCheckCount;
352}
353
354void JSGlobalObject::stopTimeoutCheck()
355{
356 --d()->timeoutCheckCount;
357}
358
359void JSGlobalObject::resetTimeoutCheck()
360{
361 d()->tickCount = 0;
362 d()->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
363 d()->timeAtLastCheckTimeout = 0;
364 d()->timeExecuting = 0;
365}
366
367bool JSGlobalObject::checkTimeout()
368{
369 d()->tickCount = 0;
370
371 unsigned currentTime = getCurrentTime();
372
373 if (!d()->timeAtLastCheckTimeout) {
374 // Suspicious amount of looping in a script -- start timing it
375 d()->timeAtLastCheckTimeout = currentTime;
376 return false;
377 }
378
379 unsigned timeDiff = currentTime - d()->timeAtLastCheckTimeout;
380
381 if (timeDiff == 0)
382 timeDiff = 1;
383
384 d()->timeExecuting += timeDiff;
385 d()->timeAtLastCheckTimeout = currentTime;
386
387 // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in
388 // preferredScriptCheckTimeInterval
389 d()->ticksUntilNextTimeoutCheck = (unsigned)((float)preferredScriptCheckTimeInterval / timeDiff) * d()->ticksUntilNextTimeoutCheck;
390
391 // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
392 // preferred script check time interval.
393 if (d()->ticksUntilNextTimeoutCheck == 0)
394 d()->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
395
396 if (d()->timeoutTime && d()->timeExecuting > d()->timeoutTime) {
397 if (shouldInterruptScript())
398 return true;
399
400 resetTimeoutCheck();
401 }
402
403 return false;
404}
405
406void JSGlobalObject::mark()
407{
408 JSVariableObject::mark();
409
410 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
411 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
412 (*it)->mark();
413
414 registerFileStack().mark();
415
416 markIfNeeded(d()->globalExec->exception());
417
418 markIfNeeded(d()->objectConstructor);
419 markIfNeeded(d()->functionConstructor);
420 markIfNeeded(d()->arrayConstructor);
421 markIfNeeded(d()->booleanConstructor);
422 markIfNeeded(d()->stringConstructor);
423 markIfNeeded(d()->numberConstructor);
424 markIfNeeded(d()->dateConstructor);
425 markIfNeeded(d()->regExpConstructor);
426 markIfNeeded(d()->errorConstructor);
427 markIfNeeded(d()->evalErrorConstructor);
428 markIfNeeded(d()->rangeErrorConstructor);
429 markIfNeeded(d()->referenceErrorConstructor);
430 markIfNeeded(d()->syntaxErrorConstructor);
431 markIfNeeded(d()->typeErrorConstructor);
432 markIfNeeded(d()->URIErrorConstructor);
433
434 markIfNeeded(d()->evalFunction);
435
436 markIfNeeded(d()->objectPrototype);
437 markIfNeeded(d()->functionPrototype);
438 markIfNeeded(d()->arrayPrototype);
439 markIfNeeded(d()->booleanPrototype);
440 markIfNeeded(d()->stringPrototype);
441 markIfNeeded(d()->numberPrototype);
442 markIfNeeded(d()->datePrototype);
443 markIfNeeded(d()->regExpPrototype);
444 markIfNeeded(d()->errorPrototype);
445 markIfNeeded(d()->evalErrorPrototype);
446 markIfNeeded(d()->rangeErrorPrototype);
447 markIfNeeded(d()->referenceErrorPrototype);
448 markIfNeeded(d()->syntaxErrorPrototype);
449 markIfNeeded(d()->typeErrorPrototype);
450 markIfNeeded(d()->URIErrorPrototype);
451}
452
453JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
454{
455 return const_cast<JSGlobalObject*>(this);
456}
457
458ExecState* JSGlobalObject::globalExec()
459{
460 return d()->globalExec.get();
461}
462
463bool JSGlobalObject::isDynamicScope() const
464{
465 return true;
466}
467
468
469} // namespace KJS
Note: See TracBrowser for help on using the repository browser.