equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtScript module of the Qt Toolkit. |
7 ** This file is part of the QtScript module of the Qt Toolkit. |
8 ** |
8 ** |
52 #include "bridge/qscriptobject_p.h" |
52 #include "bridge/qscriptobject_p.h" |
53 #include "bridge/qscriptclassobject_p.h" |
53 #include "bridge/qscriptclassobject_p.h" |
54 #include "bridge/qscriptvariant_p.h" |
54 #include "bridge/qscriptvariant_p.h" |
55 #include "bridge/qscriptqobject_p.h" |
55 #include "bridge/qscriptqobject_p.h" |
56 #include "bridge/qscriptdeclarativeclass_p.h" |
56 #include "bridge/qscriptdeclarativeclass_p.h" |
|
57 #include "bridge/qscriptdeclarativeobject_p.h" |
57 |
58 |
58 /*! |
59 /*! |
59 \since 4.3 |
60 \since 4.3 |
60 \class QScriptValue |
61 \class QScriptValue |
61 |
62 |
1145 "a different engine"); |
1146 "a different engine"); |
1146 return false; |
1147 return false; |
1147 } |
1148 } |
1148 |
1149 |
1149 if (d->type != other.d_ptr->type) { |
1150 if (d->type != other.d_ptr->type) { |
1150 if (d->type == QScriptValuePrivate::JavaScriptCore) |
1151 if (d->type == QScriptValuePrivate::JavaScriptCore) { |
1151 return JSC::JSValue::strictEqual(d->jscValue, d->engine->scriptValueToJSCValue(other)); |
1152 QScriptEnginePrivate *eng_p = d->engine ? d->engine : other.d_ptr->engine; |
1152 else if (other.d_ptr->type == QScriptValuePrivate::JavaScriptCore) |
1153 if (eng_p) |
1153 return JSC::JSValue::strictEqual(other.d_ptr->engine->scriptValueToJSCValue(*this), other.d_ptr->jscValue); |
1154 return JSC::JSValue::strictEqual(d->jscValue, eng_p->scriptValueToJSCValue(other)); |
|
1155 } else if (other.d_ptr->type == QScriptValuePrivate::JavaScriptCore) { |
|
1156 QScriptEnginePrivate *eng_p = other.d_ptr->engine ? other.d_ptr->engine : d->engine; |
|
1157 if (eng_p) |
|
1158 return JSC::JSValue::strictEqual(eng_p->scriptValueToJSCValue(*this), other.d_ptr->jscValue); |
|
1159 } |
1154 |
1160 |
1155 return false; |
1161 return false; |
1156 } |
1162 } |
1157 switch (d->type) { |
1163 switch (d->type) { |
1158 case QScriptValuePrivate::JavaScriptCore: |
1164 case QScriptValuePrivate::JavaScriptCore: |
1568 QObject *QScriptValue::toQObject() const |
1574 QObject *QScriptValue::toQObject() const |
1569 { |
1575 { |
1570 Q_D(const QScriptValue); |
1576 Q_D(const QScriptValue); |
1571 if (isQObject()) { |
1577 if (isQObject()) { |
1572 QScriptObject *object = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); |
1578 QScriptObject *object = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); |
1573 return static_cast<QScript::QObjectDelegate*>(object->delegate())->value(); |
1579 QScriptObjectDelegate *delegate = object->delegate(); |
1574 } else if (QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(*this)) { |
1580 if (delegate->type() == QScriptObjectDelegate::DeclarativeClassObject) |
1575 return dc->toQObject(QScriptDeclarativeClass::object(*this)); |
1581 return static_cast<QScript::DeclarativeObjectDelegate*>(delegate)->scriptClass()->toQObject(QScriptDeclarativeClass::object(*this)); |
|
1582 return static_cast<QScript::QObjectDelegate*>(delegate)->value(); |
1576 } else if (isVariant()) { |
1583 } else if (isVariant()) { |
1577 QVariant var = toVariant(); |
1584 QVariant var = toVariant(); |
1578 int type = var.userType(); |
1585 int type = var.userType(); |
1579 if ((type == QMetaType::QObjectStar) || (type == QMetaType::QWidgetStar)) |
1586 if ((type == QMetaType::QObjectStar) || (type == QMetaType::QWidgetStar)) |
1580 return *reinterpret_cast<QObject* const *>(var.constData()); |
1587 return *reinterpret_cast<QObject* const *>(var.constData()); |
2243 Q_D(const QScriptValue); |
2250 Q_D(const QScriptValue); |
2244 if (!d || !d->isJSC() || !d->jscValue.inherits(&QScriptObject::info)) |
2251 if (!d || !d->isJSC() || !d->jscValue.inherits(&QScriptObject::info)) |
2245 return false; |
2252 return false; |
2246 QScriptObject *object = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); |
2253 QScriptObject *object = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); |
2247 QScriptObjectDelegate *delegate = object->delegate(); |
2254 QScriptObjectDelegate *delegate = object->delegate(); |
2248 return (delegate && (delegate->type() == QScriptObjectDelegate::QtObject)); |
2255 return (delegate && (delegate->type() == QScriptObjectDelegate::QtObject || |
|
2256 (delegate->type() == QScriptObjectDelegate::DeclarativeClassObject && |
|
2257 static_cast<QScript::DeclarativeObjectDelegate*>(delegate)->scriptClass()->isQObject()))); |
2249 } |
2258 } |
2250 |
2259 |
2251 /*! |
2260 /*! |
2252 Returns true if this QScriptValue is a QMetaObject; otherwise returns |
2261 Returns true if this QScriptValue is a QMetaObject; otherwise returns |
2253 false. |
2262 false. |