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