summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorJedrzej Nowacki <jedrzej.nowacki@nokia.com>2009-08-19 08:12:51 (GMT)
committerJedrzej Nowacki <jedrzej.nowacki@nokia.com>2009-08-19 08:29:54 (GMT)
commit72ae891ec6b1798904962e15b36b506f5b850761 (patch)
tree5dd09b4e7d87c057df643a6cdaf6305dc9371083 /src/script
parente43e54a357adcb32a7e13e9a1efb9deaa76a1d26 (diff)
downloadQt-72ae891ec6b1798904962e15b36b506f5b850761.zip
Qt-72ae891ec6b1798904962e15b36b506f5b850761.tar.gz
Qt-72ae891ec6b1798904962e15b36b506f5b850761.tar.bz2
Clean up.
Internal API of QScriptValue were cleaned. toPublic() was removed and replaced by standard static Private::get(). All initFromXXX() methods were replaced by overload call of initFrom(). Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/qscriptengine.cpp15
-rw-r--r--src/script/api/qscriptvalue.cpp64
-rw-r--r--src/script/api/qscriptvalue_p.h27
3 files changed, 57 insertions, 49 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 02293ea..e5eaafb 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -849,9 +849,12 @@ QScriptValue QScriptEnginePrivate::scriptValueFromJSCValue(JSC::JSValue value)
Q_Q(QScriptEngine);
if (!value)
return QScriptValue();
- QScriptValue result;
- QScriptValuePrivate::initFromJSCValue(result, q, value);
- return result;
+
+ QScriptValuePrivate *p_value = new QScriptValuePrivate();
+ p_value->engine = q;
+ p_value->initFrom(value);
+
+ return QScriptValuePrivate::get(p_value);
}
JSC::JSValue QScriptEnginePrivate::scriptValueToJSCValue(const QScriptValue &value)
@@ -864,9 +867,9 @@ JSC::JSValue QScriptEnginePrivate::scriptValueToJSCValue(const QScriptValue &val
Q_ASSERT(!vv->engine || vv->engine == q);
vv->engine = q;
if (vv->type == QScriptValuePrivate::Number) {
- vv->initFromJSCValue(JSC::jsNumber(currentFrame, vv->numberValue));
+ vv->initFrom(JSC::jsNumber(currentFrame, vv->numberValue));
} else { //QScriptValuePrivate::String
- vv->initFromJSCValue(JSC::jsString(currentFrame, vv->stringValue));
+ vv->initFrom(JSC::jsString(currentFrame, vv->stringValue));
}
}
return vv->jscValue;
@@ -3706,7 +3709,7 @@ QScriptValue QScriptEngine::objectById(qint64 id) const
QSet<QScriptValuePrivate*>::const_iterator i = d->attachedScriptValues.constBegin();
while(i != d->attachedScriptValues.constEnd()) {
if ( (*i)->id == id )
- return (*i)->toPublic();
+ return QScriptValuePrivate::get(*i);
i++;
}
return QScriptValue();
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp
index 6a8227a..3bf976b 100644
--- a/src/script/api/qscriptvalue.cpp
+++ b/src/script/api/qscriptvalue.cpp
@@ -305,7 +305,7 @@ QScriptValuePrivate::QScriptValueAutoRegister& QScriptValuePrivate::QScriptValue
return *this;
};
-void QScriptValuePrivate::initFromJSCValue(JSC::JSValue value)
+void QScriptValuePrivate::initFrom(JSC::JSValue value)
{
if (value.isCell()) {
Q_ASSERT(engine != 0);
@@ -321,13 +321,13 @@ void QScriptValuePrivate::initFromJSCValue(JSC::JSValue value)
jscValue = value;
}
-void QScriptValuePrivate::initFromNumber(double value)
+void QScriptValuePrivate::initFrom(double value)
{
type = Number;
numberValue = value;
}
-void QScriptValuePrivate::initFromString(const QString &value)
+void QScriptValuePrivate::initFrom(const QString &value)
{
type = String;
stringValue = value;
@@ -340,7 +340,7 @@ void QScriptValuePrivate::initFromJSCValue(QScriptValue &result,
Q_ASSERT(!result.isValid());
result.d_ptr = new QScriptValuePrivate();
result.d_ptr->engine = engine;
- result.d_ptr->initFromJSCValue(value);
+ result.d_ptr->initFrom(value);
result.d_ptr->ref.ref();
}
@@ -479,10 +479,10 @@ QScriptValue::QScriptValue(QScriptEngine *engine, QScriptValue::SpecialValue val
d_ptr->engine = engine;
switch (value) {
case NullValue:
- d_ptr->initFromJSCValue(JSC::jsNull());
+ d_ptr->initFrom(JSC::jsNull());
break;
case UndefinedValue:
- d_ptr->initFromJSCValue(JSC::jsUndefined());
+ d_ptr->initFrom(JSC::jsUndefined());
break;
}
d_ptr->ref.ref();
@@ -500,7 +500,7 @@ QScriptValue::QScriptValue(QScriptEngine *engine, bool val)
: d_ptr(new QScriptValuePrivate)
{
d_ptr->engine = engine;
- d_ptr->initFromJSCValue(JSC::jsBoolean(val));
+ d_ptr->initFrom(JSC::jsBoolean(val));
d_ptr->ref.ref();
}
@@ -518,13 +518,13 @@ QScriptValue::QScriptValue(QScriptEngine *engine, int val)
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
JSC::ExecState *exec = eng_p->currentFrame;
- d_ptr->initFromJSCValue(JSC::jsNumber(exec, val));
+ d_ptr->initFrom(JSC::jsNumber(exec, val));
} else {
JSC::JSValue immediate = JSC::JSImmediate::from(val);
if (immediate)
- d_ptr->initFromJSCValue(immediate);
+ d_ptr->initFrom(immediate);
else
- d_ptr->initFromNumber(val);
+ d_ptr->initFrom(val);
}
d_ptr->ref.ref();
}
@@ -543,13 +543,13 @@ QScriptValue::QScriptValue(QScriptEngine *engine, uint val)
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
JSC::ExecState *exec = eng_p->currentFrame;
- d_ptr->initFromJSCValue(JSC::jsNumber(exec, val));
+ d_ptr->initFrom(JSC::jsNumber(exec, val));
} else {
JSC::JSValue immediate = JSC::JSImmediate::from(val);
if (immediate)
- d_ptr->initFromJSCValue(immediate);
+ d_ptr->initFrom(immediate);
else
- d_ptr->initFromNumber(val);
+ d_ptr->initFrom(val);
}
d_ptr->ref.ref();
}
@@ -568,13 +568,13 @@ QScriptValue::QScriptValue(QScriptEngine *engine, qsreal val)
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
JSC::ExecState *exec = eng_p->currentFrame;
- d_ptr->initFromJSCValue(JSC::jsNumber(exec, val));
+ d_ptr->initFrom(JSC::jsNumber(exec, val));
} else {
JSC::JSValue immediate = JSC::JSImmediate::from(val);
if (immediate)
- d_ptr->initFromJSCValue(immediate);
+ d_ptr->initFrom(immediate);
else
- d_ptr->initFromNumber(val);
+ d_ptr->initFrom(val);
}
d_ptr->ref.ref();
}
@@ -593,9 +593,9 @@ QScriptValue::QScriptValue(QScriptEngine *engine, const QString &val)
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
JSC::ExecState *exec = eng_p->currentFrame;
- d_ptr->initFromJSCValue(JSC::jsString(exec, val));
+ d_ptr->initFrom(JSC::jsString(exec, val));
} else {
- d_ptr->initFromString(val);
+ d_ptr->initFrom(val);
}
d_ptr->ref.ref();
}
@@ -616,9 +616,9 @@ QScriptValue::QScriptValue(QScriptEngine *engine, const char *val)
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
JSC::ExecState *exec = eng_p->currentFrame;
- d_ptr->initFromJSCValue(JSC::jsString(exec, val));
+ d_ptr->initFrom(JSC::jsString(exec, val));
} else {
- d_ptr->initFromString(QString::fromAscii(val));
+ d_ptr->initFrom(QString::fromAscii(val));
}
d_ptr->ref.ref();
}
@@ -635,10 +635,10 @@ QScriptValue::QScriptValue(SpecialValue value)
d_ptr->engine = 0;
switch (value) {
case NullValue:
- d_ptr->initFromJSCValue(JSC::jsNull());
+ d_ptr->initFrom(JSC::jsNull());
break;
case UndefinedValue:
- d_ptr->initFromJSCValue(JSC::jsUndefined());
+ d_ptr->initFrom(JSC::jsUndefined());
break;
}
d_ptr->ref.ref();
@@ -653,7 +653,7 @@ QScriptValue::QScriptValue(bool value)
: d_ptr(new QScriptValuePrivate)
{
d_ptr->engine = 0;
- d_ptr->initFromJSCValue(JSC::jsBoolean(value));
+ d_ptr->initFrom(JSC::jsBoolean(value));
d_ptr->ref.ref();
}
@@ -668,9 +668,9 @@ QScriptValue::QScriptValue(int value)
d_ptr->engine = 0;
JSC::JSValue immediate = JSC::JSImmediate::from(value);
if (immediate)
- d_ptr->initFromJSCValue(immediate);
+ d_ptr->initFrom(immediate);
else
- d_ptr->initFromNumber(value);
+ d_ptr->initFrom(value);
d_ptr->ref.ref();
}
@@ -685,9 +685,9 @@ QScriptValue::QScriptValue(uint value)
d_ptr->engine = 0;
JSC::JSValue immediate = JSC::JSImmediate::from(value);
if (immediate)
- d_ptr->initFromJSCValue(immediate);
+ d_ptr->initFrom(immediate);
else
- d_ptr->initFromNumber(value);
+ d_ptr->initFrom(value);
d_ptr->ref.ref();
}
@@ -702,9 +702,9 @@ QScriptValue::QScriptValue(qsreal value)
d_ptr->engine = 0;
JSC::JSValue immediate = JSC::JSImmediate::from(value);
if (immediate)
- d_ptr->initFromJSCValue(immediate);
+ d_ptr->initFrom(immediate);
else
- d_ptr->initFromNumber(value);
+ d_ptr->initFrom(value);
d_ptr->ref.ref();
}
@@ -717,7 +717,7 @@ QScriptValue::QScriptValue(const QString &value)
: d_ptr(new QScriptValuePrivate)
{
d_ptr->engine = 0;
- d_ptr->initFromString(value);
+ d_ptr->initFrom(value);
d_ptr->ref.ref();
}
@@ -730,7 +730,7 @@ QScriptValue::QScriptValue(const QLatin1String &value)
: d_ptr(new QScriptValuePrivate)
{
d_ptr->engine = 0;
- d_ptr->initFromString(value);
+ d_ptr->initFrom(value);
d_ptr->ref.ref();
}
@@ -745,7 +745,7 @@ QScriptValue::QScriptValue(const char *value)
: d_ptr(new QScriptValuePrivate)
{
d_ptr->engine = 0;
- d_ptr->initFromString(QString::fromAscii(value));
+ d_ptr->initFrom(QString::fromAscii(value));
d_ptr->ref.ref();
}
#endif
diff --git a/src/script/api/qscriptvalue_p.h b/src/script/api/qscriptvalue_p.h
index 7090916..a3ebbed 100644
--- a/src/script/api/qscriptvalue_p.h
+++ b/src/script/api/qscriptvalue_p.h
@@ -112,9 +112,9 @@ public:
QScriptValuePrivate();
~QScriptValuePrivate();
- void initFromJSCValue(JSC::JSValue value);
- void initFromNumber(double value);
- void initFromString(const QString &value);
+ void initFrom(JSC::JSValue value);
+ void initFrom(double value);
+ void initFrom(const QString &value);
static void initFromJSCValue(QScriptValue &result,
QScriptEngine *engine,
@@ -125,17 +125,22 @@ public:
QVariant &variantValue() const;
void setVariantValue(const QVariant &value);
- static QScriptValuePrivate *get(const QScriptValue &q) { return q.d_ptr; }
-
- QScriptValue property(const JSC::Identifier &id, int resolveMode) const;
- QScriptValue property(const QString &, int resolveMode) const;
- QScriptValue property(quint32 index, int resolveMode) const;
+ static QScriptValuePrivate *get(const QScriptValue &q)
+ {
+ return q.d_ptr;
+ }
- QScriptValue toPublic() {
+ static QScriptValue get(QScriptValuePrivate *d)
+ {
QScriptValue tmp;
- tmp.d_ptr = this;
+ tmp.d_ptr = d;
+ d->ref.ref();
return tmp;
- };
+ }
+
+ QScriptValue property(const JSC::Identifier &id, int resolveMode) const;
+ QScriptValue property(quint32 index, int resolveMode) const;
+ QScriptValue property(const QString &, int resolveMode) const;
bool isValid() const {return valid;}
void detachEngine()