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