JSAPIValueWrapper.h 2.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
 *  Copyright (C) 2003, 2004, 2005, 2007, 2008 Apple Inc. All rights reserved.
 *
 *  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.
 *
 */

#ifndef JSAPIValueWrapper_h
#define JSAPIValueWrapper_h

#include "JSCell.h"
27
#include "JSValue.h"
28
#include "CallFrame.h"
29
#include "Structure.h"
30 31 32 33 34 35

namespace JSC {

    class JSAPIValueWrapper : public JSCell {
        friend JSValue jsAPIValueWrapper(ExecState*, JSValue);
    public:
36 37
        typedef JSCell Base;

38
        JSValue value() const { return m_value.get(); }
39 40 41

        virtual bool isAPIValueWrapper() const { return true; }

42
        static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
43
        {
44
            return Structure::create(globalData, prototype, TypeInfo(CompoundType, OverridesVisitChildren | OverridesGetPropertyNames), AnonymousSlotCount, &s_info);
45
        }
46
        
47
        static const ClassInfo s_info;
48 49 50
        
        static JSAPIValueWrapper* create(ExecState* exec, JSValue value) 
        {
51 52 53
            JSAPIValueWrapper* wrapper = new (allocateCell<JSAPIValueWrapper>(*exec->heap())) JSAPIValueWrapper(exec);
            wrapper->finishCreation(exec, value);
            return wrapper;
54
        }
55

56 57 58 59 60 61 62 63
    protected:
        void finishCreation(ExecState* exec, JSValue value)
        {
            Base::finishCreation(exec->globalData());
            m_value.set(exec->globalData(), this, value);
            ASSERT(!value.isCell());
        }

64
    private:
65
        JSAPIValueWrapper(ExecState* exec)
66
            : JSCell(exec->globalData(), exec->globalData().apiWrapperStructure.get())
67 68 69
        {
        }

70
        WriteBarrier<Unknown> m_value;
71 72 73 74
    };

    inline JSValue jsAPIValueWrapper(ExecState* exec, JSValue value)
    {
75
        return JSAPIValueWrapper::create(exec, value);
76 77 78 79 80
    }

} // namespace JSC

#endif // JSAPIValueWrapper_h