本文整理汇总了C++中QScriptValueList::at方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValueList::at方法的具体用法?C++ QScriptValueList::at怎么用?C++ QScriptValueList::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValueList
的用法示例。
在下文中一共展示了QScriptValueList::at方法的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();
}
示例2: execute
/*!
Applies the given \a command to the given \a backend.
*/
QScriptDebuggerResponse QScriptDebuggerCommandExecutor::execute(
QScriptDebuggerBackend *backend,
const QScriptDebuggerCommand &command)
{
QScriptDebuggerResponse response;
switch (command.type()) {
case QScriptDebuggerCommand::None:
break;
case QScriptDebuggerCommand::Interrupt:
backend->interruptEvaluation();
break;
case QScriptDebuggerCommand::Continue:
if (backend->engine()->isEvaluating()) {
backend->continueEvalution();
response.setAsync(true);
}
break;
case QScriptDebuggerCommand::StepInto: {
QVariant attr = command.attribute(QScriptDebuggerCommand::StepCount);
int count = attr.isValid() ? attr.toInt() : 1;
backend->stepInto(count);
response.setAsync(true);
} break;
case QScriptDebuggerCommand::StepOver: {
QVariant attr = command.attribute(QScriptDebuggerCommand::StepCount);
int count = attr.isValid() ? attr.toInt() : 1;
backend->stepOver(count);
response.setAsync(true);
} break;
case QScriptDebuggerCommand::StepOut:
backend->stepOut();
response.setAsync(true);
break;
case QScriptDebuggerCommand::RunToLocation:
backend->runToLocation(command.fileName(), command.lineNumber());
response.setAsync(true);
break;
case QScriptDebuggerCommand::RunToLocationByID:
backend->runToLocation(command.scriptId(), command.lineNumber());
response.setAsync(true);
break;
case QScriptDebuggerCommand::ForceReturn: {
int contextIndex = command.contextIndex();
QScriptDebuggerValue value = command.scriptValue();
QScriptEngine *engine = backend->engine();
QScriptValue realValue = value.toScriptValue(engine);
backend->returnToCaller(contextIndex, realValue);
response.setAsync(true);
} break;
case QScriptDebuggerCommand::Resume:
backend->resume();
response.setAsync(true);
break;
case QScriptDebuggerCommand::SetBreakpoint: {
QScriptBreakpointData data = command.breakpointData();
if (!data.isValid())
data = QScriptBreakpointData(command.fileName(), command.lineNumber());
int id = backend->setBreakpoint(data);
response.setResult(id);
} break;
case QScriptDebuggerCommand::DeleteBreakpoint: {
int id = command.breakpointId();
if (!backend->deleteBreakpoint(id))
response.setError(QScriptDebuggerResponse::InvalidBreakpointID);
} break;
case QScriptDebuggerCommand::DeleteAllBreakpoints:
backend->deleteAllBreakpoints();
break;
case QScriptDebuggerCommand::GetBreakpoints: {
QScriptBreakpointMap bps = backend->breakpoints();
if (!bps.isEmpty())
response.setResult(bps);
} break;
case QScriptDebuggerCommand::GetBreakpointData: {
int id = command.breakpointId();
QScriptBreakpointData data = backend->breakpointData(id);
if (data.isValid())
response.setResult(data);
else
response.setError(QScriptDebuggerResponse::InvalidBreakpointID);
} break;
case QScriptDebuggerCommand::SetBreakpointData: {
//.........这里部分代码省略.........
示例3: 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);
}
}
示例4: extension
void tst_QScriptClass::extension()
{
QScriptEngine eng;
{
TestClass cls(&eng);
cls.setCallableMode(TestClass::NotCallable);
QVERIFY(!cls.supportsExtension(QScriptClass::Callable));
QVERIFY(!cls.supportsExtension(QScriptClass::HasInstance));
QScriptValue obj = eng.newObject(&cls);
QVERIFY(!obj.call().isValid());
QCOMPARE((int)cls.lastExtensionType(), -1);
QVERIFY(!obj.instanceOf(obj));
QCOMPARE((int)cls.lastExtensionType(), -1);
}
// Callable
{
TestClass cls(&eng);
cls.setCallableMode(TestClass::CallableReturnsSum);
QVERIFY(cls.supportsExtension(QScriptClass::Callable));
QScriptValue obj = eng.newObject(&cls);
eng.globalObject().setProperty("obj", obj);
obj.setProperty("one", QScriptValue(&eng, 1));
obj.setProperty("two", QScriptValue(&eng, 2));
obj.setProperty("three", QScriptValue(&eng, 3));
// From C++
cls.clearReceivedArgs();
{
QScriptValueList args;
args << QScriptValue(&eng, 4) << QScriptValue(&eng, 5);
QScriptValue ret = obj.call(obj, args);
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isNumber());
QCOMPARE(ret.toNumber(), qsreal(15));
}
// From JS
cls.clearReceivedArgs();
{
QScriptValue ret = eng.evaluate("obj(4, 5)");
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isNumber());
QCOMPARE(ret.toNumber(), qsreal(15));
}
cls.setCallableMode(TestClass::CallableReturnsArgument);
// From C++
cls.clearReceivedArgs();
{
QScriptValue ret = obj.call(obj, QScriptValueList() << 123);
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isNumber());
QCOMPARE(ret.toInt32(), 123);
}
cls.clearReceivedArgs();
{
QScriptValue ret = obj.call(obj, QScriptValueList() << true);
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isBoolean());
QCOMPARE(ret.toBoolean(), true);
}
{
QScriptValue ret = obj.call(obj, QScriptValueList() << QString::fromLatin1("ciao"));
QVERIFY(ret.isString());
QCOMPARE(ret.toString(), QString::fromLatin1("ciao"));
}
{
QScriptValue objobj = eng.newObject();
QScriptValue ret = obj.call(obj, QScriptValueList() << objobj);
QVERIFY(ret.isObject());
QVERIFY(ret.strictlyEquals(objobj));
}
{
QScriptValue ret = obj.call(obj, QScriptValueList() << QScriptValue());
QVERIFY(ret.isUndefined());
}
// From JS
cls.clearReceivedArgs();
{
QScriptValue ret = eng.evaluate("obj(123)");
QVERIFY(ret.isNumber());
QCOMPARE(ret.toInt32(), 123);
}
cls.setCallableMode(TestClass::CallableReturnsInvalidVariant);
{
QScriptValue ret = obj.call(obj);
QVERIFY(ret.isUndefined());
}
cls.setCallableMode(TestClass::CallableReturnsThisObject);
// From C++
{
QScriptValue ret = obj.call(obj);
QVERIFY(ret.isObject());
QVERIFY(ret.strictlyEquals(obj));
}
//.........这里部分代码省略.........