diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 116 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 93 | ||||
-rw-r--r-- | src/script/api/qscriptstring.cpp | 3 | ||||
-rw-r--r-- | src/script/api/qscriptstring_p.h | 7 | ||||
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 111 | ||||
-rw-r--r-- | src/script/api/qscriptvalue_p.h | 21 | ||||
-rw-r--r-- | src/script/bridge/qscriptclassobject.cpp | 11 | ||||
-rw-r--r-- | src/script/bridge/qscriptclassobject_p.h | 15 | ||||
-rw-r--r-- | src/script/bridge/qscriptobject.cpp | 30 | ||||
-rw-r--r-- | src/script/bridge/qscriptobject_p.h | 38 |
10 files changed, 241 insertions, 204 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 360036a..9288723 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -343,15 +343,10 @@ public: namespace QScript { -struct GlobalClientData : public JSC::JSGlobalData::ClientData +void GlobalClientData::mark(JSC::MarkStack& markStack) { - GlobalClientData(QScriptEnginePrivate *e) - : engine(e) {} - virtual ~GlobalClientData() {} - virtual void mark(JSC::MarkStack& markStack) { engine->mark(markStack); } - - QScriptEnginePrivate *engine; -}; + engine->mark(markStack); +} class TimeoutCheckerProxy : public JSC::TimeoutChecker { @@ -452,11 +447,6 @@ qsreal integerFromString(const QString &str, int radix) return integerFromString(ba.constData(), ba.size(), radix); } -QScriptEnginePrivate *scriptEngineFromExec(const JSC::ExecState *exec) -{ - return static_cast<GlobalClientData*>(exec->globalData().clientData)->engine; -} - bool isFunction(JSC::JSValue value) { if (!value || !value.isObject()) @@ -797,6 +787,10 @@ QScriptEnginePrivate::QScriptEnginePrivate() registeredScriptStrings(0), inEval(false) { qMetaTypeId<QScriptValue>(); + qMetaTypeId<QList<int> >(); +#ifndef QT_NO_QOBJECT + qMetaTypeId<QObjectList>(); +#endif JSC::initializeThreading(); // ### hmmm @@ -991,26 +985,6 @@ void QScriptEnginePrivate::setDefaultPrototype(int metaTypeId, JSC::JSValue prot info->prototype = prototype; } -QScriptContext *QScriptEnginePrivate::contextForFrame(JSC::ExecState *frame) -{ - if (frame && frame->callerFrame()->hasHostCallFrameFlag() && !frame->callee() - && frame->callerFrame()->removeHostCallFrameFlag() == QScript::scriptEngineFromExec(frame)->globalExec()) { - //skip the "fake" context created in Interpreter::execute. - frame = frame->callerFrame()->removeHostCallFrameFlag(); - } - return reinterpret_cast<QScriptContext *>(frame); -} - -JSC::ExecState *QScriptEnginePrivate::frameForContext(QScriptContext *context) -{ - return reinterpret_cast<JSC::ExecState*>(context); -} - -const JSC::ExecState *QScriptEnginePrivate::frameForContext(const QScriptContext *context) -{ - return reinterpret_cast<const JSC::ExecState*>(context); -} - JSC::JSGlobalObject *QScriptEnginePrivate::originalGlobalObject() const { return globalData->head; @@ -1052,11 +1026,6 @@ void QScriptEnginePrivate::setGlobalObject(JSC::JSObject *object) } } -JSC::ExecState *QScriptEnginePrivate::globalExec() const -{ - return originalGlobalObject()->globalExec(); -} - /*! \internal @@ -2539,63 +2508,50 @@ QScriptValue QScriptEngine::create(int type, const void *ptr) QScriptValue QScriptEnginePrivate::create(int type, const void *ptr) { + Q_Q(QScriptEngine); Q_ASSERT(ptr != 0); QScriptValue result; QScriptTypeInfo *info = m_typeInfos.value(type); if (info && info->marshal) { - result = info->marshal(q_func(), ptr); + result = info->marshal(q, ptr); } else { // check if it's one of the types we know switch (QMetaType::Type(type)) { case QMetaType::Void: - result = QScriptValue(QScriptValue::UndefinedValue); - break; + return QScriptValue(q, QScriptValue::UndefinedValue); case QMetaType::Bool: - result = QScriptValue(*reinterpret_cast<const bool*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const bool*>(ptr)); case QMetaType::Int: - result = QScriptValue(*reinterpret_cast<const int*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const int*>(ptr)); case QMetaType::UInt: - result = QScriptValue(*reinterpret_cast<const uint*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const uint*>(ptr)); case QMetaType::LongLong: - result = QScriptValue(qsreal(*reinterpret_cast<const qlonglong*>(ptr))); - break; + return QScriptValue(q, qsreal(*reinterpret_cast<const qlonglong*>(ptr))); case QMetaType::ULongLong: #if defined(Q_OS_WIN) && defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 12008804 #pragma message("** NOTE: You need the Visual Studio Processor Pack to compile support for 64bit unsigned integers.") - result = QScriptValue(qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr))); + return QScriptValue(q, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr))); #elif defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) - result = QScriptValue(qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr))); + return QScriptValue(q, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr))); #else - result = QScriptValue(qsreal(*reinterpret_cast<const qulonglong*>(ptr))); + return QScriptValue(q, qsreal(*reinterpret_cast<const qulonglong*>(ptr))); #endif - break; case QMetaType::Double: - result = QScriptValue(*reinterpret_cast<const double*>(ptr)); - break; + return QScriptValue(q, qsreal(*reinterpret_cast<const double*>(ptr))); case QMetaType::QString: - result = QScriptValue(q_func(), *reinterpret_cast<const QString*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const QString*>(ptr)); case QMetaType::Float: - result = QScriptValue(*reinterpret_cast<const float*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const float*>(ptr)); case QMetaType::Short: - result = QScriptValue(*reinterpret_cast<const short*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const short*>(ptr)); case QMetaType::UShort: - result = QScriptValue(*reinterpret_cast<const unsigned short*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const unsigned short*>(ptr)); case QMetaType::Char: - result = QScriptValue(*reinterpret_cast<const char*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const char*>(ptr)); case QMetaType::UChar: - result = QScriptValue(*reinterpret_cast<const unsigned char*>(ptr)); - break; + return QScriptValue(q, *reinterpret_cast<const unsigned char*>(ptr)); case QMetaType::QChar: - result = QScriptValue((*reinterpret_cast<const QChar*>(ptr)).unicode()); - break; + return QScriptValue(q, (*reinterpret_cast<const QChar*>(ptr)).unicode()); case QMetaType::QStringList: result = arrayFromStringList(*reinterpret_cast<const QStringList *>(ptr)); break; @@ -2606,38 +2562,38 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr) result = objectFromVariantMap(*reinterpret_cast<const QVariantMap *>(ptr)); break; case QMetaType::QDateTime: - result = q_func()->newDate(*reinterpret_cast<const QDateTime *>(ptr)); + result = q->newDate(*reinterpret_cast<const QDateTime *>(ptr)); break; case QMetaType::QDate: - result = q_func()->newDate(QDateTime(*reinterpret_cast<const QDate *>(ptr))); + result = q->newDate(QDateTime(*reinterpret_cast<const QDate *>(ptr))); break; #ifndef QT_NO_REGEXP case QMetaType::QRegExp: - result = q_func()->newRegExp(*reinterpret_cast<const QRegExp *>(ptr)); + result = q->newRegExp(*reinterpret_cast<const QRegExp *>(ptr)); break; #endif #ifndef QT_NO_QOBJECT case QMetaType::QObjectStar: case QMetaType::QWidgetStar: - result = q_func()->newQObject(*reinterpret_cast<QObject* const *>(ptr)); + result = q->newQObject(*reinterpret_cast<QObject* const *>(ptr)); break; #endif default: if (type == qMetaTypeId<QScriptValue>()) { result = *reinterpret_cast<const QScriptValue*>(ptr); if (!result.isValid()) - result = QScriptValue(QScriptValue::UndefinedValue); + return QScriptValue(q, QScriptValue::UndefinedValue); } #ifndef QT_NO_QOBJECT // lazy registration of some common list types else if (type == qMetaTypeId<QObjectList>()) { - qScriptRegisterSequenceMetaType<QObjectList>(q_func()); + qScriptRegisterSequenceMetaType<QObjectList>(q); return create(type, ptr); } #endif else if (type == qMetaTypeId<QList<int> >()) { - qScriptRegisterSequenceMetaType<QList<int> >(q_func()); + qScriptRegisterSequenceMetaType<QList<int> >(q); return create(type, ptr); } @@ -2646,9 +2602,9 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr) if (typeName == "QVariant") result = scriptValueFromVariant(*reinterpret_cast<const QVariant*>(ptr)); if (typeName.endsWith('*') && !*reinterpret_cast<void* const *>(ptr)) - result = QScriptValue(QScriptValue::NullValue); + return QScriptValue(q, QScriptValue::NullValue); else - result = q_func()->newVariant(QVariant(type, ptr)); + result = q->newVariant(QVariant(type, ptr)); } } } @@ -2663,8 +2619,8 @@ bool QScriptEnginePrivate::convert(const QScriptValue &value, int type, void *ptr, QScriptEnginePrivate *eng) { - if (!eng && value.engine()) - eng = QScriptEnginePrivate::get(value.engine()); + if (!eng) + eng = QScriptValuePrivate::getEngine(value); if (eng) { QScriptTypeInfo *info = eng->m_typeInfos.value(type); if (info && info->demarshal) { diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index cde116d..ec7c144 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -101,11 +101,22 @@ namespace QScript class TimeoutCheckerProxy; //some conversion helper functions - QScriptEnginePrivate *scriptEngineFromExec(const JSC::ExecState *exec); + inline QScriptEnginePrivate *scriptEngineFromExec(const JSC::ExecState *exec); bool isFunction(JSC::JSValue value); class UStringSourceProviderWithFeedback; -} + +struct GlobalClientData : public JSC::JSGlobalData::ClientData +{ + GlobalClientData(QScriptEnginePrivate *e) + : engine(e) {} + virtual ~GlobalClientData() {} + virtual void mark(JSC::MarkStack& markStack); + + QScriptEnginePrivate *engine; +}; + +} // namespace QScript class QScriptEnginePrivate #ifndef QT_NO_QOBJECT @@ -147,16 +158,16 @@ public: JSC::JSValue defaultPrototype(int metaTypeId) const; void setDefaultPrototype(int metaTypeId, JSC::JSValue prototype); - static QScriptContext *contextForFrame(JSC::ExecState *frame); - static JSC::ExecState *frameForContext(QScriptContext *context); - static const JSC::ExecState *frameForContext(const QScriptContext *context); + static inline QScriptContext *contextForFrame(JSC::ExecState *frame); + static inline JSC::ExecState *frameForContext(QScriptContext *context); + static inline const JSC::ExecState *frameForContext(const QScriptContext *context); JSC::JSGlobalObject *originalGlobalObject() const; JSC::JSObject *getOriginalGlobalObjectProxy(); JSC::JSObject *customGlobalObject() const; JSC::JSObject *globalObject() const; void setGlobalObject(JSC::JSObject *object); - JSC::ExecState *globalExec() const; + inline JSC::ExecState *globalExec() const; JSC::JSValue toUsableValue(JSC::JSValue value); static JSC::JSValue thisForContext(JSC::ExecState *frame); static JSC::Register *thisRegisterForFrame(JSC::ExecState *frame); @@ -367,6 +378,11 @@ private: JSC::ExecState *oldFrame; }; +inline QScriptEnginePrivate *scriptEngineFromExec(const JSC::ExecState *exec) +{ + return static_cast<GlobalClientData*>(exec->globalData().clientData)->engine; +} + } // namespace QScript inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(size_t size) @@ -451,7 +467,7 @@ inline void QScriptValuePrivate::initFrom(JSC::JSValue value) engine->registerScriptValue(this); } -inline void QScriptValuePrivate::initFrom(double value) +inline void QScriptValuePrivate::initFrom(qsreal value) { type = Number; numberValue = value; @@ -473,6 +489,28 @@ inline QScriptValue QScriptValuePrivate::property(const QString &name, int resol return property(JSC::Identifier(exec, name), resolveMode); } +inline QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const +{ + Q_ASSERT(isObject()); + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if ((resolveMode & QScriptValue::ResolvePrototype) && object->getPropertySlot(exec, id, slot)) + return engine->scriptValueFromJSCValue(slot.getValue(exec, id)); + return propertyHelper(id, resolveMode); +} + +inline QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const +{ + Q_ASSERT(isObject()); + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if ((resolveMode & QScriptValue::ResolvePrototype) && object->getPropertySlot(exec, index, slot)) + return engine->scriptValueFromJSCValue(slot.getValue(exec, index)); + return propertyHelper(index, resolveMode); +} + inline void* QScriptValuePrivate::operator new(size_t size, QScriptEnginePrivate *engine) { if (engine) @@ -489,6 +527,22 @@ inline void QScriptValuePrivate::operator delete(void *ptr) qFree(d); } +inline void QScriptValuePrivate::saveException(JSC::ExecState *exec, JSC::JSValue *val) +{ + if (exec) { + *val = exec->exception(); + exec->clearException(); + } else { + *val = JSC::JSValue(); + } +} + +inline void QScriptValuePrivate::restoreException(JSC::ExecState *exec, JSC::JSValue val) +{ + if (exec && val) + exec->setException(val); +} + inline void QScriptEnginePrivate::registerScriptString(QScriptStringPrivate *value) { Q_ASSERT(value->type == QScriptStringPrivate::HeapAllocated); @@ -512,6 +566,31 @@ inline void QScriptEnginePrivate::unregisterScriptString(QScriptStringPrivate *v value->next = 0; } +inline QScriptContext *QScriptEnginePrivate::contextForFrame(JSC::ExecState *frame) +{ + if (frame && frame->callerFrame()->hasHostCallFrameFlag() && !frame->callee() + && frame->callerFrame()->removeHostCallFrameFlag() == QScript::scriptEngineFromExec(frame)->globalExec()) { + //skip the "fake" context created in Interpreter::execute. + frame = frame->callerFrame()->removeHostCallFrameFlag(); + } + return reinterpret_cast<QScriptContext *>(frame); +} + +inline JSC::ExecState *QScriptEnginePrivate::frameForContext(QScriptContext *context) +{ + return reinterpret_cast<JSC::ExecState*>(context); +} + +inline const JSC::ExecState *QScriptEnginePrivate::frameForContext(const QScriptContext *context) +{ + return reinterpret_cast<const JSC::ExecState*>(context); +} + +inline JSC::ExecState *QScriptEnginePrivate::globalExec() const +{ + return originalGlobalObject()->globalExec(); +} + QT_END_NAMESPACE #endif diff --git a/src/script/api/qscriptstring.cpp b/src/script/api/qscriptstring.cpp index 2fb157f..1ede51c 100644 --- a/src/script/api/qscriptstring.cpp +++ b/src/script/api/qscriptstring.cpp @@ -139,8 +139,7 @@ QScriptString &QScriptString::operator=(const QScriptString &other) */ bool QScriptString::isValid() const { - Q_D(const QScriptString); - return (d && d->engine); + return QScriptStringPrivate::isValid(*this); } /*! diff --git a/src/script/api/qscriptstring_p.h b/src/script/api/qscriptstring_p.h index d3bb47d..8e344e8 100644 --- a/src/script/api/qscriptstring_p.h +++ b/src/script/api/qscriptstring_p.h @@ -77,6 +77,8 @@ public: inline void detachFromEngine(); + static inline bool isValid(const QScriptString &q); + QBasicAtomicInt ref; QScriptEnginePrivate *engine; JSC::Identifier identifier; @@ -114,6 +116,11 @@ inline void QScriptStringPrivate::detachFromEngine() identifier = JSC::Identifier(); } +inline bool QScriptStringPrivate::isValid(const QScriptString &q) +{ + return (q.d_ptr && q.d_ptr->engine); +} + QT_END_NAMESPACE #endif diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index b8340a7..52a1e6d 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -213,7 +213,7 @@ qint32 ToInt32(qsreal n) if (qIsNaN(n) || qIsInf(n) || (n == 0)) return 0; - double sign = (n < 0) ? -1.0 : 1.0; + qsreal sign = (n < 0) ? -1.0 : 1.0; qsreal abs_n = fabs(n); n = ::fmod(sign * ::floor(abs_n), D32); @@ -233,7 +233,7 @@ quint32 ToUint32(qsreal n) if (qIsNaN(n) || qIsInf(n) || (n == 0)) return 0; - double sign = (n < 0) ? -1.0 : 1.0; + qsreal sign = (n < 0) ? -1.0 : 1.0; qsreal abs_n = fabs(n); n = ::fmod(sign * ::floor(abs_n), D32); @@ -251,7 +251,7 @@ quint16 ToUint16(qsreal n) if (qIsNaN(n) || qIsInf(n) || (n == 0)) return 0; - double sign = (n < 0) ? -1.0 : 1.0; + qsreal sign = (n < 0) ? -1.0 : 1.0; qsreal abs_n = fabs(n); n = ::fmod(sign * ::floor(abs_n), D16); @@ -276,41 +276,36 @@ qsreal ToInteger(qsreal n) } // namespace QScript -QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const +QScriptValue QScriptValuePrivate::propertyHelper(const JSC::Identifier &id, int resolveMode) const { - Q_ASSERT(isObject()); - JSC::ExecState *exec = engine->currentFrame; - JSC::JSObject *object = JSC::asObject(jscValue); - JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); JSC::JSValue result; - if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { - result = slot.getValue(exec, id); - } else { - if ((resolveMode & QScriptValue::ResolvePrototype) - && const_cast<JSC::JSObject*>(object)->getPropertySlot(exec, id, slot)) { + if (!(resolveMode & QScriptValue::ResolvePrototype)) { + // Look in the object's own properties + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if (object->getOwnPropertySlot(exec, id, slot)) result = slot.getValue(exec, id); - } else if (resolveMode & QScriptValue::ResolveScope) { - // ### check if it's a function object and look in the scope chain - QScriptValue scope = property(QString::fromLatin1("__qt_scope__"), QScriptValue::ResolveLocal); - if (scope.isObject()) - result = engine->scriptValueToJSCValue(QScriptValuePrivate::get(scope)->property(id, resolveMode)); - } + } + if (!result && (resolveMode & QScriptValue::ResolveScope)) { + // ### check if it's a function object and look in the scope chain + QScriptValue scope = property(QString::fromLatin1("__qt_scope__"), QScriptValue::ResolveLocal); + if (scope.isObject()) + result = engine->scriptValueToJSCValue(QScriptValuePrivate::get(scope)->property(id, resolveMode)); } return engine->scriptValueFromJSCValue(result); } -QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const +QScriptValue QScriptValuePrivate::propertyHelper(quint32 index, int resolveMode) const { - Q_ASSERT(isObject()); - JSC::ExecState *exec = engine->currentFrame; - JSC::JSObject *object = JSC::asObject(jscValue); - JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); JSC::JSValue result; - if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, index, slot)) { - result = slot.getValue(exec, index); - } else if ((resolveMode & QScriptValue::ResolvePrototype) - && const_cast<JSC::JSObject*>(object)->getPropertySlot(exec, index, slot)) { - result = slot.getValue(exec, index); + if (!(resolveMode & QScriptValue::ResolvePrototype)) { + // Look in the object's own properties + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if (object->getOwnPropertySlot(exec, index, slot)) + result = slot.getValue(exec, index); } return engine->scriptValueFromJSCValue(result); } @@ -318,8 +313,8 @@ QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const void QScriptValuePrivate::setProperty(const JSC::Identifier &id, const QScriptValue &value, const QScriptValue::PropertyFlags &flags) { - QScriptEngine *valueEngine = value.engine(); - if (valueEngine && (QScriptEnginePrivate::get(valueEngine) != engine)) { + QScriptEnginePrivate *valueEngine = QScriptValuePrivate::getEngine(value); + if (valueEngine && (valueEngine != engine)) { qWarning("QScriptValue::setProperty(%s) failed: " "cannot set value created in a different engine", qPrintable(QString(id.ustring()))); @@ -443,22 +438,6 @@ void QScriptValuePrivate::setVariantValue(const QVariant &value) static_cast<QScript::QVariantDelegate*>(delegate)->setValue(value); } -void QScriptValuePrivate::saveException(JSC::ExecState *exec, JSC::JSValue *val) -{ - if (exec) { - *val = exec->exception(); - exec->clearException(); - } else { - *val = JSC::JSValue(); - } -} - -void QScriptValuePrivate::restoreException(JSC::ExecState *exec, JSC::JSValue val) -{ - if (exec && val) - exec->setException(val); -} - void QScriptValuePrivate::detachFromEngine() { if (isJSC()) @@ -822,8 +801,8 @@ void QScriptValue::setPrototype(const QScriptValue &prototype) Q_D(QScriptValue); if (!d || !d->isObject()) return; - if (prototype.isValid() && prototype.engine() - && (prototype.engine() != engine())) { + if (prototype.isValid() && QScriptValuePrivate::getEngine(prototype) + && (QScriptValuePrivate::getEngine(prototype) != d->engine)) { qWarning("QScriptValue::setPrototype() failed: " "cannot set a prototype created in " "a different engine"); @@ -864,8 +843,8 @@ void QScriptValue::setScope(const QScriptValue &scope) Q_D(QScriptValue); if (!d || !d->isObject()) return; - if (scope.isValid() && scope.engine() - && (scope.engine() != engine())) { + if (scope.isValid() && QScriptValuePrivate::getEngine(scope) + && (QScriptValuePrivate::getEngine(scope) != d->engine)) { qWarning("QScriptValue::setScope() failed: " "cannot set a scope object created in " "a different engine"); @@ -896,7 +875,7 @@ bool QScriptValue::instanceOf(const QScriptValue &other) const Q_D(const QScriptValue); if (!d || !d->isObject() || !other.isObject()) return false; - if (other.engine() != engine()) { + if (QScriptValuePrivate::getEngine(other) != d->engine) { qWarning("QScriptValue::instanceof: " "cannot perform operation on a value created in " "a different engine"); @@ -1083,10 +1062,12 @@ static bool Equals(QScriptValue lhs, QScriptValue rhs) */ bool QScriptValue::lessThan(const QScriptValue &other) const { + Q_D(const QScriptValue); // no equivalent function in JSC? There's a jsLess() in VM/Machine.cpp if (!isValid() || !other.isValid()) return false; - if (other.engine() && engine() && (other.engine() != engine())) { + if (QScriptValuePrivate::getEngine(other) && d->engine + && (QScriptValuePrivate::getEngine(other) != d->engine)) { qWarning("QScriptValue::lessThan: " "cannot compare to a value created in " "a different engine"); @@ -1124,7 +1105,8 @@ bool QScriptValue::equals(const QScriptValue &other) const Q_D(const QScriptValue); if (!d || !other.d_ptr) return (d_ptr == other.d_ptr); - if (other.engine() && engine() && (other.engine() != engine())) { + if (QScriptValuePrivate::getEngine(other) && d->engine + && (QScriptValuePrivate::getEngine(other) != d->engine)) { qWarning("QScriptValue::equals: " "cannot compare to a value created in " "a different engine"); @@ -1173,7 +1155,8 @@ bool QScriptValue::strictlyEquals(const QScriptValue &other) const Q_D(const QScriptValue); if (!d || !other.d_ptr) return (d_ptr == other.d_ptr); - if (other.engine() && engine() && (other.engine() != engine())) { + if (QScriptValuePrivate::getEngine(other) && d->engine + && (QScriptValuePrivate::getEngine(other) != d->engine)) { qWarning("QScriptValue::strictlyEquals: " "cannot compare to a value created in " "a different engine"); @@ -1725,7 +1708,8 @@ void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue &value, Q_D(QScriptValue); if (!d || !d->isObject()) return; - if (value.engine() && (value.engine() != engine())) { + if (QScriptValuePrivate::getEngine(value) + && (QScriptValuePrivate::getEngine(value) != d->engine)) { qWarning("QScriptValue::setProperty() failed: " "cannot set value created in a different engine"); return; @@ -1775,7 +1759,7 @@ QScriptValue QScriptValue::property(const QScriptString &name, const ResolveFlags &mode) const { Q_D(const QScriptValue); - if (!d || !d->isObject() || !name.isValid()) + if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name)) return QScriptValue(); return d->property(name.d_ptr->identifier, mode); } @@ -1798,7 +1782,7 @@ void QScriptValue::setProperty(const QScriptString &name, const PropertyFlags &flags) { Q_D(QScriptValue); - if (!d || !d->isObject() || !name.isValid()) + if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name)) return; d->setProperty(name.d_ptr->identifier, value, flags); } @@ -1832,7 +1816,7 @@ QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QScriptString &nam const ResolveFlags &mode) const { Q_D(const QScriptValue); - if (!d || !d->isObject() || !name.isValid()) + if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name)) return 0; return d->propertyFlags(name.d_ptr->identifier, mode); } @@ -1872,7 +1856,8 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, if (callType == JSC::CallTypeNone) return QScriptValue(); - if (thisObject.engine() && (thisObject.engine() != engine())) { + if (QScriptValuePrivate::getEngine(thisObject) + && (QScriptValuePrivate::getEngine(thisObject) != d->engine)) { qWarning("QScriptValue::call() failed: " "cannot call function with thisObject created in " "a different engine"); @@ -1890,7 +1875,8 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, const QScriptValue &arg = args.at(i); if (!arg.isValid()) { argsVector[i] = JSC::jsUndefined(); - } else if (arg.engine() && (arg.engine() != engine())) { + } else if (QScriptValuePrivate::getEngine(arg) + && (QScriptValuePrivate::getEngine(arg) != d->engine)) { qWarning("QScriptValue::call() failed: " "cannot call function with argument created in " "a different engine"); @@ -1947,7 +1933,8 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, if (callType == JSC::CallTypeNone) return QScriptValue(); - if (thisObject.engine() && (thisObject.engine() != engine())) { + if (QScriptValuePrivate::getEngine(thisObject) + && (QScriptValuePrivate::getEngine(thisObject) != d->engine)) { qWarning("QScriptValue::call() failed: " "cannot call function with thisObject created in " "a different engine"); diff --git a/src/script/api/qscriptvalue_p.h b/src/script/api/qscriptvalue_p.h index 77b5084..c322a37 100644 --- a/src/script/api/qscriptvalue_p.h +++ b/src/script/api/qscriptvalue_p.h @@ -81,7 +81,7 @@ public: inline ~QScriptValuePrivate(); inline void initFrom(JSC::JSValue value); - inline void initFrom(double value); + inline void initFrom(qsreal value); inline void initFrom(const QString &value); inline bool isJSC() const; @@ -100,8 +100,17 @@ public: return QScriptValue(d); } - QScriptValue property(const JSC::Identifier &id, int resolveMode) const; - QScriptValue property(quint32 index, int resolveMode) const; + static inline QScriptEnginePrivate *getEngine(const QScriptValue &q) + { + if (!q.d_ptr) + return 0; + return q.d_ptr->engine; + } + + inline QScriptValue property(const JSC::Identifier &id, int resolveMode) const; + QScriptValue propertyHelper(const JSC::Identifier &id, int resolveMode) const; + inline QScriptValue property(quint32 index, int resolveMode) const; + QScriptValue propertyHelper(quint32, int resolveMode) const; inline QScriptValue property(const QString &, int resolveMode) const; void setProperty(const JSC::Identifier &id, const QScriptValue &value, const QScriptValue::PropertyFlags &flags); @@ -118,13 +127,13 @@ public: return -1; } - static void saveException(JSC::ExecState*, JSC::JSValue*); - static void restoreException(JSC::ExecState*, JSC::JSValue); + static inline void saveException(JSC::ExecState*, JSC::JSValue*); + static inline void restoreException(JSC::ExecState*, JSC::JSValue); QScriptEnginePrivate *engine; Type type; JSC::JSValue jscValue; - double numberValue; + qsreal numberValue; QString stringValue; // linked list of engine's script values diff --git a/src/script/bridge/qscriptclassobject.cpp b/src/script/bridge/qscriptclassobject.cpp index 0d88532..1dde98b 100644 --- a/src/script/bridge/qscriptclassobject.cpp +++ b/src/script/bridge/qscriptclassobject.cpp @@ -70,17 +70,6 @@ ClassObjectDelegate::~ClassObjectDelegate() { } -QScriptClass *ClassObjectDelegate::scriptClass() const -{ - return m_scriptClass; -} - -void ClassObjectDelegate::setScriptClass(QScriptClass *scriptClass) -{ - Q_ASSERT(scriptClass != 0); - m_scriptClass = scriptClass; -} - QScriptObjectDelegate::Type ClassObjectDelegate::type() const { return ClassObject; diff --git a/src/script/bridge/qscriptclassobject_p.h b/src/script/bridge/qscriptclassobject_p.h index f5cce76..9b34244 100644 --- a/src/script/bridge/qscriptclassobject_p.h +++ b/src/script/bridge/qscriptclassobject_p.h @@ -70,8 +70,8 @@ public: ClassObjectDelegate(QScriptClass *scriptClass); ~ClassObjectDelegate(); - QScriptClass *scriptClass() const; - void setScriptClass(QScriptClass *scriptClass); + inline QScriptClass *scriptClass() const; + inline void setScriptClass(QScriptClass *scriptClass); virtual Type type() const; @@ -105,6 +105,17 @@ private: QScriptClass *m_scriptClass; }; +inline QScriptClass *ClassObjectDelegate::scriptClass() const +{ + return m_scriptClass; +} + +inline void ClassObjectDelegate::setScriptClass(QScriptClass *scriptClass) +{ + Q_ASSERT(scriptClass != 0); + m_scriptClass = scriptClass; +} + } // namespace QScript QT_END_NAMESPACE diff --git a/src/script/bridge/qscriptobject.cpp b/src/script/bridge/qscriptobject.cpp index 55644fe..1fdf0b1 100644 --- a/src/script/bridge/qscriptobject.cpp +++ b/src/script/bridge/qscriptobject.cpp @@ -70,36 +70,6 @@ QScriptObject::~QScriptObject() delete d; } -JSC::JSValue QScriptObject::data() const -{ - if (!d) - return JSC::JSValue(); - return d->data; -} - -void QScriptObject::setData(JSC::JSValue data) -{ - if (!d) - d = new Data(); - d->data = data; -} - -QScriptObjectDelegate *QScriptObject::delegate() const -{ - if (!d) - return 0; - return d->delegate; -} - -void QScriptObject::setDelegate(QScriptObjectDelegate *delegate) -{ - if (!d) - d = new Data(); - else - delete d->delegate; - d->delegate = delegate; -} - bool QScriptObject::getOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot) diff --git a/src/script/bridge/qscriptobject_p.h b/src/script/bridge/qscriptobject_p.h index c1cee31..9dd9d88 100644 --- a/src/script/bridge/qscriptobject_p.h +++ b/src/script/bridge/qscriptobject_p.h @@ -104,11 +104,11 @@ public: return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance | JSC::OverridesHasInstance)); } - JSC::JSValue data() const; - void setData(JSC::JSValue data); + inline JSC::JSValue data() const; + inline void setData(JSC::JSValue data); - QScriptObjectDelegate *delegate() const; - void setDelegate(QScriptObjectDelegate *delegate); + inline QScriptObjectDelegate *delegate() const; + inline void setDelegate(QScriptObjectDelegate *delegate); protected: Data *d; @@ -158,6 +158,36 @@ private: Q_DISABLE_COPY(QScriptObjectDelegate) }; +inline JSC::JSValue QScriptObject::data() const +{ + if (!d) + return JSC::JSValue(); + return d->data; +} + +inline void QScriptObject::setData(JSC::JSValue data) +{ + if (!d) + d = new Data(); + d->data = data; +} + +inline QScriptObjectDelegate *QScriptObject::delegate() const +{ + if (!d) + return 0; + return d->delegate; +} + +inline void QScriptObject::setDelegate(QScriptObjectDelegate *delegate) +{ + if (!d) + d = new Data(); + else + delete d->delegate; + d->delegate = delegate; +} + QT_END_NAMESPACE #endif |