Rollout r200426 since it causes PLT regressions.
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007-2009, 2014-2016 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 "BooleanConstructor.h"
37 #include "BooleanPrototype.h"
38 #include "BuiltinNames.h"
39 #include "ClonedArguments.h"
40 #include "CodeBlock.h"
41 #include "CodeCache.h"
42 #include "ConsoleObject.h"
43 #include "DateConstructor.h"
44 #include "DatePrototype.h"
45 #include "Debugger.h"
46 #include "DebuggerScope.h"
47 #include "DirectArguments.h"
48 #include "ECMAScriptSpecInternalFunctions.h"
49 #include "Error.h"
50 #include "ErrorConstructor.h"
51 #include "ErrorPrototype.h"
52 #include "FunctionConstructor.h"
53 #include "FunctionPrototype.h"
54 #include "GeneratorFunctionConstructor.h"
55 #include "GeneratorFunctionPrototype.h"
56 #include "GeneratorPrototype.h"
57 #include "GetterSetter.h"
58 #include "HeapIterationScope.h"
59 #include "InspectorInstrumentationObject.h"
60 #include "Interpreter.h"
61 #include "IteratorPrototype.h"
62 #include "JSAPIWrapperObject.h"
63 #include "JSArrayBuffer.h"
64 #include "JSArrayBufferConstructor.h"
65 #include "JSArrayBufferPrototype.h"
66 #include "JSArrayIterator.h"
67 #include "JSBoundFunction.h"
68 #include "JSBoundSlotBaseFunction.h"
69 #include "JSCInlines.h"
70 #include "JSCallbackConstructor.h"
71 #include "JSCallbackFunction.h"
72 #include "JSCallbackObject.h"
73 #include "JSDataView.h"
74 #include "JSDataViewPrototype.h"
75 #include "JSDollarVM.h"
76 #include "JSDollarVMPrototype.h"
77 #include "JSFunction.h"
78 #include "JSGeneratorFunction.h"
79 #include "JSGenericTypedArrayViewConstructorInlines.h"
80 #include "JSGenericTypedArrayViewInlines.h"
81 #include "JSGenericTypedArrayViewPrototypeInlines.h"
82 #include "JSGlobalObjectFunctions.h"
83 #include "JSInternalPromise.h"
84 #include "JSInternalPromiseConstructor.h"
85 #include "JSInternalPromisePrototype.h"
86 #include "JSJob.h"
87 #include "JSLexicalEnvironment.h"
88 #include "JSLock.h"
89 #include "JSMap.h"
90 #include "JSMapIterator.h"
91 #include "JSModuleEnvironment.h"
92 #include "JSModuleNamespaceObject.h"
93 #include "JSModuleRecord.h"
94 #include "JSNativeStdFunction.h"
95 #include "JSONObject.h"
96 #include "JSPromise.h"
97 #include "JSPromiseConstructor.h"
98 #include "JSPromisePrototype.h"
99 #include "JSPropertyNameIterator.h"
100 #include "JSSet.h"
101 #include "JSSetIterator.h"
102 #include "JSStringIterator.h"
103 #include "JSTemplateRegistryKey.h"
104 #include "JSTypedArrayConstructors.h"
105 #include "JSTypedArrayPrototypes.h"
106 #include "JSTypedArrayViewConstructor.h"
107 #include "JSTypedArrayViewPrototype.h"
108 #include "JSTypedArrays.h"
109 #include "JSWASMModule.h"
110 #include "JSWeakMap.h"
111 #include "JSWeakSet.h"
112 #include "JSWithScope.h"
113 #include "LazyClassStructureInlines.h"
114 #include "LazyPropertyInlines.h"
115 #include "LegacyProfiler.h"
116 #include "Lookup.h"
117 #include "MapConstructor.h"
118 #include "MapIteratorPrototype.h"
119 #include "MapPrototype.h"
120 #include "MathObject.h"
121 #include "Microtask.h"
122 #include "ModuleLoaderObject.h"
123 #include "NativeErrorConstructor.h"
124 #include "NativeErrorPrototype.h"
125 #include "NullGetterFunction.h"
126 #include "NullSetterFunction.h"
127 #include "NumberConstructor.h"
128 #include "NumberPrototype.h"
129 #include "ObjCCallbackFunction.h"
130 #include "ObjectConstructor.h"
131 #include "ObjectPrototype.h"
132 #include "ParserError.h"
133 #include "ProxyConstructor.h"
134 #include "ProxyObject.h"
135 #include "ProxyRevoke.h"
136 #include "ReflectObject.h"
137 #include "RegExpConstructor.h"
138 #include "RegExpMatchesArray.h"
139 #include "RegExpObject.h"
140 #include "RegExpPrototype.h"
141 #include "ScopedArguments.h"
142 #include "SetConstructor.h"
143 #include "SetIteratorPrototype.h"
144 #include "SetPrototype.h"
145 #include "StrictEvalActivation.h"
146 #include "StringConstructor.h"
147 #include "StringIteratorPrototype.h"
148 #include "StringPrototype.h"
149 #include "Symbol.h"
150 #include "SymbolConstructor.h"
151 #include "SymbolPrototype.h"
152 #include "VariableWriteFireDetail.h"
153 #include "WeakGCMapInlines.h"
154 #include "WeakMapConstructor.h"
155 #include "WeakMapPrototype.h"
156 #include "WeakSetConstructor.h"
157 #include "WeakSetPrototype.h"
158 #include <wtf/RandomNumber.h>
159
160 #if ENABLE(INTL)
161 #include "IntlObject.h"
162 #include <unicode/ucol.h>
163 #include <unicode/udat.h>
164 #include <unicode/unum.h>
165 #endif // ENABLE(INTL)
166
167 #if ENABLE(REMOTE_INSPECTOR)
168 #include "JSGlobalObjectDebuggable.h"
169 #include "JSGlobalObjectInspectorController.h"
170 #endif
171
172 #if ENABLE(WEB_REPLAY)
173 #include "EmptyInputCursor.h"
174 #include "JSReplayInputs.h"
175 #endif
176
177 namespace JSC {
178
179 static JSValue createProxyProperty(VM& vm, JSObject* object)
180 {
181     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
182     return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
183 }
184
185 static JSValue createJSONProperty(VM& vm, JSObject* object)
186 {
187     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
188     return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
189 }
190
191 static JSValue createMathProperty(VM& vm, JSObject* object)
192 {
193     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
194     return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
195 }
196
197 static JSValue createConsoleProperty(VM& vm, JSObject* object)
198 {
199     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
200     return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
201 }
202
203 } // namespace JSC
204
205 #include "JSGlobalObject.lut.h"
206
207 namespace JSC {
208
209 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
210
211 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
212
213 /* Source for JSGlobalObject.lut.h
214 @begin globalObjectTable
215   parseFloat            globalFuncParseFloat                         DontEnum|Function 1
216   isNaN                 globalFuncIsNaN                              DontEnum|Function 1
217   isFinite              globalFuncIsFinite                           DontEnum|Function 1
218   escape                globalFuncEscape                             DontEnum|Function 1
219   unescape              globalFuncUnescape                           DontEnum|Function 1
220   decodeURI             globalFuncDecodeURI                          DontEnum|Function 1
221   decodeURIComponent    globalFuncDecodeURIComponent                 DontEnum|Function 1
222   encodeURI             globalFuncEncodeURI                          DontEnum|Function 1
223   encodeURIComponent    globalFuncEncodeURIComponent                 DontEnum|Function 1
224   EvalError             JSGlobalObject::m_evalErrorConstructor       DontEnum|CellProperty
225   ReferenceError        JSGlobalObject::m_referenceErrorConstructor  DontEnum|CellProperty
226   SyntaxError           JSGlobalObject::m_syntaxErrorConstructor     DontEnum|CellProperty
227   URIError              JSGlobalObject::m_URIErrorConstructor        DontEnum|CellProperty
228   Proxy                 createProxyProperty                          DontEnum|PropertyCallback
229   JSON                  createJSONProperty                           DontEnum|PropertyCallback
230   Math                  createMathProperty                           DontEnum|PropertyCallback
231   console               createConsoleProperty                        DontEnum|PropertyCallback
232   Int8Array             JSGlobalObject::m_typedArrayInt8             DontEnum|ClassStructure
233   Int16Array            JSGlobalObject::m_typedArrayInt16            DontEnum|ClassStructure
234   Int32Array            JSGlobalObject::m_typedArrayInt32            DontEnum|ClassStructure
235   Uint8Array            JSGlobalObject::m_typedArrayUint8            DontEnum|ClassStructure
236   Uint8ClampedArray     JSGlobalObject::m_typedArrayUint8Clamped     DontEnum|ClassStructure
237   Uint16Array           JSGlobalObject::m_typedArrayUint16           DontEnum|ClassStructure
238   Uint32Array           JSGlobalObject::m_typedArrayUint32           DontEnum|ClassStructure
239   Float32Array          JSGlobalObject::m_typedArrayFloat32          DontEnum|ClassStructure
240   Float64Array          JSGlobalObject::m_typedArrayFloat64          DontEnum|ClassStructure
241   DataView              JSGlobalObject::m_typedArrayDataView         DontEnum|ClassStructure
242   Set                   JSGlobalObject::m_setStructure               DontEnum|ClassStructure
243   Map                   JSGlobalObject::m_mapStructure               DontEnum|ClassStructure
244   Date                  JSGlobalObject::m_dateStructure              DontEnum|ClassStructure
245   Boolean               JSGlobalObject::m_booleanObjectStructure     DontEnum|ClassStructure
246   Number                JSGlobalObject::m_numberObjectStructure      DontEnum|ClassStructure
247   WeakMap               JSGlobalObject::m_weakMapStructure           DontEnum|ClassStructure
248   WeakSet               JSGlobalObject::m_weakSetStructure           DontEnum|ClassStructure
249 @end
250 */
251
252 static EncodedJSValue JSC_HOST_CALL getTemplateObject(ExecState* exec)
253 {
254     JSValue thisValue = exec->thisValue();
255     ASSERT(thisValue.inherits(JSTemplateRegistryKey::info()));
256     return JSValue::encode(exec->lexicalGlobalObject()->templateRegistry().getTemplateObject(exec, jsCast<JSTemplateRegistryKey*>(thisValue)->templateRegistryKey()));
257 }
258
259
260 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
261 {
262     VM& vm = exec->vm();
263     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
264
265     JSValue job = exec->argument(0);
266     JSValue arguments = exec->argument(1);
267     ASSERT(arguments.inherits(JSArray::info()));
268
269     globalObject->queueMicrotask(createJSJob(vm, job, jsCast<JSArray*>(arguments)));
270
271     return JSValue::encode(jsUndefined());
272 }
273
274 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
275     : Base(vm, structure, 0)
276     , m_vm(vm)
277 #if ENABLE(WEB_REPLAY)
278     , m_inputCursor(EmptyInputCursor::create())
279 #endif
280     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
281     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
282     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
283     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
284     , m_templateRegistry(vm)
285     , m_evalEnabled(true)
286     , m_runtimeFlags()
287     , m_consoleClient(nullptr)
288     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
289 {
290 }
291
292 JSGlobalObject::~JSGlobalObject()
293 {
294 #if ENABLE(REMOTE_INSPECTOR)
295     m_inspectorController->globalObjectDestroyed();
296 #endif
297
298     if (m_debugger)
299         m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
300
301     if (LegacyProfiler* profiler = vm().enabledProfiler())
302         profiler->stopProfiling(this);
303 }
304
305 void JSGlobalObject::destroy(JSCell* cell)
306 {
307     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
308 }
309
310 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
311 {
312     m_globalThis.set(vm, this, globalThis);
313 }
314
315 static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
316 {
317     JSValue baseValue = JSValue(base);
318     PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
319     baseValue.getPropertySlot(exec, ident, slot);
320     return slot.getPureResult().toObject(exec);
321 }
322
323 void JSGlobalObject::init(VM& vm)
324 {
325     ASSERT(vm.currentThreadIsHoldingAPILock());
326
327     JSGlobalObject::globalExec()->init(0, 0, CallFrame::noCaller(), 0, 0);
328
329     m_debugger = 0;
330
331 #if ENABLE(REMOTE_INSPECTOR)
332     m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
333     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
334     m_inspectorDebuggable->init();
335     m_consoleClient = m_inspectorController->consoleClient();
336 #endif
337
338     ExecState* exec = JSGlobalObject::globalExec();
339
340     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
341     m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
342
343     m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
344     // Need to create the callee structure (above) before creating the callee.
345     m_globalCallee.set(vm, this, JSCallee::create(vm, this, globalScope()));
346     exec->setCallee(m_globalCallee.get());
347
348     m_functionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
349     m_boundSlotBaseFunctionStructure.initLater(
350         [] (const Initializer<Structure>& init) {
351             init.set(JSBoundSlotBaseFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
352         });
353     m_boundFunctionStructure.initLater(
354         [] (const Initializer<Structure>& init) {
355             init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
356         });
357     m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
358     m_nativeStdFunctionStructure.initLater(
359         [] (const Initializer<Structure>& init) {
360             init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
361         });
362     m_namedFunctionStructure.initLater(
363         [] (const Initializer<Structure>& init) {
364             init.set(Structure::addPropertyTransition(init.vm, init.owner->m_functionStructure.get(), init.vm.propertyNames->name, DontDelete | ReadOnly | DontEnum, init.owner->m_functionNameOffset));
365         });
366     JSFunction* callFunction = 0;
367     JSFunction* applyFunction = 0;
368     JSFunction* hasInstanceSymbolFunction = 0;
369     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
370     m_callFunction.set(vm, this, callFunction);
371     m_applyFunction.set(vm, this, applyFunction);
372     m_arrayProtoValuesFunction.initLater(
373         [] (const Initializer<JSFunction>& init) {
374             init.set(JSFunction::createBuiltinFunction(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
375         });
376     m_initializePromiseFunction.initLater(
377         [] (const Initializer<JSFunction>& init) {
378             init.set(JSFunction::createBuiltinFunction(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
379         });
380     m_newPromiseCapabilityFunction.set(vm, this, JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
381     m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
382     m_throwTypeErrorGetterSetter.initLater(
383         [] (const Initializer<GetterSetter>& init) {
384             JSFunction* thrower = JSFunction::create(init.vm, init.owner, 0, String(), globalFuncThrowTypeError);
385             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
386             getterSetter->setGetter(init.vm, init.owner, thrower);
387             getterSetter->setSetter(init.vm, init.owner, thrower);
388             init.set(getterSetter);
389         });
390     m_throwTypeErrorCalleeAndCallerGetterSetter.initLater(
391         [] (const Initializer<GetterSetter>& init) {
392             JSFunction* thrower = JSFunction::create(init.vm, init.owner, 0, String(), globalFuncThrowTypeErrorCalleeAndCaller);
393             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
394             getterSetter->setGetter(init.vm, init.owner, thrower);
395             getterSetter->setSetter(init.vm, init.owner, thrower);
396             init.set(getterSetter);
397         });
398     m_throwTypeErrorArgumentsAndCallerInStrictModeGetterSetter.initLater(
399         [] (const Initializer<GetterSetter>& init) {
400             JSFunction* thrower = JSFunction::create(init.vm, init.owner, 0, String(), globalFuncThrowTypeErrorArgumentsAndCallerInStrictMode);
401             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
402             getterSetter->setGetter(init.vm, init.owner, thrower);
403             getterSetter->setSetter(init.vm, init.owner, thrower);
404             init.set(getterSetter);
405         });
406     m_throwTypeErrorArgumentsAndCallerInClassContextGetterSetter.initLater(
407         [] (const Initializer<GetterSetter>& init) {
408             JSFunction* thrower = JSFunction::create(init.vm, init.owner, 0, String(), globalFuncThrowTypeErrorArgumentsAndCallerInClassContext);
409             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
410             getterSetter->setGetter(init.vm, init.owner, thrower);
411             getterSetter->setSetter(init.vm, init.owner, thrower);
412             init.set(getterSetter);
413         });
414     m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
415     m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
416     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
417     GetterSetter* protoAccessor = GetterSetter::create(vm, this);
418     protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter));
419     protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
420     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, Accessor | DontEnum);
421     m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
422     m_objectStructureForObjectConstructor.set(vm, this, vm.prototypeMap.emptyObjectStructureForPrototype(m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
423
424     m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this));
425     m_speciesGetterSetter->setGetter(vm, this, JSFunction::createBuiltinFunction(vm, globalObjectSpeciesGetterCodeGenerator(vm), this, "get [Symbol.species]"));
426
427     m_typedArrayProto.initLater(
428         [] (const Initializer<JSTypedArrayViewPrototype>& init) {
429             init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
430             
431             // Make sure that the constructor gets initialized, too.
432             init.owner->m_typedArraySuperConstructor.get(init.owner);
433         });
434     m_typedArraySuperConstructor.initLater(
435         [] (const Initializer<JSTypedArrayViewConstructor>& init) {
436             JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
437             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());
438             prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, DontEnum);
439             init.set(constructor);
440         });
441     
442 #define INIT_TYPED_ARRAY_LATER(type) \
443     m_typedArray ## type.initLater( \
444         [] (LazyClassStructure::Initializer& init) { \
445             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)))); \
446             init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
447             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, ASCIILiteral(#type "Array"), typedArrayConstructorAllocate ## type ## ArrayCodeGenerator(init.vm))); \
448             init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->type ## ArrayPrivateName, init.constructor, DontEnum); \
449         });
450     FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
451 #undef INIT_TYPED_ARRAY_LATER
452     
453     m_typedArrayDataView.initLater(
454         [] (LazyClassStructure::Initializer& init) {
455             init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
456             init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
457             init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, ASCIILiteral("DataView"), nullptr));
458         });
459     
460     m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
461     m_moduleEnvironmentStructure.initLater(
462         [] (const Initializer<Structure>& init) {
463             init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
464         });
465     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
466     m_debuggerScopeStructure.initLater(
467         [] (const Initializer<Structure>& init) {
468             init.set(DebuggerScope::createStructure(init.vm, init.owner));
469         });
470     m_withScopeStructure.initLater(
471         [] (const Initializer<Structure>& init) {
472             init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
473         });
474     
475     m_nullPrototypeObjectStructure.initLater(
476         [] (const Initializer<Structure>& init) {
477             init.set(JSFinalObject::createStructure(init.vm, init.owner, jsNull(), JSFinalObject::defaultInlineCapacity()));
478         });
479     
480     m_callbackFunctionStructure.initLater(
481         [] (const Initializer<Structure>& init) {
482             init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
483         });
484     m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
485     m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
486     m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
487     m_callbackConstructorStructure.initLater(
488         [] (const Initializer<Structure>& init) {
489             init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
490         });
491     m_callbackObjectStructure.initLater(
492         [] (const Initializer<Structure>& init) {
493             init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
494         });
495
496 #if JSC_OBJC_API_ENABLED
497     m_objcCallbackFunctionStructure.initLater(
498         [] (const Initializer<Structure>& init) {
499             init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
500         });
501     m_objcWrapperObjectStructure.initLater(
502         [] (const Initializer<Structure>& init) {
503             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
504         });
505 #endif
506     
507     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
508     
509     m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
510     m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
511     m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
512     m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
513     m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
514     m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
515     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
516         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
517
518     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
519     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
520     m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
521     m_regExpMatchesArraySlowPutStructure.set(vm, this, createRegExpMatchesArraySlowPutStructure(vm, this));
522
523     m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
524     m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
525     {
526         bool isCallable = false;
527         m_proxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, m_objectPrototype.get(), isCallable));
528         isCallable = true;
529         m_callableProxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, m_objectPrototype.get(), isCallable));
530     }
531     m_proxyRevokeStructure.set(vm, this, ProxyRevoke::createStructure(vm, this, m_functionPrototype.get()));
532     
533 #if ENABLE(WEBASSEMBLY)
534     m_wasmModuleStructure.set(vm, this, JSWASMModule::createStructure(vm, this));
535 #endif
536
537     m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, NoIntrinsic));
538     putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum);
539
540 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
541 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_objectPrototype.get()))); \
542 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
543     
544     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
545     
546 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
547
548 #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
549     m_ ## properName ## Structure.initLater(\
550         [] (LazyClassStructure::Initializer& init) { \
551             init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get()))); \
552             init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
553             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())); \
554         });
555     
556     FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
557     
558 #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
559     
560     m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
561
562 #define CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
563     m_ ## lowerName ## Structure.initLater( \
564         [] (const Initializer<Structure>& init) { \
565             JSObject* prototype = capitalName ## Prototype::create(init.vm, init.owner, capitalName ## Prototype::createStructure(init.vm, init.owner, init.owner->m_iteratorPrototype.get())); \
566             init.set(instanceType::createStructure(init.vm, init.owner, prototype)); \
567         });
568     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE)
569 #undef CREATE_PROTOTYPE_FOR_DERIVED_ITERATOR_TYPE
570
571     m_propertyNameIteratorStructure.set(vm, this, JSPropertyNameIterator::createStructure(vm, this, m_iteratorPrototype.get()));
572     m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
573     
574     // Constructors
575
576     ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
577     m_objectConstructor.set(vm, this, objectConstructor);
578
579     JSFunction* definePropertyFunction = m_objectConstructor->addDefineProperty(exec, this);
580     m_definePropertyFunction.set(vm, this, definePropertyFunction);
581
582     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
583     JSObject* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
584     
585     m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get()));
586     
587 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
588 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
589 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, DontEnum); \
590
591     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
592     
593 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
594
595     m_errorConstructor.set(vm, this, errorConstructor);
596     m_promiseConstructor.set(vm, this, promiseConstructor);
597     m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
598     
599     m_nativeErrorPrototypeStructure.set(vm, this, NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get()));
600     m_nativeErrorStructure.set(vm, this, NativeErrorConstructor::createStructure(vm, this, m_functionPrototype.get()));
601     m_evalErrorConstructor.initLater(
602         [] (const Initializer<NativeErrorConstructor>& init) {
603             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("EvalError")));
604         });
605     m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("RangeError")));
606     m_referenceErrorConstructor.initLater(
607         [] (const Initializer<NativeErrorConstructor>& init) {
608             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("ReferenceError")));
609         });
610     m_syntaxErrorConstructor.initLater(
611         [] (const Initializer<NativeErrorConstructor>& init) {
612             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("SyntaxError")));
613         });
614     m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("TypeError")));
615     m_URIErrorConstructor.initLater(
616         [] (const Initializer<NativeErrorConstructor>& init) {
617             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("URIError")));
618         });
619
620     m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
621     GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
622     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, DontEnum);
623     m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
624
625     m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), DontEnum);
626     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), DontEnum);
627     
628     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, DontEnum);
629     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, DontEnum);
630     m_arrayPrototype->setConstructor(vm, arrayConstructor, DontEnum);
631     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), DontEnum);
632     
633     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, DontEnum);
634     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, DontEnum);
635     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, DontEnum);
636     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), DontEnum);
637     putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), DontEnum);
638     putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), DontEnum);
639
640     putDirectWithoutTransition(vm, vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly);
641     putDirectWithoutTransition(vm, vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly);
642
643 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
644 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, DontEnum); \
645
646     FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
647
648 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
649     m_iteratorResultObjectStructure.set(vm, this, createIteratorResultObjectStructure(vm, *this));
650     
651     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
652     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), DontEnum);
653     
654 #if ENABLE(INTL)
655     IntlObject* intl = IntlObject::create(vm, this, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
656     putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, DontEnum);
657 #endif // ENABLE(INTL)
658     ReflectObject* reflectObject = ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get()));
659     putDirectWithoutTransition(vm, vm.propertyNames->Reflect, reflectObject, DontEnum);
660
661     m_moduleLoader.set(vm, this, ModuleLoaderObject::create(vm, this, ModuleLoaderObject::createStructure(vm, this, m_objectPrototype.get())));
662     if (Options::exposeInternalModuleLoader())
663         putDirectWithoutTransition(vm, vm.propertyNames->Loader, m_moduleLoader.get(), DontEnum);
664
665     JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
666
667     JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
668     JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
669     JSFunction* privateFuncIsFinite = JSFunction::create(vm, this, 0, String(), globalFuncIsFinite);
670     JSFunction* privateFuncIsNaN = JSFunction::create(vm, this, 0, String(), globalFuncIsNaN);
671     JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
672
673     JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject);
674     JSFunction* privateFuncToLength = JSFunction::createBuiltinFunction(vm, globalObjectToLengthCodeGenerator(vm), this);
675     JSFunction* privateFuncToInteger = JSFunction::createBuiltinFunction(vm, globalObjectToIntegerCodeGenerator(vm), this);
676     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
677     JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
678     JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
679     JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
680     JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
681     JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
682     JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
683     JSFunction* privateFuncThisNumberValue = JSFunction::create(vm, this, 0, String(), numberProtoFuncValueOf);
684     JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
685
686     JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
687     JSFunction* privateFuncCreateArrayIterator = JSFunction::createBuiltinFunction(vm, arrayPrototypeCreateArrayIteratorConstructorCodeGenerator(vm), this);
688     privateFuncCreateArrayIterator->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
689     JSFunction* privateFuncArrayIteratorValueNext = JSFunction::createBuiltinFunction(vm, arrayIteratorPrototypeArrayIteratorValueNextCodeGenerator(vm), this);
690     JSFunction* privateFuncArrayIteratorKeyNext = JSFunction::createBuiltinFunction(vm, arrayIteratorPrototypeArrayIteratorKeyNextCodeGenerator(vm), this);
691     JSFunction* privateFuncArrayIteratorKeyValueNext = JSFunction::createBuiltinFunction(vm, arrayIteratorPrototypeArrayIteratorKeyValueNextCodeGenerator(vm), this);
692
693     JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
694     JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
695     m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
696     JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
697     JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
698     JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
699     JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
700     JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
701     m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
702     JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
703     m_regExpProtoExec.set(vm, this, builtinRegExpExec);
704     JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
705     m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
706
707     GlobalPropertyInfo staticGlobals[] = {
708         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
709         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
710         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
711         GlobalPropertyInfo(vm.propertyNames->ObjectPrivateName, objectConstructor, DontEnum | DontDelete | ReadOnly),
712         GlobalPropertyInfo(vm.propertyNames->ownEnumerablePropertyKeysPrivateName, JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly),
713         GlobalPropertyInfo(vm.propertyNames->getTemplateObjectPrivateName, privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly),
714         GlobalPropertyInfo(vm.propertyNames->enqueueJobPrivateName, JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
715         GlobalPropertyInfo(vm.propertyNames->ErrorPrivateName, m_errorConstructor.get(), DontEnum | DontDelete | ReadOnly),
716         GlobalPropertyInfo(vm.propertyNames->RangeErrorPrivateName, m_rangeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
717         GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
718         GlobalPropertyInfo(vm.propertyNames->typedArrayLengthPrivateName, privateFuncTypedArrayLength, DontEnum | DontDelete | ReadOnly),
719         GlobalPropertyInfo(vm.propertyNames->typedArrayGetOriginalConstructorPrivateName, privateFuncTypedArrayGetOriginalConstructor, DontEnum | DontDelete | ReadOnly),
720         GlobalPropertyInfo(vm.propertyNames->typedArraySortPrivateName, privateFuncTypedArraySort, DontEnum | DontDelete | ReadOnly),
721         GlobalPropertyInfo(vm.propertyNames->isBoundFunctionPrivateName, privateFuncIsBoundFunction, DontEnum | DontDelete | ReadOnly),
722         GlobalPropertyInfo(vm.propertyNames->hasInstanceBoundFunctionPrivateName, privateFuncHasInstanceBoundFunction, DontEnum | DontDelete | ReadOnly),
723         GlobalPropertyInfo(vm.propertyNames->instanceOfPrivateName, privateFuncInstanceOf, DontEnum | DontDelete | ReadOnly),
724         GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
725         GlobalPropertyInfo(vm.propertyNames->ArrayPrivateName, arrayConstructor, DontEnum | DontDelete | ReadOnly),
726         GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
727         GlobalPropertyInfo(vm.propertyNames->RegExpPrivateName, m_regExpConstructor.get(), DontEnum | DontDelete | ReadOnly),
728         GlobalPropertyInfo(vm.propertyNames->StringPrivateName, stringConstructor, DontEnum | DontDelete | ReadOnly),
729         GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
730         GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
731         GlobalPropertyInfo(vm.propertyNames->truncPrivateName, privateFuncTrunc, DontEnum | DontDelete | ReadOnly),
732         GlobalPropertyInfo(vm.propertyNames->isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly),
733         GlobalPropertyInfo(vm.propertyNames->isNaNPrivateName, privateFuncIsNaN, DontEnum | DontDelete | ReadOnly),
734         GlobalPropertyInfo(vm.propertyNames->PromisePrivateName, promiseConstructor, DontEnum | DontDelete | ReadOnly),
735         GlobalPropertyInfo(vm.propertyNames->ReflectPrivateName, reflectObject, DontEnum | DontDelete | ReadOnly),
736         GlobalPropertyInfo(vm.propertyNames->InternalPromisePrivateName, internalPromiseConstructor, DontEnum | DontDelete | ReadOnly),
737
738         GlobalPropertyInfo(vm.propertyNames->repeatCharacterPrivateName, JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), DontEnum | DontDelete | ReadOnly),
739         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatSlowPathPrivateName(), JSFunction::createBuiltinFunction(vm, stringPrototypeRepeatSlowPathCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
740         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharactersSlowPathPrivateName(), JSFunction::createBuiltinFunction(vm, stringPrototypeRepeatCharactersSlowPathCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
741
742         GlobalPropertyInfo(vm.propertyNames->isSetPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncIsSet), DontEnum | DontDelete | ReadOnly),
743         GlobalPropertyInfo(vm.propertyNames->SetIteratorPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncSetIterator), DontEnum | DontDelete | ReadOnly),
744         GlobalPropertyInfo(vm.propertyNames->setIteratorNextPrivateName, JSFunction::create(vm, this, 0, String(), privateFuncSetIteratorNext), DontEnum | DontDelete | ReadOnly),
745         GlobalPropertyInfo(vm.propertyNames->isMapPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncIsMap), DontEnum | DontDelete | ReadOnly),
746         GlobalPropertyInfo(vm.propertyNames->isArrayPrivateName, arrayConstructor->getDirect(vm, vm.propertyNames->isArray), DontEnum | DontDelete | ReadOnly),
747         GlobalPropertyInfo(vm.propertyNames->isArrayConstructorPrivateName, privateFuncIsArrayConstructor, DontEnum | DontDelete | ReadOnly),
748         GlobalPropertyInfo(vm.propertyNames->MapIteratorPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncMapIterator), DontEnum | DontDelete | ReadOnly),
749         GlobalPropertyInfo(vm.propertyNames->mapIteratorNextPrivateName, JSFunction::create(vm, this, 0, String(), privateFuncMapIteratorNext), DontEnum | DontDelete | ReadOnly),
750         GlobalPropertyInfo(vm.propertyNames->builtinNames().arrayIteratorValueNextPrivateName(), privateFuncArrayIteratorValueNext, DontEnum | DontDelete | ReadOnly),
751         GlobalPropertyInfo(vm.propertyNames->builtinNames().arrayIteratorKeyNextPrivateName(), privateFuncArrayIteratorKeyNext, DontEnum | DontDelete | ReadOnly),
752         GlobalPropertyInfo(vm.propertyNames->builtinNames().arrayIteratorKeyValueNextPrivateName(), privateFuncArrayIteratorKeyValueNext, DontEnum | DontDelete | ReadOnly),
753         GlobalPropertyInfo(vm.propertyNames->builtinNames().createArrayIteratorPrivateName(), privateFuncCreateArrayIterator, DontEnum | DontDelete | ReadOnly),
754
755         GlobalPropertyInfo(vm.propertyNames->builtinNames().toLengthPrivateName(), privateFuncToLength, DontEnum | DontDelete | ReadOnly),
756         GlobalPropertyInfo(vm.propertyNames->builtinNames().toIntegerPrivateName(), privateFuncToInteger, DontEnum | DontDelete | ReadOnly),
757         GlobalPropertyInfo(vm.propertyNames->builtinNames().isDictionaryPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectIsDictionaryCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
758         GlobalPropertyInfo(vm.propertyNames->builtinNames().isPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsIsPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
759         GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseReactionPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseReactionCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
760         GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseCapabilityPrivateName(), m_newPromiseCapabilityFunction.get(), DontEnum | DontDelete | ReadOnly),
761         GlobalPropertyInfo(vm.propertyNames->builtinNames().triggerPromiseReactionsPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsTriggerPromiseReactionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
762         GlobalPropertyInfo(vm.propertyNames->builtinNames().rejectPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsRejectPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
763         GlobalPropertyInfo(vm.propertyNames->builtinNames().fulfillPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsFulfillPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
764         GlobalPropertyInfo(vm.propertyNames->builtinNames().createResolvingFunctionsPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsCreateResolvingFunctionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
765         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseReactionJobPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsPromiseReactionJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
766         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseResolveThenableJobPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsPromiseResolveThenableJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
767         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum | DontDelete | ReadOnly),
768         GlobalPropertyInfo(vm.propertyNames->MapPrivateName, mapConstructor, DontEnum | DontDelete | ReadOnly),
769         GlobalPropertyInfo(vm.propertyNames->builtinNames().generatorResumePrivateName(), JSFunction::createBuiltinFunction(vm, generatorPrototypeGeneratorResumeCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
770         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, DontEnum | DontDelete | ReadOnly),
771         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisNumberValuePrivateName(), privateFuncThisNumberValue, DontEnum | DontDelete | ReadOnly),
772 #if ENABLE(INTL)
773         GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), DontEnum | DontDelete | ReadOnly),
774         GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),
775         GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), DontEnum | DontDelete | ReadOnly),
776 #endif // ENABLE(INTL)
777
778         GlobalPropertyInfo(vm.propertyNames->isConstructorPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
779         GlobalPropertyInfo(vm.propertyNames->isRegExpObjectPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsRegExpObject, IsRegExpObjectIntrinsic), DontEnum | DontDelete | ReadOnly),
780         GlobalPropertyInfo(vm.propertyNames->builtinNames().speciesConstructorPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectSpeciesConstructorCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
781
782         GlobalPropertyInfo(vm.propertyNames->regExpProtoFlagsGetterPrivateName, regExpProtoFlagsGetterObject, DontEnum | DontDelete | ReadOnly),
783         GlobalPropertyInfo(vm.propertyNames->regExpProtoGlobalGetterPrivateName, regExpProtoGlobalGetterObject, DontEnum | DontDelete | ReadOnly),
784         GlobalPropertyInfo(vm.propertyNames->regExpProtoIgnoreCaseGetterPrivateName, regExpProtoIgnoreCaseGetterObject, DontEnum | DontDelete | ReadOnly),
785         GlobalPropertyInfo(vm.propertyNames->regExpProtoMultilineGetterPrivateName, regExpProtoMultilineGetterObject, DontEnum | DontDelete | ReadOnly),
786         GlobalPropertyInfo(vm.propertyNames->regExpProtoSourceGetterPrivateName, regExpProtoSourceGetterObject, DontEnum | DontDelete | ReadOnly),
787         GlobalPropertyInfo(vm.propertyNames->regExpProtoStickyGetterPrivateName, regExpProtoStickyGetterObject, DontEnum | DontDelete | ReadOnly),
788         GlobalPropertyInfo(vm.propertyNames->regExpProtoUnicodeGetterPrivateName, regExpProtoUnicodeGetterObject, DontEnum | DontDelete | ReadOnly),
789
790         // RegExp.prototype helpers.
791         GlobalPropertyInfo(vm.propertyNames->regExpBuiltinExecPrivateName, builtinRegExpExec, DontEnum | DontDelete | ReadOnly),
792         GlobalPropertyInfo(vm.propertyNames->regExpCreatePrivateName, JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
793         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForRegExpMatchPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeHasObservableSideEffectsForRegExpMatchCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
794         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForRegExpSplitPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeHasObservableSideEffectsForRegExpSplitCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
795         GlobalPropertyInfo(vm.propertyNames->builtinNames().advanceStringIndexPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeAdvanceStringIndexCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
796         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpExecPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeRegExpExecCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
797         GlobalPropertyInfo(vm.propertyNames->regExpMatchFastPrivateName, JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast), DontEnum | DontDelete | ReadOnly),
798         GlobalPropertyInfo(vm.propertyNames->regExpSearchFastPrivateName, JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), DontEnum | DontDelete | ReadOnly),
799         GlobalPropertyInfo(vm.propertyNames->regExpSplitFastPrivateName, JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
800         GlobalPropertyInfo(vm.propertyNames->regExpPrototypeSymbolReplacePrivateName, m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), DontEnum | DontDelete | ReadOnly),
801         GlobalPropertyInfo(vm.propertyNames->regExpTestFastPrivateName, JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), DontEnum | DontDelete | ReadOnly),
802
803         // String.prototype helpers.
804         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForStringReplacePrivateName(), JSFunction::createBuiltinFunction(vm, stringPrototypeHasObservableSideEffectsForStringReplaceCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
805         GlobalPropertyInfo(vm.propertyNames->stringIncludesInternalPrivateName, JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), DontEnum | DontDelete | ReadOnly),
806         GlobalPropertyInfo(vm.propertyNames->stringSplitFastPrivateName, JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
807         GlobalPropertyInfo(vm.propertyNames->stringSubstrInternalPrivateName, JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), DontEnum | DontDelete | ReadOnly),
808     };
809     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
810     
811     m_specialPointers[Special::CallFunction] = m_callFunction.get();
812     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
813     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
814     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
815
816     m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::DefinePropertyFunction)] = m_definePropertyFunction.get();
817
818     if (UNLIKELY(Options::useDollarVM())) {
819         JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get()));
820         m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype));
821         JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
822
823         GlobalPropertyInfo extraStaticGlobals[] = {
824             GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, DontEnum | DontDelete | ReadOnly),
825         };
826         addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
827
828         putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum);
829     }
830
831     resetPrototype(vm, getPrototypeDirect());
832 }
833
834 bool JSGlobalObject::hasLegacyProfiler() const
835 {
836     return globalObjectMethodTable()->supportsLegacyProfiling(this);
837 }
838
839 bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
840 {
841     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
842     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
843
844     if (UNLIKELY(isThisValueAltered(slot, thisObject)))
845         return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
846
847     bool shouldThrowReadOnlyError = slot.isStrictMode();
848     bool ignoreReadOnlyErrors = false;
849     bool putResult = false;
850     if (symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult))
851         return putResult;
852     return Base::put(thisObject, exec, propertyName, value, slot);
853 }
854
855 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
856 {
857     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
858     PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
859     // silently ignore attempts to add accessors aliasing vars.
860     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
861         return false;
862     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
863 }
864
865 void JSGlobalObject::addGlobalVar(const Identifier& ident)
866 {
867     ConcurrentJITLocker locker(symbolTable()->m_lock);
868     SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
869     if (!entry.isNull())
870         return;
871     
872     ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
873     SymbolTableEntry newEntry(VarOffset(offset), 0);
874     newEntry.prepareToWatch();
875     symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
876     
877     ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
878     RELEASE_ASSERT(offsetForAssert == offset);
879 }
880
881 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
882 {
883     VM& vm = exec->vm();
884     removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties.
885     addGlobalVar(propertyName);
886 }
887
888 void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
889 {
890     m_globalScopeExtension.set(vm(), this, scope);
891 }
892
893 void JSGlobalObject::clearGlobalScopeExtension()
894 {
895     m_globalScopeExtension.clear();
896 }
897
898 static inline JSObject* lastInPrototypeChain(JSObject* object)
899 {
900     JSObject* o = object;
901     while (o->getPrototypeDirect().isObject())
902         o = asObject(o->getPrototypeDirect());
903     return o;
904 }
905
906 // Private namespace for helpers for JSGlobalObject::haveABadTime()
907 namespace {
908
909 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
910 public:
911     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
912     IterationStatus operator()(JSCell*);
913
914 private:
915     void visit(JSCell*);
916
917     MarkedArgumentBuffer& m_foundObjects;
918     JSGlobalObject* m_globalObject;
919 };
920
921 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
922     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
923     : m_foundObjects(foundObjects)
924     , m_globalObject(globalObject)
925 {
926 }
927
928 inline bool hasBrokenIndexing(JSObject* object)
929 {
930     // This will change if we have more indexing types.
931     IndexingType type = object->indexingType();
932     // This could be made obviously more efficient, but isn't made so right now, because
933     // we expect this to be an unlikely slow path anyway.
934     return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
935 }
936
937 inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
938 {
939     if (!cell->isObject())
940         return;
941     
942     JSObject* object = asObject(cell);
943
944     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
945     if (!hasBrokenIndexing(object))
946         return;
947     
948     // We only want to have a bad time in the affected global object, not in the entire
949     // VM. But we have to be careful, since there may be objects that claim to belong to
950     // a different global object that have prototypes from our global object.
951     bool foundGlobalObject = false;
952     for (JSObject* current = object; ;) {
953         if (current->globalObject() == m_globalObject) {
954             foundGlobalObject = true;
955             break;
956         }
957         
958         JSValue prototypeValue = current->getPrototypeDirect();
959         if (prototypeValue.isNull())
960             break;
961         current = asObject(prototypeValue);
962     }
963     if (!foundGlobalObject)
964         return;
965     
966     m_foundObjects.append(object);
967 }
968
969 IterationStatus ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
970 {
971     visit(cell);
972     return IterationStatus::Continue;
973 }
974
975 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
976
977 void JSGlobalObject::haveABadTime(VM& vm)
978 {
979     ASSERT(&vm == &this->vm());
980     
981     if (isHavingABadTime())
982         return;
983     
984     // Make sure that all allocations or indexed storage transitions that are inlining
985     // the assumption that it's safe to transition to a non-SlowPut array storage don't
986     // do so anymore.
987     m_havingABadTimeWatchpoint->fireAll("Having a bad time");
988     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
989     
990     // Make sure that all JSArray allocations that load the appropriate structure from
991     // this object now load a structure that uses SlowPut.
992     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
993         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
994
995     // Same for any special array structures.
996     m_regExpMatchesArrayStructure.set(vm, this, m_regExpMatchesArraySlowPutStructure.get());
997     
998     // Make sure that all objects that have indexed storage switch to the slow kind of
999     // indexed storage.
1000     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
1001     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
1002     {
1003         HeapIterationScope iterationScope(vm.heap);
1004         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
1005     }
1006     while (!foundObjects.isEmpty()) {
1007         JSObject* object = asObject(foundObjects.last());
1008         foundObjects.removeLast();
1009         ASSERT(hasBrokenIndexing(object));
1010         object->switchToSlowPutArrayStorage(vm);
1011     }
1012 }
1013
1014 bool JSGlobalObject::objectPrototypeIsSane()
1015 {
1016     return !hasIndexedProperties(m_objectPrototype->indexingType())
1017         && m_objectPrototype->getPrototypeDirect().isNull();
1018 }
1019
1020 bool JSGlobalObject::arrayPrototypeChainIsSane()
1021 {
1022     return !hasIndexedProperties(m_arrayPrototype->indexingType())
1023         && m_arrayPrototype->getPrototypeDirect() == m_objectPrototype.get()
1024         && objectPrototypeIsSane();
1025 }
1026
1027 bool JSGlobalObject::stringPrototypeChainIsSane()
1028 {
1029     return !hasIndexedProperties(m_stringPrototype->indexingType())
1030         && m_stringPrototype->getPrototypeDirect() == m_objectPrototype.get()
1031         && objectPrototypeIsSane();
1032 }
1033
1034 // Set prototype, and also insert the object prototype at the end of the chain.
1035 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1036 {
1037     setPrototypeDirect(vm, prototype);
1038
1039     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
1040     JSObject* objectPrototype = m_objectPrototype.get();
1041     if (oldLastInPrototypeChain != objectPrototype)
1042         oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1043
1044     // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1045     setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1046 }
1047
1048 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1049
1050     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1051     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1052     Base::visitChildren(thisObject, visitor);
1053
1054     visitor.append(&thisObject->m_globalThis);
1055
1056     visitor.append(&thisObject->m_globalLexicalEnvironment);
1057     visitor.append(&thisObject->m_globalScopeExtension);
1058     visitor.append(&thisObject->m_globalCallee);
1059     visitor.append(&thisObject->m_regExpConstructor);
1060     visitor.append(&thisObject->m_errorConstructor);
1061     visitor.append(&thisObject->m_nativeErrorPrototypeStructure);
1062     visitor.append(&thisObject->m_nativeErrorStructure);
1063     thisObject->m_evalErrorConstructor.visit(visitor);
1064     visitor.append(&thisObject->m_rangeErrorConstructor);
1065     thisObject->m_referenceErrorConstructor.visit(visitor);
1066     thisObject->m_syntaxErrorConstructor.visit(visitor);
1067     visitor.append(&thisObject->m_typeErrorConstructor);
1068     thisObject->m_URIErrorConstructor.visit(visitor);
1069     visitor.append(&thisObject->m_objectConstructor);
1070     visitor.append(&thisObject->m_promiseConstructor);
1071
1072     visitor.append(&thisObject->m_nullGetterFunction);
1073     visitor.append(&thisObject->m_nullSetterFunction);
1074
1075     visitor.append(&thisObject->m_parseIntFunction);
1076     visitor.append(&thisObject->m_evalFunction);
1077     visitor.append(&thisObject->m_callFunction);
1078     visitor.append(&thisObject->m_applyFunction);
1079     visitor.append(&thisObject->m_definePropertyFunction);
1080     thisObject->m_arrayProtoValuesFunction.visit(visitor);
1081     thisObject->m_initializePromiseFunction.visit(visitor);
1082     visitor.append(&thisObject->m_newPromiseCapabilityFunction);
1083     visitor.append(&thisObject->m_functionProtoHasInstanceSymbolFunction);
1084     thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1085     thisObject->m_throwTypeErrorCalleeAndCallerGetterSetter.visit(visitor);
1086     thisObject->m_throwTypeErrorArgumentsAndCallerInStrictModeGetterSetter.visit(visitor);
1087     thisObject->m_throwTypeErrorArgumentsAndCallerInClassContextGetterSetter.visit(visitor);
1088     visitor.append(&thisObject->m_moduleLoader);
1089
1090     visitor.append(&thisObject->m_objectPrototype);
1091     visitor.append(&thisObject->m_functionPrototype);
1092     visitor.append(&thisObject->m_arrayPrototype);
1093     visitor.append(&thisObject->m_errorPrototype);
1094     visitor.append(&thisObject->m_iteratorPrototype);
1095     visitor.append(&thisObject->m_generatorFunctionPrototype);
1096     visitor.append(&thisObject->m_generatorPrototype);
1097
1098     thisObject->m_debuggerScopeStructure.visit(visitor);
1099     thisObject->m_withScopeStructure.visit(visitor);
1100     visitor.append(&thisObject->m_strictEvalActivationStructure);
1101     visitor.append(&thisObject->m_lexicalEnvironmentStructure);
1102     thisObject->m_moduleEnvironmentStructure.visit(visitor);
1103     visitor.append(&thisObject->m_directArgumentsStructure);
1104     visitor.append(&thisObject->m_scopedArgumentsStructure);
1105     visitor.append(&thisObject->m_clonedArgumentsStructure);
1106     visitor.append(&thisObject->m_objectStructureForObjectConstructor);
1107     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1108         visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
1109     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1110         visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1111     thisObject->m_callbackConstructorStructure.visit(visitor);
1112     thisObject->m_callbackFunctionStructure.visit(visitor);
1113     thisObject->m_callbackObjectStructure.visit(visitor);
1114     visitor.append(&thisObject->m_propertyNameIteratorStructure);
1115 #if JSC_OBJC_API_ENABLED
1116     thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1117     thisObject->m_objcWrapperObjectStructure.visit(visitor);
1118 #endif
1119     thisObject->m_nullPrototypeObjectStructure.visit(visitor);
1120     visitor.append(&thisObject->m_errorStructure);
1121     visitor.append(&thisObject->m_calleeStructure);
1122     visitor.append(&thisObject->m_functionStructure);
1123     thisObject->m_boundSlotBaseFunctionStructure.visit(visitor);
1124     thisObject->m_boundFunctionStructure.visit(visitor);
1125     visitor.append(&thisObject->m_getterSetterStructure);
1126     thisObject->m_nativeStdFunctionStructure.visit(visitor);
1127     thisObject->m_namedFunctionStructure.visit(visitor);
1128     visitor.append(&thisObject->m_symbolObjectStructure);
1129     visitor.append(&thisObject->m_regExpStructure);
1130     visitor.append(&thisObject->m_generatorFunctionStructure);
1131     visitor.append(&thisObject->m_iteratorResultObjectStructure);
1132     visitor.append(&thisObject->m_regExpMatchesArrayStructure);
1133     visitor.append(&thisObject->m_regExpMatchesArraySlowPutStructure);
1134     visitor.append(&thisObject->m_moduleRecordStructure);
1135     visitor.append(&thisObject->m_moduleNamespaceObjectStructure);
1136     visitor.append(&thisObject->m_dollarVMStructure);
1137     visitor.append(&thisObject->m_proxyObjectStructure);
1138     visitor.append(&thisObject->m_callableProxyObjectStructure);
1139     visitor.append(&thisObject->m_proxyRevokeStructure);
1140 #if ENABLE(WEBASSEMBLY)
1141     visitor.append(&thisObject->m_wasmModuleStructure);
1142 #endif
1143
1144 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
1145     visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
1146     visitor.append(&thisObject->m_ ## properName ## Structure); \
1147
1148     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1149
1150 #undef VISIT_SIMPLE_TYPE
1151
1152 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
1153     thisObject->m_ ## properName ## Structure.visit(visitor);
1154     
1155     FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1156     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_LAZY_TYPE)
1157
1158 #undef VISIT_LAZY_TYPE
1159
1160     for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;)
1161         thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1162     
1163     visitor.append(&thisObject->m_speciesGetterSetter);
1164     thisObject->m_typedArrayProto.visit(visitor);
1165     thisObject->m_typedArraySuperConstructor.visit(visitor);
1166 }
1167
1168 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
1169 {
1170     if (ecmaMode == StrictMode)
1171         return jsUndefined();
1172     return exec->globalThisValue();
1173 }
1174
1175 ExecState* JSGlobalObject::globalExec()
1176 {
1177     return CallFrame::create(m_globalCallFrame);
1178 }
1179
1180 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1181 {
1182     ScopeOffset startOffset = addVariables(count, jsUndefined());
1183
1184     for (int i = 0; i < count; ++i) {
1185         GlobalPropertyInfo& global = globals[i];
1186         ASSERT(global.attributes & DontDelete);
1187         
1188         WatchpointSet* watchpointSet = nullptr;
1189         WriteBarrierBase<Unknown>* variable = nullptr;
1190         {
1191             ConcurrentJITLocker locker(symbolTable()->m_lock);
1192             ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1193             RELEASE_ASSERT(offset = startOffset + i);
1194             SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1195             newEntry.prepareToWatch();
1196             watchpointSet = newEntry.watchpointSet();
1197             symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1198             variable = &variableAt(offset);
1199         }
1200         symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1201     }
1202 }
1203
1204 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1205 {
1206     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
1207     if (getStaticPropertySlot<JSGlobalObject, Base>(exec, globalObjectTable, thisObject, propertyName, slot))
1208         return true;
1209     return symbolTableGet(thisObject, propertyName, slot);
1210 }
1211
1212 void JSGlobalObject::clearRareData(JSCell* cell)
1213 {
1214     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1215 }
1216
1217 void slowValidateCell(JSGlobalObject* globalObject)
1218 {
1219     RELEASE_ASSERT(globalObject->isGlobalObject());
1220     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1221 }
1222
1223 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
1224 {
1225     ParserError error;
1226     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
1227     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
1228     ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
1229     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(
1230         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, 
1231         debuggerMode, profilerMode, error);
1232
1233     if (hasDebugger())
1234         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1235
1236     if (error.isValid()) {
1237         *exception = error.toErrorObject(this, executable->source());
1238         return nullptr;
1239     }
1240     
1241     return unlinkedCodeBlock;
1242 }
1243
1244 UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable, ThisTDZMode thisTDZMode, const VariableEnvironment* variablesUnderTDZ)
1245 {
1246     ParserError error;
1247     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
1248     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
1249     EvalContextType evalContextType = executable->executableInfo().evalContextType();
1250     
1251     ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
1252     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(
1253         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, debuggerMode, profilerMode, error, evalContextType, variablesUnderTDZ);
1254
1255     if (hasDebugger())
1256         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1257
1258     if (error.isValid()) {
1259         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
1260         return nullptr;
1261     }
1262
1263     return unlinkedCodeBlock;
1264 }
1265
1266 UnlinkedModuleProgramCodeBlock* JSGlobalObject::createModuleProgramCodeBlock(CallFrame* callFrame, ModuleProgramExecutable* executable)
1267 {
1268     ParserError error;
1269     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
1270     ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
1271     UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getModuleProgramCodeBlock(
1272         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, debuggerMode, profilerMode, error);
1273
1274     if (hasDebugger())
1275         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1276
1277     if (error.isValid()) {
1278         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
1279         return nullptr;
1280     }
1281
1282     return unlinkedCodeBlock;
1283 }
1284
1285 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1286 {
1287 #if ENABLE(REMOTE_INSPECTOR)
1288     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1289 #else
1290     UNUSED_PARAM(enabled);
1291 #endif
1292 }
1293
1294 bool JSGlobalObject::remoteDebuggingEnabled() const
1295 {
1296 #if ENABLE(REMOTE_INSPECTOR)
1297     return m_inspectorDebuggable->remoteDebuggingAllowed();
1298 #else
1299     return false;
1300 #endif
1301 }
1302
1303 #if ENABLE(WEB_REPLAY)
1304 void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
1305 {
1306     m_inputCursor = prpCursor;
1307     ASSERT(m_inputCursor);
1308
1309     InputCursor& cursor = inputCursor();
1310     // Save or set the random seed. This performed here rather than the constructor
1311     // to avoid threading the input cursor through all the abstraction layers.
1312     if (cursor.isCapturing())
1313         cursor.appendInput<SetRandomSeed>(m_weakRandom.seed());
1314     else if (cursor.isReplaying()) {
1315         if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
1316             m_weakRandom.setSeed(static_cast<unsigned>(input->randomSeed()));
1317     }
1318 }
1319 #endif
1320
1321 void JSGlobalObject::setName(const String& name)
1322 {
1323     m_name = name;
1324
1325 #if ENABLE(REMOTE_INSPECTOR)
1326     m_inspectorDebuggable->update();
1327 #endif
1328 }
1329
1330 # if ENABLE(INTL)
1331 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1332 {
1333     if (m_intlCollatorAvailableLocales.isEmpty()) {
1334         int32_t count = ucol_countAvailable();
1335         for (int32_t i = 0; i < count; ++i) {
1336             String locale(ucol_getAvailable(i));
1337             convertICULocaleToBCP47LanguageTag(locale);
1338             m_intlCollatorAvailableLocales.add(locale);
1339         }
1340     }
1341     return m_intlCollatorAvailableLocales;
1342 }
1343
1344 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1345 {
1346     if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1347         int32_t count = udat_countAvailable();
1348         for (int32_t i = 0; i < count; ++i) {
1349             String locale(udat_getAvailable(i));
1350             convertICULocaleToBCP47LanguageTag(locale);
1351             m_intlDateTimeFormatAvailableLocales.add(locale);
1352         }
1353     }
1354     return m_intlDateTimeFormatAvailableLocales;
1355 }
1356
1357 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1358 {
1359     if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1360         int32_t count = unum_countAvailable();
1361         for (int32_t i = 0; i < count; ++i) {
1362             String locale(unum_getAvailable(i));
1363             convertICULocaleToBCP47LanguageTag(locale);
1364             m_intlNumberFormatAvailableLocales.add(locale);
1365         }
1366     }
1367     return m_intlNumberFormatAvailableLocales;
1368 }
1369 #endif // ENABLE(INTL)
1370
1371 void JSGlobalObject::queueMicrotask(PassRefPtr<Microtask> task)
1372 {
1373     if (globalObjectMethodTable()->queueTaskToEventLoop) {
1374         globalObjectMethodTable()->queueTaskToEventLoop(this, task);
1375         return;
1376     }
1377
1378     vm().queueMicrotask(this, task);
1379 }
1380
1381 bool JSGlobalObject::hasDebugger() const
1382
1383     return m_debugger;
1384 }
1385
1386 bool JSGlobalObject::hasInteractiveDebugger() const 
1387
1388     return m_debugger && m_debugger->isInteractivelyDebugging();
1389 }
1390
1391 } // namespace JSC