src/script/bridge/qscriptobject.cpp
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 #include "config.h"
       
    43 #include "qscriptobject_p.h"
       
    44 #include "private/qobject_p.h"
       
    45 
       
    46 namespace JSC
       
    47 {
       
    48 //QT_USE_NAMESPACE
       
    49 ASSERT_CLASS_FITS_IN_CELL(QT_PREPEND_NAMESPACE(QScriptObject));
       
    50 ASSERT_CLASS_FITS_IN_CELL(QT_PREPEND_NAMESPACE(QScriptObjectPrototype));
       
    51 }
       
    52 
       
    53 QT_BEGIN_NAMESPACE
       
    54 
       
    55 // masquerading as JSC::JSObject
       
    56 const JSC::ClassInfo QScriptObject::info = { "Object", 0, 0, 0 };
       
    57 
       
    58 QScriptObject::Data::~Data()
       
    59 {
       
    60     delete delegate;
       
    61 }
       
    62 
       
    63 QScriptObject::QScriptObject(WTF::PassRefPtr<JSC::Structure> sid)
       
    64     : JSC::JSObject(sid), d(0)
       
    65 {
       
    66 }
       
    67 
       
    68 QScriptObject::~QScriptObject()
       
    69 {
       
    70     delete d;
       
    71 }
       
    72 
       
    73 bool QScriptObject::getOwnPropertySlot(JSC::ExecState* exec,
       
    74                                        const JSC::Identifier& propertyName,
       
    75                                        JSC::PropertySlot& slot)
       
    76 {
       
    77     if (!d || !d->delegate)
       
    78         return JSC::JSObject::getOwnPropertySlot(exec, propertyName, slot);
       
    79     return d->delegate->getOwnPropertySlot(this, exec, propertyName, slot);
       
    80 }
       
    81 
       
    82 void QScriptObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
       
    83                         JSC::JSValue value, JSC::PutPropertySlot& slot)
       
    84 {
       
    85     if (!d || !d->delegate) {
       
    86         JSC::JSObject::put(exec, propertyName, value, slot);
       
    87         return;
       
    88     }
       
    89     d->delegate->put(this, exec, propertyName, value, slot);
       
    90 }
       
    91 
       
    92 bool QScriptObject::deleteProperty(JSC::ExecState* exec,
       
    93                                    const JSC::Identifier& propertyName,
       
    94                                    bool checkDontDelete)
       
    95 {
       
    96     if (!d || !d->delegate)
       
    97         return JSC::JSObject::deleteProperty(exec, propertyName, checkDontDelete);
       
    98     return d->delegate->deleteProperty(this, exec, propertyName, checkDontDelete);
       
    99 }
       
   100 
       
   101 bool QScriptObject::getPropertyAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName,
       
   102                                           unsigned& attributes) const
       
   103 {
       
   104     if (!d || !d->delegate)
       
   105         return JSC::JSObject::getPropertyAttributes(exec, propertyName, attributes);
       
   106     return d->delegate->getPropertyAttributes(this, exec, propertyName, attributes);
       
   107 }
       
   108 
       
   109 void QScriptObject::getOwnPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArray& propertyNames,
       
   110                                         bool includeNonEnumerable)
       
   111 {
       
   112     if (!d || !d->delegate) {
       
   113         JSC::JSObject::getOwnPropertyNames(exec, propertyNames, includeNonEnumerable);
       
   114         return;
       
   115     }
       
   116     d->delegate->getOwnPropertyNames(this, exec, propertyNames, includeNonEnumerable);
       
   117 }
       
   118 
       
   119 bool QScriptObject::compareToObject(JSC::ExecState* exec, JSC::JSObject *other)
       
   120 {
       
   121     if (!d || !d->delegate) {
       
   122         return JSC::JSObject::compareToObject(exec, other);
       
   123     }
       
   124     return d->delegate->compareToObject(this, exec, other);
       
   125 }
       
   126 
       
   127 void QScriptObject::markChildren(JSC::MarkStack& markStack)
       
   128 {
       
   129     if (!d)
       
   130         d = new Data();
       
   131     if (d->isMarking)
       
   132         return;
       
   133     QBoolBlocker markBlocker(d->isMarking, true);
       
   134     if (d && d->data)
       
   135         markStack.append(d->data);
       
   136     if (!d || !d->delegate) {
       
   137         JSC::JSObject::markChildren(markStack);
       
   138         return;
       
   139     }
       
   140     d->delegate->markChildren(this, markStack);
       
   141 }
       
   142 
       
   143 JSC::CallType QScriptObject::getCallData(JSC::CallData &data)
       
   144 {
       
   145     if (!d || !d->delegate)
       
   146         return JSC::JSObject::getCallData(data);
       
   147     return d->delegate->getCallData(this, data);
       
   148 }
       
   149 
       
   150 JSC::ConstructType QScriptObject::getConstructData(JSC::ConstructData &data)
       
   151 {
       
   152     if (!d || !d->delegate)
       
   153         return JSC::JSObject::getConstructData(data);
       
   154     return d->delegate->getConstructData(this, data);
       
   155 }
       
   156 
       
   157 bool QScriptObject::hasInstance(JSC::ExecState* exec, JSC::JSValue value, JSC::JSValue proto)
       
   158 {
       
   159     if (!d || !d->delegate)
       
   160         return JSC::JSObject::hasInstance(exec, value, proto);
       
   161     return d->delegate->hasInstance(this, exec, value, proto);
       
   162 }
       
   163 
       
   164 QScriptObjectPrototype::QScriptObjectPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure> structure,
       
   165                                                JSC::Structure* /*prototypeFunctionStructure*/)
       
   166     : QScriptObject(structure)
       
   167 {
       
   168 }
       
   169 
       
   170 QScriptObjectDelegate::QScriptObjectDelegate()
       
   171 {
       
   172 }
       
   173 
       
   174 QScriptObjectDelegate::~QScriptObjectDelegate()
       
   175 {
       
   176 }
       
   177 
       
   178 bool QScriptObjectDelegate::getOwnPropertySlot(QScriptObject* object, JSC::ExecState* exec,
       
   179                                                const JSC::Identifier& propertyName,
       
   180                                                JSC::PropertySlot& slot)
       
   181 {
       
   182     return object->JSC::JSObject::getOwnPropertySlot(exec, propertyName, slot);
       
   183 }
       
   184 
       
   185 void QScriptObjectDelegate::put(QScriptObject* object, JSC::ExecState* exec,
       
   186                                 const JSC::Identifier& propertyName,
       
   187                                 JSC::JSValue value, JSC::PutPropertySlot& slot)
       
   188 {
       
   189     object->JSC::JSObject::put(exec, propertyName, value, slot);
       
   190 }
       
   191 
       
   192 bool QScriptObjectDelegate::deleteProperty(QScriptObject* object, JSC::ExecState* exec,
       
   193                                            const JSC::Identifier& propertyName,
       
   194                                            bool checkDontDelete)
       
   195 {
       
   196     return object->JSC::JSObject::deleteProperty(exec, propertyName, checkDontDelete);
       
   197 }
       
   198 
       
   199 bool QScriptObjectDelegate::getPropertyAttributes(const QScriptObject* object,
       
   200                                                   JSC::ExecState* exec,
       
   201                                                   const JSC::Identifier& propertyName,
       
   202                                                   unsigned& attributes) const
       
   203 {
       
   204     return object->JSC::JSObject::getPropertyAttributes(exec, propertyName, attributes);
       
   205 }
       
   206 
       
   207 void QScriptObjectDelegate::getOwnPropertyNames(QScriptObject* object, JSC::ExecState* exec,
       
   208                                                 JSC::PropertyNameArray& propertyNames,
       
   209                                                 bool includeNonEnumerable)
       
   210 {
       
   211     object->JSC::JSObject::getOwnPropertyNames(exec, propertyNames, includeNonEnumerable);
       
   212 }
       
   213 
       
   214 void QScriptObjectDelegate::markChildren(QScriptObject* object, JSC::MarkStack& markStack)
       
   215 {
       
   216     // ### should this call the virtual function instead??
       
   217     object->JSC::JSObject::markChildren(markStack);
       
   218 }
       
   219 
       
   220 JSC::CallType QScriptObjectDelegate::getCallData(QScriptObject* object, JSC::CallData& data)
       
   221 {
       
   222     return object->JSC::JSObject::getCallData(data);
       
   223 }
       
   224 
       
   225 JSC::ConstructType QScriptObjectDelegate::getConstructData(QScriptObject* object, JSC::ConstructData& data)
       
   226 {
       
   227     return object->JSC::JSObject::getConstructData(data);
       
   228 }
       
   229 
       
   230 bool QScriptObjectDelegate::hasInstance(QScriptObject* object, JSC::ExecState* exec,
       
   231                                         JSC::JSValue value, JSC::JSValue proto)
       
   232 {
       
   233     return object->JSC::JSObject::hasInstance(exec, value, proto);
       
   234 }
       
   235 
       
   236 bool QScriptObjectDelegate::compareToObject(QScriptObject* object, JSC::ExecState* exec, JSC::JSObject* o)
       
   237 {
       
   238     return object->JSC::JSObject::compareToObject(exec, o);
       
   239 }
       
   240 
       
   241 QT_END_NAMESPACE