2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
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.
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.
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.
24 #include "ArrayAllocationProfile.h"
25 #include "ArrayBufferSharingMode.h"
26 #include "BigIntPrototype.h"
27 #include "BooleanPrototype.h"
28 #include "ExceptionHelpers.h"
29 #include "InternalFunction.h"
31 #include "JSArrayBufferPrototype.h"
32 #include "JSClassRef.h"
33 #include "JSGlobalLexicalEnvironment.h"
34 #include "JSSegmentedVariableObject.h"
35 #include "JSWeakObjectMapRefInternal.h"
36 #include "LazyProperty.h"
37 #include "LazyClassStructure.h"
38 #include "NumberPrototype.h"
39 #include "RuntimeFlags.h"
40 #include "SpecialPointer.h"
41 #include "StringPrototype.h"
42 #include "SymbolPrototype.h"
43 #include "TemplateRegistry.h"
45 #include "Watchpoint.h"
46 #include <JavaScriptCore/JSBase.h>
48 #include <wtf/HashSet.h>
49 #include <wtf/RetainPtr.h>
52 struct OpaqueJSClassContextData;
53 OBJC_CLASS JSWrapperMap;
56 class JSGlobalObjectInspectorController;
60 class ArrayConstructor;
62 class AsyncIteratorPrototype;
63 class AsyncFunctionPrototype;
64 class AsyncGeneratorPrototype;
65 class AsyncGeneratorFunctionPrototype;
66 class BooleanPrototype;
69 class ErrorConstructor;
73 class FunctionConstructor;
74 class FunctionPrototype;
75 class GeneratorPrototype;
76 class GeneratorFunctionPrototype;
78 class GlobalCodeBlock;
79 class IndirectEvalExecutable;
82 class JSArrayBufferConstructor;
83 class JSArrayBufferPrototype;
84 class JSGlobalObjectDebuggable;
85 class JSInternalPromise;
89 class JSPromiseConstructor;
90 class JSPromisePrototype;
91 class JSSharedArrayBuffer;
92 class JSSharedArrayBufferConstructor;
93 class JSSharedArrayBufferPrototype;
94 class JSTypedArrayViewConstructor;
95 class JSTypedArrayViewPrototype;
96 class DirectEvalExecutable;
97 class LLIntOffsetsExtractor;
100 class ModuleLoaderPrototype;
101 class ModuleProgramExecutable;
102 class NativeErrorConstructor;
103 class NullGetterFunction;
104 class NullSetterFunction;
105 class ObjectConstructor;
106 class ProgramCodeBlock;
107 class ProgramExecutable;
108 class RegExpConstructor;
109 class RegExpPrototype;
113 class UnlinkedModuleProgramCodeBlock;
114 class VariableEnvironment;
115 struct ActivationStackNode;
118 template<typename Watchpoint> class ObjectPropertyChangeAdaptiveWatchpoint;
120 #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName, object)
122 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
123 macro(String, string, stringObject, StringObject, String, object) \
124 macro(Symbol, symbol, symbolObject, SymbolObject, Symbol, object) \
125 macro(Number, number, numberObject, NumberObject, Number, object) \
126 macro(Boolean, boolean, booleanObject, BooleanObject, Boolean, object) \
127 macro(Error, error, error, ErrorInstance, Error, object) \
128 macro(Map, map, map, JSMap, Map, object) \
129 macro(Set, set, set, JSSet, Set, object) \
130 macro(JSPromise, promise, promise, JSPromise, Promise, object)
132 #define FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
133 macro(BigInt, bigInt, bigIntObject, BigIntObject, BigInt, object)
135 #define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
136 macro(StringIterator, stringIterator, stringIterator, JSStringIterator, StringIterator, iterator) \
138 #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
139 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
140 macro(JSInternalPromise, internalPromise, internalPromise, JSInternalPromise, InternalPromise, object) \
142 #define FOR_EACH_LAZY_BUILTIN_TYPE(macro) \
143 macro(Date, date, date, DateInstance, Date, object) \
144 DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
145 DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \
147 #if ENABLE(WEBASSEMBLY)
148 #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro) \
149 macro(WebAssemblyCompileError, webAssemblyCompileError, WebAssemblyCompileError, WebAssemblyCompileError, CompileError, error) \
150 macro(WebAssemblyInstance, webAssemblyInstance, WebAssemblyInstance, WebAssemblyInstance, Instance, object) \
151 macro(WebAssemblyLinkError, webAssemblyLinkError, WebAssemblyLinkError, WebAssemblyLinkError, LinkError, error) \
152 macro(WebAssemblyMemory, webAssemblyMemory, WebAssemblyMemory, WebAssemblyMemory, Memory, object) \
153 macro(WebAssemblyModule, webAssemblyModule, WebAssemblyModule, WebAssemblyModule, Module, object) \
154 macro(WebAssemblyRuntimeError, webAssemblyRuntimeError, WebAssemblyRuntimeError, WebAssemblyRuntimeError, RuntimeError, error) \
155 macro(WebAssemblyTable, webAssemblyTable, WebAssemblyTable, WebAssemblyTable, Table, object)
157 #define FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(macro)
158 #endif // ENABLE(WEBASSEMBLY)
160 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
161 class JS ## capitalName; \
162 class capitalName ## Prototype; \
163 class capitalName ## Constructor;
165 class IteratorPrototype;
166 FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
167 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DECLARE_SIMPLE_BUILTIN_TYPE)
168 FOR_EACH_LAZY_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
169 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
170 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
172 #undef DECLARE_SIMPLE_BUILTIN_TYPE
174 enum class JSPromiseRejectionOperation : unsigned {
175 Reject, // When a promise is rejected without any handlers.
176 Handle, // When a handler is added to a rejected promise for the first time.
179 struct GlobalObjectMethodTable {
180 typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*);
181 SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo;
183 typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*);
184 ShouldInterruptScriptFunctionPtr shouldInterruptScript;
186 typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr)(const JSGlobalObject*);
187 JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags;
189 typedef void (*QueueTaskToEventLoopFunctionPtr)(JSGlobalObject&, Ref<Microtask>&&);
190 QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
192 typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*);
193 ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout;
195 typedef JSInternalPromise* (*ModuleLoaderImportModulePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, JSValue, const SourceOrigin&);
196 ModuleLoaderImportModulePtr moduleLoaderImportModule;
198 typedef Identifier (*ModuleLoaderResolvePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
199 ModuleLoaderResolvePtr moduleLoaderResolve;
201 typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
202 ModuleLoaderFetchPtr moduleLoaderFetch;
204 typedef JSObject* (*ModuleLoaderCreateImportMetaPropertiesPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
205 ModuleLoaderCreateImportMetaPropertiesPtr moduleLoaderCreateImportMetaProperties;
207 typedef JSValue (*ModuleLoaderEvaluatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
208 ModuleLoaderEvaluatePtr moduleLoaderEvaluate;
210 typedef void (*PromiseRejectionTrackerPtr)(JSGlobalObject*, ExecState*, JSPromise*, JSPromiseRejectionOperation);
211 PromiseRejectionTrackerPtr promiseRejectionTracker;
213 typedef String (*DefaultLanguageFunctionPtr)();
214 DefaultLanguageFunctionPtr defaultLanguage;
217 class JSGlobalObject : public JSSegmentedVariableObject {
219 typedef HashSet<RefPtr<OpaqueJSWeakObjectMap>> WeakMapSet;
220 typedef HashMap<OpaqueJSClass*, std::unique_ptr<OpaqueJSClassContextData>> OpaqueJSClassDataMap;
222 struct JSGlobalObjectRareData {
223 WTF_MAKE_FAST_ALLOCATED;
225 JSGlobalObjectRareData()
231 unsigned profileGroup;
233 OpaqueJSClassDataMap opaqueJSClassData;
236 // Our hashtable code-generator tries to access these properties, so we make them public.
237 // However, we'd like it better if they could be protected.
239 template<typename T> using Initializer = typename LazyProperty<JSGlobalObject, T>::Initializer;
241 Register m_globalCallFrame[CallFrame::headerSizeInRegisters];
243 WriteBarrier<JSObject> m_globalThis;
245 WriteBarrier<JSGlobalLexicalEnvironment> m_globalLexicalEnvironment;
246 WriteBarrier<JSScope> m_globalScopeExtension;
247 WriteBarrier<JSObject> m_globalCallee;
248 WriteBarrier<RegExpConstructor> m_regExpConstructor;
249 WriteBarrier<ErrorConstructor> m_errorConstructor;
250 WriteBarrier<Structure> m_nativeErrorPrototypeStructure;
251 WriteBarrier<Structure> m_nativeErrorStructure;
252 LazyProperty<JSGlobalObject, NativeErrorConstructor> m_evalErrorConstructor;
253 WriteBarrier<NativeErrorConstructor> m_rangeErrorConstructor;
254 LazyProperty<JSGlobalObject, NativeErrorConstructor> m_referenceErrorConstructor;
255 LazyProperty<JSGlobalObject, NativeErrorConstructor> m_syntaxErrorConstructor;
256 WriteBarrier<NativeErrorConstructor> m_typeErrorConstructor;
257 LazyProperty<JSGlobalObject, NativeErrorConstructor> m_URIErrorConstructor;
258 WriteBarrier<ObjectConstructor> m_objectConstructor;
259 WriteBarrier<ArrayConstructor> m_arrayConstructor;
260 WriteBarrier<JSPromiseConstructor> m_promiseConstructor;
261 WriteBarrier<JSInternalPromiseConstructor> m_internalPromiseConstructor;
263 WriteBarrier<NullGetterFunction> m_nullGetterFunction;
264 WriteBarrier<NullSetterFunction> m_nullSetterFunction;
266 WriteBarrier<JSFunction> m_parseIntFunction;
267 WriteBarrier<JSFunction> m_parseFloatFunction;
269 WriteBarrier<JSFunction> m_evalFunction;
270 WriteBarrier<JSFunction> m_callFunction;
271 WriteBarrier<JSFunction> m_applyFunction;
272 WriteBarrier<JSFunction> m_throwTypeErrorFunction;
273 LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoToStringFunction;
274 LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction;
275 LazyProperty<JSGlobalObject, JSFunction> m_initializePromiseFunction;
276 LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction;
277 LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction;
278 WriteBarrier<JSFunction> m_objectProtoValueOfFunction;
279 WriteBarrier<JSFunction> m_numberProtoToStringFunction;
280 WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
281 WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction;
282 LazyProperty<JSGlobalObject, GetterSetter> m_throwTypeErrorGetterSetter;
283 WriteBarrier<JSObject> m_regExpProtoExec;
284 WriteBarrier<JSObject> m_regExpProtoSymbolReplace;
285 WriteBarrier<JSObject> m_regExpProtoGlobalGetter;
286 WriteBarrier<JSObject> m_regExpProtoUnicodeGetter;
287 WriteBarrier<GetterSetter> m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter;
289 WriteBarrier<JSModuleLoader> m_moduleLoader;
291 WriteBarrier<ObjectPrototype> m_objectPrototype;
292 WriteBarrier<FunctionPrototype> m_functionPrototype;
293 WriteBarrier<ArrayPrototype> m_arrayPrototype;
294 WriteBarrier<RegExpPrototype> m_regExpPrototype;
295 WriteBarrier<IteratorPrototype> m_iteratorPrototype;
296 WriteBarrier<AsyncIteratorPrototype> m_asyncIteratorPrototype;
297 WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype;
298 WriteBarrier<GeneratorPrototype> m_generatorPrototype;
299 WriteBarrier<AsyncGeneratorPrototype> m_asyncGeneratorPrototype;
300 WriteBarrier<ModuleLoaderPrototype> m_moduleLoaderPrototype;
302 LazyProperty<JSGlobalObject, Structure> m_debuggerScopeStructure;
303 LazyProperty<JSGlobalObject, Structure> m_withScopeStructure;
304 WriteBarrier<Structure> m_strictEvalActivationStructure;
305 WriteBarrier<Structure> m_lexicalEnvironmentStructure;
306 LazyProperty<JSGlobalObject, Structure> m_moduleEnvironmentStructure;
307 WriteBarrier<Structure> m_directArgumentsStructure;
308 WriteBarrier<Structure> m_scopedArgumentsStructure;
309 WriteBarrier<Structure> m_clonedArgumentsStructure;
311 WriteBarrier<Structure> m_objectStructureForObjectConstructor;
313 // Lists the actual structures used for having these particular indexing shapes.
314 WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfIndexingShapes];
315 // Lists the structures we should use during allocation for these particular indexing shapes.
316 // These structures will differ from the originals list above when we are having a bad time.
317 WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfIndexingShapes];
319 LazyProperty<JSGlobalObject, Structure> m_callbackConstructorStructure;
320 LazyProperty<JSGlobalObject, Structure> m_callbackFunctionStructure;
321 LazyProperty<JSGlobalObject, Structure> m_callbackObjectStructure;
322 WriteBarrier<Structure> m_propertyNameIteratorStructure;
323 #if JSC_OBJC_API_ENABLED
324 LazyProperty<JSGlobalObject, Structure> m_objcCallbackFunctionStructure;
325 LazyProperty<JSGlobalObject, Structure> m_objcWrapperObjectStructure;
327 LazyProperty<JSGlobalObject, Structure> m_nullPrototypeObjectStructure;
328 WriteBarrier<Structure> m_calleeStructure;
329 WriteBarrier<Structure> m_strictFunctionStructure;
330 WriteBarrier<Structure> m_arrowFunctionStructure;
331 WriteBarrier<Structure> m_sloppyFunctionStructure;
332 LazyProperty<JSGlobalObject, Structure> m_boundFunctionStructure;
333 LazyProperty<JSGlobalObject, Structure> m_customGetterSetterFunctionStructure;
334 WriteBarrier<Structure> m_getterSetterStructure;
335 LazyProperty<JSGlobalObject, Structure> m_nativeStdFunctionStructure;
336 PropertyOffset m_functionNameOffset;
337 WriteBarrier<Structure> m_regExpStructure;
338 WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype;
339 WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype;
340 WriteBarrier<Structure> m_asyncFunctionStructure;
341 WriteBarrier<Structure> m_asyncGeneratorFunctionStructure;
342 WriteBarrier<Structure> m_generatorFunctionStructure;
343 WriteBarrier<Structure> m_dollarVMStructure;
344 WriteBarrier<Structure> m_iteratorResultObjectStructure;
345 WriteBarrier<Structure> m_regExpMatchesArrayStructure;
346 WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure;
347 WriteBarrier<Structure> m_moduleRecordStructure;
348 WriteBarrier<Structure> m_moduleNamespaceObjectStructure;
349 WriteBarrier<Structure> m_proxyObjectStructure;
350 WriteBarrier<Structure> m_callableProxyObjectStructure;
351 WriteBarrier<Structure> m_proxyRevokeStructure;
352 WriteBarrier<Structure> m_moduleLoaderStructure;
353 WriteBarrier<JSArrayBufferPrototype> m_arrayBufferPrototype;
354 WriteBarrier<Structure> m_arrayBufferStructure;
355 WriteBarrier<JSArrayBufferPrototype> m_sharedArrayBufferPrototype;
356 WriteBarrier<Structure> m_sharedArrayBufferStructure;
358 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
359 WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
360 WriteBarrier<Structure> m_ ## properName ## Structure;
362 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
363 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
364 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
366 #if ENABLE(WEBASSEMBLY)
367 WriteBarrier<Structure> m_webAssemblyStructure;
368 WriteBarrier<Structure> m_webAssemblyModuleRecordStructure;
369 WriteBarrier<Structure> m_webAssemblyFunctionStructure;
370 WriteBarrier<Structure> m_webAssemblyWrapperFunctionStructure;
371 WriteBarrier<Structure> m_webAssemblyToJSCalleeStructure;
372 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
373 #endif // ENABLE(WEBASSEMBLY)
375 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
377 #define DEFINE_STORAGE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
378 LazyClassStructure m_ ## properName ## Structure;
379 FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE)
380 #undef DEFINE_STORAGE_FOR_LAZY_TYPE
382 WriteBarrier<GetterSetter> m_speciesGetterSetter;
384 LazyProperty<JSGlobalObject, JSTypedArrayViewPrototype> m_typedArrayProto;
385 LazyProperty<JSGlobalObject, JSTypedArrayViewConstructor> m_typedArraySuperConstructor;
387 #define DECLARE_TYPED_ARRAY_TYPE_STRUCTURE(name) LazyClassStructure m_typedArray ## name;
388 FOR_EACH_TYPED_ARRAY_TYPE(DECLARE_TYPED_ARRAY_TYPE_STRUCTURE)
389 #undef DECLARE_TYPED_ARRAY_TYPE_STRUCTURE
391 JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
392 JSCell* m_linkTimeConstants[LinkTimeConstantCount];
396 Debugger* m_debugger;
400 #if ENABLE(REMOTE_INSPECTOR)
401 std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController;
402 std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
406 HashSet<String> m_intlCollatorAvailableLocales;
407 HashSet<String> m_intlDateTimeFormatAvailableLocales;
408 HashSet<String> m_intlNumberFormatAvailableLocales;
409 #endif // ENABLE(INTL)
411 RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
412 RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
413 RefPtr<WatchpointSet> m_varInjectionWatchpoint;
415 std::unique_ptr<JSGlobalObjectRareData> m_rareData;
417 WeakRandom m_weakRandom;
419 InlineWatchpointSet& arrayIteratorProtocolWatchpoint() { return m_arrayIteratorProtocolWatchpoint; }
420 InlineWatchpointSet& mapIteratorProtocolWatchpoint() { return m_mapIteratorProtocolWatchpoint; }
421 InlineWatchpointSet& setIteratorProtocolWatchpoint() { return m_setIteratorProtocolWatchpoint; }
422 InlineWatchpointSet& stringIteratorProtocolWatchpoint() { return m_stringIteratorProtocolWatchpoint; }
423 InlineWatchpointSet& mapSetWatchpoint() { return m_mapSetWatchpoint; }
424 InlineWatchpointSet& setAddWatchpoint() { return m_setAddWatchpoint; }
425 InlineWatchpointSet& arraySpeciesWatchpoint() { return m_arraySpeciesWatchpoint; }
426 InlineWatchpointSet& numberToStringWatchpoint() { return m_numberToStringWatchpoint; }
427 // If this hasn't been invalidated, it means the array iterator protocol
428 // is not observable to user code yet.
429 InlineWatchpointSet m_arrayIteratorProtocolWatchpoint;
430 InlineWatchpointSet m_mapIteratorProtocolWatchpoint;
431 InlineWatchpointSet m_setIteratorProtocolWatchpoint;
432 InlineWatchpointSet m_stringIteratorProtocolWatchpoint;
433 InlineWatchpointSet m_mapSetWatchpoint;
434 InlineWatchpointSet m_setAddWatchpoint;
435 InlineWatchpointSet m_arraySpeciesWatchpoint;
436 InlineWatchpointSet m_numberToStringWatchpoint;
437 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeSymbolIteratorWatchpoint;
438 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayIteratorPrototypeNext;
439 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSymbolIteratorWatchpoint;
440 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapIteratorPrototypeNextWatchpoint;
441 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeSymbolIteratorWatchpoint;
442 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setIteratorPrototypeNextWatchpoint;
443 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringPrototypeSymbolIteratorWatchpoint;
444 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringIteratorPrototypeNextWatchpoint;
445 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSetWatchpoint;
446 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeAddWatchpoint;
447 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_numberPrototypeToStringWatchpoint;
449 bool isArrayPrototypeIteratorProtocolFastAndNonObservable();
450 bool isMapPrototypeIteratorProtocolFastAndNonObservable();
451 bool isSetPrototypeIteratorProtocolFastAndNonObservable();
452 bool isStringPrototypeIteratorProtocolFastAndNonObservable();
453 bool isMapPrototypeSetFastAndNonObservable();
454 bool isSetPrototypeAddFastAndNonObservable();
456 TemplateRegistry m_templateRegistry;
458 bool m_evalEnabled { true };
459 bool m_webAssemblyEnabled { true };
460 String m_evalDisabledErrorMessage;
461 String m_webAssemblyDisabledErrorMessage;
462 RuntimeFlags m_runtimeFlags;
463 ConsoleClient* m_consoleClient { nullptr };
465 static JS_EXPORTDATA const GlobalObjectMethodTable s_globalObjectMethodTable;
466 const GlobalObjectMethodTable* m_globalObjectMethodTable;
468 void createRareDataIfNeeded()
472 m_rareData = std::make_unique<JSGlobalObjectRareData>();
476 typedef JSSegmentedVariableObject Base;
477 static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | IsImmutablePrototypeExoticObject;
479 JS_EXPORT_PRIVATE static JSGlobalObject* create(VM&, Structure*);
483 bool hasDebugger() const;
484 bool hasInteractiveDebugger() const;
485 const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; }
488 JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = 0);
490 JS_EXPORT_PRIVATE void finishCreation(VM&);
492 JS_EXPORT_PRIVATE void finishCreation(VM&, JSObject*);
494 void addGlobalVar(const Identifier&);
497 JS_EXPORT_PRIVATE ~JSGlobalObject();
498 JS_EXPORT_PRIVATE static void destroy(JSCell*);
500 JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
502 JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
503 JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
505 JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
506 JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
507 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
509 void addVar(ExecState* exec, const Identifier& propertyName)
511 if (!hasProperty(exec, propertyName))
512 addGlobalVar(propertyName);
514 void addFunction(ExecState*, const Identifier&);
516 JSScope* globalScope() { return m_globalLexicalEnvironment.get(); }
517 JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); }
519 JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); }
520 void setGlobalScopeExtension(JSScope*);
521 void clearGlobalScopeExtension();
523 // The following accessors return pristine values, even if a script
524 // replaces the global object's associated property.
526 GetterSetter* speciesGetterSetter() const { return m_speciesGetterSetter.get(); }
528 RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); }
530 ErrorConstructor* errorConstructor() const { return m_errorConstructor.get(); }
531 ArrayConstructor* arrayConstructor() const { return m_arrayConstructor.get(); }
532 ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); }
533 JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); }
534 JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); }
535 NativeErrorConstructor* evalErrorConstructor() const { return m_evalErrorConstructor.get(this); }
536 NativeErrorConstructor* rangeErrorConstructor() const { return m_rangeErrorConstructor.get(); }
537 NativeErrorConstructor* referenceErrorConstructor() const { return m_referenceErrorConstructor.get(this); }
538 NativeErrorConstructor* syntaxErrorConstructor() const { return m_syntaxErrorConstructor.get(this); }
539 NativeErrorConstructor* typeErrorConstructor() const { return m_typeErrorConstructor.get(); }
540 NativeErrorConstructor* URIErrorConstructor() const { return m_URIErrorConstructor.get(this); }
542 NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
543 NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
545 JSFunction* parseIntFunction() const { return m_parseIntFunction.get(); }
546 JSFunction* parseFloatFunction() const { return m_parseFloatFunction.get(); }
548 JSFunction* evalFunction() const { return m_evalFunction.get(); }
549 JSFunction* callFunction() const { return m_callFunction.get(); }
550 JSFunction* applyFunction() const { return m_applyFunction.get(); }
551 JSFunction* throwTypeErrorFunction() const { return m_throwTypeErrorFunction.get(); }
552 JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); }
553 JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
554 JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(this); }
555 JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); }
556 JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); }
557 JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); }
558 JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.get(); }
559 JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
560 JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
561 JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); }
562 JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); }
563 JSObject* regExpProtoGlobalGetter() const { return m_regExpProtoGlobalGetter.get(); }
564 JSObject* regExpProtoUnicodeGetter() const { return m_regExpProtoUnicodeGetter.get(); }
565 GetterSetter* throwTypeErrorArgumentsCalleeAndCallerGetterSetter()
567 return m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.get();
570 JSModuleLoader* moduleLoader() const { return m_moduleLoader.get(); }
572 ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
573 FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
574 ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
575 BooleanPrototype* booleanPrototype() const { return m_booleanPrototype.get(); }
576 StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
577 SymbolPrototype* symbolPrototype() const { return m_symbolPrototype.get(); }
578 NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
579 BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); }
580 JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
581 RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
582 ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
583 IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
584 AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); }
585 GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
586 GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); }
587 AsyncFunctionPrototype* asyncFunctionPrototype() const { return m_asyncFunctionPrototype.get(); }
588 MapPrototype* mapPrototype() const { return m_mapPrototype.get(); }
589 // Workaround for the name conflict between JSCell::setPrototype.
590 SetPrototype* jsSetPrototype() const { return m_setPrototype.get(); }
591 AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); }
592 AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); }
594 Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); }
595 Structure* withScopeStructure() const { return m_withScopeStructure.get(this); }
596 Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(); }
597 Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); }
598 Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(this); }
599 Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); }
600 Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); }
601 Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); }
602 Structure* objectStructureForObjectConstructor() const { return m_objectStructureForObjectConstructor.get(); }
603 Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
605 ASSERT(indexingType & IsArray);
606 return m_originalArrayStructureForIndexingShape[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
608 Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
610 ASSERT(indexingType & IsArray);
611 return m_arrayStructureForIndexingShapeDuringAllocation[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
613 Structure* arrayStructureForIndexingTypeDuringAllocation(ExecState* exec, IndexingType indexingType, JSValue newTarget) const
615 return InternalFunction::createSubclassStructure(exec, newTarget, arrayStructureForIndexingTypeDuringAllocation(indexingType));
617 Structure* arrayStructureForProfileDuringAllocation(ExecState* exec, ArrayAllocationProfile* profile, JSValue newTarget) const
619 return arrayStructureForIndexingTypeDuringAllocation(exec, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget);
622 bool isOriginalArrayStructure(Structure* structure)
624 return originalArrayStructureForIndexingType(structure->indexingType() | IsArray) == structure;
627 Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(); }
628 Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(this); }
629 Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(this); }
630 Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(this); }
631 Structure* propertyNameIteratorStructure() const { return m_propertyNameIteratorStructure.get(); }
632 #if JSC_OBJC_API_ENABLED
633 Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(this); }
634 Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(this); }
636 Structure* dateStructure() const { return m_dateStructure.get(this); }
637 Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(this); }
638 Structure* errorStructure() const { return m_errorStructure.get(); }
639 Structure* calleeStructure() const { return m_calleeStructure.get(); }
640 Structure* strictFunctionStructure() const { return m_strictFunctionStructure.get(); }
641 Structure* sloppyFunctionStructure() const { return m_sloppyFunctionStructure.get(); }
642 Structure* arrowFunctionStructure() const { return m_arrowFunctionStructure.get(); }
643 Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(this); }
644 Structure* customGetterSetterFunctionStructure() const { return m_customGetterSetterFunctionStructure.get(this); }
645 Structure* getterSetterStructure() const { return m_getterSetterStructure.get(); }
646 Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(this); }
647 PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
648 Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
649 Structure* mapStructure() const { return m_mapStructure.get(); }
650 Structure* regExpStructure() const { return m_regExpStructure.get(); }
651 Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); }
652 Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); }
653 Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); }
654 Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
655 Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
656 Structure* bigIntObjectStructure() const { return m_bigIntObjectStructure.get(); }
657 Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(); }
658 Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
659 Structure* regExpMatchesArrayWithGroupsStructure() const { return m_regExpMatchesArrayWithGroupsStructure.get(); }
660 Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(); }
661 Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(); }
662 Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(); }
663 Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(); }
664 Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(); }
665 Structure* moduleLoaderStructure() const { return m_moduleLoaderStructure.get(); }
666 Structure* restParameterStructure() const { return arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); }
667 #if ENABLE(WEBASSEMBLY)
668 Structure* webAssemblyModuleRecordStructure() const { return m_webAssemblyModuleRecordStructure.get(); }
669 Structure* webAssemblyFunctionStructure() const { return m_webAssemblyFunctionStructure.get(); }
670 Structure* webAssemblyWrapperFunctionStructure() const { return m_webAssemblyWrapperFunctionStructure.get(); }
671 Structure* webAssemblyToJSCalleeStructure() const { return m_webAssemblyToJSCalleeStructure.get(); }
672 #endif // ENABLE(WEBASSEMBLY)
674 JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
675 JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
677 #if ENABLE(REMOTE_INSPECTOR)
678 Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); }
679 JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
683 const HashSet<String>& intlCollatorAvailableLocales();
684 const HashSet<String>& intlDateTimeFormatAvailableLocales();
685 const HashSet<String>& intlNumberFormatAvailableLocales();
686 #endif // ENABLE(INTL)
688 void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
689 ConsoleClient* consoleClient() const { return m_consoleClient; }
691 void setName(const String&);
692 const String& name() const { return m_name; }
694 JSArrayBufferPrototype* arrayBufferPrototype(ArrayBufferSharingMode sharingMode) const
696 switch (sharingMode) {
697 case ArrayBufferSharingMode::Default:
698 return m_arrayBufferPrototype.get();
699 case ArrayBufferSharingMode::Shared:
700 return m_sharedArrayBufferPrototype.get();
703 Structure* arrayBufferStructure(ArrayBufferSharingMode sharingMode) const
705 switch (sharingMode) {
706 case ArrayBufferSharingMode::Default:
707 return m_arrayBufferStructure.get();
708 case ArrayBufferSharingMode::Shared:
709 return m_sharedArrayBufferStructure.get();
711 RELEASE_ASSERT_NOT_REACHED();
715 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
716 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
718 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
719 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
720 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
721 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
723 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
725 #define DEFINE_ACCESSORS_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
726 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(this); }
728 FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE)
730 #undef DEFINE_ACCESSORS_FOR_LAZY_TYPE
732 LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type)
736 RELEASE_ASSERT_NOT_REACHED();
737 return m_typedArrayInt8;
738 #define TYPED_ARRAY_TYPE_CASE(name) case Type ## name: return m_typedArray ## name;
739 FOR_EACH_TYPED_ARRAY_TYPE(TYPED_ARRAY_TYPE_CASE)
740 #undef TYPED_ARRAY_TYPE_CASE
742 RELEASE_ASSERT_NOT_REACHED();
743 return m_typedArrayInt8;
745 const LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) const
747 return const_cast<const LazyClassStructure&>(const_cast<JSGlobalObject*>(this)->lazyTypedArrayStructure(type));
750 Structure* typedArrayStructure(TypedArrayType type) const
752 return lazyTypedArrayStructure(type).get(this);
754 Structure* typedArrayStructureConcurrently(TypedArrayType type) const
756 return lazyTypedArrayStructure(type).getConcurrently();
758 bool isOriginalTypedArrayStructure(Structure* structure)
760 TypedArrayType type = structure->classInfo()->typedArrayStorageType;
761 if (type == NotTypedArray)
763 return typedArrayStructureConcurrently(type) == structure;
766 JSObject* typedArrayConstructor(TypedArrayType type) const
768 return lazyTypedArrayStructure(type).constructor(this);
771 JSCell* actualPointerFor(Special::Pointer pointer)
773 ASSERT(pointer < Special::TableSize);
774 return m_specialPointers[pointer];
776 JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type)
778 unsigned index = static_cast<unsigned>(type);
779 ASSERT(index < LinkTimeConstantCount);
780 return m_linkTimeConstants[index];
783 WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
784 WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
785 WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); }
787 bool isHavingABadTime() const
789 return m_havingABadTimeWatchpoint->hasBeenInvalidated();
792 void haveABadTime(VM&);
794 bool objectPrototypeIsSane();
795 bool arrayPrototypeChainIsSane();
796 bool stringPrototypeChainIsSane();
798 void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
799 unsigned profileGroup() const
803 return m_rareData->profileGroup;
806 Debugger* debugger() const { return m_debugger; }
807 void setDebugger(Debugger* debugger) { m_debugger = debugger; }
809 const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
811 static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
813 JS_EXPORT_PRIVATE ExecState* globalExec();
815 static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
816 static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
817 static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
819 void queueMicrotask(Ref<Microtask>&&);
821 bool evalEnabled() const { return m_evalEnabled; }
822 bool webAssemblyEnabled() const { return m_webAssemblyEnabled; }
823 const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
824 const String& webAssemblyDisabledErrorMessage() const { return m_webAssemblyDisabledErrorMessage; }
825 void setEvalEnabled(bool enabled, const String& errorMessage = String())
827 m_evalEnabled = enabled;
828 m_evalDisabledErrorMessage = errorMessage;
830 void setWebAssemblyEnabled(bool enabled, const String& errorMessage = String())
832 m_webAssemblyEnabled = enabled;
833 m_webAssemblyDisabledErrorMessage = errorMessage;
836 void resetPrototype(VM&, JSValue prototype);
838 VM& vm() const { return m_vm; }
839 JSObject* globalThis() const;
840 WriteBarrier<JSObject>* addressOfGlobalThis() { return &m_globalThis; }
842 static Structure* createStructure(VM& vm, JSValue prototype)
844 Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
845 result->setTransitionWatchpointIsLikelyToBeFired(true);
849 void registerWeakMap(OpaqueJSWeakObjectMap* map)
851 createRareDataIfNeeded();
852 m_rareData->weakMaps.add(map);
855 void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
858 m_rareData->weakMaps.remove(map);
861 OpaqueJSClassDataMap& opaqueJSClassData()
863 createRareDataIfNeeded();
864 return m_rareData->opaqueJSClassData;
867 TemplateRegistry& templateRegistry() { return m_templateRegistry; }
869 static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); }
870 double weakRandomNumber() { return m_weakRandom.get(); }
871 unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
872 WeakRandom& weakRandom() { return m_weakRandom; }
874 bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
876 #if JSC_OBJC_API_ENABLED
877 JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
878 void setWrapperMap(JSWrapperMap* map) { m_wrapperMap = map; }
882 struct GlobalPropertyInfo {
883 GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
890 const Identifier identifier;
894 JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
896 void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; }
899 friend class LLIntOffsetsExtractor;
901 void setGlobalThis(VM&, JSObject* globalThis);
903 JS_EXPORT_PRIVATE void init(VM&);
905 JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
907 bool m_needsSiteSpecificQuirks { false };
908 #if JSC_OBJC_API_ENABLED
909 RetainPtr<JSWrapperMap> m_wrapperMap;
913 JSGlobalObject* asGlobalObject(JSValue);
915 inline JSGlobalObject* asGlobalObject(JSValue value)
917 ASSERT(asObject(value)->isGlobalObject());
918 return jsCast<JSGlobalObject*>(asObject(value));
921 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0, JSValue newTarget = JSValue())
923 VM& vm = globalObject->vm();
924 auto scope = DECLARE_THROW_SCOPE(vm);
925 Structure* structure;
926 if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)
927 structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(exec, ArrayWithArrayStorage, newTarget);
929 structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
930 RETURN_IF_EXCEPTION(scope, nullptr);
932 JSArray* result = JSArray::tryCreate(vm, structure, initialLength);
933 if (UNLIKELY(!result)) {
934 throwOutOfMemoryError(exec, scope);
937 return ArrayAllocationProfile::updateLastAllocationFor(profile, result);
940 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue())
942 return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength, newTarget);
945 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values, JSValue newTarget = JSValue())
947 VM& vm = globalObject->vm();
948 auto scope = DECLARE_THROW_SCOPE(vm);
949 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
950 RETURN_IF_EXCEPTION(scope, nullptr);
951 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values));
954 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue())
956 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, newTarget);
959 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
961 VM& vm = globalObject->vm();
962 auto scope = DECLARE_THROW_SCOPE(vm);
963 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
964 RETURN_IF_EXCEPTION(scope, nullptr);
965 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values, length));
968 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
970 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
973 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
975 VM& vm = globalObject->vm();
976 auto scope = DECLARE_THROW_SCOPE(vm);
977 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
978 RETURN_IF_EXCEPTION(scope, nullptr);
979 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, structure, values, length));
982 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
984 return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
987 inline JSObject* ExecState::globalThisValue() const
989 return lexicalGlobalObject()->globalThis();
992 inline JSObject* JSScope::globalThis()
994 return globalObject()->globalThis();
997 inline JSObject* JSGlobalObject::globalThis() const
999 return m_globalThis.get();