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