JSGlobalObject.h 20.3 KB
Newer Older
1 2
/*
 *  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3
 *  Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

weinig@apple.com's avatar
weinig@apple.com committed
22 23
#ifndef JSGlobalObject_h
#define JSGlobalObject_h
24

25
#include "JSArray.h"
ap@webkit.org's avatar
ap@webkit.org committed
26
#include "JSGlobalData.h"
27
#include "JSGlobalThis.h"
28
#include "JSSegmentedVariableObject.h"
29
#include "JSWeakObjectMapRefInternal.h"
30 31
#include "NumberPrototype.h"
#include "StringPrototype.h"
32
#include "StructureChain.h"
33
#include "Watchpoint.h"
34 35
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
36
#include <wtf/RandomNumber.h>
37

38
namespace JSC {
ggaren@apple.com's avatar
ggaren@apple.com committed
39

ggaren@apple.com's avatar
ggaren@apple.com committed
40 41 42 43
    class ArrayPrototype;
    class BooleanPrototype;
    class DatePrototype;
    class Debugger;
darin@apple.com's avatar
darin@apple.com committed
44
    class ErrorConstructor;
arv@chromium.org's avatar
arv@chromium.org committed
45
    class ErrorPrototype;
ggaren@apple.com's avatar
ggaren@apple.com committed
46
    class FunctionPrototype;
47
    class GetterSetter;
48
    class GlobalCodeBlock;
49
    class LLIntOffsetsExtractor;
darin@apple.com's avatar
darin@apple.com committed
50
    class NativeErrorConstructor;
51
    class ProgramCodeBlock;
darin@apple.com's avatar
darin@apple.com committed
52
    class RegExpConstructor;
ggaren@apple.com's avatar
ggaren@apple.com committed
53
    class RegExpPrototype;
ap@webkit.org's avatar
ap@webkit.org committed
54
    class RegisterFile;
darin@apple.com's avatar
darin@apple.com committed
55

56
    struct ActivationStackNode;
darin@apple.com's avatar
darin@apple.com committed
57
    struct HashTable;
ggaren@apple.com's avatar
ggaren@apple.com committed
58

weinig@apple.com's avatar
weinig@apple.com committed
59
    typedef Vector<ExecState*, 16> ExecStateStack;
60
    
61
    struct GlobalObjectMethodTable {
62 63 64
        typedef bool (*AllowsAccessFromFunctionPtr)(const JSGlobalObject*, ExecState*);
        AllowsAccessFromFunctionPtr allowsAccessFrom;

65 66 67 68 69 70 71 72
        typedef bool (*SupportsProfilingFunctionPtr)(const JSGlobalObject*); 
        SupportsProfilingFunctionPtr supportsProfiling;

        typedef bool (*SupportsRichSourceInfoFunctionPtr)(const JSGlobalObject*);
        SupportsRichSourceInfoFunctionPtr supportsRichSourceInfo;

        typedef bool (*ShouldInterruptScriptFunctionPtr)(const JSGlobalObject*);
        ShouldInterruptScriptFunctionPtr shouldInterruptScript;
73 74 75

        typedef bool (*JavaScriptExperimentsEnabledFunctionPtr)(const JSGlobalObject*);
        JavaScriptExperimentsEnabledFunctionPtr javaScriptExperimentsEnabled;
76 77
    };

78
    class JSGlobalObject : public JSSegmentedVariableObject {
79
    private:
80
        typedef HashSet<RefPtr<OpaqueJSWeakObjectMap> > WeakMapSet;
ggaren@apple.com's avatar
ggaren@apple.com committed
81

82 83 84 85 86 87 88 89 90 91 92 93
        struct JSGlobalObjectRareData {
            JSGlobalObjectRareData()
                : profileGroup(0)
            {
            }

            WeakMapSet weakMaps;
            unsigned profileGroup;
        };

    protected:

94
        Register m_globalCallFrame[RegisterFile::CallFrameHeaderSize];
95 96

        WriteBarrier<ScopeChainNode> m_globalScopeChain;
97
        WriteBarrier<JSObject> m_methodCallDummy;
98 99 100 101 102 103 104 105 106 107 108 109 110

        WriteBarrier<RegExpConstructor> m_regExpConstructor;
        WriteBarrier<ErrorConstructor> m_errorConstructor;
        WriteBarrier<NativeErrorConstructor> m_evalErrorConstructor;
        WriteBarrier<NativeErrorConstructor> m_rangeErrorConstructor;
        WriteBarrier<NativeErrorConstructor> m_referenceErrorConstructor;
        WriteBarrier<NativeErrorConstructor> m_syntaxErrorConstructor;
        WriteBarrier<NativeErrorConstructor> m_typeErrorConstructor;
        WriteBarrier<NativeErrorConstructor> m_URIErrorConstructor;

        WriteBarrier<JSFunction> m_evalFunction;
        WriteBarrier<JSFunction> m_callFunction;
        WriteBarrier<JSFunction> m_applyFunction;
111
        WriteBarrier<GetterSetter> m_throwTypeErrorGetterSetter;
112 113 114 115 116 117 118 119 120

        WriteBarrier<ObjectPrototype> m_objectPrototype;
        WriteBarrier<FunctionPrototype> m_functionPrototype;
        WriteBarrier<ArrayPrototype> m_arrayPrototype;
        WriteBarrier<BooleanPrototype> m_booleanPrototype;
        WriteBarrier<StringPrototype> m_stringPrototype;
        WriteBarrier<NumberPrototype> m_numberPrototype;
        WriteBarrier<DatePrototype> m_datePrototype;
        WriteBarrier<RegExpPrototype> m_regExpPrototype;
arv@chromium.org's avatar
arv@chromium.org committed
121
        WriteBarrier<ErrorPrototype> m_errorPrototype;
122

123 124 125 126 127 128 129 130
        WriteBarrier<Structure> m_argumentsStructure;
        WriteBarrier<Structure> m_arrayStructure;
        WriteBarrier<Structure> m_booleanObjectStructure;
        WriteBarrier<Structure> m_callbackConstructorStructure;
        WriteBarrier<Structure> m_callbackFunctionStructure;
        WriteBarrier<Structure> m_callbackObjectStructure;
        WriteBarrier<Structure> m_dateStructure;
        WriteBarrier<Structure> m_emptyObjectStructure;
131
        WriteBarrier<Structure> m_nullPrototypeObjectStructure;
132 133
        WriteBarrier<Structure> m_errorStructure;
        WriteBarrier<Structure> m_functionStructure;
134
        WriteBarrier<Structure> m_boundFunctionStructure;
135
        WriteBarrier<Structure> m_namedFunctionStructure;
136
        PropertyOffset m_functionNameOffset;
137
        WriteBarrier<Structure> m_numberObjectStructure;
138
        WriteBarrier<Structure> m_privateNameStructure;
139 140 141 142
        WriteBarrier<Structure> m_regExpMatchesArrayStructure;
        WriteBarrier<Structure> m_regExpStructure;
        WriteBarrier<Structure> m_stringObjectStructure;
        WriteBarrier<Structure> m_internalFunctionStructure;
143

144
        Debugger* m_debugger;
145

146 147
        RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;

148
        OwnPtr<JSGlobalObjectRareData> m_rareData;
149

150
        WeakRandom m_weakRandom;
ggaren@apple.com's avatar
ggaren@apple.com committed
151

152 153
        SymbolTable m_symbolTable;

154
        bool m_evalEnabled;
155
        bool m_experimentsEnabled;
156

157 158 159
        static JS_EXPORTDATA const GlobalObjectMethodTable s_globalObjectMethodTable;
        const GlobalObjectMethodTable* m_globalObjectMethodTable;

160 161
        void createRareDataIfNeeded()
        {
162 163 164 165
            if (m_rareData)
                return;
            m_rareData = adoptPtr(new JSGlobalObjectRareData);
            Heap::heap(this)->addFinalizer(this, clearRareData);
166 167
        }
        
ggaren@apple.com's avatar
ggaren@apple.com committed
168
    public:
169
        typedef JSSegmentedVariableObject Base;
170

171 172
        static JSGlobalObject* create(JSGlobalData& globalData, Structure* structure)
        {
173
            JSGlobalObject* globalObject = new (NotNull, allocateCell<JSGlobalObject>(globalData.heap)) JSGlobalObject(globalData, structure);
174
            globalObject->finishCreation(globalData);
175
            return globalObject;
176 177 178 179 180
        }

        static JS_EXPORTDATA const ClassInfo s_info;

    protected:
181
        JS_EXPORT_PRIVATE explicit JSGlobalObject(JSGlobalData&, Structure*, const GlobalObjectMethodTable* = 0);
182

183 184 185 186
        void finishCreation(JSGlobalData& globalData)
        {
            Base::finishCreation(globalData);
            structure()->setGlobalObject(globalData, this);
187
            m_experimentsEnabled = m_globalObjectMethodTable->javaScriptExperimentsEnabled(this);
188 189 190 191
            init(this);
        }

        void finishCreation(JSGlobalData& globalData, JSGlobalThis* thisValue)
ggaren@apple.com's avatar
ggaren@apple.com committed
192
        {
193
            Base::finishCreation(globalData);
194
            structure()->setGlobalObject(globalData, this);
195
            m_experimentsEnabled = m_globalObjectMethodTable->javaScriptExperimentsEnabled(this);
darin@apple.com's avatar
darin@apple.com committed
196
            init(thisValue);
ggaren@apple.com's avatar
ggaren@apple.com committed
197 198
        }

199
    public:
200 201
        JS_EXPORT_PRIVATE ~JSGlobalObject();
        JS_EXPORT_PRIVATE static void destroy(JSCell*);
ggaren@apple.com's avatar
ggaren@apple.com committed
202

203
        JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
204

205 206 207 208
        JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
        JS_EXPORT_PRIVATE static bool getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
        bool hasOwnPropertyForWrite(ExecState*, PropertyName);
        JS_EXPORT_PRIVATE static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
209

210
        JS_EXPORT_PRIVATE static void putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned attributes);
ggaren@apple.com's avatar
ggaren@apple.com committed
211

212 213 214
        JS_EXPORT_PRIVATE static void defineGetter(JSObject*, ExecState*, PropertyName, JSObject* getterFunc, unsigned attributes);
        JS_EXPORT_PRIVATE static void defineSetter(JSObject*, ExecState*, PropertyName, JSObject* setterFunc, unsigned attributes);
        JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool shouldThrow);
215

216 217
        // We use this in the code generator as we perform symbol table
        // lookups prior to initializing the properties
218
        bool symbolTableHasProperty(PropertyName);
219

ggaren@apple.com's avatar
ggaren@apple.com committed
220 221 222
        // The following accessors return pristine values, even if a script 
        // replaces the global object's associated property.

223 224 225 226 227 228 229 230 231 232 233 234 235
        RegExpConstructor* regExpConstructor() const { return m_regExpConstructor.get(); }

        ErrorConstructor* errorConstructor() const { return m_errorConstructor.get(); }
        NativeErrorConstructor* evalErrorConstructor() const { return m_evalErrorConstructor.get(); }
        NativeErrorConstructor* rangeErrorConstructor() const { return m_rangeErrorConstructor.get(); }
        NativeErrorConstructor* referenceErrorConstructor() const { return m_referenceErrorConstructor.get(); }
        NativeErrorConstructor* syntaxErrorConstructor() const { return m_syntaxErrorConstructor.get(); }
        NativeErrorConstructor* typeErrorConstructor() const { return m_typeErrorConstructor.get(); }
        NativeErrorConstructor* URIErrorConstructor() const { return m_URIErrorConstructor.get(); }

        JSFunction* evalFunction() const { return m_evalFunction.get(); }
        JSFunction* callFunction() const { return m_callFunction.get(); }
        JSFunction* applyFunction() const { return m_applyFunction.get(); }
236 237 238 239 240 241
        GetterSetter* throwTypeErrorGetterSetter(ExecState* exec)
        {
            if (!m_throwTypeErrorGetterSetter)
                createThrowTypeError(exec);
            return m_throwTypeErrorGetterSetter.get();
        }
242 243 244 245 246 247 248 249 250

        ObjectPrototype* objectPrototype() const { return m_objectPrototype.get(); }
        FunctionPrototype* functionPrototype() const { return m_functionPrototype.get(); }
        ArrayPrototype* arrayPrototype() const { return m_arrayPrototype.get(); }
        BooleanPrototype* booleanPrototype() const { return m_booleanPrototype.get(); }
        StringPrototype* stringPrototype() const { return m_stringPrototype.get(); }
        NumberPrototype* numberPrototype() const { return m_numberPrototype.get(); }
        DatePrototype* datePrototype() const { return m_datePrototype.get(); }
        RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
arv@chromium.org's avatar
arv@chromium.org committed
251
        ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
252 253 254 255 256 257 258 259 260 261 262

        JSObject* methodCallDummy() const { return m_methodCallDummy.get(); }

        Structure* argumentsStructure() const { return m_argumentsStructure.get(); }
        Structure* arrayStructure() const { return m_arrayStructure.get(); }
        Structure* booleanObjectStructure() const { return m_booleanObjectStructure.get(); }
        Structure* callbackConstructorStructure() const { return m_callbackConstructorStructure.get(); }
        Structure* callbackFunctionStructure() const { return m_callbackFunctionStructure.get(); }
        Structure* callbackObjectStructure() const { return m_callbackObjectStructure.get(); }
        Structure* dateStructure() const { return m_dateStructure.get(); }
        Structure* emptyObjectStructure() const { return m_emptyObjectStructure.get(); }
263
        Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
264 265
        Structure* errorStructure() const { return m_errorStructure.get(); }
        Structure* functionStructure() const { return m_functionStructure.get(); }
266
        Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(); }
267
        Structure* namedFunctionStructure() const { return m_namedFunctionStructure.get(); }
268
        PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
269
        Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
270
        Structure* privateNameStructure() const { return m_privateNameStructure.get(); }
271 272 273 274 275
        Structure* internalFunctionStructure() const { return m_internalFunctionStructure.get(); }
        Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
        Structure* regExpStructure() const { return m_regExpStructure.get(); }
        Structure* stringObjectStructure() const { return m_stringObjectStructure.get(); }

276 277
        WatchpointSet* masqueradesAsUndefinedWatchpoint() { return m_masqueradesAsUndefinedWatchpoint.get(); }

278 279 280 281 282 283 284
        void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
        unsigned profileGroup() const
        { 
            if (!m_rareData)
                return 0;
            return m_rareData->profileGroup;
        }
285 286 287

        Debugger* debugger() const { return m_debugger; }
        void setDebugger(Debugger* debugger) { m_debugger = debugger; }
288

289 290
        const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }

291
        static bool allowsAccessFrom(const JSGlobalObject*, ExecState*) { return true; }
292 293
        static bool supportsProfiling(const JSGlobalObject*) { return false; }
        static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
294

295
        ScopeChainNode* globalScopeChain() { return m_globalScopeChain.get(); }
ggaren@apple.com's avatar
ggaren@apple.com committed
296

297
        JS_EXPORT_PRIVATE ExecState* globalExec();
ggaren@apple.com's avatar
ggaren@apple.com committed
298

299
        static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
300
        static bool javaScriptExperimentsEnabled(const JSGlobalObject*) { return false; }
ggaren@apple.com's avatar
ggaren@apple.com committed
301

302
        bool isDynamicScope(bool& requiresDynamicChecks) const;
303

304 305
        void setEvalEnabled(bool enabled) { m_evalEnabled = enabled; }
        bool evalEnabled() { return m_evalEnabled; }
306

307
        void resetPrototype(JSGlobalData&, JSValue prototype);
308

309
        JSGlobalData& globalData() const { return *Heap::heap(this)->globalData(); }
ggaren@apple.com's avatar
ggaren@apple.com committed
310

311
        static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
darin@apple.com's avatar
darin@apple.com committed
312
        {
313
            return Structure::create(globalData, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), &s_info);
darin@apple.com's avatar
darin@apple.com committed
314 315
        }

316 317
        void registerWeakMap(OpaqueJSWeakObjectMap* map)
        {
318 319
            createRareDataIfNeeded();
            m_rareData->weakMaps.add(map);
320 321
        }

322
        void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
323
        {
324 325
            if (m_rareData)
                m_rareData->weakMaps.remove(map);
326 327
        }

328
        double weakRandomNumber() { return m_weakRandom.get(); }
329
        unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
mjs@apple.com's avatar
mjs@apple.com committed
330
    protected:
331

332
        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | JSSegmentedVariableObject::StructureFlags;
333

334
        struct GlobalPropertyInfo {
ggaren@apple.com's avatar
ggaren@apple.com committed
335
            GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
336 337 338 339 340 341
                : identifier(i)
                , value(v)
                , attributes(a)
            {
            }

342
            const Identifier identifier;
ggaren@apple.com's avatar
ggaren@apple.com committed
343
            JSValue value;
344 345
            unsigned attributes;
        };
346
        JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
347

ap@webkit.org's avatar
ap@webkit.org committed
348
    private:
349 350
        friend class LLIntOffsetsExtractor;
        
darin@apple.com's avatar
darin@apple.com committed
351
        // FIXME: Fold reset into init.
352
        JS_EXPORT_PRIVATE void init(JSObject* thisValue);
ggaren@apple.com's avatar
ggaren@apple.com committed
353
        void reset(JSValue prototype);
weinig@apple.com's avatar
weinig@apple.com committed
354

355 356
        void createThrowTypeError(ExecState*);

357
        JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
358
    };
ggaren@apple.com's avatar
ggaren@apple.com committed
359

ggaren@apple.com's avatar
ggaren@apple.com committed
360
    JSGlobalObject* asGlobalObject(JSValue);
darin@apple.com's avatar
darin@apple.com committed
361

ggaren@apple.com's avatar
ggaren@apple.com committed
362
    inline JSGlobalObject* asGlobalObject(JSValue value)
darin@apple.com's avatar
darin@apple.com committed
363 364
    {
        ASSERT(asObject(value)->isGlobalObject());
365
        return jsCast<JSGlobalObject*>(asObject(value));
darin@apple.com's avatar
darin@apple.com committed
366 367
    }

368
    inline bool JSGlobalObject::hasOwnPropertyForWrite(ExecState* exec, PropertyName propertyName)
369
    {
barraclough@apple.com's avatar
barraclough@apple.com committed
370
        PropertySlot slot;
371
        if (JSSegmentedVariableObject::getOwnPropertySlot(this, exec, propertyName, slot))
372
            return true;
barraclough@apple.com's avatar
barraclough@apple.com committed
373
        bool slotIsWriteable;
374
        return symbolTableGet(this, propertyName, slot, slotIsWriteable);
375 376
    }

377
    inline bool JSGlobalObject::symbolTableHasProperty(PropertyName propertyName)
378
    {
379
        SymbolTableEntry entry = symbolTable().inlineGet(propertyName.publicName());
380 381 382
        return !entry.isNull();
    }

383
    inline JSValue Structure::prototypeForLookup(JSGlobalObject* globalObject) const
384
    {
385
        if (isObject())
386
            return m_prototype.get();
387

388
        ASSERT(typeInfo().type() == StringType);
389 390 391 392 393 394
        return globalObject->stringPrototype();
    }

    inline JSValue Structure::prototypeForLookup(ExecState* exec) const
    {
        return prototypeForLookup(exec->lexicalGlobalObject());
395 396
    }

ggaren@apple.com's avatar
ggaren@apple.com committed
397 398 399 400
    inline StructureChain* Structure::prototypeChain(ExecState* exec) const
    {
        // We cache our prototype chain so our clients can share it.
        if (!isValid(exec, m_cachedPrototypeChain.get())) {
ggaren@apple.com's avatar
ggaren@apple.com committed
401
            JSValue prototype = prototypeForLookup(exec);
402
            m_cachedPrototypeChain.set(exec->globalData(), this, StructureChain::create(exec->globalData(), prototype.isNull() ? 0 : asObject(prototype)->structure()));
ggaren@apple.com's avatar
ggaren@apple.com committed
403 404 405 406 407 408 409 410 411
        }
        return m_cachedPrototypeChain.get();
    }

    inline bool Structure::isValid(ExecState* exec, StructureChain* cachedPrototypeChain) const
    {
        if (!cachedPrototypeChain)
            return false;

ggaren@apple.com's avatar
ggaren@apple.com committed
412
        JSValue prototype = prototypeForLookup(exec);
413
        WriteBarrier<Structure>* cachedStructure = cachedPrototypeChain->head();
ggaren@apple.com's avatar
ggaren@apple.com committed
414
        while(*cachedStructure && !prototype.isNull()) {
415
            if (asObject(prototype)->structure() != cachedStructure->get())
ggaren@apple.com's avatar
ggaren@apple.com committed
416 417 418 419 420 421 422
                return false;
            ++cachedStructure;
            prototype = asObject(prototype)->prototype();
        }
        return prototype.isNull() && !*cachedStructure;
    }

423 424 425 426 427 428 429 430 431 432
    inline JSGlobalObject* ExecState::dynamicGlobalObject()
    {
        if (this == lexicalGlobalObject()->globalExec())
            return lexicalGlobalObject();

        // For any ExecState that's not a globalExec, the 
        // dynamic global object must be set since code is running
        ASSERT(globalData().dynamicGlobalObject);
        return globalData().dynamicGlobalObject;
    }
433

434 435
    inline JSObject* constructEmptyObject(ExecState* exec, JSGlobalObject* globalObject)
    {
436
        return constructEmptyObject(exec, globalObject->emptyObjectStructure());
437
    }
438

439 440 441 442
    inline JSObject* constructEmptyObject(ExecState* exec)
    {
        return constructEmptyObject(exec, exec->lexicalGlobalObject());
    }
443

444
    inline JSArray* constructEmptyArray(ExecState* exec, JSGlobalObject* globalObject, unsigned initialLength = 0)
445
    {
446
        return JSArray::create(exec->globalData(), globalObject->arrayStructure(), initialLength);
447
    }
448

449
    inline JSArray* constructEmptyArray(ExecState* exec, unsigned initialLength = 0)
450
    {
451
        return constructEmptyArray(exec, exec->lexicalGlobalObject(), initialLength);
452
    }
453
 
454 455
    inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, const ArgList& values)
    {
456
        return constructArray(exec, globalObject->arrayStructure(), values);
457 458 459 460
    }

    inline JSArray* constructArray(ExecState* exec, const ArgList& values)
    {
461
        return constructArray(exec, exec->lexicalGlobalObject(), values);
462 463
    }

464 465
    inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, const JSValue* values, unsigned length)
    {
466
        return constructArray(exec, globalObject->arrayStructure(), values, length);
467 468 469
    }

    inline JSArray* constructArray(ExecState* exec, const JSValue* values, unsigned length)
470
    {
471
        return constructArray(exec, exec->lexicalGlobalObject(), values, length);
472 473
    }

474 475
    class DynamicGlobalObjectScope {
        WTF_MAKE_NONCOPYABLE(DynamicGlobalObjectScope);
476
    public:
477
        JS_EXPORT_PRIVATE DynamicGlobalObjectScope(JSGlobalData&, JSGlobalObject*);
478 479 480 481 482 483 484 485 486 487 488

        ~DynamicGlobalObjectScope()
        {
            m_dynamicGlobalObjectSlot = m_savedDynamicGlobalObject;
        }

    private:
        JSGlobalObject*& m_dynamicGlobalObjectSlot;
        JSGlobalObject* m_savedDynamicGlobalObject;
    };

489 490 491 492 493
    inline bool JSGlobalObject::isDynamicScope(bool&) const
    {
        return true;
    }

494
} // namespace JSC
495

weinig@apple.com's avatar
weinig@apple.com committed
496
#endif // JSGlobalObject_h