Пример #1
0
void QFAppScriptRunnable::release()
{
    if (!m_condition.isNull() &&
            m_condition.isObject() &&
        m_condition.hasProperty("disconnect")) {

        QJSValue disconnect = m_condition.property("disconnect");
        QJSValueList args;
        args << m_callback;

        disconnect.callWithInstance(m_condition,args);
    }

    m_condition = QJSValue();
    m_callback = QJSValue();
}
Пример #2
0
void QFAppScriptRunnable::setCondition(QJSValue condition)
{
    m_condition = condition;

    if (condition.isString()) {
        setType(condition.toString());
        m_isSignalCondition = false;
    } else if (condition.isObject() && condition.hasProperty("connect")) {
        Q_ASSERT(!m_engine.isNull());

        QString type = QString("QuickFlux.AppScript.%1").arg(QUuid::createUuid().toString());
        setType(type);

        QString generator = "(function(dispatcher) { return function() {dispatcher.dispatch(arguments)}})";
        QFAppDispatcher* dispatcher = QFAppDispatcher::instance(m_engine);
        QFAppScriptDispatcherWrapper * wrapper = new QFAppScriptDispatcherWrapper();
        wrapper->setType(type);
        wrapper->setDispatcher(dispatcher);

        QJSValue generatorFunc = m_engine->evaluate(generator);

        QJSValueList args;
        args << m_engine->newQObject(wrapper);
        QJSValue callback = generatorFunc.call(args);

        args.clear();
        args << callback;

        QJSValue connect = condition.property("connect");
        connect.callWithInstance(condition,args);

        m_callback = callback;
        m_isSignalCondition = true;
    } else {
        qWarning() << "AppScript: Invalid condition type";
    }
}
Пример #3
0
bool QmlCovPlugin::jsParse(QJSEngine *engine, const QString &content, QJSValue &value)
{
    QJSValue JSON = engine->evaluate("JSON");
    if (JSON.isError()) {
        qCritical() << "Uncaught exception:" << JSON.toString();
        return false;
    }

    QJSValue parse = JSON.property("parse");
    if (parse.isError()) {
        qCritical() << "Uncaught exception:" << parse.toString();
        return false;
    }

    QJSValue results = parse.callWithInstance(JSON, QJSValueList() << content);
    if (results.isError()) {
        qCritical() << "Uncaught exception:" << results.toString();
        return false;
    }

    value = results;

    return true;
}
Пример #4
0
bool QmlCovPlugin::jsStringify(QJSEngine *engine, const QJSValue &value, QString &content)
{
    QJSValue JSON = engine->evaluate("JSON");
    if (JSON.isError()) {
        qCritical() << "Uncaught exception:" << JSON.toString();
        return false;
    }

    QJSValue stringify = JSON.property("stringify");
    if (stringify.isError()) {
        qCritical() << "Uncaught exception:" << stringify.toString();
        return false;
    }

    QJSValue results = stringify.callWithInstance(JSON, QJSValueList() << value);
    if (results.isError()) {
        qCritical() << "Uncaught exception:" << results.toString();
        return false;
    }

    content = results.toString();

    return true;
}
Пример #5
0
qmlbind_value qmlbind_value_call_with_instance(qmlbind_value self, qmlbind_value instance, int argc, qmlbind_value *argv)
{
    QJSValue func = *self;
    return new QJSValue(func.callWithInstance(*instance, pack_args(argc, argv)));
}