[Development] Porting code from QScriptEngine (Qt4) to QJSEngine (Qt5)

a.grandi at gmail.com a.grandi at gmail.com
Thu Jun 21 14:33:19 CEST 2012


I've started porting some code from QScriptEngine to QJSEngine, but
there are some missing parts I don't know how to implement.

1) Here is the comparative "table":

- QScriptEngine --> QJSEngine
- QScriptValue --> QJSValue
- QScriptValueIterator --> QJSValueIterator
- QScriptContext --> ???

QScriptContext is the first big missing part. In the actual code is
used to retrive the name of an argument, like this:

static QScriptValue Envjs_runAsync(QScriptContext *ctx, QScriptEngine *eng)
{
    QScriptValue fun = ctx->argument(0);
    QtScriptFunctionInvoker *invoker = new QtScriptFunctionInvoker(fun, eng);
    invoker->invokeLater();
    return eng->undefinedValue();
}

There is not anything similar in QJSEngine as far as I know.

2) Some methods are using the throwError() method that return a
particular QScriptValue/QJSValue. I cannot simply create a new
QJSValue because I cannot pass the "Error" type to the constructor (I
can only verify if a QJSValue is an error with the isError() method.

Do you know where I can an overview of the changes needed in Qt5 when
we have to inject/evaluate/calling JavaScript code in Qt5? Are we
missing some methods?

p.s: if anyone is interested I'm trying to make EnvJs work like
explained here http://labs.qt.nokia.com/2011/03/10/say-hello-to-envjs-for-qtscript/
but no success at the moment.

-- 
Andrea Grandi - Nokia Qt Ambassador
Ubuntu Member: https://launchpad.net/~andreagrandi
website: http://www.andreagrandi.it



More information about the Development mailing list