[JSC] GetterSetter should be JSCell, not JSObject
[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<GetterSetter> m_regExpProtoGlobalGetter;
310     WriteBarrier<GetterSetter> 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     LazyProperty<JSGlobalObject, Structure> m_nativeStdFunctionStructure;
369     PropertyOffset m_functionNameOffset;
370     WriteBarrier<Structure> m_regExpStructure;
371     WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype;
372     WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype;
373     WriteBarrier<Structure> m_asyncFunctionStructure;
374     WriteBarrier<Structure> m_asyncGeneratorFunctionStructure;
375     WriteBarrier<Structure> m_generatorFunctionStructure;
376     WriteBarrier<Structure> m_generatorStructure;
377     WriteBarrier<Structure> m_asyncGeneratorStructure;
378     LazyProperty<JSGlobalObject, Structure> m_iteratorResultObjectStructure;
379     WriteBarrier<Structure> m_regExpMatchesArrayStructure;
380     WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure;
381     LazyProperty<JSGlobalObject, Structure> m_moduleRecordStructure;
382     LazyProperty<JSGlobalObject, Structure> m_moduleNamespaceObjectStructure;
383     LazyProperty<JSGlobalObject, Structure> m_proxyObjectStructure;
384     LazyProperty<JSGlobalObject, Structure> m_callableProxyObjectStructure;
385     LazyProperty<JSGlobalObject, Structure> m_proxyRevokeStructure;
386 #if ENABLE(SHARED_ARRAY_BUFFER)
387     WriteBarrier<JSArrayBufferPrototype> m_sharedArrayBufferPrototype;
388     WriteBarrier<Structure> m_sharedArrayBufferStructure;
389 #endif
390
391 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
392     WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
393     WriteBarrier<Structure> m_ ## properName ## Structure;
394
395 #define DEFINE_STORAGE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
396     LazyClassStructure m_ ## properName ## Structure;
397
398     FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
399     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
400     
401 #if ENABLE(WEBASSEMBLY)
402     LazyProperty<JSGlobalObject, Structure> m_webAssemblyModuleRecordStructure;
403     LazyProperty<JSGlobalObject, Structure> m_webAssemblyFunctionStructure;
404     LazyProperty<JSGlobalObject, Structure> m_jsToWasmICCalleeStructure;
405     LazyProperty<JSGlobalObject, Structure> m_webAssemblyWrapperFunctionStructure;
406     LazyProperty<JSGlobalObject, Structure> m_webAssemblyToJSCalleeStructure;
407     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE)
408 #endif // ENABLE(WEBASSEMBLY)
409
410     FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE)
411
412 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
413 #undef DEFINE_STORAGE_FOR_LAZY_TYPE
414
415     WriteBarrier<GetterSetter> m_speciesGetterSetter;
416     
417     LazyProperty<JSGlobalObject, JSTypedArrayViewPrototype> m_typedArrayProto;
418     LazyProperty<JSGlobalObject, JSTypedArrayViewConstructor> m_typedArraySuperConstructor;
419     
420 #define DECLARE_TYPED_ARRAY_TYPE_STRUCTURE(name) LazyClassStructure m_typedArray ## name;
421     FOR_EACH_TYPED_ARRAY_TYPE(DECLARE_TYPED_ARRAY_TYPE_STRUCTURE)
422 #undef DECLARE_TYPED_ARRAY_TYPE_STRUCTURE
423
424     JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
425     JSCell* m_linkTimeConstants[LinkTimeConstantCount];
426
427     String m_name;
428
429     Strong<JSObject> m_unhandledRejectionCallback;
430
431     Debugger* m_debugger;
432
433     VM& m_vm;
434
435 #if ENABLE(REMOTE_INSPECTOR)
436     std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController;
437     std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
438 #endif
439
440 #if ENABLE(INTL)
441     HashSet<String> m_intlCollatorAvailableLocales;
442     HashSet<String> m_intlDateTimeFormatAvailableLocales;
443     HashSet<String> m_intlNumberFormatAvailableLocales;
444     HashSet<String> m_intlPluralRulesAvailableLocales;
445 #endif // ENABLE(INTL)
446
447     RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
448     RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
449     RefPtr<WatchpointSet> m_varInjectionWatchpoint;
450
451     std::unique_ptr<JSGlobalObjectRareData> m_rareData;
452
453     WeakRandom m_weakRandom;
454     RegExpGlobalData m_regExpGlobalData;
455
456     JSCallee* stackOverflowFrameCallee() const { return m_stackOverflowFrameCallee.get(); }
457
458     InlineWatchpointSet& arrayIteratorProtocolWatchpointSet() { return m_arrayIteratorProtocolWatchpointSet; }
459     InlineWatchpointSet& mapIteratorProtocolWatchpointSet() { return m_mapIteratorProtocolWatchpointSet; }
460     InlineWatchpointSet& setIteratorProtocolWatchpointSet() { return m_setIteratorProtocolWatchpointSet; }
461     InlineWatchpointSet& stringIteratorProtocolWatchpointSet() { return m_stringIteratorProtocolWatchpointSet; }
462     InlineWatchpointSet& mapSetWatchpointSet() { return m_mapSetWatchpointSet; }
463     InlineWatchpointSet& setAddWatchpointSet() { return m_setAddWatchpointSet; }
464     InlineWatchpointSet& arraySpeciesWatchpointSet() { return m_arraySpeciesWatchpointSet; }
465     InlineWatchpointSet& arrayJoinWatchpointSet() { return m_arrayJoinWatchpointSet; }
466     InlineWatchpointSet& numberToStringWatchpointSet()
467     {
468         RELEASE_ASSERT(VM::canUseJIT());
469         return m_numberToStringWatchpointSet;
470     }
471     // If this hasn't been invalidated, it means the array iterator protocol
472     // is not observable to user code yet.
473     InlineWatchpointSet m_arrayIteratorProtocolWatchpointSet;
474     InlineWatchpointSet m_mapIteratorProtocolWatchpointSet;
475     InlineWatchpointSet m_setIteratorProtocolWatchpointSet;
476     InlineWatchpointSet m_stringIteratorProtocolWatchpointSet;
477     InlineWatchpointSet m_mapSetWatchpointSet;
478     InlineWatchpointSet m_setAddWatchpointSet;
479     InlineWatchpointSet m_arraySpeciesWatchpointSet;
480     InlineWatchpointSet m_arrayJoinWatchpointSet;
481     InlineWatchpointSet m_numberToStringWatchpointSet;
482     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayConstructorSpeciesWatchpoint;
483     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeConstructorWatchpoint;
484     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeSymbolIteratorWatchpoint;
485     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeJoinWatchpoint;
486     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayIteratorPrototypeNext;
487     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSymbolIteratorWatchpoint;
488     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapIteratorPrototypeNextWatchpoint;
489     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeSymbolIteratorWatchpoint;
490     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setIteratorPrototypeNextWatchpoint;
491     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringPrototypeSymbolIteratorWatchpoint;
492     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringIteratorPrototypeNextWatchpoint;
493     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSetWatchpoint;
494     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeAddWatchpoint;
495     std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_numberPrototypeToStringWatchpoint;
496
497     bool isArrayPrototypeIteratorProtocolFastAndNonObservable();
498     bool isMapPrototypeIteratorProtocolFastAndNonObservable();
499     bool isSetPrototypeIteratorProtocolFastAndNonObservable();
500     bool isStringPrototypeIteratorProtocolFastAndNonObservable();
501     bool isMapPrototypeSetFastAndNonObservable();
502     bool isSetPrototypeAddFastAndNonObservable();
503
504 #if ENABLE(DFG_JIT)
505     using ReferencedGlobalPropertyWatchpointSets = HashMap<RefPtr<UniquedStringImpl>, Ref<WatchpointSet>, IdentifierRepHash>;
506     ReferencedGlobalPropertyWatchpointSets m_referencedGlobalPropertyWatchpointSets;
507     ConcurrentJSLock m_referencedGlobalPropertyWatchpointSetsLock;
508 #endif
509
510     bool m_evalEnabled { true };
511     bool m_webAssemblyEnabled { true };
512     unsigned m_globalLexicalBindingEpoch { 1 };
513     String m_evalDisabledErrorMessage;
514     String m_webAssemblyDisabledErrorMessage;
515     RuntimeFlags m_runtimeFlags;
516     ConsoleClient* m_consoleClient { nullptr };
517     Optional<unsigned> m_stackTraceLimit;
518
519 #if !ASSERT_DISABLED
520     const ExecState* m_callFrameAtDebuggerEntry { nullptr };
521 #endif
522
523     static JS_EXPORT_PRIVATE const GlobalObjectMethodTable s_globalObjectMethodTable;
524     const GlobalObjectMethodTable* m_globalObjectMethodTable;
525
526     void createRareDataIfNeeded()
527     {
528         if (m_rareData)
529             return;
530         m_rareData = makeUnique<JSGlobalObjectRareData>();
531     }
532         
533 public:
534     typedef JSSegmentedVariableObject Base;
535     static constexpr unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | IsImmutablePrototypeExoticObject;
536
537     JS_EXPORT_PRIVATE static JSGlobalObject* create(VM&, Structure*);
538
539     DECLARE_EXPORT_INFO;
540
541     bool hasDebugger() const;
542     bool hasInteractiveDebugger() const;
543     const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; }
544
545 #if ENABLE(DFG_JIT)
546     WatchpointSet* getReferencedPropertyWatchpointSet(UniquedStringImpl*);
547     WatchpointSet& ensureReferencedPropertyWatchpointSet(UniquedStringImpl*);
548 #endif
549
550     Optional<unsigned> stackTraceLimit() const { return m_stackTraceLimit; }
551     void setStackTraceLimit(Optional<unsigned> value) { m_stackTraceLimit = value; }
552
553 protected:
554     JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = nullptr);
555
556     JS_EXPORT_PRIVATE void finishCreation(VM&);
557
558     JS_EXPORT_PRIVATE void finishCreation(VM&, JSObject*);
559
560     void addGlobalVar(const Identifier&);
561
562 public:
563     JS_EXPORT_PRIVATE ~JSGlobalObject();
564     JS_EXPORT_PRIVATE static void destroy(JSCell*);
565
566     JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
567
568     JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
569     JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
570
571     JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
572     JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
573     JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
574
575     void addVar(ExecState* exec, const Identifier& propertyName)
576     {
577         if (!hasOwnProperty(exec, propertyName))
578             addGlobalVar(propertyName);
579     }
580     void addFunction(ExecState*, const Identifier&);
581
582     JSScope* globalScope() { return m_globalLexicalEnvironment.get(); }
583     JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); }
584
585     JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); }
586     void setGlobalScopeExtension(JSScope*);
587     void clearGlobalScopeExtension();
588
589     // The following accessors return pristine values, even if a script 
590     // replaces the global object's associated property.
591
592     GetterSetter* speciesGetterSetter() const { return m_speciesGetterSetter.get(); }
593
594     ArrayConstructor* arrayConstructor() const { return m_arrayConstructor.get(); }
595     ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); }
596     JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); }
597     JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); }
598
599 #if ENABLE(INTL)
600     IntlCollator* defaultCollator(ExecState*);
601 #endif
602
603     NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
604     NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
605
606     JSFunction* parseIntFunction() const { return m_parseIntFunction.get(this); }
607     JSFunction* parseFloatFunction() const { return m_parseFloatFunction.get(this); }
608
609     JSFunction* evalFunction() const { return m_evalFunction.get(this); }
610     JSFunction* callFunction() const { return m_callFunction.get(); }
611     JSFunction* applyFunction() const { return m_applyFunction.get(); }
612     JSFunction* throwTypeErrorFunction() const { return m_throwTypeErrorFunction.get(); }
613     JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); }
614     JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
615     JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); }
616     JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); }
617     JSFunction* promiseProtoThenFunction() const { return m_promiseProtoThenFunction.get(); }
618     JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); }
619     JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.get(); }
620     JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
621     JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
622     JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); }
623     JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); }
624     GetterSetter* regExpProtoGlobalGetter() const { return m_regExpProtoGlobalGetter.get(); }
625     GetterSetter* regExpProtoUnicodeGetter() const { return m_regExpProtoUnicodeGetter.get(); }
626     GetterSetter* throwTypeErrorArgumentsCalleeAndCallerGetterSetter()
627     {
628         return m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.get();
629     }
630     
631     JSModuleLoader* moduleLoader() const { return m_moduleLoader.get(this); }
632
633     ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
634     FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
635     ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
636     JSObject* booleanPrototype() const { return m_booleanObjectStructure.prototypeInitializedOnMainThread(this); }
637     StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
638     JSObject* numberPrototype() const { return m_numberObjectStructure.prototypeInitializedOnMainThread(this); }
639     BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); }
640     JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
641     JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototypeInitializedOnMainThread(this); }
642     RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
643     JSObject* errorPrototype() const { return m_errorStructure.prototype(this); }
644     IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
645     AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); }
646     GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
647     GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); }
648     AsyncFunctionPrototype* asyncFunctionPrototype() const { return m_asyncFunctionPrototype.get(); }
649     MapPrototype* mapPrototype() const { return m_mapPrototype.get(); }
650     // Workaround for the name conflict between JSCell::setPrototype.
651     SetPrototype* jsSetPrototype() const { return m_setPrototype.get(); }
652     JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); }
653     AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); }
654     AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); }
655
656     Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); }
657     Structure* withScopeStructure() const { return m_withScopeStructure.get(this); }
658     Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(this); }
659     Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); }
660     Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(this); }
661     Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); }
662     Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); }
663     Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); }
664     Structure* objectStructureForObjectConstructor() const { return m_objectStructureForObjectConstructor.get(); }
665     Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
666     {
667         ASSERT(indexingType & IsArray);
668         return m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(indexingType)].get();
669     }
670     Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
671     {
672         ASSERT(indexingType & IsArray);
673         return m_arrayStructureForIndexingShapeDuringAllocation[arrayIndexFromIndexingType(indexingType)].get();
674     }
675     Structure* arrayStructureForIndexingTypeDuringAllocation(ExecState* exec, IndexingType indexingType, JSValue newTarget) const
676     {
677         return InternalFunction::createSubclassStructure(exec, newTarget, arrayStructureForIndexingTypeDuringAllocation(indexingType));
678     }
679     Structure* arrayStructureForProfileDuringAllocation(ExecState* exec, ArrayAllocationProfile* profile, JSValue newTarget) const
680     {
681         return arrayStructureForIndexingTypeDuringAllocation(exec, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget);
682     }
683         
684     bool isOriginalArrayStructure(Structure* structure)
685     {
686         return originalArrayStructureForIndexingType(structure->indexingMode() | IsArray) == structure;
687     }
688         
689     Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(this); }
690     Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(this); }
691     Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(this); }
692     Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(this); }
693 #if JSC_OBJC_API_ENABLED
694     Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(this); }
695     Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(this); }
696 #endif
697 #ifdef JSC_GLIB_API_ENABLED
698     Structure* glibCallbackFunctionStructure() const { return m_glibCallbackFunctionStructure.get(this); }
699     Structure* glibWrapperObjectStructure() const { return m_glibWrapperObjectStructure.get(this); }
700 #endif
701     Structure* dateStructure() const { return m_dateStructure.get(this); }
702     Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(this); }
703     Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
704     Structure* errorStructure() const { return m_errorStructure.get(this); }
705     Structure* errorStructure(ErrorType errorType) const
706     {
707         switch (errorType) {
708         case ErrorType::Error:
709             return errorStructure();
710         case ErrorType::EvalError:
711             return m_evalErrorStructure.get(this);
712         case ErrorType::RangeError:
713             return m_rangeErrorStructure.get(this);
714         case ErrorType::ReferenceError:
715             return m_referenceErrorStructure.get(this);
716         case ErrorType::SyntaxError:
717             return m_syntaxErrorStructure.get(this);
718         case ErrorType::TypeError:
719             return m_typeErrorStructure.get(this);
720         case ErrorType::URIError:
721             return m_URIErrorStructure.get(this);
722         }
723         ASSERT_NOT_REACHED();
724         return nullptr;
725     }
726     Structure* calleeStructure() const { return m_calleeStructure.get(); }
727     Structure* hostFunctionStructure() const { return m_hostFunctionStructure.get(); }
728
729     Structure* arrowFunctionStructure(bool isBuiltin) const
730     {
731         if (isBuiltin)
732             return m_builtinFunctions.arrowFunctionStructure.get();
733         return m_ordinaryFunctions.arrowFunctionStructure.get();
734     }
735     Structure* sloppyFunctionStructure(bool isBuiltin) const
736     {
737         if (isBuiltin)
738             return m_builtinFunctions.sloppyFunctionStructure.get();
739         return m_ordinaryFunctions.sloppyFunctionStructure.get();
740     }
741     Structure* strictFunctionStructure(bool isBuiltin) const
742     {
743         if (isBuiltin)
744             return m_builtinFunctions.strictFunctionStructure.get();
745         return m_ordinaryFunctions.strictFunctionStructure.get();
746     }
747
748     Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(this); }
749     Structure* customGetterSetterFunctionStructure() const { return m_customGetterSetterFunctionStructure.get(this); }
750     Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(this); }
751     PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
752     Structure* numberObjectStructure() const { return m_numberObjectStructure.get(this); }
753     Structure* mapStructure() const { return m_mapStructure.get(); }
754     Structure* regExpStructure() const { return m_regExpStructure.get(); }
755     Structure* generatorStructure() const { return m_generatorStructure.get(); }
756     Structure* asyncGeneratorStructure() const { return m_asyncGeneratorStructure.get(); }
757     Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); }
758     Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); }
759     Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); }
760     Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
761     Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(this); }
762     Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
763     Structure* regExpMatchesArrayWithGroupsStructure() const { return m_regExpMatchesArrayWithGroupsStructure.get(); }
764     Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(this); }
765     Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(this); }
766     Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(this); }
767     Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(this); }
768     Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(this); }
769     Structure* restParameterStructure() const { return arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); }
770     Structure* originalRestParameterStructure() const { return originalArrayStructureForIndexingType(ArrayWithContiguous); }
771 #if ENABLE(WEBASSEMBLY)
772     Structure* webAssemblyModuleRecordStructure() const { return m_webAssemblyModuleRecordStructure.get(this); }
773     Structure* webAssemblyFunctionStructure() const { return m_webAssemblyFunctionStructure.get(this); }
774     Structure* jsToWasmICCalleeStructure() const { return m_jsToWasmICCalleeStructure.get(this); }
775     Structure* webAssemblyWrapperFunctionStructure() const { return m_webAssemblyWrapperFunctionStructure.get(this); }
776     Structure* webAssemblyToJSCalleeStructure() const { return m_webAssemblyToJSCalleeStructure.get(this); }
777 #endif // ENABLE(WEBASSEMBLY)
778 #if ENABLE(INTL)
779     Structure* collatorStructure() { return m_collatorStructure.get(this); }
780     Structure* numberFormatStructure() { return m_numberFormatStructure.get(this); }
781     Structure* dateTimeFormatStructure() { return m_dateTimeFormatStructure.get(this); }
782     Structure* pluralRulesStructure() { return m_pluralRulesStructure.get(this); }
783 #endif // ENABLE(INTL)
784
785     JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
786     JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
787
788     RegExpGlobalData& regExpGlobalData() { return m_regExpGlobalData; }
789     static ptrdiff_t regExpGlobalDataOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_regExpGlobalData); }
790
791 #if ENABLE(REMOTE_INSPECTOR)
792     Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); }
793     JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
794 #endif
795
796 #if ENABLE(INTL)
797     const HashSet<String>& intlCollatorAvailableLocales();
798     const HashSet<String>& intlDateTimeFormatAvailableLocales();
799     const HashSet<String>& intlNumberFormatAvailableLocales();
800     const HashSet<String>& intlPluralRulesAvailableLocales();
801 #endif // ENABLE(INTL)
802
803     void bumpGlobalLexicalBindingEpoch(VM&);
804     unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; }
805     static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); }
806     unsigned* addressOfGlobalLexicalBindingEpoch() { return &m_globalLexicalBindingEpoch; }
807
808     void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
809     ConsoleClient* consoleClient() const { return m_consoleClient; }
810
811     void setName(const String&);
812     const String& name() const { return m_name; }
813
814     void setUnhandledRejectionCallback(VM& vm, JSObject* function) { m_unhandledRejectionCallback.set(vm, function); }
815     JSObject* unhandledRejectionCallback() const { return m_unhandledRejectionCallback.get(); }
816
817     JSObject* arrayBufferConstructor() const { return m_arrayBufferStructure.constructor(this); }
818
819     JSObject* arrayBufferPrototype(ArrayBufferSharingMode sharingMode) const
820     {
821         switch (sharingMode) {
822         case ArrayBufferSharingMode::Default:
823             return m_arrayBufferStructure.prototype(this);
824 #if ENABLE(SHARED_ARRAY_BUFFER)
825         case ArrayBufferSharingMode::Shared:
826             return m_sharedArrayBufferPrototype.get();
827 #else
828         default:
829             return m_arrayBufferStructure.prototype(this);
830 #endif
831         }
832     }
833     Structure* arrayBufferStructure(ArrayBufferSharingMode sharingMode) const
834     {
835         switch (sharingMode) {
836         case ArrayBufferSharingMode::Default:
837             return m_arrayBufferStructure.get(this);
838 #if ENABLE(SHARED_ARRAY_BUFFER)
839         case ArrayBufferSharingMode::Shared:
840             return m_sharedArrayBufferStructure.get();
841 #else
842         default:
843             return m_arrayBufferStructure.get(this);
844 #endif
845         }
846         RELEASE_ASSERT_NOT_REACHED();
847         return nullptr;
848     }
849
850 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
851     Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
852
853     FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
854     FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
855
856 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
857
858 #define DEFINE_ACCESSORS_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase, featureFlag) \
859     Structure* properName ## Structure() { return m_ ## properName ## Structure.get(this); } \
860     JSObject* properName ## Constructor() { return m_ ## properName ## Structure.constructor(this); }
861
862     FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE)
863     FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE)
864
865 #undef DEFINE_ACCESSORS_FOR_LAZY_TYPE
866
867     LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type)
868     {
869         switch (type) {
870         case NotTypedArray:
871             RELEASE_ASSERT_NOT_REACHED();
872             return m_typedArrayInt8;
873 #define TYPED_ARRAY_TYPE_CASE(name) case Type ## name: return m_typedArray ## name;
874             FOR_EACH_TYPED_ARRAY_TYPE(TYPED_ARRAY_TYPE_CASE)
875 #undef TYPED_ARRAY_TYPE_CASE
876         }
877         RELEASE_ASSERT_NOT_REACHED();
878         return m_typedArrayInt8;
879     }
880     const LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) const
881     {
882         return const_cast<const LazyClassStructure&>(const_cast<JSGlobalObject*>(this)->lazyTypedArrayStructure(type));
883     }
884     
885     Structure* typedArrayStructure(TypedArrayType type) const
886     {
887         return lazyTypedArrayStructure(type).get(this);
888     }
889     Structure* typedArrayStructureConcurrently(TypedArrayType type) const
890     {
891         return lazyTypedArrayStructure(type).getConcurrently();
892     }
893     bool isOriginalTypedArrayStructure(Structure* structure)
894     {
895         TypedArrayType type = structure->classInfo()->typedArrayStorageType;
896         if (type == NotTypedArray)
897             return false;
898         return typedArrayStructureConcurrently(type) == structure;
899     }
900
901     JSObject* typedArrayConstructor(TypedArrayType type) const
902     {
903         return lazyTypedArrayStructure(type).constructor(this);
904     }
905
906     JSCell* actualPointerFor(Special::Pointer pointer)
907     {
908         ASSERT(pointer < Special::TableSize);
909         return m_specialPointers[pointer];
910     }
911     JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type)
912     {
913         unsigned index = static_cast<unsigned>(type);
914         ASSERT(index < LinkTimeConstantCount);
915         return m_linkTimeConstants[index];
916     }
917
918     WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
919     WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
920     WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); }
921         
922     bool isHavingABadTime() const
923     {
924         return m_havingABadTimeWatchpoint->hasBeenInvalidated();
925     }
926         
927     void haveABadTime(VM&);
928         
929     bool objectPrototypeIsSane();
930     bool arrayPrototypeChainIsSane();
931     bool stringPrototypeChainIsSane();
932
933     void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
934     unsigned profileGroup() const
935     { 
936         if (!m_rareData)
937             return 0;
938         return m_rareData->profileGroup;
939     }
940
941     Debugger* debugger() const { return m_debugger; }
942     void setDebugger(Debugger*);
943
944     const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
945
946     static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
947
948     JS_EXPORT_PRIVATE ExecState* globalExec();
949
950     static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
951     static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
952     static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
953
954     JS_EXPORT_PRIVATE void queueMicrotask(Ref<Microtask>&&);
955
956     bool evalEnabled() const { return m_evalEnabled; }
957     bool webAssemblyEnabled() const { return m_webAssemblyEnabled; }
958     const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
959     const String& webAssemblyDisabledErrorMessage() const { return m_webAssemblyDisabledErrorMessage; }
960     void setEvalEnabled(bool enabled, const String& errorMessage = String())
961     {
962         m_evalEnabled = enabled;
963         m_evalDisabledErrorMessage = errorMessage;
964     }
965     void setWebAssemblyEnabled(bool enabled, const String& errorMessage = String())
966     {
967         m_webAssemblyEnabled = enabled;
968         m_webAssemblyDisabledErrorMessage = errorMessage;
969     }
970
971 #if !ASSERT_DISABLED
972     const ExecState* callFrameAtDebuggerEntry() const { return m_callFrameAtDebuggerEntry; }
973     void setCallFrameAtDebuggerEntry(const ExecState* callFrame) { m_callFrameAtDebuggerEntry = callFrame; }
974 #endif
975
976     void resetPrototype(VM&, JSValue prototype);
977
978     VM& vm() const { return m_vm; }
979     JSObject* globalThis() const;
980     WriteBarrier<JSObject>* addressOfGlobalThis() { return &m_globalThis; }
981     OptionSet<CodeGenerationMode> defaultCodeGenerationMode() const;
982
983     static Structure* createStructure(VM& vm, JSValue prototype)
984     {
985         Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
986         result->setTransitionWatchpointIsLikelyToBeFired(true);
987         return result;
988     }
989
990     void registerWeakMap(OpaqueJSWeakObjectMap* map)
991     {
992         createRareDataIfNeeded();
993         m_rareData->weakMaps.add(map);
994     }
995
996     void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
997     {
998         if (m_rareData)
999             m_rareData->weakMaps.remove(map);
1000     }
1001
1002     OpaqueJSClassDataMap& opaqueJSClassData()
1003     {
1004         createRareDataIfNeeded();
1005         return m_rareData->opaqueJSClassData;
1006     }
1007
1008     static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); }
1009     double weakRandomNumber() { return m_weakRandom.get(); }
1010     unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
1011     WeakRandom& weakRandom() { return m_weakRandom; }
1012
1013     bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
1014     JS_EXPORT_PRIVATE void exposeDollarVM(VM&);
1015
1016 #if JSC_OBJC_API_ENABLED
1017     JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
1018     void setWrapperMap(JSWrapperMap* map) { m_wrapperMap = map; }
1019 #endif
1020 #ifdef JSC_GLIB_API_ENABLED
1021     WrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
1022     void setWrapperMap(std::unique_ptr<WrapperMap>&&);
1023 #endif
1024
1025     void tryInstallArraySpeciesWatchpoint(ExecState*);
1026
1027 protected:
1028     struct GlobalPropertyInfo {
1029         GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
1030             : identifier(i)
1031             , value(v)
1032             , attributes(a)
1033         {
1034         }
1035
1036         const Identifier identifier;
1037         JSValue value;
1038         unsigned attributes;
1039     };
1040     JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
1041
1042     void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; }
1043
1044 private:
1045     friend class LLIntOffsetsExtractor;
1046
1047     void fireWatchpointAndMakeAllArrayStructuresSlowPut(VM&);
1048     void setGlobalThis(VM&, JSObject* globalThis);
1049
1050     template<ErrorType errorType>
1051     void initializeErrorConstructor(LazyClassStructure::Initializer&);
1052
1053     JS_EXPORT_PRIVATE void init(VM&);
1054     void fixupPrototypeChainWithObjectPrototype(VM&);
1055
1056     JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
1057
1058     bool m_needsSiteSpecificQuirks { false };
1059 #if JSC_OBJC_API_ENABLED
1060     RetainPtr<JSWrapperMap> m_wrapperMap;
1061 #endif
1062 #ifdef JSC_GLIB_API_ENABLED
1063     std::unique_ptr<WrapperMap> m_wrapperMap;
1064 #endif
1065 };
1066
1067 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0, JSValue newTarget = JSValue())
1068 {
1069     VM& vm = globalObject->vm();
1070     auto scope = DECLARE_THROW_SCOPE(vm);
1071     Structure* structure;
1072     if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)
1073         structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(exec, ArrayWithArrayStorage, newTarget);
1074     else
1075         structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1076     RETURN_IF_EXCEPTION(scope, nullptr);
1077
1078     JSArray* result = JSArray::tryCreate(vm, structure, initialLength);
1079     if (UNLIKELY(!result)) {
1080         throwOutOfMemoryError(exec, scope);
1081         return nullptr;
1082     }
1083     return ArrayAllocationProfile::updateLastAllocationFor(profile, result);
1084 }
1085
1086 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue())
1087 {
1088     return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength, newTarget);
1089 }
1090  
1091 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values, JSValue newTarget = JSValue())
1092 {
1093     VM& vm = globalObject->vm();
1094     auto scope = DECLARE_THROW_SCOPE(vm);
1095     Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1096     RETURN_IF_EXCEPTION(scope, nullptr);
1097     return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values));
1098 }
1099
1100 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue())
1101 {
1102     return constructArray(exec, profile, exec->lexicalGlobalObject(), values, newTarget);
1103 }
1104
1105 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1106 {
1107     VM& vm = globalObject->vm();
1108     auto scope = DECLARE_THROW_SCOPE(vm);
1109     Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1110     RETURN_IF_EXCEPTION(scope, nullptr);
1111     return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values, length));
1112 }
1113
1114 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1115 {
1116     return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
1117 }
1118
1119 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1120 {
1121     VM& vm = globalObject->vm();
1122     auto scope = DECLARE_THROW_SCOPE(vm);
1123     Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1124     RETURN_IF_EXCEPTION(scope, nullptr);
1125     return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, structure, values, length));
1126 }
1127
1128 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1129 {
1130     return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
1131 }
1132
1133 inline JSObject* ExecState::globalThisValue() const
1134 {
1135     return lexicalGlobalObject()->globalThis();
1136 }
1137
1138 inline JSObject* JSScope::globalThis()
1139
1140     return globalObject()->globalThis();
1141 }
1142
1143 inline JSObject* JSGlobalObject::globalThis() const
1144
1145     return m_globalThis.get();
1146 }
1147
1148 inline OptionSet<CodeGenerationMode> JSGlobalObject::defaultCodeGenerationMode() const
1149 {
1150     OptionSet<CodeGenerationMode> codeGenerationMode;
1151     if (hasInteractiveDebugger() || Options::forceDebuggerBytecodeGeneration())
1152         codeGenerationMode.add(CodeGenerationMode::Debugger);
1153     if (m_vm.typeProfiler())
1154         codeGenerationMode.add(CodeGenerationMode::TypeProfiler);
1155     if (m_vm.controlFlowProfiler())
1156         codeGenerationMode.add(CodeGenerationMode::ControlFlowProfiler);
1157     return codeGenerationMode;
1158 }
1159
1160 } // namespace JSC