Function.prototype.caller shouldn't return generator bodies
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.cpp
1 /*
2  * Copyright (C) 2007-2018 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Cameron Zwarich (cwzwarich@uwaterloo.ca)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "config.h"
31 #include "JSGlobalObject.h"
32
33 #include "ArrayConstructor.h"
34 #include "ArrayIteratorPrototype.h"
35 #include "ArrayPrototype.h"
36 #include "AsyncFromSyncIteratorPrototype.h"
37 #include "AtomicsObject.h"
38 #include "AsyncFunctionConstructor.h"
39 #include "AsyncFunctionPrototype.h"
40 #include "AsyncGeneratorFunctionConstructor.h"
41 #include "AsyncGeneratorFunctionPrototype.h"
42 #include "AsyncGeneratorPrototype.h"
43 #include "AsyncIteratorPrototype.h"
44 #include "BigIntConstructor.h"
45 #include "BigIntObject.h"
46 #include "BigIntPrototype.h"
47 #include "BooleanConstructor.h"
48 #include "BooleanPrototype.h"
49 #include "BuiltinNames.h"
50 #include "CatchScope.h"
51 #include "ClonedArguments.h"
52 #include "CodeBlock.h"
53 #include "CodeCache.h"
54 #include "ConsoleObject.h"
55 #include "DateConstructor.h"
56 #include "DatePrototype.h"
57 #include "Debugger.h"
58 #include "DebuggerScope.h"
59 #include "DirectArguments.h"
60 #include "DirectEvalExecutable.h"
61 #include "ECMAScriptSpecInternalFunctions.h"
62 #include "Error.h"
63 #include "ErrorConstructor.h"
64 #include "ErrorPrototype.h"
65 #include "FunctionConstructor.h"
66 #include "FunctionPrototype.h"
67 #include "GeneratorFunctionConstructor.h"
68 #include "GeneratorFunctionPrototype.h"
69 #include "GeneratorPrototype.h"
70 #include "GetterSetter.h"
71 #include "HeapIterationScope.h"
72 #include "IndirectEvalExecutable.h"
73 #include "InspectorInstrumentationObject.h"
74 #include "Interpreter.h"
75 #include "IteratorPrototype.h"
76 #include "JSAPIWrapperObject.h"
77 #include "JSArrayBuffer.h"
78 #include "JSArrayBufferConstructor.h"
79 #include "JSArrayBufferPrototype.h"
80 #include "JSAsyncFunction.h"
81 #include "JSAsyncGeneratorFunction.h"
82 #include "JSBigInt.h"
83 #include "JSBoundFunction.h"
84 #include "JSCInlines.h"
85 #include "JSCallbackConstructor.h"
86 #include "JSCallbackFunction.h"
87 #include "JSCallbackObject.h"
88 #include "JSCustomGetterSetterFunction.h"
89 #include "JSDataView.h"
90 #include "JSDataViewPrototype.h"
91 #include "JSDollarVM.h"
92 #include "JSFunction.h"
93 #include "JSGeneratorFunction.h"
94 #include "JSGenericTypedArrayViewConstructorInlines.h"
95 #include "JSGenericTypedArrayViewInlines.h"
96 #include "JSGenericTypedArrayViewPrototypeInlines.h"
97 #include "JSGlobalObjectFunctions.h"
98 #include "JSInternalPromise.h"
99 #include "JSInternalPromiseConstructor.h"
100 #include "JSInternalPromisePrototype.h"
101 #include "JSJob.h"
102 #include "JSLexicalEnvironment.h"
103 #include "JSLock.h"
104 #include "JSMap.h"
105 #include "JSModuleEnvironment.h"
106 #include "JSModuleLoader.h"
107 #include "JSModuleNamespaceObject.h"
108 #include "JSModuleRecord.h"
109 #include "JSNativeStdFunction.h"
110 #include "JSONObject.h"
111 #include "JSPromise.h"
112 #include "JSPromiseConstructor.h"
113 #include "JSPromisePrototype.h"
114 #include "JSSet.h"
115 #include "JSStringIterator.h"
116 #include "JSTypedArrayConstructors.h"
117 #include "JSTypedArrayPrototypes.h"
118 #include "JSTypedArrayViewConstructor.h"
119 #include "JSTypedArrayViewPrototype.h"
120 #include "JSTypedArrays.h"
121 #include "JSWeakMap.h"
122 #include "JSWeakSet.h"
123 #include "JSWebAssembly.h"
124 #include "JSWithScope.h"
125 #include "LazyClassStructureInlines.h"
126 #include "LazyPropertyInlines.h"
127 #include "Lookup.h"
128 #include "MapConstructor.h"
129 #include "MapIteratorPrototype.h"
130 #include "MapPrototype.h"
131 #include "MarkedSpaceInlines.h"
132 #include "MathObject.h"
133 #include "Microtask.h"
134 #include "ModuleLoaderPrototype.h"
135 #include "NativeErrorConstructor.h"
136 #include "NativeErrorPrototype.h"
137 #include "NullGetterFunction.h"
138 #include "NullSetterFunction.h"
139 #include "NumberConstructor.h"
140 #include "NumberPrototype.h"
141 #include "ObjCCallbackFunction.h"
142 #include "ObjectConstructor.h"
143 #include "ObjectPropertyChangeAdaptiveWatchpoint.h"
144 #include "ObjectPropertyConditionSet.h"
145 #include "ObjectPrototype.h"
146 #include "ParserError.h"
147 #include "ProxyConstructor.h"
148 #include "ProxyObject.h"
149 #include "ProxyRevoke.h"
150 #include "ReflectObject.h"
151 #include "RegExpConstructor.h"
152 #include "RegExpMatchesArray.h"
153 #include "RegExpObject.h"
154 #include "RegExpPrototype.h"
155 #include "ScopedArguments.h"
156 #include "SetConstructor.h"
157 #include "SetIteratorPrototype.h"
158 #include "SetPrototype.h"
159 #include "StrictEvalActivation.h"
160 #include "StringConstructor.h"
161 #include "StringIteratorPrototype.h"
162 #include "StringPrototype.h"
163 #include "Symbol.h"
164 #include "SymbolConstructor.h"
165 #include "SymbolObject.h"
166 #include "SymbolPrototype.h"
167 #include "VariableWriteFireDetail.h"
168 #include "WeakGCMapInlines.h"
169 #include "WeakMapConstructor.h"
170 #include "WeakMapPrototype.h"
171 #include "WeakSetConstructor.h"
172 #include "WeakSetPrototype.h"
173 #include "WebAssemblyToJSCallee.h"
174 #include <wtf/RandomNumber.h>
175
176 #if ENABLE(INTL)
177 #include "IntlObject.h"
178 #include <unicode/ucol.h>
179 #include <unicode/udat.h>
180 #include <unicode/unum.h>
181 #endif // ENABLE(INTL)
182
183 #if ENABLE(REMOTE_INSPECTOR)
184 #include "JSGlobalObjectDebuggable.h"
185 #include "JSGlobalObjectInspectorController.h"
186 #endif
187
188 #ifdef JSC_GLIB_API_ENABLED
189 #include "JSCCallbackFunction.h"
190 #include "JSCWrapperMap.h"
191 #endif
192
193 namespace JSC {
194
195     static JSValue createProxyProperty(VM& vm, JSObject* object)
196 {
197     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
198     return ProxyConstructor::create(vm, ProxyConstructor::createStructure(vm, global, global->functionPrototype()));
199 }
200
201 static JSValue createJSONProperty(VM& vm, JSObject* object)
202 {
203     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
204     return JSONObject::create(vm, JSONObject::createStructure(vm, global, global->objectPrototype()));
205 }
206
207 static JSValue createMathProperty(VM& vm, JSObject* object)
208 {
209     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
210     return MathObject::create(vm, global, MathObject::createStructure(vm, global, global->objectPrototype()));
211 }
212
213 static JSValue createConsoleProperty(VM& vm, JSObject* object)
214 {
215     JSGlobalObject* global = jsCast<JSGlobalObject*>(object);
216     return ConsoleObject::create(vm, global, ConsoleObject::createStructure(vm, global, constructEmptyObject(global->globalExec())));
217 }
218
219 static EncodedJSValue JSC_HOST_CALL makeBoundFunction(ExecState* exec)
220 {
221     VM& vm = exec->vm();
222     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
223
224     JSObject* target = asObject(exec->uncheckedArgument(0));
225     JSValue boundThis = exec->uncheckedArgument(1);
226     JSValue boundArgs = exec->uncheckedArgument(2);
227     JSValue length = exec->uncheckedArgument(3);
228     JSString* name = asString(exec->uncheckedArgument(4));
229
230     return JSValue::encode(JSBoundFunction::create(
231         vm, exec, globalObject, target, boundThis, boundArgs.isCell() ? jsCast<JSArray*>(boundArgs) : nullptr, length.asInt32(), name->value(exec)));
232 }
233
234 static EncodedJSValue JSC_HOST_CALL hasOwnLengthProperty(ExecState* exec)
235 {
236     VM& vm = exec->vm();
237     JSObject* target = asObject(exec->uncheckedArgument(0));
238     return JSValue::encode(jsBoolean(target->hasOwnProperty(exec, vm.propertyNames->length)));
239 }
240
241 #if !ASSERT_DISABLED
242 static EncodedJSValue JSC_HOST_CALL assertCall(ExecState* exec)
243 {
244     RELEASE_ASSERT(exec->argument(0).isBoolean());
245     if (exec->argument(0).asBoolean())
246         return JSValue::encode(jsUndefined());
247
248     bool iteratedOnce = false;
249     CodeBlock* codeBlock = nullptr;
250     unsigned line;
251     exec->iterate([&] (StackVisitor& visitor) {
252         if (!iteratedOnce) {
253             iteratedOnce = true;
254             return StackVisitor::Continue;
255         }
256
257         RELEASE_ASSERT(visitor->hasLineAndColumnInfo());
258         unsigned column;
259         visitor->computeLineAndColumn(line, column);
260         codeBlock = visitor->codeBlock();
261         return StackVisitor::Done;
262     });
263     RELEASE_ASSERT(!!codeBlock);
264     RELEASE_ASSERT_WITH_MESSAGE(false, "JS assertion failed at line %u in:\n%s\n", line, codeBlock->sourceCodeForTools().data());
265     return JSValue::encode(jsUndefined());
266 }
267 #endif
268
269 } // namespace JSC
270
271 #include "JSGlobalObject.lut.h"
272
273 namespace JSC {
274
275 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, nullptr, CREATE_METHOD_TABLE(JSGlobalObject) };
276
277 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
278     &supportsRichSourceInfo,
279     &shouldInterruptScript,
280     &javaScriptRuntimeFlags,
281     nullptr, // queueTaskToEventLoop
282     &shouldInterruptScriptBeforeTimeout,
283     nullptr, // moduleLoaderImportModule
284     nullptr, // moduleLoaderResolve
285     nullptr, // moduleLoaderFetch
286     nullptr, // moduleLoaderCreateImportMetaProperties
287     nullptr, // moduleLoaderEvaluate
288     nullptr, // promiseRejectionTracker
289     nullptr, // defaultLanguage
290 };
291
292 /* Source for JSGlobalObject.lut.h
293 @begin globalObjectTable
294   isNaN                 JSBuiltin                                    DontEnum|Function 1
295   isFinite              JSBuiltin                                    DontEnum|Function 1
296   escape                globalFuncEscape                             DontEnum|Function 1
297   unescape              globalFuncUnescape                           DontEnum|Function 1
298   decodeURI             globalFuncDecodeURI                          DontEnum|Function 1
299   decodeURIComponent    globalFuncDecodeURIComponent                 DontEnum|Function 1
300   encodeURI             globalFuncEncodeURI                          DontEnum|Function 1
301   encodeURIComponent    globalFuncEncodeURIComponent                 DontEnum|Function 1
302   EvalError             JSGlobalObject::m_evalErrorConstructor       DontEnum|CellProperty
303   ReferenceError        JSGlobalObject::m_referenceErrorConstructor  DontEnum|CellProperty
304   SyntaxError           JSGlobalObject::m_syntaxErrorConstructor     DontEnum|CellProperty
305   URIError              JSGlobalObject::m_URIErrorConstructor        DontEnum|CellProperty
306   Proxy                 createProxyProperty                          DontEnum|PropertyCallback
307   JSON                  createJSONProperty                           DontEnum|PropertyCallback
308   Math                  createMathProperty                           DontEnum|PropertyCallback
309   console               createConsoleProperty                        DontEnum|PropertyCallback
310   Int8Array             JSGlobalObject::m_typedArrayInt8             DontEnum|ClassStructure
311   Int16Array            JSGlobalObject::m_typedArrayInt16            DontEnum|ClassStructure
312   Int32Array            JSGlobalObject::m_typedArrayInt32            DontEnum|ClassStructure
313   Uint8Array            JSGlobalObject::m_typedArrayUint8            DontEnum|ClassStructure
314   Uint8ClampedArray     JSGlobalObject::m_typedArrayUint8Clamped     DontEnum|ClassStructure
315   Uint16Array           JSGlobalObject::m_typedArrayUint16           DontEnum|ClassStructure
316   Uint32Array           JSGlobalObject::m_typedArrayUint32           DontEnum|ClassStructure
317   Float32Array          JSGlobalObject::m_typedArrayFloat32          DontEnum|ClassStructure
318   Float64Array          JSGlobalObject::m_typedArrayFloat64          DontEnum|ClassStructure
319   DataView              JSGlobalObject::m_typedArrayDataView         DontEnum|ClassStructure
320   Date                  JSGlobalObject::m_dateStructure              DontEnum|ClassStructure
321   Boolean               JSGlobalObject::m_booleanObjectStructure     DontEnum|ClassStructure
322   Number                JSGlobalObject::m_numberObjectStructure      DontEnum|ClassStructure
323   WeakMap               JSGlobalObject::m_weakMapStructure           DontEnum|ClassStructure
324   WeakSet               JSGlobalObject::m_weakSetStructure           DontEnum|ClassStructure
325 @end
326 */
327
328 static EncodedJSValue JSC_HOST_CALL enqueueJob(ExecState* exec)
329 {
330     VM& vm = exec->vm();
331     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
332
333     JSValue job = exec->argument(0);
334     JSValue arguments = exec->argument(1);
335     ASSERT(arguments.inherits<JSArray>(vm));
336
337     globalObject->queueMicrotask(createJSJob(vm, job, jsCast<JSArray*>(arguments)));
338
339     return JSValue::encode(jsUndefined());
340 }
341
342 JSGlobalObject::JSGlobalObject(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable)
343     : Base(vm, structure, 0)
344     , m_vm(vm)
345     , m_masqueradesAsUndefinedWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
346     , m_havingABadTimeWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
347     , m_varInjectionWatchpoint(adoptRef(new WatchpointSet(IsWatched)))
348     , m_weakRandom(Options::forceWeakRandomSeed() ? Options::forcedWeakRandomSeed() : static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
349     , m_arrayIteratorProtocolWatchpoint(IsWatched)
350     , m_mapIteratorProtocolWatchpoint(IsWatched)
351     , m_setIteratorProtocolWatchpoint(IsWatched)
352     , m_stringIteratorProtocolWatchpoint(IsWatched)
353     , m_mapSetWatchpoint(IsWatched)
354     , m_setAddWatchpoint(IsWatched)
355     , m_arraySpeciesWatchpoint(ClearWatchpoint)
356     , m_numberToStringWatchpoint(IsWatched)
357     , m_runtimeFlags()
358     , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable)
359 {
360 }
361
362 JSGlobalObject::~JSGlobalObject()
363 {
364 #if ENABLE(REMOTE_INSPECTOR)
365     m_inspectorController->globalObjectDestroyed();
366 #endif
367
368     if (m_debugger)
369         m_debugger->detach(this, Debugger::GlobalObjectIsDestructing);
370 }
371
372 void JSGlobalObject::destroy(JSCell* cell)
373 {
374     static_cast<JSGlobalObject*>(cell)->JSGlobalObject::~JSGlobalObject();
375 }
376
377 void JSGlobalObject::setGlobalThis(VM& vm, JSObject* globalThis)
378 {
379     m_globalThis.set(vm, this, globalThis);
380 }
381
382 static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier& ident)
383 {
384     JSValue baseValue = JSValue(base);
385     PropertySlot slot(baseValue, PropertySlot::InternalMethodType::VMInquiry);
386     baseValue.getPropertySlot(exec, ident, slot);
387     return slot.getPureResult().toObject(exec);
388 }
389
390 void JSGlobalObject::init(VM& vm)
391 {
392     ASSERT(vm.currentThreadIsHoldingAPILock());
393     auto catchScope = DECLARE_CATCH_SCOPE(vm);
394
395     Base::setStructure(vm, Structure::toCacheableDictionaryTransition(vm, structure()));
396
397     m_debugger = 0;
398
399 #if ENABLE(REMOTE_INSPECTOR)
400     m_inspectorController = std::make_unique<Inspector::JSGlobalObjectInspectorController>(*this);
401     m_inspectorDebuggable = std::make_unique<JSGlobalObjectDebuggable>(*this);
402     m_inspectorDebuggable->init();
403     m_consoleClient = m_inspectorController->consoleClient();
404 #endif
405
406     m_functionPrototype.set(vm, this, FunctionPrototype::create(vm, FunctionPrototype::createStructure(vm, this, jsNull()))); // The real prototype will be set once ObjectPrototype is created.
407     m_calleeStructure.set(vm, this, JSCallee::createStructure(vm, this, jsNull()));
408
409     m_globalLexicalEnvironment.set(vm, this, JSGlobalLexicalEnvironment::create(vm, JSGlobalLexicalEnvironment::createStructure(vm, this), this));
410     // Need to create the callee structure (above) before creating the callee.
411     JSCallee* globalCallee = JSCallee::create(vm, this, globalScope());
412     m_globalCallee.set(vm, this, globalCallee);
413
414     ExecState::initGlobalExec(JSGlobalObject::globalExec(), globalCallee);
415     ExecState* exec = JSGlobalObject::globalExec();
416
417     m_strictFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
418     m_sloppyFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
419     m_arrowFunctionStructure.set(vm, this, JSFunction::createStructure(vm, this, m_functionPrototype.get()));
420     m_customGetterSetterFunctionStructure.initLater(
421         [] (const Initializer<Structure>& init) {
422             init.set(JSCustomGetterSetterFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
423         });
424     m_boundFunctionStructure.initLater(
425         [] (const Initializer<Structure>& init) {
426             init.set(JSBoundFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
427         });
428     m_getterSetterStructure.set(vm, this, GetterSetter::createStructure(vm, this, jsNull()));
429     m_nativeStdFunctionStructure.initLater(
430         [] (const Initializer<Structure>& init) {
431             init.set(JSNativeStdFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
432         });
433     JSFunction* callFunction = nullptr;
434     JSFunction* applyFunction = nullptr;
435     JSFunction* hasInstanceSymbolFunction = nullptr;
436     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
437     m_callFunction.set(vm, this, callFunction);
438     m_applyFunction.set(vm, this, applyFunction);
439     m_arrayProtoToStringFunction.initLater(
440         [] (const Initializer<JSFunction>& init) {
441             init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
442         });
443     m_arrayProtoValuesFunction.initLater(
444         [] (const Initializer<JSFunction>& init) {
445             init.set(JSFunction::create(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
446         });
447     m_initializePromiseFunction.initLater(
448         [] (const Initializer<JSFunction>& init) {
449             init.set(JSFunction::create(init.vm, promiseOperationsInitializePromiseCodeGenerator(init.vm), init.owner));
450         });
451
452     m_iteratorProtocolFunction.initLater(
453         [] (const Initializer<JSFunction>& init) {
454             init.set(JSFunction::create(init.vm, iteratorHelpersPerformIterationCodeGenerator(init.vm), init.owner));
455         });
456
457     m_promiseResolveFunction.initLater(
458         [] (const Initializer<JSFunction>& init) {
459             init.set(JSFunction::create(init.vm, promiseConstructorResolveCodeGenerator(init.vm), init.owner));
460         });
461
462     m_newPromiseCapabilityFunction.set(vm, this, JSFunction::create(vm, promiseOperationsNewPromiseCapabilityCodeGenerator(vm), this));
463     m_functionProtoHasInstanceSymbolFunction.set(vm, this, hasInstanceSymbolFunction);
464     m_throwTypeErrorGetterSetter.initLater(
465         [] (const Initializer<GetterSetter>& init) {
466             JSFunction* thrower = init.owner->throwTypeErrorFunction();
467             GetterSetter* getterSetter = GetterSetter::create(init.vm, init.owner);
468             getterSetter->setGetter(init.vm, init.owner, thrower);
469             getterSetter->setSetter(init.vm, init.owner, thrower);
470             init.set(getterSetter);
471         });
472
473     m_nullGetterFunction.set(vm, this, NullGetterFunction::create(vm, NullGetterFunction::createStructure(vm, this, m_functionPrototype.get())));
474     m_nullSetterFunction.set(vm, this, NullSetterFunction::create(vm, NullSetterFunction::createStructure(vm, this, m_functionPrototype.get())));
475     m_objectPrototype.set(vm, this, ObjectPrototype::create(vm, this, ObjectPrototype::createStructure(vm, this, jsNull())));
476     GetterSetter* protoAccessor = GetterSetter::create(vm, this);
477     protoAccessor->setGetter(vm, this, JSFunction::create(vm, this, 0, makeString("get ", vm.propertyNames->underscoreProto.string()), globalFuncProtoGetter, UnderscoreProtoIntrinsic));
478     protoAccessor->setSetter(vm, this, JSFunction::create(vm, this, 0, makeString("set ", vm.propertyNames->underscoreProto.string()), globalFuncProtoSetter));
479     m_objectPrototype->putDirectNonIndexAccessor(vm, vm.propertyNames->underscoreProto, protoAccessor, PropertyAttribute::Accessor | PropertyAttribute::DontEnum);
480     m_functionPrototype->structure()->setPrototypeWithoutTransition(vm, m_objectPrototype.get());
481     m_objectStructureForObjectConstructor.set(vm, this, vm.structureCache.emptyObjectStructureForPrototype(this, m_objectPrototype.get(), JSFinalObject::defaultInlineCapacity()));
482     m_objectProtoValueOfFunction.set(vm, this, jsCast<JSFunction*>(objectPrototype()->getDirect(vm, vm.propertyNames->valueOf)));
483     
484     JSFunction* thrower = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeErrorArgumentsCalleeAndCaller);
485     GetterSetter* getterSetter = GetterSetter::create(vm, this);
486     getterSetter->setGetter(vm, this, thrower);
487     getterSetter->setSetter(vm, this, thrower);
488     m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.set(vm, this, getterSetter);
489     
490     m_functionPrototype->initRestrictedProperties(exec, this);
491
492     m_speciesGetterSetter.set(vm, this, GetterSetter::create(vm, this));
493     m_speciesGetterSetter->setGetter(vm, this, JSFunction::create(vm, globalOperationsSpeciesGetterCodeGenerator(vm), this));
494
495     m_typedArrayProto.initLater(
496         [] (const Initializer<JSTypedArrayViewPrototype>& init) {
497             init.set(JSTypedArrayViewPrototype::create(init.vm, init.owner, JSTypedArrayViewPrototype::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get())));
498             
499             // Make sure that the constructor gets initialized, too.
500             init.owner->m_typedArraySuperConstructor.get(init.owner);
501         });
502     m_typedArraySuperConstructor.initLater(
503         [] (const Initializer<JSTypedArrayViewConstructor>& init) {
504             JSTypedArrayViewPrototype* prototype = init.owner->m_typedArrayProto.get(init.owner);
505             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());
506             prototype->putDirectWithoutTransition(init.vm, init.vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
507             init.set(constructor);
508         });
509     
510 #define INIT_TYPED_ARRAY_LATER(type) \
511     m_typedArray ## type.initLater( \
512         [] (LazyClassStructure::Initializer& init) { \
513             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)))); \
514             init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
515             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))); \
516             init.global->putDirectWithoutTransition(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
517         });
518     FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER)
519 #undef INIT_TYPED_ARRAY_LATER
520     
521     m_typedArrayDataView.initLater(
522         [] (LazyClassStructure::Initializer& init) {
523             init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
524             init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
525             init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, ASCIILiteral("DataView"), nullptr));
526         });
527     
528     m_lexicalEnvironmentStructure.set(vm, this, JSLexicalEnvironment::createStructure(vm, this));
529     m_moduleEnvironmentStructure.initLater(
530         [] (const Initializer<Structure>& init) {
531             init.set(JSModuleEnvironment::createStructure(init.vm, init.owner));
532         });
533     m_strictEvalActivationStructure.set(vm, this, StrictEvalActivation::createStructure(vm, this, jsNull()));
534     m_debuggerScopeStructure.initLater(
535         [] (const Initializer<Structure>& init) {
536             init.set(DebuggerScope::createStructure(init.vm, init.owner));
537         });
538     m_withScopeStructure.initLater(
539         [] (const Initializer<Structure>& init) {
540             init.set(JSWithScope::createStructure(init.vm, init.owner, jsNull()));
541         });
542     
543     m_nullPrototypeObjectStructure.initLater(
544         [] (const Initializer<Structure>& init) {
545             init.set(JSFinalObject::createStructure(init.vm, init.owner, jsNull(), JSFinalObject::defaultInlineCapacity()));
546         });
547     
548     m_callbackFunctionStructure.initLater(
549         [] (const Initializer<Structure>& init) {
550             init.set(JSCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
551         });
552     m_directArgumentsStructure.set(vm, this, DirectArguments::createStructure(vm, this, m_objectPrototype.get()));
553     m_scopedArgumentsStructure.set(vm, this, ScopedArguments::createStructure(vm, this, m_objectPrototype.get()));
554     m_clonedArgumentsStructure.set(vm, this, ClonedArguments::createStructure(vm, this, m_objectPrototype.get()));
555     m_callbackConstructorStructure.initLater(
556         [] (const Initializer<Structure>& init) {
557             init.set(JSCallbackConstructor::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
558         });
559     m_callbackObjectStructure.initLater(
560         [] (const Initializer<Structure>& init) {
561             init.set(JSCallbackObject<JSDestructibleObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
562         });
563
564 #if JSC_OBJC_API_ENABLED
565     m_objcCallbackFunctionStructure.initLater(
566         [] (const Initializer<Structure>& init) {
567             init.set(ObjCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
568         });
569     m_objcWrapperObjectStructure.initLater(
570         [] (const Initializer<Structure>& init) {
571             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
572         });
573 #endif
574 #ifdef JSC_GLIB_API_ENABLED
575     m_glibCallbackFunctionStructure.initLater(
576         [] (const Initializer<Structure>& init) {
577             init.set(JSCCallbackFunction::createStructure(init.vm, init.owner, init.owner->m_functionPrototype.get()));
578         });
579     m_glibWrapperObjectStructure.initLater(
580         [] (const Initializer<Structure>& init) {
581             init.set(JSCallbackObject<JSAPIWrapperObject>::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
582         });
583 #endif
584     m_arrayPrototype.set(vm, this, ArrayPrototype::create(vm, this, ArrayPrototype::createStructure(vm, this, m_objectPrototype.get())));
585     
586     m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithUndecided));
587     m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithInt32));
588     m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithDouble));
589     m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithContiguous));
590     m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithArrayStorage));
591     m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(vm, this, JSArray::createStructure(vm, this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage));
592     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
593         m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i];
594
595     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, this, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get())));
596     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
597     m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, this));
598     m_regExpMatchesArrayWithGroupsStructure.set(vm, this, createRegExpMatchesArrayWithGroupsStructure(vm, this));
599
600     m_moduleRecordStructure.set(vm, this, JSModuleRecord::createStructure(vm, this, jsNull()));
601     m_moduleNamespaceObjectStructure.set(vm, this, JSModuleNamespaceObject::createStructure(vm, this, jsNull()));
602     {
603         bool isCallable = false;
604         m_proxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
605         isCallable = true;
606         m_callableProxyObjectStructure.set(vm, this, ProxyObject::createStructure(vm, this, jsNull(), isCallable));
607     }
608     m_proxyRevokeStructure.set(vm, this, ProxyRevoke::createStructure(vm, this, m_functionPrototype.get()));
609
610     m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, ParseIntIntrinsic));
611     putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
612     m_parseFloatFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->parseFloat.string(), globalFuncParseFloat, NoIntrinsic));
613     putDirectWithoutTransition(vm, vm.propertyNames->parseFloat, m_parseFloatFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
614     
615     m_arrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Default));
616     m_arrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_arrayBufferPrototype.get()));
617 #if ENABLE(SHARED_ARRAY_BUFFER)
618     m_sharedArrayBufferPrototype.set(vm, this, JSArrayBufferPrototype::create(vm, this, JSArrayBufferPrototype::createStructure(vm, this, m_objectPrototype.get()), ArrayBufferSharingMode::Shared));
619     m_sharedArrayBufferStructure.set(vm, this, JSArrayBuffer::createStructure(vm, this, m_sharedArrayBufferPrototype.get()));
620 #endif
621
622     m_iteratorPrototype.set(vm, this, IteratorPrototype::create(vm, this, IteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
623     m_asyncIteratorPrototype.set(vm, this, AsyncIteratorPrototype::create(vm, this, AsyncIteratorPrototype::createStructure(vm, this, m_objectPrototype.get())));
624
625     m_generatorPrototype.set(vm, this, GeneratorPrototype::create(vm, this, GeneratorPrototype::createStructure(vm, this, m_iteratorPrototype.get())));
626     m_asyncGeneratorPrototype.set(vm, this, AsyncGeneratorPrototype::create(vm, this, AsyncGeneratorPrototype::createStructure(vm, this, m_asyncIteratorPrototype.get())));
627
628 #define CREATE_PROTOTYPE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
629 m_ ## lowerName ## Prototype.set(vm, this, capitalName##Prototype::create(vm, this, capitalName##Prototype::createStructure(vm, this, m_ ## prototypeBase ## Prototype.get()))); \
630 m_ ## properName ## Structure.set(vm, this, instanceType::createStructure(vm, this, m_ ## lowerName ## Prototype.get()));
631     
632     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
633
634     if (UNLIKELY(Options::useBigInt()))
635         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
636
637     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(CREATE_PROTOTYPE_FOR_SIMPLE_TYPE)
638     
639 #undef CREATE_PROTOTYPE_FOR_SIMPLE_TYPE
640
641 #define CREATE_PROTOTYPE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
642     m_ ## properName ## Structure.initLater(\
643         [] (LazyClassStructure::Initializer& init) { \
644             init.setPrototype(capitalName##Prototype::create(init.vm, init.global, capitalName##Prototype::createStructure(init.vm, init.global, init.global->m_ ## prototypeBase ## Prototype.get()))); \
645             init.setStructure(instanceType::createStructure(init.vm, init.global, init.prototype)); \
646             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())); \
647         });
648     
649     FOR_EACH_LAZY_BUILTIN_TYPE(CREATE_PROTOTYPE_FOR_LAZY_TYPE)
650     
651 #undef CREATE_PROTOTYPE_FOR_LAZY_TYPE
652     
653     m_moduleLoaderPrototype.set(vm, this, ModuleLoaderPrototype::create(vm, this, ModuleLoaderPrototype::createStructure(vm, this, m_objectPrototype.get())));
654     
655     // Constructors
656
657     ObjectConstructor* objectConstructor = ObjectConstructor::create(vm, this, ObjectConstructor::createStructure(vm, this, m_functionPrototype.get()), m_objectPrototype.get());
658     m_objectConstructor.set(vm, this, objectConstructor);
659
660     JSFunction* throwTypeErrorFunction = JSFunction::create(vm, this, 0, String(), globalFuncThrowTypeError);
661     m_throwTypeErrorFunction.set(vm, this, throwTypeErrorFunction);
662
663     JSCell* functionConstructor = FunctionConstructor::create(vm, FunctionConstructor::createStructure(vm, this, m_functionPrototype.get()), m_functionPrototype.get());
664
665     ArrayConstructor* arrayConstructor = ArrayConstructor::create(vm, this, ArrayConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayPrototype.get(), m_speciesGetterSetter.get());
666     m_arrayConstructor.set(vm, this, arrayConstructor);
667     
668     m_regExpConstructor.set(vm, this, RegExpConstructor::create(vm, RegExpConstructor::createStructure(vm, this, m_functionPrototype.get()), m_regExpPrototype.get(), m_speciesGetterSetter.get()));
669     
670     JSArrayBufferConstructor* arrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_arrayBufferPrototype.get(), m_speciesGetterSetter.get(), ArrayBufferSharingMode::Default);
671     m_arrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
672
673 #if ENABLE(SHARED_ARRAY_BUFFER)
674     JSArrayBufferConstructor* sharedArrayBufferConstructor = nullptr;
675     sharedArrayBufferConstructor = JSArrayBufferConstructor::create(vm, JSArrayBufferConstructor::createStructure(vm, this, m_functionPrototype.get()), m_sharedArrayBufferPrototype.get(), m_speciesGetterSetter.get(), ArrayBufferSharingMode::Shared);
676     m_sharedArrayBufferPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
677
678     AtomicsObject* atomicsObject = AtomicsObject::create(vm, this, AtomicsObject::createStructure(vm, this, m_objectPrototype.get()));
679 #endif
680
681 #define CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
682 capitalName ## Constructor* lowerName ## Constructor = capitalName ## Constructor::create(vm, capitalName ## Constructor::createStructure(vm, this, m_functionPrototype.get()), m_ ## lowerName ## Prototype.get(), m_speciesGetterSetter.get()); \
683 m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
684
685     FOR_EACH_SIMPLE_BUILTIN_TYPE(CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE)
686     BigIntConstructor* bigIntConstructor = nullptr;
687     if (UNLIKELY(Options::useBigInt())) {
688         bigIntConstructor = BigIntConstructor::create(vm, BigIntConstructor::createStructure(vm, this, m_functionPrototype.get()), m_bigIntPrototype.get(), m_speciesGetterSetter.get());
689         m_bigIntPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, bigIntConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
690     }
691     
692 #undef CREATE_CONSTRUCTOR_FOR_SIMPLE_TYPE
693
694     m_errorConstructor.set(vm, this, errorConstructor);
695     m_promiseConstructor.set(vm, this, promiseConstructor);
696     m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
697     
698     m_nativeErrorPrototypeStructure.set(vm, this, NativeErrorPrototype::createStructure(vm, this, m_errorPrototype.get()));
699     m_nativeErrorStructure.set(vm, this, NativeErrorConstructor::createStructure(vm, this, errorConstructor));
700     m_evalErrorConstructor.initLater(
701         [] (const Initializer<NativeErrorConstructor>& init) {
702             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("EvalError")));
703         });
704     m_rangeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("RangeError")));
705     m_referenceErrorConstructor.initLater(
706         [] (const Initializer<NativeErrorConstructor>& init) {
707             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("ReferenceError")));
708         });
709     m_syntaxErrorConstructor.initLater(
710         [] (const Initializer<NativeErrorConstructor>& init) {
711             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("SyntaxError")));
712         });
713     m_typeErrorConstructor.set(vm, this, NativeErrorConstructor::create(vm, this, m_nativeErrorStructure.get(), m_nativeErrorPrototypeStructure.get(), ASCIILiteral("TypeError")));
714     m_URIErrorConstructor.initLater(
715         [] (const Initializer<NativeErrorConstructor>& init) {
716             init.set(NativeErrorConstructor::create(init.vm, init.owner, init.owner->m_nativeErrorStructure.get(), init.owner->m_nativeErrorPrototypeStructure.get(), ASCIILiteral("URIError")));
717         });
718
719     m_generatorFunctionPrototype.set(vm, this, GeneratorFunctionPrototype::create(vm, GeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
720     GeneratorFunctionConstructor* generatorFunctionConstructor = GeneratorFunctionConstructor::create(vm, GeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_generatorFunctionPrototype.get());
721     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, generatorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
722     m_generatorFunctionStructure.set(vm, this, JSGeneratorFunction::createStructure(vm, this, m_generatorFunctionPrototype.get()));
723
724     m_generatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_generatorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
725     m_generatorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_generatorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
726
727     m_asyncFunctionPrototype.set(vm, this, AsyncFunctionPrototype::create(vm, AsyncFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
728     AsyncFunctionConstructor* asyncFunctionConstructor = AsyncFunctionConstructor::create(vm, AsyncFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncFunctionPrototype.get());
729     m_asyncFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
730     m_asyncFunctionStructure.set(vm, this, JSAsyncFunction::createStructure(vm, this, m_asyncFunctionPrototype.get()));
731
732     m_asyncGeneratorFunctionPrototype.set(vm, this, AsyncGeneratorFunctionPrototype::create(vm, AsyncGeneratorFunctionPrototype::createStructure(vm, this, m_functionPrototype.get())));
733     AsyncGeneratorFunctionConstructor* asyncGeneratorFunctionConstructor = AsyncGeneratorFunctionConstructor::create(vm, AsyncGeneratorFunctionConstructor::createStructure(vm, this, functionConstructor), m_asyncGeneratorFunctionPrototype.get());
734     m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, asyncGeneratorFunctionConstructor, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
735     m_asyncGeneratorFunctionStructure.set(vm, this, JSAsyncGeneratorFunction::createStructure(vm, this, m_asyncGeneratorFunctionPrototype.get()));
736
737     m_asyncGeneratorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_asyncGeneratorFunctionPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
738     m_asyncGeneratorFunctionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->prototype, m_asyncGeneratorPrototype.get(), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
739     
740     
741     m_objectPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
742     m_functionPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
743     m_arrayPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
744     m_regExpPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, m_regExpConstructor.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
745     
746     putDirectWithoutTransition(vm, vm.propertyNames->Object, objectConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
747     putDirectWithoutTransition(vm, vm.propertyNames->Function, functionConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
748     putDirectWithoutTransition(vm, vm.propertyNames->Array, arrayConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
749     putDirectWithoutTransition(vm, vm.propertyNames->RegExp, m_regExpConstructor.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
750     putDirectWithoutTransition(vm, vm.propertyNames->RangeError, m_rangeErrorConstructor.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
751     putDirectWithoutTransition(vm, vm.propertyNames->TypeError, m_typeErrorConstructor.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
752
753     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ObjectPrivateName(), objectConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
754     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().ArrayPrivateName(), arrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
755
756     putDirectWithoutTransition(vm, vm.propertyNames->ArrayBuffer, arrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
757 #if ENABLE(SHARED_ARRAY_BUFFER)
758     putDirectWithoutTransition(vm, vm.propertyNames->SharedArrayBuffer, sharedArrayBufferConstructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
759     putDirectWithoutTransition(vm, Identifier::fromString(exec, "Atomics"), atomicsObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
760 #endif
761
762 #define PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
763 putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
764
765     FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
766     if (UNLIKELY(Options::useBigInt()))
767         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE)
768
769 #undef PUT_CONSTRUCTOR_FOR_SIMPLE_TYPE
770     m_iteratorResultObjectStructure.set(vm, this, createIteratorResultObjectStructure(vm, *this));
771     
772     m_evalFunction.set(vm, this, JSFunction::create(vm, this, 1, vm.propertyNames->eval.string(), globalFuncEval));
773     putDirectWithoutTransition(vm, vm.propertyNames->eval, m_evalFunction.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
774     
775 #if ENABLE(INTL)
776     IntlObject* intl = IntlObject::create(vm, this, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
777     putDirectWithoutTransition(vm, vm.propertyNames->Intl, intl, static_cast<unsigned>(PropertyAttribute::DontEnum));
778 #endif // ENABLE(INTL)
779     ReflectObject* reflectObject = ReflectObject::create(vm, this, ReflectObject::createStructure(vm, this, m_objectPrototype.get()));
780     putDirectWithoutTransition(vm, vm.propertyNames->Reflect, reflectObject, static_cast<unsigned>(PropertyAttribute::DontEnum));
781
782     m_moduleLoaderStructure.set(vm, this, JSModuleLoader::createStructure(vm, this, m_moduleLoaderPrototype.get()));
783     m_moduleLoader.set(vm, this, JSModuleLoader::create(globalExec(), vm, this, m_moduleLoaderStructure.get()));
784     if (Options::exposeInternalModuleLoader())
785         putDirectWithoutTransition(vm, vm.propertyNames->Loader, m_moduleLoader.get(), static_cast<unsigned>(PropertyAttribute::DontEnum));
786
787     JSFunction* builtinLog = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinLog);
788     JSFunction* builtinDescribe = JSFunction::create(vm, this, 1, vm.propertyNames->emptyIdentifier.string(), globalFuncBuiltinDescribe);
789
790     JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
791     JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
792     JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
793
794     JSFunction* privateFuncGetOwnPropertyNames = JSFunction::create(vm, this, 0, String(), objectConstructorGetOwnPropertyNames);
795     JSFunction* privateFuncPropertyIsEnumerable = JSFunction::create(vm, this, 0, String(), globalFuncPropertyIsEnumerable);
796     JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
797     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
798     JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
799     JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
800     JSFunction* privateFuncIsTypedArrayView = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncIsTypedArrayView, IsTypedArrayViewIntrinsic);
801     JSFunction* privateFuncTypedArraySubarrayCreate = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSubarrayCreate);
802     JSFunction* privateFuncIsBoundFunction = JSFunction::create(vm, this, 0, String(), isBoundFunction);
803     JSFunction* privateFuncHasInstanceBoundFunction = JSFunction::create(vm, this, 0, String(), hasInstanceBoundFunction);
804     JSFunction* privateFuncInstanceOf = JSFunction::create(vm, this, 0, String(), objectPrivateFuncInstanceOf);
805     JSFunction* privateFuncThisTimeValue = JSFunction::create(vm, this, 0, String(), dateProtoFuncGetTime);
806     JSFunction* privateFuncThisNumberValue = JSFunction::create(vm, this, 0, String(), numberProtoFuncValueOf);
807     JSFunction* privateFuncIsArrayConstructor = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArrayConstructor);
808     JSFunction* privateFuncIsArraySlow = JSFunction::create(vm, this, 0, String(), arrayConstructorPrivateFuncIsArraySlow);
809     JSFunction* privateFuncConcatMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncConcatMemcpy);
810     JSFunction* privateFuncAppendMemcpy = JSFunction::create(vm, this, 0, String(), arrayProtoPrivateFuncAppendMemcpy);
811     JSFunction* privateFuncMapBucketHead = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketHead, JSMapBucketHeadIntrinsic);
812     JSFunction* privateFuncMapBucketNext = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketNext, JSMapBucketNextIntrinsic);
813     JSFunction* privateFuncMapBucketKey = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketKey, JSMapBucketKeyIntrinsic);
814     JSFunction* privateFuncMapBucketValue = JSFunction::create(vm, this, 0, String(), mapPrivateFuncMapBucketValue, JSMapBucketValueIntrinsic);
815     JSFunction* privateFuncSetBucketHead = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketHead, JSSetBucketHeadIntrinsic);
816     JSFunction* privateFuncSetBucketNext = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketNext, JSSetBucketNextIntrinsic);
817     JSFunction* privateFuncSetBucketKey = JSFunction::create(vm, this, 0, String(), setPrivateFuncSetBucketKey, JSSetBucketKeyIntrinsic);
818
819     JSObject* regExpProtoFlagsGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->flags);
820     catchScope.assertNoException();
821     JSObject* regExpProtoGlobalGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->global);
822     catchScope.assertNoException();
823     m_regExpProtoGlobalGetter.set(vm, this, regExpProtoGlobalGetterObject);
824     JSObject* regExpProtoIgnoreCaseGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->ignoreCase);
825     catchScope.assertNoException();
826     JSObject* regExpProtoMultilineGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->multiline);
827     catchScope.assertNoException();
828     JSObject* regExpProtoSourceGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->source);
829     catchScope.assertNoException();
830     JSObject* regExpProtoStickyGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->sticky);
831     catchScope.assertNoException();
832     JSObject* regExpProtoUnicodeGetterObject = getGetterById(exec, m_regExpPrototype.get(), vm.propertyNames->unicode);
833     catchScope.assertNoException();
834     m_regExpProtoUnicodeGetter.set(vm, this, regExpProtoUnicodeGetterObject);
835     JSObject* builtinRegExpExec = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->exec).asCell());
836     m_regExpProtoExec.set(vm, this, builtinRegExpExec);
837     JSObject* regExpSymbolReplace = asObject(m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol).asCell());
838     m_regExpProtoSymbolReplace.set(vm, this, regExpSymbolReplace);
839
840 #define CREATE_PRIVATE_GLOBAL_FUNCTION(name, code) JSFunction* name ## PrivateFunction = JSFunction::create(vm, code ## CodeGenerator(vm), this);
841     JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(CREATE_PRIVATE_GLOBAL_FUNCTION)
842 #undef CREATE_PRIVATE_GLOBAL_FUNCTION
843
844     JSObject* arrayIteratorPrototype = ArrayIteratorPrototype::create(vm, this, ArrayIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
845     createArrayIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, arrayIteratorPrototype);
846
847     JSObject* asyncFromSyncIteratorPrototype = AsyncFromSyncIteratorPrototype::create(vm, this, AsyncFromSyncIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
848     AsyncFromSyncIteratorConstructorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, asyncFromSyncIteratorPrototype);
849
850     JSObject* mapIteratorPrototype = MapIteratorPrototype::create(vm, this, MapIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
851     createMapIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, mapIteratorPrototype);
852
853     JSObject* setIteratorPrototype = SetIteratorPrototype::create(vm, this, SetIteratorPrototype::createStructure(vm, this, m_iteratorPrototype.get()));
854     createSetIteratorPrivateFunction->putDirect(vm, vm.propertyNames->prototype, setIteratorPrototype);
855
856     GlobalPropertyInfo staticGlobals[] = {
857 #define INIT_PRIVATE_GLOBAL(name, code) GlobalPropertyInfo(vm.propertyNames->builtinNames().name ## PrivateName(), name ## PrivateFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
858         JSC_FOREACH_BUILTIN_FUNCTION_PRIVATE_GLOBAL_NAME(INIT_PRIVATE_GLOBAL)
859 #undef INIT_PRIVATE_GLOBAL
860         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
861         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
862         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
863         GlobalPropertyInfo(vm.propertyNames->builtinNames().getOwnPropertyNamesPrivateName(), privateFuncGetOwnPropertyNames, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
864         GlobalPropertyInfo(vm.propertyNames->builtinNames().propertyIsEnumerablePrivateName(), privateFuncPropertyIsEnumerable, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
865         GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
866         GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
867         GlobalPropertyInfo(vm.propertyNames->builtinNames().ErrorPrivateName(), m_errorConstructor.get(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
868         GlobalPropertyInfo(vm.propertyNames->builtinNames().RangeErrorPrivateName(), m_rangeErrorConstructor.get(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
869         GlobalPropertyInfo(vm.propertyNames->builtinNames().TypeErrorPrivateName(), m_typeErrorConstructor.get(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
870         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
871         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
872         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
873         GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
874         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySubarrayCreatePrivateName(), privateFuncTypedArraySubarrayCreate, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
875         GlobalPropertyInfo(vm.propertyNames->builtinNames().isBoundFunctionPrivateName(), privateFuncIsBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
876         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasInstanceBoundFunctionPrivateName(), privateFuncHasInstanceBoundFunction, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
877         GlobalPropertyInfo(vm.propertyNames->builtinNames().instanceOfPrivateName(), privateFuncInstanceOf, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
878         GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinLogPrivateName(), builtinLog, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
879         GlobalPropertyInfo(vm.propertyNames->builtinNames().BuiltinDescribePrivateName(), builtinDescribe, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
880         GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberPrivateName(), numberConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
881         GlobalPropertyInfo(vm.propertyNames->builtinNames().RegExpPrivateName(), m_regExpConstructor.get(), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
882         GlobalPropertyInfo(vm.propertyNames->builtinNames().StringPrivateName(), stringConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
883         GlobalPropertyInfo(vm.propertyNames->builtinNames().absPrivateName(), privateFuncAbs, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
884         GlobalPropertyInfo(vm.propertyNames->builtinNames().floorPrivateName(), privateFuncFloor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
885         GlobalPropertyInfo(vm.propertyNames->builtinNames().truncPrivateName(), privateFuncTrunc, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
886         GlobalPropertyInfo(vm.propertyNames->builtinNames().PromisePrivateName(), promiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
887         GlobalPropertyInfo(vm.propertyNames->builtinNames().ReflectPrivateName(), reflectObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
888         GlobalPropertyInfo(vm.propertyNames->builtinNames().InternalPromisePrivateName(), internalPromiseConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
889
890         GlobalPropertyInfo(vm.propertyNames->builtinNames().repeatCharacterPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncRepeatCharacter), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
891         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayPrivateName(), arrayConstructor->getDirect(vm, vm.propertyNames->isArray), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
892         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArraySlowPrivateName(), privateFuncIsArraySlow, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
893         GlobalPropertyInfo(vm.propertyNames->builtinNames().isArrayConstructorPrivateName(), privateFuncIsArrayConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
894         GlobalPropertyInfo(vm.propertyNames->builtinNames().concatMemcpyPrivateName(), privateFuncConcatMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
895         GlobalPropertyInfo(vm.propertyNames->builtinNames().appendMemcpyPrivateName(), privateFuncAppendMemcpy, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
896
897         GlobalPropertyInfo(vm.propertyNames->builtinNames().hostPromiseRejectionTrackerPrivateName(), JSFunction::create(vm, this, 2, String(), globalFuncHostPromiseRejectionTracker), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
898         GlobalPropertyInfo(vm.propertyNames->builtinNames().InspectorInstrumentationPrivateName(), InspectorInstrumentationObject::create(vm, this, InspectorInstrumentationObject::createStructure(vm, this, m_objectPrototype.get())), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
899         GlobalPropertyInfo(vm.propertyNames->builtinNames().MapPrivateName(), mapConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
900         GlobalPropertyInfo(vm.propertyNames->builtinNames().SetPrivateName(), setConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
901         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisTimeValuePrivateName(), privateFuncThisTimeValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
902         GlobalPropertyInfo(vm.propertyNames->builtinNames().thisNumberValuePrivateName(), privateFuncThisNumberValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
903 #if ENABLE(INTL)
904         GlobalPropertyInfo(vm.propertyNames->builtinNames().CollatorPrivateName(), intl->getDirect(vm, vm.propertyNames->Collator), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
905         GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
906         GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
907 #endif // ENABLE(INTL)
908
909         GlobalPropertyInfo(vm.propertyNames->builtinNames().isConstructorPrivateName(), JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
910
911         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoFlagsGetterPrivateName(), regExpProtoFlagsGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
912         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoGlobalGetterPrivateName(), regExpProtoGlobalGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
913         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoIgnoreCaseGetterPrivateName(), regExpProtoIgnoreCaseGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
914         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoMultilineGetterPrivateName(), regExpProtoMultilineGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
915         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoSourceGetterPrivateName(), regExpProtoSourceGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
916         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoStickyGetterPrivateName(), regExpProtoStickyGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
917         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpProtoUnicodeGetterPrivateName(), regExpProtoUnicodeGetterObject, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
918
919         // RegExp.prototype helpers.
920         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpBuiltinExecPrivateName(), builtinRegExpExec, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
921         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpCreatePrivateName(), JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
922         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpMatchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncMatchFast, RegExpMatchFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
923         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSearchFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncSearchFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
924         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
925         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpPrototypeSymbolReplacePrivateName(), m_regExpPrototype->getDirect(vm, vm.propertyNames->replaceSymbol), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
926         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpTestFastPrivateName(), JSFunction::create(vm, this, 1, String(), regExpProtoFuncTestFast, RegExpTestFastIntrinsic), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
927
928         // String.prototype helpers.
929         GlobalPropertyInfo(vm.propertyNames->builtinNames().stringIncludesInternalPrivateName(), JSFunction::create(vm, this, 1, String(), builtinStringIncludesInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
930         GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSplitFastPrivateName(), JSFunction::create(vm, this, 2, String(), stringProtoFuncSplitFast), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
931         GlobalPropertyInfo(vm.propertyNames->builtinNames().stringSubstrInternalPrivateName(), JSFunction::create(vm, this, 2, String(), builtinStringSubstrInternal), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
932
933         // Function prototype helpers.
934         GlobalPropertyInfo(vm.propertyNames->builtinNames().makeBoundFunctionPrivateName(), JSFunction::create(vm, this, 5, String(), makeBoundFunction), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
935         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasOwnLengthPropertyPrivateName(), JSFunction::create(vm, this, 1, String(), hasOwnLengthProperty), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
936
937         // Map and Set helpers.
938         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketHeadPrivateName(), privateFuncMapBucketHead, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
939         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketNextPrivateName(), privateFuncMapBucketNext, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
940         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketKeyPrivateName(), privateFuncMapBucketKey, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
941         GlobalPropertyInfo(vm.propertyNames->builtinNames().mapBucketValuePrivateName(), privateFuncMapBucketValue, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
942         GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketHeadPrivateName(), privateFuncSetBucketHead, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
943         GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketNextPrivateName(), privateFuncSetBucketNext, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
944         GlobalPropertyInfo(vm.propertyNames->builtinNames().setBucketKeyPrivateName(), privateFuncSetBucketKey, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
945 #if !ASSERT_DISABLED
946         GlobalPropertyInfo(vm.propertyNames->builtinNames().assertPrivateName(), JSFunction::create(vm, this, 1, String(), assertCall), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
947 #endif
948     };
949     addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
950     
951     m_specialPointers[Special::CallFunction] = m_callFunction.get();
952     m_specialPointers[Special::ApplyFunction] = m_applyFunction.get();
953     m_specialPointers[Special::ObjectConstructor] = objectConstructor;
954     m_specialPointers[Special::ArrayConstructor] = arrayConstructor;
955
956     m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::ThrowTypeErrorFunction)] = m_throwTypeErrorFunction.get();
957
958     if (UNLIKELY(Options::useDollarVM())) {
959         m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
960         JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
961
962         GlobalPropertyInfo extraStaticGlobals[] = {
963             GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
964         };
965         addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
966
967         putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
968     }
969
970 #if ENABLE(WEBASSEMBLY)
971     if (Options::useWebAssembly()) {
972         auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
973         m_webAssemblyStructure.set(vm, this, JSWebAssembly::createStructure(vm, this, webAssemblyPrototype));
974         m_webAssemblyModuleRecordStructure.set(vm, this, WebAssemblyModuleRecord::createStructure(vm, this, m_objectPrototype.get()));
975         m_webAssemblyFunctionStructure.set(vm, this, WebAssemblyFunction::createStructure(vm, this, m_functionPrototype.get()));
976         m_webAssemblyWrapperFunctionStructure.set(vm, this, WebAssemblyWrapperFunction::createStructure(vm, this, m_functionPrototype.get()));
977         m_webAssemblyToJSCalleeStructure.set(vm, this, WebAssemblyToJSCallee::createStructure(vm, this, jsNull()));
978         auto* webAssembly = JSWebAssembly::create(vm, this, m_webAssemblyStructure.get());
979         putDirectWithoutTransition(vm, Identifier::fromString(exec, "WebAssembly"), webAssembly, static_cast<unsigned>(PropertyAttribute::DontEnum));
980
981 #define CREATE_WEBASSEMBLY_CONSTRUCTOR(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) do { \
982         typedef capitalName ## Prototype Prototype; \
983         typedef capitalName ## Constructor Constructor; \
984         typedef JS ## capitalName JSObj; \
985         auto* base = m_ ## prototypeBase ## Prototype.get(); \
986         auto* prototype = Prototype::create(vm, this, Prototype::createStructure(vm, this, base)); \
987         auto* structure = JSObj::createStructure(vm, this, prototype); \
988         auto* constructor = Constructor::create(vm, Constructor::createStructure(vm, this, this->functionPrototype()), prototype); \
989         prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
990         m_ ## lowerName ## Prototype.set(vm, this, prototype); \
991         m_ ## properName ## Structure.set(vm, this, structure); \
992         webAssembly->putDirectWithoutTransition(vm, Identifier::fromString(this->globalExec(), #jsName), constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
993     } while (0);
994
995         FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(CREATE_WEBASSEMBLY_CONSTRUCTOR)
996
997 #undef CREATE_WEBASSEMBLY_CONSTRUCTOR
998     }
999 #endif // ENABLE(WEBASSEMBLY)
1000
1001     {
1002         ExecState* exec = globalExec();
1003
1004         auto setupAdaptiveWatchpoint = [&] (JSObject* base, const Identifier& ident) -> ObjectPropertyCondition {
1005             // Performing these gets should not throw.
1006             PropertySlot slot(base, PropertySlot::InternalMethodType::Get);
1007             bool result = base->getOwnPropertySlot(base, exec, ident, slot);
1008             ASSERT_UNUSED(result, result);
1009             catchScope.assertNoException();
1010             RELEASE_ASSERT(slot.isCacheableValue());
1011             JSValue functionValue = slot.getValue(exec, ident);
1012             catchScope.assertNoException();
1013             ASSERT(jsDynamicCast<JSFunction*>(vm, functionValue));
1014
1015             ObjectPropertyCondition condition = generateConditionForSelfEquivalence(m_vm, nullptr, base, ident.impl());
1016             RELEASE_ASSERT(condition.requiredValue() == functionValue);
1017
1018             bool isWatchable = condition.isWatchable(PropertyCondition::EnsureWatchability);
1019             RELEASE_ASSERT(isWatchable); // We allow this to install the necessary watchpoints.
1020
1021             return condition;
1022         };
1023
1024         {
1025             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(arrayIteratorPrototype, m_vm.propertyNames->next);
1026             m_arrayIteratorPrototypeNext = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_arrayIteratorProtocolWatchpoint);
1027             m_arrayIteratorPrototypeNext->install();
1028         }
1029         {
1030             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(this->arrayPrototype(), m_vm.propertyNames->iteratorSymbol);
1031             m_arrayPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_arrayIteratorProtocolWatchpoint);
1032             m_arrayPrototypeSymbolIteratorWatchpoint->install();
1033         }
1034
1035         {
1036             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(mapIteratorPrototype, m_vm.propertyNames->next);
1037             m_mapIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_mapIteratorProtocolWatchpoint);
1038             m_mapIteratorPrototypeNextWatchpoint->install();
1039         }
1040         {
1041             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_mapPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1042             m_mapPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_mapIteratorProtocolWatchpoint);
1043             m_mapPrototypeSymbolIteratorWatchpoint->install();
1044         }
1045
1046         {
1047             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(setIteratorPrototype, m_vm.propertyNames->next);
1048             m_setIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_setIteratorProtocolWatchpoint);
1049             m_setIteratorPrototypeNextWatchpoint->install();
1050         }
1051         {
1052             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_setPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1053             m_setPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_setIteratorProtocolWatchpoint);
1054             m_setPrototypeSymbolIteratorWatchpoint->install();
1055         }
1056
1057         {
1058             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_stringIteratorPrototype.get(), m_vm.propertyNames->next);
1059             m_stringIteratorPrototypeNextWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_stringIteratorProtocolWatchpoint);
1060             m_stringIteratorPrototypeNextWatchpoint->install();
1061         }
1062         {
1063             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_stringPrototype.get(), m_vm.propertyNames->iteratorSymbol);
1064             m_stringPrototypeSymbolIteratorWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_stringIteratorProtocolWatchpoint);
1065             m_stringPrototypeSymbolIteratorWatchpoint->install();
1066         }
1067
1068         {
1069             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_mapPrototype.get(), m_vm.propertyNames->set);
1070             m_mapPrototypeSetWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_mapSetWatchpoint);
1071             m_mapPrototypeSetWatchpoint->install();
1072         }
1073
1074         {
1075             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(m_setPrototype.get(), m_vm.propertyNames->add);
1076             m_setPrototypeAddWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_setAddWatchpoint);
1077             m_setPrototypeAddWatchpoint->install();
1078         }
1079
1080         {
1081             ObjectPropertyCondition condition = setupAdaptiveWatchpoint(numberPrototype(), m_vm.propertyNames->toString);
1082             m_numberPrototypeToStringWatchpoint = std::make_unique<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>>(vm, condition, m_numberToStringWatchpoint);
1083             m_numberPrototypeToStringWatchpoint->install();
1084             m_numberProtoToStringFunction.set(vm, this, jsCast<JSFunction*>(numberPrototype()->getDirect(vm, vm.propertyNames->toString)));
1085         }
1086     }
1087
1088     resetPrototype(vm, getPrototypeDirect(vm));
1089 }
1090
1091 bool JSGlobalObject::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
1092 {
1093     VM& vm = exec->vm();
1094     auto scope = DECLARE_THROW_SCOPE(vm);
1095     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1096     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(thisObject));
1097
1098     if (UNLIKELY(isThisValueAltered(slot, thisObject))) {
1099         scope.release();
1100         return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
1101     }
1102
1103     bool shouldThrowReadOnlyError = slot.isStrictMode();
1104     bool ignoreReadOnlyErrors = false;
1105     bool putResult = false;
1106     bool done = symbolTablePutTouchWatchpointSet(thisObject, exec, propertyName, value, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
1107     EXCEPTION_ASSERT((!!scope.exception() == (done && !putResult)) || !shouldThrowReadOnlyError);
1108     if (done)
1109         return putResult;
1110     scope.release();
1111     return Base::put(thisObject, exec, propertyName, value, slot);
1112 }
1113
1114 bool JSGlobalObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
1115 {
1116     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(object);
1117     PropertySlot slot(thisObject, PropertySlot::InternalMethodType::VMInquiry);
1118     // silently ignore attempts to add accessors aliasing vars.
1119     if (descriptor.isAccessorDescriptor() && symbolTableGet(thisObject, propertyName, slot))
1120         return false;
1121     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
1122 }
1123
1124 void JSGlobalObject::addGlobalVar(const Identifier& ident)
1125 {
1126     ConcurrentJSLocker locker(symbolTable()->m_lock);
1127     SymbolTableEntry entry = symbolTable()->get(locker, ident.impl());
1128     if (!entry.isNull())
1129         return;
1130     
1131     ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1132     SymbolTableEntry newEntry(VarOffset(offset), 0);
1133     newEntry.prepareToWatch();
1134     symbolTable()->add(locker, ident.impl(), WTFMove(newEntry));
1135     
1136     ScopeOffset offsetForAssert = addVariables(1, jsUndefined());
1137     RELEASE_ASSERT(offsetForAssert == offset);
1138 }
1139
1140 void JSGlobalObject::addFunction(ExecState* exec, const Identifier& propertyName)
1141 {
1142     VM& vm = exec->vm();
1143     VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
1144     methodTable(vm)->deleteProperty(this, exec, propertyName);
1145     addGlobalVar(propertyName);
1146 }
1147
1148 void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
1149 {
1150     m_globalScopeExtension.set(vm(), this, scope);
1151 }
1152
1153 void JSGlobalObject::clearGlobalScopeExtension()
1154 {
1155     m_globalScopeExtension.clear();
1156 }
1157
1158 static inline JSObject* lastInPrototypeChain(VM& vm, JSObject* object)
1159 {
1160     JSObject* o = object;
1161     while (o->getPrototypeDirect(vm).isObject())
1162         o = asObject(o->getPrototypeDirect(vm));
1163     return o;
1164 }
1165
1166 // Private namespace for helpers for JSGlobalObject::haveABadTime()
1167 namespace {
1168
1169 class ObjectsWithBrokenIndexingFinder : public MarkedBlock::VoidFunctor {
1170 public:
1171     ObjectsWithBrokenIndexingFinder(MarkedArgumentBuffer&, JSGlobalObject*);
1172     IterationStatus operator()(HeapCell*, HeapCell::Kind) const;
1173
1174 private:
1175     void visit(JSCell*);
1176
1177     MarkedArgumentBuffer& m_foundObjects;
1178     JSGlobalObject* m_globalObject;
1179 };
1180
1181 ObjectsWithBrokenIndexingFinder::ObjectsWithBrokenIndexingFinder(
1182     MarkedArgumentBuffer& foundObjects, JSGlobalObject* globalObject)
1183     : m_foundObjects(foundObjects)
1184     , m_globalObject(globalObject)
1185 {
1186 }
1187
1188 inline bool hasBrokenIndexing(IndexingType type)
1189 {
1190     return type && !hasSlowPutArrayStorage(type);
1191 }
1192
1193 inline bool hasBrokenIndexing(JSObject* object)
1194 {
1195     IndexingType type = object->indexingType();
1196     return hasBrokenIndexing(type);
1197 }
1198
1199 inline void ObjectsWithBrokenIndexingFinder::visit(JSCell* cell)
1200 {
1201     if (!cell->isObject())
1202         return;
1203     
1204     VM& vm = m_globalObject->vm();
1205
1206     // We only want to have a bad time in the affected global object, not in the entire
1207     // VM. But we have to be careful, since there may be objects that claim to belong to
1208     // a different global object that have prototypes from our global object.
1209     auto isInEffectedGlobalObject = [&] (JSObject* object) {
1210         for (JSObject* current = object; ;) {
1211             if (current->globalObject() == m_globalObject)
1212                 return true;
1213             
1214             JSValue prototypeValue = current->getPrototypeDirect(vm);
1215             if (prototypeValue.isNull())
1216                 return false;
1217             current = asObject(prototypeValue);
1218         }
1219         RELEASE_ASSERT_NOT_REACHED();
1220     };
1221
1222     JSObject* object = asObject(cell);
1223
1224     if (JSFunction* function = jsDynamicCast<JSFunction*>(vm, object)) {
1225         if (FunctionRareData* rareData = function->rareData()) {
1226             // We only use this to cache JSFinalObjects. They do not start off with a broken indexing type.
1227             ASSERT(!(rareData->objectAllocationStructure() && hasBrokenIndexing(rareData->objectAllocationStructure()->indexingType())));
1228
1229             if (Structure* structure = rareData->internalFunctionAllocationStructure()) {
1230                 if (hasBrokenIndexing(structure->indexingType())) {
1231                     bool isRelevantGlobalObject = (structure->globalObject() == m_globalObject)
1232                         || (structure->hasMonoProto() && !structure->storedPrototype().isNull() && isInEffectedGlobalObject(asObject(structure->storedPrototype())));
1233                     if (isRelevantGlobalObject)
1234                         rareData->clearInternalFunctionAllocationProfile();
1235                 }
1236             }
1237         }
1238     }
1239
1240     // Run this filter first, since it's cheap, and ought to filter out a lot of objects.
1241     if (!hasBrokenIndexing(object))
1242         return;
1243     
1244     if (isInEffectedGlobalObject(object))
1245         m_foundObjects.append(object);
1246 }
1247
1248 IterationStatus ObjectsWithBrokenIndexingFinder::operator()(HeapCell* cell, HeapCell::Kind kind) const
1249 {
1250     if (kind == HeapCell::JSCell) {
1251         // FIXME: This const_cast exists because this isn't a C++ lambda.
1252         // https://bugs.webkit.org/show_bug.cgi?id=159644
1253         const_cast<ObjectsWithBrokenIndexingFinder*>(this)->visit(static_cast<JSCell*>(cell));
1254     }
1255     return IterationStatus::Continue;
1256 }
1257
1258 } // end private namespace for helpers for JSGlobalObject::haveABadTime()
1259
1260 void JSGlobalObject::haveABadTime(VM& vm)
1261 {
1262     ASSERT(&vm == &this->vm());
1263     
1264     if (isHavingABadTime())
1265         return;
1266
1267     vm.structureCache.clear(); // We may be caching array structures in here.
1268
1269     // Make sure that all allocations or indexed storage transitions that are inlining
1270     // the assumption that it's safe to transition to a non-SlowPut array storage don't
1271     // do so anymore.
1272     m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
1273     ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
1274     
1275     // Make sure that all JSArray allocations that load the appropriate structure from
1276     // this object now load a structure that uses SlowPut.
1277     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1278         m_arrayStructureForIndexingShapeDuringAllocation[i].set(vm, this, originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
1279
1280     // Same for any special array structures.
1281     Structure* slowPutStructure;
1282     slowPutStructure = createRegExpMatchesArraySlowPutStructure(vm, this);
1283     m_regExpMatchesArrayStructure.set(vm, this, slowPutStructure);
1284     slowPutStructure = createRegExpMatchesArrayWithGroupsSlowPutStructure(vm, this);
1285     m_regExpMatchesArrayWithGroupsStructure.set(vm, this, slowPutStructure);
1286     slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
1287     m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
1288
1289     // Make sure that all objects that have indexed storage switch to the slow kind of
1290     // indexed storage.
1291     MarkedArgumentBuffer foundObjects; // Use MarkedArgumentBuffer because switchToSlowPutArrayStorage() may GC.
1292     ObjectsWithBrokenIndexingFinder finder(foundObjects, this);
1293     {
1294         HeapIterationScope iterationScope(vm.heap);
1295         vm.heap.objectSpace().forEachLiveCell(iterationScope, finder);
1296     }
1297     RELEASE_ASSERT(!foundObjects.hasOverflowed());
1298     while (!foundObjects.isEmpty()) {
1299         JSObject* object = asObject(foundObjects.last());
1300         foundObjects.removeLast();
1301         ASSERT(hasBrokenIndexing(object));
1302         object->switchToSlowPutArrayStorage(vm);
1303     }
1304 }
1305
1306 // Set prototype, and also insert the object prototype at the end of the chain.
1307 void JSGlobalObject::resetPrototype(VM& vm, JSValue prototype)
1308 {
1309     setPrototypeDirect(vm, prototype);
1310
1311     JSObject* oldLastInPrototypeChain = lastInPrototypeChain(vm, this);
1312     JSObject* objectPrototype = m_objectPrototype.get();
1313     if (oldLastInPrototypeChain != objectPrototype)
1314         oldLastInPrototypeChain->setPrototypeDirect(vm, objectPrototype);
1315
1316     // Whenever we change the prototype of the global object, we need to create a new JSProxy with the correct prototype.
1317     setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype, PureForwardingProxyType), this));
1318 }
1319
1320 void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
1321
1322     JSGlobalObject* thisObject = jsCast<JSGlobalObject*>(cell);
1323     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
1324     Base::visitChildren(thisObject, visitor);
1325
1326     visitor.append(thisObject->m_globalThis);
1327
1328     visitor.append(thisObject->m_globalLexicalEnvironment);
1329     visitor.append(thisObject->m_globalScopeExtension);
1330     visitor.append(thisObject->m_globalCallee);
1331     visitor.append(thisObject->m_regExpConstructor);
1332     visitor.append(thisObject->m_errorConstructor);
1333     visitor.append(thisObject->m_nativeErrorPrototypeStructure);
1334     visitor.append(thisObject->m_nativeErrorStructure);
1335     thisObject->m_evalErrorConstructor.visit(visitor);
1336     visitor.append(thisObject->m_rangeErrorConstructor);
1337     thisObject->m_referenceErrorConstructor.visit(visitor);
1338     thisObject->m_syntaxErrorConstructor.visit(visitor);
1339     visitor.append(thisObject->m_typeErrorConstructor);
1340     thisObject->m_URIErrorConstructor.visit(visitor);
1341     visitor.append(thisObject->m_objectConstructor);
1342     visitor.append(thisObject->m_promiseConstructor);
1343
1344     visitor.append(thisObject->m_nullGetterFunction);
1345     visitor.append(thisObject->m_nullSetterFunction);
1346
1347     visitor.append(thisObject->m_parseIntFunction);
1348     visitor.append(thisObject->m_parseFloatFunction);
1349     visitor.append(thisObject->m_evalFunction);
1350     visitor.append(thisObject->m_callFunction);
1351     visitor.append(thisObject->m_applyFunction);
1352     visitor.append(thisObject->m_throwTypeErrorFunction);
1353     thisObject->m_arrayProtoToStringFunction.visit(visitor);
1354     thisObject->m_arrayProtoValuesFunction.visit(visitor);
1355     thisObject->m_initializePromiseFunction.visit(visitor);
1356     thisObject->m_iteratorProtocolFunction.visit(visitor);
1357     thisObject->m_promiseResolveFunction.visit(visitor);
1358     visitor.append(thisObject->m_objectProtoValueOfFunction);
1359     visitor.append(thisObject->m_numberProtoToStringFunction);
1360     visitor.append(thisObject->m_newPromiseCapabilityFunction);
1361     visitor.append(thisObject->m_functionProtoHasInstanceSymbolFunction);
1362     thisObject->m_throwTypeErrorGetterSetter.visit(visitor);
1363     visitor.append(thisObject->m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter);
1364     visitor.append(thisObject->m_moduleLoader);
1365
1366     visitor.append(thisObject->m_objectPrototype);
1367     visitor.append(thisObject->m_functionPrototype);
1368     visitor.append(thisObject->m_arrayPrototype);
1369     visitor.append(thisObject->m_errorPrototype);
1370     visitor.append(thisObject->m_iteratorPrototype);
1371     visitor.append(thisObject->m_generatorFunctionPrototype);
1372     visitor.append(thisObject->m_generatorPrototype);
1373     visitor.append(thisObject->m_asyncFunctionPrototype);
1374     visitor.append(thisObject->m_asyncGeneratorPrototype);
1375     visitor.append(thisObject->m_asyncIteratorPrototype);
1376     visitor.append(thisObject->m_asyncGeneratorFunctionPrototype);
1377     visitor.append(thisObject->m_moduleLoaderPrototype);
1378
1379     thisObject->m_debuggerScopeStructure.visit(visitor);
1380     thisObject->m_withScopeStructure.visit(visitor);
1381     visitor.append(thisObject->m_strictEvalActivationStructure);
1382     visitor.append(thisObject->m_lexicalEnvironmentStructure);
1383     thisObject->m_moduleEnvironmentStructure.visit(visitor);
1384     visitor.append(thisObject->m_directArgumentsStructure);
1385     visitor.append(thisObject->m_scopedArgumentsStructure);
1386     visitor.append(thisObject->m_clonedArgumentsStructure);
1387     visitor.append(thisObject->m_objectStructureForObjectConstructor);
1388     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1389         visitor.append(thisObject->m_originalArrayStructureForIndexingShape[i]);
1390     for (unsigned i = 0; i < NumberOfIndexingShapes; ++i)
1391         visitor.append(thisObject->m_arrayStructureForIndexingShapeDuringAllocation[i]);
1392     thisObject->m_callbackConstructorStructure.visit(visitor);
1393     thisObject->m_callbackFunctionStructure.visit(visitor);
1394     thisObject->m_callbackObjectStructure.visit(visitor);
1395 #if JSC_OBJC_API_ENABLED
1396     thisObject->m_objcCallbackFunctionStructure.visit(visitor);
1397     thisObject->m_objcWrapperObjectStructure.visit(visitor);
1398 #endif
1399 #ifdef JSC_GLIB_API_ENABLED
1400     thisObject->m_glibCallbackFunctionStructure.visit(visitor);
1401     thisObject->m_glibWrapperObjectStructure.visit(visitor);
1402 #endif
1403     thisObject->m_nullPrototypeObjectStructure.visit(visitor);
1404     visitor.append(thisObject->m_errorStructure);
1405     visitor.append(thisObject->m_calleeStructure);
1406     visitor.append(thisObject->m_strictFunctionStructure);
1407     visitor.append(thisObject->m_sloppyFunctionStructure);
1408     visitor.append(thisObject->m_arrowFunctionStructure);
1409     thisObject->m_customGetterSetterFunctionStructure.visit(visitor);
1410     thisObject->m_boundFunctionStructure.visit(visitor);
1411     visitor.append(thisObject->m_getterSetterStructure);
1412     thisObject->m_nativeStdFunctionStructure.visit(visitor);
1413     visitor.append(thisObject->m_bigIntObjectStructure);
1414     visitor.append(thisObject->m_symbolObjectStructure);
1415     visitor.append(thisObject->m_regExpStructure);
1416     visitor.append(thisObject->m_generatorFunctionStructure);
1417     visitor.append(thisObject->m_asyncFunctionStructure);
1418     visitor.append(thisObject->m_asyncGeneratorFunctionStructure);
1419     visitor.append(thisObject->m_iteratorResultObjectStructure);
1420     visitor.append(thisObject->m_regExpMatchesArrayStructure);
1421     visitor.append(thisObject->m_regExpMatchesArrayWithGroupsStructure);
1422     visitor.append(thisObject->m_moduleRecordStructure);
1423     visitor.append(thisObject->m_moduleNamespaceObjectStructure);
1424     visitor.append(thisObject->m_dollarVMStructure);
1425     visitor.append(thisObject->m_proxyObjectStructure);
1426     visitor.append(thisObject->m_callableProxyObjectStructure);
1427     visitor.append(thisObject->m_proxyRevokeStructure);
1428     visitor.append(thisObject->m_moduleLoaderStructure);
1429     
1430     visitor.append(thisObject->m_arrayBufferPrototype);
1431     visitor.append(thisObject->m_arrayBufferStructure);
1432 #if ENABLE(SHARED_ARRAY_BUFFER)
1433     visitor.append(thisObject->m_sharedArrayBufferPrototype);
1434     visitor.append(thisObject->m_sharedArrayBufferStructure);
1435 #endif
1436
1437 #define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1438     visitor.append(thisObject->m_ ## lowerName ## Prototype); \
1439     visitor.append(thisObject->m_ ## properName ## Structure); \
1440
1441     FOR_EACH_SIMPLE_BUILTIN_TYPE(VISIT_SIMPLE_TYPE)
1442     if (UNLIKELY(Options::useBigInt()))
1443         FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(VISIT_SIMPLE_TYPE)
1444     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(VISIT_SIMPLE_TYPE)
1445     
1446 #if ENABLE(WEBASSEMBLY)
1447     visitor.append(thisObject->m_webAssemblyStructure);
1448     visitor.append(thisObject->m_webAssemblyModuleRecordStructure);
1449     visitor.append(thisObject->m_webAssemblyFunctionStructure);
1450     visitor.append(thisObject->m_webAssemblyWrapperFunctionStructure);
1451     visitor.append(thisObject->m_webAssemblyToJSCalleeStructure);
1452     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(VISIT_SIMPLE_TYPE)
1453 #endif // ENABLE(WEBASSEMBLY)
1454
1455 #undef VISIT_SIMPLE_TYPE
1456
1457 #define VISIT_LAZY_TYPE(CapitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
1458     thisObject->m_ ## properName ## Structure.visit(visitor);
1459     
1460     FOR_EACH_LAZY_BUILTIN_TYPE(VISIT_LAZY_TYPE)
1461
1462 #undef VISIT_LAZY_TYPE
1463
1464     for (unsigned i = NumberOfTypedArrayTypes; i--;)
1465         thisObject->lazyTypedArrayStructure(indexToTypedArrayType(i)).visit(visitor);
1466     
1467     visitor.append(thisObject->m_speciesGetterSetter);
1468     thisObject->m_typedArrayProto.visit(visitor);
1469     thisObject->m_typedArraySuperConstructor.visit(visitor);
1470 }
1471
1472 ExecState* JSGlobalObject::globalExec()
1473 {
1474     return CallFrame::create(m_globalCallFrame);
1475 }
1476
1477 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
1478 {
1479     ScopeOffset startOffset = addVariables(count, jsUndefined());
1480
1481     for (int i = 0; i < count; ++i) {
1482         GlobalPropertyInfo& global = globals[i];
1483         ASSERT(global.attributes & PropertyAttribute::DontDelete);
1484         
1485         WatchpointSet* watchpointSet = nullptr;
1486         WriteBarrierBase<Unknown>* variable = nullptr;
1487         {
1488             ConcurrentJSLocker locker(symbolTable()->m_lock);
1489             ScopeOffset offset = symbolTable()->takeNextScopeOffset(locker);
1490             RELEASE_ASSERT(offset == startOffset + i);
1491             SymbolTableEntry newEntry(VarOffset(offset), global.attributes);
1492             newEntry.prepareToWatch();
1493             watchpointSet = newEntry.watchpointSet();
1494             symbolTable()->add(locker, global.identifier.impl(), WTFMove(newEntry));
1495             variable = &variableAt(offset);
1496         }
1497         symbolTablePutTouchWatchpointSet(vm(), this, global.identifier, global.value, variable, watchpointSet);
1498     }
1499 }
1500
1501 bool JSGlobalObject::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
1502 {
1503     if (Base::getOwnPropertySlot(object, exec, propertyName, slot))
1504         return true;
1505     return symbolTableGet(jsCast<JSGlobalObject*>(object), propertyName, slot);
1506 }
1507
1508 void JSGlobalObject::clearRareData(JSCell* cell)
1509 {
1510     jsCast<JSGlobalObject*>(cell)->m_rareData = nullptr;
1511 }
1512
1513 void slowValidateCell(JSGlobalObject* globalObject)
1514 {
1515     RELEASE_ASSERT(globalObject->isGlobalObject());
1516     ASSERT_GC_OBJECT_INHERITS(globalObject, JSGlobalObject::info());
1517 }
1518
1519 void JSGlobalObject::setRemoteDebuggingEnabled(bool enabled)
1520 {
1521 #if ENABLE(REMOTE_INSPECTOR)
1522     m_inspectorDebuggable->setRemoteDebuggingAllowed(enabled);
1523 #else
1524     UNUSED_PARAM(enabled);
1525 #endif
1526 }
1527
1528 bool JSGlobalObject::remoteDebuggingEnabled() const
1529 {
1530 #if ENABLE(REMOTE_INSPECTOR)
1531     return m_inspectorDebuggable->remoteDebuggingAllowed();
1532 #else
1533     return false;
1534 #endif
1535 }
1536
1537 void JSGlobalObject::setName(const String& name)
1538 {
1539     m_name = name;
1540
1541 #if ENABLE(REMOTE_INSPECTOR)
1542     m_inspectorDebuggable->update();
1543 #endif
1544 }
1545
1546 # if ENABLE(INTL)
1547 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
1548 {
1549     if (m_intlCollatorAvailableLocales.isEmpty()) {
1550         int32_t count = ucol_countAvailable();
1551         for (int32_t i = 0; i < count; ++i) {
1552             String locale(ucol_getAvailable(i));
1553             convertICULocaleToBCP47LanguageTag(locale);
1554             m_intlCollatorAvailableLocales.add(locale);
1555         }
1556     }
1557     return m_intlCollatorAvailableLocales;
1558 }
1559
1560 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
1561 {
1562     if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
1563         int32_t count = udat_countAvailable();
1564         for (int32_t i = 0; i < count; ++i) {
1565             String locale(udat_getAvailable(i));
1566             convertICULocaleToBCP47LanguageTag(locale);
1567             m_intlDateTimeFormatAvailableLocales.add(locale);
1568         }
1569     }
1570     return m_intlDateTimeFormatAvailableLocales;
1571 }
1572
1573 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
1574 {
1575     if (m_intlNumberFormatAvailableLocales.isEmpty()) {
1576         int32_t count = unum_countAvailable();
1577         for (int32_t i = 0; i < count; ++i) {
1578             String locale(unum_getAvailable(i));
1579             convertICULocaleToBCP47LanguageTag(locale);
1580             m_intlNumberFormatAvailableLocales.add(locale);
1581         }
1582     }
1583     return m_intlNumberFormatAvailableLocales;
1584 }
1585 #endif // ENABLE(INTL)
1586
1587 void JSGlobalObject::queueMicrotask(Ref<Microtask>&& task)
1588 {
1589     if (globalObjectMethodTable()->queueTaskToEventLoop) {
1590         globalObjectMethodTable()->queueTaskToEventLoop(*this, WTFMove(task));
1591         return;
1592     }
1593
1594     vm().queueMicrotask(*this, WTFMove(task));
1595 }
1596
1597 bool JSGlobalObject::hasDebugger() const
1598
1599     return m_debugger;
1600 }
1601
1602 bool JSGlobalObject::hasInteractiveDebugger() const 
1603
1604     return m_debugger && m_debugger->isInteractivelyDebugging();
1605 }
1606
1607 JSGlobalObject* JSGlobalObject::create(VM& vm, Structure* structure)
1608 {
1609     JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
1610     globalObject->finishCreation(vm);
1611     return globalObject;
1612 }
1613
1614 void JSGlobalObject::finishCreation(VM& vm)
1615 {
1616     Base::finishCreation(vm);
1617     structure()->setGlobalObject(vm, this);
1618     m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1619     init(vm);
1620     setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, getPrototypeDirect(vm), PureForwardingProxyType), this));
1621     ASSERT(type() == GlobalObjectType);
1622 }
1623
1624 void JSGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
1625 {
1626     Base::finishCreation(vm);
1627     structure()->setGlobalObject(vm, this);
1628     m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
1629     init(vm);
1630     setGlobalThis(vm, thisValue);
1631     ASSERT(type() == GlobalObjectType);
1632 }
1633
1634 #ifdef JSC_GLIB_API_ENABLED
1635 void JSGlobalObject::setWrapperMap(std::unique_ptr<WrapperMap>&& map)
1636 {
1637     m_wrapperMap = WTFMove(map);
1638 }
1639 #endif
1640
1641 } // namespace JSC