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
334 334
335void ScriptEngineV8::registerValue(ScriptEngineScopeGuardV8* scopeGuard, const QString& valueName, V8ScriptValue value) {335void ScriptEngineV8::registerValue(ScriptEngineScopeGuardV8* scopeGuard, const QString& valueName, V8ScriptValue value) {
336 Q_ASSERT(scopeGuard);336 Q_ASSERT(scopeGuard);
337 if (QThread::currentThread() != thread()) {337 Q_ASSERT(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 }
346 Q_ASSERT(_v8Isolate->IsCurrent());338 Q_ASSERT(_v8Isolate->IsCurrent());
347 v8::HandleScope handleScope(_v8Isolate);339 v8::HandleScope handleScope(_v8Isolate);
348 v8::Local<v8::Context> context = getContext();340 v8::Local<v8::Context> context = getContext();
@@ -392,18 +384,7 @@ void ScriptEngineV8::registerValue(ScriptEngineScopeGuardV8* scopeGuard, const Q · 43 unmodified lines
392 384
393void ScriptEngineV8::registerGlobalObject(ScriptEngineScopeGuard* scopeGuard, const QString& name, QObject* object, ScriptEngine::ValueOwnership) {385void ScriptEngineV8::registerGlobalObject(ScriptEngineScopeGuard* scopeGuard, const QString& name, QObject* object, ScriptEngine::ValueOwnership) {
394 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));386 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
395 if (QThread::currentThread() != thread()) {387 Q_ASSERT(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
407 Q_ASSERT(_v8Isolate->IsCurrent());388 Q_ASSERT(_v8Isolate->IsCurrent());
408 v8::HandleScope handleScope(_v8Isolate);389 v8::HandleScope handleScope(_v8Isolate);
409 Q_ASSERT(_v8Isolate->IsCurrent());390 Q_ASSERT(_v8Isolate->IsCurrent());
@@ -428,20 +409,7 @@ void ScriptEngineV8::registerGlobalObject(ScriptEngineScopeGuard* scopeGuard, co · 18 unmodified lines
428 409
429void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {410void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {
430 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));411 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
431 if (QThread::currentThread() != thread()) {412 Q_ASSERT(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
445 Q_ASSERT(_v8Isolate->IsCurrent());413 Q_ASSERT(_v8Isolate->IsCurrent());
446 v8::HandleScope handleScope(_v8Isolate);414 v8::HandleScope handleScope(_v8Isolate);
447 v8::Context::Scope contextScope(getContext());415 v8::Context::Scope contextScope(getContext());
@@ -452,20 +420,7 @@ void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const · 4 unmodified lines
452 420
453void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const QString& parent, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {421void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const QString& parent, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {
454 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));422 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
455 if (QThread::currentThread() != thread()) {423 Q_ASSERT(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
469 Q_ASSERT(_v8Isolate->IsCurrent());424 Q_ASSERT(_v8Isolate->IsCurrent());
470 v8::HandleScope handleScope(_v8Isolate);425 v8::HandleScope handleScope(_v8Isolate);
471 v8::Context::Scope contextScope(getContext());426 v8::Context::Scope contextScope(getContext());
@@ -479,21 +434,7 @@ void ScriptEngineV8::registerFunction(ScriptEngineScopeGuard* scopeGuard, const · 7 unmodified lines
479void ScriptEngineV8::registerGetterSetter(ScriptEngineScopeGuard* scopeGuard, const QString& name, ScriptEngine::FunctionSignature getter,434void ScriptEngineV8::registerGetterSetter(ScriptEngineScopeGuard* scopeGuard, const QString& name, ScriptEngine::FunctionSignature getter,
480 ScriptEngine::FunctionSignature setter, const QString& parent) {435 ScriptEngine::FunctionSignature setter, const QString& parent) {
481 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));436 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
482 if (QThread::currentThread() != thread()) {437 Q_ASSERT(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
497 438
498 Q_ASSERT(_v8Isolate->IsCurrent());439 Q_ASSERT(_v8Isolate->IsCurrent());
499 v8::HandleScope handleScope(_v8Isolate);440 v8::HandleScope handleScope(_v8Isolate);