History

Added more debug info to crash with signals

ksuprynowicz committed 3 years ago

Commit b786ffc1 parent 3e692a62 files · +45 −29Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp+39−29
@@ -673,7 +673,7 @@ void ScriptMethodV8Proxy::callback(const v8::FunctionCallbackInfo<v8::Value>& ar · 672 unmodified lines
673673 v8::Locker locker(arguments.GetIsolate());
674674 v8::Isolate::Scope isolateScope(arguments.GetIsolate());
675675 v8::HandleScope handleScope(arguments.GetIsolate());
676− Q_ASSERT(!arguments.GetIsolate()->GetCurrentContext().IsEmpty());
676+ //Q_ASSERT(!arguments.GetIsolate()->GetCurrentContext().IsEmpty());
677677 v8::Context::Scope contextScope(arguments.GetIsolate()->GetCurrentContext());
678678 if (!arguments.Data()->IsObject()) {
679679 arguments.GetIsolate()->ThrowError("Method value is not an object");
@@ -1082,40 +1082,50 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu · 402 unmodified lines
10821082 args[arg] = _engine->castVariantToValue(argValue).get();
10831083 }
10841084
1085− QList<Connection> connections;
1085+ /*QList<Connection> connections;
10861086 withReadLock([&]{
10871087 connections = _connections;
1088− });
1088+ });*/
10891089
1090− for (ConnectionList::iterator iter = connections.begin(); iter != connections.end(); ++iter) {
1091− Connection& conn = *iter;
1092− Q_ASSERT(!conn.callback.get().IsEmpty());
1093− Q_ASSERT(!conn.callback.get()->IsUndefined());
1094− Q_ASSERT(conn.callback.get()->IsFunction());
1095− {
1096− v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
1097− //auto functionContext = callback->CreationContext();
1098− auto functionContext = _v8Context.Get(_engine->getIsolate());
1099− _engine->pushContext(functionContext);
1100− v8::Context::Scope functionContextScope(functionContext);
1101−
1102− v8::Local<v8::Value> v8This;
1103− if (conn.thisValue.get()->IsObject()) {
1104− v8This = conn.thisValue.get();
1105− } else {
1106− v8This = functionContext->Global();
1107− }
1090+ withReadLock([&]{
1091+ //for (ConnectionList::iterator iter = connections.begin(); iter != connections.end(); ++iter) {
1092+ for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) {
1093+ Connection& conn = *iter;
1094+ {
1095+ //auto functionContext = callback->CreationContext();
1096+ auto functionContext = _v8Context.Get(_engine->getIsolate());
1097+ _engine->pushContext(functionContext);
1098+ v8::Context::Scope functionContextScope(functionContext);
1099+
1100+ Q_ASSERT(!conn.callback.get().IsEmpty());
1101+ Q_ASSERT(!conn.callback.get()->IsUndefined());
1102+ Q_ASSERT(!conn.callback.get()->IsNull());
1103+ if (!conn.callback.get()->IsFunction()) {
1104+ auto stringV8 = conn.callback.get()->ToDetailString(functionContext).ToLocalChecked();
1105+ QString error = *v8::String::Utf8Value(_engine->getIsolate(), stringV8);
1106+ qDebug() << error;
1107+ Q_ASSERT(false);
1108+ }
1109+ v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
11081110
1109− v8::TryCatch tryCatch(isolate);
1110− callback->Call(functionContext, v8This, numArgs, args);
1111− if (tryCatch.HasCaught()) {
1112− qCDebug(scriptengine) << "Signal proxy " << fullName() << " connection call failed: \""
1113− << _engine->formatErrorMessageFromTryCatch(tryCatch)
1114− << "\nThis provided: " << conn.thisValue.get()->IsObject();
1111+ v8::Local<v8::Value> v8This;
1112+ if (conn.thisValue.get()->IsObject()) {
1113+ v8This = conn.thisValue.get();
1114+ } else {
1115+ v8This = functionContext->Global();
1116+ }
1117+
1118+ v8::TryCatch tryCatch(isolate);
1119+ callback->Call(functionContext, v8This, numArgs, args);
1120+ if (tryCatch.HasCaught()) {
1121+ qCDebug(scriptengine) << "Signal proxy " << fullName() << " connection call failed: \""
1122+ << _engine->formatErrorMessageFromTryCatch(tryCatch)
1123+ << "\nThis provided: " << conn.thisValue.get()->IsObject();
1124+ }
1125+ _engine->popContext();
11151126 }
1116− _engine->popContext();
11171127 }
1118− }
1128+ });
11191129
11201130 return -1;
11211131 }