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