本文整理汇总了C++中QScriptEngine::hasUncaughtException方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::hasUncaughtException方法的具体用法?C++ QScriptEngine::hasUncaughtException怎么用?C++ QScriptEngine::hasUncaughtException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::hasUncaughtException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qt_metacall
int tst_Suite::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
QString name = testNames.at(_id);
QString path = testsDir.absoluteFilePath(name + ".js");
QString excludeMessage;
if (isExcludedTest(name, &excludeMessage)) {
QTest::qSkip(excludeMessage.toLatin1(), QTest::SkipAll, path.toLatin1(), -1);
} else {
QScriptEngine engine;
engine.evaluate(mjsunitContents).toString();
if (engine.hasUncaughtException()) {
QStringList bt = engine.uncaughtExceptionBacktrace();
QString err = engine.uncaughtException().toString();
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
} else {
QScriptValue fakeFail = engine.newFunction(qscript_fail);
fakeFail.setData(engine.globalObject().property("fail"));
engine.globalObject().setProperty("fail", fakeFail);
QString contents = readFile(path);
QScriptValue ret = engine.evaluate(contents);
if (engine.hasUncaughtException()) {
if (!ret.isError()) {
Q_ASSERT(ret.instanceOf(engine.globalObject().property("MjsUnitAssertionError")));
QString actual = ret.property("actual").toString();
QString expected = ret.property("expected").toString();
int lineNumber = ret.property("lineNumber").toInt32();
QString failMessage;
if (isExpectedFailure(name, actual, expected, &failMessage)) {
QTest::qExpectFail("", failMessage.toLatin1(),
QTest::Continue, path.toLatin1(),
lineNumber);
}
#ifdef GENERATE_ADDEXPECTEDFAILURE_CODE
else {
generatedAddExpectedFailureCode.append(
" addExpectedFailure(\"" + name
+ "\", \"" + actual + "\", \"" + expected
+ "\", willFixInNextReleaseMessage);\n");
}
#endif
QTest::qCompare(actual, expected, "actual", "expect",
path.toLatin1(), lineNumber);
} else {
int lineNumber = ret.property("lineNumber").toInt32();
QTest::qExpectFail("", ret.toString().toLatin1(),
QTest::Continue, path.toLatin1(), lineNumber);
QTest::qVerify(false, ret.toString().toLatin1(), "", path.toLatin1(), lineNumber);
}
}
}
}
_id -= testNames.size();
}
return _id;
}
示例2: main
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
if ( argc < 3 )
{
qDebug("not enough arguments");
return 1;
}
QFile f(argv[1]);
if ( !f.open(QFile::ReadOnly | QFile::Text) )
{
qDebug("Unable to open assembler script file.");
return 1;
}
QScriptEngine engine;
QScriptValue v = engine.evaluate(QString::fromLocal8Bit(f.readAll()), f.fileName(), 1);
if ( engine.hasUncaughtException() )
{
qDebug("Uncaught exception while loading assembler script at line %i: %s",
engine.uncaughtExceptionLineNumber(),
qPrintable(engine.uncaughtException().toString())
);
return 2;
}
f.close();
f.setFileName(argv[2]);
if ( !f.open(QFile::ReadOnly | QFile::Text) )
{
qDebug("Unable to open source file.");
return 1;
}
engine.globalObject().setProperty("source", engine.newVariant(QString::fromLocal8Bit(f.readAll())));
engine.globalObject().setProperty("reloc", engine.newVariant(argc > 3 ? QString::fromLocal8Bit(argv[3]) : "0x0000"));
QScriptValue r = engine.evaluate("assemble(source, reloc)");
if ( engine.hasUncaughtException() )
{
qDebug("Uncaught exception while assembling file at line %i: %s",
engine.uncaughtExceptionLineNumber(),
qPrintable(engine.uncaughtException().toString())
);
return 3;
}
qDebug("%s", qPrintable(r.toString()));
return 0;
}
示例3: qWarning
void tst_QScriptV8TestSuite::runTestFunction(int testIndex)
{
QString name = testNames.at(testIndex);
QString path = testsDir.absoluteFilePath(name + ".js");
QString excludeMessage;
if (isExcludedTest(name, &excludeMessage)) {
QTest::qSkip(excludeMessage.toLatin1(), path.toLatin1(), -1);
return;
}
QScriptEngine engine;
engine.evaluate(mjsunitContents);
if (engine.hasUncaughtException()) {
QStringList bt = engine.uncaughtExceptionBacktrace();
QString err = engine.uncaughtException().toString();
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
} else {
// Prepare to intercept calls to mjsunit's fail() function.
QScriptValue fakeFail = engine.newFunction(qscript_fail);
fakeFail.setData(engine.globalObject().property("fail"));
engine.globalObject().setProperty("fail", fakeFail);
QString contents = readFile(path);
QScriptValue ret = engine.evaluate(contents);
if (engine.hasUncaughtException()) {
if (!ret.isError()) {
int lineNumber = ret.property("lineNumber").toInt32();
QTest::qVerify(ret.instanceOf(engine.globalObject().property("MjsUnitAssertionError")),
ret.toString().toLatin1(),
"",
path.toLatin1(),
lineNumber);
QString actual = ret.property("actual").toString();
QString expected = ret.property("expected").toString();
QString failMessage;
if (shouldGenerateExpectedFailures) {
if (ret.property("message").isString())
failMessage = ret.property("message").toString();
addExpectedFailure(name, actual, expected, failMessage);
} else if (isExpectedFailure(name, actual, expected, &failMessage)) {
QTest::qExpectFail("", failMessage.toLatin1(),
QTest::Continue, path.toLatin1(),
lineNumber);
}
QTest::qCompare(actual, expected, "actual", "expect",
path.toLatin1(), lineNumber);
} else {
int lineNumber = ret.property("lineNumber").toInt32();
QTest::qExpectFail("", ret.toString().toLatin1(),
QTest::Continue, path.toLatin1(), lineNumber);
QTest::qVerify(false, ret.toString().toLatin1(), "", path.toLatin1(), lineNumber);
}
}
}
}
示例4: eval
QScriptValue QDeclarativeQtScriptExpression::eval(QObject *secondaryScope, bool *isUndefined)
{
Q_ASSERT(context() && context()->engine);
DeleteWatcher watcher(this);
QDeclarativeEngine *engine = context()->engine;
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
QDeclarativeContextData *oldSharedContext = 0;
QObject *oldSharedScope = 0;
QObject *oldOverride = 0;
bool isShared = (expressionFunctionMode == SharedContext);
if (isShared) {
oldSharedContext = ep->sharedContext;
oldSharedScope = ep->sharedScope;
ep->sharedContext = context();
ep->sharedScope = scopeObject;
} else {
oldOverride = ep->contextClass->setOverrideObject(expressionContext, secondaryScope);
}
QScriptValue thisObject;
if (evalFlags & RequiresThisObject)
thisObject = ep->objectClass->newQObject(scopeObject);
QScriptValue svalue = expressionFunction.call(thisObject); // This could cause this c++ object to be deleted
if (isShared) {
ep->sharedContext = oldSharedContext;
ep->sharedScope = oldSharedScope;
} else if (!watcher.wasDeleted()) {
ep->contextClass->setOverrideObject(expressionContext, oldOverride);
}
if (isUndefined)
*isUndefined = svalue.isUndefined() || scriptEngine->hasUncaughtException();
// Handle exception
if (scriptEngine->hasUncaughtException()) {
if (!watcher.wasDeleted())
QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
scriptEngine->clearExceptions();
return QScriptValue();
} else {
if (!watcher.wasDeleted())
error = QDeclarativeError();
return svalue;
}
}
示例5: lineNumber
void tst_QScriptContext::lineNumber()
{
QScriptEngine eng;
QScriptValue result = eng.evaluate("try { eval(\"foo = 123;\\n this[is{a{syntax|[email protected]#$%@#% \"); } catch (e) { e.lineNumber; }", "foo.qs", 123);
QVERIFY(!eng.hasUncaughtException());
QVERIFY(result.isNumber());
QCOMPARE(result.toInt32(), 2);
result = eng.evaluate("foo = 123;\n bar = 42\n0 = 0");
QVERIFY(eng.hasUncaughtException());
QCOMPARE(eng.uncaughtExceptionLineNumber(), 3);
QCOMPARE(result.property("lineNumber").toInt32(), 3);
}
示例6: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString fileName = "load.qs";
QFile scriptFile(fileName);
if (!scriptFile.open(QIODevice::ReadOnly))
{
// handle error
qDebug()<<"File open error";
}
else
{
QFileInfo info(scriptFile);
qDebug()<< "File Path" + info.absoluteFilePath();
}
QTextStream stream(&scriptFile);
QString contents = stream.readAll();
scriptFile.close();
ScriptFunctions functions;
QScriptEngine myEngine;
QScriptValue scriptFunctions = myEngine.newQObject(&functions);
myEngine.globalObject().setProperty("nativeFunctions", scriptFunctions);
myEngine.globalObject().setProperty("load", myEngine.newFunction(loadScripts, /*length=*/1));
QScriptValue result = myEngine.evaluate(contents, fileName);
if (myEngine.hasUncaughtException()) {
int line = myEngine.uncaughtExceptionLineNumber();
qDebug() << "uncaught exception at line" << line << ":" << result.toString();
}
return a.exec();
}
示例7: addObject
void addObject(QObject* object, const QString& name = QString()) {
Q_ASSERT( m_engine );
Q_ASSERT( ! m_engine->hasUncaughtException() );
QScriptValue global = m_engine->globalObject();
QScriptValue value = m_engine->newQObject(object, QScriptEngine::AutoOwnership);
global.setProperty(name.isEmpty() ? object->objectName() : name, value);
}
示例8: main
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(rtfedit);
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QScriptEngine engine;
QFile scriptFile(":/rtfedit.js");
scriptFile.open(QIODevice::ReadOnly);
engine.evaluate(QObject::tr(scriptFile.readAll()));
scriptFile.close();
RTFUiLoader loader;
QFile uiFile(":/rtfedit.ui");
uiFile.open(QIODevice::ReadOnly);
QWidget *ui = loader.load(&uiFile);
uiFile.close();
QScriptValue func = engine.evaluate("RTF");
QScriptValue scriptUi = engine.newQObject(ui);
QScriptValue table = func.construct(QScriptValueList() << scriptUi);
if(engine.hasUncaughtException()) {
QScriptValue value = engine.uncaughtException();
QString lineNumber = QString("\nLine Number:%1\n").arg(engine.uncaughtExceptionLineNumber());
QStringList btList = engine.uncaughtExceptionBacktrace();
QString trace;
for(short i=0; i<btList.size(); ++i)
trace += btList.at(i);
QMessageBox::information(NULL, QObject::tr("Exception"), value.toString() + lineNumber + trace );
}
ui->show();
return app.exec();
}
示例9: World
World *ScriptEvaluator::evaluate(const QString &script)
{
QScriptEngine engine;
World* world = new World();
QScriptValue worldValue = engine.newQObject(world);
engine.globalObject().setProperty("world", worldValue);
QScriptValue directionalLightClass = engine.scriptValueFromQMetaObject<DirectionalLight>();
engine.globalObject().setProperty("DirectionalLight", directionalLightClass);
engine.evaluate(script);
if (engine.hasUncaughtException())
{
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setWindowTitle("Script error");
messageBox.setText("An error occurred while executing the script.");
messageBox.setInformativeText(engine.uncaughtException().toString());
messageBox.setDetailedText(engine.uncaughtExceptionBacktrace().join("\n"));
messageBox.exec();
return 0;
}
return world;
}
示例10: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QScriptEngine engine;
QFile scriptFile(":/object.js");
scriptFile.open(QFile::ReadOnly);
engine.evaluate(scriptFile.readAll());
scriptFile.close();
QTextEdit editor;
QTimer timer;
QScriptValue constructor = engine.evaluate("Object");
QScriptValueList arguments;
arguments << engine.newQObject(&timer);
arguments << engine.newQObject(&editor);
QScriptValue object = constructor.construct(arguments);
if (engine.hasUncaughtException()) {
qDebug() << engine.uncaughtException().toString();
}
editor.show();
timer.start(1000);
return app.exec();
}
示例11: parseJson
QVariant JsonTranslationService::parseJson(const QByteArray &json)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QString js;
js.reserve(json.size() + 2);
js.append("(").append(QString::fromUtf8(json)).append(")");
static QScriptEngine engine;
if (!engine.canEvaluate(js)) {
m_error = tr("Couldn't parse response from the server because of an error: \"%1\"")
.arg(tr("Can't evaluate JSON data"));
return QVariant();
}
QScriptValue data = engine.evaluate(js);
if (engine.hasUncaughtException()) {
m_error = tr("Couldn't parse response from the server because of an error: \"%1\"")
.arg(engine.uncaughtException().toString());
return QVariant();
}
return data.toVariant();
#else
QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson(json, &err);
if (err.error != QJsonParseError::NoError) {
m_error = tr("Couldn't parse response from the server because of an error: \"%1\"")
.arg(err.errorString());
return QVariant();
}
return doc.toVariant();
#endif
}
示例12: init
bool init() {
if( m_script->action()->hadError() )
m_script->action()->clearError();
delete m_engine;
m_engine = new QScriptEngine();
// load the Qross QScriptExtensionPlugin plugin that provides
// us a bridge between Qross and QtScript. See here plugin.h
m_engine->importExtension("qross");
if( m_engine->hasUncaughtException() ) {
handleException();
delete m_engine;
m_engine = 0;
return false;
}
// the Qross QScriptExtensionPlugin exports the "Qross" property.
QScriptValue global = m_engine->globalObject();
m_qross = global.property("Qross");
Q_ASSERT( m_qross.isQObject() );
Q_ASSERT( ! m_engine->hasUncaughtException() );
// Attach our Qross::Action instance to be able to access it in
// scripts. Just like at the Kjs-backend we publish our own
// action as "self".
m_self = m_engine->newQObject( m_script->action() );
global.setProperty("self", m_self, QScriptValue::ReadOnly|QScriptValue::Undeletable);
{ // publish the global objects.
QHash< QString, QObject* > objects = Manager::self().objects();
QHash< QString, QObject* >::Iterator it(objects.begin()), end(objects.end());
for(; it != end; ++it)
global.setProperty(it.key(), m_engine->newQObject( it.value() ) );
}
{ // publish the local objects.
QHash< QString, QObject* > objects = m_script->action()->objects();
QHash< QString, QObject* >::Iterator it(objects.begin()), end(objects.end());
for(; it != end; ++it) {
copyEnumsToProperties( it.value() );
global.setProperty(it.key(), m_engine->newQObject( it.value() ) );
}
}
return ! m_engine->hasUncaughtException();
}
示例13: handleException
void handleException() {
Q_ASSERT( m_engine );
Q_ASSERT( m_engine->hasUncaughtException() );
const QString err = m_engine->uncaughtException().toString();
const int linenr = m_engine->uncaughtExceptionLineNumber();
const QString trace = m_engine->uncaughtExceptionBacktrace().join("\n");
qrossdebug( QString("%1, line:%2, backtrace:\n%3").arg(err).arg(linenr).arg(trace) );
m_script->action()->setError(err, trace, linenr);
m_engine->clearExceptions();
}
示例14: build
JsonValue *JsonValue::create(const QString &s, JsonMemoryPool *pool)
{
QScriptEngine engine;
QScriptValue jsonParser = engine.evaluate(QLatin1String("JSON.parse"));
QScriptValue value = jsonParser.call(QScriptValue(), QScriptValueList() << s);
if (engine.hasUncaughtException() || !value.isValid())
return 0;
return build(value.toVariant(), pool);
}
示例15: connectFunctions
void connectFunctions(ChildrenInterface* children) {
Q_ASSERT( m_engine );
Q_ASSERT( ! m_engine->hasUncaughtException() );
QString eval;
QScriptValue global = m_engine->globalObject();
QHashIterator< QString, ChildrenInterface::Options > it( children->objectOptions() );
while(it.hasNext()) {
it.next();
if( it.value() & ChildrenInterface::AutoConnectSignals ) {
QObject* sender = children->object(it.key());
if( ! sender )
continue;
QScriptValue obj = m_engine->globalObject().property(it.key());
if( ! obj.isQObject() )
continue;
const QMetaObject* mo = sender->metaObject();
const int count = mo->methodCount();
for(int i = 0; i < count; ++i) {
QMetaMethod mm = mo->method(i);
#if QT_VERSION < 0x050000
const QString signature = mm.signature();
#else
const QString signature = mm.methodSignature();
#endif
const QString name = signature.left(signature.indexOf('('));
if( mm.methodType() == QMetaMethod::Signal ) {
QScriptValue func = global.property(name);
if( ! func.isFunction() ) {
//qrossdebug( QString("EcmaScript::connectFunctions No function to connect with %1.%2").arg(it.key()).arg(name) );
continue;
}
qrossdebug( QString("EcmaScript::connectFunctions Connecting with %1.%2").arg(it.key()).arg(name) );
eval += QString("try { %1.%2.connect(%3); } catch(e) { print(e); }\n").arg(it.key()).arg(name).arg(name);
}
}
}
}
Q_ASSERT( ! m_engine->hasUncaughtException() );
if( ! eval.isNull() ) {
m_engine->evaluate(eval);
Q_ASSERT( ! m_engine->hasUncaughtException() );
}
}