本文整理汇总了C++中QScriptValue::strictlyEquals方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::strictlyEquals方法的具体用法?C++ QScriptValue::strictlyEquals怎么用?C++ QScriptValue::strictlyEquals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::strictlyEquals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assignAndCopyConstruct_test
void tst_QScriptValueGenerated::assignAndCopyConstruct_test(const char *, const QScriptValue &value)
{
QScriptValue copy(value);
QCOMPARE(copy.strictlyEquals(value), !value.isNumber() || !qIsNaN(value.toNumber()));
QCOMPARE(copy.engine(), value.engine());
QScriptValue assigned = copy;
QCOMPARE(assigned.strictlyEquals(value), !copy.isNumber() || !qIsNaN(copy.toNumber()));
QCOMPARE(assigned.engine(), assigned.engine());
QScriptValue other(!value.toBool());
assigned = other;
QVERIFY(!assigned.strictlyEquals(copy));
QVERIFY(assigned.strictlyEquals(other));
QCOMPARE(assigned.engine(), other.engine());
}
示例2: pushAndPopContext
void tst_QScriptContext::pushAndPopContext()
{
QScriptEngine eng;
QScriptContext *topLevel = eng.currentContext();
QCOMPARE(topLevel->engine(), &eng);
QScriptContext *ctx = eng.pushContext();
QVERIFY(ctx != 0);
QCOMPARE(ctx->parentContext(), topLevel);
QCOMPARE(eng.currentContext(), ctx);
QCOMPARE(ctx->engine(), &eng);
QCOMPARE(ctx->state(), QScriptContext::NormalState);
QCOMPARE(ctx->isCalledAsConstructor(), false);
QCOMPARE(ctx->argumentCount(), 0);
QCOMPARE(ctx->argument(0).isUndefined(), true);
QVERIFY(!ctx->argument(-1).isValid());
QCOMPARE(ctx->argumentsObject().isObject(), true);
QCOMPARE(ctx->activationObject().isObject(), true);
QCOMPARE(ctx->callee().isValid(), false);
QCOMPARE(ctx->thisObject().strictlyEquals(eng.globalObject()), true);
QCOMPARE(ctx->scopeChain().size(), 2);
QVERIFY(ctx->scopeChain().at(0).equals(ctx->activationObject()));
QVERIFY(ctx->scopeChain().at(1).equals(eng.globalObject()));
QScriptContext *ctx2 = eng.pushContext();
QCOMPARE(ctx2->parentContext(), ctx);
QCOMPARE(eng.currentContext(), ctx2);
eng.popContext();
QCOMPARE(eng.currentContext(), ctx);
eng.popContext();
QCOMPARE(eng.currentContext(), topLevel);
// popping the top-level context is not allowed
QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::popContext() doesn't match with pushContext()");
eng.popContext();
QCOMPARE(eng.currentContext(), topLevel);
{
QScriptContext *ctx3 = eng.pushContext();
ctx3->activationObject().setProperty("foo", QScriptValue(&eng, 123));
QVERIFY(eng.evaluate("foo").strictlyEquals(QScriptValue(&eng, 123)));
eng.evaluate("var bar = 'ciao'");
QVERIFY(ctx3->activationObject().property("bar", QScriptValue::ResolveLocal).strictlyEquals(QScriptValue(&eng, "ciao")));
eng.popContext();
}
{
QScriptContext *ctx4 = eng.pushContext();
QScriptValue obj = eng.newObject();
obj.setProperty("prop", QScriptValue(&eng, 456));
ctx4->setThisObject(obj);
QScriptValue ret = eng.evaluate("var tmp = this.prop; tmp + 1");
QCOMPARE(eng.currentContext(), ctx4);
QVERIFY(ret.strictlyEquals(QScriptValue(&eng, 457)));
eng.popContext();
}
// throwing an exception
{
QScriptContext *ctx5 = eng.pushContext();
QScriptValue ret = eng.evaluate("throw new Error('oops')");
QVERIFY(ret.isError());
QVERIFY(eng.hasUncaughtException());
QCOMPARE(eng.currentContext(), ctx5);
eng.popContext();
}
}
示例3: 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));
}
//.........这里部分代码省略.........
示例4: getAndSetProperty
void tst_QScriptClass::getAndSetProperty()
{
QScriptEngine eng;
TestClass cls(&eng);
QScriptValue obj1 = eng.newObject(&cls);
QScriptValue obj2 = eng.newObject(&cls);
QScriptString foo = eng.toStringHandle("foo");
QScriptString bar = eng.toStringHandle("bar");
QScriptValue num(&eng, 123);
// should behave just like normal
for (int x = 0; x < 2; ++x) {
QScriptValue &o = (x == 0) ? obj1 : obj2;
for (int y = 0; y < 2; ++y) {
QScriptString &s = (y == 0) ? foo : bar;
// read property
cls.clearReceivedArgs();
QScriptValue ret = o.property(s);
QVERIFY(!ret.isValid());
QVERIFY(cls.lastQueryPropertyObject().strictlyEquals(o));
QVERIFY(cls.lastQueryPropertyName() == s);
QVERIFY(!cls.lastPropertyObject().isValid());
QVERIFY(!cls.lastSetPropertyObject().isValid());
QVERIFY(cls.lastQueryPropertyFlags() == QScriptClass::HandlesReadAccess);
// write property
cls.clearReceivedArgs();
o.setProperty(s, num);
QVERIFY(cls.lastQueryPropertyObject().strictlyEquals(o));
QVERIFY(cls.lastQueryPropertyName() == s);
QVERIFY(!cls.lastPropertyObject().isValid());
QVERIFY(!cls.lastSetPropertyObject().isValid());
QVERIFY(cls.lastQueryPropertyFlags() == QScriptClass::HandlesWriteAccess);
// re-read property
// When a QScriptClass doesn't want to handle a property write,
// that property becomes a normal property and the QScriptClass
// shall not be queried about it again.
cls.clearReceivedArgs();
QVERIFY(o.property(s).strictlyEquals(num));
QVERIFY(!cls.lastQueryPropertyObject().isValid());
}
}
// add a custom property
QScriptString foo2 = eng.toStringHandle("foo2");
const uint foo2Id = 123;
const QScriptValue::PropertyFlags foo2Pflags = QScriptValue::Undeletable;
QScriptValue foo2Value(&eng, 456);
cls.addCustomProperty(foo2, QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess,
foo2Id, foo2Pflags, foo2Value);
{
// read property
cls.clearReceivedArgs();
{
QScriptValue ret = obj1.property(foo2);
QVERIFY(ret.strictlyEquals(foo2Value));
}
QVERIFY(cls.lastQueryPropertyObject().strictlyEquals(obj1));
QVERIFY(cls.lastQueryPropertyName() == foo2);
QVERIFY(cls.lastPropertyObject().strictlyEquals(obj1));
QVERIFY(cls.lastPropertyName() == foo2);
QCOMPARE(cls.lastPropertyId(), foo2Id);
// read flags
cls.clearReceivedArgs();
QCOMPARE(obj1.propertyFlags(foo2), foo2Pflags);
QVERIFY(cls.lastQueryPropertyObject().strictlyEquals(obj1));
QVERIFY(cls.lastQueryPropertyName() == foo2);
QEXPECT_FAIL("", "classObject.getOwnPropertyDescriptor() reads the property value", Continue);
QVERIFY(!cls.lastPropertyObject().isValid());
QVERIFY(cls.lastPropertyFlagsObject().strictlyEquals(obj1));
QVERIFY(cls.lastPropertyFlagsName() == foo2);
QCOMPARE(cls.lastPropertyFlagsId(), foo2Id);
// write property
cls.clearReceivedArgs();
QScriptValue newFoo2Value(&eng, 789);
obj1.setProperty(foo2, newFoo2Value);
QVERIFY(cls.lastQueryPropertyObject().strictlyEquals(obj1));
QVERIFY(cls.lastQueryPropertyName() == foo2);
// read property again
cls.clearReceivedArgs();
{
QScriptValue ret = obj1.property(foo2);
QVERIFY(ret.strictlyEquals(newFoo2Value));
}
QVERIFY(cls.lastQueryPropertyObject().strictlyEquals(obj1));
QVERIFY(cls.lastQueryPropertyName() == foo2);
QVERIFY(cls.lastPropertyObject().strictlyEquals(obj1));
QVERIFY(cls.lastPropertyName() == foo2);
QCOMPARE(cls.lastPropertyId(), foo2Id);
}
// remove script class; normal properties should remain
//.........这里部分代码省略.........
示例5:
/**
An unfortunate kludge, this is used by QList<QScriptValue>::find().
We could use std::set<QScriptValue,CustomLessFtor>, but we have no
sensible way to perform < on QScriptValue objects.
*/
bool operator==(QScriptValue const & lhs, QScriptValue const & rhs)
{
return lhs.strictlyEquals(rhs);
}