JSGlobalObject.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*
  2. * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
  3. * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. *
  20. */
  21. #ifndef JSGlobalObject_h
  22. #define JSGlobalObject_h
  23. #include "ArrayAllocationProfile.h"
  24. #include "JSArray.h"
  25. #include "JSClassRef.h"
  26. #include "VM.h"
  27. #include "JSCBridgeToll.h"
  28. #include "JSSegmentedVariableObject.h"
  29. #include "JSWeakObjectMapRefInternal.h"
  30. #include "NumberPrototype.h"
  31. #include "SpecialPointer.h"
  32. #include "StringPrototype.h"
  33. #include "StructureChain.h"
  34. #include "StructureRareDataInlines.h"
  35. #include "Watchpoint.h"
  36. #include <JavaScriptCore/JSBase.h>
  37. #include <wtf/HashSet.h>
  38. #include <wtf/OwnPtr.h>
  39. #include <wtf/RandomNumber.h>
  40. struct OpaqueJSClass;
  41. struct OpaqueJSClassContextData;
  42. namespace JSC {
  43. class ArrayPrototype;
  44. class BooleanPrototype;
  45. class DatePrototype;
  46. class Debugger;
  47. class ErrorConstructor;
  48. class ErrorPrototype;
  49. class EvalCodeBlock;
  50. class EvalExecutable;
  51. class FunctionCodeBlock;
  52. class FunctionExecutable;
  53. class FunctionPrototype;
  54. class GetterSetter;
  55. class GlobalCodeBlock;
  56. class JSStack;
  57. class LLIntOffsetsExtractor;
  58. class NativeErrorConstructor;
  59. class ProgramCodeBlock;
  60. class ProgramExecutable;
  61. class RegExpConstructor;
  62. class RegExpPrototype;
  63. class SourceCode;
  64. struct ActivationStackNode;
  65. struct HashTable;
  66. typedef Vector<ExecState*, 16> ExecStateStack;
  67. struct GlobalObjectMethodTable {
  68. typedef bool (*AllowsAccessFromFunctionPtr)(const JSGlobalObject*, ExecState*);
  69. AllowsAccessFromFunctionPtr allowsAccessFrom;
  70. typedef bool (*SupportsProfilingFunctionPtr)(const JSGlobalObject*);
  71. SupportsProfilingFunctionPtr supportsProfiling;
  72. typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*);
  73. SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo;
  74. typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*);
  75. ShouldInterruptScriptFunctionPtr shouldInterruptScript;
  76. typedef bool (*JavaScriptExperimentsEnabledFunctionPtr)(const JSGlobalObject*);
  77. JavaScriptExperimentsEnabledFunctionPtr javaScriptExperimentsEnabled;
  78. };
  79. class JSGlobalObject : public JSSegmentedVariableObject {
  80. #if ENABLE(DETACHED_JIT)
  81. friend void JSCBridgeToll::prepare(JSGlobalObject * globalObject);
  82. #endif
  83. private:
  84. typedef HashSet<RefPtr<OpaqueJSWeakObjectMap> > WeakMapSet;
  85. typedef HashMap<OpaqueJSClass*, OwnPtr<OpaqueJSClassContextData> > OpaqueJSClassDataMap;
  86. struct JSGlobalObjectRareData {
  87. JSGlobalObjectRareData()
  88. : profileGroup(0)
  89. {
  90. }
  91. WeakMapSet weakMaps;
  92. unsigned profileGroup;
  93. OpaqueJSClassDataMap opaqueJSClassData;
  94. };
  95. protected:
  96. Register m_globalCallFrame[JSStack::CallFrameHeaderSize];
  97. WriteBarrier<JSObject> m_globalThis;
  98. WriteBarrier<RegExpConstructor> m_regExpConstructor;
  99. WriteBarrier<ErrorConstructor> m_errorConstructor;
  100. WriteBarrier<NativeErrorConstructor> m_evalErrorConstructor;
  101. WriteBarrier<NativeErrorConstructor> m_rangeErrorConstructor;
  102. WriteBarrier<NativeErrorConstructor> m_referenceErrorConstructor;
  103. WriteBarrier<NativeErrorConstructor> m_syntaxErrorConstructor;
  104. WriteBarrier<NativeErrorConstructor> m_typeErrorConstructor;
  105. WriteBarrier<NativeErrorConstructor> m_URIErrorConstructor;
  106. WriteBarrier<JSFunction> m_evalFunction;
  107. WriteBarrier<JSFunction> m_callFunction;
  108. WriteBarrier<JSFunction> m_applyFunction;
  109. WriteBarrier<GetterSetter> m_throwTypeErrorGetterSetter;
  110. WriteBarrier<ObjectPrototype> m_objectPrototype;
  111. WriteBarrier<FunctionPrototype> m_functionPrototype;
  112. WriteBarrier<ArrayPrototype> m_arrayPrototype;
  113. WriteBarrier<BooleanPrototype> m_booleanPrototype;
  114. WriteBarrier<StringPrototype> m_stringPrototype;
  115. WriteBarrier<NumberPrototype> m_numberPrototype;
  116. WriteBarrier<DatePrototype> m_datePrototype;
  117. WriteBarrier<RegExpPrototype> m_regExpPrototype;
  118. WriteBarrier<ErrorPrototype> m_errorPrototype;
  119. WriteBarrier<Structure> m_withScopeStructure;
  120. WriteBarrier<Structure> m_strictEvalActivationStructure;
  121. WriteBarrier<Structure> m_activationStructure;
  122. WriteBarrier<Structure> m_nameScopeStructure;
  123. WriteBarrier<Structure> m_argumentsStructure;
  124. // Lists the actual structures used for having these particular indexing shapes.
  125. WriteBarrier<Structure> m_originalArrayStructureForIndexingShape[NumberOfIndexingShapes];
  126. // Lists the structures we should use during allocation for these particular indexing shapes.
  127. WriteBarrier<Structure> m_arrayStructureForIndexingShapeDuringAllocation[NumberOfIndexingShapes];
  128. WriteBarrier<Structure> m_booleanObjectStructure;
  129. WriteBarrier<Structure> m_callbackConstructorStructure;
  130. WriteBarrier<Structure> m_callbackFunctionStructure;
  131. WriteBarrier<Structure> m_callbackObjectStructure;
  132. #if JSC_OBJC_API_ENABLED
  133. WriteBarrier<Structure> m_objcCallbackFunctionStructure;
  134. WriteBarrier<Structure> m_objcWrapperObjectStructure;
  135. #endif
  136. WriteBarrier<Structure> m_dateStructure;
  137. WriteBarrier<Structure> m_nullPrototypeObjectStructure;
  138. WriteBarrier<Structure> m_errorStructure;
  139. WriteBarrier<Structure> m_functionStructure;
  140. WriteBarrier<Structure> m_boundFunctionStructure;
  141. WriteBarrier<Structure> m_namedFunctionStructure;
  142. PropertyOffset m_functionNameOffset;
  143. WriteBarrier<Structure> m_numberObjectStructure;
  144. WriteBarrier<Structure> m_privateNameStructure;
  145. WriteBarrier<Structure> m_regExpMatchesArrayStructure;
  146. WriteBarrier<Structure> m_regExpStructure;
  147. WriteBarrier<Structure> m_stringObjectStructure;
  148. WriteBarrier<Structure> m_internalFunctionStructure;
  149. void* m_specialPointers[Special::TableSize]; // Special pointers used by the LLInt and JIT.
  150. Debugger* m_debugger;
  151. RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
  152. RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
  153. OwnPtr<JSGlobalObjectRareData> m_rareData;
  154. WeakRandom m_weakRandom;
  155. bool m_evalEnabled;
  156. String m_evalDisabledErrorMessage;
  157. bool m_experimentsEnabled;
  158. static JS_EXPORTDATA const GlobalObjectMethodTable s_globalObjectMethodTable;
  159. const GlobalObjectMethodTable* m_globalObjectMethodTable;
  160. void createRareDataIfNeeded()
  161. {
  162. if (m_rareData)
  163. return;
  164. m_rareData = adoptPtr(new JSGlobalObjectRareData);
  165. }
  166. public:
  167. typedef JSSegmentedVariableObject Base;
  168. static JSGlobalObject* create(VM& vm, Structure* structure)
  169. {
  170. JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(vm.heap)) JSGlobalObject(vm, structure);
  171. globalObject->finishCreation(vm);
  172. vm.heap.addFinalizer(globalObject, destroy);
  173. return globalObject;
  174. }
  175. static JS_EXPORTDATA const ClassInfo s_info;
  176. bool hasDebugger() const { return m_debugger; }
  177. bool hasProfiler() const { return globalObjectMethodTable()->supportsProfiling(this); }
  178. protected:
  179. JS_EXPORT_PRIVATE explicit JSGlobalObject(VM&, Structure*, const GlobalObjectMethodTable* = 0);
  180. void finishCreation(VM& vm)
  181. {
  182. Base::finishCreation(vm);
  183. structure()->setGlobalObject(vm, this);
  184. m_experimentsEnabled = m_globalObjectMethodTable->javaScriptExperimentsEnabled(this);
  185. init(this);
  186. }
  187. void finishCreation(VM& vm, JSObject* thisValue)
  188. {
  189. Base::finishCreation(vm);
  190. structure()->setGlobalObject(vm, this);
  191. m_experimentsEnabled = m_globalObjectMethodTable->javaScriptExperimentsEnabled(this);
  192. init(thisValue);
  193. }
  194. public:
  195. JS_EXPORT_PRIVATE ~JSGlobalObject();
  196. JS_EXPORT_PRIVATE static void destroy(JSCell*);
  197. // We don't need a destructor because we use a finalizer instead.
  198. static const bool needsDestruction = false;
  199. JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
  200. JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
  201. JS_EXPORT_PRIVATE static bool getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
  202. bool hasOwnPropertyForWrite(ExecState*, PropertyName);
  203. JS_EXPORT_PRIVATE static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
  204. JS_EXPORT_PRIVATE static void putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned attributes);
  205. JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
  206. JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
  207. JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool shouldThrow);
  208. // We use this in the code generator as we perform symbol table
  209. // lookups prior to initializing the properties
  210. bool symbolTableHasProperty(PropertyName);
  211. // The following accessors return pristine values, even if a script
  212. // replaces the global object's associated property.
  213. RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); }
  214. ErrorConstructor* errorConstructor() const { return m_errorConstructor.get(); }
  215. NativeErrorConstructor* evalErrorConstructor() const { return m_evalErrorConstructor.get(); }
  216. NativeErrorConstructor* rangeErrorConstructor() const { return m_rangeErrorConstructor.get(); }
  217. NativeErrorConstructor* referenceErrorConstructor() const { return m_referenceErrorConstructor.get(); }
  218. NativeErrorConstructor* syntaxErrorConstructor() const { return m_syntaxErrorConstructor.get(); }
  219. NativeErrorConstructor* typeErrorConstructor() const { return m_typeErrorConstructor.get(); }
  220. NativeErrorConstructor* URIErrorConstructor() const { return m_URIErrorConstructor.get(); }
  221. JSFunction* evalFunction() const { return m_evalFunction.get(); }
  222. JSFunction* callFunction() const { return m_callFunction.get(); }
  223. JSFunction* applyFunction() const { return m_applyFunction.get(); }
  224. GetterSetter* throwTypeErrorGetterSetter(ExecState* exec)
  225. {
  226. if (!m_throwTypeErrorGetterSetter)
  227. createThrowTypeError(exec);
  228. return m_throwTypeErrorGetterSetter.get();
  229. }
  230. ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
  231. FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
  232. ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
  233. BooleanPrototype* booleanPrototype() const { return m_booleanPrototype.get(); }
  234. StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
  235. NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
  236. DatePrototype* datePrototype() const { return m_datePrototype.get(); }
  237. RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
  238. ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
  239. Structure* withScopeStructure() const { return m_withScopeStructure.get(); }
  240. Structure* strictEvalActivationStructure() const { return m_strictEvalActivationStructure.get(); }
  241. Structure* activationStructure() const { return m_activationStructure.get(); }
  242. Structure* nameScopeStructure() const { return m_nameScopeStructure.get(); }
  243. Structure* argumentsStructure() const { return m_argumentsStructure.get(); }
  244. Structure* originalArrayStructureForIndexingType(IndexingType indexingType) const
  245. {
  246. ASSERT(indexingType & IsArray);
  247. return m_originalArrayStructureForIndexingShape[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
  248. }
  249. Structure* arrayStructureForIndexingTypeDuringAllocation(IndexingType indexingType) const
  250. {
  251. ASSERT(indexingType & IsArray);
  252. return m_arrayStructureForIndexingShapeDuringAllocation[(indexingType & IndexingShapeMask) >> IndexingShapeShift].get();
  253. }
  254. Structure* arrayStructureForProfileDuringAllocation(ArrayAllocationProfile* profile) const
  255. {
  256. return arrayStructureForIndexingTypeDuringAllocation(ArrayAllocationProfile::selectIndexingTypeFor(profile));
  257. }
  258. bool isOriginalArrayStructure(Structure* structure)
  259. {
  260. return originalArrayStructureForIndexingType(structure->indexingType() | IsArray) == structure;
  261. }
  262. Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(); }
  263. Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(); }
  264. Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(); }
  265. Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(); }
  266. #if JSC_OBJC_API_ENABLED
  267. Structure* objcCallbackFunctionStructure() const { return m_objcCallbackFunctionStructure.get(); }
  268. Structure* objcWrapperObjectStructure() const { return m_objcWrapperObjectStructure.get(); }
  269. #endif
  270. Structure* dateStructure() const { return m_dateStructure.get(); }
  271. Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
  272. Structure* errorStructure() const { return m_errorStructure.get(); }
  273. Structure* functionStructure() const { return m_functionStructure.get(); }
  274. Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(); }
  275. Structure* namedFunctionStructure() const { return m_namedFunctionStructure.get(); }
  276. PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
  277. Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
  278. Structure* privateNameStructure() const { return m_privateNameStructure.get(); }
  279. Structure* internalFunctionStructure() const { return m_internalFunctionStructure.get(); }
  280. Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
  281. Structure* regExpStructure() const { return m_regExpStructure.get(); }
  282. Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }
  283. void* actualPointerFor(Special::Pointer pointer)
  284. {
  285. ASSERT(pointer < Special::TableSize);
  286. #if ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT
  287. return JSCBridge::sharedInstance()->toll()->forGlobalObject(this).m_specialPointers[pointer];
  288. #else
  289. return m_specialPointers[pointer];
  290. #endif
  291. }
  292. WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }
  293. WatchpointSet* havingABadTimeWatchpoint() { return m_havingABadTimeWatchpoint.get(); }
  294. bool isHavingABadTime() const
  295. {
  296. return m_havingABadTimeWatchpoint->hasBeenInvalidated();
  297. }
  298. void haveABadTime(VM&);
  299. bool arrayPrototypeChainIsSane();
  300. void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
  301. unsigned profileGroup() const
  302. {
  303. if (!m_rareData)
  304. return 0;
  305. return m_rareData->profileGroup;
  306. }
  307. Debugger* debugger() const { return m_debugger; }
  308. void setDebugger(Debugger* debugger) { m_debugger = debugger; }
  309. const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }
  310. static bool allowsAccessFrom(const JSGlobalObject*, ExecState*) { return true; }
  311. static bool supportsProfiling(const JSGlobalObject*) { return false; }
  312. static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
  313. JS_EXPORT_PRIVATE ExecState* globalExec();
  314. static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
  315. static bool javaScriptExperimentsEnabled(const JSGlobalObject*) { return false; }
  316. bool isDynamicScope(bool& requiresDynamicChecks) const;
  317. bool evalEnabled() const { return m_evalEnabled; }
  318. const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; }
  319. void setEvalEnabled(bool enabled, const String& errorMessage = String())
  320. {
  321. m_evalEnabled = enabled;
  322. m_evalDisabledErrorMessage = errorMessage;
  323. }
  324. void resetPrototype(VM&, JSValue prototype);
  325. VM& vm() const { return *Heap::heap(this)->vm(); }
  326. JSObject* globalThis() const;
  327. static Structure* createStructure(VM& vm, JSValue prototype)
  328. {
  329. return Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), &s_info);
  330. }
  331. void registerWeakMap(OpaqueJSWeakObjectMap* map)
  332. {
  333. createRareDataIfNeeded();
  334. m_rareData->weakMaps.add(map);
  335. }
  336. void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
  337. {
  338. if (m_rareData)
  339. m_rareData->weakMaps.remove(map);
  340. }
  341. OpaqueJSClassDataMap& opaqueJSClassData()
  342. {
  343. createRareDataIfNeeded();
  344. return m_rareData->opaqueJSClassData;
  345. }
  346. double weakRandomNumber() { return m_weakRandom.get(); }
  347. unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
  348. UnlinkedProgramCodeBlock* createProgramCodeBlock(CallFrame*, ProgramExecutable*, JSObject** exception);
  349. UnlinkedEvalCodeBlock* createEvalCodeBlock(CodeCache*, CallFrame*, JSScope*, EvalExecutable*, JSObject** exception);
  350. protected:
  351. static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
  352. struct GlobalPropertyInfo {
  353. GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
  354. : identifier(i)
  355. , value(v)
  356. , attributes(a)
  357. {
  358. }
  359. const Identifier identifier;
  360. JSValue value;
  361. unsigned attributes;
  362. };
  363. JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
  364. JS_EXPORT_PRIVATE static JSC::JSObject* toThisObject(JSC::JSCell*, JSC::ExecState*);
  365. JS_EXPORT_PRIVATE void setGlobalThis(VM&, JSObject* globalThis);
  366. private:
  367. friend class LLIntOffsetsExtractor;
  368. // FIXME: Fold reset into init.
  369. JS_EXPORT_PRIVATE void init(JSObject* thisValue);
  370. void reset(JSValue prototype);
  371. void createThrowTypeError(ExecState*);
  372. JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
  373. };
  374. JSGlobalObject* asGlobalObject(JSValue);
  375. inline JSGlobalObject* asGlobalObject(JSValue value)
  376. {
  377. ASSERT(asObject(value)->isGlobalObject());
  378. return jsCast<JSGlobalObject*>(asObject(value));
  379. }
  380. inline bool JSGlobalObject::hasOwnPropertyForWrite(ExecState* exec, PropertyName propertyName)
  381. {
  382. PropertySlot slot;
  383. if (Base::getOwnPropertySlot(this, exec, propertyName, slot))
  384. return true;
  385. bool slotIsWriteable;
  386. return symbolTableGet(this, propertyName, slot, slotIsWriteable);
  387. }
  388. inline bool JSGlobalObject::symbolTableHasProperty(PropertyName propertyName)
  389. {
  390. SymbolTableEntry entry = symbolTable()->inlineGet(propertyName.publicName());
  391. return !entry.isNull();
  392. }
  393. inline JSGlobalObject* ExecState::dynamicGlobalObject()
  394. {
  395. if (this == lexicalGlobalObject()->globalExec())
  396. return lexicalGlobalObject();
  397. // For any ExecState that's not a globalExec, the
  398. // dynamic global object must be set since code is running
  399. ASSERT(vm().dynamicGlobalObject);
  400. return vm().dynamicGlobalObject;
  401. }
  402. inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, unsigned initialLength = 0)
  403. {
  404. return ArrayAllocationProfile::updateLastAllocationFor(profile, JSArray::create(exec->vm(), initialLength >= MIN_SPARSE_ARRAY_INDEX ? globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithArrayStorage) : globalObject->arrayStructureForProfileDuringAllocation(profile), initialLength));
  405. }
  406. inline JSArray* constructEmptyArray(ExecState* exec, ArrayAllocationProfile* profile, unsigned initialLength = 0)
  407. {
  408. return constructEmptyArray(exec, profile, exec->lexicalGlobalObject(), initialLength);
  409. }
  410. inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const ArgList& values)
  411. {
  412. return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, globalObject->arrayStructureForProfileDuringAllocation(profile), values));
  413. }
  414. inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const ArgList& values)
  415. {
  416. return constructArray(exec, profile, exec->lexicalGlobalObject(), values);
  417. }
  418. inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, const JSValue* values, unsigned length)
  419. {
  420. return ArrayAllocationProfile::updateLastAllocationFor(profile, constructArray(exec, globalObject->arrayStructureForProfileDuringAllocation(profile), values, length));
  421. }
  422. inline JSArray* constructArray(ExecState* exec, ArrayAllocationProfile* profile, const JSValue* values, unsigned length)
  423. {
  424. return constructArray(exec, profile, exec->lexicalGlobalObject(), values, length);
  425. }
  426. class DynamicGlobalObjectScope {
  427. WTF_MAKE_NONCOPYABLE(DynamicGlobalObjectScope);
  428. public:
  429. JS_EXPORT_PRIVATE DynamicGlobalObjectScope(VM&, JSGlobalObject*);
  430. ~DynamicGlobalObjectScope()
  431. {
  432. m_dynamicGlobalObjectSlot = m_savedDynamicGlobalObject;
  433. }
  434. private:
  435. JSGlobalObject*& m_dynamicGlobalObjectSlot;
  436. JSGlobalObject* m_savedDynamicGlobalObject;
  437. };
  438. inline bool JSGlobalObject::isDynamicScope(bool&) const
  439. {
  440. return true;
  441. }
  442. inline JSObject* JSScope::globalThis()
  443. {
  444. return globalObject()->globalThis();
  445. }
  446. inline JSObject* JSGlobalObject::globalThis() const
  447. {
  448. return m_globalThis.get();
  449. }
  450. } // namespace JSC
  451. #endif // JSGlobalObject_h