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