mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
Functions connected to signals now use context that was active during connecting
This commit is contained in:
parent
044cd506a6
commit
3a5b927979
5 changed files with 18 additions and 7 deletions
|
@ -1122,6 +1122,7 @@ void ScriptManager::stopTimer(QTimer *timer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl ScriptManager::resolvePath(const QString& include) const {
|
QUrl ScriptManager::resolvePath(const QString& include) const {
|
||||||
|
//qDebug(scriptengine) << "ScriptManager::resolvePath: getCurrentScriptURLs: " << _engine->getCurrentScriptURLs();
|
||||||
QUrl url(include);
|
QUrl url(include);
|
||||||
// first lets check to see if it's already a full URL -- or a Windows path like "c:/"
|
// first lets check to see if it's already a full URL -- or a Windows path like "c:/"
|
||||||
if (include.startsWith("/") || url.scheme().length() == 1) {
|
if (include.startsWith("/") || url.scheme().length() == 1) {
|
||||||
|
@ -1139,7 +1140,7 @@ QUrl ScriptManager::resolvePath(const QString& include) const {
|
||||||
do {
|
do {
|
||||||
auto contextInfo = context->functionContext();
|
auto contextInfo = context->functionContext();
|
||||||
parentURL = QUrl(contextInfo->fileName());
|
parentURL = QUrl(contextInfo->fileName());
|
||||||
qDebug(scriptengine) << "ScriptManager::resolvePath: URL get: " << parentURL << " backtrace: " << context->backtrace() << " " << _engine->getCurrentScriptURLs();
|
//qDebug(scriptengine) << "ScriptManager::resolvePath: URL get: " << parentURL << " backtrace: " << context->backtrace() << " " << _engine->getCurrentScriptURLs();
|
||||||
parentContext = context->parentContext();
|
parentContext = context->parentContext();
|
||||||
context = parentContext.get();
|
context = parentContext.get();
|
||||||
} while (parentURL.isRelative() && context);
|
} while (parentURL.isRelative() && context);
|
||||||
|
|
|
@ -1111,7 +1111,7 @@ QString ScriptEngineV8::formatErrorMessageFromTryCatch(v8::TryCatch &tryCatch) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptContextV8Pointer ScriptEngineV8::pushContext(v8::Local<v8::Context> &context) {
|
ScriptContextV8Pointer ScriptEngineV8::pushContext(v8::Local<v8::Context> context) {
|
||||||
Q_ASSERT(!_contexts.isEmpty());
|
Q_ASSERT(!_contexts.isEmpty());
|
||||||
ScriptContextPointer parent = _contexts.last();
|
ScriptContextPointer parent = _contexts.last();
|
||||||
_contexts.append(std::make_shared<ScriptContextV8Wrapper>(this, context, ScriptContextPointer()));
|
_contexts.append(std::make_shared<ScriptContextV8Wrapper>(this, context, ScriptContextPointer()));
|
||||||
|
|
|
@ -199,7 +199,7 @@ public: // not for public use, but I don't like how Qt strings this along with p
|
||||||
// V8TODO add a V8 callback that removes pointer from the map so that it gets deleted
|
// V8TODO add a V8 callback that removes pointer from the map so that it gets deleted
|
||||||
QMap<QObject*, QSharedPointer<ScriptObjectV8Proxy>> _qobjectWrapperMapV8;
|
QMap<QObject*, QSharedPointer<ScriptObjectV8Proxy>> _qobjectWrapperMapV8;
|
||||||
|
|
||||||
ScriptContextV8Pointer pushContext(v8::Local<v8::Context> &context);
|
ScriptContextV8Pointer pushContext(v8::Local<v8::Context> context);
|
||||||
void popContext();
|
void popContext();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1094,9 +1094,11 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
|
||||||
Q_ASSERT(conn.callback.get()->IsFunction());
|
Q_ASSERT(conn.callback.get()->IsFunction());
|
||||||
{
|
{
|
||||||
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
|
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
|
||||||
auto functionContext = callback->CreationContext();
|
//auto functionContext = callback->CreationContext();
|
||||||
_engine->pushContext(functionContext);
|
//_engine->pushContext(functionContext);
|
||||||
v8::Context::Scope functionContextScope(functionContext);
|
_engine->pushContext(_v8Context.Get(_engine->getIsolate()));
|
||||||
|
//v8::Context::Scope functionContextScope(functionContext);
|
||||||
|
v8::Context::Scope functionContextScope(_v8Context.Get(_engine->getIsolate()));
|
||||||
v8::Local<v8::Value> v8This;
|
v8::Local<v8::Value> v8This;
|
||||||
if (conn.thisValue.get()->IsObject()) {
|
if (conn.thisValue.get()->IsObject()) {
|
||||||
v8This = conn.thisValue.get();
|
v8This = conn.thisValue.get();
|
||||||
|
|
|
@ -221,7 +221,13 @@ private: // storage
|
||||||
|
|
||||||
public: // construction
|
public: // construction
|
||||||
inline ScriptSignalV8Proxy(ScriptEngineV8* engine, QObject* object, V8ScriptValue lifetime, const QMetaMethod& meta) :
|
inline ScriptSignalV8Proxy(ScriptEngineV8* engine, QObject* object, V8ScriptValue lifetime, const QMetaMethod& meta) :
|
||||||
_engine(engine), _object(object), _objectLifetime(lifetime), _meta(meta), _metaCallId(discoverMetaCallIdx()) {}
|
_engine(engine), _object(object), _objectLifetime(lifetime), _meta(meta), _metaCallId(discoverMetaCallIdx()) {
|
||||||
|
v8::Locker locker(_engine->getIsolate());
|
||||||
|
v8::Isolate::Scope isolateScope(_engine->getIsolate());
|
||||||
|
v8::HandleScope handleScope(_engine->getIsolate());
|
||||||
|
v8::Context::Scope contextScope(_engine->getContext());
|
||||||
|
_v8Context.Reset(_engine->getIsolate(), _engine->getContext());
|
||||||
|
}
|
||||||
|
|
||||||
private: // implementation
|
private: // implementation
|
||||||
virtual int qt_metacall(QMetaObject::Call call, int id, void** arguments) override;
|
virtual int qt_metacall(QMetaObject::Call call, int id, void** arguments) override;
|
||||||
|
@ -245,6 +251,8 @@ private: // storage
|
||||||
const int _metaCallId;
|
const int _metaCallId;
|
||||||
ConnectionList _connections;
|
ConnectionList _connections;
|
||||||
bool _isConnected{ false };
|
bool _isConnected{ false };
|
||||||
|
// Context in which it was created
|
||||||
|
v8::UniquePersistent<v8::Context> _v8Context;
|
||||||
|
|
||||||
Q_DISABLE_COPY(ScriptSignalV8Proxy)
|
Q_DISABLE_COPY(ScriptSignalV8Proxy)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue