Implement ES6 Symbol
[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     GlobalPropertyInfo staticGlobals[] = {
408         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
409         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
410         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
411         GlobalPropertyInfo(vm.propertyNames->undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly),
412         GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
413         GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
414         GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly)
415     };
416     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
417     
418     m_specialPointers[Special::CallFunction] = m_callFunction.get();
419     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
420     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
421     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
422     
423     ConsolePrototype* consolePrototype = ConsolePrototype::create(vm, this, ConsolePrototype::createStructure(vm, this, m_objectPrototype.get()));
424     m_consoleStructure.set(vm, this, JSConsole::createStructure(vm, this, consolePrototype));
425     JSConsole* consoleObject = JSConsole::create(vm, m_consoleStructure.get());
426     putDirectWithoutTransition(vm, Identifier(exec, "console"), consoleObject, DontEnum);
427     
428     resetPrototype(vm, prototype());
429 }
430
431 void JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
432 {
433     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
434     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
435
436     if (symbolTablePut(thisObject, exec, propertyName, value, slot.isStrictMode()))
437         return;
438     Base::put(thisObject, exec, propertyName, value, slot);
439 }
440
441 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
442 {
443     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
444     PropertySlot slot(thisObject);
445     // silently ignore attempts to add accessors aliasing vars.
446     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
447         return false;
448     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
449 }
450
451 JSGlobalObject::NewGlobalVar JSGlobalObject::addGlobalVar(const Identifier& ident, ConstantMode constantMode)
452 {
453     ConcurrentJITLocker locker(symbolTable()->m_lock);
454     int index = symbolTable()->size(locker);
455     SymbolTableEntry newEntry(index, (constantMode == IsConstant) ? ReadOnly : 0);
456     if (constantMode == IsVariable)
457         newEntry.prepareToWatch(symbolTable());
458     SymbolTable::Map::AddResult result = symbolTable()->add(locker, ident.impl(), newEntry);
459     if (result.isNewEntry)
460         addRegisters(1);
461     else
462         index = result.iterator->value.getIndex();
463     NewGlobalVar var;
464     var.registerNumber = index;
465     var.set = result.iterator->value.watchpointSet();
466     return var;
467 }
468
469 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName, JSValue value)
470 {
471     VM& vm = exec->vm();
472     removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties.
473     NewGlobalVar var = addGlobalVar(propertyName, IsVariable);
474     registerAt(var.registerNumber).set(exec->vm(), this, value);
475     if (var.set)
476         var.set->notifyWrite(vm, value, VariableWriteFireDetail(this, propertyName));
477 }
478
479 static inline JSObject* lastInPrototypeChain(JSObject* object)
480 {
481     JSObject* o = object;
482     while (o->prototype().isObject())
483         o = asObject(o->prototype());
484     return o;
485 }
486
487 // Private namespace for helpers for JSGlobalObject::haveABadTime()
488 namespace {
489
490 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
491 public:
492     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
493     void operator()(JSCell*);
494
495 private:
496     MarkedArgumentBuffer& m_foundObjects;
497     JSGlobalObject* m_globalObject;
498 };
499
500 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
501     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
502     : m_foundObjects(foundObjects)
503     , m_globalObject(globalObject)
504 {
505 }
506
507 inline bool hasBrokenIndexing(JSObject* object)
508 {
509     // This will change if we have more indexing types.
510     IndexingType type = object->indexingType();
511     // This could be made obviously more efficient, but isn't made so right now, because
512     // we expect this to be an unlikely slow path anyway.
513     return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
514 }
515
516 void ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
517 {
518     if (!cell->isObject())
519         return;
520     
521     JSObject* object = asObject(cell);
522
523     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
524     if (!hasBrokenIndexing(object))
525         return;
526     
527     // We only want to have a bad time in the affected global object, not in the entire
528     // VM. But we have to be careful, since there may be objects that claim to belong to
529     // a different global object that have prototypes from our global object.
530     bool foundGlobalObject = false;
531     for (JSObject* current = object; ;) {
532         if (current->globalObject() == m_globalObject) {
533             foundGlobalObject = true;
534             break;
535         }
536         
537         JSValue prototypeValue = current->prototype();
538         if (prototypeValue.isNull())
539             break;
540         current = asObject(prototypeValue);
541     }
542     if (!foundGlobalObject)
543         return;
544     
545     m_foundObjects.append(object);
546 }
547
548 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
549
550 void JSGlobalObject::haveABadTime(VM& vm)
551 {
552     ASSERT(&vm == &this->vm());
553     
554     if (isHavingABadTime())
555         return;
556     
557     // Make sure that all allocations or indexed storage transitions that are inlining
558     // the assumption that it's safe to transition to a non-SlowPut array storage don't
559     // do so anymore.
560     m_havingABadTimeWatchpoint->fireAll("Having a bad time");
561     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
562     
563     // Make sure that all JSArray allocations that load the appropriate structure from
564     // this object now load a structure that uses SlowPut.
565     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
566         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
567     
568     // Make sure that all objects that have indexed storage switch to the slow kind of
569     // indexed storage.
570     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
571     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
572     {
573         HeapIterationScope iterationScope(vm.heap);
574         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
575     }
576     while (!foundObjects.isEmpty()) {
577         JSObject* object = asObject(foundObjects.last());
578         foundObjects.removeLast();
579         ASSERT(hasBrokenIndexing(object));
580         object->switchToSlowPutArrayStorage(vm);
581     }
582 }
583
584 bool JSGlobalObject::objectPrototypeIsSane()
585 {
586     return !hasIndexedProperties(m_objectPrototype->indexingType())
587         && m_objectPrototype->prototype().isNull();
588 }
589
590 bool JSGlobalObject::arrayPrototypeChainIsSane()
591 {
592     return !hasIndexedProperties(m_arrayPrototype->indexingType())
593         && m_arrayPrototype->prototype() == m_objectPrototype.get()
594         && objectPrototypeIsSane();
595 }
596
597 bool JSGlobalObject::stringPrototypeChainIsSane()
598 {
599     return !hasIndexedProperties(m_stringPrototype->indexingType())
600         && m_stringPrototype->prototype() == m_objectPrototype.get()
601         && objectPrototypeIsSane();
602 }
603
604 void JSGlobalObject::createThrowTypeError(VM& vm)
605 {
606     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
607     GetterSetter* getterSetter = GetterSetter::create(vm, this);
608     getterSetter->setGetter(vm, this, thrower);
609     getterSetter->setSetter(vm, this, thrower);
610     m_throwTypeErrorGetterSetter.set(vm, this, getterSetter);
611 }
612
613 // Set prototype, and also insert the object prototype at the end of the chain.
614 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
615 {
616     setPrototype(vm, prototype);
617
618     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
619     JSObject* objectPrototype = m_objectPrototype.get();
620     if (oldLastInPrototypeChain != objectPrototype)
621         oldLastInPrototypeChain->setPrototype(vm, objectPrototype);
622
623     // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
624     setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
625 }
626
627 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
628
629     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
630     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
631     Base::visitChildren(thisObject, visitor);
632
633     visitor.append(&thisObject->m_globalThis);
634
635     visitor.append(&thisObject->m_globalCallee);
636     visitor.append(&thisObject->m_regExpConstructor);
637     visitor.append(&thisObject->m_errorConstructor);
638     visitor.append(&thisObject->m_evalErrorConstructor);
639     visitor.append(&thisObject->m_rangeErrorConstructor);
640     visitor.append(&thisObject->m_referenceErrorConstructor);
641     visitor.append(&thisObject->m_syntaxErrorConstructor);
642     visitor.append(&thisObject->m_typeErrorConstructor);
643     visitor.append(&thisObject->m_URIErrorConstructor);
644     visitor.append(&thisObject->m_objectConstructor);
645 #if ENABLE(PROMISES)
646     visitor.append(&thisObject->m_promiseConstructor);
647 #endif
648
649     visitor.append(&thisObject->m_nullGetterFunction);
650     visitor.append(&thisObject->m_nullSetterFunction);
651
652     visitor.append(&thisObject->m_evalFunction);
653     visitor.append(&thisObject->m_callFunction);
654     visitor.append(&thisObject->m_applyFunction);
655     visitor.append(&thisObject->m_throwTypeErrorGetterSetter);
656
657     visitor.append(&thisObject->m_objectPrototype);
658     visitor.append(&thisObject->m_functionPrototype);
659     visitor.append(&thisObject->m_arrayPrototype);
660     visitor.append(&thisObject->m_errorPrototype);
661 #if ENABLE(PROMISES)
662     visitor.append(&thisObject->m_promisePrototype);
663 #endif
664
665     visitor.append(&thisObject->m_debuggerScopeStructure);
666     visitor.append(&thisObject->m_withScopeStructure);
667     visitor.append(&thisObject->m_strictEvalActivationStructure);
668     visitor.append(&thisObject->m_lexicalEnvironmentStructure);
669     visitor.append(&thisObject->m_nameScopeStructure);
670     visitor.append(&thisObject->m_argumentsStructure);
671     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
672         visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
673     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
674         visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
675     visitor.append(&thisObject->m_booleanObjectStructure);
676     visitor.append(&thisObject->m_callbackConstructorStructure);
677     visitor.append(&thisObject->m_callbackFunctionStructure);
678     visitor.append(&thisObject->m_callbackObjectStructure);
679 #if JSC_OBJC_API_ENABLED
680     visitor.append(&thisObject->m_objcCallbackFunctionStructure);
681     visitor.append(&thisObject->m_objcWrapperObjectStructure);
682 #endif
683     visitor.append(&thisObject->m_nullPrototypeObjectStructure);
684     visitor.append(&thisObject->m_errorStructure);
685     visitor.append(&thisObject->m_calleeStructure);
686     visitor.append(&thisObject->m_functionStructure);
687     visitor.append(&thisObject->m_boundFunctionStructure);
688     visitor.append(&thisObject->m_namedFunctionStructure);
689     visitor.append(&thisObject->m_symbolObjectStructure);
690     visitor.append(&thisObject->m_regExpMatchesArrayStructure);
691     visitor.append(&thisObject->m_regExpStructure);
692     visitor.append(&thisObject->m_consoleStructure);
693     visitor.append(&thisObject->m_internalFunctionStructure);
694
695 #if ENABLE(PROMISES)
696     visitor.append(&thisObject->m_promiseStructure);
697 #endif // ENABLE(PROMISES)
698
699 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
700     visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
701     visitor.append(&thisObject->m_ ## properName ## Structure); \
702
703     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
704
705 #undef VISIT_SIMPLE_TYPE
706
707     for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) {
708         visitor.append(&thisObject->m_typedArrays[i].prototype);
709         visitor.append(&thisObject->m_typedArrays[i].structure);
710     }
711 }
712
713 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
714 {
715     if (ecmaMode == StrictMode)
716         return jsUndefined();
717     return exec->globalThisValue();
718 }
719
720 ExecState* JSGlobalObject::globalExec()
721 {
722     return CallFrame::create(m_globalCallFrame);
723 }
724
725 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
726 {
727     addRegisters(count);
728
729     for (int i = 0; i < count; ++i) {
730         GlobalPropertyInfo& global = globals[i];
731         ASSERT(global.attributes & DontDelete);
732         
733         int index = symbolTable()->size();
734         SymbolTableEntry newEntry(index, global.attributes);
735         symbolTable()->add(global.identifier.impl(), newEntry);
736         registerAt(index).set(vm(), this, global.value);
737     }
738 }
739
740 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
741 {
742     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
743     if (getStaticFunctionSlot<Base>(exec, globalObjectTable, thisObject, propertyName, slot))
744         return true;
745     return symbolTableGet(thisObject, propertyName, slot);
746 }
747
748 void JSGlobalObject::clearRareData(JSCell* cell)
749 {
750     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
751 }
752
753 void slowValidateCell(JSGlobalObject* globalObject)
754 {
755     RELEASE_ASSERT(globalObject->isGlobalObject());
756     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
757 }
758
759 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
760 {
761     ParserError error;
762     JSParserStrictness strictness = executable->isStrictMode() ? JSParseStrict : JSParseNormal;
763     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
764     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
765     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(vm(), executable, executable->source(), strictness, debuggerMode, profilerMode, error);
766
767     if (hasDebugger())
768         debugger()->sourceParsed(callFrame, executable->source().provider(), error.m_line, error.m_message);
769
770     if (error.m_type != ParserError::ErrorNone) {
771         *exception = error.toErrorObject(this, executable->source());
772         return 0;
773     }
774     
775     return unlinkedCodeBlock;
776 }
777
778 UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable)
779 {
780     ParserError error;
781     JSParserStrictness strictness = executable->isStrictMode() ? JSParseStrict : JSParseNormal;
782     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
783     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
784     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(vm(), executable, executable->source(), strictness, debuggerMode, profilerMode, error);
785
786     if (hasDebugger())
787         debugger()->sourceParsed(callFrame, executable->source().provider(), error.m_line, error.m_message);
788
789     if (error.m_type != ParserError::ErrorNone) {
790         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
791         return 0;
792     }
793
794     return unlinkedCodeBlock;
795 }
796
797 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
798 {
799 #if ENABLE(REMOTE_INSPECTOR)
800     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
801 #else
802     UNUSED_PARAM(enabled);
803 #endif
804 }
805
806 bool JSGlobalObject::remoteDebuggingEnabled() const
807 {
808 #if ENABLE(REMOTE_INSPECTOR)
809     return m_inspectorDebuggable->remoteDebuggingAllowed();
810 #else
811     return false;
812 #endif
813 }
814
815 #if ENABLE(WEB_REPLAY)
816 void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
817 {
818     m_inputCursor = prpCursor;
819     ASSERT(m_inputCursor);
820
821     InputCursor& cursor = inputCursor();
822     // Save or set the random seed. This performed here rather than the constructor
823     // to avoid threading the input cursor through all the abstraction layers.
824     if (cursor.isCapturing())
825         cursor.appendInput<SetRandomSeed>(m_weakRandom.seedUnsafe());
826     else if (cursor.isReplaying()) {
827         if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
828             m_weakRandom.initializeSeed(static_cast<unsigned>(input->randomSeed()));
829     }
830 }
831 #endif
832
833 void JSGlobalObject::setName(const String& name)
834 {
835     m_name = name;
836
837 #if ENABLE(REMOTE_INSPECTOR)
838     m_inspectorDebuggable->update();
839 #endif
840 }
841
842 void JSGlobalObject::queueMicrotask(PassRefPtr<Microtask> task)
843 {
844     if (globalObjectMethodTable()->queueTaskToEventLoop)
845         globalObjectMethodTable()->queueTaskToEventLoop(this, task);
846     else
847         WTFLogAlways("ERROR: Event loop not supported.");
848 }
849
850 } // namespace JSC