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

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

JavaScriptCore:

2008-10-02 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

1.019x as fast on SunSpider.

  • API/JSBase.cpp: (JSEvaluateScript): Use heap. instead of heap-> to work with the heap. (JSCheckScriptSyntax): Ditto. (JSGarbageCollect): Ditto. (JSReportExtraMemoryCost): Ditto.
  • API/JSContextRef.cpp: (JSGlobalContextRetain): Ditto. (JSGlobalContextRelease): Destroy the heap with the destroy function instead of the delete operator. (JSContextGetGlobalObject): Use heap. instead of heap-> to work with the heap.
  • API/JSObjectRef.cpp: (JSObjectMake): Use heap. instead of heap-> to work with the heap. (JSObjectMakeFunctionWithCallback): Ditto. (JSObjectMakeConstructor): Ditto. (JSObjectMakeFunction): Ditto. (JSObjectMakeArray): Ditto. (JSObjectMakeDate): Ditto. (JSObjectMakeError): Ditto. (JSObjectMakeRegExp): Ditto. (JSObjectHasProperty): Ditto. (JSObjectGetProperty): Ditto. (JSObjectSetProperty): Ditto. (JSObjectGetPropertyAtIndex): Ditto. (JSObjectSetPropertyAtIndex): Ditto. (JSObjectDeleteProperty): Ditto. (JSObjectCallAsFunction): Ditto. (JSObjectCallAsConstructor): Ditto. (JSObjectCopyPropertyNames): Ditto. (JSPropertyNameAccumulatorAddName): Ditto.
  • API/JSValueRef.cpp: (JSValueIsEqual): Ditto. (JSValueIsInstanceOfConstructor): Ditto. (JSValueMakeNumber): Ditto. (JSValueMakeString): Ditto. (JSValueToNumber): Ditto. (JSValueToStringCopy): Ditto. (JSValueToObject): Ditto. (JSValueProtect): Ditto. (JSValueUnprotect): Ditto.
  • kjs/ExecState.h: (JSC::ExecState::heap): Update to use the & operator.
  • kjs/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): Update to initialize a heap member instead of calling new to make a heap. (JSC::JSGlobalData::~JSGlobalData): Destroy the heap with the destroy function instead of the delete operator.
  • kjs/JSGlobalData.h: Change from Heap* to a Heap.
  • kjs/JSGlobalObject.cpp: (JSC::JSGlobalObject::mark): Use the & operator here. (JSC::JSGlobalObject::operator new): Use heap. instead of heap-> to work with the heap.

WebCore:

2008-10-02 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

  • bindings/js/GCController.cpp: (WebCore::collect): Use heap. instead of heap-> to work with the heap. (WebCore::GCController::gcTimerFired): Ditto. (WebCore::GCController::garbageCollectNow): Ditto.
  • bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::operator new): Ditto.
  • storage/Database.cpp: (WebCore::Database::Database): Ditto.

WebKit/mac:

2008-10-02 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

  • Misc/WebCoreStatistics.mm: (+[WebCoreStatistics javaScriptObjectsCount]): Use heap. instead of heap-> to work with the heap. (+[WebCoreStatistics javaScriptGlobalObjectsCount]): Ditto. (+[WebCoreStatistics javaScriptProtectedObjectsCount]): Ditto. (+[WebCoreStatistics javaScriptProtectedGlobalObjectsCount]): Ditto. (+[WebCoreStatistics javaScriptProtectedObjectTypeCounts]): Ditto. (+[WebCoreStatistics javaScriptReferencedObjectsCount]): Ditto.

WebKit/win:

2008-10-02 Darin Adler <Darin Adler>

  • WebCoreStatistics.cpp: (WebCoreStatistics::javaScriptObjectsCount): Use heap. instead of heap-> to work with the heap. (WebCoreStatistics::javaScriptGlobalObjectsCount): Ditto. (WebCoreStatistics::javaScriptProtectedObjectsCount): Ditto. (WebCoreStatistics::javaScriptProtectedGlobalObjectsCount): Ditto. (WebCoreStatistics::javaScriptProtectedObjectTypeCounts): Ditto.
  • WebJavaScriptCollector.cpp: (WebJavaScriptCollector::objectCount): Ditto.
  • Property svn:eol-style set to native
File size: 21.3 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 "JSCallbackConstructor.h"
34#include "JSCallbackFunction.h"
35#include "JSCallbackObject.h"
36
37#include "Arguments.h"
38#include "ArrayConstructor.h"
39#include "ArrayPrototype.h"
40#include "BooleanConstructor.h"
41#include "BooleanPrototype.h"
42#include "CodeBlock.h"
43#include "DateConstructor.h"
44#include "DatePrototype.h"
45#include "ErrorConstructor.h"
46#include "ErrorPrototype.h"
47#include "FunctionConstructor.h"
48#include "FunctionPrototype.h"
49#include "GlobalEvalFunction.h"
50#include "JSGlobalObjectFunctions.h"
51#include "JSLock.h"
52#include "Machine.h"
53#include "MathObject.h"
54#include "NativeErrorConstructor.h"
55#include "NativeErrorPrototype.h"
56#include "NumberConstructor.h"
57#include "NumberPrototype.h"
58#include "ObjectConstructor.h"
59#include "ObjectPrototype.h"
60#include "Profiler.h"
61#include "PrototypeFunction.h"
62#include "RegExpConstructor.h"
63#include "RegExpMatchesArray.h"
64#include "RegExpObject.h"
65#include "RegExpPrototype.h"
66#include "ScopeChainMark.h"
67#include "StringConstructor.h"
68#include "StringPrototype.h"
69#include "debugger.h"
70
71namespace JSC {
72
73ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
74
75// Default number of ticks before a timeout check should be done.
76static const int initialTickCountThreshold = 255;
77
78// Preferred number of milliseconds between each timeout check
79static const int preferredScriptCheckTimeInterval = 1000;
80
81static inline void markIfNeeded(JSValue* v)
82{
83 if (v && !v->marked())
84 v->mark();
85}
86
87static inline void markIfNeeded(const RefPtr<StructureID>& s)
88{
89 if (s)
90 s->mark();
91}
92
93JSGlobalObject::~JSGlobalObject()
94{
95 ASSERT(JSLock::currentThreadIsHoldingLock());
96
97 if (d()->debugger)
98 d()->debugger->detach(this);
99
100 Profiler** profiler = Profiler::enabledProfilerReference();
101 if (UNLIKELY(*profiler != 0)) {
102 (*profiler)->stopProfiling(globalExec(), UString());
103 }
104
105 d()->next->d()->prev = d()->prev;
106 d()->prev->d()->next = d()->next;
107 JSGlobalObject*& headObject = head();
108 if (headObject == this)
109 headObject = d()->next;
110 if (headObject == this)
111 headObject = 0;
112
113 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
114 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
115 (*it)->globalObject = 0;
116
117 RegisterFile& registerFile = globalData()->machine->registerFile();
118 if (registerFile.globalObject() == this) {
119 registerFile.setGlobalObject(0);
120 registerFile.setNumGlobals(0);
121 }
122 delete d();
123}
124
125void JSGlobalObject::init()
126{
127 ASSERT(JSLock::currentThreadIsHoldingLock());
128
129 d()->globalData = Heap::heap(this)->globalData();
130
131 if (JSGlobalObject*& headObject = head()) {
132 d()->prev = headObject;
133 d()->next = headObject->d()->next;
134 headObject->d()->next->d()->prev = this;
135 headObject->d()->next = this;
136 } else
137 headObject = d()->next = d()->prev = this;
138
139 d()->recursion = 0;
140 d()->debugger = 0;
141
142 d()->globalExec.set(new ExecState(this, d()->globalCallFrame + RegisterFile::CallFrameHeaderSize));
143
144 d()->profileGroup = 0;
145
146 reset(prototype());
147}
148
149void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
150{
151 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
152
153 if (symbolTablePut(propertyName, value))
154 return;
155 JSVariableObject::put(exec, propertyName, value, slot);
156}
157
158void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
159{
160 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
161
162 if (symbolTablePutWithAttributes(propertyName, value, attributes))
163 return;
164
165 JSValue* valueBefore = getDirect(propertyName);
166 PutPropertySlot slot;
167 JSVariableObject::put(exec, propertyName, value, slot);
168 if (!valueBefore) {
169 if (JSValue* valueAfter = getDirect(propertyName))
170 putDirect(propertyName, valueAfter, attributes);
171 }
172}
173
174void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
175{
176 PropertySlot slot;
177 if (!symbolTableGet(propertyName, slot))
178 JSVariableObject::defineGetter(exec, propertyName, getterFunc);
179}
180
181void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
182{
183 PropertySlot slot;
184 if (!symbolTableGet(propertyName, slot))
185 JSVariableObject::defineSetter(exec, propertyName, setterFunc);
186}
187
188static inline JSObject* lastInPrototypeChain(JSObject* object)
189{
190 JSObject* o = object;
191 while (o->prototype()->isObject())
192 o = static_cast<JSObject*>(o->prototype());
193 return o;
194}
195
196void JSGlobalObject::reset(JSValue* prototype)
197{
198 ExecState* exec = d()->globalExec.get();
199
200 // Prototypes
201
202 d()->functionPrototype = new (exec) FunctionPrototype(exec);
203 d()->functionStructure = JSFunction::createStructureID(d()->functionPrototype);
204 d()->callbackFunctionStructure = JSCallbackFunction::createStructureID(d()->functionPrototype);
205 d()->prototypeFunctionStructure = PrototypeFunction::createStructureID(d()->functionPrototype);
206 d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get());
207 d()->objectPrototype = new (exec) ObjectPrototype(exec, d()->prototypeFunctionStructure.get());
208 d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
209 d()->functionPrototype->setPrototype(d()->objectPrototype);
210 d()->argumentsStructure = Arguments::createStructureID(d()->objectPrototype);
211 d()->callbackConstructorStructure = JSCallbackConstructor::createStructureID(d()->objectPrototype);
212 d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructureID(d()->objectPrototype);
213 d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructureID(d()->objectPrototype));
214 d()->arrayStructure = JSArray::createStructureID(d()->arrayPrototype);
215 d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructureID(d()->arrayPrototype);
216 d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructureID(d()->objectPrototype));
217 d()->stringObjectStructure = StringObject::createStructureID(d()->stringPrototype);
218 d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
219 d()->booleanObjectStructure = BooleanObject::createStructureID(d()->booleanPrototype);
220 d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
221 d()->numberObjectStructure = NumberObject::createStructureID(d()->numberPrototype);
222 d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructureID(d()->objectPrototype));
223 d()->dateStructure = DateInstance::createStructureID(d()->datePrototype);
224 d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
225 d()->regExpStructure = RegExpObject::createStructureID(d()->regExpPrototype);
226 ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructureID(d()->objectPrototype), d()->prototypeFunctionStructure.get());
227 d()->errorStructure = ErrorInstance::createStructureID(errorPrototype);
228
229 RefPtr<StructureID> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructureID(errorPrototype);
230
231 NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError");
232 NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError");
233 NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError");
234 NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError");
235 NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError");
236 NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError");
237
238 // Constructors
239
240 JSValue* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructureID(d()->functionPrototype), d()->objectPrototype);
241 JSValue* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructureID(d()->functionPrototype), d()->functionPrototype);
242 JSValue* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructureID(d()->functionPrototype), d()->arrayPrototype);
243 JSValue* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructureID(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
244 JSValue* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructureID(d()->functionPrototype), d()->booleanPrototype);
245 JSValue* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructureID(d()->functionPrototype), d()->numberPrototype);
246 JSValue* dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructureID(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
247
248 d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructureID(d()->functionPrototype), d()->regExpPrototype);
249
250 d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructureID(d()->functionPrototype), errorPrototype);
251
252 RefPtr<StructureID> nativeErrorStructure = NativeErrorConstructor::createStructureID(d()->functionPrototype);
253
254 d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
255 d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
256 d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype);
257 d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype);
258 d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype);
259 d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype);
260
261 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
262
263 d()->objectPrototype->putDirect(exec->propertyNames().constructor, objectConstructor, DontEnum);
264 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum);
265 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, arrayConstructor, DontEnum);
266 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, booleanConstructor, DontEnum);
267 d()->stringPrototype->putDirect(exec->propertyNames().constructor, stringConstructor, DontEnum);
268 d()->numberPrototype->putDirect(exec->propertyNames().constructor, numberConstructor, DontEnum);
269 d()->datePrototype->putDirect(exec->propertyNames().constructor, dateConstructor, DontEnum);
270 d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
271 errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
272 evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
273 rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
274 referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
275 syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
276 typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
277 URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum);
278
279 // Set global constructors
280
281 // FIXME: These properties could be handled by a static hash table.
282
283 putDirect(Identifier(exec, "Object"), objectConstructor, DontEnum);
284 putDirect(Identifier(exec, "Function"), functionConstructor, DontEnum);
285 putDirect(Identifier(exec, "Array"), arrayConstructor, DontEnum);
286 putDirect(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
287 putDirect(Identifier(exec, "String"), stringConstructor, DontEnum);
288 putDirect(Identifier(exec, "Number"), numberConstructor, DontEnum);
289 putDirect(Identifier(exec, "Date"), dateConstructor, DontEnum);
290 putDirect(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
291 putDirect(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
292 putDirect(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
293 putDirect(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
294 putDirect(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
295 putDirect(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
296 putDirect(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
297 putDirect(Identifier(exec, "URIError"), d()->URIErrorConstructor);
298
299 // Set global values.
300 GlobalPropertyInfo staticGlobals[] = {
301 GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructureID(d()->objectPrototype)), DontEnum | DontDelete),
302 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
303 GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
304 GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
305 };
306
307 addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
308
309 // Set global functions.
310
311 d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructureID(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
312 putDirectFunction(exec, d()->evalFunction, DontEnum);
313 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
314 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
315 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
316 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
317 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
318 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
319 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
320 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
321 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
322 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
323#ifndef NDEBUG
324 putDirectFunction(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
325#endif
326
327 resetPrototype(prototype);
328}
329
330// Set prototype, and also insert the object prototype at the end of the chain.
331void JSGlobalObject::resetPrototype(JSValue* prototype)
332{
333 setPrototype(prototype);
334 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
335}
336
337void JSGlobalObject::setTimeoutTime(unsigned timeoutTime)
338{
339 globalData()->machine->setTimeoutTime(timeoutTime);
340}
341
342void JSGlobalObject::startTimeoutCheck()
343{
344 globalData()->machine->startTimeoutCheck();
345}
346
347void JSGlobalObject::stopTimeoutCheck()
348{
349 globalData()->machine->stopTimeoutCheck();
350}
351
352void JSGlobalObject::mark()
353{
354 JSVariableObject::mark();
355
356 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
357 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
358 (*it)->mark();
359
360 RegisterFile& registerFile = globalData()->machine->registerFile();
361 if (registerFile.globalObject() == this)
362 registerFile.markGlobals(&globalData()->heap);
363
364 markIfNeeded(d()->globalExec->exception());
365
366 markIfNeeded(d()->regExpConstructor);
367 markIfNeeded(d()->errorConstructor);
368 markIfNeeded(d()->evalErrorConstructor);
369 markIfNeeded(d()->rangeErrorConstructor);
370 markIfNeeded(d()->referenceErrorConstructor);
371 markIfNeeded(d()->syntaxErrorConstructor);
372 markIfNeeded(d()->typeErrorConstructor);
373 markIfNeeded(d()->URIErrorConstructor);
374
375 markIfNeeded(d()->evalFunction);
376
377 markIfNeeded(d()->objectPrototype);
378 markIfNeeded(d()->functionPrototype);
379 markIfNeeded(d()->arrayPrototype);
380 markIfNeeded(d()->booleanPrototype);
381 markIfNeeded(d()->stringPrototype);
382 markIfNeeded(d()->numberPrototype);
383 markIfNeeded(d()->datePrototype);
384 markIfNeeded(d()->regExpPrototype);
385
386 markIfNeeded(d()->errorStructure);
387
388 // No need to mark the other structures, because their prototypes are all
389 // guaranteed to be referenced elsewhere.
390
391 Register* registerArray = d()->registerArray.get();
392 if (!registerArray)
393 return;
394
395 size_t size = d()->registerArraySize;
396 for (size_t i = 0; i < size; ++i) {
397 Register& r = registerArray[i];
398 if (!r.marked())
399 r.mark();
400 }
401}
402
403JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
404{
405 return const_cast<JSGlobalObject*>(this);
406}
407
408ExecState* JSGlobalObject::globalExec()
409{
410 return d()->globalExec.get();
411}
412
413bool JSGlobalObject::isDynamicScope() const
414{
415 return true;
416}
417
418void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
419{
420 ASSERT(!d()->registerArray);
421 ASSERT(!d()->registerArraySize);
422
423 int numGlobals = registerFile.numGlobals();
424 if (!numGlobals) {
425 d()->registers = 0;
426 return;
427 }
428
429 Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals);
430 setRegisters(registerArray + numGlobals, registerArray, numGlobals);
431}
432
433void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
434{
435 JSGlobalObject* lastGlobalObject = registerFile.globalObject();
436 if (lastGlobalObject && lastGlobalObject != this)
437 lastGlobalObject->copyGlobalsFrom(registerFile);
438
439 registerFile.setGlobalObject(this);
440 registerFile.setNumGlobals(symbolTable().size());
441
442 if (d()->registerArray) {
443 memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
444 setRegisters(registerFile.start(), 0, 0);
445 }
446}
447
448void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
449{
450#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
451 return globalData->heap.inlineAllocate(size);
452#else
453 return globalData->heap.allocate(size);
454#endif
455}
456
457} // namespace JSC
Note: See TracBrowser for help on using the repository browser.