Web Inspector: CRASH when debugger closes while paused and remote inspecting a JSContext
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Cameron Zwarich (cwzwarich@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 "Arguments.h"
34 #include "ArgumentsIteratorConstructor.h"
35 #include "ArgumentsIteratorPrototype.h"
36 #include "ArrayConstructor.h"
37 #include "ArrayIteratorConstructor.h"
38 #include "ArrayIteratorPrototype.h"
39 #include "ArrayPrototype.h"
40 #include "BooleanConstructor.h"
41 #include "BooleanPrototype.h"
42 #include "CodeBlock.h"
43 #include "CodeCache.h"
44 #include "DateConstructor.h"
45 #include "DatePrototype.h"
46 #include "Debugger.h"
47 #include "Error.h"
48 #include "ErrorConstructor.h"
49 #include "ErrorPrototype.h"
50 #include "FunctionConstructor.h"
51 #include "FunctionPrototype.h"
52 #include "GetterSetter.h"
53 #include "HeapIterationScope.h"
54 #include "Interpreter.h"
55 #include "JSAPIWrapperObject.h"
56 #include "JSActivation.h"
57 #include "JSArgumentsIterator.h"
58 #include "JSArrayBuffer.h"
59 #include "JSArrayBufferConstructor.h"
60 #include "JSArrayBufferPrototype.h"
61 #include "JSArrayIterator.h"
62 #include "JSBoundFunction.h"
63 #include "JSCInlines.h"
64 #include "JSCallbackConstructor.h"
65 #include "JSCallbackFunction.h"
66 #include "JSCallbackObject.h"
67 #include "JSDataView.h"
68 #include "JSDataViewPrototype.h"
69 #include "JSFunction.h"
70 #include "JSGenericTypedArrayViewConstructorInlines.h"
71 #include "JSGenericTypedArrayViewInlines.h"
72 #include "JSGenericTypedArrayViewPrototypeInlines.h"
73 #include "JSGlobalObjectFunctions.h"
74 #include "JSLock.h"
75 #include "JSMap.h"
76 #include "JSMapIterator.h"
77 #include "JSNameScope.h"
78 #include "JSONObject.h"
79 #include "JSSet.h"
80 #include "JSSetIterator.h"
81 #include "JSTypedArrayConstructors.h"
82 #include "JSTypedArrayPrototypes.h"
83 #include "JSTypedArrays.h"
84 #include "JSWeakMap.h"
85 #include "JSWithScope.h"
86 #include "LegacyProfiler.h"
87 #include "Lookup.h"
88 #include "MapConstructor.h"
89 #include "MapIteratorConstructor.h"
90 #include "MapIteratorPrototype.h"
91 #include "MapPrototype.h"
92 #include "MathObject.h"
93 #include "Microtask.h"
94 #include "NameConstructor.h"
95 #include "NameInstance.h"
96 #include "NamePrototype.h"
97 #include "NativeErrorConstructor.h"
98 #include "NativeErrorPrototype.h"
99 #include "NumberConstructor.h"
100 #include "NumberPrototype.h"
101 #include "ObjCCallbackFunction.h"
102 #include "ObjectConstructor.h"
103 #include "ObjectPrototype.h"
104 #include "ParserError.h"
105 #include "RegExpConstructor.h"
106 #include "RegExpMatchesArray.h"
107 #include "RegExpObject.h"
108 #include "RegExpPrototype.h"
109 #include "SetConstructor.h"
110 #include "SetIteratorConstructor.h"
111 #include "SetIteratorPrototype.h"
112 #include "SetPrototype.h"
113 #include "StrictEvalActivation.h"
114 #include "StringConstructor.h"
115 #include "StringPrototype.h"
116 #include "WeakMapConstructor.h"
117 #include "WeakMapPrototype.h"
118
119 #if ENABLE(PROMISES)
120 #include "JSPromise.h"
121 #include "JSPromiseConstructor.h"
122 #include "JSPromisePrototype.h"
123 #endif // ENABLE(PROMISES)
124
125 #if ENABLE(REMOTE_INSPECTOR)
126 #include "JSGlobalObjectDebuggable.h"
127 #include "JSGlobalObjectInspectorController.h"
128 #endif
129
130 #if ENABLE(WEB_REPLAY)
131 #include "EmptyInputCursor.h"
132 #include "JSReplayInputs.h"
133 #endif
134
135 #include "JSGlobalObject.lut.h"
136
137 namespace JSC {
138
139 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
140
141 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0, &shouldInterruptScriptBeforeTimeout };
142
143 /* Source for JSGlobalObject.lut.h
144 @begin globalObjectTable
145   parseInt              globalFuncParseInt              DontEnum|Function 2
146   parseFloat            globalFuncParseFloat            DontEnum|Function 1
147   isNaN                 globalFuncIsNaN                 DontEnum|Function 1
148   isFinite              globalFuncIsFinite              DontEnum|Function 1
149   escape                globalFuncEscape                DontEnum|Function 1
150   unescape              globalFuncUnescape              DontEnum|Function 1
151   decodeURI             globalFuncDecodeURI             DontEnum|Function 1
152   decodeURIComponent    globalFuncDecodeURIComponent    DontEnum|Function 1
153   encodeURI             globalFuncEncodeURI             DontEnum|Function 1
154   encodeURIComponent    globalFuncEncodeURIComponent    DontEnum|Function 1
155 @end
156 */
157
158 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
159     : Base(vm, structure, 0)
160 #if ENABLE(WEB_REPLAY)
161     , m_inputCursor(EmptyInputCursor::create())
162 #endif
163     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
164     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
165     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
166     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
167     , m_evalEnabled(true)
168     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
169 {
170 }
171
172 JSGlobalObject::~JSGlobalObject()
173 {
174 #if ENABLE(REMOTE_INSPECTOR)
175     m_inspectorController->globalObjectDestroyed();
176 #endif
177
178     if (m_debugger)
179         m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
180
181     if (LegacyProfiler* profiler = vm().enabledProfiler())
182         profiler->stopProfiling(this);
183 }
184
185 void JSGlobalObject::destroy(JSCell* cell)
186 {
187     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
188 }
189
190 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
191 {
192     m_globalThis.set(vm, this, globalThis);
193 }
194
195 void JSGlobalObject::init(JSObject* thisValue)
196 {
197     ASSERT(vm().currentThreadIsHoldingAPILock());
198
199     setGlobalThis(vm(), thisValue);
200     JSGlobalObject::globalExec()->init(0, 0, this, CallFrame::noCaller(), 0, 0);
201
202     m_debugger = 0;
203
204 #if ENABLE(REMOTE_INSPECTOR)
205     m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
206     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
207     m_inspectorDebuggable->init();
208     m_inspectorDebuggable->setRemoteDebuggingAllowed(true);
209 #endif
210
211     reset(prototype());
212 }
213
214 void JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
215 {
216     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
217     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
218
219     if (symbolTablePut(thisObject, exec, propertyName, value, slot.isStrictMode()))
220         return;
221     Base::put(thisObject, exec, propertyName, value, slot);
222 }
223
224 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
225 {
226     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
227     PropertySlot slot(thisObject);
228     // silently ignore attempts to add accessors aliasing vars.
229     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
230         return false;
231     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
232 }
233
234 JSGlobalObject::NewGlobalVar JSGlobalObject::addGlobalVar(const Identifier& ident, ConstantMode constantMode)
235 {
236     ConcurrentJITLocker locker(symbolTable()->m_lock);
237     int index = symbolTable()->size(locker);
238     SymbolTableEntry newEntry(index, (constantMode == IsConstant) ? ReadOnly : 0);
239     if (constantMode == IsVariable)
240         newEntry.prepareToWatch();
241     SymbolTable::Map::AddResult result = symbolTable()->add(locker, ident.impl(), newEntry);
242     if (result.isNewEntry)
243         addRegisters(1);
244     else
245         index = result.iterator->value.getIndex();
246     NewGlobalVar var;
247     var.registerNumber = index;
248     var.set = result.iterator->value.watchpointSet();
249     return var;
250 }
251
252 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName, JSValue value)
253 {
254     removeDirect(exec->vm(), propertyName); // Newly declared functions overwrite existing properties.
255     NewGlobalVar var = addGlobalVar(propertyName, IsVariable);
256     registerAt(var.registerNumber).set(exec->vm(), this, value);
257     if (var.set)
258         var.set->notifyWrite(value);
259 }
260
261 static inline JSObject* lastInPrototypeChain(JSObject* object)
262 {
263     JSObject* o = object;
264     while (o->prototype().isObject())
265         o = asObject(o->prototype());
266     return o;
267 }
268
269 void JSGlobalObject::reset(JSValue prototype)
270 {
271     ExecState* exec = JSGlobalObject::globalExec();
272     VM& vm = exec->vm();
273
274     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
275     m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
276     m_boundFunctionStructure.set(vm, this, JSBoundFunction::createStructure(vm, this, m_functionPrototype.get()));
277     m_namedFunctionStructure.set(vm, this, Structure::addPropertyTransition(vm, m_functionStructure.get(), vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, 0, m_functionNameOffset));
278     m_internalFunctionStructure.set(vm, this, InternalFunction::createStructure(vm, this, m_functionPrototype.get()));
279     JSFunction* callFunction = 0;
280     JSFunction* applyFunction = 0;
281     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
282     m_callFunction.set(vm, this, callFunction);
283     m_applyFunction.set(vm, this, applyFunction);
284     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
285     GetterSetter* protoAccessor = GetterSetter::create(vm);
286     protoAccessor->setGetter(vm, JSFunction::create(vm, this, 0, String(), globalFuncProtoGetter));
287     protoAccessor->setSetter(vm, JSFunction::create(vm, this, 0, String(), globalFuncProtoSetter));
288     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
289     m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
290     
291     m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
292     m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
293     m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
294     m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
295     m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
296     m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
297     m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
298     m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
299     m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
300     m_typedArrays[toIndex(TypeDataView)].prototype.set(vm, this, JSDataViewPrototype::create(vm, JSDataViewPrototype::createStructure(vm, this, m_objectPrototype.get())));
301     
302     m_typedArrays[toIndex(TypeInt8)].structure.set(vm, this, JSInt8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt8)].prototype.get()));
303     m_typedArrays[toIndex(TypeInt16)].structure.set(vm, this, JSInt16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt16)].prototype.get()));
304     m_typedArrays[toIndex(TypeInt32)].structure.set(vm, this, JSInt32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt32)].prototype.get()));
305     m_typedArrays[toIndex(TypeUint8)].structure.set(vm, this, JSUint8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8)].prototype.get()));
306     m_typedArrays[toIndex(TypeUint8Clamped)].structure.set(vm, this, JSUint8ClampedArray::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get()));
307     m_typedArrays[toIndex(TypeUint16)].structure.set(vm, this, JSUint16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint16)].prototype.get()));
308     m_typedArrays[toIndex(TypeUint32)].structure.set(vm, this, JSUint32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint32)].prototype.get()));
309     m_typedArrays[toIndex(TypeFloat32)].structure.set(vm, this, JSFloat32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat32)].prototype.get()));
310     m_typedArrays[toIndex(TypeFloat64)].structure.set(vm, this, JSFloat64Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat64)].prototype.get()));
311     m_typedArrays[toIndex(TypeDataView)].structure.set(vm, this, JSDataView::createStructure(vm, this, m_typedArrays[toIndex(TypeDataView)].prototype.get()));
312
313     m_nameScopeStructure.set(vm, this, JSNameScope::createStructure(vm, this, jsNull()));
314     m_activationStructure.set(vm, this, JSActivation::createStructure(vm, this, jsNull()));
315     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
316     m_withScopeStructure.set(vm, this, JSWithScope::createStructure(vm, this, jsNull()));
317
318     m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
319
320     m_callbackFunctionStructure.set(vm, this, JSCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
321     m_argumentsStructure.set(vm, this, Arguments::createStructure(vm, this, m_objectPrototype.get()));
322     m_callbackConstructorStructure.set(vm, this, JSCallbackConstructor::createStructure(vm, this, m_objectPrototype.get()));
323     m_callbackObjectStructure.set(vm, this, JSCallbackObject<JSDestructibleObject>::createStructure(vm, this, m_objectPrototype.get()));
324 #if JSC_OBJC_API_ENABLED
325     m_objcCallbackFunctionStructure.set(vm, this, ObjCCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
326     m_objcWrapperObjectStructure.set(vm, this, JSCallbackObject<JSAPIWrapperObject>::createStructure(vm, this, m_objectPrototype.get()));
327 #endif
328
329     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
330     
331     m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
332     m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
333     m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
334     m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
335     m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
336     m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
337     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
338         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
339     
340     m_regExpMatchesArrayStructure.set(vm, this, RegExpMatchesArray::createStructure(vm, this, m_arrayPrototype.get()));
341
342     RegExp* emptyRegex = RegExp::create(vm, "", NoFlags);
343     
344     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
345     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
346
347 #if ENABLE(PROMISES)
348     m_promisePrototype.set(vm, this, JSPromisePrototype::create(exec, this, JSPromisePrototype::createStructure(vm, this, m_objectPrototype.get())));
349     m_promiseStructure.set(vm, this, JSPromise::createStructure(vm, this, m_promisePrototype.get()));
350 #endif // ENABLE(PROMISES)
351
352 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
353     m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_objectPrototype.get()))); \
354     m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
355
356     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
357
358 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
359
360     // Constructors
361
362     ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
363     m_objectConstructor.set(vm, this, objectConstructor);
364     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
365     JSCell* arrayConstructor = ArrayConstructor::create(vm, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get());
366
367     m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get()));
368
369 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
370     capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get()); \
371     m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
372
373     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
374
375 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
376
377     m_errorConstructor.set(vm, this, errorConstructor);
378
379     Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get());
380     Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get());
381     m_evalErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("EvalError")));
382     m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("RangeError")));
383     m_referenceErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("ReferenceError")));
384     m_syntaxErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("SyntaxError")));
385     m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("TypeError")));
386     m_URIErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("URIError")));
387     m_promiseConstructor.set(vm, this, JSPromiseConstructor::create(vm, JSPromiseConstructor::createStructure(vm, this, m_functionPrototype.get()), m_promisePrototype.get()));
388
389     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
390     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
391     m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum);
392     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
393 #if ENABLE(PROMISES)
394     m_promisePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_promiseConstructor.get(), DontEnum);
395 #endif
396
397     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
398     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
399     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
400     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
401     putDirectWithoutTransition(vm, vm.propertyNames->EvalError, m_evalErrorConstructor.get(), DontEnum);
402     putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
403     putDirectWithoutTransition(vm, vm.propertyNames->ReferenceError, m_referenceErrorConstructor.get(), DontEnum);
404     putDirectWithoutTransition(vm, vm.propertyNames->SyntaxError, m_syntaxErrorConstructor.get(), DontEnum);
405     putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
406     putDirectWithoutTransition(vm, vm.propertyNames->URIError, m_URIErrorConstructor.get(), DontEnum);
407     putDirectWithoutTransition(vm, vm.propertyNames->Promise, m_promiseConstructor.get(), DontEnum);
408
409
410 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
411     putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
412
413     FOR_EACH_SIMPLE_BUILTIN_TYPE(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
414
415 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
416     PrototypeMap& prototypeMap = vm.prototypeMap;
417     Structure* iteratorResultStructure = prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity());
418     PropertyOffset offset;
419     iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->done, 0, 0, offset);
420     iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->value, 0, 0, offset);
421     m_iteratorResultStructure.set(vm, this, iteratorResultStructure);
422
423     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
424     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
425
426     putDirectWithoutTransition(vm, vm.propertyNames->JSON, JSONObject::create(vm, JSONObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
427     putDirectWithoutTransition(vm, vm.propertyNames->Math, MathObject::create(vm, this, MathObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
428     
429     std::array<InternalFunction*, NUMBER_OF_TYPED_ARRAY_TYPES> typedArrayConstructors;
430     typedArrayConstructors[toIndex(TypeInt8)] = JSInt8ArrayConstructor::create(vm, JSInt8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt8)].prototype.get(), "Int8Array");
431     typedArrayConstructors[toIndex(TypeInt16)] = JSInt16ArrayConstructor::create(vm, JSInt16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt16)].prototype.get(), "Int16Array");
432     typedArrayConstructors[toIndex(TypeInt32)] = JSInt32ArrayConstructor::create(vm, JSInt32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeInt32)].prototype.get(), "Int32Array");
433     typedArrayConstructors[toIndex(TypeUint8)] = JSUint8ArrayConstructor::create(vm, JSUint8ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8)].prototype.get(), "Uint8Array");
434     typedArrayConstructors[toIndex(TypeUint8Clamped)] = JSUint8ClampedArrayConstructor::create(vm, JSUint8ClampedArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get(), "Uint8ClampedArray");
435     typedArrayConstructors[toIndex(TypeUint16)] = JSUint16ArrayConstructor::create(vm, JSUint16ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint16)].prototype.get(), "Uint16Array");
436     typedArrayConstructors[toIndex(TypeUint32)] = JSUint32ArrayConstructor::create(vm, JSUint32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeUint32)].prototype.get(), "Uint32Array");
437     typedArrayConstructors[toIndex(TypeFloat32)] = JSFloat32ArrayConstructor::create(vm, JSFloat32ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat32)].prototype.get(), "Float32Array");
438     typedArrayConstructors[toIndex(TypeFloat64)] = JSFloat64ArrayConstructor::create(vm, JSFloat64ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeFloat64)].prototype.get(), "Float64Array");
439     typedArrayConstructors[toIndex(TypeDataView)] = JSDataViewConstructor::create(vm, JSDataViewConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeDataView)].prototype.get(), "DataView");
440
441     for (unsigned typedArrayIndex = NUMBER_OF_TYPED_ARRAY_TYPES; typedArrayIndex--;) {
442         m_typedArrays[typedArrayIndex].prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, typedArrayConstructors[typedArrayIndex], DontEnum);
443         putDirectWithoutTransition(vm, Identifier(exec, typedArrayConstructors[typedArrayIndex]->name(exec)), typedArrayConstructors[typedArrayIndex], DontEnum);
444     }
445
446     GlobalPropertyInfo staticGlobals[] = {
447         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
448         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
449         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
450         GlobalPropertyInfo(vm.propertyNames->undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly),
451         GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
452         GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly)
453     };
454     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
455     
456     m_specialPointers[Special::CallFunction] = m_callFunction.get();
457     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
458     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
459     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
460
461     if (m_experimentsEnabled) {
462         NamePrototype* privateNamePrototype = NamePrototype::create(exec, NamePrototype::createStructure(vm, this, m_objectPrototype.get()));
463         m_privateNameStructure.set(vm, this, NameInstance::createStructure(vm, this, privateNamePrototype));
464
465         JSCell* privateNameConstructor = NameConstructor::create(vm, NameConstructor::createStructure(vm, this, m_functionPrototype.get()), privateNamePrototype);
466         privateNamePrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, privateNameConstructor, DontEnum);
467         putDirectWithoutTransition(vm, Identifier(exec, "Name"), privateNameConstructor, DontEnum);
468     }
469
470     resetPrototype(vm, prototype);
471 }
472
473 // Private namespace for helpers for JSGlobalObject::haveABadTime()
474 namespace {
475
476 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
477 public:
478     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
479     void operator()(JSCell*);
480
481 private:
482     MarkedArgumentBuffer& m_foundObjects;
483     JSGlobalObject* m_globalObject;
484 };
485
486 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
487     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
488     : m_foundObjects(foundObjects)
489     , m_globalObject(globalObject)
490 {
491 }
492
493 inline bool hasBrokenIndexing(JSObject* object)
494 {
495     // This will change if we have more indexing types.
496     IndexingType type = object->structure()->indexingType();
497     // This could be made obviously more efficient, but isn't made so right now, because
498     // we expect this to be an unlikely slow path anyway.
499     return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasFastArrayStorage(type);
500 }
501
502 void ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
503 {
504     if (!cell->isObject())
505         return;
506     
507     JSObject* object = asObject(cell);
508
509     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
510     if (!hasBrokenIndexing(object))
511         return;
512     
513     // We only want to have a bad time in the affected global object, not in the entire
514     // VM. But we have to be careful, since there may be objects that claim to belong to
515     // a different global object that have prototypes from our global object.
516     bool foundGlobalObject = false;
517     for (JSObject* current = object; ;) {
518         if (current->globalObject() == m_globalObject) {
519             foundGlobalObject = true;
520             break;
521         }
522         
523         JSValue prototypeValue = current->prototype();
524         if (prototypeValue.isNull())
525             break;
526         current = asObject(prototypeValue);
527     }
528     if (!foundGlobalObject)
529         return;
530     
531     m_foundObjects.append(object);
532 }
533
534 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
535
536 void JSGlobalObject::haveABadTime(VM& vm)
537 {
538     ASSERT(&vm == &this->vm());
539     
540     if (isHavingABadTime())
541         return;
542     
543     // Make sure that all allocations or indexed storage transitions that are inlining
544     // the assumption that it's safe to transition to a non-SlowPut array storage don't
545     // do so anymore.
546     m_havingABadTimeWatchpoint->fireAll();
547     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
548     
549     // Make sure that all JSArray allocations that load the appropriate structure from
550     // this object now load a structure that uses SlowPut.
551     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
552         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
553     
554     // Make sure that all objects that have indexed storage switch to the slow kind of
555     // indexed storage.
556     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
557     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
558     {
559         HeapIterationScope iterationScope(vm.heap);
560         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
561     }
562     while (!foundObjects.isEmpty()) {
563         JSObject* object = asObject(foundObjects.last());
564         foundObjects.removeLast();
565         ASSERT(hasBrokenIndexing(object));
566         object->switchToSlowPutArrayStorage(vm);
567     }
568 }
569
570 bool JSGlobalObject::objectPrototypeIsSane()
571 {
572     return !hasIndexedProperties(m_objectPrototype->structure()->indexingType())
573         && m_objectPrototype->prototype().isNull();
574 }
575
576 bool JSGlobalObject::arrayPrototypeChainIsSane()
577 {
578     return !hasIndexedProperties(m_arrayPrototype->structure()->indexingType())
579         && m_arrayPrototype->prototype() == m_objectPrototype.get()
580         && objectPrototypeIsSane();
581 }
582
583 bool JSGlobalObject::stringPrototypeChainIsSane()
584 {
585     return !hasIndexedProperties(m_stringPrototype->structure()->indexingType())
586         && m_stringPrototype->prototype() == m_objectPrototype.get()
587         && objectPrototypeIsSane();
588 }
589
590 void JSGlobalObject::createThrowTypeError(VM& vm)
591 {
592     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
593     GetterSetter* getterSetter = GetterSetter::create(vm);
594     getterSetter->setGetter(vm, thrower);
595     getterSetter->setSetter(vm, thrower);
596     m_throwTypeErrorGetterSetter.set(vm, this, getterSetter);
597 }
598
599 // Set prototype, and also insert the object prototype at the end of the chain.
600 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
601 {
602     setPrototype(vm, prototype);
603
604     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
605     JSObject* objectPrototype = m_objectPrototype.get();
606     if (oldLastInPrototypeChain != objectPrototype)
607         oldLastInPrototypeChain->setPrototype(vm, objectPrototype);
608 }
609
610 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
611
612     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
613     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
614     COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
615     ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
616     Base::visitChildren(thisObject, visitor);
617
618     visitor.append(&thisObject->m_globalThis);
619
620     visitor.append(&thisObject->m_regExpConstructor);
621     visitor.append(&thisObject->m_errorConstructor);
622     visitor.append(&thisObject->m_evalErrorConstructor);
623     visitor.append(&thisObject->m_rangeErrorConstructor);
624     visitor.append(&thisObject->m_referenceErrorConstructor);
625     visitor.append(&thisObject->m_syntaxErrorConstructor);
626     visitor.append(&thisObject->m_typeErrorConstructor);
627     visitor.append(&thisObject->m_URIErrorConstructor);
628     visitor.append(&thisObject->m_objectConstructor);
629     visitor.append(&thisObject->m_promiseConstructor);
630
631     visitor.append(&thisObject->m_evalFunction);
632     visitor.append(&thisObject->m_callFunction);
633     visitor.append(&thisObject->m_applyFunction);
634     visitor.append(&thisObject->m_throwTypeErrorGetterSetter);
635
636     visitor.append(&thisObject->m_objectPrototype);
637     visitor.append(&thisObject->m_functionPrototype);
638     visitor.append(&thisObject->m_arrayPrototype);
639     visitor.append(&thisObject->m_errorPrototype);
640 #if ENABLE(PROMISES)
641     visitor.append(&thisObject->m_promisePrototype);
642 #endif
643
644     visitor.append(&thisObject->m_withScopeStructure);
645     visitor.append(&thisObject->m_strictEvalActivationStructure);
646     visitor.append(&thisObject->m_activationStructure);
647     visitor.append(&thisObject->m_nameScopeStructure);
648     visitor.append(&thisObject->m_argumentsStructure);
649     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
650         visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
651     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
652         visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
653     visitor.append(&thisObject->m_booleanObjectStructure);
654     visitor.append(&thisObject->m_callbackConstructorStructure);
655     visitor.append(&thisObject->m_callbackFunctionStructure);
656     visitor.append(&thisObject->m_callbackObjectStructure);
657 #if JSC_OBJC_API_ENABLED
658     visitor.append(&thisObject->m_objcCallbackFunctionStructure);
659     visitor.append(&thisObject->m_objcWrapperObjectStructure);
660 #endif
661     visitor.append(&thisObject->m_nullPrototypeObjectStructure);
662     visitor.append(&thisObject->m_errorStructure);
663     visitor.append(&thisObject->m_functionStructure);
664     visitor.append(&thisObject->m_boundFunctionStructure);
665     visitor.append(&thisObject->m_namedFunctionStructure);
666     visitor.append(&thisObject->m_privateNameStructure);
667     visitor.append(&thisObject->m_regExpMatchesArrayStructure);
668     visitor.append(&thisObject->m_regExpStructure);
669     visitor.append(&thisObject->m_internalFunctionStructure);
670
671 #if ENABLE(PROMISES)
672     visitor.append(&thisObject->m_promiseStructure);
673 #endif // ENABLE(PROMISES)
674
675 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
676     visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
677     visitor.append(&thisObject->m_ ## properName ## Structure); \
678
679     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
680
681 #undef VISIT_SIMPLE_TYPE
682
683     for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) {
684         visitor.append(&thisObject->m_typedArrays[i].prototype);
685         visitor.append(&thisObject->m_typedArrays[i].structure);
686     }
687 }
688
689 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
690 {
691     if (ecmaMode == StrictMode)
692         return jsUndefined();
693     return exec->globalThisValue();
694 }
695
696 ExecState* JSGlobalObject::globalExec()
697 {
698     return CallFrame::create(m_globalCallFrame);
699 }
700
701 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
702 {
703     addRegisters(count);
704
705     for (int i = 0; i < count; ++i) {
706         GlobalPropertyInfo& global = globals[i];
707         ASSERT(global.attributes & DontDelete);
708         
709         int index = symbolTable()->size();
710         SymbolTableEntry newEntry(index, global.attributes);
711         symbolTable()->add(global.identifier.impl(), newEntry);
712         registerAt(index).set(vm(), this, global.value);
713     }
714 }
715
716 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
717 {
718     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
719     if (getStaticFunctionSlot<Base>(exec, ExecState::globalObjectTable(exec->vm()), thisObject, propertyName, slot))
720         return true;
721     return symbolTableGet(thisObject, propertyName, slot);
722 }
723
724 void JSGlobalObject::clearRareData(JSCell* cell)
725 {
726     jsCast<JSGlobalObject*>(cell)->m_rareData.clear();
727 }
728
729 void slowValidateCell(JSGlobalObject* globalObject)
730 {
731     RELEASE_ASSERT(globalObject->isGlobalObject());
732     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
733 }
734
735 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
736 {
737     ParserError error;
738     JSParserStrictness strictness = executable->isStrictMode() ? JSParseStrict : JSParseNormal;
739     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
740     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
741     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(vm(), executable, executable->source(), strictness, debuggerMode, profilerMode, error);
742
743     if (hasDebugger())
744         debugger()->sourceParsed(callFrame, executable->source().provider(), error.m_line, error.m_message);
745
746     if (error.m_type != ParserError::ErrorNone) {
747         *exception = error.toErrorObject(this, executable->source());
748         return 0;
749     }
750     
751     return unlinkedCodeBlock;
752 }
753
754 UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable)
755 {
756     ParserError error;
757     JSParserStrictness strictness = executable->isStrictMode() ? JSParseStrict : JSParseNormal;
758     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
759     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
760     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(vm(), executable, executable->source(), strictness, debuggerMode, profilerMode, error);
761
762     if (hasDebugger())
763         debugger()->sourceParsed(callFrame, executable->source().provider(), error.m_line, error.m_message);
764
765     if (error.m_type != ParserError::ErrorNone) {
766         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
767         return 0;
768     }
769
770     return unlinkedCodeBlock;
771 }
772
773 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
774 {
775 #if ENABLE(REMOTE_INSPECTOR)
776     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
777 #else
778     UNUSED_PARAM(enabled);
779 #endif
780 }
781
782 bool JSGlobalObject::remoteDebuggingEnabled() const
783 {
784 #if ENABLE(REMOTE_INSPECTOR)
785     return m_inspectorDebuggable->remoteDebuggingAllowed();
786 #else
787     return false;
788 #endif
789 }
790
791 #if ENABLE(WEB_REPLAY)
792 void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
793 {
794     m_inputCursor = prpCursor;
795     ASSERT(m_inputCursor);
796
797     InputCursor& cursor = inputCursor();
798     // Save or set the random seed. This performed here rather than the constructor
799     // to avoid threading the input cursor through all the abstraction layers.
800     if (cursor.isCapturing())
801         cursor.appendInput<SetRandomSeed>(m_weakRandom.seedUnsafe());
802     else if (cursor.isReplaying()) {
803         if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
804             m_weakRandom.initializeSeed(input->randomSeed());
805     }
806 }
807 #endif
808
809 void JSGlobalObject::setName(const String& name)
810 {
811     m_name = name;
812
813 #if ENABLE(REMOTE_INSPECTOR)
814     m_inspectorDebuggable->update();
815 #endif
816 }
817
818 void JSGlobalObject::queueMicrotask(PassRefPtr<Microtask> task)
819 {
820     if (globalObjectMethodTable()->queueTaskToEventLoop)
821         globalObjectMethodTable()->queueTaskToEventLoop(this, task);
822     else
823         WTFLogAlways("ERROR: Event loop not supported.");
824 }
825
826 } // namespace JSC