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