src/script/bridge/qscriptobject_p.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtScript module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QSCRIPTOBJECT_P_H
       
    43 #define QSCRIPTOBJECT_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include <QtCore/qobjectdefs.h>
       
    57 
       
    58 #include "JSObject.h"
       
    59 
       
    60 QT_BEGIN_NAMESPACE
       
    61 
       
    62 class QScriptObjectDelegate;
       
    63 
       
    64 class QScriptObject : public JSC::JSObject
       
    65 {
       
    66 public:
       
    67      // work around CELL_SIZE limitation
       
    68     struct Data
       
    69     {
       
    70         JSC::JSValue data; // QScriptValue::data
       
    71         QScriptObjectDelegate *delegate;
       
    72         bool isMarking; // recursion guard
       
    73 
       
    74         Data() : delegate(0), isMarking(false) {}
       
    75         ~Data();
       
    76     };
       
    77 
       
    78     explicit QScriptObject(WTF::PassRefPtr<JSC::Structure> sid);
       
    79     virtual ~QScriptObject();
       
    80 
       
    81     virtual bool getOwnPropertySlot(JSC::ExecState*,
       
    82                                     const JSC::Identifier& propertyName,
       
    83                                     JSC::PropertySlot&);
       
    84     virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
       
    85                      JSC::JSValue, JSC::PutPropertySlot&);
       
    86     virtual bool deleteProperty(JSC::ExecState*,
       
    87                                 const JSC::Identifier& propertyName,
       
    88                                 bool checkDontDelete = true);
       
    89     virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier&,
       
    90                                        unsigned&) const;
       
    91     virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&,
       
    92                                      bool includeNonEnumerable = false);
       
    93     virtual void markChildren(JSC::MarkStack& markStack);
       
    94     virtual JSC::CallType getCallData(JSC::CallData&);
       
    95     virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
       
    96     virtual bool hasInstance(JSC::ExecState*, JSC::JSValue value, JSC::JSValue proto);
       
    97     virtual bool compareToObject(JSC::ExecState*, JSC::JSObject*);
       
    98 
       
    99     virtual const JSC::ClassInfo* classInfo() const { return &info; }
       
   100     static const JSC::ClassInfo info;
       
   101 
       
   102     static WTF::PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
       
   103     {
       
   104         return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance | JSC::OverridesHasInstance));
       
   105     }
       
   106 
       
   107     inline JSC::JSValue data() const;
       
   108     inline void setData(JSC::JSValue data);
       
   109 
       
   110     inline QScriptObjectDelegate *delegate() const;
       
   111     inline void setDelegate(QScriptObjectDelegate *delegate);
       
   112 
       
   113 protected:
       
   114     Data *d;
       
   115 };
       
   116 
       
   117 class QScriptObjectPrototype : public QScriptObject
       
   118 {
       
   119 public:
       
   120     QScriptObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,
       
   121                            JSC::Structure* prototypeFunctionStructure);
       
   122 };
       
   123 
       
   124 class QScriptObjectDelegate
       
   125 {
       
   126 public:
       
   127     enum Type {
       
   128         QtObject,
       
   129         Variant,
       
   130         ClassObject
       
   131     };
       
   132 
       
   133     QScriptObjectDelegate();
       
   134     virtual ~QScriptObjectDelegate();
       
   135 
       
   136     virtual Type type() const = 0;
       
   137 
       
   138     virtual bool getOwnPropertySlot(QScriptObject*, JSC::ExecState*,
       
   139                                     const JSC::Identifier& propertyName,
       
   140                                     JSC::PropertySlot&);
       
   141     virtual void put(QScriptObject*, JSC::ExecState* exec, const JSC::Identifier& propertyName,
       
   142                      JSC::JSValue, JSC::PutPropertySlot&);
       
   143     virtual bool deleteProperty(QScriptObject*, JSC::ExecState*,
       
   144                                 const JSC::Identifier& propertyName,
       
   145                                 bool checkDontDelete = true);
       
   146     virtual bool getPropertyAttributes(const QScriptObject*, JSC::ExecState*,
       
   147                                        const JSC::Identifier&, unsigned&) const;
       
   148     virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*, JSC::PropertyNameArray&,
       
   149                                      bool includeNonEnumerable = false);
       
   150     virtual void markChildren(QScriptObject*, JSC::MarkStack& markStack);
       
   151     virtual JSC::CallType getCallData(QScriptObject*, JSC::CallData&);
       
   152     virtual JSC::ConstructType getConstructData(QScriptObject*, JSC::ConstructData&);
       
   153     virtual bool hasInstance(QScriptObject*, JSC::ExecState*,
       
   154                              JSC::JSValue value, JSC::JSValue proto);
       
   155     virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
       
   156 
       
   157 private:
       
   158     Q_DISABLE_COPY(QScriptObjectDelegate)
       
   159 };
       
   160 
       
   161 inline JSC::JSValue QScriptObject::data() const
       
   162 {
       
   163     if (!d)
       
   164         return JSC::JSValue();
       
   165     return d->data;
       
   166 }
       
   167 
       
   168 inline void QScriptObject::setData(JSC::JSValue data)
       
   169 {
       
   170     if (!d)
       
   171         d = new Data();
       
   172     d->data = data;
       
   173 }
       
   174 
       
   175 inline QScriptObjectDelegate *QScriptObject::delegate() const
       
   176 {
       
   177     if (!d)
       
   178         return 0;
       
   179     return d->delegate;
       
   180 }
       
   181 
       
   182 inline void QScriptObject::setDelegate(QScriptObjectDelegate *delegate)
       
   183 {
       
   184     if (!d)
       
   185         d = new Data();
       
   186     else
       
   187         delete d->delegate;
       
   188     d->delegate = delegate;
       
   189 }
       
   190 
       
   191 QT_END_NAMESPACE
       
   192 
       
   193 #endif