diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-30 08:44:15 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-30 08:48:45 (GMT) |
commit | 776c4a5b8035b87d011b8e431c3d9e970ad98cd9 (patch) | |
tree | 1407bc256a512722e40fcb0b940c3880eb503e62 /examples/script/customclass/main.cpp | |
parent | d2820e3a67812d31f45df282b378a75511bb1c4b (diff) | |
download | Qt-776c4a5b8035b87d011b8e431c3d9e970ad98cd9.zip Qt-776c4a5b8035b87d011b8e431c3d9e970ad98cd9.tar.gz Qt-776c4a5b8035b87d011b8e431c3d9e970ad98cd9.tar.bz2 |
fix two bugs in the custom script class example
1) fromScriptValue() needs to call qvariant_cast() on the data, in
order to be symmetric with toScriptValue().
2) use the overload of newFunction() that takes a prototype object,
so that the prototype.constructor and constructor.prototype
relationship is set up correctly; otherwise the instanceof operator
won't work.
Diffstat (limited to 'examples/script/customclass/main.cpp')
-rw-r--r-- | examples/script/customclass/main.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/examples/script/customclass/main.cpp b/examples/script/customclass/main.cpp index 05aefd5..3b98f5c 100644 --- a/examples/script/customclass/main.cpp +++ b/examples/script/customclass/main.cpp @@ -52,6 +52,7 @@ int main(int argc, char **argv) eng.globalObject().setProperty("ByteArray", baClass->constructor()); qDebug() << "ba = new ByteArray(4):" << eng.evaluate("ba = new ByteArray(4)").toString(); + qDebug() << "ba instanceof ByteArray:" << eng.evaluate("ba instanceof ByteArray").toBool(); qDebug() << "ba.length:" << eng.evaluate("ba.length").toNumber(); qDebug() << "ba[1] = 123; ba[1]:" << eng.evaluate("ba[1] = 123; ba[1]").toNumber(); qDebug() << "ba[7] = 224; ba.length:" << eng.evaluate("ba[7] = 224; ba.length").toNumber(); @@ -65,6 +66,9 @@ int main(int argc, char **argv) qDebug() << "ba.toBase64().toLatin1String():" << eng.evaluate("b64.toLatin1String()").toString(); qDebug() << "ba.valueOf():" << eng.evaluate("ba.valueOf()").toString(); qDebug() << "ba.chop(2); ba.length:" << eng.evaluate("ba.chop(2); ba.length").toNumber(); + qDebug() << "ba2 = new ByteArray(ba):" << eng.evaluate("ba2 = new ByteArray(ba)").toString(); + qDebug() << "ba2.equals(ba):" << eng.evaluate("ba2.equals(ba)").toBool(); + qDebug() << "ba2.equals(new ByteArray()):" << eng.evaluate("ba2.equals(new ByteArray())").toBool(); return 0; } |