a91abd7bc36a6f3a894cb2f357d4d4a8c77bedbb
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007-2019 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 "AsyncFromSyncIteratorPrototype.h"
37 #include "AtomicsObject.h"
38 #include "AsyncFunctionConstructor.h"
39 #include "AsyncFunctionPrototype.h"
40 #include "AsyncGeneratorFunctionConstructor.h"
41 #include "AsyncGeneratorFunctionPrototype.h"
42 #include "AsyncGeneratorPrototype.h"
43 #include "AsyncIteratorPrototype.h"
44 #include "BigIntConstructor.h"
45 #include "BigIntObject.h"
46 #include "BigIntPrototype.h"
47 #include "BooleanConstructor.h"
48 #include "BooleanPrototype.h"
49 #include "BuiltinNames.h"
50 #include "CatchScope.h"
51 #include "ClonedArguments.h"
52 #include "CodeBlock.h"
53 #include "CodeBlockSetInlines.h"
54 #include "CodeCache.h"
55 #include "ConsoleObject.h"
56 #include "DateConstructor.h"
57 #include "DatePrototype.h"
58 #include "Debugger.h"
59 #include "DebuggerScope.h"
60 #include "DirectArguments.h"
61 #include "DirectEvalExecutable.h"
62 #include "ECMAScriptSpecInternalFunctions.h"
63 #include "Error.h"
64 #include "ErrorConstructor.h"
65 #include "ErrorPrototype.h"
66 #include "Exception.h"
67 #include "FunctionConstructor.h"
68 #include "FunctionPrototype.h"
69 #include "GeneratorFunctionConstructor.h"
70 #include "GeneratorFunctionPrototype.h"
71 #include "GeneratorPrototype.h"
72 #include "GetterSetter.h"
73 #include "HeapIterationScope.h"
74 #include "IndirectEvalExecutable.h"
75 #include "InspectorInstrumentationObject.h"
76 #include "Interpreter.h"
77 #include "IteratorPrototype.h"
78 #include "JSAPIWrapperObject.h"
79 #include "JSArrayBuffer.h"
80 #include "JSArrayBufferConstructor.h"
81 #include "JSArrayBufferPrototype.h"
82 #include "JSAsyncFunction.h"
83 #include "JSAsyncGeneratorFunction.h"
84 #include "JSBigInt.h"
85 #include "JSBoundFunction.h"
86 #include "JSCInlines.h"
87 #include "JSCallbackConstructor.h"
88 #include "JSCallbackFunction.h"
89 #include "JSCallbackObject.h"
90 #include "JSCustomGetterSetterFunction.h"
91 #include "JSDataView.h"
92 #include "JSDataViewPrototype.h"
93 #include "JSDollarVM.h"
94 #include "JSFunction.h"
95 #include "JSGeneratorFunction.h"
96 #include "JSGenericTypedArrayViewConstructorInlines.h"
97 #include "JSGenericTypedArrayViewInlines.h"
98 #include "JSGenericTypedArrayViewPrototypeInlines.h"
99 #include "JSGlobalObjectFunctions.h"
100 #include "JSInternalPromise.h"
101 #include "JSInternalPromiseConstructor.h"
102 #include "JSInternalPromisePrototype.h"
103 #include "JSLexicalEnvironment.h"
104 #include "JSLock.h"
105 #include "JSMap.h"
106 #include "JSMicrotask.h"
107 #include "JSModuleEnvironment.h"
108 #include "JSModuleLoader.h"
109 #include "JSModuleNamespaceObject.h"
110 #include "JSModuleRecord.h"
111 #include "JSNativeStdFunction.h"
112 #include "JSNonDestructibleProxy.h"
113 #include "JSONObject.h"
114 #include "JSPromise.h"
115 #include "JSPromiseConstructor.h"
116 #include "JSPromisePrototype.h"
117 #include "JSSet.h"
118 #include "JSStringIterator.h"
119 #include "JSTypedArrayConstructors.h"
120 #include "JSTypedArrayPrototypes.h"
121 #include "JSTypedArrayViewConstructor.h"
122 #include "JSTypedArrayViewPrototype.h"
123 #include "JSTypedArrays.h"
124 #include "JSWeakMap.h"
125 #include "JSWeakSet.h"
126 #include "JSWebAssembly.h"
127 #include "JSWithScope.h"
128 #include "LazyClassStructureInlines.h"
129 #include "LazyPropertyInlines.h"
130 #include "Lookup.h"
131 #include "MapConstructor.h"
132 #include "MapIteratorPrototype.h"
133 #include "MapPrototype.h"
134 #include "MarkedSpaceInlines.h"
135 #include "MathObject.h"
136 #include "Microtask.h"
137 #include "NativeErrorConstructor.h"
138 #include "NativeErrorPrototype.h"
139 #include "NullGetterFunction.h"
140 #include "NullSetterFunction.h"
141 #include "NumberConstructor.h"
142 #include "NumberPrototype.h"
143 #include "ObjCCallbackFunction.h"
144 #include "ObjectConstructor.h"
145 #include "ObjectPropertyChangeAdaptiveWatchpoint.h"
146 #include "ObjectPropertyConditionSet.h"
147 #include "ObjectPrototype.h"
148 #include "ParserError.h"
149 #include "ProxyConstructor.h"
150 #include "ProxyObject.h"
151 #include "ProxyRevoke.h"
152 #include "ReflectObject.h"
153 #include "RegExpCache.h"
154 #include "RegExpConstructor.h"
155 #include "RegExpMatchesArray.h"
156 #include "RegExpObject.h"
157 #include "RegExpPrototype.h"
158 #include "ScopedArguments.h"
159 #include "SetConstructor.h"
160 #include "SetIteratorPrototype.h"
161 #include "SetPrototype.h"
162 #include "StrictEvalActivation.h"
163 #include "StringConstructor.h"
164 #include "StringIteratorPrototype.h"
165 #include "StringPrototype.h"
166 #include "Symbol.h"
167 #include "SymbolConstructor.h"
168 #include "SymbolObject.h"
169 #include "SymbolPrototype.h"
170 #include "VariableWriteFireDetail.h"
171 #include "WeakGCMapInlines.h"
172 #include "WeakMapConstructor.h"
173 #include "WeakMapPrototype.h"
174 #include "WeakSetConstructor.h"
175 #include "WeakSetPrototype.h"
176 #include "WebAssemblyPrototype.h"
177 #include "WebAssemblyToJSCallee.h"
178 #include <wtf/RandomNumber.h>
179
180 #if ENABLE(INTL)
181 #include "IntlObject.h"
182 #include <unicode/ucol.h>
183 #include <unicode/udat.h>
184 #include <unicode/unum.h>
185 #endif // ENABLE(INTL)
186
187 #if ENABLE(REMOTE_INSPECTOR)
188 #include "JSGlobalObjectDebuggable.h"
189 #include "JSGlobalObjectInspectorController.h"
190 #endif
191
192 #ifdef JSC_GLIB_API_ENABLED
193 #include "JSCCallbackFunction.h"
194 #include "JSCWrapperMap.h"
195 #endif
196
197 namespace JSC {
198
199 static JSValue createProxyProperty(VM& vm, JSObject* object)
200 {
201     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
202     return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
203 }
204
205 static JSValue createJSONProperty(VM& vm, JSObject* object)
206 {
207     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
208     return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
209 }
210
211 static JSValue createMathProperty(VM& vm, JSObject* object)
212 {
213     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
214     return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
215 }
216
217 static JSValue createConsoleProperty(VM& vm, JSObject* object)
218 {
219     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
220     return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
221 }
222
223 static EncodedJSValue JSC_HOST_CALL makeBoundFunction(ExecState* exec)
224 {
225     VM& vm = exec->vm();
226     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
227
228     JSObject* target = asObject(exec->uncheckedArgument(0));
229     JSValue boundThis = exec->uncheckedArgument(1);
230     JSValue boundArgs = exec->uncheckedArgument(2);
231     JSValue length = exec->uncheckedArgument(3);
232     JSString* name = asString(exec->uncheckedArgument(4));
233
234     return JSValue::encode(JSBoundFunction::create(
235         vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length.asInt32(), name->value(exec)));
236 }
237
238 static EncodedJSValue JSC_HOST_CALL hasOwnLengthProperty(ExecState* exec)
239 {
240     VM& vm = exec->vm();
241     JSObject* target = asObject(exec->uncheckedArgument(0));
242     return JSValue::encode(jsBoolean(target->hasOwnProperty(exec, vm.propertyNames->length)));
243 }
244
245 #if !ASSERT_DISABLED
246 static EncodedJSValue JSC_HOST_CALL assertCall(ExecState* exec)
247 {
248     RELEASE_ASSERT(exec->argument(0).isBoolean());
249     if (exec->argument(0).asBoolean())
250         return JSValue::encode(jsUndefined());
251
252     bool iteratedOnce = false;
253     CodeBlock* codeBlock = nullptr;
254     unsigned line;
255     exec->iterate([&] (StackVisitor& visitor) {
256         if (!iteratedOnce) {
257             iteratedOnce = true;
258             return StackVisitor::Continue;
259         }
260
261         RELEASE_ASSERT(visitor->hasLineAndColumnInfo());
262         unsigned column;
263         visitor->computeLineAndColumn(line, column);
264         codeBlock = visitor->codeBlock();
265         return StackVisitor::Done;
266     });
267     RELEASE_ASSERT(!!codeBlock);
268     RELEASE_ASSERT_WITH_MESSAGE(false, "JS assertion failed at line %u in:\n%s\n", line, codeBlock->sourceCodeForTools().data());
269     return JSValue::encode(jsUndefined());
270 }
271 #endif
272
273 } // namespace JSC
274
275 #include "JSGlobalObject.lut.h"
276
277 namespace JSC {
278
279 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, nullptr, CREATE_METHOD_TABLE(JSGlobalObject) };
280
281 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
282     &supportsRichSourceInfo,
283     &shouldInterruptScript,
284     &javaScriptRuntimeFlags,
285     nullptr, // queueTaskToEventLoop
286     &shouldInterruptScriptBeforeTimeout,
287     nullptr, // moduleLoaderImportModule
288     nullptr, // moduleLoaderResolve
289     nullptr, // moduleLoaderFetch
290     nullptr, // moduleLoaderCreateImportMetaProperties
291     nullptr, // moduleLoaderEvaluate
292     nullptr, // promiseRejectionTracker
293     nullptr, // defaultLanguage
294     nullptr, // compileStreaming
295     nullptr, // instantiateStreaming
296 };
297
298 /* Source for JSGlobalObject.lut.h
299 @begin globalObjectTable
300   isNaN                 JSBuiltin                                    DontEnum|Function 1
301   isFinite              JSBuiltin                                    DontEnum|Function 1
302   escape                globalFuncEscape                             DontEnum|Function 1
303   unescape              globalFuncUnescape                           DontEnum|Function 1
304   decodeURI             globalFuncDecodeURI                          DontEnum|Function 1
305   decodeURIComponent    globalFuncDecodeURIComponent                 DontEnum|Function 1
306   encodeURI             globalFuncEncodeURI                          DontEnum|Function 1
307   encodeURIComponent    globalFuncEncodeURIComponent                 DontEnum|Function 1
308   globalThis            JSGlobalObject::m_globalThis                 DontEnum|CellProperty
309   EvalError             JSGlobalObject::m_evalErrorStructure         DontEnum|ClassStructure
310   RangeError            JSGlobalObject::m_rangeErrorStructure        DontEnum|ClassStructure
311   ReferenceError        JSGlobalObject::m_referenceErrorStructure    DontEnum|ClassStructure
312   SyntaxError           JSGlobalObject::m_syntaxErrorStructure       DontEnum|ClassStructure
313   TypeError             JSGlobalObject::m_typeErrorStructure         DontEnum|ClassStructure
314   URIError              JSGlobalObject::m_URIErrorStructure          DontEnum|ClassStructure
315   Proxy                 createProxyProperty                          DontEnum|PropertyCallback
316   JSON                  createJSONProperty                           DontEnum|PropertyCallback
317   Math                  createMathProperty                           DontEnum|PropertyCallback
318   console               createConsoleProperty                        DontEnum|PropertyCallback
319   Int8Array             JSGlobalObject::m_typedArrayInt8             DontEnum|ClassStructure
320   Int16Array            JSGlobalObject::m_typedArrayInt16            DontEnum|ClassStructure
321   Int32Array            JSGlobalObject::m_typedArrayInt32            DontEnum|ClassStructure
322   Uint8Array            JSGlobalObject::m_typedArrayUint8            DontEnum|ClassStructure
323   Uint8ClampedArray     JSGlobalObject::m_typedArrayUint8Clamped     DontEnum|ClassStructure
324   Uint16Array           JSGlobalObject::m_typedArrayUint16           DontEnum|ClassStructure
325   Uint32Array           JSGlobalObject::m_typedArrayUint32           DontEnum|ClassStructure
326   Float32Array          JSGlobalObject::m_typedArrayFloat32          DontEnum|ClassStructure
327   Float64Array          JSGlobalObject::m_typedArrayFloat64          DontEnum|ClassStructure
328   DataView              JSGlobalObject::m_typedArrayDataView         DontEnum|ClassStructure
329   Date                  JSGlobalObject::m_dateStructure              DontEnum|ClassStructure
330   Boolean               JSGlobalObject::m_booleanObjectStructure     DontEnum|ClassStructure
331   Number                JSGlobalObject::m_numberObjectStructure      DontEnum|ClassStructure
332   Symbol                JSGlobalObject::m_symbolObjectStructure      DontEnum|ClassStructure
333   WeakMap               JSGlobalObject::m_weakMapStructure           DontEnum|ClassStructure
334   WeakSet               JSGlobalObject::m_weakSetStructure           DontEnum|ClassStructure
335 @end
336 */
337
338 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
339 {
340     VM& vm = exec->vm();
341     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
342
343     JSValue job = exec->argument(0);
344     JSValue arguments = exec->argument(1);
345     ASSERT(arguments.inherits<JSArray>(vm));
346
347     globalObject->queueMicrotask(createJSMicrotask(vm, job, jsCast<JSArray*>(arguments)));
348
349     return JSValue::encode(jsUndefined());
350 }
351
352 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
353     : Base(vm, structure, 0)
354     , m_vm(vm)
355     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
356     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
357     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
358     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
359     , m_arrayIteratorProtocolWatchpoint(IsWatched)
360     , m_mapIteratorProtocolWatchpoint(IsWatched)
361     , m_setIteratorProtocolWatchpoint(IsWatched)
362     , m_stringIteratorProtocolWatchpoint(IsWatched)
363     , m_mapSetWatchpoint(IsWatched)
364     , m_setAddWatchpoint(IsWatched)
365     , m_arraySpeciesWatchpoint(ClearWatchpoint)
366     , m_numberToStringWatchpoint(IsWatched)
367     , m_runtimeFlags()
368     , m_stackTraceLimit(Options::defaultErrorStackTraceLimit())
369     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
370 {
371 }
372
373 JSGlobalObject::~JSGlobalObject()
374 {
375 #if ENABLE(REMOTE_INSPECTOR)
376     m_inspectorController->globalObjectDestroyed();
377 #endif
378
379     if (m_debugger)
380         m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
381 }
382
383 void JSGlobalObject::destroy(JSCell* cell)
384 {
385     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
386 }
387
388 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
389 {
390     m_globalThis.set(vm, this, globalThis);
391 }
392
393 static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
394 {
395     JSValue baseValue = JSValue(base);
396     PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
397     baseValue.getPropertySlot(exec, ident, slot);
398     return slot.getPureResult().toObject(exec);
399 }
400
401 template<ErrorType errorType>
402 void JSGlobalObject::initializeErrorConstructor(LazyClassStructure::Initializer& init)
403 {
404     init.setPrototype(NativeErrorPrototype::create(init.vm, NativeErrorPrototype::createStructure(init.vm, this, m_errorPrototype.get()), errorTypeName(errorType)));
405     init.setStructure(ErrorInstance::createStructure(init.vm, this, init.prototype));
406     init.setConstructor(NativeErrorConstructor<errorType>::create(init.vm, NativeErrorConstructor<errorType>::createStructure(init.vm, this, m_errorConstructor.get()), jsCast<NativeErrorPrototype*>(init.prototype)));
407 }
408
409 void JSGlobalObject::init(VM& vm)
410 {
411     ASSERT(vm.currentThreadIsHoldingAPILock());
412     auto catchScope = DECLARE_CATCH_SCOPE(vm);
413
414     Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure(vm)));
415
416     m_debugger = 0;
417
418 #if ENABLE(REMOTE_INSPECTOR)
419     m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
420     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
421     m_inspectorDebuggable->init();
422     m_consoleClient = m_inspectorController->consoleClient();
423 #endif
424
425     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
426     m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
427
428     m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
429     // Need to create the callee structure (above) before creating the callee.
430     JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
431     m_globalCallee.set(vm, this, globalCallee);
432
433     ExecState::initGlobalExec(JSGlobalObject::globalExec(), globalCallee);
434     ExecState* exec = JSGlobalObject::globalExec();
435
436     JSCallee* stackOverflowFrameCallee = JSCallee::create(vm, this, globalScope());
437     m_stackOverflowFrameCallee.set(vm, this, stackOverflowFrameCallee);
438
439     m_hostFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
440
441     auto initFunctionStructures = [&] (FunctionStructures& structures) {
442         structures.strictFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
443         structures.sloppyFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
444         structures.arrowFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
445     };
446     initFunctionStructures(m_builtinFunctions);
447     initFunctionStructures(m_ordinaryFunctions);
448
449     m_customGetterSetterFunctionStructure.initLater(
450         [] (const Initializer<Structure>& init) {
451             init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
452         });
453     m_boundFunctionStructure.initLater(
454         [] (const Initializer<Structure>& init) {
455             init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
456         });
457     m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
458     m_nativeStdFunctionStructure.initLater(
459         [] (const Initializer<Structure>& init) {
460             init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
461         });
462     JSFunction* callFunction = nullptr;
463     JSFunction* applyFunction = nullptr;
464     JSFunction* hasInstanceSymbolFunction = nullptr;
465     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
466     m_callFunction.set(vm, this, callFunction);
467     m_applyFunction.set(vm, this, applyFunction);
468     m_arrayProtoToStringFunction.initLater(
469         [] (const Initializer<JSFunction>& init) {
470             init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
471         });
472     m_arrayProtoValuesFunction.initLater(
473         [] (const Initializer<JSFunction>& init) {
474             init.set(JSFunction::create(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
475         });
476     m_initializePromiseFunction.initLater(
477         [] (const Initializer<JSFunction>& init) {
478             init.set(JSFunction::create(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
479         });
480
481     m_iteratorProtocolFunction.initLater(
482         [] (const Initializer<JSFunction>& init) {
483             init.set(JSFunction::create(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
484         });
485
486     m_promiseResolveFunction.initLater(
487         [] (const Initializer<JSFunction>& init) {
488             init.set(JSFunction::create(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
489         });
490
491     m_newPromiseCapabilityFunction.set(vm, this, JSFunction::create(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
492     m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
493     m_throwTypeErrorGetterSetter.initLater(
494         [] (const Initializer<GetterSetter>& init) {
495             JSFunction* thrower = init.owner->throwTypeErrorFunction();
496             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner, thrower, thrower);
497             init.set(getterSetter);
498         });
499
500     m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
501     m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
502     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
503     GetterSetter* protoAccessor = GetterSetter::create(vm, this,
504         JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter, UnderscoreProtoIntrinsic),
505         JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
506     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, PropertyAttribute::Accessor | PropertyAttribute::DontEnum);
507     m_functionPrototype->structure(vm)->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
508     m_objectStructureForObjectConstructor.set(vm, this, vm.structureCache.emptyObjectStructureForPrototype(this, m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
509     m_objectProtoValueOfFunction.set(vm, this, jsCast<JSFunction*>(objectPrototype()->getDirect(vm, vm.propertyNames->valueOf)));
510     
511     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
512     GetterSetter* getterSetter = GetterSetter::create(vm, this, thrower, thrower);
513     m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
514     
515     m_functionPrototype->initRestrictedProperties(exec, this);
516
517     m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this, JSFunction::create(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this), nullptr));
518
519     m_typedArrayProto.initLater(
520         [] (const Initializer<JSTypedArrayViewPrototype>& init) {
521             init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
522             
523             // Make sure that the constructor gets initialized, too.
524             init.owner->m_typedArraySuperConstructor.get(init.owner);
525         });
526     m_typedArraySuperConstructor.initLater(
527         [] (const Initializer<JSTypedArrayViewConstructor>& init) {
528             JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
529             JSTypedArrayViewConstructor* constructor = JSTypedArrayViewConstructor::create(init.vm, init.owner, JSTypedArrayViewConstructor::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()), prototype, init.owner->m_speciesGetterSetter.get());
530             prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
531             init.set(constructor);
532         });
533     
534 #define INIT_TYPED_ARRAY_LATER(type) \
535     m_typedArray ## type.initLater( \
536         [] (LazyClassStructure::Initializer& init) { \
537             init.setPrototype(JS ## type ## ArrayPrototype::create(init.vm, init.global, JS ## type ## ArrayPrototype::createStructure(init.vm, init.global, init.global->m_typedArrayProto.get(init.global)))); \
538             init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
539             init.setConstructor(JS ## type ## ArrayConstructor::create(init.vm, init.global, JS ## type ## ArrayConstructor::createStructure(init.vm, init.global, init.global->m_typedArraySuperConstructor.get(init.global)), init.prototype, #type "Array"_s, typedArrayConstructorAllocate ## type ## ArrayCodeGenerator(init.vm))); \
540             init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
541         });
542     FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
543 #undef INIT_TYPED_ARRAY_LATER
544     
545     m_typedArrayDataView.initLater(
546         [] (LazyClassStructure::Initializer& init) {
547             init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
548             init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
549             init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, "DataView"_s, nullptr));
550         });
551     
552     m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
553     m_moduleEnvironmentStructure.initLater(
554         [] (const Initializer<Structure>& init) {
555             init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
556         });
557     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
558     m_debuggerScopeStructure.initLater(
559         [] (const Initializer<Structure>& init) {
560             init.set(DebuggerScope::createStructure(init.vm, init.owner));
561         });
562     m_withScopeStructure.initLater(
563         [] (const Initializer<Structure>& init) {
564             init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
565         });
566     
567     m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
568     
569     m_callbackFunctionStructure.initLater(
570         [] (const Initializer<Structure>& init) {
571             init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
572         });
573     m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
574     m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
575     m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
576     m_callbackConstructorStructure.initLater(
577         [] (const Initializer<Structure>& init) {
578             init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
579         });
580     m_callbackObjectStructure.initLater(
581         [] (const Initializer<Structure>& init) {
582             init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
583         });
584
585 #if JSC_OBJC_API_ENABLED
586     m_objcCallbackFunctionStructure.initLater(
587         [] (const Initializer<Structure>& init) {
588             init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
589         });
590     m_objcWrapperObjectStructure.initLater(
591         [] (const Initializer<Structure>& init) {
592             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
593         });
594 #endif
595 #ifdef JSC_GLIB_API_ENABLED
596     m_glibCallbackFunctionStructure.initLater(
597         [] (const Initializer<Structure>& init) {
598             init.set(JSCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
599         });
600     m_glibWrapperObjectStructure.initLater(
601         [] (const Initializer<Structure>& init) {
602             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
603         });
604 #endif
605     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
606     
607     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(UndecidedShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
608     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(Int32Shape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
609     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(DoubleShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
610     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ContiguousShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
611     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
612     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(SlowPutArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
613     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithInt32)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithInt32));
614     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithDouble)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithDouble));
615     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithContiguous));
616     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
617         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
618
619     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
620     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
621     m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
622     m_regExpMatchesArrayWithGroupsStructure.set(vm, this, createRegExpMatchesArrayWithGroupsStructure(vm, this));
623
624     m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, jsNull()));
625     m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
626     {
627         bool isCallable = false;
628         m_proxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
629         isCallable = true;
630         m_callableProxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
631     }
632     m_proxyRevokeStructure.set(vm, this, ProxyRevoke::createStructure(vm, this, m_functionPrototype.get()));
633
634     m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, ParseIntIntrinsic));
635     putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
636     m_parseFloatFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->parseFloat.string(), globalFuncParseFloat, NoIntrinsic));
637     putDirectWithoutTransition(vm, vm.propertyNames->parseFloat, m_parseFloatFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
638     
639     m_arrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Default));
640     m_arrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_arrayBufferPrototype.get()));
641 #if ENABLE(SHARED_ARRAY_BUFFER)
642     m_sharedArrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
643     m_sharedArrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_sharedArrayBufferPrototype.get()));
644 #endif
645
646     m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
647     m_asyncIteratorPrototype.set(vm, this, AsyncIteratorPrototype::create(vm, this, AsyncIteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
648
649     m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
650     m_asyncGeneratorPrototype.set(vm, this, AsyncGeneratorPrototype::create(vm, this, AsyncGeneratorPrototype::createStructure(vm, this, m_asyncIteratorPrototype.get())));
651
652 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
653         m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
654         m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get())); \
655     } while (0);
656     
657     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
658
659     if (UNLIKELY(Options::useBigInt()))
660         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
661
662     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
663     
664 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
665
666 #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
667     m_ ## properName ## Structure.initLater(\
668         [] (LazyClassStructure::Initializer& init) { \
669             init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
670             init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
671             init.setConstructor(capitalName ## Constructor::create(init.vm, capitalName ## Constructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), jsCast<capitalName ## Prototype*>(init.prototype), init.global->m_speciesGetterSetter.get())); \
672         });
673     
674     FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
675     
676 #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
677     
678     // Constructors
679
680     ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
681     m_objectConstructor.set(vm, this, objectConstructor);
682
683     JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
684     m_throwTypeErrorFunction.set(vm, this, throwTypeErrorFunction);
685
686     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
687
688     ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
689     m_arrayConstructor.set(vm, this, arrayConstructor);
690     
691     RegExpConstructor* regExpConstructor = RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get());
692     m_regExpGlobalData.cachedResult().record(vm, this, nullptr, jsEmptyString(&vm), MatchResult(0, 0));
693     
694     JSArrayBufferConstructor* arrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayBufferPrototype.get(), m_speciesGetterSetter.get());
695     m_arrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
696
697 #if ENABLE(SHARED_ARRAY_BUFFER)
698     JSSharedArrayBufferConstructor* sharedArrayBufferConstructor = nullptr;
699     sharedArrayBufferConstructor = JSSharedArrayBufferConstructor::create(vm, JSSharedArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_sharedArrayBufferPrototype.get(), m_speciesGetterSetter.get());
700     m_sharedArrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
701
702     AtomicsObject* atomicsObject = AtomicsObject::create(vm, this, AtomicsObject::createStructure(vm, this, m_objectPrototype.get()));
703 #endif
704
705 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
706 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
707 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
708
709     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
710     BigIntConstructor* bigIntConstructor = nullptr;
711     if (UNLIKELY(Options::useBigInt())) {
712         bigIntConstructor = BigIntConstructor::create(vm, BigIntConstructor::createStructure(vm, this, m_functionPrototype.get()), m_bigIntPrototype.get(), m_speciesGetterSetter.get());
713         m_bigIntPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, bigIntConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
714     }
715     
716 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
717
718     m_promiseConstructor.set(vm, this, promiseConstructor);
719     m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
720     
721     m_errorConstructor.set(vm, this, errorConstructor);
722     m_evalErrorStructure.initLater(
723         [] (LazyClassStructure::Initializer& init) {
724             init.global->initializeErrorConstructor<ErrorType::EvalError>(init);
725         });
726     m_rangeErrorStructure.initLater(
727         [] (LazyClassStructure::Initializer& init) {
728             init.global->initializeErrorConstructor<ErrorType::RangeError>(init);
729         });
730     m_referenceErrorStructure.initLater(
731         [] (LazyClassStructure::Initializer& init) {
732             init.global->initializeErrorConstructor<ErrorType::ReferenceError>(init);
733         });
734     m_syntaxErrorStructure.initLater(
735         [] (LazyClassStructure::Initializer& init) {
736             init.global->initializeErrorConstructor<ErrorType::SyntaxError>(init);
737         });
738     m_typeErrorStructure.initLater(
739         [] (LazyClassStructure::Initializer& init) {
740             init.global->initializeErrorConstructor<ErrorType::TypeError>(init);
741         });
742     m_URIErrorStructure.initLater(
743         [] (LazyClassStructure::Initializer& init) {
744             init.global->initializeErrorConstructor<ErrorType::URIError>(init);
745         });
746
747     m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
748     GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
749     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
750     m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
751
752     m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
753     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
754
755     m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
756     AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
757     m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
758     m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
759
760     m_asyncGeneratorFunctionPrototype.set(vm, this, AsyncGeneratorFunctionPrototype::create(vm, AsyncGeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
761     AsyncGeneratorFunctionConstructor* asyncGeneratorFunctionConstructor = AsyncGeneratorFunctionConstructor::create(vm, AsyncGeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncGeneratorFunctionPrototype.get());
762     m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncGeneratorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
763     m_asyncGeneratorFunctionStructure.set(vm, this, JSAsyncGeneratorFunction::createStructure(vm, this, m_asyncGeneratorFunctionPrototype.get()));
764
765     m_asyncGeneratorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_asyncGeneratorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
766     m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_asyncGeneratorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
767     
768     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
769     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
770     m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
771     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
772     
773     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
774     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
775     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
776     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
777
778     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ObjectPrivateName(), objectConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
779     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ArrayPrivateName(), arrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
780
781     putDirectWithoutTransition(vm, vm.propertyNames->ArrayBuffer, arrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
782 #if ENABLE(SHARED_ARRAY_BUFFER)
783     putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
784     putDirectWithoutTransition(vm, Identifier::fromString(exec, "Atomics"), atomicsObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
785 #endif
786
787 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
788 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
789
790     FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
791     if (UNLIKELY(Options::useBigInt()))
792         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
793
794 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
795     m_iteratorResultObjectStructure.set(vm, this, createIteratorResultObjectStructure(vm, *this));
796     
797     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
798     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
799     
800 #if ENABLE(INTL)
801     IntlObject* intl = IntlObject::create(vm, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
802     putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, static_cast<unsigned>(PropertyAttribute::DontEnum));
803     m_intlObject.set(vm, this, intl);
804 #endif // ENABLE(INTL)
805     ReflectObject* reflectObject = ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get()));
806     putDirectWithoutTransition(vm, vm.propertyNames->Reflect, reflectObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
807
808     m_moduleLoader.initLater(
809         [] (const Initializer<JSModuleLoader>& init) {
810             auto catchScope = DECLARE_CATCH_SCOPE(init.vm);
811             init.set(JSModuleLoader::create(init.owner->globalExec(), init.vm, init.owner, JSModuleLoader::createStructure(init.vm, init.owner, jsNull())));
812             catchScope.releaseAssertNoException();
813         });
814     if (Options::exposeInternalModuleLoader())
815         putDirectWithoutTransition(vm, vm.propertyNames->Loader, moduleLoader(), static_cast<unsigned>(PropertyAttribute::DontEnum));
816
817     JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
818     JSFunction* builtinDescribe = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinDescribe);
819
820     JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
821
822     JSFunction* privateFuncPropertyIsEnumerable = JSFunction::create(vm, this, 0, String(), globalFuncPropertyIsEnumerable);
823     JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
824     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
825     JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
826     JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
827     JSFunction* privateFuncIsTypedArrayView = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic);
828     JSFunction* privateFuncTypedArraySubarrayCreate = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSubarrayCreate);
829     JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
830     JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
831     JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
832     JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
833     JSFunction* privateFuncThisNumberValue = JSFunction::create(vm, this, 0, String(), numberProtoFuncValueOf);
834     JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
835     JSFunction* privateFuncIsArraySlow = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArraySlow);
836     JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
837     JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
838     JSFunction* privateFuncMapBucketHead = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketHead, JSMapBucketHeadIntrinsic);
839     JSFunction* privateFuncMapBucketNext = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketNext, JSMapBucketNextIntrinsic);
840     JSFunction* privateFuncMapBucketKey = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketKey, JSMapBucketKeyIntrinsic);
841     JSFunction* privateFuncMapBucketValue = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketValue, JSMapBucketValueIntrinsic);
842     JSFunction* privateFuncSetBucketHead = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketHead, JSSetBucketHeadIntrinsic);
843     JSFunction* privateFuncSetBucketNext = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketNext, JSSetBucketNextIntrinsic);
844     JSFunction* privateFuncSetBucketKey = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketKey, JSSetBucketKeyIntrinsic);
845
846     JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
847     catchScope.assertNoException();
848     JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
849     catchScope.assertNoException();
850     m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
851     JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
852     catchScope.assertNoException();
853     JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
854     catchScope.assertNoException();
855     JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
856     catchScope.assertNoException();
857     JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
858     catchScope.assertNoException();
859     JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
860     catchScope.assertNoException();
861     m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
862     JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
863     m_regExpProtoExec.set(vm, this, builtinRegExpExec);
864     JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
865     m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
866
867 #define CREATE_PRIVATE_GLOBAL_FUNCTION(name, code) JSFunction* name ## PrivateFunction = JSFunction::create(vm, code ## CodeGenerator(vm), this);
868     JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(CREATE_PRIVATE_GLOBAL_FUNCTION)
869 #undef CREATE_PRIVATE_GLOBAL_FUNCTION
870
871     JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
872     createArrayIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
873
874     JSObject* asyncFromSyncIteratorPrototype = AsyncFromSyncIteratorPrototype::create(vm, this, AsyncFromSyncIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
875     AsyncFromSyncIteratorConstructorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, asyncFromSyncIteratorPrototype);
876
877     JSObject* mapIteratorPrototype = MapIteratorPrototype::create(vm, this, MapIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
878     createMapIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, mapIteratorPrototype);
879
880     JSObject* setIteratorPrototype = SetIteratorPrototype::create(vm, this, SetIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
881     createSetIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, setIteratorPrototype);
882
883     GlobalPropertyInfo staticGlobals[] = {
884 #define INIT_PRIVATE_GLOBAL(name, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().name ## PrivateName(), name ## PrivateFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
885         JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
886 #undef INIT_PRIVATE_GLOBAL
887         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
888         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
889         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
890         GlobalPropertyInfo(vm.propertyNames->builtinNames().propertyIsEnumerablePrivateName(), privateFuncPropertyIsEnumerable, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
891         GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
892         GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
893         // FIXME: Offer @makeTypeError function instead of exposing @TypeError here.
894         // https://bugs.webkit.org/show_bug.cgi?id=193858
895         GlobalPropertyInfo(vm.propertyNames->builtinNames().TypeErrorPrivateName(), m_typeErrorStructure.constructor(this), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
896         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
897         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
898         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
899         GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
900         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySubarrayCreatePrivateName(), privateFuncTypedArraySubarrayCreate, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
901         GlobalPropertyInfo(vm.propertyNames->builtinNames().isBoundFunctionPrivateName(), privateFuncIsBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
902         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasInstanceBoundFunctionPrivateName(), privateFuncHasInstanceBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
903         GlobalPropertyInfo(vm.propertyNames->builtinNames().instanceOfPrivateName(), privateFuncInstanceOf, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
904         GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinLogPrivateName(), builtinLog, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
905         GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinDescribePrivateName(), builtinDescribe, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
906         GlobalPropertyInfo(vm.propertyNames->builtinNames().RegExpPrivateName(), regExpConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
907         GlobalPropertyInfo(vm.propertyNames->builtinNames().truncPrivateName(), privateFuncTrunc, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
908         GlobalPropertyInfo(vm.propertyNames->builtinNames().PromisePrivateName(), promiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
909         GlobalPropertyInfo(vm.propertyNames->builtinNames().ReflectPrivateName(), reflectObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
910         GlobalPropertyInfo(vm.propertyNames->builtinNames().InternalPromisePrivateName(), internalPromiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
911
912         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharacterPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
913         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayPrivateName(), arrayConstructor->getDirect(vm, vm.propertyNames->isArray), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
914         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArraySlowPrivateName(), privateFuncIsArraySlow, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
915         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayConstructorPrivateName(), privateFuncIsArrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
916         GlobalPropertyInfo(vm.propertyNames->builtinNames().concatMemcpyPrivateName(), privateFuncConcatMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
917         GlobalPropertyInfo(vm.propertyNames->builtinNames().appendMemcpyPrivateName(), privateFuncAppendMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
918
919         GlobalPropertyInfo(vm.propertyNames->builtinNames().hostPromiseRejectionTrackerPrivateName(), JSFunction::create(vm, this, 2, String(), globalFuncHostPromiseRejectionTracker), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
920         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
921         GlobalPropertyInfo(vm.propertyNames->builtinNames().SetPrivateName(), setConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
922         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
923         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisNumberValuePrivateName(), privateFuncThisNumberValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
924 #if ENABLE(INTL)
925         GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
926         GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
927         GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
928         GlobalPropertyInfo(vm.propertyNames->builtinNames().PluralRulesPrivateName(), intl->getDirect(vm, vm.propertyNames->PluralRules), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
929 #endif // ENABLE(INTL)
930
931         GlobalPropertyInfo(vm.propertyNames->builtinNames().isConstructorPrivateName(), JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
932
933         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoFlagsGetterPrivateName(), regExpProtoFlagsGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
934         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoGlobalGetterPrivateName(), regExpProtoGlobalGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
935         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoIgnoreCaseGetterPrivateName(), regExpProtoIgnoreCaseGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
936         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoMultilineGetterPrivateName(), regExpProtoMultilineGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
937         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoSourceGetterPrivateName(), regExpProtoSourceGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
938         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoStickyGetterPrivateName(), regExpProtoStickyGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
939         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoUnicodeGetterPrivateName(), regExpProtoUnicodeGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
940
941         // RegExp.prototype helpers.
942         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpBuiltinExecPrivateName(), builtinRegExpExec, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
943         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpCreatePrivateName(), JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
944         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpMatchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast, RegExpMatchFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
945         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSearchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
946         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
947         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpPrototypeSymbolReplacePrivateName(), m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
948         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpTestFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
949
950         // String.prototype helpers.
951         GlobalPropertyInfo(vm.propertyNames->builtinNames().stringIncludesInternalPrivateName(), JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
952         GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
953         GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSubstrInternalPrivateName(), JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
954
955         // Function prototype helpers.
956         GlobalPropertyInfo(vm.propertyNames->builtinNames().makeBoundFunctionPrivateName(), JSFunction::create(vm, this, 5, String(), makeBoundFunction), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
957         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasOwnLengthPropertyPrivateName(), JSFunction::create(vm, this, 1, String(), hasOwnLengthProperty), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
958
959         // Map and Set helpers.
960         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketHeadPrivateName(), privateFuncMapBucketHead, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
961         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketNextPrivateName(), privateFuncMapBucketNext, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
962         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketKeyPrivateName(), privateFuncMapBucketKey, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
963         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketValuePrivateName(), privateFuncMapBucketValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
964         GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketHeadPrivateName(), privateFuncSetBucketHead, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
965         GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketNextPrivateName(), privateFuncSetBucketNext, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
966         GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketKeyPrivateName(), privateFuncSetBucketKey, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
967 #if ENABLE(WEBASSEMBLY) && ENABLE(WEBASSEMBLY_STREAMING_API)
968         // WebAssembly Streaming API
969         GlobalPropertyInfo(vm.propertyNames->builtinNames().webAssemblyCompileStreamingInternalPrivateName(), JSFunction::create(vm, this, 1, String(), webAssemblyCompileStreamingInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
970         GlobalPropertyInfo(vm.propertyNames->builtinNames().webAssemblyInstantiateStreamingInternalPrivateName(), JSFunction::create(vm, this, 1, String(), webAssemblyInstantiateStreamingInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
971 #endif
972 #if !ASSERT_DISABLED
973         GlobalPropertyInfo(vm.propertyNames->builtinNames().assertPrivateName(), JSFunction::create(vm, this, 1, String(), assertCall), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
974 #endif
975     };
976     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
977     
978     m_specialPointers[Special::CallFunction] = m_callFunction.get();
979     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
980     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
981     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
982
983     m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::ThrowTypeErrorFunction)] = m_throwTypeErrorFunction.get();
984
985     if (UNLIKELY(Options::useDollarVM()))
986         exposeDollarVM(vm);
987
988 #if ENABLE(WEBASSEMBLY)
989     if (Options::useWebAssembly()) {
990         auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
991         m_webAssemblyStructure.set(vm, this, JSWebAssembly::createStructure(vm, this, webAssemblyPrototype));
992         m_webAssemblyModuleRecordStructure.set(vm, this, WebAssemblyModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
993         m_webAssemblyFunctionStructure.set(vm, this, WebAssemblyFunction::createStructure(vm, this, m_functionPrototype.get()));
994         m_webAssemblyWrapperFunctionStructure.set(vm, this, WebAssemblyWrapperFunction::createStructure(vm, this, m_functionPrototype.get()));
995         m_webAssemblyToJSCalleeStructure.set(vm, this, WebAssemblyToJSCallee::createStructure(vm, this, jsNull()));
996         auto* webAssembly = JSWebAssembly::create(vm, this, m_webAssemblyStructure.get());
997         putDirectWithoutTransition(vm, Identifier::fromString(exec, "WebAssembly"), webAssembly, static_cast<unsigned>(PropertyAttribute::DontEnum));
998
999 #define CREATE_WEBASSEMBLY_CONSTRUCTOR(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
1000         typedef capitalName ## Prototype Prototype; \
1001         typedef capitalName ## Constructor Constructor; \
1002         typedef JS ## capitalName JSObj; \
1003         auto* base = m_ ## prototypeBase ## Prototype.get(); \
1004         auto* prototype = Prototype::create(vm, this, Prototype::createStructure(vm, this, base)); \
1005         auto* structure = JSObj::createStructure(vm, this, prototype); \
1006         auto* constructor = Constructor::create(vm, Constructor::createStructure(vm, this, this->functionPrototype()), prototype); \
1007         prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
1008         m_ ## lowerName ## Prototype.set(vm, this, prototype); \
1009         m_ ## properName ## Structure.set(vm, this, structure); \
1010         webAssembly->putDirectWithoutTransition(vm, Identifier::fromString(this->globalExec(), #jsName), constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
1011     } while (0);
1012
1013         FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(CREATE_WEBASSEMBLY_CONSTRUCTOR)
1014
1015 #undef CREATE_WEBASSEMBLY_CONSTRUCTOR
1016     }
1017 #endif // ENABLE(WEBASSEMBLY)
1018
1019     auto setupAdaptiveWatchpoint = [&] (JSObject* base, const Identifier& ident) -> ObjectPropertyCondition {
1020         // Performing these gets should not throw.
1021         ExecState* exec = globalExec();
1022         PropertySlot slot(base, PropertySlot::InternalMethodType::Get);
1023         bool result = base->getOwnPropertySlot(base, exec, ident, slot);
1024         ASSERT_UNUSED(result, result);
1025         catchScope.assertNoException();
1026         RELEASE_ASSERT(slot.isCacheableValue());
1027         JSValue functionValue = slot.getValue(exec, ident);
1028         catchScope.assertNoException();
1029         ASSERT(jsDynamicCast<JSFunction*>(vm, functionValue));
1030
1031         ObjectPropertyCondition condition = generateConditionForSelfEquivalence(m_vm, nullptr, base, ident.impl());
1032         RELEASE_ASSERT(condition.requiredValue() == functionValue);
1033
1034         bool isWatchable = condition.isWatchable(PropertyCondition::EnsureWatchability);
1035         RELEASE_ASSERT(isWatchable); // We allow this to install the necessary watchpoints.
1036
1037         return condition;
1038     };
1039
1040     {
1041         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayIteratorPrototype, m_vm.propertyNames->next);
1042         m_arrayIteratorPrototypeNext = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_arrayIteratorProtocolWatchpoint);
1043         m_arrayIteratorPrototypeNext->install(vm);
1044     }
1045     {
1046         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this->arrayPrototype(), m_vm.propertyNames->iteratorSymbol);
1047         m_arrayPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_arrayIteratorProtocolWatchpoint);
1048         m_arrayPrototypeSymbolIteratorWatchpoint->install(vm);
1049     }
1050
1051     {
1052         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(mapIteratorPrototype, m_vm.propertyNames->next);
1053         m_mapIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_mapIteratorProtocolWatchpoint);
1054         m_mapIteratorPrototypeNextWatchpoint->install(vm);
1055     }
1056     {
1057         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_mapPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1058         m_mapPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_mapIteratorProtocolWatchpoint);
1059         m_mapPrototypeSymbolIteratorWatchpoint->install(vm);
1060     }
1061
1062     {
1063         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(setIteratorPrototype, m_vm.propertyNames->next);
1064         m_setIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_setIteratorProtocolWatchpoint);
1065         m_setIteratorPrototypeNextWatchpoint->install(vm);
1066     }
1067     {
1068         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_setPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1069         m_setPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_setIteratorProtocolWatchpoint);
1070         m_setPrototypeSymbolIteratorWatchpoint->install(vm);
1071     }
1072
1073     {
1074         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_stringIteratorPrototype.get(), m_vm.propertyNames->next);
1075         m_stringIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_stringIteratorProtocolWatchpoint);
1076         m_stringIteratorPrototypeNextWatchpoint->install(vm);
1077     }
1078     {
1079         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_stringPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1080         m_stringPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_stringIteratorProtocolWatchpoint);
1081         m_stringPrototypeSymbolIteratorWatchpoint->install(vm);
1082     }
1083
1084     {
1085         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_mapPrototype.get(), m_vm.propertyNames->set);
1086         m_mapPrototypeSetWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_mapSetWatchpoint);
1087         m_mapPrototypeSetWatchpoint->install(vm);
1088     }
1089
1090     {
1091         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_setPrototype.get(), m_vm.propertyNames->add);
1092         m_setPrototypeAddWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_setAddWatchpoint);
1093         m_setPrototypeAddWatchpoint->install(vm);
1094     }
1095
1096     // Unfortunately, the prototype objects of the builtin objects can be touched from concurrent compilers. So eagerly initialize them only if we use JIT.
1097     if (VM::canUseJIT()) {
1098         this->booleanPrototype();
1099         auto* numberPrototype = this->numberPrototype();
1100         this->symbolPrototype();
1101
1102         ObjectPropertyCondition condition = setupAdaptiveWatchpoint(numberPrototype, m_vm.propertyNames->toString);
1103         m_numberPrototypeToStringWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(condition, m_numberToStringWatchpoint);
1104         m_numberPrototypeToStringWatchpoint->install(vm);
1105         m_numberProtoToStringFunction.set(vm, this, jsCast<JSFunction*>(numberPrototype->getDirect(vm, vm.propertyNames->toString)));
1106     }
1107
1108     resetPrototype(vm, getPrototypeDirect(vm));
1109 }
1110
1111 bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1112 {
1113     VM& vm = exec->vm();
1114     auto scope = DECLARE_THROW_SCOPE(vm);
1115     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1116     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
1117
1118     if (UNLIKELY(isThisValueAltered(slot, thisObject)))
1119         RELEASE_AND_RETURN(scope, ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()));
1120
1121     bool shouldThrowReadOnlyError = slot.isStrictMode();
1122     bool ignoreReadOnlyErrors = false;
1123     bool putResult = false;
1124     bool done = symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
1125     EXCEPTION_ASSERT((!!scope.exception() == (done && !putResult)) || !shouldThrowReadOnlyError);
1126     if (done)
1127         return putResult;
1128     RELEASE_AND_RETURN(scope, Base::put(thisObject, exec, propertyName, value, slot));
1129 }
1130
1131 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
1132 {
1133     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
1134     PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
1135     // silently ignore attempts to add accessors aliasing vars.
1136     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
1137         return false;
1138     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
1139 }
1140
1141 void JSGlobalObject::addGlobalVar(const Identifier& ident)
1142 {
1143     ConcurrentJSLocker locker(symbolTable()->m_lock);
1144     SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
1145     if (!entry.isNull())
1146         return;
1147     
1148     ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1149     SymbolTableEntry newEntry(VarOffset(offset), 0);
1150     newEntry.prepareToWatch();
1151     symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
1152     
1153     ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
1154     RELEASE_ASSERT(offsetForAssert == offset);
1155 }
1156
1157 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
1158 {
1159     VM& vm = exec->vm();
1160     VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
1161     methodTable(vm)->deleteProperty(this, exec, propertyName);
1162     addGlobalVar(propertyName);
1163 }
1164
1165 void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
1166 {
1167     m_globalScopeExtension.set(vm(), this, scope);
1168 }
1169
1170 void JSGlobalObject::clearGlobalScopeExtension()
1171 {
1172     m_globalScopeExtension.clear();
1173 }
1174
1175 static inline JSObject* lastInPrototypeChain(VM& vm, JSObject* object)
1176 {
1177     JSObject* o = object;
1178     while (o->getPrototypeDirect(vm).isObject())
1179         o = asObject(o->getPrototypeDirect(vm));
1180     return o;
1181 }
1182
1183 // Private namespace for helpers for JSGlobalObject::haveABadTime()
1184 namespace {
1185
1186 class GlobalObjectDependencyFinder : public MarkedBlock::VoidFunctor {
1187 public:
1188     GlobalObjectDependencyFinder(VM& vm)
1189         : m_vm(vm)
1190     { }
1191
1192     IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1193
1194     void addDependency(JSGlobalObject* key, JSGlobalObject* dependent);
1195     HashSet<JSGlobalObject*>* dependentsFor(JSGlobalObject* key);
1196
1197 private:
1198     void visit(JSObject*);
1199
1200     VM& m_vm;
1201     HashMap<JSGlobalObject*, HashSet<JSGlobalObject*>> m_dependencies;
1202 };
1203
1204 inline void GlobalObjectDependencyFinder::addDependency(JSGlobalObject* key, JSGlobalObject* dependent)
1205 {
1206     auto keyResult = m_dependencies.add(key, HashSet<JSGlobalObject*>());
1207     keyResult.iterator->value.add(dependent);
1208 }
1209
1210 inline HashSet<JSGlobalObject*>* GlobalObjectDependencyFinder::dependentsFor(JSGlobalObject* key)
1211 {
1212     auto iterator = m_dependencies.find(key);
1213     if (iterator == m_dependencies.end())
1214         return nullptr;
1215     return &iterator->value;
1216 }
1217
1218 inline void GlobalObjectDependencyFinder::visit(JSObject* object)
1219 {
1220     VM& vm = m_vm;
1221
1222     if (!object->mayBePrototype())
1223         return;
1224
1225     JSObject* current = object;
1226     JSGlobalObject* objectGlobalObject = object->globalObject(vm);
1227     do {
1228         JSValue prototypeValue = current->getPrototypeDirect(vm);
1229         if (prototypeValue.isNull())
1230             return;
1231         current = asObject(prototypeValue);
1232
1233         JSGlobalObject* protoGlobalObject = current->globalObject(vm);
1234         if (protoGlobalObject != objectGlobalObject)
1235             addDependency(protoGlobalObject, objectGlobalObject);
1236     } while (true);
1237 }
1238
1239 IterationStatus GlobalObjectDependencyFinder::operator()(HeapCell* cell, HeapCell::Kind kind) const
1240 {
1241     if (isJSCellKind(kind) && static_cast<JSCell*>(cell)->isObject()) {
1242         // FIXME: This const_cast exists because this isn't a C++ lambda.
1243         // https://bugs.webkit.org/show_bug.cgi?id=159644
1244         const_cast<GlobalObjectDependencyFinder*>(this)->visit(jsCast<JSObject*>(static_cast<JSCell*>(cell)));
1245     }
1246     return IterationStatus::Continue;
1247 }
1248
1249 enum class BadTimeFinderMode {
1250     SingleGlobal,
1251     MultipleGlobals
1252 };
1253
1254 template<BadTimeFinderMode mode>
1255 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
1256 public:
1257     ObjectsWithBrokenIndexingFinder(VM&, Vector<JSObject*>&, JSGlobalObject*);
1258     ObjectsWithBrokenIndexingFinder(VM&, Vector<JSObject*>&, HashSet<JSGlobalObject*>&);
1259
1260     bool needsMultiGlobalsScan() const { return m_needsMultiGlobalsScan; }
1261     IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1262
1263 private:
1264     IterationStatus visit(JSObject*);
1265
1266     VM& m_vm;
1267     Vector<JSObject*>& m_foundObjects;
1268     JSGlobalObject* m_globalObject { nullptr }; // Only used for SingleBadTimeGlobal mode.
1269     HashSet<JSGlobalObject*>* m_globalObjects { nullptr }; // Only used for BadTimeGlobalGraph mode;
1270     bool m_needsMultiGlobalsScan { false };
1271 };
1272
1273 template<>
1274 ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::SingleGlobal>::ObjectsWithBrokenIndexingFinder(
1275     VM& vm, Vector<JSObject*>& foundObjects, JSGlobalObject* globalObject)
1276     : m_vm(vm)
1277     , m_foundObjects(foundObjects)
1278     , m_globalObject(globalObject)
1279 {
1280 }
1281
1282 template<>
1283 ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::MultipleGlobals>::ObjectsWithBrokenIndexingFinder(
1284     VM& vm, Vector<JSObject*>& foundObjects, HashSet<JSGlobalObject*>& globalObjects)
1285     : m_vm(vm)
1286     , m_foundObjects(foundObjects)
1287     , m_globalObjects(&globalObjects)
1288 {
1289 }
1290
1291 inline bool hasBrokenIndexing(IndexingType type)
1292 {
1293     return type && !hasSlowPutArrayStorage(type);
1294 }
1295
1296 inline bool hasBrokenIndexing(JSObject* object)
1297 {
1298     IndexingType type = object->indexingType();
1299     return hasBrokenIndexing(type);
1300 }
1301
1302 template<BadTimeFinderMode mode>
1303 inline IterationStatus ObjectsWithBrokenIndexingFinder<mode>::visit(JSObject* object)
1304 {
1305     VM& vm = m_vm;
1306
1307     // We only want to have a bad time in the affected global object, not in the entire
1308     // VM. But we have to be careful, since there may be objects that claim to belong to
1309     // a different global object that have prototypes from our global object.
1310     auto isInAffectedGlobalObject = [&] (JSObject* object) {
1311         JSGlobalObject* objectGlobalObject { nullptr };
1312         bool objectMayBePrototype { false };
1313
1314         if (mode == BadTimeFinderMode::SingleGlobal) {
1315             objectGlobalObject = object->globalObject(vm);
1316             if (objectGlobalObject == m_globalObject)
1317                 return true;
1318
1319             objectMayBePrototype = object->mayBePrototype();
1320         }
1321
1322         for (JSObject* current = object; ;) {
1323             JSGlobalObject* currentGlobalObject = current->globalObject(vm);
1324             if (mode == BadTimeFinderMode::SingleGlobal) {
1325                 if (objectMayBePrototype && currentGlobalObject != objectGlobalObject)
1326                     m_needsMultiGlobalsScan = true;
1327                 if (currentGlobalObject == m_globalObject)
1328                     return true;
1329             } else {
1330                 if (m_globalObjects->contains(currentGlobalObject))
1331                     return true;
1332             }
1333
1334             JSValue prototypeValue = current->getPrototypeDirect(vm);
1335             if (prototypeValue.isNull())
1336                 return false;
1337             current = asObject(prototypeValue);
1338         }
1339         RELEASE_ASSERT_NOT_REACHED();
1340     };
1341
1342     if (JSFunction* function = jsDynamicCast<JSFunction*>(vm, object)) {
1343         if (FunctionRareData* rareData = function->rareData()) {
1344             // We only use this to cache JSFinalObjects. They do not start off with a broken indexing type.
1345             ASSERT(!(rareData->objectAllocationStructure() && hasBrokenIndexing(rareData->objectAllocationStructure()->indexingType())));
1346
1347             if (Structure* structure = rareData->internalFunctionAllocationStructure()) {
1348                 if (hasBrokenIndexing(structure->indexingType())) {
1349                     bool isRelevantGlobalObject =
1350                         (mode == BadTimeFinderMode::SingleGlobal
1351                             ? m_globalObject == structure->globalObject()
1352                             : m_globalObjects->contains(structure->globalObject()))
1353                         || (structure->hasMonoProto() && !structure->storedPrototype().isNull() && isInAffectedGlobalObject(asObject(structure->storedPrototype())));
1354                     if (mode == BadTimeFinderMode::SingleGlobal && m_needsMultiGlobalsScan)
1355                         return IterationStatus::Done; // Bailing early and let the MultipleGlobals path handle everything.
1356                     if (isRelevantGlobalObject)
1357                         rareData->clearInternalFunctionAllocationProfile();
1358                 }
1359             }
1360         }
1361     }
1362
1363     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
1364     if (!hasBrokenIndexing(object))
1365         return IterationStatus::Continue;
1366
1367     if (isInAffectedGlobalObject(object))
1368         m_foundObjects.append(object);
1369
1370     if (mode == BadTimeFinderMode::SingleGlobal && m_needsMultiGlobalsScan)
1371         return IterationStatus::Done; // Bailing early and let the MultipleGlobals path handle everything.
1372
1373     return IterationStatus::Continue;
1374 }
1375
1376 template<BadTimeFinderMode mode>
1377 IterationStatus ObjectsWithBrokenIndexingFinder<mode>::operator()(HeapCell* cell, HeapCell::Kind kind) const
1378 {
1379     if (isJSCellKind(kind) && static_cast<JSCell*>(cell)->isObject()) {
1380         // FIXME: This const_cast exists because this isn't a C++ lambda.
1381         // https://bugs.webkit.org/show_bug.cgi?id=159644
1382         return const_cast<ObjectsWithBrokenIndexingFinder*>(this)->visit(jsCast<JSObject*>(static_cast<JSCell*>(cell)));
1383     }
1384     return IterationStatus::Continue;
1385 }
1386
1387 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
1388
1389 void JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut(VM& vm)
1390 {
1391     if (isHavingABadTime())
1392         return;
1393
1394     // Make sure that all allocations or indexed storage transitions that are inlining
1395     // the assumption that it's safe to transition to a non-SlowPut array storage don't
1396     // do so anymore.
1397     m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
1398     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
1399     
1400     // Make sure that all JSArray allocations that load the appropriate structure from
1401     // this object now load a structure that uses SlowPut.
1402     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1403         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1404
1405     // Same for any special array structures.
1406     Structure* slowPutStructure;
1407     slowPutStructure = createRegExpMatchesArraySlowPutStructure(vm, this);
1408     m_regExpMatchesArrayStructure.set(vm, this, slowPutStructure);
1409     slowPutStructure = createRegExpMatchesArrayWithGroupsSlowPutStructure(vm, this);
1410     m_regExpMatchesArrayWithGroupsStructure.set(vm, this, slowPutStructure);
1411     slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
1412     m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
1413 };
1414
1415 void JSGlobalObject::haveABadTime(VM& vm)
1416 {
1417     ASSERT(&vm == &this->vm());
1418     
1419     if (isHavingABadTime())
1420         return;
1421
1422     vm.structureCache.clear(); // We may be caching array structures in here.
1423
1424     DeferGC deferGC(vm.heap);
1425
1426     // Consider the following objects and prototype chains:
1427     //    O (of global G1) -> A (of global G1)
1428     //    B (of global G2) where G2 has a bad time
1429     //
1430     // If we set B as the prototype of A, G1 will need to have a bad time.
1431     // See comments in Structure::mayInterceptIndexedAccesses() for why.
1432     //
1433     // Now, consider the following objects and prototype chains:
1434     //    O1 (of global G1) -> A1 (of global G1) -> B1 (of global G2)
1435     //    O2 (of global G2) -> A2 (of global G2)
1436     //    B2 (of global G3) where G3 has a bad time.
1437     //
1438     // G1 and G2 does not have a bad time, but G3 already has a bad time.
1439     // If we set B2 as the prototype of A2, then G2 needs to have a bad time.
1440     // Note that by induction, G1 also now needs to have a bad time because of
1441     // O1 -> A1 -> B1.
1442     //
1443     // We describe this as global G1 being affected by global G2, and G2 by G3.
1444     // Similarly, we say that G1 is dependent on G2, and G2 on G3.
1445     // Hence, when G3 has a bad time, we need to ensure that all globals that
1446     // are transitively dependent on it also have a bad time (G2 and G1 in this
1447     // example).
1448     //
1449     // Apart from clearing the VM structure cache above, there are 2 more things
1450     // that we have to do when globals have a bad time:
1451     // 1. For each affected global:
1452     //    a. Fire its HaveABadTime watchpoint.
1453     //    b. Convert all of its array structures to SlowPutArrayStorage.
1454     // 2. Make sure that all affected objects  switch to the slow kind of
1455     //    indexed storage. An object is considered to be affected if it has
1456     //    indexed storage and has a prototype object which may have indexed
1457     //    accessors. If the prototype object belongs to a global having a bad
1458     //    time, then the prototype object is considered to possibly have indexed
1459     //    accessors. See comments in Structure::mayInterceptIndexedAccesses()
1460     //    for details.
1461     //
1462     // Note: step 1 must be completed before step 2 because step 2 relies on
1463     // the HaveABadTime watchpoint having already been fired on all affected
1464     // globals.
1465     //
1466     // In the common case, only this global will start having a bad time here,
1467     // and no other globals are affected by it. So, we first proceed on this assumption
1468     // with a simpler ObjectsWithBrokenIndexingFinder scan to find heap objects
1469     // affected by this global that need to be converted to SlowPutArrayStorage.
1470     // We'll also have the finder check for the presence of other global objects
1471     // depending on this one.
1472     //
1473     // If we do discover other globals depending on this one, we'll abort this
1474     // first ObjectsWithBrokenIndexingFinder scan because it will be insufficient
1475     // to find all affected objects that need to be converted to SlowPutArrayStorage.
1476     // It also does not make dependent globals have a bad time. Instead, we'll
1477     // take a more comprehensive approach of first creating a dependency graph
1478     // between globals, and then using that graph to determine all affected
1479     // globals and objects. With that, we can make all affected globals have a
1480     // bad time, and convert all affected objects to SlowPutArrayStorage.
1481
1482     fireWatchpointAndMakeAllArrayStructuresSlowPut(vm); // Step 1 above.
1483     
1484     Vector<JSObject*> foundObjects;
1485     ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::SingleGlobal> finder(vm, foundObjects, this);
1486     {
1487         HeapIterationScope iterationScope(vm.heap);
1488         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); // Attempt step 2 above.
1489     }
1490
1491     if (finder.needsMultiGlobalsScan()) {
1492         foundObjects.clear();
1493
1494         // Find all globals that will also have a bad time as a side effect of
1495         // this global having a bad time.
1496         GlobalObjectDependencyFinder dependencies(vm);
1497         {
1498             HeapIterationScope iterationScope(vm.heap);
1499             vm.heap.objectSpace().forEachLiveCell(iterationScope, dependencies);
1500         }
1501
1502         HashSet<JSGlobalObject*> globalsHavingABadTime;
1503         Deque<JSGlobalObject*> globals;
1504
1505         globals.append(this);
1506         while (!globals.isEmpty()) {
1507             JSGlobalObject* global = globals.takeFirst();
1508             global->fireWatchpointAndMakeAllArrayStructuresSlowPut(vm); // Step 1 above.
1509             auto result = globalsHavingABadTime.add(global);
1510             if (result.isNewEntry) {
1511                 if (HashSet<JSGlobalObject*>* dependents = dependencies.dependentsFor(global)) {
1512                     for (JSGlobalObject* dependentGlobal : *dependents)
1513                         globals.append(dependentGlobal);
1514                 }
1515             }
1516         }
1517
1518         ObjectsWithBrokenIndexingFinder<BadTimeFinderMode::MultipleGlobals> finder(vm, foundObjects, globalsHavingABadTime);
1519         {
1520             HeapIterationScope iterationScope(vm.heap);
1521             vm.heap.objectSpace().forEachLiveCell(iterationScope, finder); // Step 2 above.
1522         }
1523     }
1524
1525     while (!foundObjects.isEmpty()) {
1526         JSObject* object = asObject(foundObjects.last());
1527         foundObjects.removeLast();
1528         ASSERT(hasBrokenIndexing(object));
1529         object->switchToSlowPutArrayStorage(vm);
1530     }
1531 }
1532
1533 // Set prototype, and also insert the object prototype at the end of the chain.
1534 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1535 {
1536     setPrototypeDirect(vm, prototype);
1537
1538     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(vm, this);
1539     JSObject* objectPrototype = m_objectPrototype.get();
1540     if (oldLastInPrototypeChain != objectPrototype)
1541         oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1542
1543     // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1544     setGlobalThis(vm, JSNonDestructibleProxy::create(vm, JSNonDestructibleProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1545 }
1546
1547 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1548
1549     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1550     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1551     Base::visitChildren(thisObject, visitor);
1552
1553     visitor.append(thisObject->m_globalThis);
1554
1555     visitor.append(thisObject->m_globalLexicalEnvironment);
1556     visitor.append(thisObject->m_globalScopeExtension);
1557     visitor.append(thisObject->m_globalCallee);
1558     visitor.append(thisObject->m_stackOverflowFrameCallee);
1559     visitor.append(thisObject->m_errorConstructor);
1560     thisObject->m_evalErrorStructure.visit(visitor);
1561     thisObject->m_rangeErrorStructure.visit(visitor);
1562     thisObject->m_referenceErrorStructure.visit(visitor);
1563     thisObject->m_syntaxErrorStructure.visit(visitor);
1564     thisObject->m_typeErrorStructure.visit(visitor);
1565     thisObject->m_URIErrorStructure.visit(visitor);
1566     visitor.append(thisObject->m_objectConstructor);
1567     visitor.append(thisObject->m_promiseConstructor);
1568
1569 #if ENABLE(INTL)
1570     visitor.append(thisObject->m_intlObject);
1571 #endif
1572     visitor.append(thisObject->m_nullGetterFunction);
1573     visitor.append(thisObject->m_nullSetterFunction);
1574
1575     visitor.append(thisObject->m_parseIntFunction);
1576     visitor.append(thisObject->m_parseFloatFunction);
1577     visitor.append(thisObject->m_evalFunction);
1578     visitor.append(thisObject->m_callFunction);
1579     visitor.append(thisObject->m_applyFunction);
1580     visitor.append(thisObject->m_throwTypeErrorFunction);
1581     thisObject->m_arrayProtoToStringFunction.visit(visitor);
1582     thisObject->m_arrayProtoValuesFunction.visit(visitor);
1583     thisObject->m_initializePromiseFunction.visit(visitor);
1584     thisObject->m_iteratorProtocolFunction.visit(visitor);
1585     thisObject->m_promiseResolveFunction.visit(visitor);
1586     visitor.append(thisObject->m_objectProtoValueOfFunction);
1587     visitor.append(thisObject->m_numberProtoToStringFunction);
1588     visitor.append(thisObject->m_newPromiseCapabilityFunction);
1589     visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
1590     thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1591     visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1592     thisObject->m_moduleLoader.visit(visitor);
1593
1594     visitor.append(thisObject->m_objectPrototype);
1595     visitor.append(thisObject->m_functionPrototype);
1596     visitor.append(thisObject->m_arrayPrototype);
1597     visitor.append(thisObject->m_errorPrototype);
1598     visitor.append(thisObject->m_iteratorPrototype);
1599     visitor.append(thisObject->m_generatorFunctionPrototype);
1600     visitor.append(thisObject->m_generatorPrototype);
1601     visitor.append(thisObject->m_asyncFunctionPrototype);
1602     visitor.append(thisObject->m_asyncGeneratorPrototype);
1603     visitor.append(thisObject->m_asyncIteratorPrototype);
1604     visitor.append(thisObject->m_asyncGeneratorFunctionPrototype);
1605
1606     thisObject->m_debuggerScopeStructure.visit(visitor);
1607     thisObject->m_withScopeStructure.visit(visitor);
1608     visitor.append(thisObject->m_strictEvalActivationStructure);
1609     visitor.append(thisObject->m_lexicalEnvironmentStructure);
1610     thisObject->m_moduleEnvironmentStructure.visit(visitor);
1611     visitor.append(thisObject->m_directArgumentsStructure);
1612     visitor.append(thisObject->m_scopedArgumentsStructure);
1613     visitor.append(thisObject->m_clonedArgumentsStructure);
1614     visitor.append(thisObject->m_objectStructureForObjectConstructor);
1615     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1616         visitor.append(thisObject->m_originalArrayStructureForIndexingShape[i]);
1617     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1618         visitor.append(thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1619     thisObject->m_callbackConstructorStructure.visit(visitor);
1620     thisObject->m_callbackFunctionStructure.visit(visitor);
1621     thisObject->m_callbackObjectStructure.visit(visitor);
1622 #if JSC_OBJC_API_ENABLED
1623     thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1624     thisObject->m_objcWrapperObjectStructure.visit(visitor);
1625 #endif
1626 #ifdef JSC_GLIB_API_ENABLED
1627     thisObject->m_glibCallbackFunctionStructure.visit(visitor);
1628     thisObject->m_glibWrapperObjectStructure.visit(visitor);
1629 #endif
1630     visitor.append(thisObject->m_nullPrototypeObjectStructure);
1631     visitor.append(thisObject->m_errorStructure);
1632     visitor.append(thisObject->m_calleeStructure);
1633
1634     visitor.append(thisObject->m_hostFunctionStructure);
1635     auto visitFunctionStructures = [&] (FunctionStructures& structures) {
1636         visitor.append(structures.arrowFunctionStructure);
1637         visitor.append(structures.sloppyFunctionStructure);
1638         visitor.append(structures.strictFunctionStructure);
1639     };
1640     visitFunctionStructures(thisObject->m_builtinFunctions);
1641     visitFunctionStructures(thisObject->m_ordinaryFunctions);
1642
1643     thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
1644     thisObject->m_boundFunctionStructure.visit(visitor);
1645     visitor.append(thisObject->m_getterSetterStructure);
1646     thisObject->m_nativeStdFunctionStructure.visit(visitor);
1647     visitor.append(thisObject->m_bigIntObjectStructure);
1648     visitor.append(thisObject->m_regExpStructure);
1649     visitor.append(thisObject->m_generatorFunctionStructure);
1650     visitor.append(thisObject->m_asyncFunctionStructure);
1651     visitor.append(thisObject->m_asyncGeneratorFunctionStructure);
1652     visitor.append(thisObject->m_iteratorResultObjectStructure);
1653     visitor.append(thisObject->m_regExpMatchesArrayStructure);
1654     visitor.append(thisObject->m_regExpMatchesArrayWithGroupsStructure);
1655     visitor.append(thisObject->m_moduleRecordStructure);
1656     visitor.append(thisObject->m_moduleNamespaceObjectStructure);
1657     visitor.append(thisObject->m_proxyObjectStructure);
1658     visitor.append(thisObject->m_callableProxyObjectStructure);
1659     visitor.append(thisObject->m_proxyRevokeStructure);
1660     
1661     visitor.append(thisObject->m_arrayBufferPrototype);
1662     visitor.append(thisObject->m_arrayBufferStructure);
1663 #if ENABLE(SHARED_ARRAY_BUFFER)
1664     visitor.append(thisObject->m_sharedArrayBufferPrototype);
1665     visitor.append(thisObject->m_sharedArrayBufferStructure);
1666 #endif
1667
1668 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
1669         visitor.append(thisObject->m_ ## lowerName ## Prototype); \
1670         visitor.append(thisObject->m_ ## properName ## Structure); \
1671     } while (0);
1672
1673     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1674     if (UNLIKELY(Options::useBigInt()))
1675         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(VISIT_SIMPLE_TYPE)
1676     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
1677     
1678 #if ENABLE(WEBASSEMBLY)
1679     visitor.append(thisObject->m_webAssemblyStructure);
1680     visitor.append(thisObject->m_webAssemblyModuleRecordStructure);
1681     visitor.append(thisObject->m_webAssemblyFunctionStructure);
1682     visitor.append(thisObject->m_webAssemblyWrapperFunctionStructure);
1683     visitor.append(thisObject->m_webAssemblyToJSCalleeStructure);
1684     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_SIMPLE_TYPE)
1685 #endif // ENABLE(WEBASSEMBLY)
1686
1687 #undef VISIT_SIMPLE_TYPE
1688
1689 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1690     thisObject->m_ ## properName ## Structure.visit(visitor);
1691     
1692     FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1693
1694 #undef VISIT_LAZY_TYPE
1695
1696     for (unsigned i = NumberOfTypedArrayTypes; i--;)
1697         thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1698     
1699     visitor.append(thisObject->m_speciesGetterSetter);
1700     thisObject->m_typedArrayProto.visit(visitor);
1701     thisObject->m_typedArraySuperConstructor.visit(visitor);
1702     thisObject->m_regExpGlobalData.visitAggregate(visitor);
1703 }
1704
1705 ExecState* JSGlobalObject::globalExec()
1706 {
1707     return CallFrame::create(m_globalCallFrame);
1708 }
1709
1710 void JSGlobalObject::exposeDollarVM(VM& vm)
1711 {
1712     if (hasOwnProperty(globalExec(), vm.propertyNames->builtinNames().dollarVMPrivateName()))
1713         return;
1714
1715     JSDollarVM* dollarVM = JSDollarVM::create(vm, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
1716
1717     GlobalPropertyInfo extraStaticGlobals[] = {
1718         GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1719     };
1720     addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
1721
1722     putDirect(vm, Identifier::fromString(globalExec(), "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
1723 }
1724
1725 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1726 {
1727     ScopeOffset startOffset = addVariables(count, jsUndefined());
1728
1729     for (int i = 0; i < count; ++i) {
1730         GlobalPropertyInfo& global = globals[i];
1731         // This `configurable = false` is necessary condition for static globals,
1732         // otherwise lexical bindings can change the result of GlobalVar queries too.
1733         // We won't be able to declare a global lexical variable with the sanem name to
1734         // the static globals because configurable = false.
1735         ASSERT(global.attributes & PropertyAttribute::DontDelete);
1736         
1737         WatchpointSet* watchpointSet = nullptr;
1738         WriteBarrierBase<Unknown>* variable = nullptr;
1739         {
1740             ConcurrentJSLocker locker(symbolTable()->m_lock);
1741             ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1742             RELEASE_ASSERT(offset == startOffset + i);
1743             SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1744             newEntry.prepareToWatch();
1745             watchpointSet = newEntry.watchpointSet();
1746             symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1747             variable = &variableAt(offset);
1748         }
1749         symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1750     }
1751 }
1752
1753 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1754 {
1755     if (Base::getOwnPropertySlot(object, exec, propertyName, slot))
1756         return true;
1757     return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
1758 }
1759
1760 void JSGlobalObject::clearRareData(JSCell* cell)
1761 {
1762     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1763 }
1764
1765 void slowValidateCell(JSGlobalObject* globalObject)
1766 {
1767     RELEASE_ASSERT(globalObject->isGlobalObject());
1768     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1769 }
1770
1771 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1772 {
1773 #if ENABLE(REMOTE_INSPECTOR)
1774     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1775 #else
1776     UNUSED_PARAM(enabled);
1777 #endif
1778 }
1779
1780 bool JSGlobalObject::remoteDebuggingEnabled() const
1781 {
1782 #if ENABLE(REMOTE_INSPECTOR)
1783     return m_inspectorDebuggable->remoteDebuggingAllowed();
1784 #else
1785     return false;
1786 #endif
1787 }
1788
1789 void JSGlobalObject::setName(const String& name)
1790 {
1791     m_name = name;
1792
1793 #if ENABLE(REMOTE_INSPECTOR)
1794     m_inspectorDebuggable->update();
1795 #endif
1796 }
1797
1798 # if ENABLE(INTL)
1799 static void addMissingScriptLocales(HashSet<String>& availableLocales)
1800 {
1801     if (availableLocales.contains("pa-Arab-PK"))
1802         availableLocales.add("pa-PK"_s);
1803     if (availableLocales.contains("zh-Hans-CN"))
1804         availableLocales.add("zh-CN"_s);
1805     if (availableLocales.contains("zh-Hant-HK"))
1806         availableLocales.add("zh-HK"_s);
1807     if (availableLocales.contains("zh-Hans-SG"))
1808         availableLocales.add("zh-SG"_s);
1809     if (availableLocales.contains("zh-Hant-TW"))
1810         availableLocales.add("zh-TW"_s);
1811 }
1812
1813 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1814 {
1815     if (m_intlCollatorAvailableLocales.isEmpty()) {
1816         int32_t count = ucol_countAvailable();
1817         for (int32_t i = 0; i < count; ++i) {
1818             String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i));
1819             if (!locale.isEmpty())
1820                 m_intlCollatorAvailableLocales.add(locale);
1821         }
1822         addMissingScriptLocales(m_intlCollatorAvailableLocales);
1823     }
1824     return m_intlCollatorAvailableLocales;
1825 }
1826
1827 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1828 {
1829     if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1830         int32_t count = udat_countAvailable();
1831         for (int32_t i = 0; i < count; ++i) {
1832             String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i));
1833             if (!locale.isEmpty())
1834                 m_intlDateTimeFormatAvailableLocales.add(locale);
1835         }
1836         addMissingScriptLocales(m_intlDateTimeFormatAvailableLocales);
1837     }
1838     return m_intlDateTimeFormatAvailableLocales;
1839 }
1840
1841 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1842 {
1843     if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1844         int32_t count = unum_countAvailable();
1845         for (int32_t i = 0; i < count; ++i) {
1846             String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i));
1847             if (!locale.isEmpty())
1848                 m_intlNumberFormatAvailableLocales.add(locale);
1849         }
1850         addMissingScriptLocales(m_intlNumberFormatAvailableLocales);
1851     }
1852     return m_intlNumberFormatAvailableLocales;
1853 }
1854
1855 const HashSet<String>& JSGlobalObject::intlPluralRulesAvailableLocales()
1856 {
1857     if (m_intlPluralRulesAvailableLocales.isEmpty()) {
1858         int32_t count = uloc_countAvailable();
1859         for (int32_t i = 0; i < count; ++i) {
1860             String locale = convertICULocaleToBCP47LanguageTag(uloc_getAvailable(i));
1861             if (!locale.isEmpty())
1862                 m_intlPluralRulesAvailableLocales.add(locale);
1863         }
1864         addMissingScriptLocales(m_intlPluralRulesAvailableLocales);
1865     }
1866     return m_intlPluralRulesAvailableLocales;
1867 }
1868 #endif // ENABLE(INTL)
1869
1870 void JSGlobalObject::bumpGlobalLexicalBindingEpoch(VM& vm)
1871 {
1872     if (++m_globalLexicalBindingEpoch == Options::thresholdForGlobalLexicalBindingEpoch()) {
1873         // Since the epoch overflows, we should rewrite all the CodeBlock to adjust to the newly started generation.
1874         m_globalLexicalBindingEpoch = 1;
1875         vm.heap.codeBlockSet().iterate([&] (CodeBlock* codeBlock) {
1876             if (codeBlock->globalObject() != this)
1877                 return;
1878             codeBlock->notifyLexicalBindingUpdate();
1879         });
1880     }
1881 }
1882
1883 void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
1884 {
1885     if (globalObjectMethodTable()->queueTaskToEventLoop) {
1886         globalObjectMethodTable()->queueTaskToEventLoop(*this, WTFMove(task));
1887         return;
1888     }
1889
1890     vm().queueMicrotask(*this, WTFMove(task));
1891 }
1892
1893 void JSGlobalObject::setDebugger(Debugger* debugger)
1894 {
1895     m_debugger = debugger;
1896     if (debugger)
1897         vm().ensureShadowChicken();
1898 }
1899
1900 bool JSGlobalObject::hasDebugger() const
1901
1902     return m_debugger;
1903 }
1904
1905 bool JSGlobalObject::hasInteractiveDebugger() const 
1906
1907     return m_debugger && m_debugger->isInteractivelyDebugging();
1908 }
1909
1910 #if ENABLE(DFG_JIT)
1911 WatchpointSet* JSGlobalObject::getReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
1912 {
1913     ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
1914     return m_referencedGlobalPropertyWatchpointSets.get(uid);
1915 }
1916
1917 WatchpointSet& JSGlobalObject::ensureReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
1918 {
1919     ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
1920     return m_referencedGlobalPropertyWatchpointSets.ensure(uid, [] {
1921         return WatchpointSet::create(IsWatched);
1922     }).iterator->value.get();
1923 }
1924 #endif
1925
1926 JSGlobalObject* JSGlobalObject::create(VM& vm, Structure* structure)
1927 {
1928     JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
1929     globalObject->finishCreation(vm);
1930     return globalObject;
1931 }
1932
1933 void JSGlobalObject::finishCreation(VM& vm)
1934 {
1935     Base::finishCreation(vm);
1936     structure(vm)->setGlobalObject(vm, this);
1937     m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1938     init(vm);
1939     setGlobalThis(vm, JSNonDestructibleProxy::create(vm, JSNonDestructibleProxy::createStructure(vm, this, getPrototypeDirect(vm), PureForwardingProxyType), this));
1940     ASSERT(type() == GlobalObjectType);
1941 }
1942
1943 void JSGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
1944 {
1945     Base::finishCreation(vm);
1946     structure(vm)->setGlobalObject(vm, this);
1947     m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1948     init(vm);
1949     setGlobalThis(vm, thisValue);
1950     ASSERT(type() == GlobalObjectType);
1951 }
1952
1953 #ifdef JSC_GLIB_API_ENABLED
1954 void JSGlobalObject::setWrapperMap(std::unique_ptr<WrapperMap>&& map)
1955 {
1956     m_wrapperMap = WTFMove(map);
1957 }
1958 #endif
1959
1960 } // namespace JSC