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