History

script_engine: assert the ScriptEngineV8 is called in the same thread

RTUnreal committed 8 months ago

Commit 00e681b1 parent 3a6d77a1 file · +5 −64Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8.cpp+5−64
@@ -334,15 +334,7 @@ void ScriptEngineV8::registerEnum(ScriptEngineScopeGuard* scopeGuard, const QStr · 333 unmodified lines
334334
335335 void ScriptEngineV8::registerValue(ScriptEngineScopeGuardV8* scopeGuard, const QString& valueName, V8ScriptValue value) {
336336 Q_ASSERT(scopeGuard);
337− if (QThread::currentThread() != thread()) {
338−#ifdef THREAD_DEBUGGING
339− qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";
340−#endif
341− QMetaObject::invokeMethod(this, "registerValue",
342− Q_ARG(const QString&, valueName),
343− Q_ARG(V8ScriptValue, value));
344− return;
345− }
337+ Q_ASSERT(QThread::currentThread() == thread());
346338 Q_ASSERT(_v8Isolate->IsCurrent());
347339 v8::HandleScope handleScope(_v8Isolate);
348340 v8::Local<v8::Context> context = getContext();
@@ -392,18 +384,7 @@ void ScriptEngineV8::registerValue(ScriptEngineScopeGuardV8* scopeGuard, const Q · 43 unmodified lines
392384
393385 void ScriptEngineV8::registerGlobalObject(ScriptEngineScopeGuard* scopeGuard, const QString& name, QObject* object, ScriptEngine::ValueOwnership) {
394386 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
395− if (QThread::currentThread() != thread()) {
396−#ifdef THREAD_DEBUGGING
397− qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerGlobalObject() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
398−#endif
399− QMetaObject::invokeMethod(this, "registerGlobalObject",
400− Q_ARG(const QString&, name),
401− Q_ARG(QObject*, object));
402− return;
403− }
404−#ifdef THREAD_DEBUGGING
405− qCDebug(scriptengine_v8) << "ScriptEngineV8::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name;
406−#endif
387+ Q_ASSERT(QThread::currentThread() == thread());
407388 Q_ASSERT(_v8Isolate->IsCurrent());
408389 v8::HandleScope handleScope(_v8Isolate);
409390 Q_ASSERT(_v8Isolate->IsCurrent());
@@ -428,20 +409,7 @@ void ScriptEngineV8::registerGlobalObject(ScriptEngineScopeGuard* scopeGuard, co · 18 unmodified lines
428409
429410 void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {
430411 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
431− if (QThread::currentThread() != thread()) {
432−#ifdef THREAD_DEBUGGING
433− qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
434−#endif
435− QMetaObject::invokeMethod(this, "registerFunction",
436− Q_ARG(const QString&, name),
437− Q_ARG(ScriptEngine::FunctionSignature, functionSignature),
438− Q_ARG(int, numArguments));
439− return;
440− }
441−#ifdef THREAD_DEBUGGING
442− qCDebug(scriptengine_v8) << "ScriptEngineV8::registerFunction() called on thread [" << QThread::currentThread() << "] name:" << name;
443−#endif
444−
412+ Q_ASSERT(QThread::currentThread() == thread());
445413 Q_ASSERT(_v8Isolate->IsCurrent());
446414 v8::HandleScope handleScope(_v8Isolate);
447415 v8::Context::Scope contextScope(getContext());
@@ -452,20 +420,7 @@ void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const · 4 unmodified lines
452420
453421 void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const QString& parent, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {
454422 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
455− if (QThread::currentThread() != thread()) {
456−#ifdef THREAD_DEBUGGING
457− qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] parent:" << parent << "name:" << name;
458−#endif
459− QMetaObject::invokeMethod(this, "registerFunction",
460− Q_ARG(const QString&, name),
461− Q_ARG(ScriptEngine::FunctionSignature, functionSignature),
462− Q_ARG(int, numArguments));
463− return;
464− }
465−#ifdef THREAD_DEBUGGING
466− qCDebug(scriptengine_v8) << "ScriptEngineV8::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name;
467−#endif
468−
423+ Q_ASSERT(QThread::currentThread() == thread());
469424 Q_ASSERT(_v8Isolate->IsCurrent());
470425 v8::HandleScope handleScope(_v8Isolate);
471426 v8::Context::Scope contextScope(getContext());
@@ -479,21 +434,7 @@ void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const · 7 unmodified lines
479434 void ScriptEngineV8::registerGetterSetter(ScriptEngineScopeGuard* scopeGuard, const QString& name, ScriptEngine::FunctionSignature getter,
480435 ScriptEngine::FunctionSignature setter, const QString& parent) {
481436 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
482− if (QThread::currentThread() != thread()) {
483−#ifdef THREAD_DEBUGGING
484− qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
485− " name:" << name << "parent:" << parent;
486−#endif
487− QMetaObject::invokeMethod(this, "registerGetterSetter",
488− Q_ARG(const QString&, name),
489− Q_ARG(ScriptEngine::FunctionSignature, getter),
490− Q_ARG(ScriptEngine::FunctionSignature, setter),
491− Q_ARG(const QString&, parent));
492− return;
493− }
494−#ifdef THREAD_DEBUGGING
495− qCDebug(scriptengine_v8) << "ScriptEngineV8::registerGetterSetter() called on thread [" << QThread::currentThread() << "] name:" << name << "parent:" << parent;
496−#endif
437+ Q_ASSERT(QThread::currentThread() == thread());
497438
498439 Q_ASSERT(_v8Isolate->IsCurrent());
499440 v8::HandleScope handleScope(_v8Isolate);