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