Skip to content

Commit

Permalink
Remove QJSValue constructors that take QJSEngine argument
Browse files Browse the repository at this point in the history
Rationale: These were remnants from QtScript.
The difference from the standard constructors is that the value is
eagerly bound to the engine, so they can be a bit faster. But they
are also more low-level and look ugly in use.

Task-number: QTBUG-23604
Change-Id: I5dae7452389383f60055d5ccc4f28d53c52f6092
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
  • Loading branch information
Kent Hansen authored and Qt by Nokia committed Feb 2, 2012
1 parent 54c51c8 commit f4c9823
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 362 deletions.
116 changes: 0 additions & 116 deletions src/declarative/qml/v8/qjsvalue.cpp
Expand Up @@ -189,122 +189,6 @@ QJSValue::QJSValue(QScriptPassPointer<QJSValuePrivate> d)
{
}

#ifdef QT_DEPRECATED

/*!
\obsolete
Constructs a new QJSValue with the boolean \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, bool value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), value);
} else {
d_ptr = new QJSValuePrivate(value);
}
}

/*!
\obsolete
Constructs a new QJSValue with the integer \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, int value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), value);
} else {
d_ptr = new QJSValuePrivate(value);
}
}

/*!
\obsolete
Constructs a new QJSValue with the unsigned integer \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, uint value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), value);
} else {
d_ptr = new QJSValuePrivate(value);
}
}

/*!
\obsolete
Constructs a new QJSValue with the double \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, double value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), value);
} else {
d_ptr = new QJSValuePrivate(value);
}
}

/*!
\obsolete
Constructs a new QJSValue with the string \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, const QString& value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), value);
} else {
d_ptr = new QJSValuePrivate(value);
}
}

/*!
\obsolete
Constructs a new QJSValue with the string \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, const char* value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), QString::fromUtf8(value));
} else {
d_ptr = new QJSValuePrivate(QString::fromUtf8(value));
}
}

/*!
\obsolete
Constructs a new QJSValue with the special \a value and
registers it with the script \a engine.
*/
QJSValue::QJSValue(QJSEngine* engine, SpecialValue value)
{
if (engine) {
QScriptIsolate api(QV8Engine::get(engine), QScriptIsolate::NotNullEngine);
d_ptr = new QJSValuePrivate(QV8Engine::get(engine), value);
} else {
d_ptr = new QJSValuePrivate(value);
}
}

#endif // QT_DEPRECATED

/*!
Constructs a new QJSValue that is a copy of \a other.
Expand Down
12 changes: 0 additions & 12 deletions src/declarative/qml/v8/qjsvalue.h
Expand Up @@ -118,13 +118,6 @@ class Q_DECLARATIVE_EXPORT QJSValue
QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());

#ifdef QT_DEPRECATED
QT_DEPRECATED QJSValue(QJSEngine *engine, SpecialValue val);
QT_DEPRECATED QJSValue(QJSEngine *engine, bool val);
QT_DEPRECATED QJSValue(QJSEngine *engine, int val);
QT_DEPRECATED QJSValue(QJSEngine *engine, uint val);
QT_DEPRECATED QJSValue(QJSEngine *engine, double val);
QT_DEPRECATED QJSValue(QJSEngine *engine, const QString &val);

QT_DEPRECATED QJSEngine *engine() const;

QT_DEPRECATED bool isFunction() const;
Expand All @@ -139,11 +132,6 @@ class Q_DECLARATIVE_EXPORT QJSValue
private:
// force compile error, prevent QJSValue(bool) to be called
QJSValue(void *);
#ifdef QT_DEPRECATED
// force compile error, prevent QJSValue(QScriptEngine*, bool) to be called
QJSValue(QJSEngine *, void *);
QJSValue(QJSEngine *, const char *);
#endif

QJSValue(QJSValuePrivate*);
QJSValue(QScriptPassPointer<QJSValuePrivate>);
Expand Down
24 changes: 12 additions & 12 deletions tests/auto/declarative/qjsengine/tst_qjsengine.cpp
Expand Up @@ -2105,7 +2105,7 @@ void tst_QJSEngine::evaluate()
#endif
if (eng.hasUncaughtException() && ret.isError()) {
QEXPECT_FAIL("", "we have no more lineNumber property ", Continue);
QVERIFY(ret.property("lineNumber").strictlyEquals(QJSValue(&eng, expectErrorLineNumber)));
QVERIFY(ret.property("lineNumber").strictlyEquals(eng.toScriptValue(expectErrorLineNumber)));
} else {
#if 0 // ###FIXME: No support for the backtrace of an uncaught exception
QVERIFY(eng.uncaughtExceptionBacktrace().isEmpty());
Expand Down Expand Up @@ -2276,8 +2276,8 @@ void tst_QJSEngine::getSetDefaultPrototype_customType()
static QJSValue fooToScriptValue(QJSEngine *eng, const Foo &foo)
{
QJSValue obj = eng->newObject();
obj.setProperty("x", QJSValue(eng, foo.x));
obj.setProperty("y", QJSValue(eng, foo.y));
obj.setProperty("x", eng->toScriptValue(foo.x));
obj.setProperty("y", eng->toScriptValue(foo.y));
return obj;
}

Expand All @@ -2289,7 +2289,7 @@ static void fooFromScriptValue(const QJSValue &value, Foo &foo)

static QJSValue fooToScriptValueV2(QJSEngine *eng, const Foo &foo)
{
return QJSValue(eng, foo.x);
return eng->toScriptValue(foo.x);
}

static void fooFromScriptValueV2(const QJSValue &value, Foo &foo)
Expand All @@ -2310,7 +2310,7 @@ void tst_QJSEngine::valueConversion_basic()
{
QJSValue num = eng.toScriptValue(123);
QCOMPARE(num.isNumber(), true);
QCOMPARE(num.strictlyEquals(QJSValue(&eng, 123)), true);
QCOMPARE(num.strictlyEquals(eng.toScriptValue(123)), true);

int inum = eng.fromScriptValue<int>(num);
QCOMPARE(inum, 123);
Expand All @@ -2321,7 +2321,7 @@ void tst_QJSEngine::valueConversion_basic()
{
QJSValue num = eng.toScriptValue(123);
QCOMPARE(num.isNumber(), true);
QCOMPARE(num.strictlyEquals(QJSValue(&eng, 123)), true);
QCOMPARE(num.strictlyEquals(eng.toScriptValue(123)), true);

int inum = eng.fromScriptValue<int>(num);
QCOMPARE(inum, 123);
Expand All @@ -2330,7 +2330,7 @@ void tst_QJSEngine::valueConversion_basic()
QCOMPARE(snum, QLatin1String("123"));
}
{
QJSValue num(&eng, 123);
QJSValue num = eng.toScriptValue(123);
QCOMPARE(eng.fromScriptValue<char>(num), char(123));
QCOMPARE(eng.fromScriptValue<unsigned char>(num), (unsigned char)(123));
QCOMPARE(eng.fromScriptValue<short>(num), short(123));
Expand Down Expand Up @@ -2360,9 +2360,9 @@ void tst_QJSEngine::valueConversion_basic()

{
QChar c = QLatin1Char('c');
QJSValue str = QJSValue(&eng, QLatin1String("ciao"));
QJSValue str = eng.toScriptValue(QString::fromLatin1("ciao"));
QCOMPARE(eng.fromScriptValue<QChar>(str), c);
QJSValue code = QJSValue(&eng, c.unicode());
QJSValue code = eng.toScriptValue(c.unicode());
QCOMPARE(eng.fromScriptValue<QChar>(code), c);
QCOMPARE(eng.fromScriptValue<QChar>(eng.toScriptValue(c)), c);
}
Expand Down Expand Up @@ -3906,7 +3906,7 @@ void tst_QJSEngine::printThrowsException()
QJSEngine eng;
QJSValue ret = eng.evaluate("print({ toString: function() { throw 'foo'; } });");
QVERIFY(eng.hasUncaughtException());
QVERIFY(ret.strictlyEquals(QJSValue(&eng, QLatin1String("foo"))));
QVERIFY(ret.strictlyEquals(eng.toScriptValue(QLatin1String("foo"))));
}
#endif

Expand Down Expand Up @@ -4293,14 +4293,14 @@ void tst_QJSEngine::stringObjects()
QCOMPARE(obj.property(pname).toString(), QString(str.at(i)));
QEXPECT_FAIL("", "FIXME: This is V8 issue 862. ECMA script standard 15.5.5.2 compliance.", Continue);
QVERIFY(!obj.deleteProperty(pname));
obj.setProperty(pname, QJSValue(&eng, 123));
obj.setProperty(pname, 123);
QVERIFY(obj.property(pname).isString());
QCOMPARE(obj.property(pname).toString(), QString(str.at(i)));
}
QVERIFY(obj.property("-1").isUndefined());
QVERIFY(obj.property(QString::number(str.length())).isUndefined());

QJSValue val(&eng, 123);
QJSValue val = eng.toScriptValue(123);
obj.setProperty("-1", val);
QVERIFY(obj.property("-1").strictlyEquals(val));
obj.setProperty("100", val);
Expand Down

0 comments on commit f4c9823

Please sign in to comment.