2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
31 #include "JSGlobalObject.h"
33 #include "JSCallbackConstructor.h"
34 #include "JSCallbackFunction.h"
35 #include "JSCallbackObject.h"
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"
46 #include "ErrorConstructor.h"
47 #include "ErrorPrototype.h"
48 #include "FunctionConstructor.h"
49 #include "FunctionPrototype.h"
50 #include "GetterSetter.h"
51 #include "JSBoundFunction.h"
52 #include "JSFunction.h"
53 #include "JSGlobalObjectFunctions.h"
55 #include "JSONObject.h"
56 #include "Interpreter.h"
58 #include "MathObject.h"
59 #include "NativeErrorConstructor.h"
60 #include "NativeErrorPrototype.h"
61 #include "NumberConstructor.h"
62 #include "NumberPrototype.h"
63 #include "ObjectConstructor.h"
64 #include "ObjectPrototype.h"
66 #include "RegExpConstructor.h"
67 #include "RegExpMatchesArray.h"
68 #include "RegExpObject.h"
69 #include "RegExpPrototype.h"
70 #include "ScopeChainMark.h"
71 #include "StringConstructor.h"
72 #include "StringPrototype.h"
75 #include "JSGlobalObject.lut.h"
79 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &JSVariableObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
81 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript };
83 /* Source for JSGlobalObject.lut.h
84 @begin globalObjectTable
85 parseInt globalFuncParseInt DontEnum|Function 2
86 parseFloat globalFuncParseFloat DontEnum|Function 1
87 isNaN globalFuncIsNaN DontEnum|Function 1
88 isFinite globalFuncIsFinite DontEnum|Function 1
89 escape globalFuncEscape DontEnum|Function 1
90 unescape globalFuncUnescape DontEnum|Function 1
91 decodeURI globalFuncDecodeURI DontEnum|Function 1
92 decodeURIComponent globalFuncDecodeURIComponent DontEnum|Function 1
93 encodeURI globalFuncEncodeURI DontEnum|Function 1
94 encodeURIComponent globalFuncEncodeURIComponent DontEnum|Function 1
98 ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject);
100 // Default number of ticks before a timeout check should be done.
101 static const int initialTickCountThreshold = 255;
103 // Preferred number of milliseconds between each timeout check
104 static const int preferredScriptCheckTimeInterval = 1000;
106 template <typename T> static inline void visitIfNeeded(SlotVisitor& visitor, WriteBarrier<T>* v)
112 JSGlobalObject::~JSGlobalObject()
114 ASSERT(JSLock::currentThreadIsHoldingLock());
117 m_debugger->detach(this);
119 Profiler** profiler = Profiler::enabledProfilerReference();
120 if (UNLIKELY(*profiler != 0)) {
121 (*profiler)->stopProfiling(this);
125 void JSGlobalObject::init(JSObject* thisValue)
127 ASSERT(JSLock::currentThreadIsHoldingLock());
129 structure()->disableSpecificFunctionTracking();
131 m_globalData = Heap::heap(this)->globalData();
132 m_globalScopeChain.set(*m_globalData, this, ScopeChainNode::create(0, this, m_globalData.get(), this, thisValue));
134 JSGlobalObject::globalExec()->init(0, 0, m_globalScopeChain.get(), CallFrame::noCaller(), 0, 0);
141 void JSGlobalObject::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
143 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
144 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
146 if (thisObject->symbolTablePut(exec->globalData(), propertyName, value))
148 JSVariableObject::put(thisObject, exec, propertyName, value, slot);
151 void JSGlobalObject::putWithAttributes(JSObject* object, ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
153 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
154 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
156 if (thisObject->symbolTablePutWithAttributes(exec->globalData(), propertyName, value, attributes))
159 JSValue valueBefore = thisObject->getDirect(exec->globalData(), propertyName);
160 PutPropertySlot slot;
161 JSVariableObject::put(thisObject, exec, propertyName, value, slot);
163 JSValue valueAfter = thisObject->getDirect(exec->globalData(), propertyName);
165 JSObject::putWithAttributes(thisObject, exec, propertyName, valueAfter, attributes);
169 void JSGlobalObject::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunc, unsigned attributes)
171 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
173 if (!thisObject->symbolTableGet(propertyName, slot))
174 JSVariableObject::defineGetter(thisObject, exec, propertyName, getterFunc, attributes);
177 void JSGlobalObject::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunc, unsigned attributes)
179 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
181 if (!thisObject->symbolTableGet(propertyName, slot))
182 JSVariableObject::defineSetter(thisObject, exec, propertyName, setterFunc, attributes);
185 static inline JSObject* lastInPrototypeChain(JSObject* object)
187 JSObject* o = object;
188 while (o->prototype().isObject())
189 o = asObject(o->prototype());
193 void JSGlobalObject::reset(JSValue prototype)
195 ExecState* exec = JSGlobalObject::globalExec();
197 m_functionPrototype.set(exec->globalData(), this, FunctionPrototype::create(exec, this, FunctionPrototype::createStructure(exec->globalData(), this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
198 m_functionStructure.set(exec->globalData(), this, JSFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
199 m_boundFunctionStructure.set(exec->globalData(), this, JSBoundFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
200 m_namedFunctionStructure.set(exec->globalData(), this, Structure::addPropertyTransition(exec->globalData(), m_functionStructure.get(), exec->globalData().propertyNames->name, DontDelete | ReadOnly | DontEnum, 0, m_functionNameOffset));
201 m_internalFunctionStructure.set(exec->globalData(), this, InternalFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
202 m_strictModeTypeErrorFunctionStructure.set(exec->globalData(), this, StrictModeTypeErrorFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
203 JSFunction* callFunction = 0;
204 JSFunction* applyFunction = 0;
205 m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
206 m_callFunction.set(exec->globalData(), this, callFunction);
207 m_applyFunction.set(exec->globalData(), this, applyFunction);
208 m_objectPrototype.set(exec->globalData(), this, ObjectPrototype::create(exec, this, ObjectPrototype::createStructure(exec->globalData(), this, jsNull())));
209 m_functionPrototype->structure()->setPrototypeWithoutTransition(exec->globalData(), m_objectPrototype.get());
211 m_emptyObjectStructure.set(exec->globalData(), this, m_objectPrototype->inheritorID(exec->globalData()));
212 m_nullPrototypeObjectStructure.set(exec->globalData(), this, createEmptyObjectStructure(exec->globalData(), this, jsNull()));
214 m_callbackFunctionStructure.set(exec->globalData(), this, JSCallbackFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
215 m_argumentsStructure.set(exec->globalData(), this, Arguments::createStructure(exec->globalData(), this, m_objectPrototype.get()));
216 m_callbackConstructorStructure.set(exec->globalData(), this, JSCallbackConstructor::createStructure(exec->globalData(), this, m_objectPrototype.get()));
217 m_callbackObjectStructure.set(exec->globalData(), this, JSCallbackObject<JSNonFinalObject>::createStructure(exec->globalData(), this, m_objectPrototype.get()));
219 m_arrayPrototype.set(exec->globalData(), this, ArrayPrototype::create(exec, this, ArrayPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
220 m_arrayStructure.set(exec->globalData(), this, JSArray::createStructure(exec->globalData(), this, m_arrayPrototype.get()));
221 m_regExpMatchesArrayStructure.set(exec->globalData(), this, RegExpMatchesArray::createStructure(exec->globalData(), this, m_arrayPrototype.get()));
223 m_stringPrototype.set(exec->globalData(), this, StringPrototype::create(exec, this, StringPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
224 m_stringObjectStructure.set(exec->globalData(), this, StringObject::createStructure(exec->globalData(), this, m_stringPrototype.get()));
226 m_booleanPrototype.set(exec->globalData(), this, BooleanPrototype::create(exec, this, BooleanPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
227 m_booleanObjectStructure.set(exec->globalData(), this, BooleanObject::createStructure(exec->globalData(), this, m_booleanPrototype.get()));
229 m_numberPrototype.set(exec->globalData(), this, NumberPrototype::create(exec, this, NumberPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
230 m_numberObjectStructure.set(exec->globalData(), this, NumberObject::createStructure(exec->globalData(), this, m_numberPrototype.get()));
232 m_datePrototype.set(exec->globalData(), this, DatePrototype::create(exec, this, DatePrototype::createStructure(exec->globalData(), this, m_objectPrototype.get())));
233 m_dateStructure.set(exec->globalData(), this, DateInstance::createStructure(exec->globalData(), this, m_datePrototype.get()));
235 RegExp* emptyRegex = RegExp::create(exec->globalData(), "", NoFlags);
237 m_regExpPrototype.set(exec->globalData(), this, RegExpPrototype::create(exec, this, RegExpPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get()), emptyRegex));
238 m_regExpStructure.set(exec->globalData(), this, RegExpObject::createStructure(exec->globalData(), this, m_regExpPrototype.get()));
240 m_methodCallDummy.set(exec->globalData(), this, constructEmptyObject(exec));
242 ErrorPrototype* errorPrototype = ErrorPrototype::create(exec, this, ErrorPrototype::createStructure(exec->globalData(), this, m_objectPrototype.get()));
243 m_errorStructure.set(exec->globalData(), this, ErrorInstance::createStructure(exec->globalData(), this, errorPrototype));
247 JSCell* objectConstructor = ObjectConstructor::create(exec, this, ObjectConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_objectPrototype.get());
248 JSCell* functionConstructor = FunctionConstructor::create(exec, this, FunctionConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_functionPrototype.get());
249 JSCell* arrayConstructor = ArrayConstructor::create(exec, this, ArrayConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_arrayPrototype.get());
250 JSCell* stringConstructor = StringConstructor::create(exec, this, StringConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_stringPrototype.get());
251 JSCell* booleanConstructor = BooleanConstructor::create(exec, this, BooleanConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_booleanPrototype.get());
252 JSCell* numberConstructor = NumberConstructor::create(exec, this, NumberConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_numberPrototype.get());
253 JSCell* dateConstructor = DateConstructor::create(exec, this, DateConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_datePrototype.get());
255 m_regExpConstructor.set(exec->globalData(), this, RegExpConstructor::create(exec, this, RegExpConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), m_regExpPrototype.get()));
257 m_errorConstructor.set(exec->globalData(), this, ErrorConstructor::create(exec, this, ErrorConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get()), errorPrototype));
259 Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(exec->globalData(), this, errorPrototype);
260 Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(exec->globalData(), this, m_functionPrototype.get());
261 m_evalErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "EvalError"));
262 m_rangeErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "RangeError"));
263 m_referenceErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "ReferenceError"));
264 m_syntaxErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "SyntaxError"));
265 m_typeErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "TypeError"));
266 m_URIErrorConstructor.set(exec->globalData(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, "URIError"));
268 m_objectPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, objectConstructor, DontEnum);
269 m_functionPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, functionConstructor, DontEnum);
270 m_arrayPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, arrayConstructor, DontEnum);
271 m_booleanPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, booleanConstructor, DontEnum);
272 m_stringPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, stringConstructor, DontEnum);
273 m_numberPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, numberConstructor, DontEnum);
274 m_datePrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, dateConstructor, DontEnum);
275 m_regExpPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_regExpConstructor.get(), DontEnum);
276 errorPrototype->putDirectWithoutTransition(exec->globalData(), exec->propertyNames().constructor, m_errorConstructor.get(), DontEnum);
278 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Object"), objectConstructor, DontEnum);
279 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Function"), functionConstructor, DontEnum);
280 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Array"), arrayConstructor, DontEnum);
281 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Boolean"), booleanConstructor, DontEnum);
282 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "String"), stringConstructor, DontEnum);
283 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Number"), numberConstructor, DontEnum);
284 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Date"), dateConstructor, DontEnum);
285 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "RegExp"), m_regExpConstructor.get(), DontEnum);
286 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "Error"), m_errorConstructor.get(), DontEnum);
287 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "EvalError"), m_evalErrorConstructor.get(), DontEnum);
288 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "RangeError"), m_rangeErrorConstructor.get(), DontEnum);
289 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "ReferenceError"), m_referenceErrorConstructor.get(), DontEnum);
290 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "SyntaxError"), m_syntaxErrorConstructor.get(), DontEnum);
291 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "TypeError"), m_typeErrorConstructor.get(), DontEnum);
292 putDirectWithoutTransition(exec->globalData(), Identifier(exec, "URIError"), m_URIErrorConstructor.get(), DontEnum);
294 m_evalFunction.set(exec->globalData(), this, JSFunction::create(exec, this, 1, exec->propertyNames().eval, globalFuncEval));
295 putDirectWithoutTransition(exec->globalData(), exec->propertyNames().eval, m_evalFunction.get(), DontEnum);
297 GlobalPropertyInfo staticGlobals[] = {
298 GlobalPropertyInfo(Identifier(exec, "Math"), MathObject::create(exec, this, MathObject::createStructure(exec->globalData(), this, m_objectPrototype.get())), DontEnum | DontDelete),
299 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(), DontEnum | DontDelete | ReadOnly),
300 GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
301 GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly),
302 GlobalPropertyInfo(Identifier(exec, "JSON"), JSONObject::create(exec, this, JSONObject::createStructure(exec->globalData(), this, m_objectPrototype.get())), DontEnum | DontDelete)
304 addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
306 resetPrototype(exec->globalData(), prototype);
309 void JSGlobalObject::createThrowTypeError(ExecState* exec)
311 JSFunction* thrower = JSFunction::create(exec, this, 0, Identifier(), globalFuncThrowTypeError);
312 GetterSetter* getterSetter = GetterSetter::create(exec);
313 getterSetter->setGetter(exec->globalData(), thrower);
314 getterSetter->setSetter(exec->globalData(), thrower);
315 m_throwTypeErrorGetterSetter.set(exec->globalData(), this, getterSetter);
318 // Set prototype, and also insert the object prototype at the end of the chain.
319 void JSGlobalObject::resetPrototype(JSGlobalData& globalData, JSValue prototype)
321 setPrototype(globalData, prototype);
323 JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
324 JSObject* objectPrototype = m_objectPrototype.get();
325 if (oldLastInPrototypeChain != objectPrototype)
326 oldLastInPrototypeChain->setPrototype(globalData, objectPrototype);
329 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
331 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
332 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
333 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
334 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
335 JSVariableObject::visitChildren(thisObject, visitor);
337 visitIfNeeded(visitor, &thisObject->m_globalScopeChain);
338 visitIfNeeded(visitor, &thisObject->m_methodCallDummy);
340 visitIfNeeded(visitor, &thisObject->m_regExpConstructor);
341 visitIfNeeded(visitor, &thisObject->m_errorConstructor);
342 visitIfNeeded(visitor, &thisObject->m_evalErrorConstructor);
343 visitIfNeeded(visitor, &thisObject->m_rangeErrorConstructor);
344 visitIfNeeded(visitor, &thisObject->m_referenceErrorConstructor);
345 visitIfNeeded(visitor, &thisObject->m_syntaxErrorConstructor);
346 visitIfNeeded(visitor, &thisObject->m_typeErrorConstructor);
347 visitIfNeeded(visitor, &thisObject->m_URIErrorConstructor);
349 visitIfNeeded(visitor, &thisObject->m_evalFunction);
350 visitIfNeeded(visitor, &thisObject->m_callFunction);
351 visitIfNeeded(visitor, &thisObject->m_applyFunction);
352 visitIfNeeded(visitor, &thisObject->m_throwTypeErrorGetterSetter);
354 visitIfNeeded(visitor, &thisObject->m_objectPrototype);
355 visitIfNeeded(visitor, &thisObject->m_functionPrototype);
356 visitIfNeeded(visitor, &thisObject->m_arrayPrototype);
357 visitIfNeeded(visitor, &thisObject->m_booleanPrototype);
358 visitIfNeeded(visitor, &thisObject->m_stringPrototype);
359 visitIfNeeded(visitor, &thisObject->m_numberPrototype);
360 visitIfNeeded(visitor, &thisObject->m_datePrototype);
361 visitIfNeeded(visitor, &thisObject->m_regExpPrototype);
363 visitIfNeeded(visitor, &thisObject->m_argumentsStructure);
364 visitIfNeeded(visitor, &thisObject->m_arrayStructure);
365 visitIfNeeded(visitor, &thisObject->m_booleanObjectStructure);
366 visitIfNeeded(visitor, &thisObject->m_callbackConstructorStructure);
367 visitIfNeeded(visitor, &thisObject->m_callbackFunctionStructure);
368 visitIfNeeded(visitor, &thisObject->m_callbackObjectStructure);
369 visitIfNeeded(visitor, &thisObject->m_dateStructure);
370 visitIfNeeded(visitor, &thisObject->m_emptyObjectStructure);
371 visitIfNeeded(visitor, &thisObject->m_nullPrototypeObjectStructure);
372 visitIfNeeded(visitor, &thisObject->m_errorStructure);
373 visitIfNeeded(visitor, &thisObject->m_functionStructure);
374 visitIfNeeded(visitor, &thisObject->m_boundFunctionStructure);
375 visitIfNeeded(visitor, &thisObject->m_namedFunctionStructure);
376 visitIfNeeded(visitor, &thisObject->m_numberObjectStructure);
377 visitIfNeeded(visitor, &thisObject->m_regExpMatchesArrayStructure);
378 visitIfNeeded(visitor, &thisObject->m_regExpStructure);
379 visitIfNeeded(visitor, &thisObject->m_stringObjectStructure);
380 visitIfNeeded(visitor, &thisObject->m_internalFunctionStructure);
381 visitIfNeeded(visitor, &thisObject->m_strictModeTypeErrorFunctionStructure);
383 if (thisObject->m_registerArray) {
384 // Outside the execution of global code, when our variables are torn off,
385 // we can mark the torn-off array.
386 visitor.appendValues(thisObject->m_registerArray.get(), thisObject->m_registerArraySize);
387 } else if (thisObject->m_registers) {
388 // During execution of global code, when our variables are in the register file,
389 // the symbol table tells us how many variables there are, and registers
390 // points to where they end, and the registers used for execution begin.
391 visitor.appendValues(thisObject->m_registers - thisObject->symbolTable().size(), thisObject->symbolTable().size());
395 ExecState* JSGlobalObject::globalExec()
397 return CallFrame::create(m_globalCallFrame + RegisterFile::CallFrameHeaderSize);
400 void JSGlobalObject::resizeRegisters(size_t newSize)
402 // Previous duplicate symbols may have created spare capacity in m_registerArray.
403 if (newSize <= m_registerArraySize)
406 size_t oldSize = m_registerArraySize;
407 OwnArrayPtr<WriteBarrier<Unknown> > registerArray = adoptArrayPtr(new WriteBarrier<Unknown>[newSize]);
408 for (size_t i = 0; i < oldSize; ++i)
409 registerArray[i].set(globalData(), this, m_registerArray[i].get());
410 for (size_t i = oldSize; i < newSize; ++i)
411 registerArray[i].setUndefined();
413 WriteBarrier<Unknown>* registers = registerArray.get();
414 setRegisters(registers, registerArray.release(), newSize);
417 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
419 resizeRegisters(symbolTable().size() + count);
421 for (int i = 0; i < count; ++i) {
422 GlobalPropertyInfo& global = globals[i];
423 ASSERT(global.attributes & DontDelete);
425 int index = symbolTable().size();
426 SymbolTableEntry newEntry(index, global.attributes);
427 symbolTable().add(global.identifier.impl(), newEntry);
428 registerAt(index).set(globalData(), this, global.value);
432 bool JSGlobalObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
434 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
435 if (getStaticFunctionSlot<JSVariableObject>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, slot))
437 return thisObject->symbolTableGet(propertyName, slot);
440 bool JSGlobalObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
442 JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
443 if (getStaticFunctionDescriptor<JSVariableObject>(exec, ExecState::globalObjectTable(exec), thisObject, propertyName, descriptor))
445 return thisObject->symbolTableGet(propertyName, descriptor);
448 void JSGlobalObject::clearRareData(JSCell* cell)
450 jsCast<JSGlobalObject*>(cell)->m_rareData.clear();
453 DynamicGlobalObjectScope::DynamicGlobalObjectScope(JSGlobalData& globalData, JSGlobalObject* dynamicGlobalObject)
454 : m_dynamicGlobalObjectSlot(globalData.dynamicGlobalObject)
455 , m_savedDynamicGlobalObject(m_dynamicGlobalObjectSlot)
457 if (!m_dynamicGlobalObjectSlot) {
458 #if ENABLE(ASSEMBLER)
459 if (ExecutableAllocator::underMemoryPressure())
460 globalData.recompileAllJSFunctions();
463 m_dynamicGlobalObjectSlot = dynamicGlobalObject;
465 // Reset the date cache between JS invocations to force the VM
466 // to observe time zone changes.
467 globalData.resetDateCache();
471 void slowValidateCell(JSGlobalObject* globalObject)
473 if (!globalObject->isGlobalObject())
475 ASSERT_GC_OBJECT_INHERITS(globalObject, &JSGlobalObject::s_info);