History

Add V8 logging category

Rename logging category to overte Make all V8 code use logging categories

Dale Glass committed 3 years ago

Commit 0fc2ab81 parent 633319c10 files · +211 −161Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8.cpp+52−51
@@ -51,6 +51,7 @@ · 50 unmodified lines
51#include "ScriptProgramV8Wrapper.h"51#include "ScriptProgramV8Wrapper.h"
52#include "ScriptValueV8Wrapper.h"52#include "ScriptValueV8Wrapper.h"
53#include "V8Lambda.h"53#include "V8Lambda.h"
54#include "ScriptEngineLoggingV8.h"
54 55
55static const int MAX_DEBUG_VALUE_LENGTH { 80 };56static const int MAX_DEBUG_VALUE_LENGTH { 80 };
56 57
@@ -62,11 +63,11 @@ bool ScriptEngineV8::IS_THREADSAFE_INVOCATION(const QThread* thread, const QStri · 5 unmodified lines
62 if (currentThread == thread) {63 if (currentThread == thread) {
63 return true;64 return true;
64 }65 }
65 qCCritical(scriptengine) << QString("Scripting::%1 @ %2 -- ignoring thread-unsafe call from %3")66 qCCritical(scriptengine_v8) << QString("Scripting::%1 @ %2 -- ignoring thread-unsafe call from %3")
66 .arg(method)67 .arg(method)
67 .arg(thread ? thread->objectName() : "(!thread)")68 .arg(thread ? thread->objectName() : "(!thread)")
68 .arg(QThread::currentThread()->objectName());69 .arg(QThread::currentThread()->objectName());
69 qCDebug(scriptengine) << "(please resolve on the calling side by using invokeMethod, executeOnScriptThread, etc.)";70 qCDebug(scriptengine_v8) << "(please resolve on the calling side by using invokeMethod, executeOnScriptThread, etc.)";
70 Q_ASSERT(false);71 Q_ASSERT(false);
71 return false;72 return false;
72}73}
@@ -206,7 +207,7 @@ QString Lambda::toString() const { · 133 unmodified lines
206 207
207Lambda::~Lambda() {208Lambda::~Lambda() {
208#ifdef DEBUG_JS_LAMBDA_FUNCS209#ifdef DEBUG_JS_LAMBDA_FUNCS
209 qDebug() << "~Lambda"210 qCDebug(scriptengine_v8) << "~Lambda"
210 << "this" << this;211 << "this" << this;
211#endif212#endif
212}213}
@@ -217,7 +218,7 @@ Lambda::Lambda(ScriptEngineV8* engine, · 4 unmodified lines
217 _engine(engine),218 _engine(engine),
218 _operation(operation), _data(data) {219 _operation(operation), _data(data) {
219#ifdef DEBUG_JS_LAMBDA_FUNCS220#ifdef DEBUG_JS_LAMBDA_FUNCS
220 qDebug() << "Lambda" << data.toString();221 qCDebug(scriptengine_v8) << "Lambda" << data.toString();
221#endif222#endif
222}223}
223V8ScriptValue Lambda::call() {224V8ScriptValue Lambda::call() {
@@ -285,10 +286,10 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager *manager) : ScriptEngine(manager), · 61 unmodified lines
285 //v8::V8::SetFlagsFromString("--stack-size=256 --single-threaded");286 //v8::V8::SetFlagsFromString("--stack-size=256 --single-threaded");
286 v8::Platform* platform = getV8Platform();287 v8::Platform* platform = getV8Platform();
287 v8::V8::InitializePlatform(platform);288 v8::V8::InitializePlatform(platform);
288 v8::V8::Initialize(); qCDebug(scriptengine) << "V8 platform initialized";289 v8::V8::Initialize(); qCDebug(scriptengine_v8) << "V8 platform initialized";
289 } );290 } );
290 _v8InitMutex.unlock();291 _v8InitMutex.unlock();
291 qDebug() << "Creating new script engine";292 qCDebug(scriptengine_v8) << "Creating new script engine";
292 {293 {
293 v8::Isolate::CreateParams isolateParams;294 v8::Isolate::CreateParams isolateParams;
294 isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();295 isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
@@ -342,7 +343,7 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager *manager) : ScriptEngine(manager), · 47 unmodified lines
342 343
343void ScriptEngineV8::registerEnum(const QString& enumName, QMetaEnum newEnum) {344void ScriptEngineV8::registerEnum(const QString& enumName, QMetaEnum newEnum) {
344 if (!newEnum.isValid()) {345 if (!newEnum.isValid()) {
345 qCCritical(scriptengine) << "registerEnum called on invalid enum with name " << enumName;346 qCCritical(scriptengine_v8) << "registerEnum called on invalid enum with name " << enumName;
346 return;347 return;
347 }348 }
348 v8::Locker locker(_v8Isolate);349 v8::Locker locker(_v8Isolate);
@@ -360,7 +361,7 @@ void ScriptEngineV8::registerEnum(const QString& enumName, QMetaEnum newEnum) { · 11 unmodified lines
360void ScriptEngineV8::registerValue(const QString& valueName, V8ScriptValue value) {361void ScriptEngineV8::registerValue(const QString& valueName, V8ScriptValue value) {
361 if (QThread::currentThread() != thread()) {362 if (QThread::currentThread() != thread()) {
362#ifdef THREAD_DEBUGGING363#ifdef THREAD_DEBUGGING
363 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";364 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]";
364#endif365#endif
365 QMetaObject::invokeMethod(this, "registerValue",366 QMetaObject::invokeMethod(this, "registerValue",
366 Q_ARG(const QString&, valueName),367 Q_ARG(const QString&, valueName),
@@ -412,7 +413,7 @@ void ScriptEngineV8::registerValue(const QString& valueName, V8ScriptValue value · 45 unmodified lines
412 if (partsToGo > 0) {413 if (partsToGo > 0) {
413 if (!child->IsObject()) {414 if (!child->IsObject()) {
414 QString details = *v8::String::Utf8Value(_v8Isolate, child->ToDetailString(context).ToLocalChecked());415 QString details = *v8::String::Utf8Value(_v8Isolate, child->ToDetailString(context).ToLocalChecked());
415 qCDebug(scriptengine) << "ScriptEngineV8::registerValue: Part of path is not an object: " << pathPart << " details: " << details;416 qCDebug(scriptengine_v8) << "ScriptEngineV8::registerValue: Part of path is not an object: " << pathPart << " details: " << details;
416 Q_ASSERT(false);417 Q_ASSERT(false);
417 }418 }
418 partObject = v8::Local<v8::Object>::Cast(child);419 partObject = v8::Local<v8::Object>::Cast(child);
@@ -423,7 +424,7 @@ void ScriptEngineV8::registerValue(const QString& valueName, V8ScriptValue value · 4 unmodified lines
423void ScriptEngineV8::registerGlobalObject(const QString& name, QObject* object) {424void ScriptEngineV8::registerGlobalObject(const QString& name, QObject* object) {
424 if (QThread::currentThread() != thread()) {425 if (QThread::currentThread() != thread()) {
425#ifdef THREAD_DEBUGGING426#ifdef THREAD_DEBUGGING
426 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::registerGlobalObject() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;427 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerGlobalObject() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
427#endif428#endif
428 QMetaObject::invokeMethod(this, "registerGlobalObject",429 QMetaObject::invokeMethod(this, "registerGlobalObject",
429 Q_ARG(const QString&, name),430 Q_ARG(const QString&, name),
@@ -431,7 +432,7 @@ void ScriptEngineV8::registerGlobalObject(const QString& name, QObject* object) · 1 unmodified line
431 return;432 return;
432 }433 }
433#ifdef THREAD_DEBUGGING434#ifdef THREAD_DEBUGGING
434 qCDebug(scriptengine) << "ScriptEngineV8::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name;435 qCDebug(scriptengine_v8) << "ScriptEngineV8::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name;
435#endif436#endif
436 /*bool is_isolate_exit_needed = false;437 /*bool is_isolate_exit_needed = false;
437 if(!_v8Isolate->IsCurrent() && !_v8Locker) {438 if(!_v8Isolate->IsCurrent() && !_v8Locker) {
@@ -475,7 +476,7 @@ void ScriptEngineV8::registerFunction(const QString& name, ScriptEngine::Functio · 37 unmodified lines
475 //}476 //}
476 if (QThread::currentThread() != thread()) {477 if (QThread::currentThread() != thread()) {
477#ifdef THREAD_DEBUGGING478#ifdef THREAD_DEBUGGING
478 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;479 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name;
479#endif480#endif
480 QMetaObject::invokeMethod(this, "registerFunction",481 QMetaObject::invokeMethod(this, "registerFunction",
481 Q_ARG(const QString&, name),482 Q_ARG(const QString&, name),
@@ -484,7 +485,7 @@ void ScriptEngineV8::registerFunction(const QString& name, ScriptEngine::Functio · 2 unmodified lines
484 return;485 return;
485 }486 }
486#ifdef THREAD_DEBUGGING487#ifdef THREAD_DEBUGGING
487 qCDebug(scriptengine) << "ScriptEngineV8::registerFunction() called on thread [" << QThread::currentThread() << "] name:" << name;488 qCDebug(scriptengine_v8) << "ScriptEngineV8::registerFunction() called on thread [" << QThread::currentThread() << "] name:" << name;
488#endif489#endif
489 490
490 /*bool is_isolate_exit_needed = false;491 /*bool is_isolate_exit_needed = false;
@@ -514,7 +515,7 @@ void ScriptEngineV8::registerFunction(const QString& name, ScriptEngine::Functio · 23 unmodified lines
514void ScriptEngineV8::registerFunction(const QString& parent, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {515void ScriptEngineV8::registerFunction(const QString& parent, const QString& name, ScriptEngine::FunctionSignature functionSignature, int numArguments) {
515 if (QThread::currentThread() != thread()) {516 if (QThread::currentThread() != thread()) {
516#ifdef THREAD_DEBUGGING517#ifdef THREAD_DEBUGGING
517 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] parent:" << parent << "name:" << name;518 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] parent:" << parent << "name:" << name;
518#endif519#endif
519 QMetaObject::invokeMethod(this, "registerFunction",520 QMetaObject::invokeMethod(this, "registerFunction",
520 Q_ARG(const QString&, name),521 Q_ARG(const QString&, name),
@@ -523,7 +524,7 @@ void ScriptEngineV8::registerFunction(const QString& parent, const QString& name · 2 unmodified lines
523 return;524 return;
524 }525 }
525#ifdef THREAD_DEBUGGING526#ifdef THREAD_DEBUGGING
526 qCDebug(scriptengine) << "ScriptEngineV8::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name;527 qCDebug(scriptengine_v8) << "ScriptEngineV8::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name;
527#endif528#endif
528 529
529 /*bool is_isolate_exit_needed = false;530 /*bool is_isolate_exit_needed = false;
@@ -554,7 +555,7 @@ void ScriptEngineV8::registerGetterSetter(const QString& name, ScriptEngine::Fun · 24 unmodified lines
554 ScriptEngine::FunctionSignature setter, const QString& parent) {555 ScriptEngine::FunctionSignature setter, const QString& parent) {
555 if (QThread::currentThread() != thread()) {556 if (QThread::currentThread() != thread()) {
556#ifdef THREAD_DEBUGGING557#ifdef THREAD_DEBUGGING
557 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "558 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
558 " name:" << name << "parent:" << parent;559 " name:" << name << "parent:" << parent;
559#endif560#endif
560 QMetaObject::invokeMethod(this, "registerGetterSetter",561 QMetaObject::invokeMethod(this, "registerGetterSetter",
@@ -565,7 +566,7 @@ void ScriptEngineV8::registerGetterSetter(const QString& name, ScriptEngine::Fun · 4 unmodified lines
565 return;566 return;
566 }567 }
567#ifdef THREAD_DEBUGGING568#ifdef THREAD_DEBUGGING
568 qCDebug(scriptengine) << "ScriptEngineV8::registerGetterSetter() called on thread [" << QThread::currentThread() << "] name:" << name << "parent:" << parent;569 qCDebug(scriptengine_v8) << "ScriptEngineV8::registerGetterSetter() called on thread [" << QThread::currentThread() << "] name:" << name << "parent:" << parent;
569#endif570#endif
570 571
571 /*bool is_isolate_exit_needed = false;572 /*bool is_isolate_exit_needed = false;
@@ -639,20 +640,20 @@ void ScriptEngineV8::registerGetterSetter(const QString& name, ScriptEngine::Fun · 67 unmodified lines
639 v8ObjectToSetProperty = v8ParentObject;640 v8ObjectToSetProperty = v8ParentObject;
640 }641 }
641 if (!v8ObjectToSetProperty->DefineProperty(getContext(), v8propertyName, propertyDescriptor).FromMaybe(false)) {642 if (!v8ObjectToSetProperty->DefineProperty(getContext(), v8propertyName, propertyDescriptor).FromMaybe(false)) {
642 qCDebug(scriptengine) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for parent: \""643 qCDebug(scriptengine_v8) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for parent: \""
643 << parent << "\"";644 << parent << "\"";
644 }645 }
645 //object.setProperty(name, setterFunction, ScriptValue::PropertySetter);646 //object.setProperty(name, setterFunction, ScriptValue::PropertySetter);
646 //object.setProperty(name, getterFunction, ScriptValue::PropertyGetter);647 //object.setProperty(name, getterFunction, ScriptValue::PropertyGetter);
647 } else {648 } else {
648 qCDebug(scriptengine) << "Parent object \"" << parent << "\" for registerGetterSetter \"" << name649 qCDebug(scriptengine_v8) << "Parent object \"" << parent << "\" for registerGetterSetter \"" << name
649 << "\" is not valid: ";650 << "\" is not valid: ";
650 }651 }
651 } else {652 } else {
652 v8::Local<v8::String> v8propertyName =653 v8::Local<v8::String> v8propertyName =
653 v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked();654 v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked();
654 if (!getContext()->Global()->DefineProperty(getContext(), v8propertyName, propertyDescriptor).FromMaybe(false)) {655 if (!getContext()->Global()->DefineProperty(getContext(), v8propertyName, propertyDescriptor).FromMaybe(false)) {
655 qCDebug(scriptengine) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for global object";656 qCDebug(scriptengine_v8) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for global object";
656 }657 }
657 //globalObject().setProperty(name, setterFunction, ScriptValue::PropertySetter);658 //globalObject().setProperty(name, setterFunction, ScriptValue::PropertySetter);
658 //globalObject().setProperty(name, getterFunction, ScriptValue::PropertyGetter);659 //globalObject().setProperty(name, getterFunction, ScriptValue::PropertyGetter);
@@ -697,7 +698,7 @@ void ScriptEngineV8::storeGlobalObjectContents() { · 38 unmodified lines
697 }698 }
698 699
699 _globalObjectContents.Reset(_v8Isolate, globalMemberObjects);700 _globalObjectContents.Reset(_v8Isolate, globalMemberObjects);
700 qDebug() << "ScriptEngineV8::storeGlobalObjectContents: " << globalMemberNames->Length() << " objects stored";701 qCDebug(scriptengine_v8) << "ScriptEngineV8::storeGlobalObjectContents: " << globalMemberNames->Length() << " objects stored";
701 areGlobalObjectContentsStored = true;702 areGlobalObjectContentsStored = true;
702}703}
703 704
@@ -725,7 +726,7 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 21 unmodified lines
725 unwrappedProgram = ScriptProgramV8Wrapper::unwrap(_program);726 unwrappedProgram = ScriptProgramV8Wrapper::unwrap(_program);
726 if (unwrappedProgram == nullptr) {727 if (unwrappedProgram == nullptr) {
727 _evaluatingCounter--;728 _evaluatingCounter--;
728 qDebug(scriptengine) << "Cannot unwrap program for closure";729 qCDebug(scriptengine_v8) << "Cannot unwrap program for closure";
729 Q_ASSERT(false);730 Q_ASSERT(false);
730 return nullValue();731 return nullValue();
731 }732 }
@@ -737,7 +738,7 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 5 unmodified lines
737 unwrappedClosure = ScriptValueV8Wrapper::unwrap(_closure);738 unwrappedClosure = ScriptValueV8Wrapper::unwrap(_closure);
738 if (unwrappedClosure == nullptr) {739 if (unwrappedClosure == nullptr) {
739 _evaluatingCounter--;740 _evaluatingCounter--;
740 qDebug(scriptengine) << "Cannot unwrap closure";741 qCDebug(scriptengine_v8) << "Cannot unwrap closure";
741 Q_ASSERT(false);742 Q_ASSERT(false);
742 return nullValue();743 return nullValue();
743 }744 }
@@ -746,27 +747,27 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 2 unmodified lines
746 //const V8ScriptProgram& program = unwrappedProgram->toV8Value();747 //const V8ScriptProgram& program = unwrappedProgram->toV8Value();
747 if (!closure.constGet()->IsObject()) {748 if (!closure.constGet()->IsObject()) {
748 _evaluatingCounter--;749 _evaluatingCounter--;
749 qDebug(scriptengine) << "Unwrapped closure is not an object";750 qCDebug(scriptengine_v8) << "Unwrapped closure is not an object";
750 Q_ASSERT(false);751 Q_ASSERT(false);
751 return nullValue();752 return nullValue();
752 }753 }
753 Q_ASSERT(closure.constGet()->IsObject());754 Q_ASSERT(closure.constGet()->IsObject());
754 closureObject = v8::Local<v8::Object>::Cast(closure.constGet());755 closureObject = v8::Local<v8::Object>::Cast(closure.constGet());
755 qDebug() << "Closure object members:" << scriptValueDebugListMembersV8(closure);756 qCDebug(scriptengine_v8) << "Closure object members:" << scriptValueDebugListMembersV8(closure);
756 v8::Local<v8::Object> testObject = v8::Object::New(_v8Isolate);757 v8::Local<v8::Object> testObject = v8::Object::New(_v8Isolate);
757 if(!testObject->Set(getContext(), v8::String::NewFromUtf8(_v8Isolate, "test_value").ToLocalChecked(), closureObject).FromMaybe(false)) {758 if(!testObject->Set(getContext(), v8::String::NewFromUtf8(_v8Isolate, "test_value").ToLocalChecked(), closureObject).FromMaybe(false)) {
758 Q_ASSERT(false);759 Q_ASSERT(false);
759 }760 }
760 qDebug() << "Test object members:" << scriptValueDebugListMembersV8(V8ScriptValue(this, testObject));761 qCDebug(scriptengine_v8) << "Test object members:" << scriptValueDebugListMembersV8(V8ScriptValue(this, testObject));
761 762
762 if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "global").ToLocalChecked())763 if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "global").ToLocalChecked())
763 .ToLocal(&closureGlobal)) {764 .ToLocal(&closureGlobal)) {
764 _evaluatingCounter--;765 _evaluatingCounter--;
765 qDebug(scriptengine) << "Cannot get global from unwrapped closure";766 qCDebug(scriptengine_v8) << "Cannot get global from unwrapped closure";
766 Q_ASSERT(false);767 Q_ASSERT(false);
767 return nullValue();768 return nullValue();
768 }769 }
769 //qDebug() << "Closure global details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, closureGlobal));770 //qCDebug(scriptengine_v8) << "Closure global details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, closureGlobal));
770 }771 }
771 //oldGlobal = _v8Context.Get(_v8Isolate)->Global();772 //oldGlobal = _v8Context.Get(_v8Isolate)->Global();
772 v8::Local<v8::Context> closureContext;773 v8::Local<v8::Context> closureContext;
@@ -794,7 +795,7 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 21 unmodified lines
794 v8::Context::Scope contextScope(closureContext);795 v8::Context::Scope contextScope(closureContext);
795 //const V8ScriptValue& closure = unwrappedClosure->toV8Value();796 //const V8ScriptValue& closure = unwrappedClosure->toV8Value();
796 if (!unwrappedProgram->compile()) {797 if (!unwrappedProgram->compile()) {
797 qDebug(scriptengine) << "Can't compile script for evaluating in closure";798 qCDebug(scriptengine_v8) << "Can't compile script for evaluating in closure";
798 Q_ASSERT(false);799 Q_ASSERT(false);
799 popContext();800 popContext();
800 return nullValue();801 return nullValue();
@@ -806,12 +807,12 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 5 unmodified lines
806 /*if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "this").ToLocalChecked())807 /*if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "this").ToLocalChecked())
807 .ToLocal(&thiz)) {808 .ToLocal(&thiz)) {
808 _evaluatingCounter--;809 _evaluatingCounter--;
809 qDebug(scriptengine) << "Empty this object in closure";810 qCDebug(scriptengine_v8) << "Empty this object in closure";
810 Q_ASSERT(false);811 Q_ASSERT(false);
811 return nullValue();812 return nullValue();
812 }*/813 }*/
813 //thiz = closure.property("this");814 //thiz = closure.property("this");
814 //qDebug() << "Closure this details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, thiz));815 //qCDebug(scriptengine_v8) << "Closure this details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, thiz));
815 // V8TODO:816 // V8TODO:
816 /*if (thiz->IsObject()) {817 /*if (thiz->IsObject()) {
817#ifdef DEBUG_JS818#ifdef DEBUG_JS
@@ -837,7 +838,7 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 19 unmodified lines
837 Q_ASSERT(false);838 Q_ASSERT(false);
838 }839 }
839 }840 }
840 qDebug() << "ScriptEngineV8::evaluateInClosure: " << globalMemberNames->Length() << " objects added to global";841 qCDebug(scriptengine_v8) << "ScriptEngineV8::evaluateInClosure: " << globalMemberNames->Length() << " objects added to global";
841 842
842 /*auto oldGlobalMemberNames = oldContext->Global()->GetPropertyNames(oldContext).ToLocalChecked();843 /*auto oldGlobalMemberNames = oldContext->Global()->GetPropertyNames(oldContext).ToLocalChecked();
843 //auto oldGlobalMemberNames = oldContext->Global()->GetPropertyNames(closureContext).ToLocalChecked();844 //auto oldGlobalMemberNames = oldContext->Global()->GetPropertyNames(closureContext).ToLocalChecked();
@@ -874,15 +875,15 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 30 unmodified lines
874 } else {875 } else {
875 membersString = QString(" Is not an object");876 membersString = QString(" Is not an object");
876 }*/877 }*/
877 //qDebug(scriptengine) << "Closure global before run:" << membersString;878 //qCDebug(scriptengine_v8) << "Closure global before run:" << membersString;
878 auto maybeResult = program.constGet()->GetUnboundScript()->BindToCurrentContext()->Run(closureContext);879 auto maybeResult = program.constGet()->GetUnboundScript()->BindToCurrentContext()->Run(closureContext);
879 //qDebug(scriptengine) << "Closure after run:" << scriptValueDebugDetailsV8(closure);880 //qCDebug(scriptengine_v8) << "Closure after run:" << scriptValueDebugDetailsV8(closure);
880 v8::Local<v8::Value> v8Result;881 v8::Local<v8::Value> v8Result;
881 if (!maybeResult.ToLocal(&v8Result)) {882 if (!maybeResult.ToLocal(&v8Result)) {
882 v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Exception());883 v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Exception());
883 QString errorMessage = QString(*utf8Value);884 QString errorMessage = QString(*utf8Value);
884 qWarning(scriptengine) << __FUNCTION__ << "---------- hasCaught:" << errorMessage;885 qCWarning(scriptengine_v8) << __FUNCTION__ << "---------- hasCaught:" << errorMessage;
885 qWarning(scriptengine) << __FUNCTION__ << "---------- tryCatch details:" << formatErrorMessageFromTryCatch(tryCatch);886 qCWarning(scriptengine_v8) << __FUNCTION__ << "---------- tryCatch details:" << formatErrorMessageFromTryCatch(tryCatch);
886 //V8TODO: better error reporting887 //V8TODO: better error reporting
887 }888 }
888 889
@@ -919,7 +920,7 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 30 unmodified lines
919 if (QThread::currentThread() != thread()) {920 if (QThread::currentThread() != thread()) {
920 ScriptValue result;921 ScriptValue result;
921#ifdef THREAD_DEBUGGING922#ifdef THREAD_DEBUGGING
922 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "923 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
923 "sourceCode:" << sourceCode << " fileName:" << fileName;924 "sourceCode:" << sourceCode << " fileName:" << fileName;
924#endif925#endif
925 BLOCKING_INVOKE_METHOD(this, "evaluate",926 BLOCKING_INVOKE_METHOD(this, "evaluate",
@@ -944,7 +945,7 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 18 unmodified lines
944 _evaluatingCounter--;945 _evaluatingCounter--;
945 return nullValue();946 return nullValue();
946 }947 }
947 //qCDebug(scriptengine) << "Script compilation succesful: " << fileName;948 //qCDebug(scriptengine_v8) << "Script compilation succesful: " << fileName;
948 949
949 //V8TODO950 //V8TODO
950 /*auto syntaxError = lintScript(sourceCode, fileName);951 /*auto syntaxError = lintScript(sourceCode, fileName);
@@ -971,7 +972,7 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 20 unmodified lines
971 Q_ASSERT(tryCatchRun.HasCaught());972 Q_ASSERT(tryCatchRun.HasCaught());
972 auto runError = tryCatchRun.Message();973 auto runError = tryCatchRun.Message();
973 ScriptValue errorValue(new ScriptValueV8Wrapper(this, V8ScriptValue(this, runError->Get())));974 ScriptValue errorValue(new ScriptValueV8Wrapper(this, V8ScriptValue(this, runError->Get())));
974 qCDebug(scriptengine) << "Running script: \"" << fileName << "\" " << formatErrorMessageFromTryCatch(tryCatchRun);975 qCDebug(scriptengine_v8) << "Running script: \"" << fileName << "\" " << formatErrorMessageFromTryCatch(tryCatchRun);
975 //V8TODO976 //V8TODO
976 977
977 978
@@ -995,7 +996,7 @@ void ScriptEngineV8::setUncaughtEngineException(const QString &reason, const QSt · 17 unmodified lines
995 996
996void ScriptEngineV8::setUncaughtException(const v8::TryCatch &tryCatch, const QString& info) {997void ScriptEngineV8::setUncaughtException(const v8::TryCatch &tryCatch, const QString& info) {
997 if (!tryCatch.HasCaught()) {998 if (!tryCatch.HasCaught()) {
998 qCWarning(scriptengine) << "setUncaughtException called without exception";999 qCWarning(scriptengine_v8) << "setUncaughtException called without exception";
999 clearExceptions();1000 clearExceptions();
1000 return;1001 return;
1001 }1002 }
@@ -1041,7 +1042,7 @@ void ScriptEngineV8::setUncaughtException(const v8::TryCatch &tryCatch, const QS · 39 unmodified lines
1041}1042}
1042 1043
1043void ScriptEngineV8::setUncaughtException(std::shared_ptr<ScriptException> uncaughtException) {1044void ScriptEngineV8::setUncaughtException(std::shared_ptr<ScriptException> uncaughtException) {
1044 qCDebug(scriptengine) << "Emitting exception:" << uncaughtException;1045 qCDebug(scriptengine_v8) << "Emitting exception:" << uncaughtException;
1045 _uncaughtException = uncaughtException;1046 _uncaughtException = uncaughtException;
1046 1047
1047 auto copy = uncaughtException->clone();1048 auto copy = uncaughtException->clone();
@@ -1105,7 +1106,7 @@ Q_INVOKABLE ScriptValue ScriptEngineV8::evaluate(const ScriptProgramPointer& pro · 57 unmodified lines
1105 if (QThread::currentThread() != thread()) {1106 if (QThread::currentThread() != thread()) {
1106 ScriptValue result;1107 ScriptValue result;
1107#ifdef THREAD_DEBUGGING1108#ifdef THREAD_DEBUGGING
1108 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineV8::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "1109 qCDebug(scriptengine_v8) << "*** WARNING *** ScriptEngineV8::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
1109 "sourceCode:" << sourceCode << " fileName:" << fileName;1110 "sourceCode:" << sourceCode << " fileName:" << fileName;
1110#endif1111#endif
1111 BLOCKING_INVOKE_METHOD(this, "evaluate",1112 BLOCKING_INVOKE_METHOD(this, "evaluate",
@@ -1498,14 +1499,14 @@ QThread* ScriptEngineV8::thread() const { · 386 unmodified lines
1498void ScriptEngineV8::setThread(QThread* thread) {1499void ScriptEngineV8::setThread(QThread* thread) {
1499 if (_v8Isolate->IsCurrent()) {1500 if (_v8Isolate->IsCurrent()) {
1500 _v8Isolate->Exit();1501 _v8Isolate->Exit();
1501 qDebug() << "Script engine " << objectName() << " exited isolate";1502 qCDebug(scriptengine_v8) << "Script engine " << objectName() << " exited isolate";
1502 }1503 }
1503 Q_ASSERT(QObject::thread() == QThread::currentThread());1504 Q_ASSERT(QObject::thread() == QThread::currentThread());
1504 /*if (_v8Locker) {1505 /*if (_v8Locker) {
1505 _v8Locker.reset();1506 _v8Locker.reset();
1506 }*/1507 }*/
1507 moveToThread(thread);1508 moveToThread(thread);
1508 qDebug() << "Moved script engine " << objectName() << " to different thread";1509 qCDebug(scriptengine_v8) << "Moved script engine " << objectName() << " to different thread";
1509}1510}
1510 1511
1511/*void ScriptEngineV8::enterIsolateOnThisThread() {1512/*void ScriptEngineV8::enterIsolateOnThisThread() {
@@ -1514,7 +1515,7 @@ void ScriptEngineV8::setThread(QThread* thread) { · 2 unmodified lines
1514 _v8Locker.reset(new v8::Locker(_v8Isolate));1515 _v8Locker.reset(new v8::Locker(_v8Isolate));
1515 if (!_v8Isolate->IsCurrent()) {1516 if (!_v8Isolate->IsCurrent()) {
1516 _v8Isolate->Enter();1517 _v8Isolate->Enter();
1517 qDebug() << "Script engine " << objectName() << " entered isolate on a new thread";1518 qCDebug(scriptengine_v8) << "Script engine " << objectName() << " entered isolate on a new thread";
1518 }1519 }
1519}*/1520}*/
1520 1521
@@ -1534,14 +1535,14 @@ bool ScriptEngineV8::raiseException(const QString& error, const QString &reason) · 13 unmodified lines
1534bool ScriptEngineV8::raiseException(const ScriptValue& exception, const QString &reason) {1535bool ScriptEngineV8::raiseException(const ScriptValue& exception, const QString &reason) {
1535 //V8TODO1536 //V8TODO
1536 //Q_ASSERT(false);1537 //Q_ASSERT(false);
1537// qCritical() << "Script exception occurred: " << exception.toString();1538// qCCritical(scriptengine_v8) << "Script exception occurred: " << exception.toString();
1538// ScriptValueV8Wrapper* unwrapped = ScriptValueV8Wrapper::unwrap(exception);1539// ScriptValueV8Wrapper* unwrapped = ScriptValueV8Wrapper::unwrap(exception);
1539// V8ScriptValue qException = unwrapped ? unwrapped->toV8Value() : QScriptEngine::newVariant(exception.toVariant());1540// V8ScriptValue qException = unwrapped ? unwrapped->toV8Value() : QScriptEngine::newVariant(exception.toVariant());
1540 1541
1541 // emit1542 // emit
1542 //return raiseException(qException);1543 //return raiseException(qException);
1543 1544
1544// qCCritical(scriptengine) << "Raise exception for reason" << reason << "NOT IMPLEMENTED!";1545// qCCritical(scriptengine_v8) << "Raise exception for reason" << reason << "NOT IMPLEMENTED!";
1545// return false;1546// return false;
1546 1547
1547 return raiseException(ScriptValueV8Wrapper::fullUnwrap(this, exception));1548 return raiseException(ScriptValueV8Wrapper::fullUnwrap(this, exception));
@@ -1615,9 +1616,9 @@ void ScriptEngineV8::compileTest() { · 67 unmodified lines
1615 v8::Local<v8::Script> script;1616 v8::Local<v8::Script> script;
1616 v8::ScriptOrigin scriptOrigin(getIsolate(), v8::String::NewFromUtf8(getIsolate(),"test").ToLocalChecked());1617 v8::ScriptOrigin scriptOrigin(getIsolate(), v8::String::NewFromUtf8(getIsolate(),"test").ToLocalChecked());
1617 if (v8::Script::Compile(getContext(), v8::String::NewFromUtf8(getIsolate(), "print(\"hello world\");").ToLocalChecked(), &scriptOrigin).ToLocal(&script)) {1618 if (v8::Script::Compile(getContext(), v8::String::NewFromUtf8(getIsolate(), "print(\"hello world\");").ToLocalChecked(), &scriptOrigin).ToLocal(&script)) {
1618 qCDebug(scriptengine) << "Compile test successful";1619 qCDebug(scriptengine_v8) << "Compile test successful";
1619 } else {1620 } else {
1620 qCDebug(scriptengine) << "Compile test failed";1621 qCDebug(scriptengine_v8) << "Compile test failed";
1621 Q_ASSERT(false);1622 Q_ASSERT(false);
1622 }1623 }
1623}1624}
@@ -1683,9 +1684,9 @@ QString ScriptEngineV8::scriptValueDebugDetailsV8(const V8ScriptValue &v8Value) · 59 unmodified lines
1683 1684
1684void ScriptEngineV8::logBacktrace(const QString &title) {1685void ScriptEngineV8::logBacktrace(const QString &title) {
1685 QStringList backtrace = currentContext()->backtrace();1686 QStringList backtrace = currentContext()->backtrace();
1686 qDebug(scriptengine) << title;1687 qCDebug(scriptengine_v8) << title;
1687 for (int n = 0; n < backtrace.length(); n++) {1688 for (int n = 0; n < backtrace.length(); n++) {
1688 qDebug(scriptengine) << backtrace[n];1689 qCDebug(scriptengine_v8) << backtrace[n];
1689 }1690 }
1690}1691}
1691 1692