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