JSGlobalObject.h 20.1 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 34
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
35
#include <wtf/RandomNumber.h>
36

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

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

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

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

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

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

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

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

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

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

            WeakMapSet weakMaps;
            unsigned profileGroup;
        };

    protected:

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

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

        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;
110
        WriteBarrier<GetterSetter> m_throwTypeErrorGetterSetter;
111 112 113 114 115 116 117 118 119

        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
120
        WriteBarrier<ErrorPrototype> m_errorPrototype;
121

122 123 124 125 126 127 128 129
        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;
130
        WriteBarrier<Structure> m_nullPrototypeObjectStructure;
131 132
        WriteBarrier<Structure> m_errorStructure;
        WriteBarrier<Structure> m_functionStructure;
133
        WriteBarrier<Structure> m_boundFunctionStructure;
134
        WriteBarrier<Structure> m_namedFunctionStructure;
135
        PropertyOffset m_functionNameOffset;
136
        WriteBarrier<Structure> m_numberObjectStructure;
137
        WriteBarrier<Structure> m_privateNameStructure;
138 139 140 141
        WriteBarrier<Structure> m_regExpMatchesArrayStructure;
        WriteBarrier<Structure> m_regExpStructure;
        WriteBarrier<Structure> m_stringObjectStructure;
        WriteBarrier<Structure> m_internalFunctionStructure;
142

143
        Debugger* m_debugger;
144

145
        OwnPtr<JSGlobalObjectRareData> m_rareData;
146

147
        WeakRandom m_weakRandom;
ggaren@apple.com's avatar
ggaren@apple.com committed
148

149 150
        SymbolTable m_symbolTable;

151
        bool m_evalEnabled;
152
        bool m_experimentsEnabled;
153

154 155 156
        static JS_EXPORTDATA const GlobalObjectMethodTable s_globalObjectMethodTable;
        const GlobalObjectMethodTable* m_globalObjectMethodTable;

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

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

        static JS_EXPORTDATA const ClassInfo s_info;

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

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

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

196
    public:
197 198
        JS_EXPORT_PRIVATE ~JSGlobalObject();
        JS_EXPORT_PRIVATE static void destroy(JSCell*);
ggaren@apple.com's avatar
ggaren@apple.com committed
199

200
        JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
201

202 203 204 205
        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&);
206

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

209 210 211
        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);
212

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

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

220 221 222 223 224 225 226 227 228 229 230 231 232
        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(); }
233 234 235 236 237 238
        GetterSetter* throwTypeErrorGetterSetter(ExecState* exec)
        {
            if (!m_throwTypeErrorGetterSetter)
                createThrowTypeError(exec);
            return m_throwTypeErrorGetterSetter.get();
        }
239 240 241 242 243 244 245 246 247

        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
248
        ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
249 250 251 252 253 254 255 256 257 258 259

        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(); }
260
        Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
261 262
        Structure* errorStructure() const { return m_errorStructure.get(); }
        Structure* functionStructure() const { return m_functionStructure.get(); }
263
        Structure* boundFunctionStructure() const { return m_boundFunctionStructure.get(); }
264
        Structure* namedFunctionStructure() const { return m_namedFunctionStructure.get(); }
265
        PropertyOffset functionNameOffset() const { return m_functionNameOffset; }
266
        Structure* numberObjectStructure() const { return m_numberObjectStructure.get(); }
267
        Structure* privateNameStructure() const { return m_privateNameStructure.get(); }
268 269 270 271 272
        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(); }

273 274 275 276 277 278 279
        void setProfileGroup(unsigned value) { createRareDataIfNeeded(); m_rareData->profileGroup = value; }
        unsigned profileGroup() const
        { 
            if (!m_rareData)
                return 0;
            return m_rareData->profileGroup;
        }
280 281 282

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

284 285
        const GlobalObjectMethodTable* globalObjectMethodTable() const { return m_globalObjectMethodTable; }

286
        static bool allowsAccessFrom(const JSGlobalObject*, ExecState*) { return true; }
287 288
        static bool supportsProfiling(const JSGlobalObject*) { return false; }
        static bool supportsRichSourceInfo(const JSGlobalObject*) { return true; }
289

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

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

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

297
        bool isDynamicScope(bool& requiresDynamicChecks) const;
298

299 300
        void setEvalEnabled(bool enabled) { m_evalEnabled = enabled; }
        bool evalEnabled() { return m_evalEnabled; }
301

302
        void resetPrototype(JSGlobalData&, JSValue prototype);
303

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

306
        static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
darin@apple.com's avatar
darin@apple.com committed
307
        {
308
            return Structure::create(globalData, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), &s_info);
darin@apple.com's avatar
darin@apple.com committed
309 310
        }

311 312
        void registerWeakMap(OpaqueJSWeakObjectMap* map)
        {
313 314
            createRareDataIfNeeded();
            m_rareData->weakMaps.add(map);
315 316
        }

317
        void unregisterWeakMap(OpaqueJSWeakObjectMap* map)
318
        {
319 320
            if (m_rareData)
                m_rareData->weakMaps.remove(map);
321 322
        }

323
        double weakRandomNumber() { return m_weakRandom.get(); }
324
        unsigned weakRandomInteger() { return m_weakRandom.getUint32(); }
mjs@apple.com's avatar
mjs@apple.com committed
325
    protected:
326

327
        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | JSSegmentedVariableObject::StructureFlags;
328

329
        struct GlobalPropertyInfo {
ggaren@apple.com's avatar
ggaren@apple.com committed
330
            GlobalPropertyInfo(const Identifier& i, JSValue v, unsigned a)
331 332 333 334 335 336
                : identifier(i)
                , value(v)
                , attributes(a)
            {
            }

337
            const Identifier identifier;
ggaren@apple.com's avatar
ggaren@apple.com committed
338
            JSValue value;
339 340
            unsigned attributes;
        };
341
        JS_EXPORT_PRIVATE void addStaticGlobals(GlobalPropertyInfo*, int count);
342

ap@webkit.org's avatar
ap@webkit.org committed
343
    private:
344 345
        friend class LLIntOffsetsExtractor;
        
darin@apple.com's avatar
darin@apple.com committed
346
        // FIXME: Fold reset into init.
347
        JS_EXPORT_PRIVATE void init(JSObject* thisValue);
ggaren@apple.com's avatar
ggaren@apple.com committed
348
        void reset(JSValue prototype);
weinig@apple.com's avatar
weinig@apple.com committed
349

350 351
        void createThrowTypeError(ExecState*);

352
        JS_EXPORT_PRIVATE static void clearRareData(JSCell*);
353
    };
ggaren@apple.com's avatar
ggaren@apple.com committed
354

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

ggaren@apple.com's avatar
ggaren@apple.com committed
357
    inline JSGlobalObject* asGlobalObject(JSValue value)
darin@apple.com's avatar
darin@apple.com committed
358 359
    {
        ASSERT(asObject(value)->isGlobalObject());
360
        return jsCast<JSGlobalObject*>(asObject(value));
darin@apple.com's avatar
darin@apple.com committed
361 362
    }

363
    inline bool JSGlobalObject::hasOwnPropertyForWrite(ExecState* exec, PropertyName propertyName)
364
    {
barraclough@apple.com's avatar
barraclough@apple.com committed
365
        PropertySlot slot;
366
        if (JSSegmentedVariableObject::getOwnPropertySlot(this, exec, propertyName, slot))
367
            return true;
barraclough@apple.com's avatar
barraclough@apple.com committed
368
        bool slotIsWriteable;
369
        return symbolTableGet(this, propertyName, slot, slotIsWriteable);
370 371
    }

372
    inline bool JSGlobalObject::symbolTableHasProperty(PropertyName propertyName)
373
    {
374
        SymbolTableEntry entry = symbolTable().inlineGet(propertyName.publicName());
375 376 377
        return !entry.isNull();
    }

378
    inline JSValue Structure::prototypeForLookup(JSGlobalObject* globalObject) const
379
    {
380
        if (isObject())
381
            return m_prototype.get();
382

383
        ASSERT(typeInfo().type() == StringType);
384 385 386 387 388 389
        return globalObject->stringPrototype();
    }

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

ggaren@apple.com's avatar
ggaren@apple.com committed
392 393 394 395
    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
396
            JSValue prototype = prototypeForLookup(exec);
397
            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
398 399 400 401 402 403 404 405 406
        }
        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
407
        JSValue prototype = prototypeForLookup(exec);
408
        WriteBarrier<Structure>* cachedStructure = cachedPrototypeChain->head();
ggaren@apple.com's avatar
ggaren@apple.com committed
409
        while(*cachedStructure && !prototype.isNull()) {
410
            if (asObject(prototype)->structure() != cachedStructure->get())
ggaren@apple.com's avatar
ggaren@apple.com committed
411 412 413 414 415 416 417
                return false;
            ++cachedStructure;
            prototype = asObject(prototype)->prototype();
        }
        return prototype.isNull() && !*cachedStructure;
    }

418 419 420 421 422 423 424 425 426 427
    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;
    }
428

429 430
    inline JSObject* constructEmptyObject(ExecState* exec, JSGlobalObject* globalObject)
    {
431
        return constructEmptyObject(exec, globalObject->emptyObjectStructure());
432
    }
433

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

439
    inline JSArray* constructEmptyArray(ExecState* exec, JSGlobalObject* globalObject, unsigned initialLength = 0)
440
    {
441
        return JSArray::create(exec->globalData(), globalObject->arrayStructure(), initialLength);
442
    }
443

444
    inline JSArray* constructEmptyArray(ExecState* exec, unsigned initialLength = 0)
445
    {
446
        return constructEmptyArray(exec, exec->lexicalGlobalObject(), initialLength);
447
    }
448
 
449 450
    inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, const ArgList& values)
    {
451
        return constructArray(exec, globalObject->arrayStructure(), values);
452 453 454 455
    }

    inline JSArray* constructArray(ExecState* exec, const ArgList& values)
    {
456
        return constructArray(exec, exec->lexicalGlobalObject(), values);
457 458
    }

459 460
    inline JSArray* constructArray(ExecState* exec, JSGlobalObject* globalObject, const JSValue* values, unsigned length)
    {
461
        return constructArray(exec, globalObject->arrayStructure(), values, length);
462 463 464
    }

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

469 470
    class DynamicGlobalObjectScope {
        WTF_MAKE_NONCOPYABLE(DynamicGlobalObjectScope);
471
    public:
472
        JS_EXPORT_PRIVATE DynamicGlobalObjectScope(JSGlobalData&, JSGlobalObject*);
473 474 475 476 477 478 479 480 481 482 483

        ~DynamicGlobalObjectScope()
        {
            m_dynamicGlobalObjectSlot = m_savedDynamicGlobalObject;
        }

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

484 485 486 487 488
    inline bool JSGlobalObject::isDynamicScope(bool&) const
    {
        return true;
    }

489
} // namespace JSC
490

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