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