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