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