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