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 LazyProperty<JSGlobalObject, JSFunction> m_parseIntFunction;
291 LazyProperty<JSGlobalObject, JSFunction> m_parseFloatFunction;
292
293 WriteBarrier<JSFunction> m_callFunction;
294 WriteBarrier<JSFunction> m_applyFunction;
295 WriteBarrier<JSFunction> m_throwTypeErrorFunction;
296 LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoToStringFunction;
297 LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction;
298 LazyProperty<JSGlobalObject, JSFunction> m_evalFunction;
299 LazyProperty<JSGlobalObject, JSFunction> m_initializePromiseFunction;
300 LazyProperty<JSGlobalObject, JSFunction> m_iteratorProtocolFunction;
301 LazyProperty<JSGlobalObject, JSFunction> m_promiseResolveFunction;
302 WriteBarrier<JSFunction> m_objectProtoValueOfFunction;
303 WriteBarrier<JSFunction> m_numberProtoToStringFunction;
304 WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
305 WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction;
306 LazyProperty<JSGlobalObject, GetterSetter> m_throwTypeErrorGetterSetter;
307 WriteBarrier<JSObject> m_regExpProtoExec;
308 WriteBarrier<JSObject> m_regExpProtoSymbolReplace;
309 WriteBarrier<JSObject> m_regExpProtoGlobalGetter;
310 WriteBarrier<JSObject> m_regExpProtoUnicodeGetter;
311 WriteBarrier<GetterSetter> m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter;
312
313 LazyProperty<JSGlobalObject, JSModuleLoader> m_moduleLoader;
314
315 WriteBarrier<ObjectPrototype> m_objectPrototype;
316 WriteBarrier<FunctionPrototype> m_functionPrototype;
317 WriteBarrier<ArrayPrototype> m_arrayPrototype;
318 WriteBarrier<RegExpPrototype> m_regExpPrototype;
319 WriteBarrier<IteratorPrototype> m_iteratorPrototype;
320 WriteBarrier<AsyncIteratorPrototype> m_asyncIteratorPrototype;
321 WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype;
322 WriteBarrier<GeneratorPrototype> m_generatorPrototype;
323 WriteBarrier<AsyncGeneratorPrototype> m_asyncGeneratorPrototype;
324
325 LazyProperty<JSGlobalObject, Structure> m_debuggerScopeStructure;
326 LazyProperty<JSGlobalObject, Structure> m_withScopeStructure;
327 LazyProperty<JSGlobalObject, Structure> m_strictEvalActivationStructure;
328 WriteBarrier<Structure> m_lexicalEnvironmentStructure;
329 LazyProperty<JSGlobalObject, Structure> m_moduleEnvironmentStructure;
330 WriteBarrier<Structure> m_directArgumentsStructure;
331 WriteBarrier<Structure> m_scopedArgumentsStructure;
332 WriteBarrier<Structure> m_clonedArgumentsStructure;
333
334 WriteBarrier<Structure> m_objectStructureForObjectConstructor;
335
336 // Lists the actual structures used for having these particular indexing shapes.
337 WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfArrayIndexingModes];
338 // Lists the structures we should use during allocation for these particular indexing shapes.
339 // These structures will differ from the originals list above when we are having a bad time.
340 WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfArrayIndexingModes];
341
342 LazyProperty<JSGlobalObject, Structure> m_callbackConstructorStructure;
343 LazyProperty<JSGlobalObject, Structure> m_callbackFunctionStructure;
344 LazyProperty<JSGlobalObject, Structure> m_callbackObjectStructure;
345#if JSC_OBJC_API_ENABLED
346 LazyProperty<JSGlobalObject, Structure> m_objcCallbackFunctionStructure;
347 LazyProperty<JSGlobalObject, Structure> m_objcWrapperObjectStructure;
348#endif
349#ifdef JSC_GLIB_API_ENABLED
350 LazyProperty<JSGlobalObject, Structure> m_glibCallbackFunctionStructure;
351 LazyProperty<JSGlobalObject, Structure> m_glibWrapperObjectStructure;
352#endif
353 WriteBarrier<Structure> m_nullPrototypeObjectStructure;
354 WriteBarrier<Structure> m_calleeStructure;
355
356 WriteBarrier<Structure> m_hostFunctionStructure;
357
358 struct FunctionStructures {
359 WriteBarrier<Structure> arrowFunctionStructure;
360 WriteBarrier<Structure> sloppyFunctionStructure;
361 WriteBarrier<Structure> strictFunctionStructure;
362 };
363 FunctionStructures m_builtinFunctions;
364 FunctionStructures m_ordinaryFunctions;
365
366 LazyProperty<JSGlobalObject, Structure> m_boundFunctionStructure;
367 LazyProperty<JSGlobalObject, Structure> m_customGetterSetterFunctionStructure;
368 WriteBarrier<Structure> m_getterSetterStructure;
369 LazyProperty<JSGlobalObject, Structure> m_nativeStdFunctionStructure;
370 PropertyOffset m_functionNameOffset;
371 WriteBarrier<Structure> m_regExpStructure;
372 WriteBarrier<AsyncFunctionPrototype> m_asyncFunctionPrototype;
373 WriteBarrier<AsyncGeneratorFunctionPrototype> m_asyncGeneratorFunctionPrototype;
374 WriteBarrier<Structure> m_asyncFunctionStructure;
375 WriteBarrier<Structure> m_asyncGeneratorFunctionStructure;
376 WriteBarrier<Structure> m_generatorFunctionStructure;
377 LazyProperty<JSGlobalObject, Structure> m_iteratorResultObjectStructure;
378 WriteBarrier<Structure> m_regExpMatchesArrayStructure;
379 WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure;
380 LazyProperty<JSGlobalObject, Structure> m_moduleRecordStructure;
381 LazyProperty<JSGlobalObject, Structure> m_moduleNamespaceObjectStructure;
382 LazyProperty<JSGlobalObject, Structure> m_proxyObjectStructure;
383 LazyProperty<JSGlobalObject, Structure> m_callableProxyObjectStructure;
384 LazyProperty<JSGlobalObject, Structure> m_proxyRevokeStructure;
385#if ENABLE(SHARED_ARRAY_BUFFER)
386 WriteBarrier<JSArrayBufferPrototype> m_sharedArrayBufferPrototype;
387 WriteBarrier<Structure> m_sharedArrayBufferStructure;
388#endif
389
390#define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
391 WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
392 WriteBarrier<Structure> m_ ## properName ## Structure;
393
394#define DEFINE_STORAGE_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
395 LazyClassStructure m_ ## properName ## Structure;
396
397 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
398 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
399 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
400
401#if ENABLE(WEBASSEMBLY)
402 LazyProperty<JSGlobalObject, Structure> m_webAssemblyModuleRecordStructure;
403 LazyProperty<JSGlobalObject, Structure> m_webAssemblyFunctionStructure;
404 LazyProperty<JSGlobalObject, Structure> m_jsToWasmICCalleeStructure;
405 LazyProperty<JSGlobalObject, Structure> m_webAssemblyWrapperFunctionStructure;
406 LazyProperty<JSGlobalObject, Structure> m_webAssemblyToJSCalleeStructure;
407 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE)
408#endif // ENABLE(WEBASSEMBLY)
409
410 FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_STORAGE_FOR_LAZY_TYPE)
411
412#undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
413#undef DEFINE_STORAGE_FOR_LAZY_TYPE
414
415 WriteBarrier<GetterSetter> m_speciesGetterSetter;
416
417 LazyProperty<JSGlobalObject, JSTypedArrayViewPrototype> m_typedArrayProto;
418 LazyProperty<JSGlobalObject, JSTypedArrayViewConstructor> m_typedArraySuperConstructor;
419
420#define DECLARE_TYPED_ARRAY_TYPE_STRUCTURE(name) LazyClassStructure m_typedArray ## name;
421 FOR_EACH_TYPED_ARRAY_TYPE(DECLARE_TYPED_ARRAY_TYPE_STRUCTURE)
422#undef DECLARE_TYPED_ARRAY_TYPE_STRUCTURE
423
424 JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
425 JSCell* m_linkTimeConstants[LinkTimeConstantCount];
426
427 String m_name;
428
429 Debugger* m_debugger;
430
431 VM& m_vm;
432
433#if ENABLE(REMOTE_INSPECTOR)
434 std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController;
435 std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
436#endif
437
438#if ENABLE(INTL)
439 HashSet<String> m_intlCollatorAvailableLocales;
440 HashSet<String> m_intlDateTimeFormatAvailableLocales;
441 HashSet<String> m_intlNumberFormatAvailableLocales;
442 HashSet<String> m_intlPluralRulesAvailableLocales;
443#endif // ENABLE(INTL)
444
445 RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
446 RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
447 RefPtr<WatchpointSet> m_varInjectionWatchpoint;
448
449 std::unique_ptr<JSGlobalObjectRareData> m_rareData;
450
451 WeakRandom m_weakRandom;
452 RegExpGlobalData m_regExpGlobalData;
453
454 JSCallee* stackOverflowFrameCallee() const { return m_stackOverflowFrameCallee.get(); }
455
456 InlineWatchpointSet& arrayIteratorProtocolWatchpoint() { return m_arrayIteratorProtocolWatchpoint; }
457 InlineWatchpointSet& mapIteratorProtocolWatchpoint() { return m_mapIteratorProtocolWatchpoint; }
458 InlineWatchpointSet& setIteratorProtocolWatchpoint() { return m_setIteratorProtocolWatchpoint; }
459 InlineWatchpointSet& stringIteratorProtocolWatchpoint() { return m_stringIteratorProtocolWatchpoint; }
460 InlineWatchpointSet& mapSetWatchpoint() { return m_mapSetWatchpoint; }
461 InlineWatchpointSet& setAddWatchpoint() { return m_setAddWatchpoint; }
462 InlineWatchpointSet& arraySpeciesWatchpoint() { return m_arraySpeciesWatchpoint; }
463 InlineWatchpointSet& numberToStringWatchpoint()
464 {
465 RELEASE_ASSERT(VM::canUseJIT());
466 return m_numberToStringWatchpoint;
467 }
468 // If this hasn't been invalidated, it means the array iterator protocol
469 // is not observable to user code yet.
470 InlineWatchpointSet m_arrayIteratorProtocolWatchpoint;
471 InlineWatchpointSet m_mapIteratorProtocolWatchpoint;
472 InlineWatchpointSet m_setIteratorProtocolWatchpoint;
473 InlineWatchpointSet m_stringIteratorProtocolWatchpoint;
474 InlineWatchpointSet m_mapSetWatchpoint;
475 InlineWatchpointSet m_setAddWatchpoint;
476 InlineWatchpointSet m_arraySpeciesWatchpoint;
477 InlineWatchpointSet m_numberToStringWatchpoint;
478 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayConstructorSpeciesWatchpoint;
479 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeConstructorWatchpoint;
480 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayPrototypeSymbolIteratorWatchpoint;
481 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_arrayIteratorPrototypeNext;
482 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSymbolIteratorWatchpoint;
483 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapIteratorPrototypeNextWatchpoint;
484 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeSymbolIteratorWatchpoint;
485 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setIteratorPrototypeNextWatchpoint;
486 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringPrototypeSymbolIteratorWatchpoint;
487 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_stringIteratorPrototypeNextWatchpoint;
488 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_mapPrototypeSetWatchpoint;
489 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_setPrototypeAddWatchpoint;
490 std::unique_ptr<ObjectPropertyChangeAdaptiveWatchpoint<InlineWatchpointSet>> m_numberPrototypeToStringWatchpoint;
491
492 bool isArrayPrototypeIteratorProtocolFastAndNonObservable();
493 bool isMapPrototypeIteratorProtocolFastAndNonObservable();
494 bool isSetPrototypeIteratorProtocolFastAndNonObservable();
495 bool isStringPrototypeIteratorProtocolFastAndNonObservable();
496 bool isMapPrototypeSetFastAndNonObservable();
497 bool isSetPrototypeAddFastAndNonObservable();
498
499#if ENABLE(DFG_JIT)
500 using ReferencedGlobalPropertyWatchpointSets = HashMap<RefPtr<UniquedStringImpl>, Ref<WatchpointSet>, IdentifierRepHash>;
501 ReferencedGlobalPropertyWatchpointSets m_referencedGlobalPropertyWatchpointSets;
502 ConcurrentJSLock m_referencedGlobalPropertyWatchpointSetsLock;
503#endif
504
505 bool m_evalEnabled { true };
506 bool m_webAssemblyEnabled { true };
507 unsigned m_globalLexicalBindingEpoch { 1 };
508 String m_evalDisabledErrorMessage;
509 String m_webAssemblyDisabledErrorMessage;
510 RuntimeFlags m_runtimeFlags;
511 ConsoleClient* m_consoleClient { nullptr };
512 Optional<unsigned> m_stackTraceLimit;
513
514#if !ASSERT_DISABLED
515 const ExecState* m_callFrameAtDebuggerEntry { nullptr };
516#endif
517
518 static JS_EXPORT_PRIVATE const GlobalObjectMethodTable s_globalObjectMethodTable;
519 const GlobalObjectMethodTable* m_globalObjectMethodTable;
520
521 void createRareDataIfNeeded()
522 {
523 if (m_rareData)
524 return;
525 m_rareData = std::make_unique<JSGlobalObjectRareData>();
526 }
527
528public:
529 typedef JSSegmentedVariableObject Base;
530 static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | IsImmutablePrototypeExoticObject;
531
532 JS_EXPORT_PRIVATE static JSGlobalObject* create(VM&, Structure*);
533
534 DECLARE_EXPORT_INFO;
535
536 bool hasDebugger() const;
537 bool hasInteractiveDebugger() const;
538 const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; }
539
540#if ENABLE(DFG_JIT)
541 WatchpointSet* getReferencedPropertyWatchpointSet(UniquedStringImpl*);
542 WatchpointSet& ensureReferencedPropertyWatchpointSet(UniquedStringImpl*);
543#endif
544
545 Optional<unsigned> stackTraceLimit() const { return m_stackTraceLimit; }
546 void setStackTraceLimit(Optional<unsigned> value) { m_stackTraceLimit = value; }
547
548protected:
549 JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = nullptr);
550
551 JS_EXPORT_PRIVATE void finishCreation(VM&);
552
553 JS_EXPORT_PRIVATE void finishCreation(VM&, JSObject*);
554
555 void addGlobalVar(const Identifier&);
556
557public:
558 JS_EXPORT_PRIVATE ~JSGlobalObject();
559 JS_EXPORT_PRIVATE static void destroy(JSCell*);
560
561 JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
562
563 JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
564 JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
565
566 JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
567 JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
568 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
569
570 void addVar(ExecState* exec, const Identifier& propertyName)
571 {
572 if (!hasOwnProperty(exec, propertyName))
573 addGlobalVar(propertyName);
574 }
575 void addFunction(ExecState*, const Identifier&);
576
577 JSScope* globalScope() { return m_globalLexicalEnvironment.get(); }
578 JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); }
579
580 JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); }
581 void setGlobalScopeExtension(JSScope*);
582 void clearGlobalScopeExtension();
583
584 // The following accessors return pristine values, even if a script
585 // replaces the global object's associated property.
586
587 GetterSetter* speciesGetterSetter() const { return m_speciesGetterSetter.get(); }
588
589 ArrayConstructor* arrayConstructor() const { return m_arrayConstructor.get(); }
590 ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); }
591 JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); }
592 JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); }
593
594#if ENABLE(INTL)
595 IntlCollator* defaultCollator(ExecState*);
596#endif
597
598 NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
599 NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
600
601 JSFunction* parseIntFunction() const { return m_parseIntFunction.get(this); }
602 JSFunction* parseFloatFunction() const { return m_parseFloatFunction.get(this); }
603
604 JSFunction* evalFunction() const { return m_evalFunction.get(this); }
605 JSFunction* callFunction() const { return m_callFunction.get(); }
606 JSFunction* applyFunction() const { return m_applyFunction.get(); }
607 JSFunction* throwTypeErrorFunction() const { return m_throwTypeErrorFunction.get(); }
608 JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); }
609 JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
610 JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(this); }
611 JSFunction* iteratorProtocolFunction() const { return m_iteratorProtocolFunction.get(this); }
612 JSFunction* promiseResolveFunction() const { return m_promiseResolveFunction.get(this); }
613 JSFunction* objectProtoValueOfFunction() const { return m_objectProtoValueOfFunction.get(); }
614 JSFunction* numberProtoToStringFunction() const { return m_numberProtoToStringFunction.get(); }
615 JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
616 JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
617 JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); }
618 JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); }
619 JSObject* regExpProtoGlobalGetter() const { return m_regExpProtoGlobalGetter.get(); }
620 JSObject* regExpProtoUnicodeGetter() const { return m_regExpProtoUnicodeGetter.get(); }
621 GetterSetter* throwTypeErrorArgumentsCalleeAndCallerGetterSetter()
622 {
623 return m_throwTypeErrorArgumentsCalleeAndCallerGetterSetter.get();
624 }
625
626 JSModuleLoader* moduleLoader() const { return m_moduleLoader.get(this); }
627
628 ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
629 FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
630 ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
631 JSObject* booleanPrototype() const { return m_booleanObjectStructure.prototypeInitializedOnMainThread(this); }
632 StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
633 JSObject* numberPrototype() const { return m_numberObjectStructure.prototypeInitializedOnMainThread(this); }
634 BigIntPrototype* bigIntPrototype() const { return m_bigIntPrototype.get(); }
635 JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
636 JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototypeInitializedOnMainThread(this); }
637 RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
638 JSObject* errorPrototype() const { return m_errorStructure.prototype(this); }
639 IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
640 AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); }
641 GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
642 GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); }
643 AsyncFunctionPrototype* asyncFunctionPrototype() const { return m_asyncFunctionPrototype.get(); }
644 MapPrototype* mapPrototype() const { return m_mapPrototype.get(); }
645 // Workaround for the name conflict between JSCell::setPrototype.
646 SetPrototype* jsSetPrototype() const { return m_setPrototype.get(); }
647 JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); }
648 AsyncGeneratorPrototype* asyncGeneratorPrototype() const { return m_asyncGeneratorPrototype.get(); }
649 AsyncGeneratorFunctionPrototype* asyncGeneratorFunctionPrototype() const { return m_asyncGeneratorFunctionPrototype.get(); }
650
651 Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(this); }
652 Structure* withScopeStructure() const { return m_withScopeStructure.get(this); }
653 Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(this); }
654 Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); }
655 Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(this); }
656 Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); }
657 Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); }
658 Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); }
659 Structure* objectStructureForObjectConstructor() const { return m_objectStructureForObjectConstructor.get(); }
660 Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
661 {
662 ASSERT(indexingType & IsArray);
663 return m_originalArrayStructureForIndexingShape[arrayIndexFromIndexingType(indexingType)].get();
664 }
665 Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
666 {
667 ASSERT(indexingType & IsArray);
668 return m_arrayStructureForIndexingShapeDuringAllocation[arrayIndexFromIndexingType(indexingType)].get();
669 }
670 Structure* arrayStructureForIndexingTypeDuringAllocation(ExecState* exec, IndexingType indexingType, JSValue newTarget) const
671 {
672 return InternalFunction::createSubclassStructure(exec, newTarget, arrayStructureForIndexingTypeDuringAllocation(indexingType));
673 }
674 Structure* arrayStructureForProfileDuringAllocation(ExecState* exec, ArrayAllocationProfile* profile, JSValue newTarget) const
675 {
676 return arrayStructureForIndexingTypeDuringAllocation(exec, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget);
677 }
678
679 bool isOriginalArrayStructure(Structure* structure)
680 {
681 return originalArrayStructureForIndexingType(structure->indexingMode() | IsArray) == structure;
682 }
683
684 Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(this); }
685 Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(this); }
686 Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(this); }
687 Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(this); }
688#if JSC_OBJC_API_ENABLED
689 Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(this); }
690 Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(this); }
691#endif
692#ifdef JSC_GLIB_API_ENABLED
693 Structure* glibCallbackFunctionStructure() const { return m_glibCallbackFunctionStructure.get(this); }
694 Structure* glibWrapperObjectStructure() const { return m_glibWrapperObjectStructure.get(this); }
695#endif
696 Structure* dateStructure() const { return m_dateStructure.get(this); }
697 Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(this); }
698 Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
699 Structure* errorStructure() const { return m_errorStructure.get(this); }
700 Structure* errorStructure(ErrorType errorType) const
701 {
702 switch (errorType) {
703 case ErrorType::Error:
704 return errorStructure();
705 case ErrorType::EvalError:
706 return m_evalErrorStructure.get(this);
707 case ErrorType::RangeError:
708 return m_rangeErrorStructure.get(this);
709 case ErrorType::ReferenceError:
710 return m_referenceErrorStructure.get(this);
711 case ErrorType::SyntaxError:
712 return m_syntaxErrorStructure.get(this);
713 case ErrorType::TypeError:
714 return m_typeErrorStructure.get(this);
715 case ErrorType::URIError:
716 return m_URIErrorStructure.get(this);
717 }
718 ASSERT_NOT_REACHED();
719 return nullptr;
720 }
721 Structure* calleeStructure() const { return m_calleeStructure.get(); }
722 Structure* hostFunctionStructure() const { return m_hostFunctionStructure.get(); }
723
724 Structure* arrowFunctionStructure(bool isBuiltin) const
725 {
726 if (isBuiltin)
727 return m_builtinFunctions.arrowFunctionStructure.get();
728 return m_ordinaryFunctions.arrowFunctionStructure.get();
729 }
730 Structure* sloppyFunctionStructure(bool isBuiltin) const
731 {
732 if (isBuiltin)
733 return m_builtinFunctions.sloppyFunctionStructure.get();
734 return m_ordinaryFunctions.sloppyFunctionStructure.get();
735 }
736 Structure* strictFunctionStructure(bool isBuiltin) const
737 {
738 if (isBuiltin)
739 return m_builtinFunctions.strictFunctionStructure.get();
740 return m_ordinaryFunctions.strictFunctionStructure.get();
741 }
742
743 Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(this); }
744 Structure* customGetterSetterFunctionStructure() const { return m_customGetterSetterFunctionStructure.get(this); }
745 Structure* getterSetterStructure() const { return m_getterSetterStructure.get(); }
746 Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(this); }
747 PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
748 Structure* numberObjectStructure() const { return m_numberObjectStructure.get(this); }
749 Structure* mapStructure() const { return m_mapStructure.get(); }
750 Structure* regExpStructure() const { return m_regExpStructure.get(); }
751 Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); }
752 Structure* asyncFunctionStructure() const { return m_asyncFunctionStructure.get(); }
753 Structure* asyncGeneratorFunctionStructure() const { return m_asyncGeneratorFunctionStructure.get(); }
754 Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
755 Structure* bigIntObjectStructure() const { return m_bigIntObjectStructure.get(); }
756 Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(this); }
757 Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
758 Structure* regExpMatchesArrayWithGroupsStructure() const { return m_regExpMatchesArrayWithGroupsStructure.get(); }
759 Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(this); }
760 Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(this); }
761 Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(this); }
762 Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(this); }
763 Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(this); }
764 Structure* restParameterStructure() const { return arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous); }
765 Structure* originalRestParameterStructure() const { return originalArrayStructureForIndexingType(ArrayWithContiguous); }
766#if ENABLE(WEBASSEMBLY)
767 Structure* webAssemblyModuleRecordStructure() const { return m_webAssemblyModuleRecordStructure.get(this); }
768 Structure* webAssemblyFunctionStructure() const { return m_webAssemblyFunctionStructure.get(this); }
769 Structure* jsToWasmICCalleeStructure() const { return m_jsToWasmICCalleeStructure.get(this); }
770 Structure* webAssemblyWrapperFunctionStructure() const { return m_webAssemblyWrapperFunctionStructure.get(this); }
771 Structure* webAssemblyToJSCalleeStructure() const { return m_webAssemblyToJSCalleeStructure.get(this); }
772#endif // ENABLE(WEBASSEMBLY)
773#if ENABLE(INTL)
774 Structure* collatorStructure() { return m_collatorStructure.get(this); }
775 Structure* numberFormatStructure() { return m_numberFormatStructure.get(this); }
776 Structure* dateTimeFormatStructure() { return m_dateTimeFormatStructure.get(this); }
777 Structure* pluralRulesStructure() { return m_pluralRulesStructure.get(this); }
778#endif // ENABLE(INTL)
779
780 JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
781 JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
782
783 RegExpGlobalData& regExpGlobalData() { return m_regExpGlobalData; }
784 static ptrdiff_t regExpGlobalDataOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_regExpGlobalData); }
785
786#if ENABLE(REMOTE_INSPECTOR)
787 Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); }
788 JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
789#endif
790
791#if ENABLE(INTL)
792 const HashSet<String>& intlCollatorAvailableLocales();
793 const HashSet<String>& intlDateTimeFormatAvailableLocales();
794 const HashSet<String>& intlNumberFormatAvailableLocales();
795 const HashSet<String>& intlPluralRulesAvailableLocales();
796#endif // ENABLE(INTL)
797
798 void bumpGlobalLexicalBindingEpoch(VM&);
799 unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; }
800 static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); }
801 unsigned* addressOfGlobalLexicalBindingEpoch() { return &m_globalLexicalBindingEpoch; }
802
803 void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
804 ConsoleClient* consoleClient() const { return m_consoleClient; }
805
806 void setName(const String&);
807 const String& name() const { return m_name; }
808
809 JSObject* arrayBufferConstructor() const { return m_arrayBufferStructure.constructor(this); }
810
811 JSObject* arrayBufferPrototype(ArrayBufferSharingMode sharingMode) const
812 {
813 switch (sharingMode) {
814 case ArrayBufferSharingMode::Default:
815 return m_arrayBufferStructure.prototype(this);
816#if ENABLE(SHARED_ARRAY_BUFFER)
817 case ArrayBufferSharingMode::Shared:
818 return m_sharedArrayBufferPrototype.get();
819#else
820 default:
821 return m_arrayBufferStructure.prototype(this);
822#endif
823 }
824 }
825 Structure* arrayBufferStructure(ArrayBufferSharingMode sharingMode) const
826 {
827 switch (sharingMode) {
828 case ArrayBufferSharingMode::Default:
829 return m_arrayBufferStructure.get(this);
830#if ENABLE(SHARED_ARRAY_BUFFER)
831 case ArrayBufferSharingMode::Shared:
832 return m_sharedArrayBufferStructure.get();
833#else
834 default:
835 return m_arrayBufferStructure.get(this);
836#endif
837 }
838 RELEASE_ASSERT_NOT_REACHED();
839 return nullptr;
840 }
841
842#define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
843 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
844
845 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
846 FOR_BIG_INT_BUILTIN_TYPE_WITH_CONSTRUCTOR(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
847 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
848
849#undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
850
851#define DEFINE_ACCESSORS_FOR_LAZY_TYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
852 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(this); } \
853 JSObject* properName ## Constructor() { return m_ ## properName ## Structure.constructor(this); }
854
855 FOR_EACH_LAZY_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE)
856 FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_ACCESSORS_FOR_LAZY_TYPE)
857
858#undef DEFINE_ACCESSORS_FOR_LAZY_TYPE
859
860 LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type)
861 {
862 switch (type) {
863 case NotTypedArray:
864 RELEASE_ASSERT_NOT_REACHED();
865 return m_typedArrayInt8;
866#define TYPED_ARRAY_TYPE_CASE(name) case Type ## name: return m_typedArray ## name;
867 FOR_EACH_TYPED_ARRAY_TYPE(TYPED_ARRAY_TYPE_CASE)
868#undef TYPED_ARRAY_TYPE_CASE
869 }
870 RELEASE_ASSERT_NOT_REACHED();
871 return m_typedArrayInt8;
872 }
873 const LazyClassStructure& lazyTypedArrayStructure(TypedArrayType type) const
874 {
875 return const_cast<const LazyClassStructure&>(const_cast<JSGlobalObject*>(this)->lazyTypedArrayStructure(type));
876 }
877
878 Structure* typedArrayStructure(TypedArrayType type) const
879 {
880 return lazyTypedArrayStructure(type).get(this);
881 }
882 Structure* typedArrayStructureConcurrently(TypedArrayType type) const
883 {
884 return lazyTypedArrayStructure(type).getConcurrently();
885 }
886 bool isOriginalTypedArrayStructure(Structure* structure)
887 {
888 TypedArrayType type = structure->classInfo()->typedArrayStorageType;
889 if (type == NotTypedArray)
890 return false;
891 return typedArrayStructureConcurrently(type) == structure;
892 }
893
894 JSObject* typedArrayConstructor(TypedArrayType type) const
895 {
896 return lazyTypedArrayStructure(type).constructor(this);
897 }
898
899 JSCell* actualPointerFor(Special::Pointer pointer)
900 {
901 ASSERT(pointer < Special::TableSize);
902 return m_specialPointers[pointer];
903 }
904 JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type)
905 {
906 unsigned index = static_cast<unsigned>(type);
907 ASSERT(index < LinkTimeConstantCount);
908 return m_linkTimeConstants[index];
909 }
910
911 WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
912 WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
913 WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); }
914
915 bool isHavingABadTime() const
916 {
917 return m_havingABadTimeWatchpoint->hasBeenInvalidated();
918 }
919
920 void haveABadTime(VM&);
921
922 bool objectPrototypeIsSane();
923 bool arrayPrototypeChainIsSane();
924 bool stringPrototypeChainIsSane();
925
926 void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
927 unsigned profileGroup() const
928 {
929 if (!m_rareData)
930 return 0;
931 return m_rareData->profileGroup;
932 }
933
934 Debugger* debugger() const { return m_debugger; }
935 void setDebugger(Debugger*);
936
937 const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
938
939 static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
940
941 JS_EXPORT_PRIVATE ExecState* globalExec();
942
943 static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
944 static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
945 static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
946
947 JS_EXPORT_PRIVATE void queueMicrotask(Ref<Microtask>&&);
948
949 bool evalEnabled() const { return m_evalEnabled; }
950 bool webAssemblyEnabled() const { return m_webAssemblyEnabled; }
951 const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
952 const String& webAssemblyDisabledErrorMessage() const { return m_webAssemblyDisabledErrorMessage; }
953 void setEvalEnabled(bool enabled, const String& errorMessage = String())
954 {
955 m_evalEnabled = enabled;
956 m_evalDisabledErrorMessage = errorMessage;
957 }
958 void setWebAssemblyEnabled(bool enabled, const String& errorMessage = String())
959 {
960 m_webAssemblyEnabled = enabled;
961 m_webAssemblyDisabledErrorMessage = errorMessage;
962 }
963
964#if !ASSERT_DISABLED
965 const ExecState* callFrameAtDebuggerEntry() const { return m_callFrameAtDebuggerEntry; }
966 void setCallFrameAtDebuggerEntry(const ExecState* callFrame) { m_callFrameAtDebuggerEntry = callFrame; }
967#endif
968
969 void resetPrototype(VM&, JSValue prototype);
970
971 VM& vm() const { return m_vm; }
972 JSObject* globalThis() const;
973 WriteBarrier<JSObject>* addressOfGlobalThis() { return &m_globalThis; }
974 OptionSet<CodeGenerationMode> defaultCodeGenerationMode() const;
975
976 static Structure* createStructure(VM& vm, JSValue prototype)
977 {
978 Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
979 result->setTransitionWatchpointIsLikelyToBeFired(true);
980 return result;
981 }
982
983 void registerWeakMap(OpaqueJSWeakObjectMap* map)
984 {
985 createRareDataIfNeeded();
986 m_rareData->weakMaps.add(map);
987 }
988
989 void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
990 {
991 if (m_rareData)
992 m_rareData->weakMaps.remove(map);
993 }
994
995 OpaqueJSClassDataMap& opaqueJSClassData()
996 {
997 createRareDataIfNeeded();
998 return m_rareData->opaqueJSClassData;
999 }
1000
1001 static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); }
1002 double weakRandomNumber() { return m_weakRandom.get(); }
1003 unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
1004 WeakRandom& weakRandom() { return m_weakRandom; }
1005
1006 bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
1007 JS_EXPORT_PRIVATE void exposeDollarVM(VM&);
1008
1009#if JSC_OBJC_API_ENABLED
1010 JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
1011 void setWrapperMap(JSWrapperMap* map) { m_wrapperMap = map; }
1012 void setAPIWrapper(void* apiWrapper) { m_apiWrapper = apiWrapper; }
1013 void* apiWrapper() const { return m_apiWrapper; }
1014#endif
1015#ifdef JSC_GLIB_API_ENABLED
1016 WrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
1017 void setWrapperMap(std::unique_ptr<WrapperMap>&&);
1018#endif
1019
1020 void tryInstallArraySpeciesWatchpoint(ExecState*);
1021
1022protected:
1023 struct GlobalPropertyInfo {
1024 GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
1025 : identifier(i)
1026 , value(v)
1027 , attributes(a)
1028 {
1029 }
1030
1031 const Identifier identifier;
1032 JSValue value;
1033 unsigned attributes;
1034 };
1035 JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
1036
1037 void setNeedsSiteSpecificQuirks(bool needQuirks) { m_needsSiteSpecificQuirks = needQuirks; }
1038
1039private:
1040 friend class LLIntOffsetsExtractor;
1041
1042 void fireWatchpointAndMakeAllArrayStructuresSlowPut(VM&);
1043 void setGlobalThis(VM&, JSObject* globalThis);
1044
1045 template<ErrorType errorType>
1046 void initializeErrorConstructor(LazyClassStructure::Initializer&);
1047
1048 JS_EXPORT_PRIVATE void init(VM&);
1049 void fixupPrototypeChainWithObjectPrototype(VM&);
1050
1051 JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
1052
1053 bool m_needsSiteSpecificQuirks { false };
1054#if JSC_OBJC_API_ENABLED
1055 RetainPtr<JSWrapperMap> m_wrapperMap;
1056 void* m_apiWrapper { nullptr };
1057#endif
1058#ifdef JSC_GLIB_API_ENABLED
1059 std::unique_ptr<WrapperMap> m_wrapperMap;
1060#endif
1061};
1062
1063inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0, JSValue newTarget = JSValue())
1064{
1065 VM& vm = globalObject->vm();
1066 auto scope = DECLARE_THROW_SCOPE(vm);
1067 Structure* structure;
1068 if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)
1069 structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(exec, ArrayWithArrayStorage, newTarget);
1070 else
1071 structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1072 RETURN_IF_EXCEPTION(scope, nullptr);
1073
1074 JSArray* result = JSArray::tryCreate(vm, structure, initialLength);
1075 if (UNLIKELY(!result)) {
1076 throwOutOfMemoryError(exec, scope);
1077 return nullptr;
1078 }
1079 return ArrayAllocationProfile::updateLastAllocationFor(profile, result);
1080}
1081
1082inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue())
1083{
1084 return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength, newTarget);
1085}
1086
1087inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values, JSValue newTarget = JSValue())
1088{
1089 VM& vm = globalObject->vm();
1090 auto scope = DECLARE_THROW_SCOPE(vm);
1091 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1092 RETURN_IF_EXCEPTION(scope, nullptr);
1093 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values));
1094}
1095
1096inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue())
1097{
1098 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, newTarget);
1099}
1100
1101inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1102{
1103 VM& vm = globalObject->vm();
1104 auto scope = DECLARE_THROW_SCOPE(vm);
1105 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1106 RETURN_IF_EXCEPTION(scope, nullptr);
1107 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values, length));
1108}
1109
1110inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1111{
1112 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
1113}
1114
1115inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1116{
1117 VM& vm = globalObject->vm();
1118 auto scope = DECLARE_THROW_SCOPE(vm);
1119 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
1120 RETURN_IF_EXCEPTION(scope, nullptr);
1121 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, structure, values, length));
1122}
1123
1124inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
1125{
1126 return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
1127}
1128
1129inline JSObject* ExecState::globalThisValue() const
1130{
1131 return lexicalGlobalObject()->globalThis();
1132}
1133
1134inline JSObject* JSScope::globalThis()
1135{
1136 return globalObject()->globalThis();
1137}
1138
1139inline JSObject* JSGlobalObject::globalThis() const
1140{
1141 return m_globalThis.get();
1142}
1143
1144inline OptionSet<CodeGenerationMode> JSGlobalObject::defaultCodeGenerationMode() const
1145{
1146 OptionSet<CodeGenerationMode> codeGenerationMode;
1147 if (hasInteractiveDebugger() || Options::forceDebuggerBytecodeGeneration())
1148 codeGenerationMode.add(CodeGenerationMode::Debugger);
1149 if (m_vm.typeProfiler())
1150 codeGenerationMode.add(CodeGenerationMode::TypeProfiler);
1151 if (m_vm.controlFlowProfiler())
1152 codeGenerationMode.add(CodeGenerationMode::ControlFlowProfiler);
1153 return codeGenerationMode;
1154}
1155
1156} // namespace JSC
1157