source: webkit/trunk/JavaScriptCore/runtime/JSGlobalObject.cpp@ 38444

Last change on this file since 38444 was 38444, checked in by [email protected], 17 years ago

Reviewed by Dan Bernstein.

https://bugs.webkit.org/show_bug.cgi?id=22290
Remove cross-heap GC and MessagePort multi-threading support

It is broken (and may not be implementable at all), and no longer needed, as we
don't use MessagePorts for communication with workers any more.

JavaScriptCore:

  • JavaScriptCore.exp:
  • runtime/Collector.cpp: (JSC::Heap::collect):
  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h: Remove hooks for cross-heap GC.

WebCore:

  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSDOMWindowBase.h: Removed cross-heap GC implementation.
  • dom/MessagePort.cpp: (WebCore::MessagePort::hasPendingActivity):
  • dom/MessagePort.h: Made objects RefCounted instead of ThreadSafeShared, added FIXME comments for code that is unnecessarily complicated for single threaded case.
  • Property svn:eol-style set to native
File size: 22.0 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<Structure>& 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()->interpreter->registerFile();
118 if (registerFile.globalObject() == this) {
119 registerFile.setGlobalObject(0);
120 registerFile.setNumGlobals(0);
121 }
122 delete d();
123}
124
125void JSGlobalObject::init(JSObject* thisValue)
126{
127 ASSERT(JSLock::currentThreadIsHoldingLock());
128
129 d()->globalData = Heap::heap(this)->globalData();
130 d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), thisValue);
131
132 JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0, 0);
133
134 if (JSGlobalObject*& headObject = head()) {
135 d()->prev = headObject;
136 d()->next = headObject->d()->next;
137 headObject->d()->next->d()->prev = this;
138 headObject->d()->next = this;
139 } else
140 headObject = d()->next = d()->prev = this;
141
142 d()->recursion = 0;
143 d()->debugger = 0;
144
145 d()->profileGroup = 0;
146
147 reset(prototype());
148}
149
150void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
151{
152 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
153
154 if (symbolTablePut(propertyName, value))
155 return;
156 JSVariableObject::put(exec, propertyName, value, slot);
157}
158
159void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue* value, unsigned attributes)
160{
161 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
162
163 if (symbolTablePutWithAttributes(propertyName, value, attributes))
164 return;
165
166 JSValue* valueBefore = getDirect(propertyName);
167 PutPropertySlot slot;
168 JSVariableObject::put(exec, propertyName, value, slot);
169 if (!valueBefore) {
170 if (JSValue* valueAfter = getDirect(propertyName))
171 putDirect(propertyName, valueAfter, attributes);
172 }
173}
174
175void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc)
176{
177 PropertySlot slot;
178 if (!symbolTableGet(propertyName, slot))
179 JSVariableObject::defineGetter(exec, propertyName, getterFunc);
180}
181
182void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc)
183{
184 PropertySlot slot;
185 if (!symbolTableGet(propertyName, slot))
186 JSVariableObject::defineSetter(exec, propertyName, setterFunc);
187}
188
189static inline JSObject* lastInPrototypeChain(JSObject* object)
190{
191 JSObject* o = object;
192 while (o->prototype()->isObject())
193 o = asObject(o->prototype());
194 return o;
195}
196
197void JSGlobalObject::reset(JSValue* prototype)
198{
199 ExecState* exec = JSGlobalObject::globalExec();
200
201 // Prototypes
202
203 d()->functionPrototype = new (exec) FunctionPrototype(exec, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created.
204 d()->prototypeFunctionStructure = PrototypeFunction::createStructure(d()->functionPrototype);
205 d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get());
206 d()->objectPrototype = new (exec) ObjectPrototype(exec, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get());
207 d()->functionPrototype->structure()->setPrototypeWithoutTransition(d()->objectPrototype);
208
209 d()->emptyObjectStructure = d()->objectPrototype->inheritorID();
210
211 d()->functionStructure = JSFunction::createStructure(d()->functionPrototype);
212 d()->callbackFunctionStructure = JSCallbackFunction::createStructure(d()->functionPrototype);
213 d()->argumentsStructure = Arguments::createStructure(d()->objectPrototype);
214 d()->callbackConstructorStructure = JSCallbackConstructor::createStructure(d()->objectPrototype);
215 d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructure(d()->objectPrototype);
216
217 d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype));
218 d()->arrayStructure = JSArray::createStructure(d()->arrayPrototype);
219 d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructure(d()->arrayPrototype);
220
221 d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructure(d()->objectPrototype));
222 d()->stringObjectStructure = StringObject::createStructure(d()->stringPrototype);
223
224 d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
225 d()->booleanObjectStructure = BooleanObject::createStructure(d()->booleanPrototype);
226
227 d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
228 d()->numberObjectStructure = NumberObject::createStructure(d()->numberPrototype);
229
230 d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructure(d()->objectPrototype));
231 d()->dateStructure = DateInstance::createStructure(d()->datePrototype);
232
233 d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
234 d()->regExpStructure = RegExpObject::createStructure(d()->regExpPrototype);
235
236 ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get());
237 d()->errorStructure = ErrorInstance::createStructure(errorPrototype);
238
239 RefPtr<Structure> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(errorPrototype);
240
241 NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError");
242 NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError");
243 NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError");
244 NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError");
245 NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError");
246 NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError");
247
248 // Constructors
249
250 JSValue* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype);
251 JSValue* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
252 JSValue* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype);
253 JSValue* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
254 JSValue* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype);
255 JSValue* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype);
256 JSValue* dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype);
257
258 d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructure(d()->functionPrototype), d()->regExpPrototype);
259
260 d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructure(d()->functionPrototype), errorPrototype);
261
262 RefPtr<Structure> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype);
263
264 d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
265 d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
266 d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype);
267 d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype);
268 d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype);
269 d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype);
270
271 d()->objectPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, objectConstructor, DontEnum);
272 d()->functionPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, functionConstructor, DontEnum);
273 d()->arrayPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, arrayConstructor, DontEnum);
274 d()->booleanPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, booleanConstructor, DontEnum);
275 d()->stringPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, stringConstructor, DontEnum);
276 d()->numberPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, numberConstructor, DontEnum);
277 d()->datePrototype->putDirectWithoutTransition(exec->propertyNames().constructor, dateConstructor, DontEnum);
278 d()->regExpPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum);
279 errorPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, d()->errorConstructor, DontEnum);
280
281 evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum);
282 rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum);
283 referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum);
284 syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum);
285 typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum);
286 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 putDirectWithoutTransition(Identifier(exec, "Object"), objectConstructor, DontEnum);
293 putDirectWithoutTransition(Identifier(exec, "Function"), functionConstructor, DontEnum);
294 putDirectWithoutTransition(Identifier(exec, "Array"), arrayConstructor, DontEnum);
295 putDirectWithoutTransition(Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
296 putDirectWithoutTransition(Identifier(exec, "String"), stringConstructor, DontEnum);
297 putDirectWithoutTransition(Identifier(exec, "Number"), numberConstructor, DontEnum);
298 putDirectWithoutTransition(Identifier(exec, "Date"), dateConstructor, DontEnum);
299 putDirectWithoutTransition(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum);
300 putDirectWithoutTransition(Identifier(exec, "Error"), d()->errorConstructor, DontEnum);
301 putDirectWithoutTransition(Identifier(exec, "EvalError"), d()->evalErrorConstructor);
302 putDirectWithoutTransition(Identifier(exec, "RangeError"), d()->rangeErrorConstructor);
303 putDirectWithoutTransition(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor);
304 putDirectWithoutTransition(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor);
305 putDirectWithoutTransition(Identifier(exec, "TypeError"), d()->typeErrorConstructor);
306 putDirectWithoutTransition(Identifier(exec, "URIError"), d()->URIErrorConstructor);
307
308 // Set global values.
309 GlobalPropertyInfo staticGlobals[] = {
310 GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete),
311 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
312 GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
313 GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
314 };
315
316 addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
317
318 // Set global functions.
319
320 d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructure(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this);
321 putDirectFunctionWithoutTransition(exec, d()->evalFunction, DontEnum);
322 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum);
323 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum);
324 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum);
325 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum);
326 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum);
327 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum);
328 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum);
329 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum);
330 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum);
331 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum);
332#ifndef NDEBUG
333 putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "kjsprint"), globalFuncKJSPrint), DontEnum);
334#endif
335
336 resetPrototype(prototype);
337}
338
339// Set prototype, and also insert the object prototype at the end of the chain.
340void JSGlobalObject::resetPrototype(JSValue* prototype)
341{
342 setPrototype(prototype);
343 lastInPrototypeChain(this)->setPrototype(d()->objectPrototype);
344}
345
346void JSGlobalObject::setTimeoutTime(unsigned timeoutTime)
347{
348 globalData()->interpreter->setTimeoutTime(timeoutTime);
349}
350
351void JSGlobalObject::startTimeoutCheck()
352{
353 globalData()->interpreter->startTimeoutCheck();
354}
355
356void JSGlobalObject::stopTimeoutCheck()
357{
358 globalData()->interpreter->stopTimeoutCheck();
359}
360
361void JSGlobalObject::mark()
362{
363 JSVariableObject::mark();
364
365 HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end();
366 for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it)
367 (*it)->mark();
368
369 RegisterFile& registerFile = globalData()->interpreter->registerFile();
370 if (registerFile.globalObject() == this)
371 registerFile.markGlobals(&globalData()->heap);
372
373 markIfNeeded(d()->regExpConstructor);
374 markIfNeeded(d()->errorConstructor);
375 markIfNeeded(d()->evalErrorConstructor);
376 markIfNeeded(d()->rangeErrorConstructor);
377 markIfNeeded(d()->referenceErrorConstructor);
378 markIfNeeded(d()->syntaxErrorConstructor);
379 markIfNeeded(d()->typeErrorConstructor);
380 markIfNeeded(d()->URIErrorConstructor);
381
382 markIfNeeded(d()->evalFunction);
383
384 markIfNeeded(d()->objectPrototype);
385 markIfNeeded(d()->functionPrototype);
386 markIfNeeded(d()->arrayPrototype);
387 markIfNeeded(d()->booleanPrototype);
388 markIfNeeded(d()->stringPrototype);
389 markIfNeeded(d()->numberPrototype);
390 markIfNeeded(d()->datePrototype);
391 markIfNeeded(d()->regExpPrototype);
392
393 markIfNeeded(d()->errorStructure);
394
395 // No need to mark the other structures, because their prototypes are all
396 // guaranteed to be referenced elsewhere.
397
398 Register* registerArray = d()->registerArray.get();
399 if (!registerArray)
400 return;
401
402 size_t size = d()->registerArraySize;
403 for (size_t i = 0; i < size; ++i) {
404 Register& r = registerArray[i];
405 if (!r.marked())
406 r.mark();
407 }
408}
409
410JSGlobalObject* JSGlobalObject::toGlobalObject(ExecState*) const
411{
412 return const_cast<JSGlobalObject*>(this);
413}
414
415ExecState* JSGlobalObject::globalExec()
416{
417 return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize);
418}
419
420bool JSGlobalObject::isDynamicScope() const
421{
422 return true;
423}
424
425void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile)
426{
427 ASSERT(!d()->registerArray);
428 ASSERT(!d()->registerArraySize);
429
430 int numGlobals = registerFile.numGlobals();
431 if (!numGlobals) {
432 d()->registers = 0;
433 return;
434 }
435
436 Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals);
437 setRegisters(registerArray + numGlobals, registerArray, numGlobals);
438}
439
440void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile)
441{
442 JSGlobalObject* lastGlobalObject = registerFile.globalObject();
443 if (lastGlobalObject && lastGlobalObject != this)
444 lastGlobalObject->copyGlobalsFrom(registerFile);
445
446 registerFile.setGlobalObject(this);
447 registerFile.setNumGlobals(symbolTable().size());
448
449 if (d()->registerArray) {
450 memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register));
451 setRegisters(registerFile.start(), 0, 0);
452 }
453}
454
455void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
456{
457#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
458 return globalData->heap.inlineAllocate(size);
459#else
460 return globalData->heap.allocate(size);
461#endif
462}
463
464} // namespace JSC
Note: See TracBrowser for help on using the repository browser.