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