summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptvalue.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-07-15 14:48:03 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-07-16 09:54:57 (GMT)
commitadb1182d4cb600f48b5858dd78b4b6a6c43a89cd (patch)
treee28b463adc196baf0f507ea5239bdff5d10f76bf /src/script/api/qscriptvalue.cpp
parent7496ce1de03c9e11e710dbd4dae2056a21f5addd (diff)
downloadQt-adb1182d4cb600f48b5858dd78b4b6a6c43a89cd.zip
Qt-adb1182d4cb600f48b5858dd78b4b6a6c43a89cd.tar.gz
Qt-adb1182d4cb600f48b5858dd78b4b6a6c43a89cd.tar.bz2
Convert the strings or number value to jscvalue when they are used with an engine
Also change the stringValue not to be a pointer. This fixes a memory leak.
Diffstat (limited to 'src/script/api/qscriptvalue.cpp')
-rw-r--r--src/script/api/qscriptvalue.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp
index 68ad93a..4d5361e 100644
--- a/src/script/api/qscriptvalue.cpp
+++ b/src/script/api/qscriptvalue.cpp
@@ -299,7 +299,7 @@ void QScriptValuePrivate::initFromNumber(double value)
void QScriptValuePrivate::initFromString(const QString &value)
{
type = String;
- stringValue = new QString(value);
+ stringValue = value;
}
void QScriptValuePrivate::initFromJSCValue(QScriptValue &result,
@@ -1168,7 +1168,7 @@ bool QScriptValue::strictlyEquals(const QScriptValue &other) const
case QScriptValuePrivate::Number:
return (d->numberValue == other.d_ptr->numberValue);
case QScriptValuePrivate::String:
- return (*d->stringValue == *other.d_ptr->stringValue);
+ return (d->stringValue == other.d_ptr->stringValue);
}
return false;
}
@@ -1200,7 +1200,7 @@ QString QScriptValue::toString() const
case QScriptValuePrivate::Number:
return QScript::qtStringFromJSCUString(JSC::UString::from(d->numberValue));
case QScriptValuePrivate::String:
- return *d->stringValue;
+ return d->stringValue;
}
return QString();
}
@@ -1231,7 +1231,7 @@ qsreal QScriptValue::toNumber() const
case QScriptValuePrivate::Number:
return d->numberValue;
case QScriptValuePrivate::String:
- return QScript::qtStringToJSCUString(*d->stringValue).toDouble();
+ return QScript::qtStringToJSCUString(d->stringValue).toDouble();
}
return 0;
}
@@ -1255,7 +1255,7 @@ bool QScriptValue::toBoolean() const
case QScriptValuePrivate::Number:
return (d->numberValue != 0) && !qIsNaN(d->numberValue);
case QScriptValuePrivate::String:
- return (d->stringValue->length() != 0);
+ return (!d->stringValue.isEmpty());
}
return false;
}
@@ -1288,7 +1288,7 @@ bool QScriptValue::toBool() const
case QScriptValuePrivate::Number:
return (d->numberValue != 0) && !qIsNaN(d->numberValue);
case QScriptValuePrivate::String:
- return (d->stringValue->length() != 0);
+ return (!d->stringValue.isEmpty());
}
return false;
}
@@ -1319,7 +1319,7 @@ qint32 QScriptValue::toInt32() const
case QScriptValuePrivate::Number:
return QScript::ToInt32(d->numberValue);
case QScriptValuePrivate::String:
- return QScript::ToInt32(QScript::qtStringToJSCUString(*d->stringValue).toDouble());
+ return QScript::ToInt32(QScript::qtStringToJSCUString(d->stringValue).toDouble());
}
return 0;
}
@@ -1350,7 +1350,7 @@ quint32 QScriptValue::toUInt32() const
case QScriptValuePrivate::Number:
return QScript::ToUint32(d->numberValue);
case QScriptValuePrivate::String:
- return QScript::ToUint32(QScript::qtStringToJSCUString(*d->stringValue).toDouble());
+ return QScript::ToUint32(QScript::qtStringToJSCUString(d->stringValue).toDouble());
}
return 0;
}
@@ -1380,7 +1380,7 @@ quint16 QScriptValue::toUInt16() const
case QScriptValuePrivate::Number:
return QScript::ToUint16(d->numberValue);
case QScriptValuePrivate::String:
- return QScript::ToUint16(QScript::qtStringToJSCUString(*d->stringValue).toDouble());
+ return QScript::ToUint16(QScript::qtStringToJSCUString(d->stringValue).toDouble());
}
return 0;
}
@@ -1411,7 +1411,7 @@ qsreal QScriptValue::toInteger() const
case QScriptValuePrivate::Number:
return QScript::ToInteger(d->numberValue);
case QScriptValuePrivate::String:
- return QScript::ToInteger(QScript::qtStringToJSCUString(*d->stringValue).toDouble());
+ return QScript::ToInteger(QScript::qtStringToJSCUString(d->stringValue).toDouble());
}
return 0;
}
@@ -1477,7 +1477,7 @@ QVariant QScriptValue::toVariant() const
case QScriptValuePrivate::Number:
return QVariant(d->numberValue);
case QScriptValuePrivate::String:
- return QVariant(*d->stringValue);
+ return QVariant(d->stringValue);
}
return QVariant();
}
@@ -1608,13 +1608,15 @@ const QMetaObject *QScriptValue::toQMetaObject() const
\sa property()
*/
+
void QScriptValue::setProperty(const QString &name, const QScriptValue &value,
const PropertyFlags &flags)
{
Q_D(QScriptValue);
if (!d || !d->isJSC() || !d->jscValue.isObject())
return;
- if (value.engine() && (value.engine() != engine())) {
+ QScriptEngine *valueEngine = value.engine();
+ if (valueEngine && (valueEngine != d->engine)) {
qWarning("QScriptValue::setProperty(%s) failed: "
"cannot set value created in a different engine",
qPrintable(name));