Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8.cpp (1 of 5 files). Show all
Unified · Split
| @@ -800,20 +800,24 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 799 unmodified lines | ||
| 800 | 800 | Q_ASSERT(false); |
| 801 | 801 | return nullValue(); |
| 802 | 802 | } |
| 803 | + //qDebug() << "Closure global details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, closureGlobal)); | |
| 803 | 804 | } |
| 804 | 805 | //_v8Context.Get(_v8Isolate)->DetachGlobal(); |
| 805 | 806 | //oldGlobal = _v8Context.Get(_v8Isolate)->Global(); |
| 806 | 807 | v8::Local<v8::Context> closureContext; |
| 807 | 808 | |
| 808 | − if (closureGlobal->IsObject()) { | |
| 809 | + // V8TODO | |
| 810 | + /*if (closureGlobal->IsObject()) { | |
| 809 | 811 | #ifdef DEBUG_JS |
| 810 | 812 | qCDebug(shared) << " setting global = closure.global" << shortName; |
| 811 | 813 | #endif |
| 814 | + closureContext = v8::Context::New(_v8Isolate, nullptr, v8::Local<v8::ObjectTemplate>(), closureGlobal); | |
| 812 | 815 | closureContext = v8::Context::New(_v8Isolate, nullptr, v8::Local<v8::ObjectTemplate>(), closureGlobal); |
| 813 | 816 | //setGlobalObject(global); |
| 814 | 817 | } else { |
| 815 | 818 | closureContext = v8::Context::New(_v8Isolate); |
| 816 | − } | |
| 819 | + }*/ | |
| 820 | + closureContext = v8::Context::New(_v8Isolate, nullptr, v8::Local<v8::ObjectTemplate>(), closureObject); | |
| 817 | 821 | |
| 818 | 822 | ScriptValue result; |
| 819 | 823 | //auto context = pushContext(); |
| @@ -828,23 +832,25 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 8 unmodified lines | ||
| 828 | 832 | const V8ScriptProgram& program = unwrappedProgram->toV8Value(); |
| 829 | 833 | |
| 830 | 834 | 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()) | |
| 833 | 837 | .ToLocal(&thiz)) { |
| 834 | 838 | _evaluatingCounter--; |
| 835 | 839 | qDebug(scriptengine) << "Empty this object in closure"; |
| 836 | 840 | Q_ASSERT(false); |
| 837 | 841 | return nullValue(); |
| 838 | − } | |
| 842 | + }*/ | |
| 839 | 843 | //thiz = closure.property("this"); |
| 840 | − if (thiz->IsObject()) { | |
| 844 | + //qDebug() << "Closure this details:" << scriptValueDebugDetailsV8(V8ScriptValue(_v8Isolate, thiz)); | |
| 845 | + // V8TODO: | |
| 846 | + /*if (thiz->IsObject()) { | |
| 841 | 847 | #ifdef DEBUG_JS |
| 842 | 848 | qCDebug(shared) << " setting this = closure.this" << shortName; |
| 843 | 849 | #endif |
| 844 | 850 | //V8TODO I don't know how to do this in V8, will adding "this" to global object work? |
| 845 | 851 | closureContext->Global()->Set(closureContext, v8::String::NewFromUtf8(_v8Isolate, "this").ToLocalChecked(), thiz); |
| 846 | 852 | //context->setThisObject(thiz); |
| 847 | − } | |
| 853 | + }*/ | |
| 848 | 854 | |
| 849 | 855 | //context->pushScope(closure); |
| 850 | 856 | #ifdef DEBUG_JS |
| @@ -852,12 +858,15 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 1 unmodified line | ||
| 852 | 858 | #endif |
| 853 | 859 | { |
| 854 | 860 | v8::TryCatch tryCatch(getIsolate()); |
| 861 | + //qDebug(scriptengine) << "Closure before run:" << scriptValueDebugDetailsV8(closure); | |
| 855 | 862 | auto maybeResult = program.constGet()->Run(closureContext); |
| 863 | + //qDebug(scriptengine) << "Closure after run:" << scriptValueDebugDetailsV8(closure); | |
| 856 | 864 | v8::Local<v8::Value> v8Result; |
| 857 | 865 | if (!maybeResult.ToLocal(&v8Result)) { |
| 858 | 866 | v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Exception()); |
| 859 | 867 | QString errorMessage = QString(*utf8Value); |
| 860 | 868 | qWarning(scriptengine) << __FUNCTION__ << "---------- hasCaught:" << errorMessage; |
| 869 | + qWarning(scriptengine) << __FUNCTION__ << "---------- tryCatch details:" << formatErrorMessageFromTryCatch(tryCatch); | |
| 861 | 870 | //V8TODO: better error reporting |
| 862 | 871 | } |
| 863 | 872 | |
| @@ -1513,7 +1522,7 @@ void ScriptEngineV8::compileTest() { · 649 unmodified lines | ||
| 1513 | 1522 | } |
| 1514 | 1523 | } |
| 1515 | 1524 | |
| 1516 | −QString ScriptEngineV8::scriptValueDebugDetails(ScriptValue &value) { | |
| 1525 | +QString ScriptEngineV8::scriptValueDebugDetails(const ScriptValue &value) { | |
| 1517 | 1526 | V8ScriptValue v8Value = ScriptValueV8Wrapper::fullUnwrap(this, value); |
| 1518 | 1527 | return scriptValueDebugDetailsV8(v8Value); |
| 1519 | 1528 | } |