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