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

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

Buildfix: Now include JSFunction.h basically everywhere we include PrototypeFunction.h

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