diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 64 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 118 | ||||
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 53 | ||||
-rw-r--r-- | src/script/api/qscriptvalue_p.h | 30 |
4 files changed, 132 insertions, 133 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index fb54c4c..631175a 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -851,33 +851,6 @@ QScriptEnginePrivate::~QScriptEnginePrivate() globalData->deref(); } -QScriptValue QScriptEnginePrivate::scriptValueFromJSCValue(JSC::JSValue value) -{ - if (!value) - return QScriptValue(); - - QScriptValuePrivate *p_value = new (this)QScriptValuePrivate(this); - p_value->initFrom(value); - return QScriptValuePrivate::toPublic(p_value); -} - -JSC::JSValue QScriptEnginePrivate::scriptValueToJSCValue(const QScriptValue &value) -{ - QScriptValuePrivate *vv = QScriptValuePrivate::get(value); - if (!vv) - return JSC::JSValue(); - if (vv->type != QScriptValuePrivate::JSC) { - Q_ASSERT(!vv->engine || vv->engine == this); - vv->engine = this; - if (vv->type == QScriptValuePrivate::Number) { - vv->initFrom(JSC::jsNumber(currentFrame, vv->numberValue)); - } else { //QScriptValuePrivate::String - vv->initFrom(JSC::jsString(currentFrame, vv->stringValue)); - } - } - return vv->jscValue; -} - QScriptValue QScriptEnginePrivate::scriptValueFromVariant(const QVariant &v) { Q_Q(QScriptEngine); @@ -1366,43 +1339,6 @@ bool QScriptEnginePrivate::scriptDisconnect(JSC::JSValue signal, JSC::JSValue re #endif -QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(size_t size) -{ - if (freeScriptValues) { - QScriptValuePrivate *p = freeScriptValues; - freeScriptValues = p->next; - return p; - } - return reinterpret_cast<QScriptValuePrivate*>(qMalloc(size)); -} - -void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p) -{ - p->next = freeScriptValues; - freeScriptValues = p; -} - -void QScriptEnginePrivate::registerScriptValue(QScriptValuePrivate *value) -{ - value->prev = 0; - value->next = registeredScriptValues; - if (registeredScriptValues) - registeredScriptValues->prev = value; - registeredScriptValues = value; -} - -void QScriptEnginePrivate::unregisterScriptValue(QScriptValuePrivate *value) -{ - if (value->prev) - value->prev->next = value->next; - if (value->next) - value->next->prev = value->prev; - if (value == registeredScriptValues) - registeredScriptValues = value->next; - value->prev = 0; - value->next = 0; -} - void QScriptEnginePrivate::detachAllRegisteredScriptValues() { QScriptValuePrivate *it; diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index c20589f..67b2d45 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -57,6 +57,7 @@ #include <QtCore/qhash.h> #include <QtCore/qset.h> +#include "qscriptvalue_p.h" #include "RefPtr.h" #include "Structure.h" @@ -79,7 +80,6 @@ class QString; class QStringList; class QScriptContext; class QScriptValue; -class QScriptValuePrivate; class QScriptTypeInfo; class QScriptEngineAgent; class QScriptEnginePrivate; @@ -120,8 +120,8 @@ public: QScriptValue create(int type, const void *ptr); bool hasDemarshalFunction(int type) const; - QScriptValue scriptValueFromJSCValue(JSC::JSValue value); - JSC::JSValue scriptValueToJSCValue(const QScriptValue &value); + inline QScriptValue scriptValueFromJSCValue(JSC::JSValue value); + inline JSC::JSValue scriptValueToJSCValue(const QScriptValue &value); QScriptValue scriptValueFromVariant(const QVariant &value); QVariant scriptValueToVariant(const QScriptValue &value, int targetType); @@ -210,11 +210,11 @@ public: bool scriptDisconnect(JSC::JSValue signal, JSC::JSValue receiver, JSC::JSValue function); - QScriptValuePrivate *allocateScriptValuePrivate(size_t); - void freeScriptValuePrivate(QScriptValuePrivate *p); + inline QScriptValuePrivate *allocateScriptValuePrivate(size_t); + inline void freeScriptValuePrivate(QScriptValuePrivate *p); - void registerScriptValue(QScriptValuePrivate *value); - void unregisterScriptValue(QScriptValuePrivate *value); + inline void registerScriptValue(QScriptValuePrivate *value); + inline void unregisterScriptValue(QScriptValuePrivate *value); void detachAllRegisteredScriptValues(); // private slots @@ -258,6 +258,110 @@ public: #endif }; +inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(size_t size) +{ + if (freeScriptValues) { + QScriptValuePrivate *p = freeScriptValues; + freeScriptValues = p->next; + return p; + } + return reinterpret_cast<QScriptValuePrivate*>(qMalloc(size)); +} + +inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p) +{ + p->next = freeScriptValues; + freeScriptValues = p; +} + +inline void QScriptEnginePrivate::registerScriptValue(QScriptValuePrivate *value) +{ + value->prev = 0; + value->next = registeredScriptValues; + if (registeredScriptValues) + registeredScriptValues->prev = value; + registeredScriptValues = value; +} + +inline void QScriptEnginePrivate::unregisterScriptValue(QScriptValuePrivate *value) +{ + if (value->prev) + value->prev->next = value->next; + if (value->next) + value->next->prev = value->prev; + if (value == registeredScriptValues) + registeredScriptValues = value->next; + value->prev = 0; + value->next = 0; +} + +inline QScriptValue QScriptEnginePrivate::scriptValueFromJSCValue(JSC::JSValue value) +{ + if (!value) + return QScriptValue(); + + QScriptValuePrivate *p_value = new (this)QScriptValuePrivate(this); + p_value->initFrom(value); + return QScriptValuePrivate::toPublic(p_value); +} + +inline JSC::JSValue QScriptEnginePrivate::scriptValueToJSCValue(const QScriptValue &value) +{ + QScriptValuePrivate *vv = QScriptValuePrivate::get(value); + if (!vv) + return JSC::JSValue(); + if (vv->type != QScriptValuePrivate::JSC) { + Q_ASSERT(!vv->engine || vv->engine == this); + vv->engine = this; + if (vv->type == QScriptValuePrivate::Number) { + vv->initFrom(JSC::jsNumber(currentFrame, vv->numberValue)); + } else { //QScriptValuePrivate::String + vv->initFrom(JSC::jsString(currentFrame, vv->stringValue)); + } + } + return vv->jscValue; +} + +inline QScriptValuePrivate::~QScriptValuePrivate() +{ + if (engine) + engine->unregisterScriptValue(this); +} + +inline void QScriptValuePrivate::initFrom(JSC::JSValue value) +{ + if (value.isCell()) { + Q_ASSERT(engine != 0); + value = engine->toUsableValue(value); + } + type = JSC; + jscValue = value; + if (engine) + engine->registerScriptValue(this); +} + +inline void QScriptValuePrivate::initFrom(double value) +{ + type = Number; + numberValue = value; + if (engine) + engine->registerScriptValue(this); +} + +inline void QScriptValuePrivate::initFrom(const QString &value) +{ + type = String; + stringValue = value; + if (engine) + engine->registerScriptValue(this); +} + +inline QScriptValue QScriptValuePrivate::property(const QString &name, int resolveMode) const +{ + JSC::ExecState *exec = engine->currentFrame; + return property(JSC::Identifier(exec, name), resolveMode); +} + QT_END_NAMESPACE #endif diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 5f11239..b0e09de 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -276,59 +276,6 @@ qsreal ToInteger(qsreal n) } // namespace QScript -QScriptValuePrivate::QScriptValuePrivate(QScriptEnginePrivate *e) - : engine(e), prev(0), next(0) -{ - ref = 0; -} - -QScriptValuePrivate::~QScriptValuePrivate() -{ - if (engine) - engine->unregisterScriptValue(this); -} - -void QScriptValuePrivate::initFrom(JSC::JSValue value) -{ - if (value.isCell()) { - Q_ASSERT(engine != 0); - value = engine->toUsableValue(value); - JSC::JSCell *cell = JSC::asCell(value); - Q_ASSERT(cell != engine->originalGlobalObject()); - } - type = JSC; - jscValue = value; - if (engine) - engine->registerScriptValue(this); -} - -void QScriptValuePrivate::initFrom(double value) -{ - type = Number; - numberValue = value; - if (engine) - engine->registerScriptValue(this); -} - -void QScriptValuePrivate::initFrom(const QString &value) -{ - type = String; - stringValue = value; - if (engine) - engine->registerScriptValue(this); -} - -bool QScriptValuePrivate::isJSC() const -{ - return (type == JSC); -} - -QScriptValue QScriptValuePrivate::property(const QString &name, int resolveMode) const -{ - JSC::ExecState *exec = engine->currentFrame; - return property(JSC::Identifier(exec, name), resolveMode); -} - QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const { Q_ASSERT(isJSC()); diff --git a/src/script/api/qscriptvalue_p.h b/src/script/api/qscriptvalue_p.h index 274586f..06bc927 100644 --- a/src/script/api/qscriptvalue_p.h +++ b/src/script/api/qscriptvalue_p.h @@ -77,24 +77,24 @@ public: String }; - QScriptValuePrivate(QScriptEnginePrivate*); - ~QScriptValuePrivate(); + inline QScriptValuePrivate(QScriptEnginePrivate*); + inline ~QScriptValuePrivate(); - void initFrom(JSC::JSValue value); - void initFrom(double value); - void initFrom(const QString &value); + inline void initFrom(JSC::JSValue value); + inline void initFrom(double value); + inline void initFrom(const QString &value); - bool isJSC() const; + inline bool isJSC() const; QVariant &variantValue() const; void setVariantValue(const QVariant &value); - static QScriptValuePrivate *get(const QScriptValue &q) + static inline QScriptValuePrivate *get(const QScriptValue &q) { return q.d_ptr.data(); } - static QScriptValue toPublic(QScriptValuePrivate *d) + static inline QScriptValue toPublic(QScriptValuePrivate *d) { QScriptValue tmp; tmp.d_ptr = d; @@ -103,7 +103,7 @@ public: QScriptValue property(const JSC::Identifier &id, int resolveMode) const; QScriptValue property(quint32 index, int resolveMode) const; - QScriptValue property(const QString &, int resolveMode) const; + inline QScriptValue property(const QString &, int resolveMode) const; void detachFromEngine(); @@ -131,6 +131,18 @@ public: QBasicAtomicInt ref; }; +inline QScriptValuePrivate::QScriptValuePrivate(QScriptEnginePrivate *e) + : engine(e), prev(0), next(0) +{ + ref = 0; +} + +inline bool QScriptValuePrivate::isJSC() const +{ + return (type == JSC); +} + +// Rest of inline functions implemented in qscriptengine_p.h QT_END_NAMESPACE |