2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007, 2008, 2009, 2014-2016 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef JSGlobalObject_h
23 #define JSGlobalObject_h
25 #include "ArrayAllocationProfile.h"
26 #include "InternalFunction.h"
28 #include "JSArrayBufferPrototype.h"
29 #include "JSClassRef.h"
30 #include "JSGlobalLexicalEnvironment.h"
32 #include "JSSegmentedVariableObject.h"
33 #include "JSWeakObjectMapRefInternal.h"
34 #include "NumberPrototype.h"
35 #include "RuntimeFlags.h"
36 #include "SpecialPointer.h"
37 #include "StringPrototype.h"
38 #include "SymbolPrototype.h"
39 #include "TemplateRegistry.h"
41 #include "Watchpoint.h"
42 #include <JavaScriptCore/JSBase.h>
44 #include <wtf/HashSet.h>
45 #include <wtf/PassRefPtr.h>
48 struct OpaqueJSClassContextData;
51 class JSGlobalObjectInspectorController;
57 class BooleanPrototype;
60 class ErrorConstructor;
64 class FunctionCodeBlock;
65 class FunctionExecutable;
66 class FunctionPrototype;
67 class GeneratorPrototype;
68 class GeneratorFunctionPrototype;
70 class GlobalCodeBlock;
72 class JSGlobalObjectDebuggable;
73 class JSInternalPromise;
75 class JSPromiseConstructor;
76 class JSPromisePrototype;
78 class LLIntOffsetsExtractor;
80 class ModuleLoaderObject;
81 class ModuleProgramExecutable;
82 class NativeErrorConstructor;
83 class NullGetterFunction;
84 class NullSetterFunction;
85 class ObjectConstructor;
86 class ProgramCodeBlock;
87 class ProgramExecutable;
88 class RegExpConstructor;
89 class RegExpPrototype;
91 class UnlinkedModuleProgramCodeBlock;
92 class VariableEnvironment;
93 enum class ThisTDZMode;
94 struct ActivationStackNode;
97 #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName)
99 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
100 macro(Set, set, set, JSSet, Set) \
101 macro(Map, map, map, JSMap, Map) \
102 macro(Date, date, date, DateInstance, Date) \
103 macro(String, string, stringObject, StringObject, String) \
104 macro(Symbol, symbol, symbolObject, SymbolObject, Symbol) \
105 macro(Boolean, boolean, booleanObject, BooleanObject, Boolean) \
106 macro(Number, number, numberObject, NumberObject, Number) \
107 macro(Error, error, error, ErrorInstance, Error) \
108 macro(JSPromise, promise, promise, JSPromise, Promise) \
109 macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
110 DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
111 DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \
113 #define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
114 DEFINE_STANDARD_BUILTIN(macro, ArrayIterator, arrayIterator) \
115 DEFINE_STANDARD_BUILTIN(macro, MapIterator, mapIterator) \
116 DEFINE_STANDARD_BUILTIN(macro, SetIterator, setIterator) \
117 DEFINE_STANDARD_BUILTIN(macro, StringIterator, stringIterator) \
119 #define FOR_EACH_BUILTIN_ITERATOR_TYPE(macro) \
120 DEFINE_STANDARD_BUILTIN(macro, Iterator, iterator) \
121 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
123 #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
124 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
125 macro(JSInternalPromise, internalPromise, internalPromise, JSInternalPromise, InternalPromise) \
127 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
128 class JS ## capitalName; \
129 class capitalName ## Prototype; \
130 class capitalName ## Constructor;
132 class IteratorPrototype;
133 FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
134 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
136 #undef DECLARE_SIMPLE_BUILTIN_TYPE
138 typedef Vector<ExecState*, 16> ExecStateStack;
140 struct GlobalObjectMethodTable {
141 typedef bool (*AllowsAccessFromFunctionPtr)(const JSGlobalObject*, ExecState*);
142 AllowsAccessFromFunctionPtr allowsAccessFrom;
144 typedef bool (*SupportsLegacyProfilingFunctionPtr)(const JSGlobalObject*);
145 SupportsLegacyProfilingFunctionPtr supportsLegacyProfiling;
147 typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*);
148 SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo;
150 typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*);
151 ShouldInterruptScriptFunctionPtr shouldInterruptScript;
153 typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr)(const JSGlobalObject*);
154 JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags;
156 typedef void (*QueueTaskToEventLoopFunctionPtr)(const JSGlobalObject*, PassRefPtr<Microtask>);
157 QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
159 typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*);
160 ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout;
162 typedef JSInternalPromise* (*ModuleLoaderResolvePtr)(JSGlobalObject*, ExecState*, JSValue, JSValue);
163 ModuleLoaderResolvePtr moduleLoaderResolve;
165 typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSValue);
166 ModuleLoaderFetchPtr moduleLoaderFetch;
168 typedef JSInternalPromise* (*ModuleLoaderTranslatePtr)(JSGlobalObject*, ExecState*, JSValue, JSValue);
169 ModuleLoaderTranslatePtr moduleLoaderTranslate;
171 typedef JSInternalPromise* (*ModuleLoaderInstantiatePtr)(JSGlobalObject*, ExecState*, JSValue, JSValue);
172 ModuleLoaderInstantiatePtr moduleLoaderInstantiate;
174 typedef JSValue (*ModuleLoaderEvaluatePtr)(JSGlobalObject*, ExecState*, JSValue, JSValue);
175 ModuleLoaderEvaluatePtr moduleLoaderEvaluate;
177 typedef String (*DefaultLanguageFunctionPtr)();
178 DefaultLanguageFunctionPtr defaultLanguage;
181 class JSGlobalObject : public JSSegmentedVariableObject {
183 typedef HashSet<RefPtr<OpaqueJSWeakObjectMap>> WeakMapSet;
184 typedef HashMap<OpaqueJSClass*, std::unique_ptr<OpaqueJSClassContextData>> OpaqueJSClassDataMap;
186 struct JSGlobalObjectRareData {
187 WTF_MAKE_FAST_ALLOCATED;
189 JSGlobalObjectRareData()
195 unsigned profileGroup;
197 OpaqueJSClassDataMap opaqueJSClassData;
201 Register m_globalCallFrame[JSStack::CallFrameHeaderSize];
203 WriteBarrier<JSObject> m_globalThis;
205 WriteBarrier<JSGlobalLexicalEnvironment> m_globalLexicalEnvironment;
206 WriteBarrier<JSObject> m_globalCallee;
207 WriteBarrier<RegExpConstructor> m_regExpConstructor;
208 WriteBarrier<ErrorConstructor> m_errorConstructor;
209 WriteBarrier<NativeErrorConstructor> m_evalErrorConstructor;
210 WriteBarrier<NativeErrorConstructor> m_rangeErrorConstructor;
211 WriteBarrier<NativeErrorConstructor> m_referenceErrorConstructor;
212 WriteBarrier<NativeErrorConstructor> m_syntaxErrorConstructor;
213 WriteBarrier<NativeErrorConstructor> m_typeErrorConstructor;
214 WriteBarrier<NativeErrorConstructor> m_URIErrorConstructor;
215 WriteBarrier<ObjectConstructor> m_objectConstructor;
216 WriteBarrier<JSPromiseConstructor> m_promiseConstructor;
217 WriteBarrier<JSInternalPromiseConstructor> m_internalPromiseConstructor;
219 WriteBarrier<NullGetterFunction> m_nullGetterFunction;
220 WriteBarrier<NullSetterFunction> m_nullSetterFunction;
222 WriteBarrier<JSFunction> m_parseIntFunction;
224 WriteBarrier<JSFunction> m_evalFunction;
225 WriteBarrier<JSFunction> m_callFunction;
226 WriteBarrier<JSFunction> m_applyFunction;
227 WriteBarrier<JSFunction> m_definePropertyFunction;
228 WriteBarrier<JSFunction> m_arrayProtoValuesFunction;
229 WriteBarrier<JSFunction> m_initializePromiseFunction;
230 WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
231 WriteBarrier<JSFunction> m_functionProtoHasInstanceSymbolFunction;
232 WriteBarrier<JSObject> m_regExpProtoExec;
233 WriteBarrier<JSObject> m_regExpProtoSymbolReplace;
234 WriteBarrier<JSObject> m_regExpProtoGlobalGetter;
235 WriteBarrier<JSObject> m_regExpProtoUnicodeGetter;
236 WriteBarrier<GetterSetter> m_throwTypeErrorGetterSetter;
237 WriteBarrier<GetterSetter> m_throwTypeErrorArgumentsAndCallerGetterSetter;
239 WriteBarrier<ModuleLoaderObject> m_moduleLoader;
241 WriteBarrier<ObjectPrototype> m_objectPrototype;
242 WriteBarrier<FunctionPrototype> m_functionPrototype;
243 WriteBarrier<ArrayPrototype> m_arrayPrototype;
244 WriteBarrier<RegExpPrototype> m_regExpPrototype;
245 WriteBarrier<IteratorPrototype> m_iteratorPrototype;
246 WriteBarrier<GeneratorFunctionPrototype> m_generatorFunctionPrototype;
247 WriteBarrier<GeneratorPrototype> m_generatorPrototype;
249 WriteBarrier<Structure> m_debuggerScopeStructure;
250 WriteBarrier<Structure> m_withScopeStructure;
251 WriteBarrier<Structure> m_strictEvalActivationStructure;
252 WriteBarrier<Structure> m_lexicalEnvironmentStructure;
253 WriteBarrier<Structure> m_moduleEnvironmentStructure;
254 WriteBarrier<Structure> m_directArgumentsStructure;
255 WriteBarrier<Structure> m_scopedArgumentsStructure;
256 WriteBarrier<Structure> m_clonedArgumentsStructure;
258 // Lists the actual structures used for having these particular indexing shapes.
259 WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfIndexingShapes];
260 // Lists the structures we should use during allocation for these particular indexing shapes.
261 // These structures will differ from the originals list above when we are having a bad time.
262 WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfIndexingShapes];
264 WriteBarrier<Structure> m_callbackConstructorStructure;
265 WriteBarrier<Structure> m_callbackFunctionStructure;
266 WriteBarrier<Structure> m_callbackObjectStructure;
267 WriteBarrier<Structure> m_propertyNameIteratorStructure;
268 #if JSC_OBJC_API_ENABLED
269 WriteBarrier<Structure> m_objcCallbackFunctionStructure;
270 WriteBarrier<Structure> m_objcWrapperObjectStructure;
272 WriteBarrier<Structure> m_nullPrototypeObjectStructure;
273 WriteBarrier<Structure> m_calleeStructure;
274 WriteBarrier<Structure> m_functionStructure;
275 WriteBarrier<Structure> m_boundFunctionStructure;
276 WriteBarrier<Structure> m_boundSlotBaseFunctionStructure;
277 WriteBarrier<Structure> m_getterSetterStructure;
278 WriteBarrier<Structure> m_nativeStdFunctionStructure;
279 WriteBarrier<Structure> m_namedFunctionStructure;
280 PropertyOffset m_functionNameOffset;
281 WriteBarrier<Structure> m_privateNameStructure;
282 WriteBarrier<Structure> m_regExpStructure;
283 WriteBarrier<Structure> m_generatorFunctionStructure;
284 WriteBarrier<Structure> m_dollarVMStructure;
285 WriteBarrier<Structure> m_internalFunctionStructure;
286 WriteBarrier<Structure> m_iteratorResultObjectStructure;
287 WriteBarrier<Structure> m_regExpMatchesArrayStructure;
288 WriteBarrier<Structure> m_regExpMatchesArraySlowPutStructure;
289 WriteBarrier<Structure> m_moduleRecordStructure;
290 WriteBarrier<Structure> m_moduleNamespaceObjectStructure;
291 WriteBarrier<Structure> m_proxyObjectStructure;
292 WriteBarrier<Structure> m_callableProxyObjectStructure;
293 WriteBarrier<Structure> m_proxyRevokeStructure;
294 #if ENABLE(WEBASSEMBLY)
295 WriteBarrier<Structure> m_wasmModuleStructure;
298 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
299 WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
300 WriteBarrier<Structure> m_ ## properName ## Structure;
302 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
303 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
305 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
307 struct TypedArrayData {
308 WriteBarrier<JSObject> prototype;
309 WriteBarrier<InternalFunction> constructor;
310 WriteBarrier<Structure> structure;
313 std::array<TypedArrayData, NUMBER_OF_TYPED_ARRAY_TYPES> m_typedArrays;
315 JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
316 JSCell* m_linkTimeConstants[LinkTimeConstantCount];
320 Debugger* m_debugger;
324 #if ENABLE(WEB_REPLAY)
325 RefPtr<InputCursor> m_inputCursor;
328 #if ENABLE(REMOTE_INSPECTOR)
329 std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController;
330 std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
334 HashSet<String> m_intlCollatorAvailableLocales;
335 HashSet<String> m_intlDateTimeFormatAvailableLocales;
336 HashSet<String> m_intlNumberFormatAvailableLocales;
337 #endif // ENABLE(INTL)
339 RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
340 RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
341 RefPtr<WatchpointSet> m_varInjectionWatchpoint;
343 std::unique_ptr<JSGlobalObjectRareData> m_rareData;
345 WeakRandom m_weakRandom;
347 TemplateRegistry m_templateRegistry;
350 String m_evalDisabledErrorMessage;
351 RuntimeFlags m_runtimeFlags;
352 ConsoleClient* m_consoleClient;
354 static JS_EXPORTDATA const GlobalObjectMethodTable s_globalObjectMethodTable;
355 const GlobalObjectMethodTable* m_globalObjectMethodTable;
357 void createRareDataIfNeeded()
361 m_rareData = std::make_unique<JSGlobalObjectRareData>();
365 typedef JSSegmentedVariableObject Base;
366 static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames | OverridesToThis;
368 static JSGlobalObject* create(VM& vm, Structure* structure)
370 JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
371 globalObject->finishCreation(vm);
372 vm.heap.addFinalizer(globalObject, destroy);
378 bool hasDebugger() const;
379 bool hasInteractiveDebugger() const;
380 bool hasLegacyProfiler() const;
381 const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; }
384 JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = 0);
386 void finishCreation(VM& vm)
388 Base::finishCreation(vm);
389 structure()->setGlobalObject(vm, this);
390 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
392 setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, getPrototypeDirect(), PureForwardingProxyType), this));
395 void finishCreation(VM& vm, JSObject* thisValue)
397 Base::finishCreation(vm);
398 structure()->setGlobalObject(vm, this);
399 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
401 setGlobalThis(vm, thisValue);
404 void addGlobalVar(const Identifier&);
407 JS_EXPORT_PRIVATE ~JSGlobalObject();
408 JS_EXPORT_PRIVATE static void destroy(JSCell*);
409 // We don't need a destructor because we use a finalizer instead.
410 static const bool needsDestruction = false;
412 JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
414 JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
415 JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
417 JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
418 JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
419 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
421 void addVar(ExecState* exec, const Identifier& propertyName)
423 if (!hasProperty(exec, propertyName))
424 addGlobalVar(propertyName);
426 void addFunction(ExecState*, const Identifier&);
428 JSScope* globalScope() { return m_globalLexicalEnvironment.get(); }
429 JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); }
431 // The following accessors return pristine values, even if a script
432 // replaces the global object's associated property.
434 RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); }
436 ErrorConstructor* errorConstructor() const { return m_errorConstructor.get(); }
437 ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); }
438 JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); }
439 JSInternalPromiseConstructor* internalPromiseConstructor() const { return m_internalPromiseConstructor.get(); }
440 NativeErrorConstructor* evalErrorConstructor() const { return m_evalErrorConstructor.get(); }
441 NativeErrorConstructor* rangeErrorConstructor() const { return m_rangeErrorConstructor.get(); }
442 NativeErrorConstructor* referenceErrorConstructor() const { return m_referenceErrorConstructor.get(); }
443 NativeErrorConstructor* syntaxErrorConstructor() const { return m_syntaxErrorConstructor.get(); }
444 NativeErrorConstructor* typeErrorConstructor() const { return m_typeErrorConstructor.get(); }
445 NativeErrorConstructor* URIErrorConstructor() const { return m_URIErrorConstructor.get(); }
447 NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
448 NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
450 JSFunction* parseIntFunction() const { return m_parseIntFunction.get(); }
452 JSFunction* evalFunction() const { return m_evalFunction.get(); }
453 JSFunction* callFunction() const { return m_callFunction.get(); }
454 JSFunction* applyFunction() const { return m_applyFunction.get(); }
455 JSFunction* definePropertyFunction() const { return m_definePropertyFunction.get(); }
456 JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(); }
457 JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(); }
458 JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }
459 JSFunction* functionProtoHasInstanceSymbolFunction() const { return m_functionProtoHasInstanceSymbolFunction.get(); }
460 JSObject* regExpProtoExecFunction() const { return m_regExpProtoExec.get(); }
461 JSObject* regExpProtoSymbolReplaceFunction() const { return m_regExpProtoSymbolReplace.get(); }
462 JSObject* regExpProtoGlobalGetter() const { return m_regExpProtoGlobalGetter.get(); }
463 JSObject* regExpProtoUnicodeGetter() const { return m_regExpProtoUnicodeGetter.get(); }
464 GetterSetter* throwTypeErrorGetterSetter(VM& vm)
466 if (!m_throwTypeErrorGetterSetter)
467 createThrowTypeError(vm);
468 return m_throwTypeErrorGetterSetter.get();
471 GetterSetter* throwTypeErrorArgumentsAndCallerGetterSetter(VM& vm)
473 if (!m_throwTypeErrorArgumentsAndCallerGetterSetter)
474 createThrowTypeErrorArgumentsAndCaller(vm);
475 return m_throwTypeErrorArgumentsAndCallerGetterSetter.get();
478 ModuleLoaderObject* moduleLoader() const { return m_moduleLoader.get(); }
480 ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
481 FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
482 ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
483 BooleanPrototype* booleanPrototype() const { return m_booleanPrototype.get(); }
484 StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
485 SymbolPrototype* symbolPrototype() const { return m_symbolPrototype.get(); }
486 NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
487 DatePrototype* datePrototype() const { return m_datePrototype.get(); }
488 RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
489 ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
490 IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
491 GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
492 GeneratorPrototype* generatorPrototype() const { return m_generatorPrototype.get(); }
494 Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(); }
495 Structure* withScopeStructure() const { return m_withScopeStructure.get(); }
496 Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(); }
497 Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); }
498 Structure* moduleEnvironmentStructure() const { return m_moduleEnvironmentStructure.get(); }
499 Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); }
500 Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); }
501 Structure* clonedArgumentsStructure() const { return m_clonedArgumentsStructure.get(); }
502 Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
504 ASSERT(indexingType & IsArray);
505 return m_originalArrayStructureForIndexingShape[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
507 Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
509 ASSERT(indexingType & IsArray);
510 return m_arrayStructureForIndexingShapeDuringAllocation[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
512 Structure* arrayStructureForIndexingTypeDuringAllocation(ExecState* exec, IndexingType indexingType, JSValue newTarget) const
514 return InternalFunction::createSubclassStructure(exec, newTarget, arrayStructureForIndexingTypeDuringAllocation(indexingType));
516 Structure* arrayStructureForProfileDuringAllocation(ExecState* exec, ArrayAllocationProfile* profile, JSValue newTarget) const
518 return arrayStructureForIndexingTypeDuringAllocation(exec, ArrayAllocationProfile::selectIndexingTypeFor(profile), newTarget);
521 bool isOriginalArrayStructure(Structure* structure)
523 return originalArrayStructureForIndexingType(structure->indexingType() | IsArray) == structure;
526 Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(); }
527 Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(); }
528 Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(); }
529 Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(); }
530 Structure* propertyNameIteratorStructure() const { return m_propertyNameIteratorStructure.get(); }
531 #if JSC_OBJC_API_ENABLED
532 Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(); }
533 Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(); }
535 Structure* dateStructure() const { return m_dateStructure.get(); }
536 Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
537 Structure* errorStructure() const { return m_errorStructure.get(); }
538 Structure* calleeStructure() const { return m_calleeStructure.get(); }
539 Structure* functionStructure() const { return m_functionStructure.get(); }
540 Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(); }
541 Structure* boundSlotBaseFunctionStructure() const { return m_boundSlotBaseFunctionStructure.get(); }
542 Structure* getterSetterStructure() const { return m_getterSetterStructure.get(); }
543 Structure* nativeStdFunctionStructure() const { return m_nativeStdFunctionStructure.get(); }
544 Structure* namedFunctionStructure() const { return m_namedFunctionStructure.get(); }
545 PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
546 Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
547 Structure* privateNameStructure() const { return m_privateNameStructure.get(); }
548 Structure* internalFunctionStructure() const { return m_internalFunctionStructure.get(); }
549 Structure* mapStructure() const { return m_mapStructure.get(); }
550 Structure* regExpStructure() const { return m_regExpStructure.get(); }
551 Structure* generatorFunctionStructure() const { return m_generatorFunctionStructure.get(); }
552 Structure* setStructure() const { return m_setStructure.get(); }
553 Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
554 Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
555 Structure* iteratorResultObjectStructure() const { return m_iteratorResultObjectStructure.get(); }
556 Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
557 Structure* moduleRecordStructure() const { return m_moduleRecordStructure.get(); }
558 Structure* moduleNamespaceObjectStructure() const { return m_moduleNamespaceObjectStructure.get(); }
559 Structure* proxyObjectStructure() const { return m_proxyObjectStructure.get(); }
560 Structure* callableProxyObjectStructure() const { return m_callableProxyObjectStructure.get(); }
561 Structure* proxyRevokeStructure() const { return m_proxyRevokeStructure.get(); }
562 #if ENABLE(WEBASSEMBLY)
563 Structure* wasmModuleStructure() const { return m_wasmModuleStructure.get(); }
566 JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
567 JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
569 #if ENABLE(WEB_REPLAY)
570 JS_EXPORT_PRIVATE void setInputCursor(PassRefPtr<InputCursor>);
571 InputCursor& inputCursor() const { return *m_inputCursor; }
574 #if ENABLE(REMOTE_INSPECTOR)
575 Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); }
576 JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
580 const HashSet<String>& intlCollatorAvailableLocales();
581 const HashSet<String>& intlDateTimeFormatAvailableLocales();
582 const HashSet<String>& intlNumberFormatAvailableLocales();
583 #endif // ENABLE(INTL)
585 void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
586 ConsoleClient* consoleClient() const { return m_consoleClient; }
588 void setName(const String&);
589 const String& name() const { return m_name; }
591 JSArrayBufferPrototype* arrayBufferPrototype() const { return m_arrayBufferPrototype.get(); }
593 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
594 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
596 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
597 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
599 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
601 Structure* typedArrayStructure(TypedArrayType type) const
603 return m_typedArrays[toIndex(type)].structure.get();
605 bool isOriginalTypedArrayStructure(Structure* structure)
607 TypedArrayType type = structure->classInfo()->typedArrayStorageType;
608 if (type == NotTypedArray)
610 return typedArrayStructure(type) == structure;
613 JSObject* typedArrayConstructor(TypedArrayType type) const
615 return m_typedArrays[toIndex(type)].constructor.get();
618 JSCell* actualPointerFor(Special::Pointer pointer)
620 ASSERT(pointer < Special::TableSize);
621 return m_specialPointers[pointer];
623 JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type)
625 unsigned index = static_cast<unsigned>(type);
626 ASSERT(index < LinkTimeConstantCount);
627 return m_linkTimeConstants[index];
630 WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
631 WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
632 WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); }
634 bool isHavingABadTime() const
636 return m_havingABadTimeWatchpoint->hasBeenInvalidated();
639 void haveABadTime(VM&);
641 bool objectPrototypeIsSane();
642 bool arrayPrototypeChainIsSane();
643 bool stringPrototypeChainIsSane();
645 void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
646 unsigned profileGroup() const
650 return m_rareData->profileGroup;
653 Debugger* debugger() const { return m_debugger; }
654 void setDebugger(Debugger* debugger) { m_debugger = debugger; }
656 const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
658 static bool allowsAccessFrom(const JSGlobalObject*, ExecState*) { return true; }
659 static bool supportsLegacyProfiling(const JSGlobalObject*) { return false; }
660 static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
662 JS_EXPORT_PRIVATE ExecState* globalExec();
664 static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
665 static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
666 static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
668 void queueMicrotask(PassRefPtr<Microtask>);
670 bool evalEnabled() const { return m_evalEnabled; }
671 const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
672 void setEvalEnabled(bool enabled, const String& errorMessage = String())
674 m_evalEnabled = enabled;
675 m_evalDisabledErrorMessage = errorMessage;
678 void resetPrototype(VM&, JSValue prototype);
680 VM& vm() const { return m_vm; }
681 JSObject* globalThis() const;
683 static Structure* createStructure(VM& vm, JSValue prototype)
685 Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
686 result->setTransitionWatchpointIsLikelyToBeFired(true);
690 void registerWeakMap(OpaqueJSWeakObjectMap* map)
692 createRareDataIfNeeded();
693 m_rareData->weakMaps.add(map);
696 void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
699 m_rareData->weakMaps.remove(map);
702 OpaqueJSClassDataMap& opaqueJSClassData()
704 createRareDataIfNeeded();
705 return m_rareData->opaqueJSClassData;
708 TemplateRegistry& templateRegistry() { return m_templateRegistry; }
710 static ptrdiff_t weakRandomOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_weakRandom); }
711 double weakRandomNumber() { return m_weakRandom.get(); }
712 unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
714 UnlinkedProgramCodeBlock* createProgramCodeBlock(CallFrame*, ProgramExecutable*, JSObject** exception);
715 UnlinkedEvalCodeBlock* createEvalCodeBlock(CallFrame*, EvalExecutable*, ThisTDZMode, const VariableEnvironment*);
716 UnlinkedModuleProgramCodeBlock* createModuleProgramCodeBlock(CallFrame*, ModuleProgramExecutable*);
719 struct GlobalPropertyInfo {
720 GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
727 const Identifier identifier;
731 JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
733 JS_EXPORT_PRIVATE static JSC::JSValue toThis(JSC::JSCell*, JSC::ExecState*, ECMAMode);
736 friend class LLIntOffsetsExtractor;
738 JS_EXPORT_PRIVATE void setGlobalThis(VM&, JSObject* globalThis);
740 JS_EXPORT_PRIVATE void init(VM&);
742 void createThrowTypeError(VM&);
743 void createThrowTypeErrorArgumentsAndCaller(VM&);
745 JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
748 JSGlobalObject* asGlobalObject(JSValue);
750 inline JSGlobalObject* asGlobalObject(JSValue value)
752 ASSERT(asObject(value)->isGlobalObject());
753 return jsCast<JSGlobalObject*>(asObject(value));
756 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0, JSValue newTarget = JSValue())
758 Structure* structure;
759 if (initialLength >= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)
760 structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(exec, ArrayWithArrayStorage, newTarget);
762 structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
763 if (exec->hadException())
766 return ArrayAllocationProfile::updateLastAllocationFor(profile, JSArray::create(exec->vm(), structure, initialLength));
769 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0, JSValue newTarget = JSValue())
771 return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength, newTarget);
774 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values, JSValue newTarget = JSValue())
776 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
777 if (exec->hadException())
779 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values));
782 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values, JSValue newTarget = JSValue())
784 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, newTarget);
787 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
789 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
790 if (exec->hadException())
792 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, structure, values, length));
795 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
797 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
800 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
802 Structure* structure = globalObject->arrayStructureForProfileDuringAllocation(exec, profile, newTarget);
803 if (exec->hadException())
805 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, structure, values, length));
808 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length, JSValue newTarget = JSValue())
810 return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length, newTarget);
813 inline JSObject* ExecState::globalThisValue() const
815 return lexicalGlobalObject()->globalThis();
818 inline JSObject* JSScope::globalThis()
820 return globalObject()->globalThis();
823 inline JSObject* JSGlobalObject::globalThis() const
825 return m_globalThis.get();
830 #endif // JSGlobalObject_h