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