当前位置: 首页>>代码示例>>C++>>正文


C++ QScriptValueList::size方法代码示例

本文整理汇总了C++中QScriptValueList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValueList::size方法的具体用法?C++ QScriptValueList::size怎么用?C++ QScriptValueList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QScriptValueList的用法示例。


在下文中一共展示了QScriptValueList::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: extension

QVariant TestClass::extension(Extension extension,
                              const QVariant &argument)
{
    if (extension == Callable) {
        Q_ASSERT(m_callableMode != NotCallable);
        QScriptContext *ctx = qvariant_cast<QScriptContext*>(argument);
        if (m_callableMode == CallableReturnsSum) {
            qsreal sum = 0;
            for (int i = 0; i < ctx->argumentCount(); ++i)
                sum += ctx->argument(i).toNumber();
            QScriptValueIterator it(ctx->thisObject());
            while (it.hasNext()) {
                it.next();
                sum += it.value().toNumber();
            }
            return sum;
        } else if (m_callableMode == CallableReturnsArgument) {
            return qVariantFromValue(ctx->argument(0));
        } else if (m_callableMode == CallableReturnsInvalidVariant) {
            return QVariant();
        }
    } else if (extension == HasInstance) {
        Q_ASSERT(m_hasInstance);
        QScriptValueList args = qvariant_cast<QScriptValueList>(argument);
        Q_ASSERT(args.size() == 2);
        QScriptValue obj = args.at(0);
        QScriptValue value = args.at(1);
        return value.property("foo").equals(obj.property("foo"));
    }
    return QVariant();
}
开发者ID:,项目名称:,代码行数:31,代码来源:

示例2: scopeChain

void tst_QScriptContext::scopeChain()
{
    QScriptEngine eng;
    {
        QScriptValueList ret = eng.currentContext()->scopeChain();
        QCOMPARE(ret.size(), 1);
        QVERIFY(ret.at(0).strictlyEquals(eng.globalObject()));
    }
    {
        eng.globalObject().setProperty("getScopeChain", eng.newFunction(getScopeChain));
        QScriptValueList ret = qscriptvalue_cast<QScriptValueList>(eng.evaluate("getScopeChain()"));
        QCOMPARE(ret.size(), 1);
        QVERIFY(ret.at(0).strictlyEquals(eng.globalObject()));
    }
    {
        eng.evaluate("function foo() { function bar() { return getScopeChain(); } return bar() }");
        QScriptValueList ret = qscriptvalue_cast<QScriptValueList>(eng.evaluate("foo()"));
        QEXPECT_FAIL("", "Number of items in returned scope chain is incorrect", Abort);
        QCOMPARE(ret.size(), 3);
        QVERIFY(ret.at(2).strictlyEquals(eng.globalObject()));
        QCOMPARE(ret.at(1).toString(), QString::fromLatin1("activation"));
        QVERIFY(ret.at(1).property("arguments").isObject());
        QCOMPARE(ret.at(0).toString(), QString::fromLatin1("activation"));
        QVERIFY(ret.at(0).property("arguments").isObject());
    }
    {
        QScriptValueList ret = qscriptvalue_cast<QScriptValueList>(eng.evaluate("o = { x: 123 }; with(o) getScopeChain();"));
        QCOMPARE(ret.size(), 2);
        QVERIFY(ret.at(1).strictlyEquals(eng.globalObject()));
        QVERIFY(ret.at(0).isObject());
        QCOMPARE(ret.at(0).property("x").toInt32(), 123);
    }
    {
        QScriptValueList ret = qscriptvalue_cast<QScriptValueList>(
            eng.evaluate("o1 = { x: 123}; o2 = { y: 456 }; with(o1) { with(o2) { getScopeChain(); } }"));
        QCOMPARE(ret.size(), 3);
        QVERIFY(ret.at(2).strictlyEquals(eng.globalObject()));
        QVERIFY(ret.at(1).isObject());
        QCOMPARE(ret.at(1).property("x").toInt32(), 123);
        QVERIFY(ret.at(0).isObject());
        QCOMPARE(ret.at(0).property("y").toInt32(), 456);
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:43,代码来源:tst_qscriptcontext.cpp

示例3: execute


//.........这里部分代码省略.........
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetContextInfo: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(QScriptContextInfo(ctx));
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetThisObject: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(ctx->thisObject());
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetActivationObject: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(ctx->activationObject());
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetScopeChain: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx) {
            QScriptDebuggerValueList dest;
            QScriptValueList src = ctx->scopeChain();
            for (int i = 0; i < src.size(); ++i)
                dest.append(src.at(i));
            response.setResult(dest);
        } else {
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
        }
    }   break;

    case QScriptDebuggerCommand::ContextsCheckpoint: {
        response.setResult(QVariant::fromValue(backend->contextsCheckpoint()));
    }   break;

    case QScriptDebuggerCommand::GetPropertyExpressionValue: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        int lineNumber = command.lineNumber();
        QVariant attr = command.attribute(QScriptDebuggerCommand::UserAttribute);
        QStringList path = attr.toStringList();
        if (!ctx || path.isEmpty())
            break;
        QScriptContextInfo ctxInfo(ctx);
        if (ctx->callee().isValid()
            && ((lineNumber < ctxInfo.functionStartLineNumber())
                || (lineNumber > ctxInfo.functionEndLineNumber()))) {
            break;
        }
        QScriptValueList objects;
        int pathIndex = 0;
        if (path.at(0) == QLatin1String("this")) {
            objects.append(ctx->thisObject());
            ++pathIndex;
        } else {
            objects << ctx->scopeChain();
        }
开发者ID:Blizzard,项目名称:qt4,代码行数:67,代码来源:qscriptdebuggercommandexecutor.cpp

示例4: extension


//.........这里部分代码省略.........
            QScriptValue ret = obj.call(obj, QScriptValueList() << 123);
            QVERIFY(ret.isObject());
            QVERIFY(ret.property("length").isNumber());
            QCOMPARE(ret.property("length").toInt32(), 1);
            QVERIFY(ret.property(0).isNumber());
            QCOMPARE(ret.property(0).toInt32(), 123);
        }
        // From JS
        {
            QScriptValue ret = eng.evaluate("obj(123)");
            QVERIFY(ret.isObject());
            QVERIFY(ret.property("length").isNumber());
            QCOMPARE(ret.property("length").toInt32(), 1);
            QVERIFY(ret.property(0).isNumber());
            QCOMPARE(ret.property(0).toInt32(), 123);
        }

        // construct()
        // From C++
        cls.clearReceivedArgs();
        cls.setCallableMode(TestClass::CallableReturnsGlobalObject);
        {
            QScriptValue ret = obj.construct();
            QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
            QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
            QVERIFY(ret.isObject());
            QVERIFY(ret.strictlyEquals(eng.globalObject()));
        }
        // From JS
        cls.clearReceivedArgs();
        {
            QScriptValue ret = eng.evaluate("new obj()");
            QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
            QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
            QVERIFY(ret.isObject());
            QVERIFY(ret.strictlyEquals(eng.globalObject()));
        }
        // From C++
        cls.clearReceivedArgs();
        cls.setCallableMode(TestClass::CallableInitializesThisObject);
        {
            QScriptValue ret = obj.construct();
            QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
            QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
            QVERIFY(ret.isQObject());
            QCOMPARE(ret.toQObject(), (QObject*)&eng);
        }
        // From JS
        cls.clearReceivedArgs();
        {
            QScriptValue ret = eng.evaluate("new obj()");
            QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
            QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
            QVERIFY(ret.isQObject());
            QCOMPARE(ret.toQObject(), (QObject*)&eng);
        }
    }
    // HasInstance
    {
        TestClass cls(&eng);
        cls.setHasInstance(true);
        QVERIFY(cls.supportsExtension(QScriptClass::HasInstance));

        QScriptValue obj = eng.newObject(&cls);
        obj.setProperty("foo", QScriptValue(&eng, 123));
        QScriptValue plain = eng.newObject();
        QVERIFY(!plain.instanceOf(obj));

        eng.globalObject().setProperty("HasInstanceTester", obj);
        eng.globalObject().setProperty("hasInstanceValue", plain);
        cls.clearReceivedArgs();
        {
            QScriptValue ret = eng.evaluate("hasInstanceValue instanceof HasInstanceTester");
            QCOMPARE(cls.lastExtensionType(), QScriptClass::HasInstance);
            QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptValueList>());
            QScriptValueList lst = qvariant_cast<QScriptValueList>(cls.lastExtensionArgument());
            QCOMPARE(lst.size(), 2);
            QVERIFY(lst.at(0).strictlyEquals(obj));
            QVERIFY(lst.at(1).strictlyEquals(plain));
            QVERIFY(ret.isBoolean());
            QVERIFY(!ret.toBoolean());
        }

        plain.setProperty("foo", QScriptValue(&eng, 456));
        QVERIFY(!plain.instanceOf(obj));
        {
            QScriptValue ret = eng.evaluate("hasInstanceValue instanceof HasInstanceTester");
            QVERIFY(ret.isBoolean());
            QVERIFY(!ret.toBoolean());
        }

        plain.setProperty("foo", obj.property("foo"));
        QVERIFY(plain.instanceOf(obj));
        {
            QScriptValue ret = eng.evaluate("hasInstanceValue instanceof HasInstanceTester");
            QVERIFY(ret.isBoolean());
            QVERIFY(ret.toBoolean());
        }
    }
}
开发者ID:husninazer,项目名称:qt,代码行数:101,代码来源:tst_qscriptclass.cpp


注:本文中的QScriptValueList::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。