de61850a71323a2899ca10a0d661ea200e89773b
[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, IsArrayConstructorIntrinsic);
685     JSFunction* privateFuncIsJSArray = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncIsJSArray, IsJSArrayIntrinsic);
686     JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
687     JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
688     JSFunction* privateFuncConcatSlowPath = JSFunction::createBuiltinFunction(vm, arrayPrototypeConcatSlowPathCodeGenerator(vm), this);
689
690     JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
691     JSFunction* privateFuncCreateArrayIterator = JSFunction::createBuiltinFunction(vm, arrayPrototypeCreateArrayIteratorConstructorCodeGenerator(vm), this);
692     privateFuncCreateArrayIterator->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
693     JSFunction* privateFuncArrayIteratorValueNext = JSFunction::createBuiltinFunction(vm, arrayIteratorPrototypeArrayIteratorValueNextCodeGenerator(vm), this);
694     JSFunction* privateFuncArrayIteratorKeyNext = JSFunction::createBuiltinFunction(vm, arrayIteratorPrototypeArrayIteratorKeyNextCodeGenerator(vm), this);
695     JSFunction* privateFuncArrayIteratorKeyValueNext = JSFunction::createBuiltinFunction(vm, arrayIteratorPrototypeArrayIteratorKeyValueNextCodeGenerator(vm), this);
696
697     JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
698     JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
699     m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
700     JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
701     JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
702     JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
703     JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
704     JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
705     m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
706     JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
707     m_regExpProtoExec.set(vm, this, builtinRegExpExec);
708     JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
709     m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
710
711     GlobalPropertyInfo staticGlobals[] = {
712         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
713         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
714         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
715         GlobalPropertyInfo(vm.propertyNames->ownEnumerablePropertyKeysPrivateName, JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly),
716         GlobalPropertyInfo(vm.propertyNames->getTemplateObjectPrivateName, privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly),
717         GlobalPropertyInfo(vm.propertyNames->enqueueJobPrivateName, JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),
718         GlobalPropertyInfo(vm.propertyNames->ErrorPrivateName, m_errorConstructor.get(), DontEnum | DontDelete | ReadOnly),
719         GlobalPropertyInfo(vm.propertyNames->RangeErrorPrivateName, m_rangeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
720         GlobalPropertyInfo(vm.propertyNames->TypeErrorPrivateName, m_typeErrorConstructor.get(), DontEnum | DontDelete | ReadOnly),
721         GlobalPropertyInfo(vm.propertyNames->typedArrayLengthPrivateName, privateFuncTypedArrayLength, DontEnum | DontDelete | ReadOnly),
722         GlobalPropertyInfo(vm.propertyNames->typedArrayGetOriginalConstructorPrivateName, privateFuncTypedArrayGetOriginalConstructor, DontEnum | DontDelete | ReadOnly),
723         GlobalPropertyInfo(vm.propertyNames->typedArraySortPrivateName, privateFuncTypedArraySort, DontEnum | DontDelete | ReadOnly),
724         GlobalPropertyInfo(vm.propertyNames->isBoundFunctionPrivateName, privateFuncIsBoundFunction, DontEnum | DontDelete | ReadOnly),
725         GlobalPropertyInfo(vm.propertyNames->hasInstanceBoundFunctionPrivateName, privateFuncHasInstanceBoundFunction, DontEnum | DontDelete | ReadOnly),
726         GlobalPropertyInfo(vm.propertyNames->instanceOfPrivateName, privateFuncInstanceOf, DontEnum | DontDelete | ReadOnly),
727         GlobalPropertyInfo(vm.propertyNames->BuiltinLogPrivateName, builtinLog, DontEnum | DontDelete | ReadOnly),
728         GlobalPropertyInfo(vm.propertyNames->NumberPrivateName, numberConstructor, DontEnum | DontDelete | ReadOnly),
729         GlobalPropertyInfo(vm.propertyNames->RegExpPrivateName, m_regExpConstructor.get(), DontEnum | DontDelete | ReadOnly),
730         GlobalPropertyInfo(vm.propertyNames->StringPrivateName, stringConstructor, DontEnum | DontDelete | ReadOnly),
731         GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
732         GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
733         GlobalPropertyInfo(vm.propertyNames->truncPrivateName, privateFuncTrunc, DontEnum | DontDelete | ReadOnly),
734         GlobalPropertyInfo(vm.propertyNames->isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly),
735         GlobalPropertyInfo(vm.propertyNames->isNaNPrivateName, privateFuncIsNaN, DontEnum | DontDelete | ReadOnly),
736         GlobalPropertyInfo(vm.propertyNames->PromisePrivateName, promiseConstructor, DontEnum | DontDelete | ReadOnly),
737         GlobalPropertyInfo(vm.propertyNames->ReflectPrivateName, reflectObject, DontEnum | DontDelete | ReadOnly),
738         GlobalPropertyInfo(vm.propertyNames->InternalPromisePrivateName, internalPromiseConstructor, DontEnum | DontDelete | ReadOnly),
739
740         GlobalPropertyInfo(vm.propertyNames->repeatCharacterPrivateName, JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), DontEnum | DontDelete | ReadOnly),
741         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatSlowPathPrivateName(), JSFunction::createBuiltinFunction(vm, stringPrototypeRepeatSlowPathCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
742         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharactersSlowPathPrivateName(), JSFunction::createBuiltinFunction(vm, stringPrototypeRepeatCharactersSlowPathCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
743
744         GlobalPropertyInfo(vm.propertyNames->isSetPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncIsSet), DontEnum | DontDelete | ReadOnly),
745         GlobalPropertyInfo(vm.propertyNames->SetIteratorPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncSetIterator), DontEnum | DontDelete | ReadOnly),
746         GlobalPropertyInfo(vm.propertyNames->setIteratorNextPrivateName, JSFunction::create(vm, this, 0, String(), privateFuncSetIteratorNext), DontEnum | DontDelete | ReadOnly),
747         GlobalPropertyInfo(vm.propertyNames->isMapPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncIsMap), DontEnum | DontDelete | ReadOnly),
748         GlobalPropertyInfo(vm.propertyNames->isArrayPrivateName, arrayConstructor->getDirect(vm, vm.propertyNames->isArray), DontEnum | DontDelete | ReadOnly),
749         GlobalPropertyInfo(vm.propertyNames->isArrayConstructorPrivateName, privateFuncIsArrayConstructor, DontEnum | DontDelete | ReadOnly),
750         GlobalPropertyInfo(vm.propertyNames->isJSArrayPrivateName, privateFuncIsJSArray, DontEnum | DontDelete | ReadOnly),
751         GlobalPropertyInfo(vm.propertyNames->concatMemcpyPrivateName, privateFuncConcatMemcpy, DontEnum | DontDelete | ReadOnly),
752         GlobalPropertyInfo(vm.propertyNames->appendMemcpyPrivateName, privateFuncAppendMemcpy, DontEnum | DontDelete | ReadOnly),
753         GlobalPropertyInfo(vm.propertyNames->builtinNames().concatSlowPathPrivateName(), privateFuncConcatSlowPath, DontEnum | DontDelete | ReadOnly),
754         GlobalPropertyInfo(vm.propertyNames->MapIteratorPrivateName, JSFunction::create(vm, this, 1, String(), privateFuncMapIterator), DontEnum | DontDelete | ReadOnly),
755         GlobalPropertyInfo(vm.propertyNames->mapIteratorNextPrivateName, JSFunction::create(vm, this, 0, String(), privateFuncMapIteratorNext), DontEnum | DontDelete | ReadOnly),
756         GlobalPropertyInfo(vm.propertyNames->builtinNames().arrayIteratorValueNextPrivateName(), privateFuncArrayIteratorValueNext, DontEnum | DontDelete | ReadOnly),
757         GlobalPropertyInfo(vm.propertyNames->builtinNames().arrayIteratorKeyNextPrivateName(), privateFuncArrayIteratorKeyNext, DontEnum | DontDelete | ReadOnly),
758         GlobalPropertyInfo(vm.propertyNames->builtinNames().arrayIteratorKeyValueNextPrivateName(), privateFuncArrayIteratorKeyValueNext, DontEnum | DontDelete | ReadOnly),
759         GlobalPropertyInfo(vm.propertyNames->builtinNames().createArrayIteratorPrivateName(), privateFuncCreateArrayIterator, DontEnum | DontDelete | ReadOnly),
760
761         GlobalPropertyInfo(vm.propertyNames->builtinNames().toLengthPrivateName(), privateFuncToLength, DontEnum | DontDelete | ReadOnly),
762         GlobalPropertyInfo(vm.propertyNames->builtinNames().toIntegerPrivateName(), privateFuncToInteger, DontEnum | DontDelete | ReadOnly),
763         GlobalPropertyInfo(vm.propertyNames->builtinNames().isDictionaryPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectIsDictionaryCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
764         GlobalPropertyInfo(vm.propertyNames->builtinNames().isPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsIsPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
765         GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseReactionPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsNewPromiseReactionCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
766         GlobalPropertyInfo(vm.propertyNames->builtinNames().newPromiseCapabilityPrivateName(), m_newPromiseCapabilityFunction.get(), DontEnum | DontDelete | ReadOnly),
767         GlobalPropertyInfo(vm.propertyNames->builtinNames().triggerPromiseReactionsPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsTriggerPromiseReactionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
768         GlobalPropertyInfo(vm.propertyNames->builtinNames().rejectPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsRejectPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
769         GlobalPropertyInfo(vm.propertyNames->builtinNames().fulfillPromisePrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsFulfillPromiseCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
770         GlobalPropertyInfo(vm.propertyNames->builtinNames().createResolvingFunctionsPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsCreateResolvingFunctionsCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
771         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseReactionJobPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsPromiseReactionJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
772         GlobalPropertyInfo(vm.propertyNames->builtinNames().promiseResolveThenableJobPrivateName(), JSFunction::createBuiltinFunction(vm, promiseOperationsPromiseResolveThenableJobCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
773         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), DontEnum | DontDelete | ReadOnly),
774         GlobalPropertyInfo(vm.propertyNames->MapPrivateName, mapConstructor, DontEnum | DontDelete | ReadOnly),
775         GlobalPropertyInfo(vm.propertyNames->builtinNames().generatorResumePrivateName(), JSFunction::createBuiltinFunction(vm, generatorPrototypeGeneratorResumeCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
776         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, DontEnum | DontDelete | ReadOnly),
777         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisNumberValuePrivateName(), privateFuncThisNumberValue, DontEnum | DontDelete | ReadOnly),
778 #if ENABLE(INTL)
779         GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), DontEnum | DontDelete | ReadOnly),
780         GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),
781         GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), DontEnum | DontDelete | ReadOnly),
782 #endif // ENABLE(INTL)
783
784         GlobalPropertyInfo(vm.propertyNames->isConstructorPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
785         GlobalPropertyInfo(vm.propertyNames->isRegExpObjectPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsRegExpObject, IsRegExpObjectIntrinsic), DontEnum | DontDelete | ReadOnly),
786         GlobalPropertyInfo(vm.propertyNames->builtinNames().speciesConstructorPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectSpeciesConstructorCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
787
788         GlobalPropertyInfo(vm.propertyNames->regExpProtoFlagsGetterPrivateName, regExpProtoFlagsGetterObject, DontEnum | DontDelete | ReadOnly),
789         GlobalPropertyInfo(vm.propertyNames->regExpProtoGlobalGetterPrivateName, regExpProtoGlobalGetterObject, DontEnum | DontDelete | ReadOnly),
790         GlobalPropertyInfo(vm.propertyNames->regExpProtoIgnoreCaseGetterPrivateName, regExpProtoIgnoreCaseGetterObject, DontEnum | DontDelete | ReadOnly),
791         GlobalPropertyInfo(vm.propertyNames->regExpProtoMultilineGetterPrivateName, regExpProtoMultilineGetterObject, DontEnum | DontDelete | ReadOnly),
792         GlobalPropertyInfo(vm.propertyNames->regExpProtoSourceGetterPrivateName, regExpProtoSourceGetterObject, DontEnum | DontDelete | ReadOnly),
793         GlobalPropertyInfo(vm.propertyNames->regExpProtoStickyGetterPrivateName, regExpProtoStickyGetterObject, DontEnum | DontDelete | ReadOnly),
794         GlobalPropertyInfo(vm.propertyNames->regExpProtoUnicodeGetterPrivateName, regExpProtoUnicodeGetterObject, DontEnum | DontDelete | ReadOnly),
795
796         // RegExp.prototype helpers.
797         GlobalPropertyInfo(vm.propertyNames->regExpBuiltinExecPrivateName, builtinRegExpExec, DontEnum | DontDelete | ReadOnly),
798         GlobalPropertyInfo(vm.propertyNames->regExpCreatePrivateName, JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
799         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForRegExpMatchPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeHasObservableSideEffectsForRegExpMatchCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
800         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForRegExpSplitPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeHasObservableSideEffectsForRegExpSplitCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
801         GlobalPropertyInfo(vm.propertyNames->builtinNames().advanceStringIndexPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeAdvanceStringIndexCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
802         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpExecPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeRegExpExecCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
803         GlobalPropertyInfo(vm.propertyNames->regExpMatchFastPrivateName, JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast), DontEnum | DontDelete | ReadOnly),
804         GlobalPropertyInfo(vm.propertyNames->regExpSearchFastPrivateName, JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), DontEnum | DontDelete | ReadOnly),
805         GlobalPropertyInfo(vm.propertyNames->regExpSplitFastPrivateName, JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
806         GlobalPropertyInfo(vm.propertyNames->regExpPrototypeSymbolReplacePrivateName, m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), DontEnum | DontDelete | ReadOnly),
807         GlobalPropertyInfo(vm.propertyNames->regExpTestFastPrivateName, JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), DontEnum | DontDelete | ReadOnly),
808
809         // String.prototype helpers.
810         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForStringReplacePrivateName(), JSFunction::createBuiltinFunction(vm, stringPrototypeHasObservableSideEffectsForStringReplaceCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
811         GlobalPropertyInfo(vm.propertyNames->stringIncludesInternalPrivateName, JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), DontEnum | DontDelete | ReadOnly),
812         GlobalPropertyInfo(vm.propertyNames->stringSplitFastPrivateName, JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
813         GlobalPropertyInfo(vm.propertyNames->stringSubstrInternalPrivateName, JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), DontEnum | DontDelete | ReadOnly),
814     };
815     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
816     
817     m_specialPointers[Special::CallFunction] = m_callFunction.get();
818     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
819     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
820     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
821
822     m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::DefinePropertyFunction)] = m_definePropertyFunction.get();
823
824     if (UNLIKELY(Options::useDollarVM())) {
825         JSDollarVMPrototype* dollarVMPrototype = JSDollarVMPrototype::create(vm, this, JSDollarVMPrototype::createStructure(vm, this, m_objectPrototype.get()));
826         m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, dollarVMPrototype));
827         JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
828
829         GlobalPropertyInfo extraStaticGlobals[] = {
830             GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, DontEnum | DontDelete | ReadOnly),
831         };
832         addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
833
834         putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, DontEnum);
835     }
836
837     resetPrototype(vm, getPrototypeDirect());
838 }
839
840 bool JSGlobalObject::hasLegacyProfiler() const
841 {
842     return globalObjectMethodTable()->supportsLegacyProfiling(this);
843 }
844
845 bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
846 {
847     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
848     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
849
850     if (UNLIKELY(isThisValueAltered(slot, thisObject)))
851         return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
852
853     bool shouldThrowReadOnlyError = slot.isStrictMode();
854     bool ignoreReadOnlyErrors = false;
855     bool putResult = false;
856     if (symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult))
857         return putResult;
858     return Base::put(thisObject, exec, propertyName, value, slot);
859 }
860
861 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
862 {
863     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
864     PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
865     // silently ignore attempts to add accessors aliasing vars.
866     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
867         return false;
868     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
869 }
870
871 void JSGlobalObject::addGlobalVar(const Identifier& ident)
872 {
873     ConcurrentJITLocker locker(symbolTable()->m_lock);
874     SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
875     if (!entry.isNull())
876         return;
877     
878     ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
879     SymbolTableEntry newEntry(VarOffset(offset), 0);
880     newEntry.prepareToWatch();
881     symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
882     
883     ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
884     RELEASE_ASSERT(offsetForAssert == offset);
885 }
886
887 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
888 {
889     VM& vm = exec->vm();
890     removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties.
891     addGlobalVar(propertyName);
892 }
893
894 void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
895 {
896     m_globalScopeExtension.set(vm(), this, scope);
897 }
898
899 void JSGlobalObject::clearGlobalScopeExtension()
900 {
901     m_globalScopeExtension.clear();
902 }
903
904 static inline JSObject* lastInPrototypeChain(JSObject* object)
905 {
906     JSObject* o = object;
907     while (o->getPrototypeDirect().isObject())
908         o = asObject(o->getPrototypeDirect());
909     return o;
910 }
911
912 // Private namespace for helpers for JSGlobalObject::haveABadTime()
913 namespace {
914
915 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
916 public:
917     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
918     IterationStatus operator()(JSCell*);
919
920 private:
921     void visit(JSCell*);
922
923     MarkedArgumentBuffer& m_foundObjects;
924     JSGlobalObject* m_globalObject;
925 };
926
927 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
928     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
929     : m_foundObjects(foundObjects)
930     , m_globalObject(globalObject)
931 {
932 }
933
934 inline bool hasBrokenIndexing(JSObject* object)
935 {
936     // This will change if we have more indexing types.
937     IndexingType type = object->indexingType();
938     // This could be made obviously more efficient, but isn't made so right now, because
939     // we expect this to be an unlikely slow path anyway.
940     return hasUndecided(type) || hasInt32(type) || hasDouble(type) || hasContiguous(type) || hasArrayStorage(type);
941 }
942
943 inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
944 {
945     if (!cell->isObject())
946         return;
947     
948     JSObject* object = asObject(cell);
949
950     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
951     if (!hasBrokenIndexing(object))
952         return;
953     
954     // We only want to have a bad time in the affected global object, not in the entire
955     // VM. But we have to be careful, since there may be objects that claim to belong to
956     // a different global object that have prototypes from our global object.
957     bool foundGlobalObject = false;
958     for (JSObject* current = object; ;) {
959         if (current->globalObject() == m_globalObject) {
960             foundGlobalObject = true;
961             break;
962         }
963         
964         JSValue prototypeValue = current->getPrototypeDirect();
965         if (prototypeValue.isNull())
966             break;
967         current = asObject(prototypeValue);
968     }
969     if (!foundGlobalObject)
970         return;
971     
972     m_foundObjects.append(object);
973 }
974
975 IterationStatus ObjectsWithBrokenIndexingFinder::operator()(JSCell* cell)
976 {
977     visit(cell);
978     return IterationStatus::Continue;
979 }
980
981 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
982
983 void JSGlobalObject::haveABadTime(VM& vm)
984 {
985     ASSERT(&vm == &this->vm());
986     
987     if (isHavingABadTime())
988         return;
989     
990     // Make sure that all allocations or indexed storage transitions that are inlining
991     // the assumption that it's safe to transition to a non-SlowPut array storage don't
992     // do so anymore.
993     m_havingABadTimeWatchpoint->fireAll("Having a bad time");
994     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
995     
996     // Make sure that all JSArray allocations that load the appropriate structure from
997     // this object now load a structure that uses SlowPut.
998     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
999         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1000
1001     // Same for any special array structures.
1002     m_regExpMatchesArrayStructure.set(vm, this, m_regExpMatchesArraySlowPutStructure.get());
1003     
1004     // Make sure that all objects that have indexed storage switch to the slow kind of
1005     // indexed storage.
1006     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
1007     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
1008     {
1009         HeapIterationScope iterationScope(vm.heap);
1010         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
1011     }
1012     while (!foundObjects.isEmpty()) {
1013         JSObject* object = asObject(foundObjects.last());
1014         foundObjects.removeLast();
1015         ASSERT(hasBrokenIndexing(object));
1016         object->switchToSlowPutArrayStorage(vm);
1017     }
1018 }
1019
1020 bool JSGlobalObject::objectPrototypeIsSane()
1021 {
1022     return !hasIndexedProperties(m_objectPrototype->indexingType())
1023         && m_objectPrototype->getPrototypeDirect().isNull();
1024 }
1025
1026 bool JSGlobalObject::arrayPrototypeChainIsSane()
1027 {
1028     return !hasIndexedProperties(m_arrayPrototype->indexingType())
1029         && m_arrayPrototype->getPrototypeDirect() == m_objectPrototype.get()
1030         && objectPrototypeIsSane();
1031 }
1032
1033 bool JSGlobalObject::stringPrototypeChainIsSane()
1034 {
1035     return !hasIndexedProperties(m_stringPrototype->indexingType())
1036         && m_stringPrototype->getPrototypeDirect() == m_objectPrototype.get()
1037         && objectPrototypeIsSane();
1038 }
1039
1040 // Set prototype, and also insert the object prototype at the end of the chain.
1041 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1042 {
1043     setPrototypeDirect(vm, prototype);
1044
1045     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(this);
1046     JSObject* objectPrototype = m_objectPrototype.get();
1047     if (oldLastInPrototypeChain != objectPrototype)
1048         oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1049
1050     // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1051     setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1052 }
1053
1054 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1055
1056     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1057     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1058     Base::visitChildren(thisObject, visitor);
1059
1060     visitor.append(&thisObject->m_globalThis);
1061
1062     visitor.append(&thisObject->m_globalLexicalEnvironment);
1063     visitor.append(&thisObject->m_globalScopeExtension);
1064     visitor.append(&thisObject->m_globalCallee);
1065     visitor.append(&thisObject->m_regExpConstructor);
1066     visitor.append(&thisObject->m_errorConstructor);
1067     visitor.append(&thisObject->m_nativeErrorPrototypeStructure);
1068     visitor.append(&thisObject->m_nativeErrorStructure);
1069     thisObject->m_evalErrorConstructor.visit(visitor);
1070     visitor.append(&thisObject->m_rangeErrorConstructor);
1071     thisObject->m_referenceErrorConstructor.visit(visitor);
1072     thisObject->m_syntaxErrorConstructor.visit(visitor);
1073     visitor.append(&thisObject->m_typeErrorConstructor);
1074     thisObject->m_URIErrorConstructor.visit(visitor);
1075     visitor.append(&thisObject->m_objectConstructor);
1076     visitor.append(&thisObject->m_promiseConstructor);
1077
1078     visitor.append(&thisObject->m_nullGetterFunction);
1079     visitor.append(&thisObject->m_nullSetterFunction);
1080
1081     visitor.append(&thisObject->m_parseIntFunction);
1082     visitor.append(&thisObject->m_evalFunction);
1083     visitor.append(&thisObject->m_callFunction);
1084     visitor.append(&thisObject->m_applyFunction);
1085     visitor.append(&thisObject->m_definePropertyFunction);
1086     thisObject->m_arrayProtoValuesFunction.visit(visitor);
1087     thisObject->m_initializePromiseFunction.visit(visitor);
1088     visitor.append(&thisObject->m_newPromiseCapabilityFunction);
1089     visitor.append(&thisObject->m_functionProtoHasInstanceSymbolFunction);
1090     thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1091     thisObject->m_throwTypeErrorCalleeAndCallerGetterSetter.visit(visitor);
1092     thisObject->m_throwTypeErrorArgumentsAndCallerInStrictModeGetterSetter.visit(visitor);
1093     thisObject->m_throwTypeErrorArgumentsAndCallerInClassContextGetterSetter.visit(visitor);
1094     visitor.append(&thisObject->m_moduleLoader);
1095
1096     visitor.append(&thisObject->m_objectPrototype);
1097     visitor.append(&thisObject->m_functionPrototype);
1098     visitor.append(&thisObject->m_arrayPrototype);
1099     visitor.append(&thisObject->m_errorPrototype);
1100     visitor.append(&thisObject->m_iteratorPrototype);
1101     visitor.append(&thisObject->m_generatorFunctionPrototype);
1102     visitor.append(&thisObject->m_generatorPrototype);
1103
1104     thisObject->m_debuggerScopeStructure.visit(visitor);
1105     thisObject->m_withScopeStructure.visit(visitor);
1106     visitor.append(&thisObject->m_strictEvalActivationStructure);
1107     visitor.append(&thisObject->m_lexicalEnvironmentStructure);
1108     thisObject->m_moduleEnvironmentStructure.visit(visitor);
1109     visitor.append(&thisObject->m_directArgumentsStructure);
1110     visitor.append(&thisObject->m_scopedArgumentsStructure);
1111     visitor.append(&thisObject->m_clonedArgumentsStructure);
1112     visitor.append(&thisObject->m_objectStructureForObjectConstructor);
1113     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1114         visitor.append(&thisObject->m_originalArrayStructureForIndexingShape[i]);
1115     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1116         visitor.append(&thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1117     thisObject->m_callbackConstructorStructure.visit(visitor);
1118     thisObject->m_callbackFunctionStructure.visit(visitor);
1119     thisObject->m_callbackObjectStructure.visit(visitor);
1120     visitor.append(&thisObject->m_propertyNameIteratorStructure);
1121 #if JSC_OBJC_API_ENABLED
1122     thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1123     thisObject->m_objcWrapperObjectStructure.visit(visitor);
1124 #endif
1125     thisObject->m_nullPrototypeObjectStructure.visit(visitor);
1126     visitor.append(&thisObject->m_errorStructure);
1127     visitor.append(&thisObject->m_calleeStructure);
1128     visitor.append(&thisObject->m_functionStructure);
1129     thisObject->m_boundSlotBaseFunctionStructure.visit(visitor);
1130     thisObject->m_boundFunctionStructure.visit(visitor);
1131     visitor.append(&thisObject->m_getterSetterStructure);
1132     thisObject->m_nativeStdFunctionStructure.visit(visitor);
1133     thisObject->m_namedFunctionStructure.visit(visitor);
1134     visitor.append(&thisObject->m_symbolObjectStructure);
1135     visitor.append(&thisObject->m_regExpStructure);
1136     visitor.append(&thisObject->m_generatorFunctionStructure);
1137     visitor.append(&thisObject->m_iteratorResultObjectStructure);
1138     visitor.append(&thisObject->m_regExpMatchesArrayStructure);
1139     visitor.append(&thisObject->m_regExpMatchesArraySlowPutStructure);
1140     visitor.append(&thisObject->m_moduleRecordStructure);
1141     visitor.append(&thisObject->m_moduleNamespaceObjectStructure);
1142     visitor.append(&thisObject->m_dollarVMStructure);
1143     visitor.append(&thisObject->m_proxyObjectStructure);
1144     visitor.append(&thisObject->m_callableProxyObjectStructure);
1145     visitor.append(&thisObject->m_proxyRevokeStructure);
1146 #if ENABLE(WEBASSEMBLY)
1147     visitor.append(&thisObject->m_wasmModuleStructure);
1148 #endif
1149
1150 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
1151     visitor.append(&thisObject->m_ ## lowerName ## Prototype); \
1152     visitor.append(&thisObject->m_ ## properName ## Structure); \
1153
1154     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1155
1156 #undef VISIT_SIMPLE_TYPE
1157
1158 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
1159     thisObject->m_ ## properName ## Structure.visit(visitor);
1160     
1161     FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1162     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_LAZY_TYPE)
1163
1164 #undef VISIT_LAZY_TYPE
1165
1166     for (unsigned i = NUMBER_OF_TYPED_ARRAY_TYPES; i--;)
1167         thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1168     
1169     visitor.append(&thisObject->m_speciesGetterSetter);
1170     thisObject->m_typedArrayProto.visit(visitor);
1171     thisObject->m_typedArraySuperConstructor.visit(visitor);
1172 }
1173
1174 JSValue JSGlobalObject::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode)
1175 {
1176     if (ecmaMode == StrictMode)
1177         return jsUndefined();
1178     return exec->globalThisValue();
1179 }
1180
1181 ExecState* JSGlobalObject::globalExec()
1182 {
1183     return CallFrame::create(m_globalCallFrame);
1184 }
1185
1186 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1187 {
1188     ScopeOffset startOffset = addVariables(count, jsUndefined());
1189
1190     for (int i = 0; i < count; ++i) {
1191         GlobalPropertyInfo& global = globals[i];
1192         ASSERT(global.attributes & DontDelete);
1193         
1194         WatchpointSet* watchpointSet = nullptr;
1195         WriteBarrierBase<Unknown>* variable = nullptr;
1196         {
1197             ConcurrentJITLocker locker(symbolTable()->m_lock);
1198             ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1199             RELEASE_ASSERT(offset = startOffset + i);
1200             SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1201             newEntry.prepareToWatch();
1202             watchpointSet = newEntry.watchpointSet();
1203             symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1204             variable = &variableAt(offset);
1205         }
1206         symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1207     }
1208 }
1209
1210 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1211 {
1212     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
1213     if (getStaticPropertySlot<JSGlobalObject, Base>(exec, globalObjectTable, thisObject, propertyName, slot))
1214         return true;
1215     return symbolTableGet(thisObject, propertyName, slot);
1216 }
1217
1218 void JSGlobalObject::clearRareData(JSCell* cell)
1219 {
1220     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1221 }
1222
1223 void slowValidateCell(JSGlobalObject* globalObject)
1224 {
1225     RELEASE_ASSERT(globalObject->isGlobalObject());
1226     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1227 }
1228
1229 UnlinkedProgramCodeBlock* JSGlobalObject::createProgramCodeBlock(CallFrame* callFrame, ProgramExecutable* executable, JSObject** exception)
1230 {
1231     ParserError error;
1232     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
1233     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
1234     ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
1235     UnlinkedProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getProgramCodeBlock(
1236         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, 
1237         debuggerMode, profilerMode, error);
1238
1239     if (hasDebugger())
1240         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1241
1242     if (error.isValid()) {
1243         *exception = error.toErrorObject(this, executable->source());
1244         return nullptr;
1245     }
1246     
1247     return unlinkedCodeBlock;
1248 }
1249
1250 UnlinkedEvalCodeBlock* JSGlobalObject::createEvalCodeBlock(CallFrame* callFrame, EvalExecutable* executable, ThisTDZMode thisTDZMode, const VariableEnvironment* variablesUnderTDZ)
1251 {
1252     ParserError error;
1253     JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
1254     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
1255     EvalContextType evalContextType = executable->executableInfo().evalContextType();
1256     
1257     ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
1258     UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock(
1259         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, debuggerMode, profilerMode, error, evalContextType, variablesUnderTDZ);
1260
1261     if (hasDebugger())
1262         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1263
1264     if (error.isValid()) {
1265         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
1266         return nullptr;
1267     }
1268
1269     return unlinkedCodeBlock;
1270 }
1271
1272 UnlinkedModuleProgramCodeBlock* JSGlobalObject::createModuleProgramCodeBlock(CallFrame* callFrame, ModuleProgramExecutable* executable)
1273 {
1274     ParserError error;
1275     DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
1276     ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
1277     UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock = vm().codeCache()->getModuleProgramCodeBlock(
1278         vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, debuggerMode, profilerMode, error);
1279
1280     if (hasDebugger())
1281         debugger()->sourceParsed(callFrame, executable->source().provider(), error.line(), error.message());
1282
1283     if (error.isValid()) {
1284         throwVMError(callFrame, error.toErrorObject(this, executable->source()));
1285         return nullptr;
1286     }
1287
1288     return unlinkedCodeBlock;
1289 }
1290
1291 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1292 {
1293 #if ENABLE(REMOTE_INSPECTOR)
1294     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1295 #else
1296     UNUSED_PARAM(enabled);
1297 #endif
1298 }
1299
1300 bool JSGlobalObject::remoteDebuggingEnabled() const
1301 {
1302 #if ENABLE(REMOTE_INSPECTOR)
1303     return m_inspectorDebuggable->remoteDebuggingAllowed();
1304 #else
1305     return false;
1306 #endif
1307 }
1308
1309 #if ENABLE(WEB_REPLAY)
1310 void JSGlobalObject::setInputCursor(PassRefPtr<InputCursor> prpCursor)
1311 {
1312     m_inputCursor = prpCursor;
1313     ASSERT(m_inputCursor);
1314
1315     InputCursor& cursor = inputCursor();
1316     // Save or set the random seed. This performed here rather than the constructor
1317     // to avoid threading the input cursor through all the abstraction layers.
1318     if (cursor.isCapturing())
1319         cursor.appendInput<SetRandomSeed>(m_weakRandom.seed());
1320     else if (cursor.isReplaying()) {
1321         if (SetRandomSeed* input = cursor.fetchInput<SetRandomSeed>())
1322             m_weakRandom.setSeed(static_cast<unsigned>(input->randomSeed()));
1323     }
1324 }
1325 #endif
1326
1327 void JSGlobalObject::setName(const String& name)
1328 {
1329     m_name = name;
1330
1331 #if ENABLE(REMOTE_INSPECTOR)
1332     m_inspectorDebuggable->update();
1333 #endif
1334 }
1335
1336 # if ENABLE(INTL)
1337 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1338 {
1339     if (m_intlCollatorAvailableLocales.isEmpty()) {
1340         int32_t count = ucol_countAvailable();
1341         for (int32_t i = 0; i < count; ++i) {
1342             String locale(ucol_getAvailable(i));
1343             convertICULocaleToBCP47LanguageTag(locale);
1344             m_intlCollatorAvailableLocales.add(locale);
1345         }
1346     }
1347     return m_intlCollatorAvailableLocales;
1348 }
1349
1350 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1351 {
1352     if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1353         int32_t count = udat_countAvailable();
1354         for (int32_t i = 0; i < count; ++i) {
1355             String locale(udat_getAvailable(i));
1356             convertICULocaleToBCP47LanguageTag(locale);
1357             m_intlDateTimeFormatAvailableLocales.add(locale);
1358         }
1359     }
1360     return m_intlDateTimeFormatAvailableLocales;
1361 }
1362
1363 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1364 {
1365     if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1366         int32_t count = unum_countAvailable();
1367         for (int32_t i = 0; i < count; ++i) {
1368             String locale(unum_getAvailable(i));
1369             convertICULocaleToBCP47LanguageTag(locale);
1370             m_intlNumberFormatAvailableLocales.add(locale);
1371         }
1372     }
1373     return m_intlNumberFormatAvailableLocales;
1374 }
1375 #endif // ENABLE(INTL)
1376
1377 void JSGlobalObject::queueMicrotask(PassRefPtr<Microtask> task)
1378 {
1379     if (globalObjectMethodTable()->queueTaskToEventLoop) {
1380         globalObjectMethodTable()->queueTaskToEventLoop(this, task);
1381         return;
1382     }
1383
1384     vm().queueMicrotask(this, task);
1385 }
1386
1387 bool JSGlobalObject::hasDebugger() const
1388
1389     return m_debugger;
1390 }
1391
1392 bool JSGlobalObject::hasInteractiveDebugger() const 
1393
1394     return m_debugger && m_debugger->isInteractivelyDebugging();
1395 }
1396
1397 } // namespace JSC