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