2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007, 2008, 2009, 2014, 2015 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 "ConstantMode.h"
28 #include "JSArrayBufferPrototype.h"
29 #include "JSClassRef.h"
31 #include "JSSegmentedVariableObject.h"
32 #include "JSWeakObjectMapRefInternal.h"
33 #include "NumberPrototype.h"
34 #include "RuntimeFlags.h"
35 #include "SpecialPointer.h"
36 #include "StringPrototype.h"
37 #include "StructureChain.h"
38 #include "StructureRareDataInlines.h"
39 #include "SymbolPrototype.h"
40 #include "TemplateRegistry.h"
42 #include "Watchpoint.h"
43 #include <JavaScriptCore/JSBase.h>
45 #include <wtf/HashSet.h>
46 #include <wtf/PassRefPtr.h>
47 #include <wtf/RandomNumber.h>
50 struct OpaqueJSClassContextData
;
53 class JSGlobalObjectInspectorController
;
59 class BooleanPrototype
;
62 class ErrorConstructor
;
66 class FunctionCodeBlock
;
67 class FunctionExecutable
;
68 class FunctionPrototype
;
70 class GlobalCodeBlock
;
72 class JSGlobalObjectDebuggable
;
73 class JSPromiseConstructor
;
74 class JSPromisePrototype
;
76 class LLIntOffsetsExtractor
;
78 class NativeErrorConstructor
;
79 class ObjectConstructor
;
80 class ProgramCodeBlock
;
81 class ProgramExecutable
;
82 class RegExpConstructor
;
83 class RegExpPrototype
;
85 class NullGetterFunction
;
86 class NullSetterFunction
;
87 enum class ThisTDZMode
;
88 struct ActivationStackNode
;
91 #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName)
93 #define FOR_EACH_EXPERIMENTAL_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
94 macro(Symbol, symbol, symbolObject, SymbolObject, Symbol) \
96 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
97 macro(Set, set, set, JSSet, Set) \
98 macro(Map, map, map, JSMap, Map) \
99 macro(Date, date, date, DateInstance, Date) \
100 macro(String, string, stringObject, StringObject, String) \
101 macro(Boolean, boolean, booleanObject, BooleanObject, Boolean) \
102 macro(Number, number, numberObject, NumberObject, Number) \
103 macro(Error, error, error, ErrorInstance, Error) \
104 macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
105 DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
106 DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \
108 #define FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
109 DEFINE_STANDARD_BUILTIN(macro, ArrayIterator, arrayIterator) \
110 DEFINE_STANDARD_BUILTIN(macro, MapIterator, mapIterator) \
111 DEFINE_STANDARD_BUILTIN(macro, SetIterator, setIterator) \
112 DEFINE_STANDARD_BUILTIN(macro, StringIterator, stringIterator) \
114 #define FOR_EACH_BUILTIN_ITERATOR_TYPE(macro) \
115 DEFINE_STANDARD_BUILTIN(macro, Iterator, iterator) \
116 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(macro) \
118 #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
119 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
120 FOR_EACH_EXPERIMENTAL_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
122 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
123 class JS ## capitalName; \
124 class capitalName ## Prototype; \
125 class capitalName ## Constructor;
127 class IteratorPrototype
;
128 FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE
)
129 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE
)
131 #undef DECLARE_SIMPLE_BUILTIN_TYPE
133 typedef Vector
<ExecState
*, 16> ExecStateStack
;
135 struct GlobalObjectMethodTable
{
136 typedef bool (*AllowsAccessFromFunctionPtr
)(const JSGlobalObject
*, ExecState
*);
137 AllowsAccessFromFunctionPtr allowsAccessFrom
;
139 typedef bool (*SupportsProfilingFunctionPtr
)(const JSGlobalObject
*);
140 SupportsProfilingFunctionPtr supportsProfiling
;
142 typedef bool (*SupportsRichSourceInfoFunctionPtr
)(const JSGlobalObject
*);
143 SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo
;
145 typedef bool (*ShouldInterruptScriptFunctionPtr
)(const JSGlobalObject
*);
146 ShouldInterruptScriptFunctionPtr shouldInterruptScript
;
148 typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr
)(const JSGlobalObject
*);
149 JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags
;
151 typedef void (*QueueTaskToEventLoopFunctionPtr
)(const JSGlobalObject
*, PassRefPtr
<Microtask
>);
152 QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop
;
154 typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr
)(const JSGlobalObject
*);
155 ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout
;
158 class JSGlobalObject
: public JSSegmentedVariableObject
{
160 typedef HashSet
<RefPtr
<OpaqueJSWeakObjectMap
>> WeakMapSet
;
161 typedef HashMap
<OpaqueJSClass
*, std::unique_ptr
<OpaqueJSClassContextData
>> OpaqueJSClassDataMap
;
163 struct JSGlobalObjectRareData
{
164 JSGlobalObjectRareData()
170 unsigned profileGroup
;
172 OpaqueJSClassDataMap opaqueJSClassData
;
176 Register m_globalCallFrame
[JSStack::CallFrameHeaderSize
];
178 WriteBarrier
<JSObject
> m_globalThis
;
180 WriteBarrier
<JSObject
> m_globalCallee
;
181 WriteBarrier
<RegExpConstructor
> m_regExpConstructor
;
182 WriteBarrier
<ErrorConstructor
> m_errorConstructor
;
183 WriteBarrier
<NativeErrorConstructor
> m_evalErrorConstructor
;
184 WriteBarrier
<NativeErrorConstructor
> m_rangeErrorConstructor
;
185 WriteBarrier
<NativeErrorConstructor
> m_referenceErrorConstructor
;
186 WriteBarrier
<NativeErrorConstructor
> m_syntaxErrorConstructor
;
187 WriteBarrier
<NativeErrorConstructor
> m_typeErrorConstructor
;
188 WriteBarrier
<NativeErrorConstructor
> m_URIErrorConstructor
;
190 WriteBarrier
<JSPromiseConstructor
> m_promiseConstructor
;
192 WriteBarrier
<ObjectConstructor
> m_objectConstructor
;
194 WriteBarrier
<NullGetterFunction
> m_nullGetterFunction
;
195 WriteBarrier
<NullSetterFunction
> m_nullSetterFunction
;
197 WriteBarrier
<JSFunction
> m_parseIntFunction
;
199 WriteBarrier
<JSFunction
> m_evalFunction
;
200 WriteBarrier
<JSFunction
> m_callFunction
;
201 WriteBarrier
<JSFunction
> m_applyFunction
;
202 WriteBarrier
<JSFunction
> m_definePropertyFunction
;
203 WriteBarrier
<JSFunction
> m_arrayProtoValuesFunction
;
205 WriteBarrier
<JSFunction
> m_initializePromiseFunction
;
206 WriteBarrier
<JSFunction
> m_newPromiseDeferredFunction
;
208 WriteBarrier
<GetterSetter
> m_throwTypeErrorGetterSetter
;
210 WriteBarrier
<ObjectPrototype
> m_objectPrototype
;
211 WriteBarrier
<FunctionPrototype
> m_functionPrototype
;
212 WriteBarrier
<ArrayPrototype
> m_arrayPrototype
;
213 WriteBarrier
<RegExpPrototype
> m_regExpPrototype
;
214 WriteBarrier
<IteratorPrototype
> m_iteratorPrototype
;
216 WriteBarrier
<JSPromisePrototype
> m_promisePrototype
;
219 WriteBarrier
<Structure
> m_debuggerScopeStructure
;
220 WriteBarrier
<Structure
> m_withScopeStructure
;
221 WriteBarrier
<Structure
> m_strictEvalActivationStructure
;
222 WriteBarrier
<Structure
> m_lexicalEnvironmentStructure
;
223 WriteBarrier
<Structure
> m_catchScopeStructure
;
224 WriteBarrier
<Structure
> m_functionNameScopeStructure
;
225 WriteBarrier
<Structure
> m_directArgumentsStructure
;
226 WriteBarrier
<Structure
> m_scopedArgumentsStructure
;
227 WriteBarrier
<Structure
> m_outOfBandArgumentsStructure
;
229 // Lists the actual structures used for having these particular indexing shapes.
230 WriteBarrier
<Structure
> m_originalArrayStructureForIndexingShape
[NumberOfIndexingShapes
];
231 // Lists the structures we should use during allocation for these particular indexing shapes.
232 WriteBarrier
<Structure
> m_arrayStructureForIndexingShapeDuringAllocation
[NumberOfIndexingShapes
];
234 WriteBarrier
<Structure
> m_callbackConstructorStructure
;
235 WriteBarrier
<Structure
> m_callbackFunctionStructure
;
236 WriteBarrier
<Structure
> m_callbackObjectStructure
;
237 #if JSC_OBJC_API_ENABLED
238 WriteBarrier
<Structure
> m_objcCallbackFunctionStructure
;
239 WriteBarrier
<Structure
> m_objcWrapperObjectStructure
;
241 WriteBarrier
<Structure
> m_nullPrototypeObjectStructure
;
242 WriteBarrier
<Structure
> m_calleeStructure
;
243 WriteBarrier
<Structure
> m_functionStructure
;
244 WriteBarrier
<Structure
> m_boundFunctionStructure
;
245 WriteBarrier
<Structure
> m_namedFunctionStructure
;
246 PropertyOffset m_functionNameOffset
;
247 WriteBarrier
<Structure
> m_privateNameStructure
;
248 WriteBarrier
<Structure
> m_regExpStructure
;
249 WriteBarrier
<Structure
> m_consoleStructure
;
250 WriteBarrier
<Structure
> m_dollarVMStructure
;
251 WriteBarrier
<Structure
> m_internalFunctionStructure
;
253 WriteBarrier
<Structure
> m_iteratorResultStructure
;
255 WriteBarrier
<Structure
> m_regExpMatchesArrayStructure
;
258 WriteBarrier
<Structure
> m_promiseStructure
;
259 #endif // ENABLE(PROMISES)
261 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
262 WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
263 WriteBarrier<Structure> m_ ## properName ## Structure;
265 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE
)
266 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE
)
268 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
270 struct TypedArrayData
{
271 WriteBarrier
<JSObject
> prototype
;
272 WriteBarrier
<Structure
> structure
;
275 std::array
<TypedArrayData
, NUMBER_OF_TYPED_ARRAY_TYPES
> m_typedArrays
;
277 JSCell
* m_specialPointers
[Special::TableSize
]; // Special pointers used by the LLInt and JIT.
278 JSCell
* m_linkTimeConstants
[LinkTimeConstantCount
];
282 Debugger
* m_debugger
;
286 #if ENABLE(WEB_REPLAY)
287 RefPtr
<InputCursor
> m_inputCursor
;
290 #if ENABLE(REMOTE_INSPECTOR)
291 std::unique_ptr
<Inspector::JSGlobalObjectInspectorController
> m_inspectorController
;
292 std::unique_ptr
<JSGlobalObjectDebuggable
> m_inspectorDebuggable
;
295 RefPtr
<WatchpointSet
> m_masqueradesAsUndefinedWatchpoint
;
296 RefPtr
<WatchpointSet
> m_havingABadTimeWatchpoint
;
297 RefPtr
<WatchpointSet
> m_varInjectionWatchpoint
;
299 std::unique_ptr
<JSGlobalObjectRareData
> m_rareData
;
301 WeakRandom m_weakRandom
;
303 TemplateRegistry m_templateRegistry
;
306 String m_evalDisabledErrorMessage
;
307 RuntimeFlags m_runtimeFlags
;
308 ConsoleClient
* m_consoleClient
;
310 static JS_EXPORTDATA
const GlobalObjectMethodTable s_globalObjectMethodTable
;
311 const GlobalObjectMethodTable
* m_globalObjectMethodTable
;
313 void createRareDataIfNeeded()
317 m_rareData
= std::make_unique
<JSGlobalObjectRareData
>();
321 typedef JSSegmentedVariableObject Base
;
322 static const unsigned StructureFlags
= Base::StructureFlags
| OverridesGetOwnPropertySlot
| OverridesGetPropertyNames
;
324 static JSGlobalObject
* create(VM
& vm
, Structure
* structure
, const GlobalObjectMethodTable
* globalObjectMethodTable
= nullptr)
326 JSGlobalObject
* globalObject
= new (NotNull
, allocateCell
<JSGlobalObject
>(vm
.heap
)) JSGlobalObject(vm
, structure
, globalObjectMethodTable
);
327 globalObject
->finishCreation(vm
);
328 vm
.heap
.addFinalizer(globalObject
, destroy
);
334 bool hasDebugger() const { return m_debugger
; }
335 bool hasProfiler() const { return globalObjectMethodTable()->supportsProfiling(this); }
336 const RuntimeFlags
& runtimeFlags() const { return m_runtimeFlags
; }
339 JS_EXPORT_PRIVATE
explicit JSGlobalObject(VM
&, Structure
*, const GlobalObjectMethodTable
* = 0);
341 void finishCreation(VM
& vm
)
343 Base::finishCreation(vm
);
344 structure()->setGlobalObject(vm
, this);
345 m_runtimeFlags
= m_globalObjectMethodTable
->javaScriptRuntimeFlags(this);
347 setGlobalThis(vm
, JSProxy::create(vm
, JSProxy::createStructure(vm
, this, prototype(), PureForwardingProxyType
), this));
350 void finishCreation(VM
& vm
, JSObject
* thisValue
)
352 Base::finishCreation(vm
);
353 structure()->setGlobalObject(vm
, this);
354 m_runtimeFlags
= m_globalObjectMethodTable
->javaScriptRuntimeFlags(this);
356 setGlobalThis(vm
, thisValue
);
359 void addGlobalVar(const Identifier
&, ConstantMode
);
362 JS_EXPORT_PRIVATE
~JSGlobalObject();
363 JS_EXPORT_PRIVATE
static void destroy(JSCell
*);
364 // We don't need a destructor because we use a finalizer instead.
365 static const bool needsDestruction
= false;
367 JS_EXPORT_PRIVATE
static void visitChildren(JSCell
*, SlotVisitor
&);
369 JS_EXPORT_PRIVATE
static bool getOwnPropertySlot(JSObject
*, ExecState
*, PropertyName
, PropertySlot
&);
370 bool hasOwnPropertyForWrite(ExecState
*, PropertyName
);
371 JS_EXPORT_PRIVATE
static void put(JSCell
*, ExecState
*, PropertyName
, JSValue
, PutPropertySlot
&);
373 JS_EXPORT_PRIVATE
static void defineGetter(JSObject
*, ExecState
*, PropertyName
, JSObject
* getterFunc
, unsigned attributes
);
374 JS_EXPORT_PRIVATE
static void defineSetter(JSObject
*, ExecState
*, PropertyName
, JSObject
* setterFunc
, unsigned attributes
);
375 JS_EXPORT_PRIVATE
static bool defineOwnProperty(JSObject
*, ExecState
*, PropertyName
, const PropertyDescriptor
&, bool shouldThrow
);
377 // We use this in the code generator as we perform symbol table
378 // lookups prior to initializing the properties
379 bool symbolTableHasProperty(PropertyName
);
381 void addVar(ExecState
* exec
, const Identifier
& propertyName
)
383 if (!hasProperty(exec
, propertyName
))
384 addGlobalVar(propertyName
, IsVariable
);
386 void addConst(ExecState
* exec
, const Identifier
& propertyName
)
388 if (!hasProperty(exec
, propertyName
))
389 addGlobalVar(propertyName
, IsConstant
);
391 void addFunction(ExecState
*, const Identifier
&);
393 // The following accessors return pristine values, even if a script
394 // replaces the global object's associated property.
396 RegExpConstructor
* regExpConstructor() const { return m_regExpConstructor
.get(); }
398 ErrorConstructor
* errorConstructor() const { return m_errorConstructor
.get(); }
399 ObjectConstructor
* objectConstructor() const { return m_objectConstructor
.get(); }
400 NativeErrorConstructor
* evalErrorConstructor() const { return m_evalErrorConstructor
.get(); }
401 NativeErrorConstructor
* rangeErrorConstructor() const { return m_rangeErrorConstructor
.get(); }
402 NativeErrorConstructor
* referenceErrorConstructor() const { return m_referenceErrorConstructor
.get(); }
403 NativeErrorConstructor
* syntaxErrorConstructor() const { return m_syntaxErrorConstructor
.get(); }
404 NativeErrorConstructor
* typeErrorConstructor() const { return m_typeErrorConstructor
.get(); }
405 NativeErrorConstructor
* URIErrorConstructor() const { return m_URIErrorConstructor
.get(); }
407 JSPromiseConstructor
* promiseConstructor() const { return m_promiseConstructor
.get(); }
410 NullGetterFunction
* nullGetterFunction() const { return m_nullGetterFunction
.get(); }
411 NullSetterFunction
* nullSetterFunction() const { return m_nullSetterFunction
.get(); }
413 JSFunction
* parseIntFunction() const { return m_parseIntFunction
.get(); }
415 JSFunction
* evalFunction() const { return m_evalFunction
.get(); }
416 JSFunction
* callFunction() const { return m_callFunction
.get(); }
417 JSFunction
* applyFunction() const { return m_applyFunction
.get(); }
418 JSFunction
* definePropertyFunction() const { return m_definePropertyFunction
.get(); }
419 JSFunction
* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction
.get(); }
421 JSFunction
* initializePromiseFunction() const { return m_initializePromiseFunction
.get(); }
422 JSFunction
* newPromiseDeferredFunction() const { return m_newPromiseDeferredFunction
.get(); }
424 GetterSetter
* throwTypeErrorGetterSetter(VM
& vm
)
426 if (!m_throwTypeErrorGetterSetter
)
427 createThrowTypeError(vm
);
428 return m_throwTypeErrorGetterSetter
.get();
431 ObjectPrototype
* objectPrototype() const { return m_objectPrototype
.get(); }
432 FunctionPrototype
* functionPrototype() const { return m_functionPrototype
.get(); }
433 ArrayPrototype
* arrayPrototype() const { return m_arrayPrototype
.get(); }
434 BooleanPrototype
* booleanPrototype() const { return m_booleanPrototype
.get(); }
435 StringPrototype
* stringPrototype() const { return m_stringPrototype
.get(); }
436 SymbolPrototype
* symbolPrototype() const { return m_symbolPrototype
.get(); }
437 NumberPrototype
* numberPrototype() const { return m_numberPrototype
.get(); }
438 DatePrototype
* datePrototype() const { return m_datePrototype
.get(); }
439 RegExpPrototype
* regExpPrototype() const { return m_regExpPrototype
.get(); }
440 ErrorPrototype
* errorPrototype() const { return m_errorPrototype
.get(); }
441 IteratorPrototype
* iteratorPrototype() const { return m_iteratorPrototype
.get(); }
443 JSPromisePrototype
* promisePrototype() const { return m_promisePrototype
.get(); }
446 Structure
* debuggerScopeStructure() const { return m_debuggerScopeStructure
.get(); }
447 Structure
* withScopeStructure() const { return m_withScopeStructure
.get(); }
448 Structure
* strictEvalActivationStructure() const { return m_strictEvalActivationStructure
.get(); }
449 Structure
* activationStructure() const { return m_lexicalEnvironmentStructure
.get(); }
450 Structure
* catchScopeStructure() const { return m_catchScopeStructure
.get(); }
451 Structure
* functionNameScopeStructure() const { return m_functionNameScopeStructure
.get(); }
452 Structure
* directArgumentsStructure() const { return m_directArgumentsStructure
.get(); }
453 Structure
* scopedArgumentsStructure() const { return m_scopedArgumentsStructure
.get(); }
454 Structure
* outOfBandArgumentsStructure() const { return m_outOfBandArgumentsStructure
.get(); }
455 Structure
* originalArrayStructureForIndexingType(IndexingType indexingType
) const
457 ASSERT(indexingType
& IsArray
);
458 return m_originalArrayStructureForIndexingShape
[(indexingType
& IndexingShapeMask
) >> IndexingShapeShift
].get();
460 Structure
* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType
) const
462 ASSERT(indexingType
& IsArray
);
463 return m_arrayStructureForIndexingShapeDuringAllocation
[(indexingType
& IndexingShapeMask
) >> IndexingShapeShift
].get();
465 Structure
* arrayStructureForProfileDuringAllocation(ArrayAllocationProfile
* profile
) const
467 return arrayStructureForIndexingTypeDuringAllocation(ArrayAllocationProfile::selectIndexingTypeFor(profile
));
470 bool isOriginalArrayStructure(Structure
* structure
)
472 return originalArrayStructureForIndexingType(structure
->indexingType() | IsArray
) == structure
;
475 Structure
* booleanObjectStructure() const { return m_booleanObjectStructure
.get(); }
476 Structure
* callbackConstructorStructure() const { return m_callbackConstructorStructure
.get(); }
477 Structure
* callbackFunctionStructure() const { return m_callbackFunctionStructure
.get(); }
478 Structure
* callbackObjectStructure() const { return m_callbackObjectStructure
.get(); }
479 #if JSC_OBJC_API_ENABLED
480 Structure
* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure
.get(); }
481 Structure
* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure
.get(); }
483 Structure
* dateStructure() const { return m_dateStructure
.get(); }
484 Structure
* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure
.get(); }
485 Structure
* errorStructure() const { return m_errorStructure
.get(); }
486 Structure
* calleeStructure() const { return m_calleeStructure
.get(); }
487 Structure
* functionStructure() const { return m_functionStructure
.get(); }
488 Structure
* boundFunctionStructure() const { return m_boundFunctionStructure
.get(); }
489 Structure
* namedFunctionStructure() const { return m_namedFunctionStructure
.get(); }
490 PropertyOffset
functionNameOffset() const { return m_functionNameOffset
; }
491 Structure
* numberObjectStructure() const { return m_numberObjectStructure
.get(); }
492 Structure
* privateNameStructure() const { return m_privateNameStructure
.get(); }
493 Structure
* internalFunctionStructure() const { return m_internalFunctionStructure
.get(); }
494 Structure
* mapStructure() const { return m_mapStructure
.get(); }
495 Structure
* regExpStructure() const { return m_regExpStructure
.get(); }
496 Structure
* setStructure() const { return m_setStructure
.get(); }
497 Structure
* stringObjectStructure() const { return m_stringObjectStructure
.get(); }
498 Structure
* symbolObjectStructure() const { return m_symbolObjectStructure
.get(); }
499 Structure
* iteratorResultStructure() const { return m_iteratorResultStructure
.get(); }
500 static ptrdiff_t iteratorResultStructureOffset() { return OBJECT_OFFSETOF(JSGlobalObject
, m_iteratorResultStructure
); }
501 Structure
* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure
.get(); }
504 Structure
* promiseStructure() const { return m_promiseStructure
.get(); }
505 #endif // ENABLE(PROMISES)
507 JS_EXPORT_PRIVATE
void setRemoteDebuggingEnabled(bool);
508 JS_EXPORT_PRIVATE
bool remoteDebuggingEnabled() const;
510 #if ENABLE(WEB_REPLAY)
511 JS_EXPORT_PRIVATE
void setInputCursor(PassRefPtr
<InputCursor
>);
512 InputCursor
& inputCursor() const { return *m_inputCursor
; }
515 #if ENABLE(REMOTE_INSPECTOR)
516 Inspector::JSGlobalObjectInspectorController
& inspectorController() const { return *m_inspectorController
.get(); }
517 JSGlobalObjectDebuggable
& inspectorDebuggable() { return *m_inspectorDebuggable
.get(); }
520 void setConsoleClient(ConsoleClient
* consoleClient
) { m_consoleClient
= consoleClient
; }
521 ConsoleClient
* consoleClient() const { return m_consoleClient
; }
523 void setName(const String
&);
524 const String
& name() const { return m_name
; }
526 JSArrayBufferPrototype
* arrayBufferPrototype() const { return m_arrayBufferPrototype
.get(); }
528 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
529 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
531 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
)
532 FOR_EACH_BUILTIN_DERIVED_ITERATOR_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
)
534 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
536 Structure
* typedArrayStructure(TypedArrayType type
) const
538 return m_typedArrays
[toIndex(type
)].structure
.get();
540 bool isOriginalTypedArrayStructure(Structure
* structure
)
542 TypedArrayType type
= structure
->classInfo()->typedArrayStorageType
;
543 if (type
== NotTypedArray
)
545 return typedArrayStructure(type
) == structure
;
548 JSCell
* actualPointerFor(Special::Pointer pointer
)
550 ASSERT(pointer
< Special::TableSize
);
551 return m_specialPointers
[pointer
];
553 JSCell
* jsCellForLinkTimeConstant(LinkTimeConstant type
)
555 unsigned index
= static_cast<unsigned>(type
);
556 ASSERT(index
< LinkTimeConstantCount
);
557 return m_linkTimeConstants
[index
];
560 WatchpointSet
* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint
.get(); }
561 WatchpointSet
* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint
.get(); }
562 WatchpointSet
* varInjectionWatchpoint() { return m_varInjectionWatchpoint
.get(); }
564 bool isHavingABadTime() const
566 return m_havingABadTimeWatchpoint
->hasBeenInvalidated();
569 void haveABadTime(VM
&);
571 bool objectPrototypeIsSane();
572 bool arrayPrototypeChainIsSane();
573 bool stringPrototypeChainIsSane();
575 void setProfileGroup(unsigned value
) { createRareDataIfNeeded(); m_rareData
->profileGroup
= value
; }
576 unsigned profileGroup() const
580 return m_rareData
->profileGroup
;
583 Debugger
* debugger() const { return m_debugger
; }
584 void setDebugger(Debugger
* debugger
) { m_debugger
= debugger
; }
586 const GlobalObjectMethodTable
* globalObjectMethodTable() const { return m_globalObjectMethodTable
; }
588 static bool allowsAccessFrom(const JSGlobalObject
*, ExecState
*) { return true; }
589 static bool supportsProfiling(const JSGlobalObject
*) { return false; }
590 static bool supportsRichSourceInfo(const JSGlobalObject
*) { return true; }
592 JS_EXPORT_PRIVATE ExecState
* globalExec();
594 static bool shouldInterruptScript(const JSGlobalObject
*) { return true; }
595 static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject
*) { return false; }
596 static RuntimeFlags
javaScriptRuntimeFlags(const JSGlobalObject
*) { return RuntimeFlags(); }
598 void queueMicrotask(PassRefPtr
<Microtask
>);
600 bool evalEnabled() const { return m_evalEnabled
; }
601 const String
& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage
; }
602 void setEvalEnabled(bool enabled
, const String
& errorMessage
= String())
604 m_evalEnabled
= enabled
;
605 m_evalDisabledErrorMessage
= errorMessage
;
608 void resetPrototype(VM
&, JSValue prototype
);
610 VM
& vm() const { return m_vm
; }
611 JSObject
* globalThis() const;
613 static Structure
* createStructure(VM
& vm
, JSValue prototype
)
615 return Structure::create(vm
, 0, prototype
, TypeInfo(GlobalObjectType
, StructureFlags
), info());
618 void registerWeakMap(OpaqueJSWeakObjectMap
* map
)
620 createRareDataIfNeeded();
621 m_rareData
->weakMaps
.add(map
);
624 void unregisterWeakMap(OpaqueJSWeakObjectMap
* map
)
627 m_rareData
->weakMaps
.remove(map
);
630 OpaqueJSClassDataMap
& opaqueJSClassData()
632 createRareDataIfNeeded();
633 return m_rareData
->opaqueJSClassData
;
636 TemplateRegistry
& templateRegistry() { return m_templateRegistry
; }
638 double weakRandomNumber() { return m_weakRandom
.get(); }
639 unsigned weakRandomInteger() { return m_weakRandom
.getUint32(); }
641 UnlinkedProgramCodeBlock
* createProgramCodeBlock(CallFrame
*, ProgramExecutable
*, JSObject
** exception
);
642 UnlinkedEvalCodeBlock
* createEvalCodeBlock(CallFrame
*, EvalExecutable
*, ThisTDZMode
);
645 struct GlobalPropertyInfo
{
646 GlobalPropertyInfo(const Identifier
& i
, JSValue v
, unsigned a
)
653 const Identifier identifier
;
657 JS_EXPORT_PRIVATE
void addStaticGlobals(GlobalPropertyInfo
*, int count
);
659 JS_EXPORT_PRIVATE
static JSC::JSValue
toThis(JSC::JSCell
*, JSC::ExecState
*, ECMAMode
);
662 friend class LLIntOffsetsExtractor
;
664 JS_EXPORT_PRIVATE
void setGlobalThis(VM
&, JSObject
* globalThis
);
666 JS_EXPORT_PRIVATE
void init(VM
&);
668 void createThrowTypeError(VM
&);
670 JS_EXPORT_PRIVATE
static void clearRareData(JSCell
*);
673 JSGlobalObject
* asGlobalObject(JSValue
);
675 inline JSGlobalObject
* asGlobalObject(JSValue value
)
677 ASSERT(asObject(value
)->isGlobalObject());
678 return jsCast
<JSGlobalObject
*>(asObject(value
));
681 inline bool JSGlobalObject::hasOwnPropertyForWrite(ExecState
* exec
, PropertyName propertyName
)
683 PropertySlot
slot(this);
684 if (Base::getOwnPropertySlot(this, exec
, propertyName
, slot
))
686 bool slotIsWriteable
;
687 return symbolTableGet(this, propertyName
, slot
, slotIsWriteable
);
690 inline bool JSGlobalObject::symbolTableHasProperty(PropertyName propertyName
)
692 SymbolTableEntry entry
= symbolTable()->inlineGet(propertyName
.uid());
693 return !entry
.isNull();
696 inline JSArray
* constructEmptyArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, unsigned initialLength
= 0)
698 return ArrayAllocationProfile::updateLastAllocationFor(profile
, JSArray::create(exec
->vm(), initialLength
>= MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH
? globalObject
->arrayStructureForIndexingTypeDuringAllocation(ArrayWithArrayStorage
) : globalObject
->arrayStructureForProfileDuringAllocation(profile
), initialLength
));
701 inline JSArray
* constructEmptyArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, unsigned initialLength
= 0)
703 return constructEmptyArray(exec
, profile
, exec
->lexicalGlobalObject(), initialLength
);
706 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, const ArgList
& values
)
708 return ArrayAllocationProfile::updateLastAllocationFor(profile
, constructArray(exec
, globalObject
->arrayStructureForProfileDuringAllocation(profile
), values
));
711 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, const ArgList
& values
)
713 return constructArray(exec
, profile
, exec
->lexicalGlobalObject(), values
);
716 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, const JSValue
* values
, unsigned length
)
718 return ArrayAllocationProfile::updateLastAllocationFor(profile
, constructArray(exec
, globalObject
->arrayStructureForProfileDuringAllocation(profile
), values
, length
));
721 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, const JSValue
* values
, unsigned length
)
723 return constructArray(exec
, profile
, exec
->lexicalGlobalObject(), values
, length
);
726 inline JSArray
* constructArrayNegativeIndexed(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, const JSValue
* values
, unsigned length
)
728 return ArrayAllocationProfile::updateLastAllocationFor(profile
, constructArrayNegativeIndexed(exec
, globalObject
->arrayStructureForProfileDuringAllocation(profile
), values
, length
));
731 inline JSArray
* constructArrayNegativeIndexed(ExecState
* exec
, ArrayAllocationProfile
* profile
, const JSValue
* values
, unsigned length
)
733 return constructArrayNegativeIndexed(exec
, profile
, exec
->lexicalGlobalObject(), values
, length
);
736 inline JSObject
* ExecState::globalThisValue() const
738 return lexicalGlobalObject()->globalThis();
741 inline JSObject
* JSScope::globalThis()
743 return globalObject()->globalThis();
746 inline JSObject
* JSGlobalObject::globalThis() const
748 return m_globalThis
.get();
753 #endif // JSGlobalObject_h