[ES6] "super" and "this" should be lexically bound inside an arrow function and shoul...
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2014, 2015 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 "ArrayConstructor.h"
34 #include "ArrayIteratorPrototype.h"
35 #include "ArrayPrototype.h"
36 #include "BooleanConstructor.h"
37 #include "BooleanPrototype.h"
38 #include "BuiltinNames.h"
39 #include "ClonedArguments.h"
40 #include "CodeBlock.h"
41 #include "CodeCache.h"
42 #include "ConsolePrototype.h"
43 #include "DateConstructor.h"
44 #include "DatePrototype.h"
45 #include "Debugger.h"
46 #include "DebuggerScope.h"
47 #include "DirectArguments.h"
48 #include "Error.h"
49 #include "ErrorConstructor.h"
50 #include "ErrorPrototype.h"
51 #include "FunctionConstructor.h"
52 #include "FunctionPrototype.h"
53 #include "GeneratorFunctionConstructor.h"
54 #include "GeneratorFunctionPrototype.h"
55 #include "GeneratorPrototype.h"
56 #include "GetterSetter.h"
57 #include "HeapIterationScope.h"
58 #include "InspectorInstrumentationObject.h"
59 #include "Interpreter.h"
60 #include "IteratorPrototype.h"
61 #include "JSAPIWrapperObject.h"
62 #include "JSArrayBuffer.h"
63 #include "JSArrayBufferConstructor.h"
64 #include "JSArrayBufferPrototype.h"
65 #include "JSArrayIterator.h"
66 #include "JSArrowFunction.h"
67 #include "JSBoundFunction.h"
68 #include "JSCInlines.h"
69 #include "JSCallbackConstructor.h"
70 #include "JSCallbackFunction.h"
71 #include "JSCallbackObject.h"
72 #include "JSConsole.h"
73 #include "JSDataView.h"
74 #include "JSDataViewPrototype.h"
75 #include "JSDollarVM.h"
76 #include "JSDollarVMPrototype.h"
77 #include "JSFunction.h"
78 #include "JSGeneratorFunction.h"
79 #include "JSGenericTypedArrayViewConstructorInlines.h"
80 #include "JSGenericTypedArrayViewInlines.h"
81 #include "JSGenericTypedArrayViewPrototypeInlines.h"
82 #include "JSGlobalObjectFunctions.h"
83 #include "JSInternalPromise.h"
84 #include "JSInternalPromiseConstructor.h"
85 #include "JSInternalPromisePrototype.h"
86 #include "JSJob.h"
87 #include "JSLexicalEnvironment.h"
88 #include "JSLock.h"
89 #include "JSMap.h"
90 #include "JSMapIterator.h"
91 #include "JSModuleEnvironment.h"
92 #include "JSModuleNamespaceObject.h"
93 #include "JSModuleRecord.h"
94 #include "JSNativeStdFunction.h"
95 #include "JSONObject.h"
96 #include "JSPromise.h"
97 #include "JSPromiseConstructor.h"
98 #include "JSPromisePrototype.h"
99 #include "JSPropertyNameIterator.h"
100 #include "JSSet.h"
101 #include "JSSetIterator.h"
102 #include "JSStringIterator.h"
103 #include "JSTemplateRegistryKey.h"
104 #include "JSTypedArrayConstructors.h"
105 #include "JSTypedArrayPrototypes.h"
106 #include "JSTypedArrayViewConstructor.h"
107 #include "JSTypedArrayViewPrototype.h"
108 #include "JSTypedArrays.h"
109 #include "JSWASMModule.h"
110 #include "JSWeakMap.h"
111 #include "JSWeakSet.h"
112 #include "JSWithScope.h"
113 #include "LegacyProfiler.h"
114 #include "Lookup.h"
115 #include "MapConstructor.h"
116 #include "MapIteratorPrototype.h"
117 #include "MapPrototype.h"
118 #include "MathObject.h"
119 #include "Microtask.h"
120 #include "ModuleLoaderObject.h"
121 #include "NativeErrorConstructor.h"
122 #include "NativeErrorPrototype.h"
123 #include "NullGetterFunction.h"
124 #include "NullSetterFunction.h"
125 #include "NumberConstructor.h"
126 #include "NumberPrototype.h"
127 #include "ObjCCallbackFunction.h"
128 #include "ObjectConstructor.h"
129 #include "ObjectPrototype.h"
130 #include "ParserError.h"
131 #include "ReflectObject.h"
132 #include "RegExpConstructor.h"
133 #include "RegExpMatchesArray.h"
134 #include "RegExpObject.h"
135 #include "RegExpPrototype.h"
136 #include "ScopedArguments.h"
137 #include "SetConstructor.h"
138 #include "SetIteratorPrototype.h"
139 #include "SetPrototype.h"
140 #include "StrictEvalActivation.h"
141 #include "StringConstructor.h"
142 #include "StringIteratorPrototype.h"
143 #include "StringPrototype.h"
144 #include "Symbol.h"
145 #include "SymbolConstructor.h"
146 #include "SymbolPrototype.h"
147 #include "VariableWriteFireDetail.h"
148 #include "WeakGCMapInlines.h"
149 #include "WeakMapConstructor.h"
150 #include "WeakMapPrototype.h"
151 #include "WeakSetConstructor.h"
152 #include "WeakSetPrototype.h"
153
154 #if ENABLE(INTL)
155 #include "IntlObject.h"
156 #include <unicode/ucol.h>
157 #include <unicode/udat.h>
158 #include <unicode/unum.h>
159 #endif // ENABLE(INTL)
160
161 #if ENABLE(REMOTE_INSPECTOR)
162 #include "JSGlobalObjectDebuggable.h"
163 #include "JSGlobalObjectInspectorController.h"
164 #endif
165
166 #if ENABLE(WEB_REPLAY)
167 #include "EmptyInputCursor.h"
168 #include "JSReplayInputs.h"
169 #endif
170
171 #include "JSGlobalObject.lut.h"
172
173 namespace JSC {
174
175 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
176
177 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr };
178
179 /* Source for JSGlobalObject.lut.h
180 @begin globalObjectTable
181   parseFloat            globalFuncParseFloat            DontEnum|Function 1
182   isNaN                 globalFuncIsNaN                 DontEnum|Function 1
183   isFinite              globalFuncIsFinite              DontEnum|Function 1
184   escape                globalFuncEscape                DontEnum|Function 1
185   unescape              globalFuncUnescape              DontEnum|Function 1
186   decodeURI             globalFuncDecodeURI             DontEnum|Function 1
187   decodeURIComponent    globalFuncDecodeURIComponent    DontEnum|Function 1
188   encodeURI             globalFuncEncodeURI             DontEnum|Function 1
189   encodeURIComponent    globalFuncEncodeURIComponent    DontEnum|Function 1
190 @end
191 */
192
193 static EncodedJSValue JSC_HOST_CALL getTemplateObject(ExecState* exec)
194 {
195     JSValue thisValue = exec->thisValue();
196     ASSERT(thisValue.inherits(JSTemplateRegistryKey::info()));
197     return JSValue::encode(exec->lexicalGlobalObject()->templateRegistry().getTemplateObject(exec, jsCast<JSTemplateRegistryKey*>(thisValue)->templateRegistryKey()));
198 }
199
200
201 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
202 {
203     VM& vm = exec->vm();
204     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
205
206     JSValue job = exec->argument(0);
207     JSValue arguments = exec->argument(1);
208     ASSERT(arguments.inherits(JSArray::info()));
209
210     globalObject->queueMicrotask(createJSJob(vm, job, jsCast<JSArray*>(arguments)));
211
212     return JSValue::encode(jsUndefined());
213 }
214
215 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
216     : Base(vm, structure, 0)
217     , m_vm(vm)
218 #if ENABLE(WEB_REPLAY)
219     , m_inputCursor(EmptyInputCursor::create())
220 #endif
221     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
222     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
223     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
224     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
225     , m_templateRegistry(vm)
226     , m_evalEnabled(true)
227     , m_runtimeFlags()
228     , m_consoleClient(nullptr)
229     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
230 {
231 }
232
233 JSGlobalObject::~JSGlobalObject()
234 {
235 #if ENABLE(REMOTE_INSPECTOR)
236     m_inspectorController->globalObjectDestroyed();
237 #endif
238
239     if (m_debugger)
240         m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
241
242     if (LegacyProfiler* profiler = vm().enabledProfiler())
243         profiler->stopProfiling(this);
244 }
245
246 void JSGlobalObject::destroy(JSCell* cell)
247 {
248     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
249 }
250
251 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
252 {
253     m_globalThis.set(vm, this, globalThis);
254 }
255
256 void JSGlobalObject::init(VM& vm)
257 {
258     ASSERT(vm.currentThreadIsHoldingAPILock());
259
260     JSGlobalObject::globalExec()->init(0, 0, CallFrame::noCaller(), 0, 0);
261
262     m_debugger = 0;
263
264 #if ENABLE(REMOTE_INSPECTOR)
265     m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
266     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
267     m_inspectorDebuggable->init();
268     m_consoleClient = m_inspectorController->consoleClient();
269 #endif
270
271     ExecState* exec = JSGlobalObject::globalExec();
272
273     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
274     m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
275
276     m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
277     // Need to create the callee structure (above) before creating the callee.
278     m_globalCallee.set(vm, this, JSCallee::create(vm, this, globalScope()));
279     exec->setCallee(m_globalCallee.get());
280
281     m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
282     m_arrowFunctionStructure.set(vm, this, JSArrowFunction::createStructure(vm, this, m_functionPrototype.get()));
283     m_boundFunctionStructure.set(vm, this, JSBoundFunction::createStructure(vm, this, m_functionPrototype.get()));
284     m_nativeStdFunctionStructure.set(vm, this, JSNativeStdFunction::createStructure(vm, this, m_functionPrototype.get()));
285     m_namedFunctionStructure.set(vm, this, Structure::addPropertyTransition(vm, m_functionStructure.get(), vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, m_functionNameOffset));
286     m_internalFunctionStructure.set(vm, this, InternalFunction::createStructure(vm, this, m_functionPrototype.get()));
287     JSFunction* callFunction = 0;
288     JSFunction* applyFunction = 0;
289     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction);
290     m_callFunction.set(vm, this, callFunction);
291     m_applyFunction.set(vm, this, applyFunction);
292     m_arrayProtoValuesFunction.set(vm, this, JSFunction::create(vm, this, 0, vm.propertyNames->values.string(), arrayProtoFuncValues));
293     m_initializePromiseFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, promiseOperationsInitializePromiseCodeGenerator(vm), this));
294     m_newPromiseCapabilityFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
295     m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
296     m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
297     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
298     GetterSetter* protoAccessor = GetterSetter::create(vm, this);
299     protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoGetter));
300     protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, String(), globalFuncProtoSetter));
301     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
302     m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
303
304     JSTypedArrayViewPrototype* typedArrayProto = JSTypedArrayViewPrototype::create(vm, this, JSTypedArrayViewPrototype::createStructure(vm, this, m_objectPrototype.get()));
305
306     m_typedArrays[toIndex(TypeInt8)].prototype.set(vm, this, JSInt8ArrayPrototype::create(vm, this, JSInt8ArrayPrototype::createStructure(vm, this, typedArrayProto)));
307     m_typedArrays[toIndex(TypeInt16)].prototype.set(vm, this, JSInt16ArrayPrototype::create(vm, this, JSInt16ArrayPrototype::createStructure(vm, this, typedArrayProto)));
308     m_typedArrays[toIndex(TypeInt32)].prototype.set(vm, this, JSInt32ArrayPrototype::create(vm, this, JSInt32ArrayPrototype::createStructure(vm, this, typedArrayProto)));
309     m_typedArrays[toIndex(TypeUint8)].prototype.set(vm, this, JSUint8ArrayPrototype::create(vm, this, JSUint8ArrayPrototype::createStructure(vm, this, typedArrayProto)));
310     m_typedArrays[toIndex(TypeUint8Clamped)].prototype.set(vm, this, JSUint8ClampedArrayPrototype::create(vm, this, JSUint8ClampedArrayPrototype::createStructure(vm, this, typedArrayProto)));
311     m_typedArrays[toIndex(TypeUint16)].prototype.set(vm, this, JSUint16ArrayPrototype::create(vm, this, JSUint16ArrayPrototype::createStructure(vm, this, typedArrayProto)));
312     m_typedArrays[toIndex(TypeUint32)].prototype.set(vm, this, JSUint32ArrayPrototype::create(vm, this, JSUint32ArrayPrototype::createStructure(vm, this, typedArrayProto)));
313     m_typedArrays[toIndex(TypeFloat32)].prototype.set(vm, this, JSFloat32ArrayPrototype::create(vm, this, JSFloat32ArrayPrototype::createStructure(vm, this, typedArrayProto)));
314     m_typedArrays[toIndex(TypeFloat64)].prototype.set(vm, this, JSFloat64ArrayPrototype::create(vm, this, JSFloat64ArrayPrototype::createStructure(vm, this, typedArrayProto)));
315     m_typedArrays[toIndex(TypeDataView)].prototype.set(vm, this, JSDataViewPrototype::create(vm, JSDataViewPrototype::createStructure(vm, this, m_objectPrototype.get())));
316     
317     m_typedArrays[toIndex(TypeInt8)].structure.set(vm, this, JSInt8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt8)].prototype.get()));
318     m_typedArrays[toIndex(TypeInt16)].structure.set(vm, this, JSInt16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt16)].prototype.get()));
319     m_typedArrays[toIndex(TypeInt32)].structure.set(vm, this, JSInt32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeInt32)].prototype.get()));
320     m_typedArrays[toIndex(TypeUint8)].structure.set(vm, this, JSUint8Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8)].prototype.get()));
321     m_typedArrays[toIndex(TypeUint8Clamped)].structure.set(vm, this, JSUint8ClampedArray::createStructure(vm, this, m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get()));
322     m_typedArrays[toIndex(TypeUint16)].structure.set(vm, this, JSUint16Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint16)].prototype.get()));
323     m_typedArrays[toIndex(TypeUint32)].structure.set(vm, this, JSUint32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeUint32)].prototype.get()));
324     m_typedArrays[toIndex(TypeFloat32)].structure.set(vm, this, JSFloat32Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat32)].prototype.get()));
325     m_typedArrays[toIndex(TypeFloat64)].structure.set(vm, this, JSFloat64Array::createStructure(vm, this, m_typedArrays[toIndex(TypeFloat64)].prototype.get()));
326     m_typedArrays[toIndex(TypeDataView)].structure.set(vm, this, JSDataView::createStructure(vm, this, m_typedArrays[toIndex(TypeDataView)].prototype.get()));
327     
328     m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
329     m_moduleEnvironmentStructure.set(vm, this, JSModuleEnvironment::createStructure(vm, this));
330     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
331     m_debuggerScopeStructure.set(m_vm, this, DebuggerScope::createStructure(m_vm, this));
332     m_withScopeStructure.set(vm, this, JSWithScope::createStructure(vm, this, jsNull()));
333     
334     m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
335     
336     m_callbackFunctionStructure.set(vm, this, JSCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
337     m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
338     m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
339     m_outOfBandArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
340     m_callbackConstructorStructure.set(vm, this, JSCallbackConstructor::createStructure(vm, this, m_objectPrototype.get()));
341     m_callbackObjectStructure.set(vm, this, JSCallbackObject<JSDestructibleObject>::createStructure(vm, this, m_objectPrototype.get()));
342
343 #if JSC_OBJC_API_ENABLED
344     m_objcCallbackFunctionStructure.set(vm, this, ObjCCallbackFunction::createStructure(vm, this, m_functionPrototype.get()));
345     m_objcWrapperObjectStructure.set(vm, this, JSCallbackObject<JSAPIWrapperObject>::createStructure(vm, this, m_objectPrototype.get()));
346 #endif
347     
348     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
349     
350     m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
351     m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
352     m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
353     m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
354     m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
355     m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
356     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
357         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
358
359     RegExp* emptyRegex = RegExp::create(vm, "", NoFlags);
360     
361     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
362     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
363     m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, *this));
364
365     m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
366     m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
367     
368 #if ENABLE(WEBASSEMBLY)
369     m_wasmModuleStructure.set(vm, this, JSWASMModule::createStructure(vm, this));
370 #endif
371
372     m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, NoIntrinsic));
373     putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum);
374
375 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
376 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_objectPrototype.get()))); \
377 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
378     
379     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
380     
381 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
382
383     m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
384
385 #define CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
386 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_iteratorPrototype.get()))); \
387 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
388     
389     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE)
390     m_propertyNameIteratorStructure.set(vm, this, JSPropertyNameIterator::createStructure(vm, this, m_iteratorPrototype.get()));
391     m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
392     
393 #undef CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE
394
395     // Constructors
396     
397     ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
398     m_objectConstructor.set(vm, this, objectConstructor);
399
400     JSFunction* definePropertyFunction = m_objectConstructor->addDefineProperty(exec, this);
401     m_definePropertyFunction.set(vm, this, definePropertyFunction);
402
403     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
404     JSCell* arrayConstructor = ArrayConstructor::create(vm, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get());
405     
406     m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get()));
407     
408 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
409 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get()); \
410 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
411
412     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
413     
414 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
415     
416     m_errorConstructor.set(vm, this, errorConstructor);
417     m_promiseConstructor.set(vm, this, promiseConstructor);
418     m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
419     
420     Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get());
421     Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get());
422     m_evalErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("EvalError")));
423     m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("RangeError")));
424     m_referenceErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("ReferenceError")));
425     m_syntaxErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("SyntaxError")));
426     m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("TypeError")));
427     m_URIErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("URIError")));
428
429     m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
430     GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
431     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, DontEnum);
432     m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
433
434     m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), DontEnum);
435     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), DontEnum);
436     
437     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
438     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
439     m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, DontEnum);
440     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
441     
442     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
443     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
444     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
445     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
446     putDirectWithoutTransition(vm, vm.propertyNames->EvalError, m_evalErrorConstructor.get(), DontEnum);
447     putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
448     putDirectWithoutTransition(vm, vm.propertyNames->ReferenceError, m_referenceErrorConstructor.get(), DontEnum);
449     putDirectWithoutTransition(vm, vm.propertyNames->SyntaxError, m_syntaxErrorConstructor.get(), DontEnum);
450     putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
451     putDirectWithoutTransition(vm, vm.propertyNames->URIError, m_URIErrorConstructor.get(), DontEnum);
452     
453     
454 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
455 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
456
457     FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
458
459 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
460     PrototypeMap& prototypeMap = vm.prototypeMap;
461     Structure* iteratorResultStructure = prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity());
462     PropertyOffset offset;
463     iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->done, 0, offset);
464     iteratorResultStructure = Structure::addPropertyTransition(vm, iteratorResultStructure, vm.propertyNames->value, 0, offset);
465     m_iteratorResultStructure.set(vm, this, iteratorResultStructure);
466     
467     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
468     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
469     
470 #if ENABLE(INTL)
471     IntlObject* intl = IntlObject::create(vm, this, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
472     putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, DontEnum);
473 #endif // ENABLE(INTL)
474     putDirectWithoutTransition(vm, vm.propertyNames->JSON, JSONObject::create(vm, JSONObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
475     putDirectWithoutTransition(vm, vm.propertyNames->Math, MathObject::create(vm, this, MathObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
476     putDirectWithoutTransition(vm, vm.propertyNames->Reflect, ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum);
477
478     JSTypedArrayViewConstructor* typedArraySuperConstructor = JSTypedArrayViewConstructor::create(vm, this, JSTypedArrayViewConstructor::createStructure(vm, this, m_functionPrototype.get()), typedArrayProto);
479     typedArrayProto->putDirectWithoutTransition(vm, vm.propertyNames->constructor, typedArraySuperConstructor, DontEnum);
480
481     std::array<InternalFunction*, NUMBER_OF_TYPED_ARRAY_TYPES> typedArrayConstructors;
482     typedArrayConstructors[toIndex(TypeInt8)] = JSInt8ArrayConstructor::create(vm, this, JSInt8ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeInt8)].prototype.get(), ASCIILiteral("Int8Array"), typedArrayConstructorAllocateInt8ArrayCodeGenerator(vm));
483     typedArrayConstructors[toIndex(TypeInt16)] = JSInt16ArrayConstructor::create(vm, this, JSInt16ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeInt16)].prototype.get(), ASCIILiteral("Int16Array"), typedArrayConstructorAllocateInt16ArrayCodeGenerator(vm));
484     typedArrayConstructors[toIndex(TypeInt32)] = JSInt32ArrayConstructor::create(vm, this, JSInt32ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeInt32)].prototype.get(), ASCIILiteral("Int32Array"), typedArrayConstructorAllocateInt32ArrayCodeGenerator(vm));
485     typedArrayConstructors[toIndex(TypeUint8)] = JSUint8ArrayConstructor::create(vm, this, JSUint8ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeUint8)].prototype.get(), ASCIILiteral("Uint8Array"), typedArrayConstructorAllocateUint8ArrayCodeGenerator(vm));
486     typedArrayConstructors[toIndex(TypeUint8Clamped)] = JSUint8ClampedArrayConstructor::create(vm, this, JSUint8ClampedArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeUint8Clamped)].prototype.get(), ASCIILiteral("Uint8ClampedArray"), typedArrayConstructorAllocateUint8ClampedArrayCodeGenerator(vm));
487     typedArrayConstructors[toIndex(TypeUint16)] = JSUint16ArrayConstructor::create(vm, this, JSUint16ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeUint16)].prototype.get(), ASCIILiteral("Uint16Array"), typedArrayConstructorAllocateUint16ArrayCodeGenerator(vm));
488     typedArrayConstructors[toIndex(TypeUint32)] = JSUint32ArrayConstructor::create(vm, this, JSUint32ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeUint32)].prototype.get(), ASCIILiteral("Uint32Array"), typedArrayConstructorAllocateUint32ArrayCodeGenerator(vm));
489     typedArrayConstructors[toIndex(TypeFloat32)] = JSFloat32ArrayConstructor::create(vm, this, JSFloat32ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeFloat32)].prototype.get(), ASCIILiteral("Float32Array"), typedArrayConstructorAllocateFloat32ArrayCodeGenerator(vm));
490     typedArrayConstructors[toIndex(TypeFloat64)] = JSFloat64ArrayConstructor::create(vm, this, JSFloat64ArrayConstructor::createStructure(vm, this, typedArraySuperConstructor), m_typedArrays[toIndex(TypeFloat64)].prototype.get(), ASCIILiteral("Float64Array"), typedArrayConstructorAllocateFloat64ArrayCodeGenerator(vm));
491     typedArrayConstructors[toIndex(TypeDataView)] = JSDataViewConstructor::create(vm, this, JSDataViewConstructor::createStructure(vm, this, m_functionPrototype.get()), m_typedArrays[toIndex(TypeDataView)].prototype.get(), ASCIILiteral("DataView"), nullptr);
492     
493     for (unsigned typedArrayIndex = NUMBER_OF_TYPED_ARRAY_TYPES; typedArrayIndex--;) {
494         m_typedArrays[typedArrayIndex].prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, typedArrayConstructors[typedArrayIndex], DontEnum);
495         putDirectWithoutTransition(vm, Identifier::fromString(exec, typedArrayConstructors[typedArrayIndex]->name(exec)), typedArrayConstructors[typedArrayIndex], DontEnum);
496     }
497
498     putDirectWithoutTransition(vm, vm.propertyNames->Int8ArrayPrivateName, typedArrayConstructors[toIndex(TypeInt8)], DontEnum);
499     putDirectWithoutTransition(vm, vm.propertyNames->Int16ArrayPrivateName, typedArrayConstructors[toIndex(TypeInt16)], DontEnum);
500     putDirectWithoutTransition(vm, vm.propertyNames->Int32ArrayPrivateName, typedArrayConstructors[toIndex(TypeInt32)], DontEnum);
501     putDirectWithoutTransition(vm, vm.propertyNames->Uint8ArrayPrivateName, typedArrayConstructors[toIndex(TypeUint8)], DontEnum);
502     putDirectWithoutTransition(vm, vm.propertyNames->Uint8ClampedArrayPrivateName, typedArrayConstructors[toIndex(TypeUint8Clamped)], DontEnum);
503     putDirectWithoutTransition(vm, vm.propertyNames->Uint16ArrayPrivateName, typedArrayConstructors[toIndex(TypeUint16)], DontEnum);
504     putDirectWithoutTransition(vm, vm.propertyNames->Uint32ArrayPrivateName, typedArrayConstructors[toIndex(TypeUint32)], DontEnum);
505     putDirectWithoutTransition(vm, vm.propertyNames->Float32ArrayPrivateName, typedArrayConstructors[toIndex(TypeFloat32)], DontEnum);
506     putDirectWithoutTransition(vm, vm.propertyNames->Float64ArrayPrivateName, typedArrayConstructors[toIndex(TypeFloat64)], DontEnum);
507
508     m_moduleLoader.set(vm, this, ModuleLoaderObject::create(vm, this, ModuleLoaderObject::createStructure(vm, this, m_objectPrototype.get())));
509     if (Options::exposeInternalModuleLoader())
510         putDirectWithoutTransition(vm, vm.propertyNames->Loader, m_moduleLoader.get(), DontEnum);
511
512     JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
513
514     JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
515     JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
516     JSFunction* privateFuncIsFinite = JSFunction::create(vm, this, 0, String(), globalFuncIsFinite);
517     JSFunction* privateFuncIsNaN = JSFunction::create(vm, this, 0, String(), globalFuncIsNaN);
518
519     JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject);
520     JSFunction* privateFuncToLength = JSFunction::createBuiltinFunction(vm, globalObjectToLengthCodeGenerator(vm), this);
521     JSFunction* privateFuncToInteger = JSFunction::createBuiltinFunction(vm, globalObjectToIntegerCodeGenerator(vm), this);
522     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
523     JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
524
525     GlobalPropertyInfo staticGlobals[] = {
526         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
527         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
528         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
529         GlobalPropertyInfo(vm.propertyNames->undefinedPrivateName, jsUndefined(), DontEnum | DontDelete | ReadOnly),
530         GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
531         GlobalPropertyInfo(vm.propertyNames->ownEnumerablePropertyKeysPrivateName, JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly),
532         GlobalPropertyInfo(vm.propertyNames->getTemplateObjectPrivateName, privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly),
533         GlobalPropertyInfo(vm.propertyNames->enqueueJobPrivateName, JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
534         GlobalPropertyInfo(vm.propertyNames->RangeErrorPrivateName, m_rangeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
535         GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
536         GlobalPropertyInfo(vm.propertyNames->typedArrayLengthPrivateName, privateFuncTypedArrayLength, DontEnum | DontDelete | ReadOnly),
537         GlobalPropertyInfo(vm.propertyNames->typedArraySortPrivateName, privateFuncTypedArraySort, DontEnum | DontDelete | ReadOnly),
538         GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
539         GlobalPropertyInfo(vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly),
540         GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
541         GlobalPropertyInfo(vm.propertyNames->StringPrivateName, stringConstructor, DontEnum | DontDelete | ReadOnly),
542         GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
543         GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
544         GlobalPropertyInfo(vm.propertyNames->isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly),
545         GlobalPropertyInfo(vm.propertyNames->isNaNPrivateName, privateFuncIsNaN, DontEnum | DontDelete | ReadOnly),
546         GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyPrivateName, jsNumber(ArrayIterateKey), DontEnum | DontDelete | ReadOnly),
547         GlobalPropertyInfo(vm.propertyNames->arrayIterationKindValuePrivateName, jsNumber(ArrayIterateValue), DontEnum | DontDelete | ReadOnly),
548         GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyValuePrivateName, jsNumber(ArrayIterateKeyValue), DontEnum | DontDelete | ReadOnly),
549         GlobalPropertyInfo(vm.propertyNames->builtinNames().symbolIteratorPrivateName(), Symbol::create(vm, static_cast<SymbolImpl&>(*vm.propertyNames->iteratorSymbol.impl())), DontEnum | DontDelete | ReadOnly),
550         GlobalPropertyInfo(vm.propertyNames->PromisePrivateName, promiseConstructor, DontEnum | DontDelete | ReadOnly),
551         GlobalPropertyInfo(vm.propertyNames->InternalPromisePrivateName, internalPromiseConstructor, DontEnum | DontDelete | ReadOnly),
552         GlobalPropertyInfo(vm.propertyNames->promisePendingPrivateName, jsNumber(static_cast<unsigned>(JSPromise::Status::Pending)), DontEnum | DontDelete | ReadOnly),
553         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseFulfilledPrivateName(), jsNumber(static_cast<unsigned>(JSPromise::Status::Fulfilled)), DontEnum | DontDelete | ReadOnly),
554         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseRejectedPrivateName(), jsNumber(static_cast<unsigned>(JSPromise::Status::Rejected)), DontEnum | DontDelete | ReadOnly),
555         GlobalPropertyInfo(vm.propertyNames->builtinNames().toLengthPrivateName(), privateFuncToLength, DontEnum | DontDelete | ReadOnly),
556         GlobalPropertyInfo(vm.propertyNames->builtinNames().toIntegerPrivateName(), privateFuncToInteger, DontEnum | DontDelete | ReadOnly),
557         GlobalPropertyInfo(vm.propertyNames->builtinNames().isObjectPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectIsObjectCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
558         GlobalPropertyInfo(vm.propertyNames->builtinNames().isDictionaryPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectIsDictionaryCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
559         GlobalPropertyInfo(vm.propertyNames->builtinNames().isPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsIsPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
560         GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseReactionPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseReactionCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
561         GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseCapabilityPrivateName(), m_newPromiseCapabilityFunction.get(), DontEnum | DontDelete | ReadOnly),
562         GlobalPropertyInfo(vm.propertyNames->builtinNames().triggerPromiseReactionsPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsTriggerPromiseReactionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
563         GlobalPropertyInfo(vm.propertyNames->builtinNames().rejectPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsRejectPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
564         GlobalPropertyInfo(vm.propertyNames->builtinNames().fulfillPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsFulfillPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
565         GlobalPropertyInfo(vm.propertyNames->builtinNames().createResolvingFunctionsPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsCreateResolvingFunctionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
566         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseReactionJobPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsPromiseReactionJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
567         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseResolveThenableJobPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsPromiseResolveThenableJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
568         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum | DontDelete | ReadOnly),
569         GlobalPropertyInfo(vm.propertyNames->MapPrivateName, mapConstructor, DontEnum | DontDelete | ReadOnly),
570         GlobalPropertyInfo(vm.propertyNames->builtinNames().generatorResumePrivateName(), JSFunction::createBuiltinFunction(vm, generatorPrototypeGeneratorResumeCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
571 #if ENABLE(INTL)
572         GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), DontEnum | DontDelete | ReadOnly),
573         GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),
574         GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), DontEnum | DontDelete | ReadOnly),
575 #endif // ENABLE(INTL)
576     };
577     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
578     
579     m_specialPointers[Special::CallFunction] = m_callFunction.get();
580     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
581     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
582     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
583
584     m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::DefinePropertyFunction)] = m_definePropertyFunction.get();
585
586     ConsolePrototype* consolePrototype = ConsolePrototype::create(vm, this, ConsolePrototype::createStructure(vm, this, m_objectPrototype.get()));
587     m_consoleStructure.set(vm, this, JSConsole::createStructure(vm, this, consolePrototype));
588     JSConsole* consoleObject = JSConsole::create(vm, m_consoleStructure.get());
589     putDirectWithoutTransition(vm, Identifier::fromString(exec, "console"), consoleObject, DontEnum);
590
591     if (UNLIKELY(Options::useDollarVM())) {
592         JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get()));
593         m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype));
594         JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
595         putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum);
596     }
597
598     resetPrototype(vm, prototype());
599 }
600
601 void JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
602 {
603     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
604     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
605
606     bool shouldThrowReadOnlyError = slot.isStrictMode();
607     bool ignoreReadOnlyErrors = false;
608     if (symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors))
609         return;
610     Base::put(thisObject, exec, propertyName, value, slot);
611 }
612
613 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
614 {
615     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
616     PropertySlot slot(thisObject);
617     // silently ignore attempts to add accessors aliasing vars.
618     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
619         return false;
620     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
621 }
622
623 void JSGlobalObject::addGlobalVar(const Identifier& ident)
624 {
625     ConcurrentJITLocker locker(symbolTable()->m_lock);
626     SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
627     if (!entry.isNull())
628         return;
629     
630     ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
631     SymbolTableEntry newEntry(VarOffset(offset), 0);
632     newEntry.prepareToWatch();
633     symbolTable()->add(locker, ident.impl(), newEntry);
634     
635     ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
636     RELEASE_ASSERT(offsetForAssert == offset);
637 }
638
639 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
640 {
641     VM& vm = exec->vm();
642     removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties.
643     addGlobalVar(propertyName);
644 }
645
646 static inline JSObject* lastInPrototypeChain(JSObject* object)
647 {
648     JSObject* o = object;
649     while (o->prototype().isObject())
650         o = asObject(o->prototype());
651     return o;
652 }
653
654 // Private namespace for helpers for JSGlobalObject::haveABadTime()
655 namespace {
656
657 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
658 public:
659     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
660     IterationStatus operator()(JSCell*);
661
662 private:
663     void visit(JSCell*);
664
665     MarkedArgumentBuffer& m_foundObjects;
666     JSGlobalObject* m_globalObject;
667 };
668
669 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
670     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
671     : m_foundObjects(foundObjects)
672     , m_globalObject(globalObject)
673 {
674 }
675
676 inline bool hasBrokenIndexing(JSObject* object)
677 {
678     // This will change if we have more indexing types.
679     IndexingType type = object->indexingType();
680     // This could be made obviously more efficient, but isn't made so right now, because
681     // we expect this to be an unlikely slow path anyway.
682     return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
683 }
684
685 inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
686 {
687     if (!cell->isObject())
688         return;
689     
690     JSObject* object = asObject(cell);
691
692     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
693     if (!hasBrokenIndexing(object))
694         return;
695     
696     // We only want to have a bad time in the affected global object, not in the entire
697     // VM. But we have to be careful, since there may be objects that claim to belong to
698     // a different global object that have prototypes from our global object.
699     bool foundGlobalObject = false;
700     for (JSObject* current = object; ;) {
701         if (current->globalObject() == m_globalObject) {
702             foundGlobalObject = true;
703             break;
704         }
705         
706         JSValue prototypeValue = current->prototype();
707         if (prototypeValue.isNull())
708             break;
709         current = asObject(prototypeValue);
710     }
711     if (!foundGlobalObject)
712         return;
713     
714     m_foundObjects.append(object);
715 }
716
717 IterationStatus ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
718 {
719     visit(cell);
720     return IterationStatus::Continue;
721 }
722
723 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
724
725 void JSGlobalObject::haveABadTime(VM& vm)
726 {
727     ASSERT(&vm == &this->vm());
728     
729     if (isHavingABadTime())
730         return;
731     
732     // Make sure that all allocations or indexed storage transitions that are inlining
733     // the assumption that it's safe to transition to a non-SlowPut array storage don't
734     // do so anymore.
735     m_havingABadTimeWatchpoint->fireAll("Having a bad time");
736     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
737     
738     // Make sure that all JSArray allocations that load the appropriate structure from
739     // this object now load a structure that uses SlowPut.
740     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
741         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
742     
743     // Make sure that all objects that have indexed storage switch to the slow kind of
744     // indexed storage.
745     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
746     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
747     {
748         HeapIterationScope iterationScope(vm.heap);
749         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
750     }
751     while (!foundObjects.isEmpty()) {
752         JSObject* object = asObject(foundObjects.last());
753         foundObjects.removeLast();
754         ASSERT(hasBrokenIndexing(object));
755         object->switchToSlowPutArrayStorage(vm);
756     }
757 }
758
759 bool JSGlobalObject::objectPrototypeIsSane()
760 {
761     return !hasIndexedProperties(m_objectPrototype->indexingType())
762         && m_objectPrototype->prototype().isNull();
763 }
764
765 bool JSGlobalObject::arrayPrototypeChainIsSane()
766 {
767     return !hasIndexedProperties(m_arrayPrototype->indexingType())
768         && m_arrayPrototype->prototype() == m_objectPrototype.get()
769         && objectPrototypeIsSane();
770 }
771
772 bool JSGlobalObject::stringPrototypeChainIsSane()
773 {
774     return !hasIndexedProperties(m_stringPrototype->indexingType())
775         && m_stringPrototype->prototype() == m_objectPrototype.get()
776         && objectPrototypeIsSane();
777 }
778
779 void JSGlobalObject::createThrowTypeError(VM& vm)
780 {
781     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
782     GetterSetter* getterSetter = GetterSetter::create(vm, this);
783     getterSetter->setGetter(vm, this, thrower);
784     getterSetter->setSetter(vm, this, thrower);
785     m_throwTypeErrorGetterSetter.set(vm, this, getterSetter);
786 }
787
788 // Set prototype, and also insert the object prototype at the end of the chain.
789 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
790 {
791     setPrototype(vm, prototype);
792
793     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
794     JSObject* objectPrototype = m_objectPrototype.get();
795     if (oldLastInPrototypeChain != objectPrototype)
796         oldLastInPrototypeChain->setPrototype(vm, objectPrototype);
797
798     // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
799     setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
800 }
801
802 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
803
804     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
805     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
806     Base::visitChildren(thisObject, visitor);
807
808     visitor.append(&thisObject->m_globalThis);
809
810     visitor.append(&thisObject->m_globalLexicalEnvironment);
811     visitor.append(&thisObject->m_globalCallee);
812     visitor.append(&thisObject->m_regExpConstructor);
813     visitor.append(&thisObject->m_errorConstructor);
814     visitor.append(&thisObject->m_evalErrorConstructor);
815     visitor.append(&thisObject->m_rangeErrorConstructor);
816     visitor.append(&thisObject->m_referenceErrorConstructor);
817     visitor.append(&thisObject->m_syntaxErrorConstructor);
818     visitor.append(&thisObject->m_typeErrorConstructor);
819     visitor.append(&thisObject->m_URIErrorConstructor);
820     visitor.append(&thisObject->m_objectConstructor);
821     visitor.append(&thisObject->m_promiseConstructor);
822     visitor.append(&thisObject->m_internalPromiseConstructor);
823
824     visitor.append(&thisObject->m_nullGetterFunction);
825     visitor.append(&thisObject->m_nullSetterFunction);
826
827     visitor.append(&thisObject->m_parseIntFunction);
828     visitor.append(&thisObject->m_evalFunction);
829     visitor.append(&thisObject->m_callFunction);
830     visitor.append(&thisObject->m_applyFunction);
831     visitor.append(&thisObject->m_definePropertyFunction);
832     visitor.append(&thisObject->m_arrayProtoValuesFunction);
833     visitor.append(&thisObject->m_initializePromiseFunction);
834     visitor.append(&thisObject->m_newPromiseCapabilityFunction);
835     visitor.append(&thisObject->m_throwTypeErrorGetterSetter);
836     visitor.append(&thisObject->m_moduleLoader);
837
838     visitor.append(&thisObject->m_objectPrototype);
839     visitor.append(&thisObject->m_functionPrototype);
840     visitor.append(&thisObject->m_arrayPrototype);
841     visitor.append(&thisObject->m_errorPrototype);
842     visitor.append(&thisObject->m_iteratorPrototype);
843     visitor.append(&thisObject->m_generatorFunctionPrototype);
844     visitor.append(&thisObject->m_generatorPrototype);
845
846     visitor.append(&thisObject->m_debuggerScopeStructure);
847     visitor.append(&thisObject->m_withScopeStructure);
848     visitor.append(&thisObject->m_strictEvalActivationStructure);
849     visitor.append(&thisObject->m_lexicalEnvironmentStructure);
850     visitor.append(&thisObject->m_moduleEnvironmentStructure);
851     visitor.append(&thisObject->m_directArgumentsStructure);
852     visitor.append(&thisObject->m_scopedArgumentsStructure);
853     visitor.append(&thisObject->m_outOfBandArgumentsStructure);
854     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
855         visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
856     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
857         visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
858     visitor.append(&thisObject->m_booleanObjectStructure);
859     visitor.append(&thisObject->m_callbackConstructorStructure);
860     visitor.append(&thisObject->m_callbackFunctionStructure);
861     visitor.append(&thisObject->m_callbackObjectStructure);
862     visitor.append(&thisObject->m_propertyNameIteratorStructure);
863 #if JSC_OBJC_API_ENABLED
864     visitor.append(&thisObject->m_objcCallbackFunctionStructure);
865     visitor.append(&thisObject->m_objcWrapperObjectStructure);
866 #endif
867     visitor.append(&thisObject->m_nullPrototypeObjectStructure);
868     visitor.append(&thisObject->m_errorStructure);
869     visitor.append(&thisObject->m_calleeStructure);
870     visitor.append(&thisObject->m_functionStructure);
871     visitor.append(&thisObject->m_boundFunctionStructure);
872     visitor.append(&thisObject->m_arrowFunctionStructure);
873     visitor.append(&thisObject->m_nativeStdFunctionStructure);
874     visitor.append(&thisObject->m_namedFunctionStructure);
875     visitor.append(&thisObject->m_symbolObjectStructure);
876     visitor.append(&thisObject->m_regExpStructure);
877     visitor.append(&thisObject->m_generatorFunctionStructure);
878     visitor.append(&thisObject->m_regExpMatchesArrayStructure);
879     visitor.append(&thisObject->m_moduleRecordStructure);
880     visitor.append(&thisObject->m_moduleNamespaceObjectStructure);
881     visitor.append(&thisObject->m_consoleStructure);
882     visitor.append(&thisObject->m_dollarVMStructure);
883     visitor.append(&thisObject->m_internalFunctionStructure);
884 #if ENABLE(WEBASSEMBLY)
885     visitor.append(&thisObject->m_wasmModuleStructure);
886 #endif
887
888 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
889     visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
890     visitor.append(&thisObject->m_ ## properName ## Structure); \
891
892     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
893     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
894
895 #undef VISIT_SIMPLE_TYPE
896
897     for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;) {
898         visitor.append(&thisObject->m_typedArrays[i].prototype);
899         visitor.append(&thisObject->m_typedArrays[i].structure);
900     }
901 }
902
903 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
904 {
905     if (ecmaMode == StrictMode)
906         return jsUndefined();
907     return exec->globalThisValue();
908 }
909
910 ExecState* JSGlobalObject::globalExec()
911 {
912     return CallFrame::create(m_globalCallFrame);
913 }
914
915 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
916 {
917     ScopeOffset startOffset = addVariables(count, jsUndefined());
918
919     for (int i = 0; i < count; ++i) {
920         GlobalPropertyInfo& global = globals[i];
921         ASSERT(global.attributes & DontDelete);
922         
923         ScopeOffset offset;
924         {
925             ConcurrentJITLocker locker(symbolTable()->m_lock);
926             offset = symbolTable()->takeNextScopeOffset(locker);
927             RELEASE_ASSERT(offset = startOffset + i);
928             SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
929             symbolTable()->add(locker, global.identifier.impl(), newEntry);
930         }
931         variableAt(offset).set(vm(), this, global.value);
932     }
933 }
934
935 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
936 {
937     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
938     if (getStaticFunctionSlot<Base>(exec, globalObjectTable, thisObject, propertyName, slot))
939         return true;
940     return symbolTableGet(thisObject, propertyName, slot);
941 }
942
943 void JSGlobalObject::clearRareData(JSCell* cell)
944 {
945     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
946 }
947
948 void slowValidateCell(JSGlobalObject* globalObject)
949 {
950     RELEASE_ASSERT(globalObject->isGlobalObject());
951     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
952 }
953
954 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
955 {
956     ParserError error;
957     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
958     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
959     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
960     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(
961         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, 
962         debuggerMode, profilerMode, error);
963
964     if (hasDebugger())
965         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
966
967     if (error.isValid()) {
968         *exception = error.toErrorObject(this, executable->source());
969         return nullptr;
970     }
971     
972     return unlinkedCodeBlock;
973 }
974
975 UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable, ThisTDZMode thisTDZMode, bool isArrowFunctionContext, const VariableEnvironment* variablesUnderTDZ)
976 {
977     ParserError error;
978     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
979     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
980     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
981     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(
982         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, isArrowFunctionContext, debuggerMode, profilerMode, error, variablesUnderTDZ);
983
984     if (hasDebugger())
985         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
986
987     if (error.isValid()) {
988         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
989         return nullptr;
990     }
991
992     return unlinkedCodeBlock;
993 }
994
995 UnlinkedModuleProgramCodeBlock* JSGlobalObject::createModuleProgramCodeBlock(CallFrame* callFrame, ModuleProgramExecutable* executable)
996 {
997     ParserError error;
998     DebuggerMode debuggerMode = hasDebugger() ? DebuggerOn : DebuggerOff;
999     ProfilerMode profilerMode = hasProfiler() ? ProfilerOn : ProfilerOff;
1000     UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getModuleProgramCodeBlock(
1001         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, debuggerMode, profilerMode, error);
1002
1003     if (hasDebugger())
1004         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1005
1006     if (error.isValid()) {
1007         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
1008         return nullptr;
1009     }
1010
1011     return unlinkedCodeBlock;
1012 }
1013
1014 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1015 {
1016 #if ENABLE(REMOTE_INSPECTOR)
1017     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1018 #else
1019     UNUSED_PARAM(enabled);
1020 #endif
1021 }
1022
1023 bool JSGlobalObject::remoteDebuggingEnabled() const
1024 {
1025 #if ENABLE(REMOTE_INSPECTOR)
1026     return m_inspectorDebuggable->remoteDebuggingAllowed();
1027 #else
1028     return false;
1029 #endif
1030 }
1031
1032 #if ENABLE(WEB_REPLAY)
1033 void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
1034 {
1035     m_inputCursor = prpCursor;
1036     ASSERT(m_inputCursor);
1037
1038     InputCursor& cursor = inputCursor();
1039     // Save or set the random seed. This performed here rather than the constructor
1040     // to avoid threading the input cursor through all the abstraction layers.
1041     if (cursor.isCapturing())
1042         cursor.appendInput<SetRandomSeed>(m_weakRandom.seed());
1043     else if (cursor.isReplaying()) {
1044         if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
1045             m_weakRandom.setSeed(static_cast<unsigned>(input->randomSeed()));
1046     }
1047 }
1048 #endif
1049
1050 void JSGlobalObject::setName(const String& name)
1051 {
1052     m_name = name;
1053
1054 #if ENABLE(REMOTE_INSPECTOR)
1055     m_inspectorDebuggable->update();
1056 #endif
1057 }
1058
1059 # if ENABLE(INTL)
1060 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1061 {
1062     if (m_intlCollatorAvailableLocales.isEmpty()) {
1063         int32_t count = ucol_countAvailable();
1064         for (int32_t i = 0; i < count; ++i) {
1065             String locale(ucol_getAvailable(i));
1066             // Change from ICU format to BCP47.
1067             locale.replace('_', '-');
1068             m_intlCollatorAvailableLocales.add(locale);
1069         }
1070     }
1071     return m_intlCollatorAvailableLocales;
1072 }
1073
1074 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1075 {
1076     if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1077         int32_t count = udat_countAvailable();
1078         for (int32_t i = 0; i < count; ++i) {
1079             String locale(udat_getAvailable(i));
1080             // Change from ICU format to BCP47.
1081             locale.replace('_', '-');
1082             m_intlDateTimeFormatAvailableLocales.add(locale);
1083         }
1084     }
1085     return m_intlDateTimeFormatAvailableLocales;
1086 }
1087
1088 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1089 {
1090     if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1091         int32_t count = unum_countAvailable();
1092         for (int32_t i = 0; i < count; ++i) {
1093             String locale(unum_getAvailable(i));
1094             // Change from ICU format to BCP47.
1095             locale.replace('_', '-');
1096             m_intlNumberFormatAvailableLocales.add(locale);
1097         }
1098     }
1099     return m_intlNumberFormatAvailableLocales;
1100 }
1101 #endif // ENABLE(INTL)
1102
1103 void JSGlobalObject::queueMicrotask(PassRefPtr<Microtask> task)
1104 {
1105     if (globalObjectMethodTable()->queueTaskToEventLoop) {
1106         globalObjectMethodTable()->queueTaskToEventLoop(this, task);
1107         return;
1108     }
1109
1110     vm().queueMicrotask(this, task);
1111 }
1112
1113 } // namespace JSC