History

Further work on evaluateInClosure

ksuprynowicz committed 3 years ago

Commit ed968e11 parent 70d4a435 files · +63 −10Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8.cpp+17−8
@@ -800,20 +800,24 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 799 unmodified lines
800800 Q_ASSERT(false);
801801 return nullValue();
802802 }
803+ //qDebug() << "Closure global details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, closureGlobal));
803804 }
804805 //_v8Context.Get(_v8Isolate)->DetachGlobal();
805806 //oldGlobal = _v8Context.Get(_v8Isolate)->Global();
806807 v8::Local<v8::Context> closureContext;
807808
808− if (closureGlobal->IsObject()) {
809+ // V8TODO
810+ /*if (closureGlobal->IsObject()) {
809811 #ifdef DEBUG_JS
810812 qCDebug(shared) << " setting global = closure.global" << shortName;
811813 #endif
814+ closureContext = v8::Context::New(_v8Isolate, nullptr, v8::Local<v8::ObjectTemplate>(), closureGlobal);
812815 closureContext = v8::Context::New(_v8Isolate, nullptr, v8::Local<v8::ObjectTemplate>(), closureGlobal);
813816 //setGlobalObject(global);
814817 } else {
815818 closureContext = v8::Context::New(_v8Isolate);
816− }
819+ }*/
820+ closureContext = v8::Context::New(_v8Isolate, nullptr, v8::Local<v8::ObjectTemplate>(), closureObject);
817821
818822 ScriptValue result;
819823 //auto context = pushContext();
@@ -828,23 +832,25 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 8 unmodified lines
828832 const V8ScriptProgram& program = unwrappedProgram->toV8Value();
829833
830834 v8::Local<v8::Value> thiz;
831− // V8TODO: not sure if "this" doesn't exist or is empty in some cases
832− if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "this").ToLocalChecked())
835+ // V8TODO: not sure if "this" is used at all here
836+ /*if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "this").ToLocalChecked())
833837 .ToLocal(&thiz)) {
834838 _evaluatingCounter--;
835839 qDebug(scriptengine) << "Empty this object in closure";
836840 Q_ASSERT(false);
837841 return nullValue();
838− }
842+ }*/
839843 //thiz = closure.property("this");
840− if (thiz->IsObject()) {
844+ //qDebug() << "Closure this details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, thiz));
845+ // V8TODO:
846+ /*if (thiz->IsObject()) {
841847 #ifdef DEBUG_JS
842848 qCDebug(shared) << " setting this = closure.this" << shortName;
843849 #endif
844850 //V8TODO I don't know how to do this in V8, will adding "this" to global object work?
845851 closureContext->Global()->Set(closureContext, v8::String::NewFromUtf8(_v8Isolate, "this").ToLocalChecked(), thiz);
846852 //context->setThisObject(thiz);
847− }
853+ }*/
848854
849855 //context->pushScope(closure);
850856 #ifdef DEBUG_JS
@@ -852,12 +858,15 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 1 unmodified line
852858 #endif
853859 {
854860 v8::TryCatch tryCatch(getIsolate());
861+ //qDebug(scriptengine) << "Closure before run:" << scriptValueDebugDetailsV8(closure);
855862 auto maybeResult = program.constGet()->Run(closureContext);
863+ //qDebug(scriptengine) << "Closure after run:" << scriptValueDebugDetailsV8(closure);
856864 v8::Local<v8::Value> v8Result;
857865 if (!maybeResult.ToLocal(&v8Result)) {
858866 v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Exception());
859867 QString errorMessage = QString(*utf8Value);
860868 qWarning(scriptengine) << __FUNCTION__ << "---------- hasCaught:" << errorMessage;
869+ qWarning(scriptengine) << __FUNCTION__ << "---------- tryCatch details:" << formatErrorMessageFromTryCatch(tryCatch);
861870 //V8TODO: better error reporting
862871 }
863872
@@ -1513,7 +1522,7 @@ void ScriptEngineV8::compileTest() { · 649 unmodified lines
15131522 }
15141523 }
15151524
1516−QString ScriptEngineV8::scriptValueDebugDetails(ScriptValue &value) {
1525+QString ScriptEngineV8::scriptValueDebugDetails(const ScriptValue &value) {
15171526 V8ScriptValue v8Value = ScriptValueV8Wrapper::fullUnwrap(this, value);
15181527 return scriptValueDebugDetailsV8(v8Value);
15191528 }