mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 01:24:36 +02:00
Capture exceptions that happen in signals in ScriptEngine, add test
This commit is contained in:
parent
6a189d33af
commit
f2e5f13f1d
4 changed files with 45 additions and 9 deletions
|
@ -225,6 +225,8 @@ protected:
|
||||||
void setUncaughtException(const v8::TryCatch &tryCatch, const QString& info = QString());
|
void setUncaughtException(const v8::TryCatch &tryCatch, const QString& info = QString());
|
||||||
void setUncaughtException(std::shared_ptr<ScriptException> exception);
|
void setUncaughtException(std::shared_ptr<ScriptException> exception);
|
||||||
|
|
||||||
|
friend class ScriptSignalV8Proxy;
|
||||||
|
|
||||||
std::shared_ptr<ScriptException> _uncaughtException;
|
std::shared_ptr<ScriptException> _uncaughtException;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o
|
||||||
//if (proxy) return engine->newObject(proxy.get(), engine->newVariant(QVariant::fromValue(proxy)));;
|
//if (proxy) return engine->newObject(proxy.get(), engine->newVariant(QVariant::fromValue(proxy)));;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ownsObject;
|
bool ownsObject;
|
||||||
switch (ownership) {
|
switch (ownership) {
|
||||||
case ScriptEngine::QtOwnership:
|
case ScriptEngine::QtOwnership:
|
||||||
|
@ -243,12 +243,12 @@ void ScriptObjectV8Proxy::investigate() {
|
||||||
v8::Isolate::Scope isolateScope(isolate);
|
v8::Isolate::Scope isolateScope(isolate);
|
||||||
v8::HandleScope handleScope(_engine->getIsolate());
|
v8::HandleScope handleScope(_engine->getIsolate());
|
||||||
v8::Context::Scope contextScope(_engine->getContext());
|
v8::Context::Scope contextScope(_engine->getContext());
|
||||||
|
|
||||||
//auto objectTemplate = _v8ObjectTemplate.Get(_engine->getIsolate());
|
//auto objectTemplate = _v8ObjectTemplate.Get(_engine->getIsolate());
|
||||||
auto objectTemplate = v8::ObjectTemplate::New(_engine->getIsolate());
|
auto objectTemplate = v8::ObjectTemplate::New(_engine->getIsolate());
|
||||||
objectTemplate->SetInternalFieldCount(3);
|
objectTemplate->SetInternalFieldCount(3);
|
||||||
objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set, nullptr, nullptr, v8GetPropertyNames));
|
objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set, nullptr, nullptr, v8GetPropertyNames));
|
||||||
|
|
||||||
const QMetaObject* metaObject = qobject->metaObject();
|
const QMetaObject* metaObject = qobject->metaObject();
|
||||||
|
|
||||||
//qDebug(scriptengine) << "Investigate: " << metaObject->className();
|
//qDebug(scriptengine) << "Investigate: " << metaObject->className();
|
||||||
|
@ -286,7 +286,7 @@ void ScriptObjectV8Proxy::investigate() {
|
||||||
for (int idx = startIdx; idx < num; ++idx) {
|
for (int idx = startIdx; idx < num; ++idx) {
|
||||||
QMetaMethod method = metaObject->method(idx);
|
QMetaMethod method = metaObject->method(idx);
|
||||||
//qDebug(scriptengine) << "Investigate: " << metaObject->className() << " Method: " << method.name();
|
//qDebug(scriptengine) << "Investigate: " << metaObject->className() << " Method: " << method.name();
|
||||||
|
|
||||||
// perhaps keep this comment? Calls (like AudioScriptingInterface::playSound) seem to expect non-public methods to be script-accessible
|
// perhaps keep this comment? Calls (like AudioScriptingInterface::playSound) seem to expect non-public methods to be script-accessible
|
||||||
/* if (method.access() != QMetaMethod::Public) continue;*/
|
/* if (method.access() != QMetaMethod::Public) continue;*/
|
||||||
|
|
||||||
|
@ -1011,12 +1011,12 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume
|
||||||
isolate->ThrowError("Referencing deleted native object");
|
isolate->ThrowError("Referencing deleted native object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//v8::HandleScope handleScope(_engine->getIsolate());
|
//v8::HandleScope handleScope(_engine->getIsolate());
|
||||||
|
|
||||||
int scriptNumArgs = arguments.Length();
|
int scriptNumArgs = arguments.Length();
|
||||||
int numArgs = std::min(scriptNumArgs, _numMaxParams);
|
int numArgs = std::min(scriptNumArgs, _numMaxParams);
|
||||||
|
|
||||||
const int scriptValueTypeId = qMetaTypeId<ScriptValue>();
|
const int scriptValueTypeId = qMetaTypeId<ScriptValue>();
|
||||||
|
|
||||||
int parameterConversionFailureId = 0;
|
int parameterConversionFailureId = 0;
|
||||||
|
@ -1202,7 +1202,7 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume
|
||||||
|
|
||||||
int scriptNumArgs = context->argumentCount();
|
int scriptNumArgs = context->argumentCount();
|
||||||
int numArgs = std::min(scriptNumArgs, _numMaxParams);
|
int numArgs = std::min(scriptNumArgs, _numMaxParams);
|
||||||
|
|
||||||
const int scriptValueTypeId = qMetaTypeId<ScriptValue>();
|
const int scriptValueTypeId = qMetaTypeId<ScriptValue>();
|
||||||
|
|
||||||
int parameterConversionFailureId = 0;
|
int parameterConversionFailureId = 0;
|
||||||
|
@ -1474,6 +1474,8 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
|
||||||
qCDebug(scriptengine) << "Signal proxy " << fullName() << " connection call failed: \""
|
qCDebug(scriptengine) << "Signal proxy " << fullName() << " connection call failed: \""
|
||||||
<< _engine->formatErrorMessageFromTryCatch(tryCatch)
|
<< _engine->formatErrorMessageFromTryCatch(tryCatch)
|
||||||
<< "\nThis provided: " << conn.thisValue.get()->IsObject();
|
<< "\nThis provided: " << conn.thisValue.get()->IsObject();
|
||||||
|
|
||||||
|
_engine->setUncaughtException(tryCatch, "Error in signal proxy");
|
||||||
}
|
}
|
||||||
//_engine->popContext();
|
//_engine->popContext();
|
||||||
}
|
}
|
||||||
|
@ -1524,7 +1526,7 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) {
|
||||||
isolate->ThrowError("Referencing deleted native object");
|
isolate->ThrowError("Referencing deleted native object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//v8::HandleScope handleScope(isolate);
|
//v8::HandleScope handleScope(isolate);
|
||||||
|
|
||||||
// untangle the arguments
|
// untangle the arguments
|
||||||
|
@ -1630,7 +1632,7 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) {
|
||||||
Connection newConnection(callbackThis, callback);
|
Connection newConnection(callbackThis, callback);
|
||||||
//newConn.callback = callback;
|
//newConn.callback = callback;
|
||||||
//newConn.thisValue = callbackThis;
|
//newConn.thisValue = callbackThis;
|
||||||
|
|
||||||
withWriteLock([&]{
|
withWriteLock([&]{
|
||||||
_connections.append(newConnection);
|
_connections.append(newConnection);
|
||||||
});
|
});
|
||||||
|
|
|
@ -271,6 +271,37 @@ void ScriptEngineTests::testSignal() {
|
||||||
QVERIFY(printed.length() >= 10);
|
QVERIFY(printed.length() >= 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEngineTests::testSignalWithException() {
|
||||||
|
QString script =
|
||||||
|
"var count = 0;"
|
||||||
|
"Script.update.connect(function(deltaTime) {"
|
||||||
|
" count++;"
|
||||||
|
" print(deltaTime);"
|
||||||
|
" if (count >= 3) {"
|
||||||
|
" Script.stop(true);"
|
||||||
|
" }"
|
||||||
|
" nonExist();"
|
||||||
|
"});";
|
||||||
|
|
||||||
|
QStringList printed;
|
||||||
|
int exceptionCount = 0;
|
||||||
|
|
||||||
|
auto sm = makeManager(script, "testSignalWithException.js");
|
||||||
|
|
||||||
|
connect(sm.get(), &ScriptManager::printedMessage, [&printed](const QString& message, const QString& engineName){
|
||||||
|
printed.append(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(sm.get(), &ScriptManager::unhandledException, [&exceptionCount](std::shared_ptr<ScriptException> exception){
|
||||||
|
exceptionCount++;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
sm->run();
|
||||||
|
QVERIFY(printed.length() >= 3);
|
||||||
|
QVERIFY(exceptionCount >= 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptEngineTests::scriptTest() {
|
void ScriptEngineTests::scriptTest() {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,6 +64,7 @@ private slots:
|
||||||
void testRaiseException();
|
void testRaiseException();
|
||||||
void testRaiseExceptionAndCatch();
|
void testRaiseExceptionAndCatch();
|
||||||
void testSignal();
|
void testSignal();
|
||||||
|
void testSignalWithException();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue