2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2007, 2008, 2009, 2014 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 "SpecialPointer.h"
35 #include "StringPrototype.h"
36 #include "StructureChain.h"
37 #include "StructureRareDataInlines.h"
39 #include "Watchpoint.h"
40 #include <JavaScriptCore/JSBase.h>
42 #include <wtf/HashSet.h>
43 #include <wtf/OwnPtr.h>
44 #include <wtf/PassRefPtr.h>
45 #include <wtf/RandomNumber.h>
48 struct OpaqueJSClassContextData
;
51 class JSGlobalObjectInspectorController
;
57 class BooleanPrototype
;
60 class ErrorConstructor
;
64 class FunctionCodeBlock
;
65 class FunctionExecutable
;
66 class FunctionPrototype
;
68 class GlobalCodeBlock
;
70 class JSGlobalObjectDebuggable
;
71 class JSPromiseConstructor
;
72 class JSPromisePrototype
;
74 class LLIntOffsetsExtractor
;
76 class NativeErrorConstructor
;
77 class ObjectConstructor
;
78 class ProgramCodeBlock
;
79 class ProgramExecutable
;
80 class RegExpConstructor
;
81 class RegExpPrototype
;
83 struct ActivationStackNode
;
86 #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName)
88 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
89 macro(Set, set, set, JSSet, Set) \
90 macro(Map, map, map, JSMap, Map) \
91 macro(Date, date, date, DateInstance, Date) \
92 macro(String, string, stringObject, StringObject, String) \
93 macro(Boolean, boolean, booleanObject, BooleanObject, Boolean) \
94 macro(Number, number, numberObject, NumberObject, Number) \
95 macro(Error, error, error, ErrorInstance, Error) \
96 macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
97 DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
99 #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
100 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
101 DEFINE_STANDARD_BUILTIN(macro, ArrayIterator, arrayIterator) \
102 DEFINE_STANDARD_BUILTIN(macro, ArgumentsIterator, argumentsIterator) \
103 DEFINE_STANDARD_BUILTIN(macro, MapIterator, mapIterator) \
104 DEFINE_STANDARD_BUILTIN(macro, SetIterator, setIterator) \
107 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
108 class JS ## capitalName; \
109 class capitalName ## Prototype; \
110 class capitalName ## Constructor;
112 FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE
)
114 #undef DECLARE_SIMPLE_BUILTIN_TYPE
116 typedef Vector
<ExecState
*, 16> ExecStateStack
;
118 struct GlobalObjectMethodTable
{
119 typedef bool (*AllowsAccessFromFunctionPtr
)(const JSGlobalObject
*, ExecState
*);
120 AllowsAccessFromFunctionPtr allowsAccessFrom
;
122 typedef bool (*SupportsProfilingFunctionPtr
)(const JSGlobalObject
*);
123 SupportsProfilingFunctionPtr supportsProfiling
;
125 typedef bool (*SupportsRichSourceInfoFunctionPtr
)(const JSGlobalObject
*);
126 SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo
;
128 typedef bool (*ShouldInterruptScriptFunctionPtr
)(const JSGlobalObject
*);
129 ShouldInterruptScriptFunctionPtr shouldInterruptScript
;
131 typedef bool (*JavaScriptExperimentsEnabledFunctionPtr
)(const JSGlobalObject
*);
132 JavaScriptExperimentsEnabledFunctionPtr javaScriptExperimentsEnabled
;
134 typedef void (*QueueTaskToEventLoopFunctionPtr
)(const JSGlobalObject
*, PassRefPtr
<Microtask
>);
135 QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop
;
137 typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr
)(const JSGlobalObject
*);
138 ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout
;
141 class JSGlobalObject
: public JSSegmentedVariableObject
{
143 typedef HashSet
<RefPtr
<OpaqueJSWeakObjectMap
>> WeakMapSet
;
144 typedef HashMap
<OpaqueJSClass
*, std::unique_ptr
<OpaqueJSClassContextData
>> OpaqueJSClassDataMap
;
146 struct JSGlobalObjectRareData
{
147 JSGlobalObjectRareData()
153 unsigned profileGroup
;
155 OpaqueJSClassDataMap opaqueJSClassData
;
159 Register m_globalCallFrame
[JSStack::CallFrameHeaderSize
];
161 WriteBarrier
<JSObject
> m_globalThis
;
163 WriteBarrier
<RegExpConstructor
> m_regExpConstructor
;
164 WriteBarrier
<ErrorConstructor
> m_errorConstructor
;
165 WriteBarrier
<NativeErrorConstructor
> m_evalErrorConstructor
;
166 WriteBarrier
<NativeErrorConstructor
> m_rangeErrorConstructor
;
167 WriteBarrier
<NativeErrorConstructor
> m_referenceErrorConstructor
;
168 WriteBarrier
<NativeErrorConstructor
> m_syntaxErrorConstructor
;
169 WriteBarrier
<NativeErrorConstructor
> m_typeErrorConstructor
;
170 WriteBarrier
<NativeErrorConstructor
> m_URIErrorConstructor
;
172 WriteBarrier
<JSPromiseConstructor
> m_promiseConstructor
;
174 WriteBarrier
<ObjectConstructor
> m_objectConstructor
;
176 WriteBarrier
<JSFunction
> m_evalFunction
;
177 WriteBarrier
<JSFunction
> m_callFunction
;
178 WriteBarrier
<JSFunction
> m_applyFunction
;
179 WriteBarrier
<GetterSetter
> m_throwTypeErrorGetterSetter
;
181 WriteBarrier
<ObjectPrototype
> m_objectPrototype
;
182 WriteBarrier
<FunctionPrototype
> m_functionPrototype
;
183 WriteBarrier
<ArrayPrototype
> m_arrayPrototype
;
184 WriteBarrier
<RegExpPrototype
> m_regExpPrototype
;
186 WriteBarrier
<JSPromisePrototype
> m_promisePrototype
;
189 WriteBarrier
<Structure
> m_withScopeStructure
;
190 WriteBarrier
<Structure
> m_strictEvalActivationStructure
;
191 WriteBarrier
<Structure
> m_activationStructure
;
192 WriteBarrier
<Structure
> m_nameScopeStructure
;
193 WriteBarrier
<Structure
> m_argumentsStructure
;
195 // Lists the actual structures used for having these particular indexing shapes.
196 WriteBarrier
<Structure
> m_originalArrayStructureForIndexingShape
[NumberOfIndexingShapes
];
197 // Lists the structures we should use during allocation for these particular indexing shapes.
198 WriteBarrier
<Structure
> m_arrayStructureForIndexingShapeDuringAllocation
[NumberOfIndexingShapes
];
200 WriteBarrier
<Structure
> m_callbackConstructorStructure
;
201 WriteBarrier
<Structure
> m_callbackFunctionStructure
;
202 WriteBarrier
<Structure
> m_callbackObjectStructure
;
203 #if JSC_OBJC_API_ENABLED
204 WriteBarrier
<Structure
> m_objcCallbackFunctionStructure
;
205 WriteBarrier
<Structure
> m_objcWrapperObjectStructure
;
207 WriteBarrier
<Structure
> m_nullPrototypeObjectStructure
;
208 WriteBarrier
<Structure
> m_functionStructure
;
209 WriteBarrier
<Structure
> m_boundFunctionStructure
;
210 WriteBarrier
<Structure
> m_namedFunctionStructure
;
211 PropertyOffset m_functionNameOffset
;
212 WriteBarrier
<Structure
> m_privateNameStructure
;
213 WriteBarrier
<Structure
> m_regExpMatchesArrayStructure
;
214 WriteBarrier
<Structure
> m_regExpStructure
;
215 WriteBarrier
<Structure
> m_consoleStructure
;
216 WriteBarrier
<Structure
> m_internalFunctionStructure
;
218 WriteBarrier
<Structure
> m_iteratorResultStructure
;
221 WriteBarrier
<Structure
> m_promiseStructure
;
222 #endif // ENABLE(PROMISES)
224 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
225 WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
226 WriteBarrier<Structure> m_ ## properName ## Structure;
228 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE
)
230 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
232 struct TypedArrayData
{
233 WriteBarrier
<JSObject
> prototype
;
234 WriteBarrier
<Structure
> structure
;
237 std::array
<TypedArrayData
, NUMBER_OF_TYPED_ARRAY_TYPES
> m_typedArrays
;
239 void* m_specialPointers
[Special::TableSize
]; // Special pointers used by the LLInt and JIT.
243 Debugger
* m_debugger
;
247 #if ENABLE(WEB_REPLAY)
248 RefPtr
<InputCursor
> m_inputCursor
;
251 #if ENABLE(REMOTE_INSPECTOR)
252 std::unique_ptr
<Inspector::JSGlobalObjectInspectorController
> m_inspectorController
;
253 std::unique_ptr
<JSGlobalObjectDebuggable
> m_inspectorDebuggable
;
256 RefPtr
<WatchpointSet
> m_masqueradesAsUndefinedWatchpoint
;
257 RefPtr
<WatchpointSet
> m_havingABadTimeWatchpoint
;
258 RefPtr
<WatchpointSet
> m_varInjectionWatchpoint
;
260 OwnPtr
<JSGlobalObjectRareData
> m_rareData
;
262 WeakRandom m_weakRandom
;
265 String m_evalDisabledErrorMessage
;
266 bool m_experimentsEnabled
;
267 ConsoleClient
* m_consoleClient
;
269 static JS_EXPORTDATA
const GlobalObjectMethodTable s_globalObjectMethodTable
;
270 const GlobalObjectMethodTable
* m_globalObjectMethodTable
;
272 void createRareDataIfNeeded()
276 m_rareData
= adoptPtr(new JSGlobalObjectRareData
);
280 typedef JSSegmentedVariableObject Base
;
282 static JSGlobalObject
* create(VM
& vm
, Structure
* structure
)
284 JSGlobalObject
* globalObject
= new (NotNull
, allocateCell
<JSGlobalObject
>(vm
.heap
)) JSGlobalObject(vm
, structure
);
285 globalObject
->finishCreation(vm
);
286 vm
.heap
.addFinalizer(globalObject
, destroy
);
292 bool hasDebugger() const { return m_debugger
; }
293 bool hasProfiler() const { return globalObjectMethodTable()->supportsProfiling(this); }
296 JS_EXPORT_PRIVATE
explicit JSGlobalObject(VM
&, Structure
*, const GlobalObjectMethodTable
* = 0);
298 void finishCreation(VM
& vm
)
300 Base::finishCreation(vm
);
301 structure()->setGlobalObject(vm
, this);
302 m_experimentsEnabled
= m_globalObjectMethodTable
->javaScriptExperimentsEnabled(this);
304 setGlobalThis(vm
, JSProxy::create(vm
, JSProxy::createStructure(vm
, this, prototype(), PureForwardingProxyType
), this));
307 void finishCreation(VM
& vm
, JSObject
* thisValue
)
309 Base::finishCreation(vm
);
310 structure()->setGlobalObject(vm
, this);
311 m_experimentsEnabled
= m_globalObjectMethodTable
->javaScriptExperimentsEnabled(this);
313 setGlobalThis(vm
, thisValue
);
316 struct NewGlobalVar
{
318 VariableWatchpointSet
* set
;
320 NewGlobalVar
addGlobalVar(const Identifier
&, ConstantMode
);
323 JS_EXPORT_PRIVATE
~JSGlobalObject();
324 JS_EXPORT_PRIVATE
static void destroy(JSCell
*);
325 // We don't need a destructor because we use a finalizer instead.
326 static const bool needsDestruction
= false;
328 JS_EXPORT_PRIVATE
static void visitChildren(JSCell
*, SlotVisitor
&);
330 JS_EXPORT_PRIVATE
static bool getOwnPropertySlot(JSObject
*, ExecState
*, PropertyName
, PropertySlot
&);
331 bool hasOwnPropertyForWrite(ExecState
*, PropertyName
);
332 JS_EXPORT_PRIVATE
static void put(JSCell
*, ExecState
*, PropertyName
, JSValue
, PutPropertySlot
&);
334 JS_EXPORT_PRIVATE
static void defineGetter(JSObject
*, ExecState
*, PropertyName
, JSObject
* getterFunc
, unsigned attributes
);
335 JS_EXPORT_PRIVATE
static void defineSetter(JSObject
*, ExecState
*, PropertyName
, JSObject
* setterFunc
, unsigned attributes
);
336 JS_EXPORT_PRIVATE
static bool defineOwnProperty(JSObject
*, ExecState
*, PropertyName
, const PropertyDescriptor
&, bool shouldThrow
);
338 // We use this in the code generator as we perform symbol table
339 // lookups prior to initializing the properties
340 bool symbolTableHasProperty(PropertyName
);
342 void addVar(ExecState
* exec
, const Identifier
& propertyName
)
344 if (!hasProperty(exec
, propertyName
))
345 addGlobalVar(propertyName
, IsVariable
);
347 void addConst(ExecState
* exec
, const Identifier
& propertyName
)
349 if (!hasProperty(exec
, propertyName
))
350 addGlobalVar(propertyName
, IsConstant
);
352 void addFunction(ExecState
*, const Identifier
&, JSValue
);
354 // The following accessors return pristine values, even if a script
355 // replaces the global object's associated property.
357 RegExpConstructor
* regExpConstructor() const { return m_regExpConstructor
.get(); }
359 ErrorConstructor
* errorConstructor() const { return m_errorConstructor
.get(); }
360 ObjectConstructor
* objectConstructor() const { return m_objectConstructor
.get(); }
361 NativeErrorConstructor
* evalErrorConstructor() const { return m_evalErrorConstructor
.get(); }
362 NativeErrorConstructor
* rangeErrorConstructor() const { return m_rangeErrorConstructor
.get(); }
363 NativeErrorConstructor
* referenceErrorConstructor() const { return m_referenceErrorConstructor
.get(); }
364 NativeErrorConstructor
* syntaxErrorConstructor() const { return m_syntaxErrorConstructor
.get(); }
365 NativeErrorConstructor
* typeErrorConstructor() const { return m_typeErrorConstructor
.get(); }
366 NativeErrorConstructor
* URIErrorConstructor() const { return m_URIErrorConstructor
.get(); }
368 JSPromiseConstructor
* promiseConstructor() const { return m_promiseConstructor
.get(); }
371 JSFunction
* evalFunction() const { return m_evalFunction
.get(); }
372 JSFunction
* callFunction() const { return m_callFunction
.get(); }
373 JSFunction
* applyFunction() const { return m_applyFunction
.get(); }
374 GetterSetter
* throwTypeErrorGetterSetter(VM
& vm
)
376 if (!m_throwTypeErrorGetterSetter
)
377 createThrowTypeError(vm
);
378 return m_throwTypeErrorGetterSetter
.get();
381 ObjectPrototype
* objectPrototype() const { return m_objectPrototype
.get(); }
382 FunctionPrototype
* functionPrototype() const { return m_functionPrototype
.get(); }
383 ArrayPrototype
* arrayPrototype() const { return m_arrayPrototype
.get(); }
384 BooleanPrototype
* booleanPrototype() const { return m_booleanPrototype
.get(); }
385 StringPrototype
* stringPrototype() const { return m_stringPrototype
.get(); }
386 NumberPrototype
* numberPrototype() const { return m_numberPrototype
.get(); }
387 DatePrototype
* datePrototype() const { return m_datePrototype
.get(); }
388 RegExpPrototype
* regExpPrototype() const { return m_regExpPrototype
.get(); }
389 ErrorPrototype
* errorPrototype() const { return m_errorPrototype
.get(); }
391 JSPromisePrototype
* promisePrototype() const { return m_promisePrototype
.get(); }
394 Structure
* withScopeStructure() const { return m_withScopeStructure
.get(); }
395 Structure
* strictEvalActivationStructure() const { return m_strictEvalActivationStructure
.get(); }
396 Structure
* activationStructure() const { return m_activationStructure
.get(); }
397 Structure
* nameScopeStructure() const { return m_nameScopeStructure
.get(); }
398 Structure
* argumentsStructure() const { return m_argumentsStructure
.get(); }
399 Structure
* originalArrayStructureForIndexingType(IndexingType indexingType
) const
401 ASSERT(indexingType
& IsArray
);
402 return m_originalArrayStructureForIndexingShape
[(indexingType
& IndexingShapeMask
) >> IndexingShapeShift
].get();
404 Structure
* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType
) const
406 ASSERT(indexingType
& IsArray
);
407 return m_arrayStructureForIndexingShapeDuringAllocation
[(indexingType
& IndexingShapeMask
) >> IndexingShapeShift
].get();
409 Structure
* arrayStructureForProfileDuringAllocation(ArrayAllocationProfile
* profile
) const
411 return arrayStructureForIndexingTypeDuringAllocation(ArrayAllocationProfile::selectIndexingTypeFor(profile
));
414 bool isOriginalArrayStructure(Structure
* structure
)
416 return originalArrayStructureForIndexingType(structure
->indexingType() | IsArray
) == structure
;
419 Structure
* booleanObjectStructure() const { return m_booleanObjectStructure
.get(); }
420 Structure
* callbackConstructorStructure() const { return m_callbackConstructorStructure
.get(); }
421 Structure
* callbackFunctionStructure() const { return m_callbackFunctionStructure
.get(); }
422 Structure
* callbackObjectStructure() const { return m_callbackObjectStructure
.get(); }
423 #if JSC_OBJC_API_ENABLED
424 Structure
* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure
.get(); }
425 Structure
* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure
.get(); }
427 Structure
* dateStructure() const { return m_dateStructure
.get(); }
428 Structure
* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure
.get(); }
429 Structure
* errorStructure() const { return m_errorStructure
.get(); }
430 Structure
* functionStructure() const { return m_functionStructure
.get(); }
431 Structure
* boundFunctionStructure() const { return m_boundFunctionStructure
.get(); }
432 Structure
* namedFunctionStructure() const { return m_namedFunctionStructure
.get(); }
433 PropertyOffset
functionNameOffset() const { return m_functionNameOffset
; }
434 Structure
* numberObjectStructure() const { return m_numberObjectStructure
.get(); }
435 Structure
* privateNameStructure() const { return m_privateNameStructure
.get(); }
436 Structure
* internalFunctionStructure() const { return m_internalFunctionStructure
.get(); }
437 Structure
* mapStructure() const { return m_mapStructure
.get(); }
438 Structure
* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure
.get(); }
439 Structure
* regExpStructure() const { return m_regExpStructure
.get(); }
440 Structure
* setStructure() const { return m_setStructure
.get(); }
441 Structure
* stringObjectStructure() const { return m_stringObjectStructure
.get(); }
442 Structure
* iteratorResultStructure() const { return m_iteratorResultStructure
.get(); }
443 static ptrdiff_t iteratorResultStructureOffset() { return OBJECT_OFFSETOF(JSGlobalObject
, m_iteratorResultStructure
); }
446 Structure
* promiseStructure() const { return m_promiseStructure
.get(); }
447 #endif // ENABLE(PROMISES)
449 JS_EXPORT_PRIVATE
void setRemoteDebuggingEnabled(bool);
450 JS_EXPORT_PRIVATE
bool remoteDebuggingEnabled() const;
452 #if ENABLE(WEB_REPLAY)
453 JS_EXPORT_PRIVATE
void setInputCursor(PassRefPtr
<InputCursor
>);
454 InputCursor
& inputCursor() const { return *m_inputCursor
; }
457 #if ENABLE(REMOTE_INSPECTOR)
458 Inspector::JSGlobalObjectInspectorController
& inspectorController() const { return *m_inspectorController
.get(); }
459 JSGlobalObjectDebuggable
& inspectorDebuggable() { return *m_inspectorDebuggable
.get(); }
462 JS_EXPORT_PRIVATE
void setConsoleClient(ConsoleClient
* consoleClient
) { m_consoleClient
= consoleClient
; }
463 ConsoleClient
* consoleClient() const { return m_consoleClient
; }
465 void setName(const String
&);
466 const String
& name() const { return m_name
; }
468 JSArrayBufferPrototype
* arrayBufferPrototype() const { return m_arrayBufferPrototype
.get(); }
470 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
471 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
473 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
)
475 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
477 Structure
* typedArrayStructure(TypedArrayType type
) const
479 return m_typedArrays
[toIndex(type
)].structure
.get();
481 bool isOriginalTypedArrayStructure(Structure
* structure
)
483 TypedArrayType type
= structure
->classInfo()->typedArrayStorageType
;
484 if (type
== NotTypedArray
)
486 return typedArrayStructure(type
) == structure
;
489 void* actualPointerFor(Special::Pointer pointer
)
491 ASSERT(pointer
< Special::TableSize
);
492 return m_specialPointers
[pointer
];
495 WatchpointSet
* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint
.get(); }
496 WatchpointSet
* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint
.get(); }
497 WatchpointSet
* varInjectionWatchpoint() { return m_varInjectionWatchpoint
.get(); }
499 bool isHavingABadTime() const
501 return m_havingABadTimeWatchpoint
->hasBeenInvalidated();
504 void haveABadTime(VM
&);
506 bool objectPrototypeIsSane();
507 bool arrayPrototypeChainIsSane();
508 bool stringPrototypeChainIsSane();
510 void setProfileGroup(unsigned value
) { createRareDataIfNeeded(); m_rareData
->profileGroup
= value
; }
511 unsigned profileGroup() const
515 return m_rareData
->profileGroup
;
518 Debugger
* debugger() const { return m_debugger
; }
519 void setDebugger(Debugger
* debugger
) { m_debugger
= debugger
; }
521 const GlobalObjectMethodTable
* globalObjectMethodTable() const { return m_globalObjectMethodTable
; }
523 static bool allowsAccessFrom(const JSGlobalObject
*, ExecState
*) { return true; }
524 static bool supportsProfiling(const JSGlobalObject
*) { return false; }
525 static bool supportsRichSourceInfo(const JSGlobalObject
*) { return true; }
527 JS_EXPORT_PRIVATE ExecState
* globalExec();
529 static bool shouldInterruptScript(const JSGlobalObject
*) { return true; }
530 static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject
*) { return false; }
531 static bool javaScriptExperimentsEnabled(const JSGlobalObject
*) { return false; }
533 void queueMicrotask(PassRefPtr
<Microtask
>);
535 bool evalEnabled() const { return m_evalEnabled
; }
536 const String
& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage
; }
537 void setEvalEnabled(bool enabled
, const String
& errorMessage
= String())
539 m_evalEnabled
= enabled
;
540 m_evalDisabledErrorMessage
= errorMessage
;
543 void resetPrototype(VM
&, JSValue prototype
);
545 VM
& vm() const { return m_vm
; }
546 JSObject
* globalThis() const;
548 static Structure
* createStructure(VM
& vm
, JSValue prototype
)
550 return Structure::create(vm
, 0, prototype
, TypeInfo(GlobalObjectType
, StructureFlags
), info());
553 void registerWeakMap(OpaqueJSWeakObjectMap
* map
)
555 createRareDataIfNeeded();
556 m_rareData
->weakMaps
.add(map
);
559 void unregisterWeakMap(OpaqueJSWeakObjectMap
* map
)
562 m_rareData
->weakMaps
.remove(map
);
565 OpaqueJSClassDataMap
& opaqueJSClassData()
567 createRareDataIfNeeded();
568 return m_rareData
->opaqueJSClassData
;
571 double weakRandomNumber() { return m_weakRandom
.get(); }
572 unsigned weakRandomInteger() { return m_weakRandom
.getUint32(); }
574 UnlinkedProgramCodeBlock
* createProgramCodeBlock(CallFrame
*, ProgramExecutable
*, JSObject
** exception
);
575 UnlinkedEvalCodeBlock
* createEvalCodeBlock(CallFrame
*, EvalExecutable
*);
579 static const unsigned StructureFlags
= OverridesGetOwnPropertySlot
| OverridesVisitChildren
| OverridesGetPropertyNames
| Base::StructureFlags
;
581 struct GlobalPropertyInfo
{
582 GlobalPropertyInfo(const Identifier
& i
, JSValue v
, unsigned a
)
589 const Identifier identifier
;
593 JS_EXPORT_PRIVATE
void addStaticGlobals(GlobalPropertyInfo
*, int count
);
595 JS_EXPORT_PRIVATE
static JSC::JSValue
toThis(JSC::JSCell
*, JSC::ExecState
*, ECMAMode
);
598 friend class LLIntOffsetsExtractor
;
600 JS_EXPORT_PRIVATE
void setGlobalThis(VM
&, JSObject
* globalThis
);
602 // FIXME: Fold reset into init.
603 JS_EXPORT_PRIVATE
void init();
604 void reset(JSValue prototype
);
606 void createThrowTypeError(VM
&);
608 JS_EXPORT_PRIVATE
static void clearRareData(JSCell
*);
611 JSGlobalObject
* asGlobalObject(JSValue
);
613 inline JSGlobalObject
* asGlobalObject(JSValue value
)
615 ASSERT(asObject(value
)->isGlobalObject());
616 return jsCast
<JSGlobalObject
*>(asObject(value
));
619 inline bool JSGlobalObject::hasOwnPropertyForWrite(ExecState
* exec
, PropertyName propertyName
)
621 PropertySlot
slot(this);
622 if (Base::getOwnPropertySlot(this, exec
, propertyName
, slot
))
624 bool slotIsWriteable
;
625 return symbolTableGet(this, propertyName
, slot
, slotIsWriteable
);
628 inline bool JSGlobalObject::symbolTableHasProperty(PropertyName propertyName
)
630 SymbolTableEntry entry
= symbolTable()->inlineGet(propertyName
.uid());
631 return !entry
.isNull();
634 inline JSArray
* constructEmptyArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, unsigned initialLength
= 0)
636 return ArrayAllocationProfile::updateLastAllocationFor(profile
, JSArray::create(exec
->vm(), initialLength
>= MIN_SPARSE_ARRAY_INDEX
? globalObject
->arrayStructureForIndexingTypeDuringAllocation(ArrayWithArrayStorage
) : globalObject
->arrayStructureForProfileDuringAllocation(profile
), initialLength
));
639 inline JSArray
* constructEmptyArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, unsigned initialLength
= 0)
641 return constructEmptyArray(exec
, profile
, exec
->lexicalGlobalObject(), initialLength
);
644 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, const ArgList
& values
)
646 return ArrayAllocationProfile::updateLastAllocationFor(profile
, constructArray(exec
, globalObject
->arrayStructureForProfileDuringAllocation(profile
), values
));
649 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, const ArgList
& values
)
651 return constructArray(exec
, profile
, exec
->lexicalGlobalObject(), values
);
654 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, const JSValue
* values
, unsigned length
)
656 return ArrayAllocationProfile::updateLastAllocationFor(profile
, constructArray(exec
, globalObject
->arrayStructureForProfileDuringAllocation(profile
), values
, length
));
659 inline JSArray
* constructArray(ExecState
* exec
, ArrayAllocationProfile
* profile
, const JSValue
* values
, unsigned length
)
661 return constructArray(exec
, profile
, exec
->lexicalGlobalObject(), values
, length
);
664 inline JSArray
* constructArrayNegativeIndexed(ExecState
* exec
, ArrayAllocationProfile
* profile
, JSGlobalObject
* globalObject
, const JSValue
* values
, unsigned length
)
666 return ArrayAllocationProfile::updateLastAllocationFor(profile
, constructArrayNegativeIndexed(exec
, globalObject
->arrayStructureForProfileDuringAllocation(profile
), values
, length
));
669 inline JSArray
* constructArrayNegativeIndexed(ExecState
* exec
, ArrayAllocationProfile
* profile
, const JSValue
* values
, unsigned length
)
671 return constructArrayNegativeIndexed(exec
, profile
, exec
->lexicalGlobalObject(), values
, length
);
674 inline JSObject
* JSScope::globalThis()
676 return globalObject()->globalThis();
679 inline JSObject
* JSGlobalObject::globalThis() const
681 return m_globalThis
.get();
686 #endif // JSGlobalObject_h