[JSC] Drop direct references to Intl constructors by rewriting Intl JS builtins in C++
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007-2019 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "config.h"
31 #include "JSGlobalObject.h"
32
33 #include "ArrayConstructor.h"
34 #include "ArrayIteratorPrototype.h"
35 #include "ArrayPrototype.h"
36 #include "AsyncFromSyncIteratorPrototype.h"
37 #include "AtomicsObject.h"
38 #include "AsyncFunctionConstructor.h"
39 #include "AsyncFunctionPrototype.h"
40 #include "AsyncGeneratorFunctionConstructor.h"
41 #include "AsyncGeneratorFunctionPrototype.h"
42 #include "AsyncGeneratorPrototype.h"
43 #include "AsyncIteratorPrototype.h"
44 #include "BigIntConstructor.h"
45 #include "BigIntObject.h"
46 #include "BigIntPrototype.h"
47 #include "BooleanConstructor.h"
48 #include "BooleanPrototype.h"
49 #include "BuiltinNames.h"
50 #include "CatchScope.h"
51 #include "ClonedArguments.h"
52 #include "CodeBlock.h"
53 #include "CodeBlockSetInlines.h"
54 #include "CodeCache.h"
55 #include "ConsoleObject.h"
56 #include "DateConstructor.h"
57 #include "DatePrototype.h"
58 #include "Debugger.h"
59 #include "DebuggerScope.h"
60 #include "DirectArguments.h"
61 #include "DirectEvalExecutable.h"
62 #include "ECMAScriptSpecInternalFunctions.h"
63 #include "Error.h"
64 #include "ErrorConstructor.h"
65 #include "ErrorPrototype.h"
66 #include "Exception.h"
67 #include "FunctionConstructor.h"
68 #include "FunctionPrototype.h"
69 #include "GeneratorFunctionConstructor.h"
70 #include "GeneratorFunctionPrototype.h"
71 #include "GeneratorPrototype.h"
72 #include "GetterSetter.h"
73 #include "HeapIterationScope.h"
74 #include "IndirectEvalExecutable.h"
75 #include "InspectorInstrumentationObject.h"
76 #include "Interpreter.h"
77 #include "IteratorPrototype.h"
78 #include "JSAPIWrapperObject.h"
79 #include "JSArrayBuffer.h"
80 #include "JSArrayBufferConstructor.h"
81 #include "JSArrayBufferPrototype.h"
82 #include "JSAsyncFunction.h"
83 #include "JSAsyncGeneratorFunction.h"
84 #include "JSBigInt.h"
85 #include "JSBoundFunction.h"
86 #include "JSCInlines.h"
87 #include "JSCallbackConstructor.h"
88 #include "JSCallbackFunction.h"
89 #include "JSCallbackObject.h"
90 #include "JSCustomGetterSetterFunction.h"
91 #include "JSDataView.h"
92 #include "JSDataViewPrototype.h"
93 #include "JSDollarVM.h"
94 #include "JSFunction.h"
95 #include "JSGeneratorFunction.h"
96 #include "JSGenericTypedArrayViewConstructorInlines.h"
97 #include "JSGenericTypedArrayViewInlines.h"
98 #include "JSGenericTypedArrayViewPrototypeInlines.h"
99 #include "JSGlobalObjectFunctions.h"
100 #include "JSInternalPromise.h"
101 #include "JSInternalPromiseConstructor.h"
102 #include "JSInternalPromisePrototype.h"
103 #include "JSLexicalEnvironment.h"
104 #include "JSLock.h"
105 #include "JSMap.h"
106 #include "JSMicrotask.h"
107 #include "JSModuleEnvironment.h"
108 #include "JSModuleLoader.h"
109 #include "JSModuleNamespaceObject.h"
110 #include "JSModuleRecord.h"
111 #include "JSNativeStdFunction.h"
112 #include "JSNonDestructibleProxy.h"
113 #include "JSONObject.h"
114 #include "JSPromise.h"
115 #include "JSPromiseConstructor.h"
116 #include "JSPromisePrototype.h"
117 #include "JSSet.h"
118 #include "JSStringIterator.h"
119 #include "JSTypedArrayConstructors.h"
120 #include "JSTypedArrayPrototypes.h"
121 #include "JSTypedArrayViewConstructor.h"
122 #include "JSTypedArrayViewPrototype.h"
123 #include "JSTypedArrays.h"
124 #include "JSWeakMap.h"
125 #include "JSWeakSet.h"
126 #include "JSWebAssembly.h"
127 #include "JSWithScope.h"
128 #include "LazyClassStructureInlines.h"
129 #include "LazyPropertyInlines.h"
130 #include "Lookup.h"
131 #include "MapConstructor.h"
132 #include "MapIteratorPrototype.h"
133 #include "MapPrototype.h"
134 #include "MarkedSpaceInlines.h"
135 #include "MathObject.h"
136 #include "Microtask.h"
137 #include "NativeErrorConstructor.h"
138 #include "NativeErrorPrototype.h"
139 #include "NullGetterFunction.h"
140 #include "NullSetterFunction.h"
141 #include "NumberConstructor.h"
142 #include "NumberPrototype.h"
143 #include "ObjCCallbackFunction.h"
144 #include "ObjectConstructor.h"
145 #include "ObjectPropertyChangeAdaptiveWatchpoint.h"
146 #include "ObjectPropertyConditionSet.h"
147 #include "ObjectPrototype.h"
148 #include "ParserError.h"
149 #include "ProxyConstructor.h"
150 #include "ProxyObject.h"
151 #include "ProxyRevoke.h"
152 #include "ReflectObject.h"
153 #include "RegExpCache.h"
154 #include "RegExpConstructor.h"
155 #include "RegExpMatchesArray.h"
156 #include "RegExpObject.h"
157 #include "RegExpPrototype.h"
158 #include "ScopedArguments.h"
159 #include "SetConstructor.h"
160 #include "SetIteratorPrototype.h"
161 #include "SetPrototype.h"
162 #include "StrictEvalActivation.h"
163 #include "StringConstructor.h"
164 #include "StringIteratorPrototype.h"
165 #include "StringPrototype.h"
166 #include "Symbol.h"
167 #include "SymbolConstructor.h"
168 #include "SymbolObject.h"
169 #include "SymbolPrototype.h"
170 #include "VariableWriteFireDetail.h"
171 #include "WeakGCMapInlines.h"
172 #include "WeakMapConstructor.h"
173 #include "WeakMapPrototype.h"
174 #include "WeakSetConstructor.h"
175 #include "WeakSetPrototype.h"
176 #include "WebAssemblyPrototype.h"
177 #include "WebAssemblyToJSCallee.h"
178 #include <wtf/RandomNumber.h>
179
180 #if ENABLE(INTL)
181 #include "IntlCollator.h"
182 #include "IntlObject.h"
183 #include <unicode/ucol.h>
184 #include <unicode/udat.h>
185 #include <unicode/unum.h>
186 #endif // ENABLE(INTL)
187
188 #if ENABLE(REMOTE_INSPECTOR)
189 #include "JSGlobalObjectDebuggable.h"
190 #include "JSGlobalObjectInspectorController.h"
191 #endif
192
193 #ifdef JSC_GLIB_API_ENABLED
194 #include "JSCCallbackFunction.h"
195 #include "JSCWrapperMap.h"
196 #endif
197
198 namespace JSC {
199
200 static JSValue createProxyProperty(VM& vm, JSObject* object)
201 {
202     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
203     return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
204 }
205
206 static JSValue createJSONProperty(VM& vm, JSObject* object)
207 {
208     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
209     return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
210 }
211
212 static JSValue createMathProperty(VM& vm, JSObject* object)
213 {
214     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
215     return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
216 }
217
218 static JSValue createConsoleProperty(VM& vm, JSObject* object)
219 {
220     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
221     return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
222 }
223
224 static EncodedJSValue JSC_HOST_CALL makeBoundFunction(ExecState* exec)
225 {
226     VM& vm = exec->vm();
227     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
228
229     JSObject* target = asObject(exec->uncheckedArgument(0));
230     JSValue boundThis = exec->uncheckedArgument(1);
231     JSValue boundArgs = exec->uncheckedArgument(2);
232     JSValue length = exec->uncheckedArgument(3);
233     JSString* name = asString(exec->uncheckedArgument(4));
234
235     return JSValue::encode(JSBoundFunction::create(
236         vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length.asInt32(), name->value(exec)));
237 }
238
239 static EncodedJSValue JSC_HOST_CALL hasOwnLengthProperty(ExecState* exec)
240 {
241     VM& vm = exec->vm();
242     JSObject* target = asObject(exec->uncheckedArgument(0));
243     return JSValue::encode(jsBoolean(target->hasOwnProperty(exec, vm.propertyNames->length)));
244 }
245
246 #if !ASSERT_DISABLED
247 static EncodedJSValue JSC_HOST_CALL assertCall(ExecState* exec)
248 {
249     RELEASE_ASSERT(exec->argument(0).isBoolean());
250     if (exec->argument(0).asBoolean())
251         return JSValue::encode(jsUndefined());
252
253     bool iteratedOnce = false;
254     CodeBlock* codeBlock = nullptr;
255     unsigned line;
256     exec->iterate([&] (StackVisitor& visitor) {
257         if (!iteratedOnce) {
258             iteratedOnce = true;
259             return StackVisitor::Continue;
260         }
261
262         RELEASE_ASSERT(visitor->hasLineAndColumnInfo());
263         unsigned column;
264         visitor->computeLineAndColumn(line, column);
265         codeBlock = visitor->codeBlock();
266         return StackVisitor::Done;
267     });
268     RELEASE_ASSERT(!!codeBlock);
269     RELEASE_ASSERT_WITH_MESSAGE(false, "JS assertion failed at line %u in:\n%s\n", line, codeBlock->sourceCodeForTools().data());
270     return JSValue::encode(jsUndefined());
271 }
272 #endif
273
274 } // namespace JSC
275
276 #include "JSGlobalObject.lut.h"
277
278 namespace JSC {
279
280 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, nullptr, CREATE_METHOD_TABLE(JSGlobalObject) };
281
282 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
283     &supportsRichSourceInfo,
284     &shouldInterruptScript,
285     &javaScriptRuntimeFlags,
286     nullptr, // queueTaskToEventLoop
287     &shouldInterruptScriptBeforeTimeout,
288     nullptr, // moduleLoaderImportModule
289     nullptr, // moduleLoaderResolve
290     nullptr, // moduleLoaderFetch
291     nullptr, // moduleLoaderCreateImportMetaProperties
292     nullptr, // moduleLoaderEvaluate
293     nullptr, // promiseRejectionTracker
294     nullptr, // defaultLanguage
295     nullptr, // compileStreaming
296     nullptr, // instantiateStreaming
297 };
298
299 /* Source for JSGlobalObject.lut.h
300 @begin globalObjectTable
301   isNaN                 JSBuiltin                                    DontEnum|Function 1
302   isFinite              JSBuiltin                                    DontEnum|Function 1
303   escape                globalFuncEscape                             DontEnum|Function 1
304   unescape              globalFuncUnescape                           DontEnum|Function 1
305   decodeURI             globalFuncDecodeURI                          DontEnum|Function 1
306   decodeURIComponent    globalFuncDecodeURIComponent                 DontEnum|Function 1
307   encodeURI             globalFuncEncodeURI                          DontEnum|Function 1
308   encodeURIComponent    globalFuncEncodeURIComponent                 DontEnum|Function 1
309   globalThis            JSGlobalObject::m_globalThis                 DontEnum|CellProperty
310   EvalError             JSGlobalObject::m_evalErrorStructure         DontEnum|ClassStructure
311   RangeError            JSGlobalObject::m_rangeErrorStructure        DontEnum|ClassStructure
312   ReferenceError        JSGlobalObject::m_referenceErrorStructure    DontEnum|ClassStructure
313   SyntaxError           JSGlobalObject::m_syntaxErrorStructure       DontEnum|ClassStructure
314   TypeError             JSGlobalObject::m_typeErrorStructure         DontEnum|ClassStructure
315   URIError              JSGlobalObject::m_URIErrorStructure          DontEnum|ClassStructure
316   Proxy                 createProxyProperty                          DontEnum|PropertyCallback
317   JSON                  createJSONProperty                           DontEnum|PropertyCallback
318   Math                  createMathProperty                           DontEnum|PropertyCallback
319   console               createConsoleProperty                        DontEnum|PropertyCallback
320   Int8Array             JSGlobalObject::m_typedArrayInt8             DontEnum|ClassStructure
321   Int16Array            JSGlobalObject::m_typedArrayInt16            DontEnum|ClassStructure
322   Int32Array            JSGlobalObject::m_typedArrayInt32            DontEnum|ClassStructure
323   Uint8Array            JSGlobalObject::m_typedArrayUint8            DontEnum|ClassStructure
324   Uint8ClampedArray     JSGlobalObject::m_typedArrayUint8Clamped     DontEnum|ClassStructure
325   Uint16Array           JSGlobalObject::m_typedArrayUint16           DontEnum|ClassStructure
326   Uint32Array           JSGlobalObject::m_typedArrayUint32           DontEnum|ClassStructure
327   Float32Array          JSGlobalObject::m_typedArrayFloat32          DontEnum|ClassStructure
328   Float64Array          JSGlobalObject::m_typedArrayFloat64          DontEnum|ClassStructure
329   DataView              JSGlobalObject::m_typedArrayDataView         DontEnum|ClassStructure
330   Date                  JSGlobalObject::m_dateStructure              DontEnum|ClassStructure
331   Boolean               JSGlobalObject::m_booleanObjectStructure     DontEnum|ClassStructure
332   Number                JSGlobalObject::m_numberObjectStructure      DontEnum|ClassStructure
333   Symbol                JSGlobalObject::m_symbolObjectStructure      DontEnum|ClassStructure
334   WeakMap               JSGlobalObject::m_weakMapStructure           DontEnum|ClassStructure
335   WeakSet               JSGlobalObject::m_weakSetStructure           DontEnum|ClassStructure
336 @end
337 */
338
339 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
340 {
341     VM& vm = exec->vm();
342     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
343
344     JSValue job = exec->argument(0);
345     JSValue arguments = exec->argument(1);
346     ASSERT(arguments.inherits<JSArray>(vm));
347
348     globalObject->queueMicrotask(createJSMicrotask(vm, job, jsCast<JSArray*>(arguments)));
349
350     return JSValue::encode(jsUndefined());
351 }
352
353 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
354     : Base(vm, structure, 0)
355     , m_vm(vm)
356     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
357     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
358     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
359     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
360     , m_arrayIteratorProtocolWatchpoint(IsWatched)
361     , m_mapIteratorProtocolWatchpoint(IsWatched)
362     , m_setIteratorProtocolWatchpoint(IsWatched)
363     , m_stringIteratorProtocolWatchpoint(IsWatched)
364     , m_mapSetWatchpoint(IsWatched)
365     , m_setAddWatchpoint(IsWatched)
366     , m_arraySpeciesWatchpoint(ClearWatchpoint)
367     , m_numberToStringWatchpoint(IsWatched)
368     , m_runtimeFlags()
369     , m_stackTraceLimit(Options::defaultErrorStackTraceLimit())
370     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
371 {
372 }
373
374 JSGlobalObject::~JSGlobalObject()
375 {
376 #if ENABLE(REMOTE_INSPECTOR)
377     m_inspectorController->globalObjectDestroyed();
378 #endif
379
380     if (m_debugger)
381         m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
382 }
383
384 void JSGlobalObject::destroy(JSCell* cell)
385 {
386     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
387 }
388
389 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
390 {
391     m_globalThis.set(vm, this, globalThis);
392 }
393
394 static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
395 {
396     JSValue baseValue = JSValue(base);
397     PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
398     baseValue.getPropertySlot(exec, ident, slot);
399     return slot.getPureResult().toObject(exec);
400 }
401
402 template<ErrorType errorType>
403 void JSGlobalObject::initializeErrorConstructor(LazyClassStructure::Initializer& init)
404 {
405     init.setPrototype(NativeErrorPrototype::create(init.vm, NativeErrorPrototype::createStructure(init.vm, this, m_errorPrototype.get()), errorTypeName(errorType)));
406     init.setStructure(ErrorInstance::createStructure(init.vm, this, init.prototype));
407     init.setConstructor(NativeErrorConstructor<errorType>::create(init.vm, NativeErrorConstructor<errorType>::createStructure(init.vm, this, m_errorConstructor.get()), jsCast<NativeErrorPrototype*>(init.prototype)));
408 }
409
410 void JSGlobalObject::init(VM& vm)
411 {
412     ASSERT(vm.currentThreadIsHoldingAPILock());
413     auto catchScope = DECLARE_CATCH_SCOPE(vm);
414
415     Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure(vm)));
416
417     m_debugger = 0;
418
419 #if ENABLE(REMOTE_INSPECTOR)
420     m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
421     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
422     m_inspectorDebuggable->init();
423     m_consoleClient = m_inspectorController->consoleClient();
424 #endif
425
426     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
427     m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
428
429     m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
430     // Need to create the callee structure (above) before creating the callee.
431     JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
432     m_globalCallee.set(vm, this, globalCallee);
433
434     ExecState::initGlobalExec(JSGlobalObject::globalExec(), globalCallee);
435     ExecState* exec = JSGlobalObject::globalExec();
436
437     JSCallee* stackOverflowFrameCallee = JSCallee::create(vm, this, globalScope());
438     m_stackOverflowFrameCallee.set(vm, this, stackOverflowFrameCallee);
439
440     m_hostFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
441
442     auto initFunctionStructures = [&] (FunctionStructures& structures) {
443         structures.strictFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
444         structures.sloppyFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
445         structures.arrowFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
446     };
447     initFunctionStructures(m_builtinFunctions);
448     initFunctionStructures(m_ordinaryFunctions);
449
450     m_customGetterSetterFunctionStructure.initLater(
451         [] (const Initializer<Structure>& init) {
452             init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
453         });
454     m_boundFunctionStructure.initLater(
455         [] (const Initializer<Structure>& init) {
456             init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
457         });
458     m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
459     m_nativeStdFunctionStructure.initLater(
460         [] (const Initializer<Structure>& init) {
461             init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
462         });
463     JSFunction* callFunction = nullptr;
464     JSFunction* applyFunction = nullptr;
465     JSFunction* hasInstanceSymbolFunction = nullptr;
466     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
467     m_callFunction.set(vm, this, callFunction);
468     m_applyFunction.set(vm, this, applyFunction);
469     m_arrayProtoToStringFunction.initLater(
470         [] (const Initializer<JSFunction>& init) {
471             init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
472         });
473     m_arrayProtoValuesFunction.initLater(
474         [] (const Initializer<JSFunction>& init) {
475             init.set(JSFunction::create(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
476         });
477     m_initializePromiseFunction.initLater(
478         [] (const Initializer<JSFunction>& init) {
479             init.set(JSFunction::create(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
480         });
481
482     m_iteratorProtocolFunction.initLater(
483         [] (const Initializer<JSFunction>& init) {
484             init.set(JSFunction::create(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
485         });
486
487     m_promiseResolveFunction.initLater(
488         [] (const Initializer<JSFunction>& init) {
489             init.set(JSFunction::create(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
490         });
491
492     m_newPromiseCapabilityFunction.set(vm, this, JSFunction::create(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
493     m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
494     m_throwTypeErrorGetterSetter.initLater(
495         [] (const Initializer<GetterSetter>& init) {
496             JSFunction* thrower = init.owner->throwTypeErrorFunction();
497             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner, thrower, thrower);
498             init.set(getterSetter);
499         });
500
501     m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
502     m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
503     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
504     GetterSetter* protoAccessor = GetterSetter::create(vm, this,
505         JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter, UnderscoreProtoIntrinsic),
506         JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
507     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, PropertyAttribute::Accessor | PropertyAttribute::DontEnum);
508     m_functionPrototype->structure(vm)->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
509     m_objectStructureForObjectConstructor.set(vm, this, vm.structureCache.emptyObjectStructureForPrototype(this, m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
510     m_objectProtoValueOfFunction.set(vm, this, jsCast<JSFunction*>(objectPrototype()->getDirect(vm, vm.propertyNames->valueOf)));
511     
512     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
513     GetterSetter* getterSetter = GetterSetter::create(vm, this, thrower, thrower);
514     m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
515     
516     m_functionPrototype->initRestrictedProperties(exec, this);
517
518     m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this, JSFunction::create(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this), nullptr));
519
520     m_typedArrayProto.initLater(
521         [] (const Initializer<JSTypedArrayViewPrototype>& init) {
522             init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
523             
524             // Make sure that the constructor gets initialized, too.
525             init.owner->m_typedArraySuperConstructor.get(init.owner);
526         });
527     m_typedArraySuperConstructor.initLater(
528         [] (const Initializer<JSTypedArrayViewConstructor>& init) {
529             JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
530             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());
531             prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
532             init.set(constructor);
533         });
534     
535 #define INIT_TYPED_ARRAY_LATER(type) \
536     m_typedArray ## type.initLater( \
537         [] (LazyClassStructure::Initializer& init) { \
538             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)))); \
539             init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
540             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))); \
541             init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
542         });
543     FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
544 #undef INIT_TYPED_ARRAY_LATER
545     
546     m_typedArrayDataView.initLater(
547         [] (LazyClassStructure::Initializer& init) {
548             init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
549             init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
550             init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, "DataView"_s, nullptr));
551         });
552     
553     m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
554     m_moduleEnvironmentStructure.initLater(
555         [] (const Initializer<Structure>& init) {
556             init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
557         });
558     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
559     m_debuggerScopeStructure.initLater(
560         [] (const Initializer<Structure>& init) {
561             init.set(DebuggerScope::createStructure(init.vm, init.owner));
562         });
563     m_withScopeStructure.initLater(
564         [] (const Initializer<Structure>& init) {
565             init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
566         });
567     
568     m_nullPrototypeObjectStructure.set(vm, this, JSFinalObject::createStructure(vm, this, jsNull(), JSFinalObject::defaultInlineCapacity()));
569     
570     m_callbackFunctionStructure.initLater(
571         [] (const Initializer<Structure>& init) {
572             init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
573         });
574     m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
575     m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
576     m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
577     m_callbackConstructorStructure.initLater(
578         [] (const Initializer<Structure>& init) {
579             init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
580         });
581     m_callbackObjectStructure.initLater(
582         [] (const Initializer<Structure>& init) {
583             init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
584         });
585
586 #if JSC_OBJC_API_ENABLED
587     m_objcCallbackFunctionStructure.initLater(
588         [] (const Initializer<Structure>& init) {
589             init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
590         });
591     m_objcWrapperObjectStructure.initLater(
592         [] (const Initializer<Structure>& init) {
593             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
594         });
595 #endif
596 #ifdef JSC_GLIB_API_ENABLED
597     m_glibCallbackFunctionStructure.initLater(
598         [] (const Initializer<Structure>& init) {
599             init.set(JSCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
600         });
601     m_glibWrapperObjectStructure.initLater(
602         [] (const Initializer<Structure>& init) {
603             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
604         });
605 #endif
606     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
607     
608     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(UndecidedShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
609     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(Int32Shape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
610     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(DoubleShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
611     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ContiguousShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
612     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(ArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
613     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(SlowPutArrayStorageShape)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
614     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithInt32)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithInt32));
615     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithDouble)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithDouble));
616     m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous)].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), CopyOnWriteArrayWithContiguous));
617     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
618         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
619
620     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
621     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
622     m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
623     m_regExpMatchesArrayWithGroupsStructure.set(vm, this, createRegExpMatchesArrayWithGroupsStructure(vm, this));
624
625     m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, jsNull()));
626     m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
627     {
628         bool isCallable = false;
629         m_proxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
630         isCallable = true;
631         m_callableProxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
632     }
633     m_proxyRevokeStructure.set(vm, this, ProxyRevoke::createStructure(vm, this, m_functionPrototype.get()));
634
635     m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, ParseIntIntrinsic));
636     putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
637     m_parseFloatFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->parseFloat.string(), globalFuncParseFloat, NoIntrinsic));
638     putDirectWithoutTransition(vm, vm.propertyNames->parseFloat, m_parseFloatFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
639     
640     m_arrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Default));
641     m_arrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_arrayBufferPrototype.get()));
642 #if ENABLE(SHARED_ARRAY_BUFFER)
643     m_sharedArrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
644     m_sharedArrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_sharedArrayBufferPrototype.get()));
645 #endif
646
647     m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
648     m_asyncIteratorPrototype.set(vm, this, AsyncIteratorPrototype::create(vm, this, AsyncIteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
649
650     m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
651     m_asyncGeneratorPrototype.set(vm, this, AsyncGeneratorPrototype::create(vm, this, AsyncGeneratorPrototype::createStructure(vm, this, m_asyncIteratorPrototype.get())));
652
653 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
654         m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
655         m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get())); \
656     } while (0);
657     
658     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
659
660     if (UNLIKELY(Options::useBigInt()))
661         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
662
663     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
664     
665 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
666
667 #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
668     m_ ## properName ## Structure.initLater(\
669         [] (LazyClassStructure::Initializer& init) { \
670             init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
671             init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
672             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())); \
673         });
674     
675     FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
676     
677 #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
678     
679     // Constructors
680
681     ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
682     m_objectConstructor.set(vm, this, objectConstructor);
683
684     JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
685     m_throwTypeErrorFunction.set(vm, this, throwTypeErrorFunction);
686
687     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
688
689     ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
690     m_arrayConstructor.set(vm, this, arrayConstructor);
691     
692     RegExpConstructor* regExpConstructor = RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get());
693     m_regExpGlobalData.cachedResult().record(vm, this, nullptr, jsEmptyString(&vm), MatchResult(0, 0));
694     
695     JSArrayBufferConstructor* arrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayBufferPrototype.get(), m_speciesGetterSetter.get());
696     m_arrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
697
698 #if ENABLE(SHARED_ARRAY_BUFFER)
699     JSSharedArrayBufferConstructor* sharedArrayBufferConstructor = nullptr;
700     sharedArrayBufferConstructor = JSSharedArrayBufferConstructor::create(vm, JSSharedArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_sharedArrayBufferPrototype.get(), m_speciesGetterSetter.get());
701     m_sharedArrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
702
703     AtomicsObject* atomicsObject = AtomicsObject::create(vm, this, AtomicsObject::createStructure(vm, this, m_objectPrototype.get()));
704 #endif
705
706 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
707 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
708 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
709
710     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
711     BigIntConstructor* bigIntConstructor = nullptr;
712     if (UNLIKELY(Options::useBigInt())) {
713         bigIntConstructor = BigIntConstructor::create(vm, BigIntConstructor::createStructure(vm, this, m_functionPrototype.get()), m_bigIntPrototype.get(), m_speciesGetterSetter.get());
714         m_bigIntPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, bigIntConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
715     }
716     
717 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
718
719     m_promiseConstructor.set(vm, this, promiseConstructor);
720     m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
721     
722     m_errorConstructor.set(vm, this, errorConstructor);
723     m_evalErrorStructure.initLater(
724         [] (LazyClassStructure::Initializer& init) {
725             init.global->initializeErrorConstructor<ErrorType::EvalError>(init);
726         });
727     m_rangeErrorStructure.initLater(
728         [] (LazyClassStructure::Initializer& init) {
729             init.global->initializeErrorConstructor<ErrorType::RangeError>(init);
730         });
731     m_referenceErrorStructure.initLater(
732         [] (LazyClassStructure::Initializer& init) {
733             init.global->initializeErrorConstructor<ErrorType::ReferenceError>(init);
734         });
735     m_syntaxErrorStructure.initLater(
736         [] (LazyClassStructure::Initializer& init) {
737             init.global->initializeErrorConstructor<ErrorType::SyntaxError>(init);
738         });
739     m_typeErrorStructure.initLater(
740         [] (LazyClassStructure::Initializer& init) {
741             init.global->initializeErrorConstructor<ErrorType::TypeError>(init);
742         });
743     m_URIErrorStructure.initLater(
744         [] (LazyClassStructure::Initializer& init) {
745             init.global->initializeErrorConstructor<ErrorType::URIError>(init);
746         });
747
748     m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
749     GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
750     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
751     m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
752
753     m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
754     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
755
756     m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
757     AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
758     m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
759     m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
760
761     m_asyncGeneratorFunctionPrototype.set(vm, this, AsyncGeneratorFunctionPrototype::create(vm, AsyncGeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
762     AsyncGeneratorFunctionConstructor* asyncGeneratorFunctionConstructor = AsyncGeneratorFunctionConstructor::create(vm, AsyncGeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncGeneratorFunctionPrototype.get());
763     m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncGeneratorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
764     m_asyncGeneratorFunctionStructure.set(vm, this, JSAsyncGeneratorFunction::createStructure(vm, this, m_asyncGeneratorFunctionPrototype.get()));
765
766     m_asyncGeneratorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_asyncGeneratorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
767     m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_asyncGeneratorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
768     
769     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
770     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
771     m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
772     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
773     
774     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
775     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
776     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
777     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, regExpConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
778
779     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ObjectPrivateName(), objectConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
780     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ArrayPrivateName(), arrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
781
782     putDirectWithoutTransition(vm, vm.propertyNames->ArrayBuffer, arrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
783 #if ENABLE(SHARED_ARRAY_BUFFER)
784     putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
785     putDirectWithoutTransition(vm, Identifier::fromString(exec, "Atomics"), atomicsObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
786 #endif
787
788 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
789 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
790
791     FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
792     if (UNLIKELY(Options::useBigInt()))
793         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
794
795 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
796     m_iteratorResultObjectStructure.set(vm, this, createIteratorResultObjectStructure(vm, *this));
797     
798     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
799     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
800     
801 #if ENABLE(INTL)
802     IntlObject* intl = IntlObject::create(vm, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
803     putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, static_cast<unsigned>(PropertyAttribute::DontEnum));
804     m_intlObject.set(vm, this, intl);
805 #endif // ENABLE(INTL)
806     ReflectObject* reflectObject = ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get()));
807     putDirectWithoutTransition(vm, vm.propertyNames->Reflect, reflectObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
808
809     m_moduleLoader.initLater(
810         [] (const Initializer<JSModuleLoader>& init) {
811             auto catchScope = DECLARE_CATCH_SCOPE(init.vm);
812             init.set(JSModuleLoader::create(init.owner->globalExec(), init.vm, init.owner, JSModuleLoader::createStructure(init.vm, init.owner, jsNull())));
813             catchScope.releaseAssertNoException();
814         });
815     if (Options::exposeInternalModuleLoader())
816         putDirectWithoutTransition(vm, vm.propertyNames->Loader, moduleLoader(), static_cast<unsigned>(PropertyAttribute::DontEnum));
817
818     JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
819     JSFunction* builtinDescribe = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinDescribe);
820
821     JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
822
823     JSFunction* privateFuncPropertyIsEnumerable = JSFunction::create(vm, this, 0, String(), globalFuncPropertyIsEnumerable);
824     JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
825     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
826     JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
827     JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
828     JSFunction* privateFuncIsTypedArrayView = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic);
829     JSFunction* privateFuncTypedArraySubarrayCreate = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSubarrayCreate);
830     JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
831     JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
832     JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
833     JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
834 #if ENABLE(INTL)
835     JSFunction* privateFuncDateTimeFormat = JSFunction::create(vm, this, 0, String(), globalFuncDateTimeFormat);
836 #endif
837     JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
838     JSFunction* privateFuncIsArraySlow = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArraySlow);
839     JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
840     JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
841     JSFunction* privateFuncMapBucketHead = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketHead, JSMapBucketHeadIntrinsic);
842     JSFunction* privateFuncMapBucketNext = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketNext, JSMapBucketNextIntrinsic);
843     JSFunction* privateFuncMapBucketKey = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketKey, JSMapBucketKeyIntrinsic);
844     JSFunction* privateFuncMapBucketValue = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketValue, JSMapBucketValueIntrinsic);
845     JSFunction* privateFuncSetBucketHead = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketHead, JSSetBucketHeadIntrinsic);
846     JSFunction* privateFuncSetBucketNext = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketNext, JSSetBucketNextIntrinsic);
847     JSFunction* privateFuncSetBucketKey = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketKey, JSSetBucketKeyIntrinsic);
848
849     JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
850     catchScope.assertNoException();
851     JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
852     catchScope.assertNoException();
853     m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
854     JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
855     catchScope.assertNoException();
856     JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
857     catchScope.assertNoException();
858     JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
859     catchScope.assertNoException();
860     JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
861     catchScope.assertNoException();
862     JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
863     catchScope.assertNoException();
864     m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
865     JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
866     m_regExpProtoExec.set(vm, this, builtinRegExpExec);
867     JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
868     m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
869
870 #define CREATE_PRIVATE_GLOBAL_FUNCTION(name, code) JSFunction* name ## PrivateFunction = JSFunction::create(vm, code ## CodeGenerator(vm), this);
871     JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(CREATE_PRIVATE_GLOBAL_FUNCTION)
872 #undef CREATE_PRIVATE_GLOBAL_FUNCTION
873
874     JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
875     createArrayIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
876
877     JSObject* asyncFromSyncIteratorPrototype = AsyncFromSyncIteratorPrototype::create(vm, this, AsyncFromSyncIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
878     AsyncFromSyncIteratorConstructorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, asyncFromSyncIteratorPrototype);
879
880     JSObject* mapIteratorPrototype = MapIteratorPrototype::create(vm, this, MapIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
881     createMapIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, mapIteratorPrototype);
882
883     JSObject* setIteratorPrototype = SetIteratorPrototype::create(vm, this, SetIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
884     createSetIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, setIteratorPrototype);
885
886     GlobalPropertyInfo staticGlobals[] = {
887 #define INIT_PRIVATE_GLOBAL(name, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().name ## PrivateName(), name ## PrivateFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
888         JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
889 #undef INIT_PRIVATE_GLOBAL
890         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
891         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
892         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
893         GlobalPropertyInfo(vm.propertyNames->builtinNames().propertyIsEnumerablePrivateName(), privateFuncPropertyIsEnumerable, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
894         GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
895         GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
896         // FIXME: Offer @makeTypeError function instead of exposing @TypeError here.
897         // https://bugs.webkit.org/show_bug.cgi?id=193858
898         GlobalPropertyInfo(vm.propertyNames->builtinNames().TypeErrorPrivateName(), m_typeErrorStructure.constructor(this), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
899         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
900         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
901         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
902         GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
903         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySubarrayCreatePrivateName(), privateFuncTypedArraySubarrayCreate, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
904         GlobalPropertyInfo(vm.propertyNames->builtinNames().isBoundFunctionPrivateName(), privateFuncIsBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
905         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasInstanceBoundFunctionPrivateName(), privateFuncHasInstanceBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
906         GlobalPropertyInfo(vm.propertyNames->builtinNames().instanceOfPrivateName(), privateFuncInstanceOf, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
907         GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinLogPrivateName(), builtinLog, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
908         GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinDescribePrivateName(), builtinDescribe, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
909         GlobalPropertyInfo(vm.propertyNames->builtinNames().RegExpPrivateName(), regExpConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
910         GlobalPropertyInfo(vm.propertyNames->builtinNames().truncPrivateName(), privateFuncTrunc, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
911         GlobalPropertyInfo(vm.propertyNames->builtinNames().PromisePrivateName(), promiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
912         GlobalPropertyInfo(vm.propertyNames->builtinNames().ReflectPrivateName(), reflectObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
913         GlobalPropertyInfo(vm.propertyNames->builtinNames().InternalPromisePrivateName(), internalPromiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
914
915         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharacterPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
916         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayPrivateName(), arrayConstructor->getDirect(vm, vm.propertyNames->isArray), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
917         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArraySlowPrivateName(), privateFuncIsArraySlow, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
918         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayConstructorPrivateName(), privateFuncIsArrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
919         GlobalPropertyInfo(vm.propertyNames->builtinNames().concatMemcpyPrivateName(), privateFuncConcatMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
920         GlobalPropertyInfo(vm.propertyNames->builtinNames().appendMemcpyPrivateName(), privateFuncAppendMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
921
922         GlobalPropertyInfo(vm.propertyNames->builtinNames().hostPromiseRejectionTrackerPrivateName(), JSFunction::create(vm, this, 2, String(), globalFuncHostPromiseRejectionTracker), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
923         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
924         GlobalPropertyInfo(vm.propertyNames->builtinNames().SetPrivateName(), setConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
925         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
926 #if ENABLE(INTL)
927         GlobalPropertyInfo(vm.propertyNames->builtinNames().dateTimeFormatPrivateName(), privateFuncDateTimeFormat, 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, JSNonDestructibleProxy::create(vm, JSNonDestructibleProxy::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     visitor.append(thisObject->m_defaultCollator);
1571 #endif
1572     visitor.append(thisObject->m_nullGetterFunction);
1573     visitor.append(thisObject->m_nullSetterFunction);
1574
1575     visitor.append(thisObject->m_parseIntFunction);
1576     visitor.append(thisObject->m_parseFloatFunction);
1577     visitor.append(thisObject->m_evalFunction);
1578     visitor.append(thisObject->m_callFunction);
1579     visitor.append(thisObject->m_applyFunction);
1580     visitor.append(thisObject->m_throwTypeErrorFunction);
1581     thisObject->m_arrayProtoToStringFunction.visit(visitor);
1582     thisObject->m_arrayProtoValuesFunction.visit(visitor);
1583     thisObject->m_initializePromiseFunction.visit(visitor);
1584     thisObject->m_iteratorProtocolFunction.visit(visitor);
1585     thisObject->m_promiseResolveFunction.visit(visitor);
1586     visitor.append(thisObject->m_objectProtoValueOfFunction);
1587     visitor.append(thisObject->m_numberProtoToStringFunction);
1588     visitor.append(thisObject->m_newPromiseCapabilityFunction);
1589     visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
1590     thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1591     visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1592     thisObject->m_moduleLoader.visit(visitor);
1593
1594     visitor.append(thisObject->m_objectPrototype);
1595     visitor.append(thisObject->m_functionPrototype);
1596     visitor.append(thisObject->m_arrayPrototype);
1597     visitor.append(thisObject->m_errorPrototype);
1598     visitor.append(thisObject->m_iteratorPrototype);
1599     visitor.append(thisObject->m_generatorFunctionPrototype);
1600     visitor.append(thisObject->m_generatorPrototype);
1601     visitor.append(thisObject->m_asyncFunctionPrototype);
1602     visitor.append(thisObject->m_asyncGeneratorPrototype);
1603     visitor.append(thisObject->m_asyncIteratorPrototype);
1604     visitor.append(thisObject->m_asyncGeneratorFunctionPrototype);
1605
1606     thisObject->m_debuggerScopeStructure.visit(visitor);
1607     thisObject->m_withScopeStructure.visit(visitor);
1608     visitor.append(thisObject->m_strictEvalActivationStructure);
1609     visitor.append(thisObject->m_lexicalEnvironmentStructure);
1610     thisObject->m_moduleEnvironmentStructure.visit(visitor);
1611     visitor.append(thisObject->m_directArgumentsStructure);
1612     visitor.append(thisObject->m_scopedArgumentsStructure);
1613     visitor.append(thisObject->m_clonedArgumentsStructure);
1614     visitor.append(thisObject->m_objectStructureForObjectConstructor);
1615     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1616         visitor.append(thisObject->m_originalArrayStructureForIndexingShape[i]);
1617     for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
1618         visitor.append(thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1619     thisObject->m_callbackConstructorStructure.visit(visitor);
1620     thisObject->m_callbackFunctionStructure.visit(visitor);
1621     thisObject->m_callbackObjectStructure.visit(visitor);
1622 #if JSC_OBJC_API_ENABLED
1623     thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1624     thisObject->m_objcWrapperObjectStructure.visit(visitor);
1625 #endif
1626 #ifdef JSC_GLIB_API_ENABLED
1627     thisObject->m_glibCallbackFunctionStructure.visit(visitor);
1628     thisObject->m_glibWrapperObjectStructure.visit(visitor);
1629 #endif
1630     visitor.append(thisObject->m_nullPrototypeObjectStructure);
1631     visitor.append(thisObject->m_errorStructure);
1632     visitor.append(thisObject->m_calleeStructure);
1633
1634     visitor.append(thisObject->m_hostFunctionStructure);
1635     auto visitFunctionStructures = [&] (FunctionStructures& structures) {
1636         visitor.append(structures.arrowFunctionStructure);
1637         visitor.append(structures.sloppyFunctionStructure);
1638         visitor.append(structures.strictFunctionStructure);
1639     };
1640     visitFunctionStructures(thisObject->m_builtinFunctions);
1641     visitFunctionStructures(thisObject->m_ordinaryFunctions);
1642
1643     thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
1644     thisObject->m_boundFunctionStructure.visit(visitor);
1645     visitor.append(thisObject->m_getterSetterStructure);
1646     thisObject->m_nativeStdFunctionStructure.visit(visitor);
1647     visitor.append(thisObject->m_bigIntObjectStructure);
1648     visitor.append(thisObject->m_regExpStructure);
1649     visitor.append(thisObject->m_generatorFunctionStructure);
1650     visitor.append(thisObject->m_asyncFunctionStructure);
1651     visitor.append(thisObject->m_asyncGeneratorFunctionStructure);
1652     visitor.append(thisObject->m_iteratorResultObjectStructure);
1653     visitor.append(thisObject->m_regExpMatchesArrayStructure);
1654     visitor.append(thisObject->m_regExpMatchesArrayWithGroupsStructure);
1655     visitor.append(thisObject->m_moduleRecordStructure);
1656     visitor.append(thisObject->m_moduleNamespaceObjectStructure);
1657     visitor.append(thisObject->m_proxyObjectStructure);
1658     visitor.append(thisObject->m_callableProxyObjectStructure);
1659     visitor.append(thisObject->m_proxyRevokeStructure);
1660     
1661     visitor.append(thisObject->m_arrayBufferPrototype);
1662     visitor.append(thisObject->m_arrayBufferStructure);
1663 #if ENABLE(SHARED_ARRAY_BUFFER)
1664     visitor.append(thisObject->m_sharedArrayBufferPrototype);
1665     visitor.append(thisObject->m_sharedArrayBufferStructure);
1666 #endif
1667
1668 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
1669         visitor.append(thisObject->m_ ## lowerName ## Prototype); \
1670         visitor.append(thisObject->m_ ## properName ## Structure); \
1671     } while (0);
1672
1673     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1674     if (UNLIKELY(Options::useBigInt()))
1675         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(VISIT_SIMPLE_TYPE)
1676     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
1677     
1678 #if ENABLE(WEBASSEMBLY)
1679     visitor.append(thisObject->m_webAssemblyStructure);
1680     visitor.append(thisObject->m_webAssemblyModuleRecordStructure);
1681     visitor.append(thisObject->m_webAssemblyFunctionStructure);
1682     visitor.append(thisObject->m_webAssemblyWrapperFunctionStructure);
1683     visitor.append(thisObject->m_webAssemblyToJSCalleeStructure);
1684     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_SIMPLE_TYPE)
1685 #endif // ENABLE(WEBASSEMBLY)
1686
1687 #undef VISIT_SIMPLE_TYPE
1688
1689 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1690     thisObject->m_ ## properName ## Structure.visit(visitor);
1691     
1692     FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1693
1694 #undef VISIT_LAZY_TYPE
1695
1696     for (unsigned i = NumberOfTypedArrayTypes; i--;)
1697         thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1698     
1699     visitor.append(thisObject->m_speciesGetterSetter);
1700     thisObject->m_typedArrayProto.visit(visitor);
1701     thisObject->m_typedArraySuperConstructor.visit(visitor);
1702     thisObject->m_regExpGlobalData.visitAggregate(visitor);
1703 }
1704
1705 ExecState* JSGlobalObject::globalExec()
1706 {
1707     return CallFrame::create(m_globalCallFrame);
1708 }
1709
1710 void JSGlobalObject::exposeDollarVM(VM& vm)
1711 {
1712     if (hasOwnProperty(globalExec(), vm.propertyNames->builtinNames().dollarVMPrivateName()))
1713         return;
1714
1715     JSDollarVM* dollarVM = JSDollarVM::create(vm, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
1716
1717     GlobalPropertyInfo extraStaticGlobals[] = {
1718         GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
1719     };
1720     addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
1721
1722     putDirect(vm, Identifier::fromString(globalExec(), "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
1723 }
1724
1725 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1726 {
1727     ScopeOffset startOffset = addVariables(count, jsUndefined());
1728
1729     for (int i = 0; i < count; ++i) {
1730         GlobalPropertyInfo& global = globals[i];
1731         // This `configurable = false` is necessary condition for static globals,
1732         // otherwise lexical bindings can change the result of GlobalVar queries too.
1733         // We won't be able to declare a global lexical variable with the sanem name to
1734         // the static globals because configurable = false.
1735         ASSERT(global.attributes & PropertyAttribute::DontDelete);
1736         
1737         WatchpointSet* watchpointSet = nullptr;
1738         WriteBarrierBase<Unknown>* variable = nullptr;
1739         {
1740             ConcurrentJSLocker locker(symbolTable()->m_lock);
1741             ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1742             RELEASE_ASSERT(offset == startOffset + i);
1743             SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1744             newEntry.prepareToWatch();
1745             watchpointSet = newEntry.watchpointSet();
1746             symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1747             variable = &variableAt(offset);
1748         }
1749         symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1750     }
1751 }
1752
1753 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1754 {
1755     if (Base::getOwnPropertySlot(object, exec, propertyName, slot))
1756         return true;
1757     return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
1758 }
1759
1760 void JSGlobalObject::clearRareData(JSCell* cell)
1761 {
1762     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1763 }
1764
1765 void slowValidateCell(JSGlobalObject* globalObject)
1766 {
1767     RELEASE_ASSERT(globalObject->isGlobalObject());
1768     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1769 }
1770
1771 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1772 {
1773 #if ENABLE(REMOTE_INSPECTOR)
1774     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1775 #else
1776     UNUSED_PARAM(enabled);
1777 #endif
1778 }
1779
1780 bool JSGlobalObject::remoteDebuggingEnabled() const
1781 {
1782 #if ENABLE(REMOTE_INSPECTOR)
1783     return m_inspectorDebuggable->remoteDebuggingAllowed();
1784 #else
1785     return false;
1786 #endif
1787 }
1788
1789 void JSGlobalObject::setName(const String& name)
1790 {
1791     m_name = name;
1792
1793 #if ENABLE(REMOTE_INSPECTOR)
1794     m_inspectorDebuggable->update();
1795 #endif
1796 }
1797
1798 # if ENABLE(INTL)
1799 static void addMissingScriptLocales(HashSet<String>& availableLocales)
1800 {
1801     if (availableLocales.contains("pa-Arab-PK"))
1802         availableLocales.add("pa-PK"_s);
1803     if (availableLocales.contains("zh-Hans-CN"))
1804         availableLocales.add("zh-CN"_s);
1805     if (availableLocales.contains("zh-Hant-HK"))
1806         availableLocales.add("zh-HK"_s);
1807     if (availableLocales.contains("zh-Hans-SG"))
1808         availableLocales.add("zh-SG"_s);
1809     if (availableLocales.contains("zh-Hant-TW"))
1810         availableLocales.add("zh-TW"_s);
1811 }
1812
1813 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1814 {
1815     if (m_intlCollatorAvailableLocales.isEmpty()) {
1816         int32_t count = ucol_countAvailable();
1817         for (int32_t i = 0; i < count; ++i) {
1818             String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i));
1819             if (!locale.isEmpty())
1820                 m_intlCollatorAvailableLocales.add(locale);
1821         }
1822         addMissingScriptLocales(m_intlCollatorAvailableLocales);
1823     }
1824     return m_intlCollatorAvailableLocales;
1825 }
1826
1827 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1828 {
1829     if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1830         int32_t count = udat_countAvailable();
1831         for (int32_t i = 0; i < count; ++i) {
1832             String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i));
1833             if (!locale.isEmpty())
1834                 m_intlDateTimeFormatAvailableLocales.add(locale);
1835         }
1836         addMissingScriptLocales(m_intlDateTimeFormatAvailableLocales);
1837     }
1838     return m_intlDateTimeFormatAvailableLocales;
1839 }
1840
1841 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1842 {
1843     if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1844         int32_t count = unum_countAvailable();
1845         for (int32_t i = 0; i < count; ++i) {
1846             String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i));
1847             if (!locale.isEmpty())
1848                 m_intlNumberFormatAvailableLocales.add(locale);
1849         }
1850         addMissingScriptLocales(m_intlNumberFormatAvailableLocales);
1851     }
1852     return m_intlNumberFormatAvailableLocales;
1853 }
1854
1855 const HashSet<String>& JSGlobalObject::intlPluralRulesAvailableLocales()
1856 {
1857     if (m_intlPluralRulesAvailableLocales.isEmpty()) {
1858         int32_t count = uloc_countAvailable();
1859         for (int32_t i = 0; i < count; ++i) {
1860             String locale = convertICULocaleToBCP47LanguageTag(uloc_getAvailable(i));
1861             if (!locale.isEmpty())
1862                 m_intlPluralRulesAvailableLocales.add(locale);
1863         }
1864         addMissingScriptLocales(m_intlPluralRulesAvailableLocales);
1865     }
1866     return m_intlPluralRulesAvailableLocales;
1867 }
1868
1869 IntlCollator* JSGlobalObject::defaultCollator(ExecState* exec)
1870 {
1871     VM& vm = exec->vm();
1872     auto scope = DECLARE_THROW_SCOPE(vm);
1873
1874     if (m_defaultCollator)
1875         return m_defaultCollator.get();
1876
1877     IntlCollator* collator = IntlCollator::create(vm, intlObject()->collatorStructure());
1878     collator->initializeCollator(*exec, jsUndefined(), jsUndefined());
1879     RETURN_IF_EXCEPTION(scope, nullptr);
1880     m_defaultCollator.set(vm, this, collator);
1881     return collator;
1882 }
1883
1884 #endif // ENABLE(INTL)
1885
1886 void JSGlobalObject::bumpGlobalLexicalBindingEpoch(VM& vm)
1887 {
1888     if (++m_globalLexicalBindingEpoch == Options::thresholdForGlobalLexicalBindingEpoch()) {
1889         // Since the epoch overflows, we should rewrite all the CodeBlock to adjust to the newly started generation.
1890         m_globalLexicalBindingEpoch = 1;
1891         vm.heap.codeBlockSet().iterate([&] (CodeBlock* codeBlock) {
1892             if (codeBlock->globalObject() != this)
1893                 return;
1894             codeBlock->notifyLexicalBindingUpdate();
1895         });
1896     }
1897 }
1898
1899 void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
1900 {
1901     if (globalObjectMethodTable()->queueTaskToEventLoop) {
1902         globalObjectMethodTable()->queueTaskToEventLoop(*this, WTFMove(task));
1903         return;
1904     }
1905
1906     vm().queueMicrotask(*this, WTFMove(task));
1907 }
1908
1909 void JSGlobalObject::setDebugger(Debugger* debugger)
1910 {
1911     m_debugger = debugger;
1912     if (debugger)
1913         vm().ensureShadowChicken();
1914 }
1915
1916 bool JSGlobalObject::hasDebugger() const
1917
1918     return m_debugger;
1919 }
1920
1921 bool JSGlobalObject::hasInteractiveDebugger() const 
1922
1923     return m_debugger && m_debugger->isInteractivelyDebugging();
1924 }
1925
1926 #if ENABLE(DFG_JIT)
1927 WatchpointSet* JSGlobalObject::getReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
1928 {
1929     ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
1930     return m_referencedGlobalPropertyWatchpointSets.get(uid);
1931 }
1932
1933 WatchpointSet& JSGlobalObject::ensureReferencedPropertyWatchpointSet(UniquedStringImpl* uid)
1934 {
1935     ConcurrentJSLocker locker(m_referencedGlobalPropertyWatchpointSetsLock);
1936     return m_referencedGlobalPropertyWatchpointSets.ensure(uid, [] {
1937         return WatchpointSet::create(IsWatched);
1938     }).iterator->value.get();
1939 }
1940 #endif
1941
1942 JSGlobalObject* JSGlobalObject::create(VM& vm, Structure* structure)
1943 {
1944     JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
1945     globalObject->finishCreation(vm);
1946     return globalObject;
1947 }
1948
1949 void JSGlobalObject::finishCreation(VM& vm)
1950 {
1951     Base::finishCreation(vm);
1952     structure(vm)->setGlobalObject(vm, this);
1953     m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1954     init(vm);
1955     setGlobalThis(vm, JSNonDestructibleProxy::create(vm, JSNonDestructibleProxy::createStructure(vm, this, getPrototypeDirect(vm), PureForwardingProxyType), this));
1956     ASSERT(type() == GlobalObjectType);
1957 }
1958
1959 void JSGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
1960 {
1961     Base::finishCreation(vm);
1962     structure(vm)->setGlobalObject(vm, this);
1963     m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1964     init(vm);
1965     setGlobalThis(vm, thisValue);
1966     ASSERT(type() == GlobalObjectType);
1967 }
1968
1969 #ifdef JSC_GLIB_API_ENABLED
1970 void JSGlobalObject::setWrapperMap(std::unique_ptr<WrapperMap>&& map)
1971 {
1972     m_wrapperMap = WTFMove(map);
1973 }
1974 #endif
1975
1976 } // namespace JSC