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"
41 #include "Watchpoint.h"
42 #include <JavaScriptCore/JSBase.h>
44 #include <wtf/HashSet.h>
45 #include <wtf/PassRefPtr.h>
46 #include <wtf/RandomNumber.h>
49 struct OpaqueJSClassContextData;
52 class JSGlobalObjectInspectorController;
58 class BooleanPrototype;
61 class ErrorConstructor;
65 class FunctionCodeBlock;
66 class FunctionExecutable;
67 class FunctionPrototype;
69 class GlobalCodeBlock;
71 class JSGlobalObjectDebuggable;
72 class JSPromiseConstructor;
73 class JSPromisePrototype;
75 class LLIntOffsetsExtractor;
77 class NativeErrorConstructor;
78 class ObjectConstructor;
79 class ProgramCodeBlock;
80 class ProgramExecutable;
81 class RegExpConstructor;
82 class RegExpPrototype;
84 class NullGetterFunction;
85 class NullSetterFunction;
86 enum class ThisTDZMode;
87 struct ActivationStackNode;
90 #define DEFINE_STANDARD_BUILTIN(macro, upperName, lowerName) macro(upperName, lowerName, lowerName, JS ## upperName, upperName)
92 #define FOR_EACH_EXPERIMENTAL_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
93 macro(Symbol, symbol, symbolObject, SymbolObject, Symbol) \
95 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
96 macro(Set, set, set, JSSet, Set) \
97 macro(Map, map, map, JSMap, Map) \
98 macro(Date, date, date, DateInstance, Date) \
99 macro(String, string, stringObject, StringObject, String) \
100 macro(Boolean, boolean, booleanObject, BooleanObject, Boolean) \
101 macro(Number, number, numberObject, NumberObject, Number) \
102 macro(Error, error, error, ErrorInstance, Error) \
103 macro(JSArrayBuffer, arrayBuffer, arrayBuffer, JSArrayBuffer, ArrayBuffer) \
104 DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
105 DEFINE_STANDARD_BUILTIN(macro, WeakSet, weakSet) \
107 #define FOR_EACH_SIMPLE_BUILTIN_TYPE(macro) \
108 FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
109 FOR_EACH_EXPERIMENTAL_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
110 DEFINE_STANDARD_BUILTIN(macro, ArrayIterator, arrayIterator) \
111 DEFINE_STANDARD_BUILTIN(macro, MapIterator, mapIterator) \
112 DEFINE_STANDARD_BUILTIN(macro, SetIterator, setIterator) \
113 DEFINE_STANDARD_BUILTIN(macro, StringIterator, stringIterator) \
116 #define DECLARE_SIMPLE_BUILTIN_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
117 class JS ## capitalName; \
118 class capitalName ## Prototype; \
119 class capitalName ## Constructor;
121 FOR_EACH_SIMPLE_BUILTIN_TYPE(DECLARE_SIMPLE_BUILTIN_TYPE)
123 #undef DECLARE_SIMPLE_BUILTIN_TYPE
125 typedef Vector<ExecState*, 16> ExecStateStack;
127 struct GlobalObjectMethodTable {
128 typedef bool (*AllowsAccessFromFunctionPtr)(const JSGlobalObject*, ExecState*);
129 AllowsAccessFromFunctionPtr allowsAccessFrom;
131 typedef bool (*SupportsProfilingFunctionPtr)(const JSGlobalObject*);
132 SupportsProfilingFunctionPtr supportsProfiling;
134 typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*);
135 SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo;
137 typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*);
138 ShouldInterruptScriptFunctionPtr shouldInterruptScript;
140 typedef RuntimeFlags (*JavaScriptRuntimeFlagsFunctionPtr)(const JSGlobalObject*);
141 JavaScriptRuntimeFlagsFunctionPtr javaScriptRuntimeFlags;
143 typedef void (*QueueTaskToEventLoopFunctionPtr)(const JSGlobalObject*, PassRefPtr<Microtask>);
144 QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
146 typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*);
147 ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout;
150 class JSGlobalObject : public JSSegmentedVariableObject {
152 typedef HashSet<RefPtr<OpaqueJSWeakObjectMap>> WeakMapSet;
153 typedef HashMap<OpaqueJSClass*, std::unique_ptr<OpaqueJSClassContextData>> OpaqueJSClassDataMap;
155 struct JSGlobalObjectRareData {
156 JSGlobalObjectRareData()
162 unsigned profileGroup;
164 OpaqueJSClassDataMap opaqueJSClassData;
168 Register m_globalCallFrame[JSStack::CallFrameHeaderSize];
170 WriteBarrier<JSObject> m_globalThis;
172 WriteBarrier<JSObject> m_globalCallee;
173 WriteBarrier<RegExpConstructor> m_regExpConstructor;
174 WriteBarrier<ErrorConstructor> m_errorConstructor;
175 WriteBarrier<NativeErrorConstructor> m_evalErrorConstructor;
176 WriteBarrier<NativeErrorConstructor> m_rangeErrorConstructor;
177 WriteBarrier<NativeErrorConstructor> m_referenceErrorConstructor;
178 WriteBarrier<NativeErrorConstructor> m_syntaxErrorConstructor;
179 WriteBarrier<NativeErrorConstructor> m_typeErrorConstructor;
180 WriteBarrier<NativeErrorConstructor> m_URIErrorConstructor;
182 WriteBarrier<JSPromiseConstructor> m_promiseConstructor;
184 WriteBarrier<ObjectConstructor> m_objectConstructor;
186 WriteBarrier<NullGetterFunction> m_nullGetterFunction;
187 WriteBarrier<NullSetterFunction> m_nullSetterFunction;
189 WriteBarrier<JSFunction> m_parseIntFunction;
191 WriteBarrier<JSFunction> m_evalFunction;
192 WriteBarrier<JSFunction> m_callFunction;
193 WriteBarrier<JSFunction> m_applyFunction;
194 WriteBarrier<JSFunction> m_definePropertyFunction;
195 WriteBarrier<JSFunction> m_arrayProtoValuesFunction;
196 WriteBarrier<GetterSetter> m_throwTypeErrorGetterSetter;
198 WriteBarrier<ObjectPrototype> m_objectPrototype;
199 WriteBarrier<FunctionPrototype> m_functionPrototype;
200 WriteBarrier<ArrayPrototype> m_arrayPrototype;
201 WriteBarrier<RegExpPrototype> m_regExpPrototype;
203 WriteBarrier<JSPromisePrototype> m_promisePrototype;
206 WriteBarrier<Structure> m_debuggerScopeStructure;
207 WriteBarrier<Structure> m_withScopeStructure;
208 WriteBarrier<Structure> m_strictEvalActivationStructure;
209 WriteBarrier<Structure> m_lexicalEnvironmentStructure;
210 WriteBarrier<Structure> m_catchScopeStructure;
211 WriteBarrier<Structure> m_functionNameScopeStructure;
212 WriteBarrier<Structure> m_directArgumentsStructure;
213 WriteBarrier<Structure> m_scopedArgumentsStructure;
214 WriteBarrier<Structure> m_outOfBandArgumentsStructure;
216 // Lists the actual structures used for having these particular indexing shapes.
217 WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfIndexingShapes];
218 // Lists the structures we should use during allocation for these particular indexing shapes.
219 WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfIndexingShapes];
221 WriteBarrier<Structure> m_callbackConstructorStructure;
222 WriteBarrier<Structure> m_callbackFunctionStructure;
223 WriteBarrier<Structure> m_callbackObjectStructure;
224 #if JSC_OBJC_API_ENABLED
225 WriteBarrier<Structure> m_objcCallbackFunctionStructure;
226 WriteBarrier<Structure> m_objcWrapperObjectStructure;
228 WriteBarrier<Structure> m_nullPrototypeObjectStructure;
229 WriteBarrier<Structure> m_calleeStructure;
230 WriteBarrier<Structure> m_functionStructure;
231 WriteBarrier<Structure> m_boundFunctionStructure;
232 WriteBarrier<Structure> m_namedFunctionStructure;
233 PropertyOffset m_functionNameOffset;
234 WriteBarrier<Structure> m_privateNameStructure;
235 WriteBarrier<Structure> m_regExpStructure;
236 WriteBarrier<Structure> m_consoleStructure;
237 WriteBarrier<Structure> m_dollarVMStructure;
238 WriteBarrier<Structure> m_internalFunctionStructure;
240 WriteBarrier<Structure> m_iteratorResultStructure;
243 WriteBarrier<Structure> m_promiseStructure;
244 #endif // ENABLE(PROMISES)
246 #define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
247 WriteBarrier<capitalName ## Prototype> m_ ## lowerName ## Prototype; \
248 WriteBarrier<Structure> m_ ## properName ## Structure;
250 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_STORAGE_FOR_SIMPLE_TYPE)
252 #undef DEFINE_STORAGE_FOR_SIMPLE_TYPE
254 struct TypedArrayData {
255 WriteBarrier<JSObject> prototype;
256 WriteBarrier<Structure> structure;
259 std::array<TypedArrayData, NUMBER_OF_TYPED_ARRAY_TYPES> m_typedArrays;
261 JSCell* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
262 JSCell* m_linkTimeConstants[LinkTimeConstantCount];
266 Debugger* m_debugger;
270 #if ENABLE(WEB_REPLAY)
271 RefPtr<InputCursor> m_inputCursor;
274 #if ENABLE(REMOTE_INSPECTOR)
275 std::unique_ptr<Inspector::JSGlobalObjectInspectorController> m_inspectorController;
276 std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
279 RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
280 RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
281 RefPtr<WatchpointSet> m_varInjectionWatchpoint;
283 std::unique_ptr<JSGlobalObjectRareData> m_rareData;
285 WeakRandom m_weakRandom;
288 String m_evalDisabledErrorMessage;
289 RuntimeFlags m_runtimeFlags;
290 ConsoleClient* m_consoleClient;
292 static JS_EXPORTDATA const GlobalObjectMethodTable s_globalObjectMethodTable;
293 const GlobalObjectMethodTable* m_globalObjectMethodTable;
295 void createRareDataIfNeeded()
299 m_rareData = std::make_unique<JSGlobalObjectRareData>();
303 typedef JSSegmentedVariableObject Base;
304 static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames;
306 static JSGlobalObject* create(VM& vm, Structure* structure, const GlobalObjectMethodTable* globalObjectMethodTable = nullptr)
308 JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure, globalObjectMethodTable);
309 globalObject->finishCreation(vm);
310 vm.heap.addFinalizer(globalObject, destroy);
316 bool hasDebugger() const { return m_debugger; }
317 bool hasProfiler() const { return globalObjectMethodTable()->supportsProfiling(this); }
318 const RuntimeFlags& runtimeFlags() const { return m_runtimeFlags; }
321 JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = 0);
323 void finishCreation(VM& vm)
325 Base::finishCreation(vm);
326 structure()->setGlobalObject(vm, this);
327 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
329 setGlobalThis(vm, JSProxy::create(vm, JSProxy::createStructure(vm, this, prototype(), PureForwardingProxyType), this));
332 void finishCreation(VM& vm, JSObject* thisValue)
334 Base::finishCreation(vm);
335 structure()->setGlobalObject(vm, this);
336 m_runtimeFlags = m_globalObjectMethodTable->javaScriptRuntimeFlags(this);
338 setGlobalThis(vm, thisValue);
341 struct NewGlobalVar {
345 NewGlobalVar addGlobalVar(const Identifier&, ConstantMode);
348 JS_EXPORT_PRIVATE ~JSGlobalObject();
349 JS_EXPORT_PRIVATE static void destroy(JSCell*);
350 // We don't need a destructor because we use a finalizer instead.
351 static const bool needsDestruction = false;
353 JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
355 JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
356 bool hasOwnPropertyForWrite(ExecState*, PropertyName);
357 JS_EXPORT_PRIVATE static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
359 JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
360 JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
361 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
363 // We use this in the code generator as we perform symbol table
364 // lookups prior to initializing the properties
365 bool symbolTableHasProperty(PropertyName);
367 void addVar(ExecState* exec, const Identifier& propertyName)
369 if (!hasProperty(exec, propertyName))
370 addGlobalVar(propertyName, IsVariable);
372 void addConst(ExecState* exec, const Identifier& propertyName)
374 if (!hasProperty(exec, propertyName))
375 addGlobalVar(propertyName, IsConstant);
377 void addFunction(ExecState*, const Identifier&, JSValue);
379 // The following accessors return pristine values, even if a script
380 // replaces the global object's associated property.
382 RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); }
384 ErrorConstructor* errorConstructor() const { return m_errorConstructor.get(); }
385 ObjectConstructor* objectConstructor() const { return m_objectConstructor.get(); }
386 NativeErrorConstructor* evalErrorConstructor() const { return m_evalErrorConstructor.get(); }
387 NativeErrorConstructor* rangeErrorConstructor() const { return m_rangeErrorConstructor.get(); }
388 NativeErrorConstructor* referenceErrorConstructor() const { return m_referenceErrorConstructor.get(); }
389 NativeErrorConstructor* syntaxErrorConstructor() const { return m_syntaxErrorConstructor.get(); }
390 NativeErrorConstructor* typeErrorConstructor() const { return m_typeErrorConstructor.get(); }
391 NativeErrorConstructor* URIErrorConstructor() const { return m_URIErrorConstructor.get(); }
393 JSPromiseConstructor* promiseConstructor() const { return m_promiseConstructor.get(); }
396 NullGetterFunction* nullGetterFunction() const { return m_nullGetterFunction.get(); }
397 NullSetterFunction* nullSetterFunction() const { return m_nullSetterFunction.get(); }
399 JSFunction* parseIntFunction() const { return m_parseIntFunction.get(); }
401 JSFunction* evalFunction() const { return m_evalFunction.get(); }
402 JSFunction* callFunction() const { return m_callFunction.get(); }
403 JSFunction* applyFunction() const { return m_applyFunction.get(); }
404 JSFunction* definePropertyFunction() const { return m_definePropertyFunction.get(); }
405 JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(); }
406 GetterSetter* throwTypeErrorGetterSetter(VM& vm)
408 if (!m_throwTypeErrorGetterSetter)
409 createThrowTypeError(vm);
410 return m_throwTypeErrorGetterSetter.get();
413 ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
414 FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
415 ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
416 BooleanPrototype* booleanPrototype() const { return m_booleanPrototype.get(); }
417 StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
418 SymbolPrototype* symbolPrototype() const { return m_symbolPrototype.get(); }
419 NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
420 DatePrototype* datePrototype() const { return m_datePrototype.get(); }
421 RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
422 ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
424 JSPromisePrototype* promisePrototype() const { return m_promisePrototype.get(); }
427 Structure* debuggerScopeStructure() const { return m_debuggerScopeStructure.get(); }
428 Structure* withScopeStructure() const { return m_withScopeStructure.get(); }
429 Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(); }
430 Structure* activationStructure() const { return m_lexicalEnvironmentStructure.get(); }
431 Structure* catchScopeStructure() const { return m_catchScopeStructure.get(); }
432 Structure* functionNameScopeStructure() const { return m_functionNameScopeStructure.get(); }
433 Structure* directArgumentsStructure() const { return m_directArgumentsStructure.get(); }
434 Structure* scopedArgumentsStructure() const { return m_scopedArgumentsStructure.get(); }
435 Structure* outOfBandArgumentsStructure() const { return m_outOfBandArgumentsStructure.get(); }
436 Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
438 ASSERT(indexingType & IsArray);
439 return m_originalArrayStructureForIndexingShape[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
441 Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
443 ASSERT(indexingType & IsArray);
444 return m_arrayStructureForIndexingShapeDuringAllocation[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
446 Structure* arrayStructureForProfileDuringAllocation(ArrayAllocationProfile* profile) const
448 return arrayStructureForIndexingTypeDuringAllocation(ArrayAllocationProfile::selectIndexingTypeFor(profile));
451 bool isOriginalArrayStructure(Structure* structure)
453 return originalArrayStructureForIndexingType(structure->indexingType() | IsArray) == structure;
456 Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(); }
457 Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(); }
458 Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(); }
459 Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(); }
460 #if JSC_OBJC_API_ENABLED
461 Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(); }
462 Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(); }
464 Structure* dateStructure() const { return m_dateStructure.get(); }
465 Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
466 Structure* errorStructure() const { return m_errorStructure.get(); }
467 Structure* calleeStructure() const { return m_calleeStructure.get(); }
468 Structure* functionStructure() const { return m_functionStructure.get(); }
469 Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(); }
470 Structure* namedFunctionStructure() const { return m_namedFunctionStructure.get(); }
471 PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
472 Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
473 Structure* privateNameStructure() const { return m_privateNameStructure.get(); }
474 Structure* internalFunctionStructure() const { return m_internalFunctionStructure.get(); }
475 Structure* mapStructure() const { return m_mapStructure.get(); }
476 Structure* regExpStructure() const { return m_regExpStructure.get(); }
477 Structure* setStructure() const { return m_setStructure.get(); }
478 Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
479 Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
480 Structure* iteratorResultStructure() const { return m_iteratorResultStructure.get(); }
481 static ptrdiff_t iteratorResultStructureOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_iteratorResultStructure); }
484 Structure* promiseStructure() const { return m_promiseStructure.get(); }
485 #endif // ENABLE(PROMISES)
487 JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
488 JS_EXPORT_PRIVATE bool remoteDebuggingEnabled() const;
490 #if ENABLE(WEB_REPLAY)
491 JS_EXPORT_PRIVATE void setInputCursor(PassRefPtr<InputCursor>);
492 InputCursor& inputCursor() const { return *m_inputCursor; }
495 #if ENABLE(REMOTE_INSPECTOR)
496 Inspector::JSGlobalObjectInspectorController& inspectorController() const { return *m_inspectorController.get(); }
497 JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
500 void setConsoleClient(ConsoleClient* consoleClient) { m_consoleClient = consoleClient; }
501 ConsoleClient* consoleClient() const { return m_consoleClient; }
503 void setName(const String&);
504 const String& name() const { return m_name; }
506 JSArrayBufferPrototype* arrayBufferPrototype() const { return m_arrayBufferPrototype.get(); }
508 #define DEFINE_ACCESSORS_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
509 Structure* properName ## Structure() { return m_ ## properName ## Structure.get(); }
511 FOR_EACH_SIMPLE_BUILTIN_TYPE(DEFINE_ACCESSORS_FOR_SIMPLE_TYPE)
513 #undef DEFINE_ACCESSORS_FOR_SIMPLE_TYPE
515 Structure* typedArrayStructure(TypedArrayType type) const
517 return m_typedArrays[toIndex(type)].structure.get();
519 bool isOriginalTypedArrayStructure(Structure* structure)
521 TypedArrayType type = structure->classInfo()->typedArrayStorageType;
522 if (type == NotTypedArray)
524 return typedArrayStructure(type) == structure;
527 JSCell* actualPointerFor(Special::Pointer pointer)
529 ASSERT(pointer < Special::TableSize);
530 return m_specialPointers[pointer];
532 JSCell* jsCellForLinkTimeConstant(LinkTimeConstant type)
534 unsigned index = static_cast<unsigned>(type);
535 ASSERT(index < LinkTimeConstantCount);
536 return m_linkTimeConstants[index];
539 WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
540 WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
541 WatchpointSet* varInjectionWatchpoint() { return m_varInjectionWatchpoint.get(); }
543 bool isHavingABadTime() const
545 return m_havingABadTimeWatchpoint->hasBeenInvalidated();
548 void haveABadTime(VM&);
550 bool objectPrototypeIsSane();
551 bool arrayPrototypeChainIsSane();
552 bool stringPrototypeChainIsSane();
554 void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
555 unsigned profileGroup() const
559 return m_rareData->profileGroup;
562 Debugger* debugger() const { return m_debugger; }
563 void setDebugger(Debugger* debugger) { m_debugger = debugger; }
565 const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
567 static bool allowsAccessFrom(const JSGlobalObject*, ExecState*) { return true; }
568 static bool supportsProfiling(const JSGlobalObject*) { return false; }
569 static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
571 JS_EXPORT_PRIVATE ExecState* globalExec();
573 static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
574 static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
575 static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
577 void queueMicrotask(PassRefPtr<Microtask>);
579 bool evalEnabled() const { return m_evalEnabled; }
580 const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
581 void setEvalEnabled(bool enabled, const String& errorMessage = String())
583 m_evalEnabled = enabled;
584 m_evalDisabledErrorMessage = errorMessage;
587 void resetPrototype(VM&, JSValue prototype);
589 VM& vm() const { return m_vm; }
590 JSObject* globalThis() const;
592 static Structure* createStructure(VM& vm, JSValue prototype)
594 return Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
597 void registerWeakMap(OpaqueJSWeakObjectMap* map)
599 createRareDataIfNeeded();
600 m_rareData->weakMaps.add(map);
603 void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
606 m_rareData->weakMaps.remove(map);
609 OpaqueJSClassDataMap& opaqueJSClassData()
611 createRareDataIfNeeded();
612 return m_rareData->opaqueJSClassData;
615 double weakRandomNumber() { return m_weakRandom.get(); }
616 unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
618 UnlinkedProgramCodeBlock* createProgramCodeBlock(CallFrame*, ProgramExecutable*, JSObject** exception);
619 UnlinkedEvalCodeBlock* createEvalCodeBlock(CallFrame*, EvalExecutable*, ThisTDZMode);
622 struct GlobalPropertyInfo {
623 GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
630 const Identifier identifier;
634 JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
636 JS_EXPORT_PRIVATE static JSC::JSValue toThis(JSC::JSCell*, JSC::ExecState*, ECMAMode);
639 friend class LLIntOffsetsExtractor;
641 JS_EXPORT_PRIVATE void setGlobalThis(VM&, JSObject* globalThis);
643 JS_EXPORT_PRIVATE void init(VM&);
645 void createThrowTypeError(VM&);
647 JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
650 JSGlobalObject* asGlobalObject(JSValue);
652 inline JSGlobalObject* asGlobalObject(JSValue value)
654 ASSERT(asObject(value)->isGlobalObject());
655 return jsCast<JSGlobalObject*>(asObject(value));
658 inline bool JSGlobalObject::hasOwnPropertyForWrite(ExecState* exec, PropertyName propertyName)
660 PropertySlot slot(this);
661 if (Base::getOwnPropertySlot(this, exec, propertyName, slot))
663 bool slotIsWriteable;
664 return symbolTableGet(this, propertyName, slot, slotIsWriteable);
667 inline bool JSGlobalObject::symbolTableHasProperty(PropertyName propertyName)
669 SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.uid());
670 return !entry.isNull();
673 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0)
675 return ArrayAllocationProfile::updateLastAllocationFor(profile, JSArray::create(exec->vm(), initialLength >= MIN_SPARSE_ARRAY_INDEX ? globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithArrayStorage) : globalObject->arrayStructureForProfileDuringAllocation(profile), initialLength));
678 inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0)
680 return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength);
683 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values)
685 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, globalObject->arrayStructureForProfileDuringAllocation(profile), values));
688 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values)
690 return constructArray(exec, profile, exec->lexicalGlobalObject(), values);
693 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length)
695 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, globalObject->arrayStructureForProfileDuringAllocation(profile), values, length));
698 inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length)
700 return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length);
703 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length)
705 return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArrayNegativeIndexed(exec, globalObject->arrayStructureForProfileDuringAllocation(profile), values, length));
708 inline JSArray* constructArrayNegativeIndexed(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length)
710 return constructArrayNegativeIndexed(exec, profile, exec->lexicalGlobalObject(), values, length);
713 inline JSObject* ExecState::globalThisValue() const
715 return lexicalGlobalObject()->globalThis();
718 inline JSObject* JSScope::globalThis()
720 return globalObject()->globalThis();
723 inline JSObject* JSGlobalObject::globalThis() const
725 return m_globalThis.get();
730 #endif // JSGlobalObject_h