[JSC] SharedArrayBufferConstructor and ArrayBufferConstructor should not have their...
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGlobalObject.h
1 /*
2  *  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3  *  Copyright (C) 2007-2018 Apple Inc. All rights reserved.
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Library General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Library General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Library General Public License
16  *  along with this library; see the file COPYING.LIB.  If not, write to
17  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  *  Boston, MA 02110-1301, USA.
19  *
20  */
21
22 #pragma once
23
24 #include "ArrayAllocationProfile.h"
25 #include "ArrayBufferSharingMode.h"
26 #include "BigIntPrototype.h"
27 #include "BooleanPrototype.h"
28 #include "ExceptionHelpers.h"
29 #include "InternalFunction.h"
30 #include "JSArray.h"
31 #include "JSArrayBufferPrototype.h"
32 #include "JSCPoison.h"
33 #include "JSClassRef.h"
34 #include "JSGlobalLexicalEnvironment.h"
35 #include "JSPromiseDeferred.h"
36 #include "JSSegmentedVariableObject.h"
37 #include "JSWeakObjectMapRefInternal.h"
38 #include "LazyProperty.h"
39 #include "LazyClassStructure.h"
40 #include "NumberPrototype.h"
41 #include "RuntimeFlags.h"
42 #include "SpecialPointer.h"
43 #include "StringPrototype.h"
44 #include "SymbolPrototype.h"
45 #include "VM.h"
46 #include "Watchpoint.h"
47 #include <JavaScriptCore/JSBase.h>
48 #include <array>
49 #include <wtf/HashSet.h>
50 #include <wtf/PoisonedUniquePtr.h>
51 #include <wtf/RetainPtr.h>
52
53 struct OpaqueJSClass;
54 struct OpaqueJSClassContextData;
55 OBJC_CLASS JSWrapperMap;
56
57 namespace Inspector {
58 class JSGlobalObjectInspectorController;
59 }
60
61 namespace JSC {
62 class ArrayConstructor;
63 class ArrayPrototype;
64 class AsyncIteratorPrototype;
65 class AsyncFunctionPrototype;
66 class AsyncGeneratorPrototype;
67 class AsyncGeneratorFunctionPrototype;
68 class BooleanPrototype;
69 class ConsoleClient;
70 class Debugger;
71 class ErrorConstructor;
72 class ErrorPrototype;
73 class EvalCodeBlock;
74 class EvalExecutable;
75 class FunctionConstructor;
76 class FunctionPrototype;
77 class GeneratorPrototype;
78 class GeneratorFunctionPrototype;
79 class GetterSetter;
80 class GlobalCodeBlock;
81 class IndirectEvalExecutable;
82 class InputCursor;
83 class IntlObject;
84 class JSArrayBuffer;
85 class JSArrayBufferPrototype;
86 class JSCallee;
87 class JSGlobalObjectDebuggable;
88 class JSInternalPromise;
89 class JSModuleLoader;
90 class JSModuleRecord;
91 class JSPromise;
92 class JSPromiseConstructor;
93 class JSPromisePrototype;
94 class JSSharedArrayBuffer;
95 class JSSharedArrayBufferPrototype;
96 class JSTypedArrayViewConstructor;
97 class JSTypedArrayViewPrototype;
98 class DirectEvalExecutable;
99 class LLIntOffsetsExtractor;
100 class MapPrototype;
101 class Microtask;
102 class ModuleLoader;
103 class ModuleProgramExecutable;
104 class NativeErrorConstructor;
105 class NullGetterFunction;
106 class NullSetterFunction;
107 class ObjectConstructor;
108 class ProgramCodeBlock;
109 class ProgramExecutable;
110 class RegExpConstructor;
111 class RegExpPrototype;
112 class SetPrototype;
113 class SourceCode;
114 class SourceOrigin;
115 class UnlinkedModuleProgramCodeBlock;
116 class VariableEnvironment;
117 struct ActivationStackNode;
118 struct HashTable;
119
120 #ifdef JSC_GLIB_API_ENABLED
121 class WrapperMap;
122 #endif
123
124 template<typename Watchpoint> class ObjectPropertyChangeAdaptiveWatchpoint;
125
126 #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName, object)
127
128 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
129     macro(String, string, stringObject, StringObject, String, object) \
130     macro(Symbol, symbol, symbolObject, SymbolObject, Symbol, object) \
131     macro(Number, number, numberObject, NumberObject, Number, object) \
132     macro(Boolean, boolean, booleanObject, BooleanObject, Boolean, object) \
133     macro(Error, error, error, ErrorInstance, Error, object) \
134     macro(Map, map, map, JSMap, Map, object) \
135     macro(Set, set, set, JSSet, Set, object) \
136     macro(JSPromise, promise, promise, JSPromise, Promise, object)
137
138 #define FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
139     macro(BigInt, bigInt, bigIntObject, BigIntObject, BigInt, object)
140
141 #define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
142     macro(StringIterator, stringIterator, stringIterator, JSStringIterator, StringIterator, iterator) \
143
144 #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
145     FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
146     macro(JSInternalPromise, internalPromise, internalPromise, JSInternalPromise, InternalPromise, object) \
147
148 #define FOR_EACH_LAZY_BUILTIN_TYPE(macro) \
149     macro(Date, date, date, DateInstance, Date, object) \
150     DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
151     DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \
152
153 #if ENABLE(WEBASSEMBLY)
154 #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) \
155     macro(WebAssemblyCompileError, webAssemblyCompileError, WebAssemblyCompileError, WebAssemblyCompileError, CompileError, error) \
156     macro(WebAssemblyInstance,     webAssemblyInstance,     WebAssemblyInstance,     WebAssemblyInstance,     Instance,     object) \
157     macro(WebAssemblyLinkError,    webAssemblyLinkError,    WebAssemblyLinkError,    WebAssemblyLinkError,    LinkError,    error) \
158     macro(WebAssemblyMemory,       webAssemblyMemory,       WebAssemblyMemory,       WebAssemblyMemory,       Memory,       object) \
159     macro(WebAssemblyModule,       webAssemblyModule,       WebAssemblyModule,       WebAssemblyModule,       Module,       object) \
160     macro(WebAssemblyRuntimeError, webAssemblyRuntimeError, WebAssemblyRuntimeError, WebAssemblyRuntimeError, RuntimeError, error) \
161     macro(WebAssemblyTable,        webAssemblyTable,        WebAssemblyTable,        WebAssemblyTable,        Table,        object)
162 #else
163 #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro)
164 #endif // ENABLE(WEBASSEMBLY)
165
166 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
167     class JS ## capitalName; \
168     class capitalName ## Prototype; \
169     class capitalName ## Constructor;
170
171 class IteratorPrototype;
172 FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
173 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DECLARE_SIMPLE_BUILTIN_TYPE)
174 FOR_EACH_LAZY_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
175 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
176 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
177
178 #undef DECLARE_SIMPLE_BUILTIN_TYPE
179
180 enum class JSPromiseRejectionOperation : unsigned {
181     Reject, // When a promise is rejected without any handlers.
182     Handle, // When a handler is added to a rejected promise for the first time.
183 };
184
185 struct GlobalObjectMethodTable {
186     typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*);
187     SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo;
188
189     typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*);
190     ShouldInterruptScriptFunctionPtr shouldInterruptScript;
191
192     typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr)(const JSGlobalObject*);
193     JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags;
194
195     typedef void (*QueueTaskToEventLoopFunctionPtr)(JSGlobalObject&, Ref<Microtask>&&);
196     QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
197
198     typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*);
199     ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout;
200
201     typedef JSInternalPromise* (*ModuleLoaderImportModulePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, JSValue, const SourceOrigin&);
202     ModuleLoaderImportModulePtr moduleLoaderImportModule;
203
204     typedef Identifier (*ModuleLoaderResolvePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
205     ModuleLoaderResolvePtr moduleLoaderResolve;
206
207     typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
208     ModuleLoaderFetchPtr moduleLoaderFetch;
209
210     typedef JSObject* (*ModuleLoaderCreateImportMetaPropertiesPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
211     ModuleLoaderCreateImportMetaPropertiesPtr moduleLoaderCreateImportMetaProperties;
212
213     typedef JSValue (*ModuleLoaderEvaluatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
214     ModuleLoaderEvaluatePtr moduleLoaderEvaluate;
215
216     typedef void (*PromiseRejectionTrackerPtr)(JSGlobalObject*, ExecState*, JSPromise*, JSPromiseRejectionOperation);
217     PromiseRejectionTrackerPtr promiseRejectionTracker;
218
219     typedef String (*DefaultLanguageFunctionPtr)();
220     DefaultLanguageFunctionPtr defaultLanguage;
221
222     typedef void (*CompileStreamingPtr)(JSGlobalObject*, ExecState*, JSPromiseDeferred*, JSValue);
223     CompileStreamingPtr compileStreaming;
224
225     typedef void (*InstantiateStreamingPtr)(JSGlobalObject*, ExecState*, JSPromiseDeferred*, JSValue, JSObject*);
226     InstantiateStreamingPtr instantiateStreaming;
227 };
228
229 class JSGlobalObject : public JSSegmentedVariableObject {
230 private:
231     typedef HashSet<RefPtr<OpaqueJSWeakObjectMap>> WeakMapSet;
232     typedef HashMap<OpaqueJSClass*, std::unique_ptr<OpaqueJSClassContextData>> OpaqueJSClassDataMap;
233
234     struct JSGlobalObjectRareData {
235         WTF_MAKE_FAST_ALLOCATED;
236     public:
237         JSGlobalObjectRareData()
238             : profileGroup(0)
239         {
240         }
241
242         WeakMapSet weakMaps;
243         unsigned profileGroup;
244         
245         OpaqueJSClassDataMap opaqueJSClassData;
246     };
247
248 // Our hashtable code-generator tries to access these properties, so we make them public.
249 // However, we'd like it better if they could be protected.
250 public:
251     template<typename T> using Initializer = typename LazyProperty<JSGlobalObject, T>::Initializer;
252     
253     Register m_globalCallFrame[CallFrame::headerSizeInRegisters];
254
255     WriteBarrier<JSObject> m_globalThis;
256
257     WriteBarrier<JSGlobalLexicalEnvironment> m_globalLexicalEnvironment;
258     WriteBarrier<JSScope> m_globalScopeExtension;
259     WriteBarrier<JSCallee> m_globalCallee;
260     WriteBarrier<JSCallee> m_stackOverflowFrameCallee;
261     WriteBarrier<RegExpConstructor> m_regExpConstructor;
262     WriteBarrier<ErrorConstructor> m_errorConstructor;
263     WriteBarrier<Structure> m_nativeErrorPrototypeStructure;
264     WriteBarrier<Structure> m_nativeErrorStructure;
265     LazyProperty<JSGlobalObject, NativeErrorConstructor> m_evalErrorConstructor;
266     WriteBarrier<NativeErrorConstructor> m_rangeErrorConstructor;
267     LazyProperty<JSGlobalObject, NativeErrorConstructor> m_referenceErrorConstructor;
268     LazyProperty<JSGlobalObject, NativeErrorConstructor> m_syntaxErrorConstructor;
269     WriteBarrier<NativeErrorConstructor> m_typeErrorConstructor;
270     LazyProperty<JSGlobalObject, NativeErrorConstructor> m_URIErrorConstructor;
271     WriteBarrier<ObjectConstructor> m_objectConstructor;
272     WriteBarrier<ArrayConstructor> m_arrayConstructor;
273     WriteBarrier<JSPromiseConstructor> m_promiseConstructor;
274     WriteBarrier<JSInternalPromiseConstructor> m_internalPromiseConstructor;
275
276 #if ENABLE(INTL)
277     WriteBarrier<IntlObject> m_intlObject;
278 #endif
279     WriteBarrier<NullGetterFunction> m_nullGetterFunction;
280     WriteBarrier<NullSetterFunction> m_nullSetterFunction;
281
282     WriteBarrier<JSFunction> m_parseIntFunction;
283     WriteBarrier<JSFunction> m_parseFloatFunction;
284
285     WriteBarrier<JSFunction> m_evalFunction;
286     WriteBarrier<JSFunction> m_callFunction;
287     WriteBarrier<JSFunction> m_applyFunction;
288     WriteBarrier<JSFunction> m_throwTypeErrorFunction;
289     LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoToStringFunction;
290     LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction;
291     LazyProperty<JSGlobalObject, JSFunction> m_initializePromiseFunction;
292     LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction;
293     LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction;
294     WriteBarrier<JSFunction> m_objectProtoValueOfFunction;
295     WriteBarrier<JSFunction> m_numberProtoToStringFunction;
296     WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
297     WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction;
298     LazyProperty<JSGlobalObject, GetterSetter> m_throwTypeErrorGetterSetter;
299     WriteBarrier<JSObject> m_regExpProtoExec;
300     WriteBarrier<JSObject> m_regExpProtoSymbolReplace;
301     WriteBarrier<JSObject> m_regExpProtoGlobalGetter;
302     WriteBarrier<JSObject> m_regExpProtoUnicodeGetter;
303     WriteBarrier<GetterSetter> m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter;
304
305     LazyProperty<JSGlobalObject, JSModuleLoader> m_moduleLoader;
306
307     WriteBarrier<ObjectPrototype> m_objectPrototype;
308     WriteBarrier<FunctionPrototype> m_functionPrototype;
309     WriteBarrier<ArrayPrototype> m_arrayPrototype;
310     WriteBarrier<RegExpPrototype> m_regExpPrototype;
311     WriteBarrier<IteratorPrototype> m_iteratorPrototype;
312     WriteBarrier<AsyncIteratorPrototype> m_asyncIteratorPrototype;
313     WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype;
314     WriteBarrier<GeneratorPrototype> m_generatorPrototype;
315     WriteBarrier<AsyncGeneratorPrototype> m_asyncGeneratorPrototype;
316
317     LazyProperty<JSGlobalObject, Structure> m_debuggerScopeStructure;
318     LazyProperty<JSGlobalObject, Structure> m_withScopeStructure;
319     WriteBarrier<Structure> m_strictEvalActivationStructure;
320     WriteBarrier<Structure> m_lexicalEnvironmentStructure;
321     LazyProperty<JSGlobalObject, Structure> m_moduleEnvironmentStructure;
322     WriteBarrier<Structure> m_directArgumentsStructure;
323     WriteBarrier<Structure> m_scopedArgumentsStructure;
324     WriteBarrier<Structure> m_clonedArgumentsStructure;
325
326     WriteBarrier<Structure> m_objectStructureForObjectConstructor;
327         
328     // Lists the actual structures used for having these particular indexing shapes.
329     WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfArrayIndexingModes];
330     // Lists the structures we should use during allocation for these particular indexing shapes.
331     // These structures will differ from the originals list above when we are having a bad time.
332     WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfArrayIndexingModes];
333
334     LazyProperty<JSGlobalObject, Structure> m_callbackConstructorStructure;
335     LazyProperty<JSGlobalObject, Structure> m_callbackFunctionStructure;
336     LazyProperty<JSGlobalObject, Structure> m_callbackObjectStructure;
337     WriteBarrier<Structure> m_propertyNameIteratorStructure;
338 #if JSC_OBJC_API_ENABLED
339     LazyProperty<JSGlobalObject, Structure> m_objcCallbackFunctionStructure;
340     LazyProperty<JSGlobalObject, Structure> m_objcWrapperObjectStructure;
341 #endif
342 #ifdef JSC_GLIB_API_ENABLED
343     LazyProperty<JSGlobalObject, Structure> m_glibCallbackFunctionStructure;
344     LazyProperty<JSGlobalObject, Structure> m_glibWrapperObjectStructure;
345 #endif
346     WriteBarrier<Structure> m_nullPrototypeObjectStructure;
347     WriteBarrier<Structure> m_calleeStructure;
348
349     WriteBarrier<Structure> m_hostFunctionStructure;
350
351     struct FunctionStructures {
352         WriteBarrier<Structure> arrowFunctionStructure;
353         WriteBarrier<Structure> sloppyFunctionStructure;
354         WriteBarrier<Structure> strictFunctionStructure;
355     };
356     FunctionStructures m_builtinFunctions;
357     FunctionStructures m_ordinaryFunctions;
358
359     LazyProperty<JSGlobalObject, Structure> m_boundFunctionStructure;
360     LazyProperty<JSGlobalObject, Structure> m_customGetterSetterFunctionStructure;
361     WriteBarrier<Structure> m_getterSetterStructure;
362     LazyProperty<JSGlobalObject, Structure> m_nativeStdFunctionStructure;
363     PropertyOffset m_functionNameOffset;
364     WriteBarrier<Structure> m_regExpStructure;
365     WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype;
366     WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype;
367     WriteBarrier<Structure> m_asyncFunctionStructure;
368     WriteBarrier<Structure> m_asyncGeneratorFunctionStructure;
369     WriteBarrier<Structure> m_generatorFunctionStructure;
370     WriteBarrier<Structure> m_iteratorResultObjectStructure;
371     WriteBarrier<Structure> m_regExpMatchesArrayStructure;
372     WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure;
373     WriteBarrier<Structure> m_moduleRecordStructure;
374     WriteBarrier<Structure> m_moduleNamespaceObjectStructure;
375     WriteBarrier<Structure> m_proxyObjectStructure;
376     WriteBarrier<Structure> m_callableProxyObjectStructure;
377     WriteBarrier<Structure> m_proxyRevokeStructure;
378     WriteBarrier<JSArrayBufferPrototype> m_arrayBufferPrototype;
379     WriteBarrier<Structure> m_arrayBufferStructure;
380 #if ENABLE(SHARED_ARRAY_BUFFER)
381     WriteBarrier<JSArrayBufferPrototype> m_sharedArrayBufferPrototype;
382     WriteBarrier<Structure> m_sharedArrayBufferStructure;
383 #endif
384
385 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
386     WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
387     WriteBarrier<Structure> m_ ## properName ## Structure;
388
389     FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
390     FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
391     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
392     
393 #if ENABLE(WEBASSEMBLY)
394     WriteBarrier<Structure> m_webAssemblyStructure;
395     WriteBarrier<Structure> m_webAssemblyModuleRecordStructure;
396     WriteBarrier<Structure> m_webAssemblyFunctionStructure;
397     WriteBarrier<Structure> m_webAssemblyWrapperFunctionStructure;
398     WriteBarrier<Structure> m_webAssemblyToJSCalleeStructure;
399     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
400 #endif // ENABLE(WEBASSEMBLY)
401
402 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
403
404 #define DEFINE_STORAGE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
405     LazyClassStructure m_ ## properName ## Structure;
406     FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE)
407 #undef DEFINE_STORAGE_FOR_LAZY_TYPE
408
409     WriteBarrier<GetterSetter> m_speciesGetterSetter;
410     
411     LazyProperty<JSGlobalObject, JSTypedArrayViewPrototype> m_typedArrayProto;
412     LazyProperty<JSGlobalObject, JSTypedArrayViewConstructor> m_typedArraySuperConstructor;
413     
414 #define DECLARE_TYPED_ARRAY_TYPE_STRUCTURE(name) LazyClassStructure m_typedArray ## name;
415     FOR_EACH_TYPED_ARRAY_TYPE(DECLARE_TYPED_ARRAY_TYPE_STRUCTURE)
416 #undef DECLARE_TYPED_ARRAY_TYPE_STRUCTURE
417
418     JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
419     JSCell* m_linkTimeConstants[LinkTimeConstantCount];
420
421     String m_name;
422
423     Debugger* m_debugger;
424
425     VM& m_vm;
426
427     template<typename T> using PoisonedUniquePtr = WTF::PoisonedUniquePtr<JSGlobalObjectPoison, T>;
428
429 #if ENABLE(REMOTE_INSPECTOR)
430     PoisonedUniquePtr<Inspector::JSGlobalObjectInspectorController> m_inspectorController;
431     PoisonedUniquePtr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
432 #endif
433
434 #if ENABLE(INTL)
435     HashSet<String> m_intlCollatorAvailableLocales;
436     HashSet<String> m_intlDateTimeFormatAvailableLocales;
437     HashSet<String> m_intlNumberFormatAvailableLocales;
438     HashSet<String> m_intlPluralRulesAvailableLocales;
439 #endif // ENABLE(INTL)
440
441     RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
442     RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
443     RefPtr<WatchpointSet> m_varInjectionWatchpoint;
444
445     std::unique_ptr<JSGlobalObjectRareData> m_rareData;
446
447     WeakRandom m_weakRandom;
448
449     JSCallee* stackOverflowFrameCallee() const { return m_stackOverflowFrameCallee.get(); }
450
451     InlineWatchpointSet& arrayIteratorProtocolWatchpoint() { return m_arrayIteratorProtocolWatchpoint; }
452     InlineWatchpointSet& mapIteratorProtocolWatchpoint() { return m_mapIteratorProtocolWatchpoint; }
453     InlineWatchpointSet& setIteratorProtocolWatchpoint() { return m_setIteratorProtocolWatchpoint; }
454     InlineWatchpointSet& stringIteratorProtocolWatchpoint() { return m_stringIteratorProtocolWatchpoint; }
455     InlineWatchpointSet& mapSetWatchpoint() { return m_mapSetWatchpoint; }
456     InlineWatchpointSet& setAddWatchpoint() { return m_setAddWatchpoint; }
457     InlineWatchpointSet& arraySpeciesWatchpoint() { return m_arraySpeciesWatchpoint; }
458     InlineWatchpointSet& numberToStringWatchpoint() { return m_numberToStringWatchpoint; }
459     // If this hasn't been invalidated, it means the array iterator protocol
460     // is not observable to user code yet.
461     InlineWatchpointSet m_arrayIteratorProtocolWatchpoint;
462     InlineWatchpointSet m_mapIteratorProtocolWatchpoint;
463     InlineWatchpointSet m_setIteratorProtocolWatchpoint;
464     InlineWatchpointSet m_stringIteratorProtocolWatchpoint;
465     InlineWatchpointSet m_mapSetWatchpoint;
466     InlineWatchpointSet m_setAddWatchpoint;
467     InlineWatchpointSet m_arraySpeciesWatchpoint;
468     InlineWatchpointSet m_numberToStringWatchpoint;
469     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeSymbolIteratorWatchpoint;
470     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayIteratorPrototypeNext;
471     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSymbolIteratorWatchpoint;
472     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapIteratorPrototypeNextWatchpoint;
473     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeSymbolIteratorWatchpoint;
474     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setIteratorPrototypeNextWatchpoint;
475     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringPrototypeSymbolIteratorWatchpoint;
476     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringIteratorPrototypeNextWatchpoint;
477     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSetWatchpoint;
478     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeAddWatchpoint;
479     PoisonedUniquePtr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_numberPrototypeToStringWatchpoint;
480
481     bool isArrayPrototypeIteratorProtocolFastAndNonObservable();
482     bool isMapPrototypeIteratorProtocolFastAndNonObservable();
483     bool isSetPrototypeIteratorProtocolFastAndNonObservable();
484     bool isStringPrototypeIteratorProtocolFastAndNonObservable();
485     bool isMapPrototypeSetFastAndNonObservable();
486     bool isSetPrototypeAddFastAndNonObservable();
487
488 #if ENABLE(DFG_JIT)
489     using ReferencedGlobalPropertyWatchpointSets = HashMap<RefPtr<UniquedStringImpl>, Ref<WatchpointSet>, IdentifierRepHash>;
490     ReferencedGlobalPropertyWatchpointSets m_referencedGlobalPropertyWatchpointSets;
491     ConcurrentJSLock m_referencedGlobalPropertyWatchpointSetsLock;
492 #endif
493
494     bool m_evalEnabled { true };
495     bool m_webAssemblyEnabled { true };
496     unsigned m_globalLexicalBindingEpoch { 1 };
497     String m_evalDisabledErrorMessage;
498     String m_webAssemblyDisabledErrorMessage;
499     RuntimeFlags m_runtimeFlags;
500     ConsoleClient* m_consoleClient { nullptr };
501
502 #if !ASSERT_DISABLED
503     const ExecState* m_callFrameAtDebuggerEntry { nullptr };
504 #endif
505
506     static JS_EXPORT_PRIVATE const GlobalObjectMethodTable s_globalObjectMethodTable;
507     const GlobalObjectMethodTable* m_globalObjectMethodTable;
508
509     void createRareDataIfNeeded()
510     {
511         if (m_rareData)
512             return;
513         m_rareData = std::make_unique<JSGlobalObjectRareData>();
514     }
515         
516 public:
517     typedef JSSegmentedVariableObject Base;
518     static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | IsImmutablePrototypeExoticObject;
519
520     JS_EXPORT_PRIVATE static JSGlobalObject* create(VM&, Structure*);
521
522     DECLARE_EXPORT_INFO;
523
524     bool hasDebugger() const;
525     bool hasInteractiveDebugger() const;
526     const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; }
527
528 #if ENABLE(DFG_JIT)
529     WatchpointSet* getReferencedPropertyWatchpointSet(UniquedStringImpl*);
530     WatchpointSet& ensureReferencedPropertyWatchpointSet(UniquedStringImpl*);
531 #endif
532
533 protected:
534     JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = nullptr);
535
536     JS_EXPORT_PRIVATE void finishCreation(VM&);
537
538     JS_EXPORT_PRIVATE void finishCreation(VM&, JSObject*);
539
540     void addGlobalVar(const Identifier&);
541
542 public:
543     JS_EXPORT_PRIVATE ~JSGlobalObject();
544     JS_EXPORT_PRIVATE static void destroy(JSCell*);
545
546     JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
547
548     JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
549     JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
550
551     JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
552     JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
553     JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
554
555     void addVar(ExecState* exec, const Identifier& propertyName)
556     {
557         if (!hasOwnProperty(exec, propertyName))
558             addGlobalVar(propertyName);
559     }
560     void addFunction(ExecState*, const Identifier&);
561
562     JSScope* globalScope() { return m_globalLexicalEnvironment.get(); }
563     JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); }
564
565     JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); }
566     void setGlobalScopeExtension(JSScope*);
567     void clearGlobalScopeExtension();
568
569     // The following accessors return pristine values, even if a script 
570     // replaces the global object's associated property.
571
572     GetterSetter* speciesGetterSetter() const { return m_speciesGetterSetter.get(); }
573
574     RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); }
575
576     ErrorConstructor* errorConstructor() const { return m_errorConstructor.get(); }
577     ArrayConstructor* arrayConstructor() const { return m_arrayConstructor.get(); }
578     ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); }
579     JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); }
580     JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); }
581     NativeErrorConstructor* evalErrorConstructor() const { return m_evalErrorConstructor.get(this); }
582     NativeErrorConstructor* rangeErrorConstructor() const { return m_rangeErrorConstructor.get(); }
583     NativeErrorConstructor* referenceErrorConstructor() const { return m_referenceErrorConstructor.get(this); }
584     NativeErrorConstructor* syntaxErrorConstructor() const { return m_syntaxErrorConstructor.get(this); }
585     NativeErrorConstructor* typeErrorConstructor() const { return m_typeErrorConstructor.get(); }
586     NativeErrorConstructor* URIErrorConstructor() const { return m_URIErrorConstructor.get(this); }
587
588 #if ENABLE(INTL)
589     IntlObject* intlObject() const { return m_intlObject.get(); }
590 #endif
591
592     NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
593     NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
594
595     JSFunction* parseIntFunction() const { return m_parseIntFunction.get(); }
596     JSFunction* parseFloatFunction() const { return m_parseFloatFunction.get(); }
597
598     JSFunction* evalFunction() const { return m_evalFunction.get(); }
599     JSFunction* callFunction() const { return m_callFunction.get(); }
600     JSFunction* applyFunction() const { return m_applyFunction.get(); }
601     JSFunction* throwTypeErrorFunction() const { return m_throwTypeErrorFunction.get(); }
602     JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); }
603     JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
604     JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(this); }
605     JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); }
606     JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); }
607     JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); }
608     JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.get(); }
609     JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
610     JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
611     JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); }
612     JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); }
613     JSObject* regExpProtoGlobalGetter() const { return m_regExpProtoGlobalGetter.get(); }
614     JSObject* regExpProtoUnicodeGetter() const { return m_regExpProtoUnicodeGetter.get(); }
615     GetterSetter* throwTypeErrorArgumentsCalleeAndCallerGetterSetter()
616     {
617         return m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.get();
618     }
619     
620     JSModuleLoader* moduleLoader() const { return m_moduleLoader.get(this); }
621
622     ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
623     FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
624     ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
625     BooleanPrototype* booleanPrototype() const { return m_booleanPrototype.get(); }
626     StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
627     SymbolPrototype* symbolPrototype() const { return m_symbolPrototype.get(); }
628     NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
629     BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); }
630     JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
631     RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
632     ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
633     IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
634     AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); }
635     GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
636     GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); }
637     AsyncFunctionPrototype* asyncFunctionPrototype() const { return m_asyncFunctionPrototype.get(); }
638     MapPrototype* mapPrototype() const { return m_mapPrototype.get(); }
639     // Workaround for the name conflict between JSCell::setPrototype.
640     SetPrototype* jsSetPrototype() const { return m_setPrototype.get(); }
641     JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); }
642     AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); }
643     AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); }
644
645     Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); }
646     Structure* withScopeStructure() const { return m_withScopeStructure.get(this); }
647     Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(); }
648     Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); }
649     Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(this); }
650     Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); }
651     Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); }
652     Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); }
653     Structure* objectStructureForObjectConstructor() const { return m_objectStructureForObjectConstructor.get(); }
654     Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
655     {
656         ASSERT(indexingType & IsArray);
657         return m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(indexingType)].get();
658     }
659     Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
660     {
661         ASSERT(indexingType & IsArray);
662         return m_arrayStructureForIndexingShapeDuringAllocation[arrayIndexFromIndexingType(indexingType)].get();
663     }
664     Structure* arrayStructureForIndexingTypeDuringAllocation(ExecState* exec, IndexingType indexingType, JSValue newTarget) const
665     {
666         return InternalFunction::createSubclassStructure(exec, newTarget, arrayStructureForIndexingTypeDuringAllocation(indexingType));
667     }
668     Structure* arrayStructureForProfileDuringAllocation(ExecState* exec, ArrayAllocationProfile* profile, JSValue newTarget) const
669     {
670         return arrayStructureForIndexingTypeDuringAllocation(exec, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget);
671     }
672         
673     bool isOriginalArrayStructure(Structure* structure)
674     {
675         return originalArrayStructureForIndexingType(structure->indexingMode() | IsArray) == structure;
676     }
677         
678     Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(); }
679     Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(this); }
680     Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(this); }
681     Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(this); }
682     Structure* propertyNameIteratorStructure() const { return m_propertyNameIteratorStructure.get(); }
683 #if JSC_OBJC_API_ENABLED
684     Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(this); }
685     Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(this); }
686 #endif
687 #ifdef JSC_GLIB_API_ENABLED
688     Structure* glibCallbackFunctionStructure() const { return m_glibCallbackFunctionStructure.get(this); }
689     Structure* glibWrapperObjectStructure() const { return m_glibWrapperObjectStructure.get(this); }
690 #endif
691     Structure* dateStructure() const { return m_dateStructure.get(this); }
692     Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
693     Structure* errorStructure() const { return m_errorStructure.get(); }
694     Structure* calleeStructure() const { return m_calleeStructure.get(); }
695     Structure* hostFunctionStructure() const { return m_hostFunctionStructure.get(); }
696
697     Structure* arrowFunctionStructure(bool isBuiltin) const
698     {
699         if (isBuiltin)
700             return m_builtinFunctions.arrowFunctionStructure.get();
701         return m_ordinaryFunctions.arrowFunctionStructure.get();
702     }
703     Structure* sloppyFunctionStructure(bool isBuiltin) const
704     {
705         if (isBuiltin)
706             return m_builtinFunctions.sloppyFunctionStructure.get();
707         return m_ordinaryFunctions.sloppyFunctionStructure.get();
708     }
709     Structure* strictFunctionStructure(bool isBuiltin) const
710     {
711         if (isBuiltin)
712             return m_builtinFunctions.strictFunctionStructure.get();
713         return m_ordinaryFunctions.strictFunctionStructure.get();
714     }
715
716     Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(this); }
717     Structure* customGetterSetterFunctionStructure() const { return m_customGetterSetterFunctionStructure.get(this); }
718     Structure* getterSetterStructure() const { return m_getterSetterStructure.get(); }
719     Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(this); }
720     PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
721     Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
722     Structure* mapStructure() const { return m_mapStructure.get(); }
723     Structure* regExpStructure() const { return m_regExpStructure.get(); }
724     Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); }
725     Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); }
726     Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); }
727     Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
728     Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
729     Structure* bigIntObjectStructure() const { return m_bigIntObjectStructure.get(); }
730     Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(); }
731     Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
732     Structure* regExpMatchesArrayWithGroupsStructure() const { return m_regExpMatchesArrayWithGroupsStructure.get(); }
733     Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(); }
734     Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(); }
735     Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(); }
736     Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(); }
737     Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(); }
738     Structure* restParameterStructure() const { return arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); }
739     Structure* originalRestParameterStructure() const { return originalArrayStructureForIndexingType(ArrayWithContiguous); }
740 #if ENABLE(WEBASSEMBLY)
741     Structure* webAssemblyModuleRecordStructure() const { return m_webAssemblyModuleRecordStructure.get(); }
742     Structure* webAssemblyFunctionStructure() const { return m_webAssemblyFunctionStructure.get(); }
743     Structure* webAssemblyWrapperFunctionStructure() const { return m_webAssemblyWrapperFunctionStructure.get(); }
744     Structure* webAssemblyToJSCalleeStructure() const { return m_webAssemblyToJSCalleeStructure.get(); }
745 #endif // ENABLE(WEBASSEMBLY)
746
747     JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
748     JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
749
750 #if ENABLE(REMOTE_INSPECTOR)
751     Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); }
752     JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
753 #endif
754
755 #if ENABLE(INTL)
756     const HashSet<String>& intlCollatorAvailableLocales();
757     const HashSet<String>& intlDateTimeFormatAvailableLocales();
758     const HashSet<String>& intlNumberFormatAvailableLocales();
759     const HashSet<String>& intlPluralRulesAvailableLocales();
760 #endif // ENABLE(INTL)
761
762     void bumpGlobalLexicalBindingEpoch(VM&);
763     unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; }
764     static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); }
765     unsigned* addressOfGlobalLexicalBindingEpoch() { return &m_globalLexicalBindingEpoch; }
766
767     void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
768     ConsoleClient* consoleClient() const { return m_consoleClient; }
769
770     void setName(const String&);
771     const String& name() const { return m_name; }
772
773     JSArrayBufferPrototype* arrayBufferPrototype(ArrayBufferSharingMode sharingMode) const
774     {
775         switch (sharingMode) {
776         case ArrayBufferSharingMode::Default:
777             return m_arrayBufferPrototype.get();
778 #if ENABLE(SHARED_ARRAY_BUFFER)
779         case ArrayBufferSharingMode::Shared:
780             return m_sharedArrayBufferPrototype.get();
781 #else
782         default:
783             return m_arrayBufferPrototype.get();
784 #endif
785         }
786     }
787     Structure* arrayBufferStructure(ArrayBufferSharingMode sharingMode) const
788     {
789         switch (sharingMode) {
790         case ArrayBufferSharingMode::Default:
791             return m_arrayBufferStructure.get();
792 #if ENABLE(SHARED_ARRAY_BUFFER)
793         case ArrayBufferSharingMode::Shared:
794             return m_sharedArrayBufferStructure.get();
795 #else
796         default:
797             return m_arrayBufferStructure.get();
798 #endif
799         }
800         RELEASE_ASSERT_NOT_REACHED();
801         return nullptr;
802     }
803
804 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
805     Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
806
807     FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
808     FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
809     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
810     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
811
812 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
813
814 #define DEFINE_ACCESSORS_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
815     Structure* properName ## Structure() { return m_ ## properName ## Structure.get(this); }
816
817     FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE)
818
819 #undef DEFINE_ACCESSORS_FOR_LAZY_TYPE
820
821     LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type)
822     {
823         switch (type) {
824         case NotTypedArray:
825             RELEASE_ASSERT_NOT_REACHED();
826             return m_typedArrayInt8;
827 #define TYPED_ARRAY_TYPE_CASE(name) case Type ## name: return m_typedArray ## name;
828             FOR_EACH_TYPED_ARRAY_TYPE(TYPED_ARRAY_TYPE_CASE)
829 #undef TYPED_ARRAY_TYPE_CASE
830         }
831         RELEASE_ASSERT_NOT_REACHED();
832         return m_typedArrayInt8;
833     }
834     const LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) const
835     {
836         return const_cast<const LazyClassStructure&>(const_cast<JSGlobalObject*>(this)->lazyTypedArrayStructure(type));
837     }
838     
839     Structure* typedArrayStructure(TypedArrayType type) const
840     {
841         return lazyTypedArrayStructure(type).get(this);
842     }
843     Structure* typedArrayStructureConcurrently(TypedArrayType type) const
844     {
845         return lazyTypedArrayStructure(type).getConcurrently();
846     }
847     bool isOriginalTypedArrayStructure(Structure* structure)
848     {
849         TypedArrayType type = structure->classInfo()->typedArrayStorageType;
850         if (type == NotTypedArray)
851             return false;
852         return typedArrayStructureConcurrently(type) == structure;
853     }
854
855     JSObject* typedArrayConstructor(TypedArrayType type) const
856     {
857         return lazyTypedArrayStructure(type).constructor(this);
858     }
859
860     JSCell* actualPointerFor(Special::Pointer pointer)
861     {
862         ASSERT(pointer < Special::TableSize);
863         return m_specialPointers[pointer];
864     }
865     JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type)
866     {
867         unsigned index = static_cast<unsigned>(type);
868         ASSERT(index < LinkTimeConstantCount);
869         return m_linkTimeConstants[index];
870     }
871
872     WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
873     WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
874     WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); }
875         
876     bool isHavingABadTime() const
877     {
878         return m_havingABadTimeWatchpoint->hasBeenInvalidated();
879     }
880         
881     void haveABadTime(VM&);
882         
883     bool objectPrototypeIsSane();
884     bool arrayPrototypeChainIsSane();
885     bool stringPrototypeChainIsSane();
886
887     void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
888     unsigned profileGroup() const
889     { 
890         if (!m_rareData)
891             return 0;
892         return m_rareData->profileGroup;
893     }
894
895     Debugger* debugger() const { return m_debugger; }
896     void setDebugger(Debugger* debugger) { m_debugger = debugger; }
897
898     const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
899
900     static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
901
902     JS_EXPORT_PRIVATE ExecState* globalExec();
903
904     static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
905     static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
906     static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
907
908     JS_EXPORT_PRIVATE void queueMicrotask(Ref<Microtask>&&);
909
910     bool evalEnabled() const { return m_evalEnabled; }
911     bool webAssemblyEnabled() const { return m_webAssemblyEnabled; }
912     const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
913     const String& webAssemblyDisabledErrorMessage() const { return m_webAssemblyDisabledErrorMessage; }
914     void setEvalEnabled(bool enabled, const String& errorMessage = String())
915     {
916         m_evalEnabled = enabled;
917         m_evalDisabledErrorMessage = errorMessage;
918     }
919     void setWebAssemblyEnabled(bool enabled, const String& errorMessage = String())
920     {
921         m_webAssemblyEnabled = enabled;
922         m_webAssemblyDisabledErrorMessage = errorMessage;
923     }
924
925 #if !ASSERT_DISABLED
926     const ExecState* callFrameAtDebuggerEntry() const { return m_callFrameAtDebuggerEntry; }
927     void setCallFrameAtDebuggerEntry(const ExecState* callFrame) { m_callFrameAtDebuggerEntry = callFrame; }
928 #endif
929
930     void resetPrototype(VM&, JSValue prototype);
931
932     VM& vm() const { return m_vm; }
933     JSObject* globalThis() const;
934     WriteBarrier<JSObject>* addressOfGlobalThis() { return &m_globalThis; }
935
936     static Structure* createStructure(VM& vm, JSValue prototype)
937     {
938         Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
939         result->setTransitionWatchpointIsLikelyToBeFired(true);
940         return result;
941     }
942
943     void registerWeakMap(OpaqueJSWeakObjectMap* map)
944     {
945         createRareDataIfNeeded();
946         m_rareData->weakMaps.add(map);
947     }
948
949     void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
950     {
951         if (m_rareData)
952             m_rareData->weakMaps.remove(map);
953     }
954
955     OpaqueJSClassDataMap& opaqueJSClassData()
956     {
957         createRareDataIfNeeded();
958         return m_rareData->opaqueJSClassData;
959     }
960
961     static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); }
962     double weakRandomNumber() { return m_weakRandom.get(); }
963     unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
964     WeakRandom& weakRandom() { return m_weakRandom; }
965
966     bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
967     JS_EXPORT_PRIVATE void exposeDollarVM(VM&);
968
969 #if JSC_OBJC_API_ENABLED
970     JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
971     void setWrapperMap(JSWrapperMap* map) { m_wrapperMap = map; }
972 #endif
973 #ifdef JSC_GLIB_API_ENABLED
974     WrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
975     void setWrapperMap(std::unique_ptr<WrapperMap>&&);
976 #endif
977
978 protected:
979     struct GlobalPropertyInfo {
980         GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
981             : identifier(i)
982             , value(v)
983             , attributes(a)
984         {
985         }
986
987         const Identifier identifier;
988         JSValue value;
989         unsigned attributes;
990     };
991     JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
992
993     void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; }
994
995 private:
996     friend class LLIntOffsetsExtractor;
997
998     void fireWatchpointAndMakeAllArrayStructuresSlowPut(VM&);
999     void setGlobalThis(VM&, JSObject* globalThis);
1000
1001     JS_EXPORT_PRIVATE void init(VM&);
1002
1003     JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
1004
1005     bool m_needsSiteSpecificQuirks { false };
1006 #if JSC_OBJC_API_ENABLED
1007     RetainPtr<JSWrapperMap> m_wrapperMap;
1008 #endif
1009 #ifdef JSC_GLIB_API_ENABLED
1010     std::unique_ptr<WrapperMap> m_wrapperMap;
1011 #endif
1012 };
1013
1014 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0, JSValue newTarget = JSValue())
1015 {
1016     VM& vm = globalObject->vm();
1017     auto scope = DECLARE_THROW_SCOPE(vm);
1018     Structure* structure;
1019     if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)
1020         structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(exec, ArrayWithArrayStorage, newTarget);
1021     else
1022         structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1023     RETURN_IF_EXCEPTION(scope, nullptr);
1024
1025     JSArray* result = JSArray::tryCreate(vm, structure, initialLength);
1026     if (UNLIKELY(!result)) {
1027         throwOutOfMemoryError(exec, scope);
1028         return nullptr;
1029     }
1030     return ArrayAllocationProfile::updateLastAllocationFor(profile, result);
1031 }
1032
1033 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue())
1034 {
1035     return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength, newTarget);
1036 }
1037  
1038 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values, JSValue newTarget = JSValue())
1039 {
1040     VM& vm = globalObject->vm();
1041     auto scope = DECLARE_THROW_SCOPE(vm);
1042     Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1043     RETURN_IF_EXCEPTION(scope, nullptr);
1044     return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values));
1045 }
1046
1047 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue())
1048 {
1049     return constructArray(exec, profile, exec->lexicalGlobalObject(), values, newTarget);
1050 }
1051
1052 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1053 {
1054     VM& vm = globalObject->vm();
1055     auto scope = DECLARE_THROW_SCOPE(vm);
1056     Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1057     RETURN_IF_EXCEPTION(scope, nullptr);
1058     return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values, length));
1059 }
1060
1061 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1062 {
1063     return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
1064 }
1065
1066 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1067 {
1068     VM& vm = globalObject->vm();
1069     auto scope = DECLARE_THROW_SCOPE(vm);
1070     Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1071     RETURN_IF_EXCEPTION(scope, nullptr);
1072     return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, structure, values, length));
1073 }
1074
1075 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1076 {
1077     return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
1078 }
1079
1080 inline JSObject* ExecState::globalThisValue() const
1081 {
1082     return lexicalGlobalObject()->globalThis();
1083 }
1084
1085 inline JSObject* JSScope::globalThis()
1086
1087     return globalObject()->globalThis();
1088 }
1089
1090 inline JSObject* JSGlobalObject::globalThis() const
1091
1092     return m_globalThis.get();
1093 }
1094
1095 } // namespace JSC