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

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

JavaScriptCore:

Reviewed by Anders.

  • API/JSCallbackObject.h: Removed attribute arguments.
  • API/JSCallbackObjectFunctions.h: (KJS::JSCallbackObject<Base>::put): Ditto.
  • API/JSObjectRef.cpp: (JSObjectSetProperty): Use initializeVariable or putDirect when necessary to set attribute values.
  • JavaScriptCore.exp: Updated.
  • bindings/objc/objc_runtime.h: Removed attribute arguments.
  • bindings/objc/objc_runtime.mm: (ObjcFallbackObjectImp::put): Ditto.
  • bindings/runtime_array.cpp: (RuntimeArray::put): Ditto.
  • bindings/runtime_array.h: Ditto.
  • bindings/runtime_object.cpp: (RuntimeObjectImp::put): Ditto.
  • bindings/runtime_object.h: Ditto. Also removed canPut which was only called from one place in WebCore that can use hasProperty instead.
  • kjs/Activation.h: Removed attribute argument from put and added the new initializeVariable function that's used to put variables in variable objects. Also made isActivationObject a const member.
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::put): Removed attribute argument. (KJS::JSGlobalObject::initializeVariable): Added. Used to give variables their initial values, which can include the read-only property. (KJS::JSGlobalObject::reset): Removed obsolete comments about flags. Removed Internal flag, which is no longer needed.
  • kjs/JSGlobalObject.h: More of the same.
  • kjs/JSVariableObject.h: Added pure virtual initializeVariable function. (KJS::JSVariableObject::symbolTablePut): Removed checkReadOnly flag; we always check read-only. (KJS::JSVariableObject::symbolTableInitializeVariable): Added.
  • kjs/array_instance.cpp: (KJS::ArrayInstance::put): Removed attribute argument.
  • kjs/array_instance.h: Ditto.
  • kjs/function.cpp: (KJS::FunctionImp::put): Ditto. (KJS::Arguments::put): Ditto. (KJS::ActivationImp::put): Ditto. (KJS::ActivationImp::initializeVariable): Added.
  • kjs/function.h: Removed attribute arguments.
  • kjs/function_object.cpp: (KJS::FunctionObjectImp::construct): Removed Internal flag.
  • kjs/lookup.h: (KJS::lookupPut): Removed attributes argument. Also changed to use putDirect instead of calling JSObject::put. (KJS::cacheGlobalObject): Ditto.
  • kjs/nodes.cpp: (KJS::ConstDeclNode::handleSlowCase): Call initializeVariable to initialize the constant. (KJS::ConstDeclNode::evaluateSingle): Ditto. (KJS::TryNode::execute): Use putDirect to set up the new object. (KJS::FunctionBodyNode::processDeclarations): Removed Internal. (KJS::ProgramNode::processDeclarations): Ditto. (KJS::EvalNode::processDeclarations): Call initializeVariable to initialize the variables and functions. (KJS::FuncDeclNode::makeFunction): Removed Internal. (KJS::FuncExprNode::evaluate): Ditto.
  • kjs/object.cpp: Removed canPut, which was only being used in one code path, not the normal high speed one. (KJS::JSObject::put): Removed attribute argument. Moved the logic from canPut here, in the one code ath that was still using it.
  • kjs/object.h: Removed Internal attribute, ad canPut function. Removed the attributes argument to the put function. Made isActivationObject const.
  • kjs/regexp_object.cpp: (KJS::RegExpImp::put): Removed attributes argument. (KJS::RegExpImp::putValueProperty): Ditto. (KJS::RegExpObjectImp::put): Ditto. (KJS::RegExpObjectImp::putValueProperty): Ditto.
  • kjs/regexp_object.h: Ditto.
  • kjs/string_object.cpp: (KJS::StringInstance::put): Removed attributes argument.
  • kjs/string_object.h: Ditto.

WebCore:

Reviewed by Anders.

  • bindings/js/JSCSSStyleDeclarationCustom.cpp: (WebCore::JSCSSStyleDeclaration::customPut): Remove attributes argument.
  • bindings/js/JSCanvasPixelArrayCustom.cpp: (WebCore::JSCanvasPixelArray::indexGetter): Use early exit idiom. (WebCore::JSCanvasPixelArray::indexSetter): Moved length check into the CanvasPixelArray object, for consistency with the getter. Removed attributes argument.
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::customPut): Removed special case for variable initialization, which is not needed since that does use put any more. Removed attributes argument.
  • bindings/js/JSEventTargetBase.h: (WebCore::JSEventTargetBase::putValueProperty): Removed attributes argument. (WebCore::JSEventTargetBase::put): Ditto. (WebCore::JSEventTargetPrototype::self): Removed Internal flag.
  • bindings/js/JSEventTargetNode.cpp: (WebCore::JSEventTargetNode::put): Removed attributes argument. (WebCore::JSEventTargetNode::putValueProperty): Ditto.
  • bindings/js/JSEventTargetNode.h: Ditto.
  • bindings/js/JSHTMLAppletElementCustom.cpp: (WebCore::JSHTMLAppletElement::customPut): Ditto.
  • bindings/js/JSHTMLEmbedElementCustom.cpp: (WebCore::JSHTMLEmbedElement::customPut): Ditto.
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBase::put): Ditto. (WebCore::JSHTMLInputElementBase::putValueProperty): Ditto.
  • bindings/js/JSHTMLInputElementBase.h: Ditto.
  • bindings/js/JSHTMLObjectElementCustom.cpp: (WebCore::JSHTMLObjectElement::customPut): Ditto.
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp: (WebCore::JSHTMLOptionsCollection::indexSetter): Ditto.
  • bindings/js/JSHTMLSelectElementCustom.cpp: (WebCore::JSHTMLSelectElement::indexSetter): Ditto.
  • bindings/js/JSHistoryCustom.cpp: (WebCore::JSHistory::customPut): Ditto.
  • bindings/js/JSLocation.cpp: (WebCore::JSLocation::put): Ditto.
  • bindings/js/JSLocation.h: Ditto.
  • bindings/js/JSXMLHttpRequest.cpp: (WebCore::JSXMLHttpRequest::put): Ditto. (WebCore::JSXMLHttpRequest::putValueProperty): Ditto.
  • bindings/js/JSXMLHttpRequest.h: Ditto.
  • bindings/js/kjs_dom.cpp: (WebCore::getRuntimeObject): Changed return type to JSObject*.
  • bindings/js/kjs_dom.h: Ditto.
  • bindings/js/kjs_events.cpp: (WebCore::JSClipboard::put): Removed attributes argument. (WebCore::JSClipboard::putValueProperty): Ditto.
  • bindings/js/kjs_events.h: Ditto.
  • bindings/js/kjs_html.cpp: (WebCore::runtimeObjectGetter): Updated for change to getRuntimeObject to return a JSObject. Used early exit idiom. (WebCore::runtimeObjectPropertyGetter): Ditto. (WebCore::runtimeObjectCustomGetOwnPropertySlot): Ditto. (WebCore::runtimeObjectCustomPut): Use hasProperty to check for properties that we should put with the property syntax instead of canPut. (WebCore::runtimeObjectImplementsCall): Ditto. (WebCore::runtimeObjectCallAsFunction): Ditto.
  • bindings/js/kjs_html.h: Removed attributes argument to runtimeObjectCustomPut.
  • bindings/js/kjs_window.cpp: (KJS::Window::put): Removed attributes argument.
  • bindings/js/kjs_window.h: Ditto.
  • bindings/scripts/CodeGeneratorJS.pm: Removed attributes argument from put, putValueProperty, customPut, and indexSetter.
  • html/CanvasPixelArray.h: (WebCore::CanvasPixelArray::set): Added index checking here, as in the get function. Before, the checking was done in the JavaScript bindings for set.
  • Property svn:eol-style set to native
File size: 23.5 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 "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
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
94void 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
103JSGlobalObject::~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
121void 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 resetTimeoutCheck();
134 d()->timeoutTime = 0;
135 d()->timeoutCheckCount = 0;
136
137 d()->recursion = 0;
138 d()->debugger = 0;
139
140 ActivationStackNode* newStackNode = new ActivationStackNode;
141 newStackNode->prev = 0;
142 d()->activations = newStackNode;
143 d()->activationCount = 0;
144
145 reset(prototype());
146}
147
148bool JSGlobalObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
149{
150 if (symbolTableGet(propertyName, slot))
151 return true;
152 return JSVariableObject::getOwnPropertySlot(exec, propertyName, slot);
153}
154
155void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
156{
157 if (symbolTablePut(propertyName, value))
158 return;
159 return JSVariableObject::put(exec, propertyName, value);
160}
161
162void JSGlobalObject::initializeVariable(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
163{
164 if (symbolTableInitializeVariable(propertyName, value, attributes))
165 return;
166
167 JSValue* valueBefore = getDirect(propertyName);
168 JSVariableObject::put(exec, propertyName, value);
169 if (!valueBefore) {
170 if (JSValue* valueAfter = getDirect(propertyName))
171 putDirect(propertyName, valueAfter, attributes);
172 }
173}
174
175static inline JSObject* lastInPrototypeChain(JSObject* object)
176{
177 JSObject* o = object;
178 while (o->prototype()->isObject())
179 o = static_cast<JSObject*>(o->prototype());
180 return o;
181}
182
183void JSGlobalObject::reset(JSValue* prototype)
184{
185 // Clear before inititalizing, to avoid calling mark() on stale pointers --
186 // which would be wasteful -- or uninitialized pointers -- which would be
187 // dangerous. (The allocations below may cause a GC.)
188
189 _prop.clear();
190 localStorage().clear();
191 symbolTable().clear();
192
193 // Prototypes
194 d()->functionPrototype = 0;
195 d()->objectPrototype = 0;
196
197 d()->arrayPrototype = 0;
198 d()->stringPrototype = 0;
199 d()->booleanPrototype = 0;
200 d()->numberPrototype = 0;
201 d()->datePrototype = 0;
202 d()->regExpPrototype = 0;
203 d()->errorPrototype = 0;
204
205 d()->evalErrorPrototype = 0;
206 d()->rangeErrorPrototype = 0;
207 d()->referenceErrorPrototype = 0;
208 d()->syntaxErrorPrototype = 0;
209 d()->typeErrorPrototype = 0;
210 d()->URIErrorPrototype = 0;
211
212 // Constructors
213 d()->objectConstructor = 0;
214 d()->functionConstructor = 0;
215 d()->arrayConstructor = 0;
216 d()->stringConstructor = 0;
217 d()->booleanConstructor = 0;
218 d()->numberConstructor = 0;
219 d()->dateConstructor = 0;
220 d()->regExpConstructor = 0;
221 d()->errorConstructor = 0;
222
223 d()->evalErrorConstructor = 0;
224 d()->rangeErrorConstructor = 0;
225 d()->referenceErrorConstructor = 0;
226 d()->syntaxErrorConstructor = 0;
227 d()->typeErrorConstructor = 0;
228 d()->URIErrorConstructor = 0;
229
230 ExecState* exec = &d()->globalExec;
231
232 // Prototypes
233 d()->functionPrototype = new FunctionPrototype(exec);
234 d()->objectPrototype = new ObjectPrototype(exec, d()->functionPrototype);
235 d()->functionPrototype->setPrototype(d()->objectPrototype);
236
237 d()->arrayPrototype = new ArrayPrototype(exec, d()->objectPrototype);
238 d()->stringPrototype = new StringPrototype(exec, d()->objectPrototype);
239 d()->booleanPrototype = new BooleanPrototype(exec, d()->objectPrototype, d()->functionPrototype);
240 d()->numberPrototype = new NumberPrototype(exec, d()->objectPrototype, d()->functionPrototype);
241 d()->datePrototype = new DatePrototype(exec, d()->objectPrototype);
242 d()->regExpPrototype = new RegExpPrototype(exec, d()->objectPrototype, d()->functionPrototype);
243 d()->errorPrototype = new ErrorPrototype(exec, d()->objectPrototype, d()->functionPrototype);
244
245 d()->evalErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "EvalError", "EvalError");
246 d()->rangeErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "RangeError", "RangeError");
247 d()->referenceErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "ReferenceError", "ReferenceError");
248 d()->syntaxErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "SyntaxError", "SyntaxError");
249 d()->typeErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "TypeError", "TypeError");
250 d()->URIErrorPrototype = new NativeErrorPrototype(exec, d()->errorPrototype, "URIError", "URIError");
251
252 // Constructors
253 d()->objectConstructor = new ObjectObjectImp(exec, d()->objectPrototype, d()->functionPrototype);
254 d()->functionConstructor = new FunctionObjectImp(exec, d()->functionPrototype);
255 d()->arrayConstructor = new ArrayObjectImp(exec, d()->functionPrototype, d()->arrayPrototype);
256 d()->stringConstructor = new StringObjectImp(exec, d()->functionPrototype, d()->stringPrototype);
257 d()->booleanConstructor = new BooleanObjectImp(exec, d()->functionPrototype, d()->booleanPrototype);
258 d()->numberConstructor = new NumberObjectImp(exec, d()->functionPrototype, d()->numberPrototype);
259 d()->dateConstructor = new DateObjectImp(exec, d()->functionPrototype, d()->datePrototype);
260 d()->regExpConstructor = new RegExpObjectImp(exec, d()->functionPrototype, d()->regExpPrototype);
261 d()->errorConstructor = new ErrorObjectImp(exec, d()->functionPrototype, d()->errorPrototype);
262
263 d()->evalErrorConstructor = new NativeErrorImp(exec, d()->functionPrototype, d()->evalErrorPrototype);
264 d()->rangeErrorConstructor = new NativeErrorImp(exec, d()->functionPrototype, d()->rangeErrorPrototype);
265 d()->referenceErrorConstructor = new NativeErrorImp(exec, d()->functionPrototype, d()->referenceErrorPrototype);
266 d()->syntaxErrorConstructor = new NativeErrorImp(exec, d()->functionPrototype, d()->syntaxErrorPrototype);
267 d()->typeErrorConstructor = new NativeErrorImp(exec, d()->functionPrototype, d()->typeErrorPrototype);
268 d()->URIErrorConstructor = new NativeErrorImp(exec, d()->functionPrototype, d()->URIErrorPrototype);
269
270 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);
271
272 d()->objectPrototype->putDirect(exec->propertyNames().constructor, d()->objectConstructor, DontEnum);
273 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);
274 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, d()->arrayConstructor, DontEnum);
275 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, d()->booleanConstructor, DontEnum);
276 d()->stringPrototype->putDirect(exec->propertyNames().constructor, d()->stringConstructor, DontEnum);
277 d()->numberPrototype->putDirect(exec->propertyNames().constructor, d()->numberConstructor, DontEnum);
278 d()->datePrototype->putDirect(exec->propertyNames().constructor, d()->dateConstructor, DontEnum);
279 d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
280 d()->errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
281 d()->evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
282 d()->rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
283 d()->referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
284 d()->syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
285 d()->typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
286 d()->URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
287
288 // Set global constructors
289
290 // FIXME: These properties could be handled by a static hash table.
291
292 putDirect("Object", d()->objectConstructor, DontEnum);
293 putDirect("Function", d()->functionConstructor, DontEnum);
294 putDirect("Array", d()->arrayConstructor, DontEnum);
295 putDirect("Boolean", d()->booleanConstructor, DontEnum);
296 putDirect("String", d()->stringConstructor, DontEnum);
297 putDirect("Number", d()->numberConstructor, DontEnum);
298 putDirect("Date", d()->dateConstructor, DontEnum);
299 putDirect("RegExp", d()->regExpConstructor, DontEnum);
300 putDirect("Error", d()->errorConstructor, DontEnum);
301 putDirect("EvalError", d()->evalErrorConstructor);
302 putDirect("RangeError", d()->rangeErrorConstructor);
303 putDirect("ReferenceError", d()->referenceErrorConstructor);
304 putDirect("SyntaxError", d()->syntaxErrorConstructor);
305 putDirect("TypeError", d()->typeErrorConstructor);
306 putDirect("URIError", d()->URIErrorConstructor);
307
308 // Set global values.
309
310 putDirect("Math", new MathObjectImp(exec, d()->objectPrototype), DontEnum);
311
312 putDirect("NaN", jsNaN(), DontEnum | DontDelete);
313 putDirect("Infinity", jsNumber(Inf), DontEnum | DontDelete);
314 putDirect("undefined", jsUndefined(), DontEnum | DontDelete);
315
316 // Set global functions.
317
318 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "eval", globalFuncEval), DontEnum);
319 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 2, "parseInt", globalFuncParseInt), DontEnum);
320 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "parseFloat", globalFuncParseFloat), DontEnum);
321 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "isNaN", globalFuncIsNaN), DontEnum);
322 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "isFinite", globalFuncIsFinite), DontEnum);
323 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "escape", globalFuncEscape), DontEnum);
324 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "unescape", globalFuncUnescape), DontEnum);
325 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "decodeURI", globalFuncDecodeURI), DontEnum);
326 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "decodeURIComponent", globalFuncDecodeURIComponent), DontEnum);
327 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "encodeURI", globalFuncEncodeURI), DontEnum);
328 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "encodeURIComponent", globalFuncEncodeURIComponent), DontEnum);
329#ifndef NDEBUG
330 putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "kjsprint", globalFuncKJSPrint), DontEnum);
331#endif
332
333 // Set prototype, and also insert the object prototype at the end of the chain.
334
335 setPrototype(prototype);
336 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
337}
338
339void JSGlobalObject::startTimeoutCheck()
340{
341 if (!d()->timeoutCheckCount)
342 resetTimeoutCheck();
343
344 ++d()->timeoutCheckCount;
345}
346
347void JSGlobalObject::stopTimeoutCheck()
348{
349 --d()->timeoutCheckCount;
350}
351
352void JSGlobalObject::resetTimeoutCheck()
353{
354 d()->tickCount = 0;
355 d()->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
356 d()->timeAtLastCheckTimeout = 0;
357 d()->timeExecuting = 0;
358}
359
360bool JSGlobalObject::checkTimeout()
361{
362 d()->tickCount = 0;
363
364 unsigned currentTime = getCurrentTime();
365
366 if (!d()->timeAtLastCheckTimeout) {
367 // Suspicious amount of looping in a script -- start timing it
368 d()->timeAtLastCheckTimeout = currentTime;
369 return false;
370 }
371
372 unsigned timeDiff = currentTime - d()->timeAtLastCheckTimeout;
373
374 if (timeDiff == 0)
375 timeDiff = 1;
376
377 d()->timeExecuting += timeDiff;
378 d()->timeAtLastCheckTimeout = currentTime;
379
380 // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in
381 // preferredScriptCheckTimeInterval
382 d()->ticksUntilNextTimeoutCheck = (unsigned)((float)preferredScriptCheckTimeInterval / timeDiff) * d()->ticksUntilNextTimeoutCheck;
383
384 // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
385 // preferred script check time interval.
386 if (d()->ticksUntilNextTimeoutCheck == 0)
387 d()->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
388
389 if (d()->timeoutTime && d()->timeExecuting > d()->timeoutTime) {
390 if (shouldInterruptScript())
391 return true;
392
393 resetTimeoutCheck();
394 }
395
396 return false;
397}
398
399void JSGlobalObject::saveBuiltins(SavedBuiltins& builtins) const
400{
401 if (!builtins._internal)
402 builtins._internal = new SavedBuiltinsInternal;
403
404 builtins._internal->objectConstructor = d()->objectConstructor;
405 builtins._internal->functionConstructor = d()->functionConstructor;
406 builtins._internal->arrayConstructor = d()->arrayConstructor;
407 builtins._internal->booleanConstructor = d()->booleanConstructor;
408 builtins._internal->stringConstructor = d()->stringConstructor;
409 builtins._internal->numberConstructor = d()->numberConstructor;
410 builtins._internal->dateConstructor = d()->dateConstructor;
411 builtins._internal->regExpConstructor = d()->regExpConstructor;
412 builtins._internal->errorConstructor = d()->errorConstructor;
413 builtins._internal->evalErrorConstructor = d()->evalErrorConstructor;
414 builtins._internal->rangeErrorConstructor = d()->rangeErrorConstructor;
415 builtins._internal->referenceErrorConstructor = d()->referenceErrorConstructor;
416 builtins._internal->syntaxErrorConstructor = d()->syntaxErrorConstructor;
417 builtins._internal->typeErrorConstructor = d()->typeErrorConstructor;
418 builtins._internal->URIErrorConstructor = d()->URIErrorConstructor;
419
420 builtins._internal->objectPrototype = d()->objectPrototype;
421 builtins._internal->functionPrototype = d()->functionPrototype;
422 builtins._internal->arrayPrototype = d()->arrayPrototype;
423 builtins._internal->booleanPrototype = d()->booleanPrototype;
424 builtins._internal->stringPrototype = d()->stringPrototype;
425 builtins._internal->numberPrototype = d()->numberPrototype;
426 builtins._internal->datePrototype = d()->datePrototype;
427 builtins._internal->regExpPrototype = d()->regExpPrototype;
428 builtins._internal->errorPrototype = d()->errorPrototype;
429 builtins._internal->evalErrorPrototype = d()->evalErrorPrototype;
430 builtins._internal->rangeErrorPrototype = d()->rangeErrorPrototype;
431 builtins._internal->referenceErrorPrototype = d()->referenceErrorPrototype;
432 builtins._internal->syntaxErrorPrototype = d()->syntaxErrorPrototype;
433 builtins._internal->typeErrorPrototype = d()->typeErrorPrototype;
434 builtins._internal->URIErrorPrototype = d()->URIErrorPrototype;
435}
436
437void JSGlobalObject::restoreBuiltins(const SavedBuiltins& builtins)
438{
439 if (!builtins._internal)
440 return;
441
442 d()->objectConstructor = builtins._internal->objectConstructor;
443 d()->functionConstructor = builtins._internal->functionConstructor;
444 d()->arrayConstructor = builtins._internal->arrayConstructor;
445 d()->booleanConstructor = builtins._internal->booleanConstructor;
446 d()->stringConstructor = builtins._internal->stringConstructor;
447 d()->numberConstructor = builtins._internal->numberConstructor;
448 d()->dateConstructor = builtins._internal->dateConstructor;
449 d()->regExpConstructor = builtins._internal->regExpConstructor;
450 d()->errorConstructor = builtins._internal->errorConstructor;
451 d()->evalErrorConstructor = builtins._internal->evalErrorConstructor;
452 d()->rangeErrorConstructor = builtins._internal->rangeErrorConstructor;
453 d()->referenceErrorConstructor = builtins._internal->referenceErrorConstructor;
454 d()->syntaxErrorConstructor = builtins._internal->syntaxErrorConstructor;
455 d()->typeErrorConstructor = builtins._internal->typeErrorConstructor;
456 d()->URIErrorConstructor = builtins._internal->URIErrorConstructor;
457
458 d()->objectPrototype = builtins._internal->objectPrototype;
459 d()->functionPrototype = builtins._internal->functionPrototype;
460 d()->arrayPrototype = builtins._internal->arrayPrototype;
461 d()->booleanPrototype = builtins._internal->booleanPrototype;
462 d()->stringPrototype = builtins._internal->stringPrototype;
463 d()->numberPrototype = builtins._internal->numberPrototype;
464 d()->datePrototype = builtins._internal->datePrototype;
465 d()->regExpPrototype = builtins._internal->regExpPrototype;
466 d()->errorPrototype = builtins._internal->errorPrototype;
467 d()->evalErrorPrototype = builtins._internal->evalErrorPrototype;
468 d()->rangeErrorPrototype = builtins._internal->rangeErrorPrototype;
469 d()->referenceErrorPrototype = builtins._internal->referenceErrorPrototype;
470 d()->syntaxErrorPrototype = builtins._internal->syntaxErrorPrototype;
471 d()->typeErrorPrototype = builtins._internal->typeErrorPrototype;
472 d()->URIErrorPrototype = builtins._internal->URIErrorPrototype;
473}
474
475void JSGlobalObject::mark()
476{
477 JSVariableObject::mark();
478
479 markIfNeeded(d()->globalExec.exception());
480
481 markIfNeeded(d()->objectConstructor);
482 markIfNeeded(d()->functionConstructor);
483 markIfNeeded(d()->arrayConstructor);
484 markIfNeeded(d()->booleanConstructor);
485 markIfNeeded(d()->stringConstructor);
486 markIfNeeded(d()->numberConstructor);
487 markIfNeeded(d()->dateConstructor);
488 markIfNeeded(d()->regExpConstructor);
489 markIfNeeded(d()->errorConstructor);
490 markIfNeeded(d()->evalErrorConstructor);
491 markIfNeeded(d()->rangeErrorConstructor);
492 markIfNeeded(d()->referenceErrorConstructor);
493 markIfNeeded(d()->syntaxErrorConstructor);
494 markIfNeeded(d()->typeErrorConstructor);
495 markIfNeeded(d()->URIErrorConstructor);
496
497 markIfNeeded(d()->objectPrototype);
498 markIfNeeded(d()->functionPrototype);
499 markIfNeeded(d()->arrayPrototype);
500 markIfNeeded(d()->booleanPrototype);
501 markIfNeeded(d()->stringPrototype);
502 markIfNeeded(d()->numberPrototype);
503 markIfNeeded(d()->datePrototype);
504 markIfNeeded(d()->regExpPrototype);
505 markIfNeeded(d()->errorPrototype);
506 markIfNeeded(d()->evalErrorPrototype);
507 markIfNeeded(d()->rangeErrorPrototype);
508 markIfNeeded(d()->referenceErrorPrototype);
509 markIfNeeded(d()->syntaxErrorPrototype);
510 markIfNeeded(d()->typeErrorPrototype);
511 markIfNeeded(d()->URIErrorPrototype);
512}
513
514ExecState* JSGlobalObject::globalExec()
515{
516 return &d()->globalExec;
517}
518
519ActivationImp* JSGlobalObject::pushActivation(ExecState* exec)
520{
521 if (d()->activationCount == activationStackNodeSize) {
522 ActivationStackNode* newNode = new ActivationStackNode;
523 newNode->prev = d()->activations;
524 d()->activations = newNode;
525 d()->activationCount = 0;
526 }
527
528 StackActivation* stackEntry = &d()->activations->data[d()->activationCount++];
529 stackEntry->activationStorage.init(exec);
530 return &stackEntry->activationStorage;
531}
532
533inline void JSGlobalObject::checkActivationCount()
534{
535 if (!d()->activationCount) {
536 ActivationStackNode* prev = d()->activations->prev;
537 ASSERT(prev);
538 delete d()->activations;
539 d()->activations = prev;
540 d()->activationCount = activationStackNodeSize;
541 }
542}
543
544void JSGlobalObject::popActivation()
545{
546 checkActivationCount();
547 d()->activations->data[--d()->activationCount].activationDataStorage.localStorage.shrink(0);
548}
549
550void JSGlobalObject::tearOffActivation(ExecState* exec, bool leaveRelic)
551{
552 ActivationImp* oldActivation = exec->activationObject();
553 if (!oldActivation || !oldActivation->isOnStack())
554 return;
555
556 ASSERT(exec->codeType() == FunctionCode);
557 ActivationImp* newActivation = new ActivationImp(*oldActivation->d(), leaveRelic);
558
559 if (!leaveRelic) {
560 checkActivationCount();
561 d()->activationCount--;
562 }
563
564 oldActivation->d()->localStorage.shrink(0);
565
566 exec->setActivationObject(newActivation);
567 exec->setVariableObject(newActivation);
568 exec->setLocalStorage(&newActivation->localStorage());
569 exec->replaceScopeChainTop(newActivation);
570}
571
572} // namespace KJS
Note: See TracBrowser for help on using the repository browser.