Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8.cpp (1 of 21 files). Show all
Unified · Split
| @@ -49,6 +49,7 @@ · 48 unmodified lines | |||
| 49 | #include "ScriptObjectV8Proxy.h" | 49 | #include "ScriptObjectV8Proxy.h" |
| 50 | #include "ScriptProgramV8Wrapper.h" | 50 | #include "ScriptProgramV8Wrapper.h" |
| 51 | #include "ScriptValueV8Wrapper.h" | 51 | #include "ScriptValueV8Wrapper.h" |
| 52 | #include "V8Lambda.h" | ||
| 52 | 53 | ||
| 53 | static const int MAX_DEBUG_VALUE_LENGTH { 80 }; | 54 | static const int MAX_DEBUG_VALUE_LENGTH { 80 }; |
| 54 | 55 | ||
| @@ -72,9 +73,9 @@ bool ScriptEngineV8::IS_THREADSAFE_INVOCATION(const QThread* thread, const QStri · 17 unmodified lines | |||
| 72 | // engine-aware JS Error copier and factory | 73 | // engine-aware JS Error copier and factory |
| 73 | V8ScriptValue ScriptEngineV8::makeError(const V8ScriptValue& _other, const QString& type) { | 74 | V8ScriptValue ScriptEngineV8::makeError(const V8ScriptValue& _other, const QString& type) { |
| 74 | if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) { | 75 | if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) { |
| 75 | return V8ScriptValue(_v8Isolate, v8::Null(_v8Isolate)); | 76 | return V8ScriptValue(this, v8::Null(_v8Isolate)); |
| 76 | } | 77 | } |
| 77 | return V8ScriptValue(_v8Isolate, v8::Null(_v8Isolate)); | 78 | return V8ScriptValue(this, v8::Null(_v8Isolate)); |
| 78 | //V8TODO | 79 | //V8TODO |
| 79 | /* | 80 | /* |
| 80 | auto other = _other; | 81 | auto other = _other; |
| @@ -293,7 +294,7 @@ bool ScriptEngineV8::maybeEmitUncaughtException(const QString& debugHint) { · 212 unmodified lines | |||
| 293 | } | 294 | } |
| 294 | 295 | ||
| 295 | // Lambda | 296 | // Lambda |
| 296 | ScriptValue ScriptEngineV8::newLambdaFunction(std::function<V8ScriptValue(V8ScriptContext*, ScriptEngineV8*)> operation, | 297 | /*ScriptValue ScriptEngineV8::newLambdaFunction(std::function<V8ScriptValue(V8ScriptContext*, ScriptEngineV8*)> operation, |
| 297 | const V8ScriptValue& data, | 298 | const V8ScriptValue& data, |
| 298 | const ValueOwnership& ownership) { | 299 | const ValueOwnership& ownership) { |
| 299 | v8::HandleScope handleScope(_v8Isolate); | 300 | v8::HandleScope handleScope(_v8Isolate); |
| @@ -305,7 +306,7 @@ ScriptValue ScriptEngineV8::newLambdaFunction(std::function<V8ScriptValue(V8Scri · 5 unmodified lines | |||
| 305 | call.setPrototype(object); // context->callee().prototype() === Lambda QObject | 306 | call.setPrototype(object); // context->callee().prototype() === Lambda QObject |
| 306 | call.setData(ScriptValue(new ScriptValueV8Wrapper(this, data))); // context->callee().data() will === data param | 307 | call.setData(ScriptValue(new ScriptValueV8Wrapper(this, data))); // context->callee().data() will === data param |
| 307 | return call; | 308 | return call; |
| 308 | } | 309 | }*/ |
| 309 | QString Lambda::toString() const { | 310 | QString Lambda::toString() const { |
| 310 | v8::HandleScope handleScope(_engine->getIsolate()); | 311 | v8::HandleScope handleScope(_engine->getIsolate()); |
| 311 | v8::Context::Scope contextScope(_engine->getContext()); | 312 | v8::Context::Scope contextScope(_engine->getContext()); |
| @@ -338,7 +339,7 @@ Lambda::Lambda(ScriptEngineV8* engine, · 26 unmodified lines | |||
| 338 | } | 339 | } |
| 339 | V8ScriptValue Lambda::call() { | 340 | V8ScriptValue Lambda::call() { |
| 340 | if (!_engine->IS_THREADSAFE_INVOCATION(__FUNCTION__)) { | 341 | if (!_engine->IS_THREADSAFE_INVOCATION(__FUNCTION__)) { |
| 341 | return V8ScriptValue(_engine->getIsolate(), v8::Null(_engine->getIsolate())); | 342 | return V8ScriptValue(_engine, v8::Null(_engine->getIsolate())); |
| 342 | } | 343 | } |
| 343 | // V8TODO: it needs to be done in entirely different way for V8 | 344 | // V8TODO: it needs to be done in entirely different way for V8 |
| 344 | Q_ASSERT(false); | 345 | Q_ASSERT(false); |
| @@ -411,10 +412,10 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager* scriptManager) : · 66 unmodified lines | |||
| 411 | _contexts.append(std::make_shared<ScriptContextV8Wrapper>(this,context, ScriptContextPointer())); | 412 | _contexts.append(std::make_shared<ScriptContextV8Wrapper>(this,context, ScriptContextPointer())); |
| 412 | 413 | ||
| 413 | 414 | ||
| 414 | V8ScriptValue nullScriptValue(_v8Isolate, v8::Null(_v8Isolate)); | 415 | V8ScriptValue nullScriptValue(this, v8::Null(_v8Isolate)); |
| 415 | _nullValue = ScriptValue(new ScriptValueV8Wrapper(this, nullScriptValue)); | 416 | _nullValue = ScriptValue(new ScriptValueV8Wrapper(this, nullScriptValue)); |
| 416 | 417 | ||
| 417 | V8ScriptValue undefined(_v8Isolate, v8::Undefined(_v8Isolate)); | 418 | V8ScriptValue undefined(this, v8::Undefined(_v8Isolate)); |
| 418 | _undefinedValue = ScriptValue(new ScriptValueV8Wrapper(this, undefined)); | 419 | _undefinedValue = ScriptValue(new ScriptValueV8Wrapper(this, undefined)); |
| 419 | 420 | ||
| 420 | registerSystemTypes(); | 421 | registerSystemTypes(); |
| @@ -463,7 +464,7 @@ void ScriptEngineV8::registerEnum(const QString& enumName, QMetaEnum newEnum) { · 42 unmodified lines | |||
| 463 | for (int i = 0; i < newEnum.keyCount(); i++) { | 464 | for (int i = 0; i < newEnum.keyCount(); i++) { |
| 464 | const char* keyName = newEnum.key(i); | 465 | const char* keyName = newEnum.key(i); |
| 465 | QString fullName = enumName + "." + keyName; | 466 | QString fullName = enumName + "." + keyName; |
| 466 | registerValue(fullName, V8ScriptValue(_v8Isolate, v8::Integer::New(_v8Isolate, newEnum.keyToValue(keyName)))); | 467 | registerValue(fullName, V8ScriptValue(this, v8::Integer::New(_v8Isolate, newEnum.keyToValue(keyName)))); |
| 467 | } | 468 | } |
| 468 | } | 469 | } |
| 469 | 470 | ||
| @@ -741,7 +742,7 @@ void ScriptEngineV8::registerGetterSetter(const QString& name, ScriptEngine::Fun · 271 unmodified lines | |||
| 741 | v8::Local<v8::String> v8propertyName = | 742 | v8::Local<v8::String> v8propertyName = |
| 742 | v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked(); | 743 | v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked(); |
| 743 | v8::Local<v8::Object> v8ObjectToSetProperty; | 744 | v8::Local<v8::Object> v8ObjectToSetProperty; |
| 744 | ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(V8ScriptValue(_v8Isolate, v8ParentObject)); | 745 | ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(V8ScriptValue(this, v8ParentObject)); |
| 745 | // If object is ScriptObjectV8Proxy, then setting property needs to be handled differently | 746 | // If object is ScriptObjectV8Proxy, then setting property needs to be handled differently |
| 746 | if (proxy) { | 747 | if (proxy) { |
| 747 | v8ObjectToSetProperty = v8ParentObject->GetInternalField(2).As<v8::Object>(); | 748 | v8ObjectToSetProperty = v8ParentObject->GetInternalField(2).As<v8::Object>(); |
| @@ -833,13 +834,14 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 85 unmodified lines | |||
| 833 | Q_ASSERT(false); | 834 | Q_ASSERT(false); |
| 834 | return nullValue(); | 835 | return nullValue(); |
| 835 | } | 836 | } |
| 837 | Q_ASSERT(closure.constGet()->IsObject()); | ||
| 836 | closureObject = v8::Local<v8::Object>::Cast(closure.constGet()); | 838 | closureObject = v8::Local<v8::Object>::Cast(closure.constGet()); |
| 837 | qDebug() << "Closure object members:" << scriptValueDebugListMembersV8(closure); | 839 | qDebug() << "Closure object members:" << scriptValueDebugListMembersV8(closure); |
| 838 | v8::Local<v8::Object> testObject = v8::Object::New(_v8Isolate); | 840 | v8::Local<v8::Object> testObject = v8::Object::New(_v8Isolate); |
| 839 | if(!testObject->Set(getContext(), v8::String::NewFromUtf8(_v8Isolate, "test_value").ToLocalChecked(), closureObject).FromMaybe(false)) { | 841 | if(!testObject->Set(getContext(), v8::String::NewFromUtf8(_v8Isolate, "test_value").ToLocalChecked(), closureObject).FromMaybe(false)) { |
| 840 | Q_ASSERT(false); | 842 | Q_ASSERT(false); |
| 841 | } | 843 | } |
| 842 | qDebug() << "Test object members:" << scriptValueDebugListMembersV8(V8ScriptValue(_v8Isolate, testObject)); | 844 | qDebug() << "Test object members:" << scriptValueDebugListMembersV8(V8ScriptValue(this, testObject)); |
| 843 | 845 | ||
| 844 | if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "global").ToLocalChecked()) | 846 | if (!closureObject->Get(closure.constGetContext(), v8::String::NewFromUtf8(_v8Isolate, "global").ToLocalChecked()) |
| 845 | .ToLocal(&closureGlobal)) { | 847 | .ToLocal(&closureGlobal)) { |
| @@ -958,7 +960,7 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 112 unmodified lines | |||
| 958 | #endif | 960 | #endif |
| 959 | result = err; | 961 | result = err; |
| 960 | } else { | 962 | } else { |
| 961 | result = ScriptValue(new ScriptValueV8Wrapper(this, V8ScriptValue(_v8Isolate, v8Result))); | 963 | result = ScriptValue(new ScriptValueV8Wrapper(this, V8ScriptValue(this, v8Result))); |
| 962 | } | 964 | } |
| 963 | } | 965 | } |
| 964 | #ifdef DEBUG_JS | 966 | #ifdef DEBUG_JS |
| @@ -1022,10 +1024,13 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 57 unmodified lines | |||
| 1022 | errorLineNumber = exceptionMessage->GetLineNumber(getContext()).FromJust(); | 1024 | errorLineNumber = exceptionMessage->GetLineNumber(getContext()).FromJust(); |
| 1023 | errorColumnNumber = exceptionMessage->GetStartColumn(getContext()).FromJust(); | 1025 | errorColumnNumber = exceptionMessage->GetStartColumn(getContext()).FromJust(); |
| 1024 | v8::Local<v8::Value> backtraceV8String; | 1026 | v8::Local<v8::Value> backtraceV8String; |
| 1025 | if (tryCatch.StackTrace(getContext()).ToLocal(&backtraceV8String) && backtraceV8String->IsString() && | 1027 | if (tryCatch.StackTrace(getContext()).ToLocal(&backtraceV8String)) { |
| 1026 | v8::Local<v8::String>::Cast(backtraceV8String)->Length() > 0) { | 1028 | if (backtraceV8String->IsString()) { |
| 1027 | v8::String::Utf8Value backtraceUtf8Value(getIsolate(), backtraceV8String); | 1029 | if (v8::Local<v8::String>::Cast(backtraceV8String)->Length() > 0) { |
| 1028 | errorBacktrace = *backtraceUtf8Value; | 1030 | v8::String::Utf8Value backtraceUtf8Value(getIsolate(), backtraceV8String); |
| 1031 | errorBacktrace = *backtraceUtf8Value; | ||
| 1032 | } | ||
| 1033 | } | ||
| 1029 | } | 1034 | } |
| 1030 | qCDebug(scriptengine) << "Compiling script \"" << fileName << "\" failed on line " << errorLineNumber << " column " << errorColumnNumber << " with message: \"" << errorMessage <<"\" backtrace: " << errorBacktrace; | 1035 | qCDebug(scriptengine) << "Compiling script \"" << fileName << "\" failed on line " << errorLineNumber << " column " << errorColumnNumber << " with message: \"" << errorMessage <<"\" backtrace: " << errorBacktrace; |
| 1031 | } | 1036 | } |
| @@ -1061,7 +1066,7 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 29 unmodified lines | |||
| 1061 | if (!script->Run(getContext()).ToLocal(&result)) { | 1066 | if (!script->Run(getContext()).ToLocal(&result)) { |
| 1062 | Q_ASSERT(tryCatchRun.HasCaught()); | 1067 | Q_ASSERT(tryCatchRun.HasCaught()); |
| 1063 | auto runError = tryCatchRun.Message(); | 1068 | auto runError = tryCatchRun.Message(); |
| 1064 | ScriptValue errorValue(new ScriptValueV8Wrapper(this, V8ScriptValue(_v8Isolate, runError->Get()))); | 1069 | ScriptValue errorValue(new ScriptValueV8Wrapper(this, V8ScriptValue(this, runError->Get()))); |
| 1065 | qCDebug(scriptengine) << "Running script: \"" << fileName << "\" " << formatErrorMessageFromTryCatch(tryCatchRun); | 1070 | qCDebug(scriptengine) << "Running script: \"" << fileName << "\" " << formatErrorMessageFromTryCatch(tryCatchRun); |
| 1066 | //V8TODO | 1071 | //V8TODO |
| 1067 | //raiseException(errorValue); | 1072 | //raiseException(errorValue); |
| @@ -1069,7 +1074,7 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 1 unmodified line | |||
| 1069 | _evaluatingCounter--; | 1074 | _evaluatingCounter--; |
| 1070 | return errorValue; | 1075 | return errorValue; |
| 1071 | } | 1076 | } |
| 1072 | V8ScriptValue resultValue(_v8Isolate, result); | 1077 | V8ScriptValue resultValue(this, result); |
| 1073 | _evaluatingCounter--; | 1078 | _evaluatingCounter--; |
| 1074 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(resultValue))); | 1079 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(resultValue))); |
| 1075 | } | 1080 | } |
| @@ -1092,10 +1097,13 @@ QString ScriptEngineV8::formatErrorMessageFromTryCatch(v8::TryCatch &tryCatch) { · 16 unmodified lines | |||
| 1092 | errorLineNumber = exceptionMessage->GetLineNumber(getContext()).FromJust(); | 1097 | errorLineNumber = exceptionMessage->GetLineNumber(getContext()).FromJust(); |
| 1093 | errorColumnNumber = exceptionMessage->GetStartColumn(getContext()).FromJust(); | 1098 | errorColumnNumber = exceptionMessage->GetStartColumn(getContext()).FromJust(); |
| 1094 | v8::Local<v8::Value> backtraceV8String; | 1099 | v8::Local<v8::Value> backtraceV8String; |
| 1095 | if (tryCatch.StackTrace(getContext()).ToLocal(&backtraceV8String) && backtraceV8String->IsString() && | 1100 | if (tryCatch.StackTrace(getContext()).ToLocal(&backtraceV8String)) { |
| 1096 | v8::Local<v8::String>::Cast(backtraceV8String)->Length() > 0) { | 1101 | if (backtraceV8String->IsString()) { |
| 1097 | v8::String::Utf8Value backtraceUtf8Value(getIsolate(), backtraceV8String); | 1102 | if (v8::Local<v8::String>::Cast(backtraceV8String)->Length() > 0) { |
| 1098 | errorBacktrace = *backtraceUtf8Value; | 1103 | v8::String::Utf8Value backtraceUtf8Value(getIsolate(), backtraceV8String); |
| 1104 | errorBacktrace = *backtraceUtf8Value; | ||
| 1105 | } | ||
| 1106 | } | ||
| 1099 | } | 1107 | } |
| 1100 | QTextStream resultStream(&result); | 1108 | QTextStream resultStream(&result); |
| 1101 | resultStream << "failed on line " << errorLineNumber << " column " << errorColumnNumber << " with message: \"" << errorMessage <<"\" backtrace: " << errorBacktrace; | 1109 | resultStream << "failed on line " << errorLineNumber << " column " << errorColumnNumber << " with message: \"" << errorMessage <<"\" backtrace: " << errorBacktrace; |
| @@ -1185,7 +1193,7 @@ Q_INVOKABLE ScriptValue ScriptEngineV8::evaluate(const ScriptProgramPointer& pro · 83 unmodified lines | |||
| 1185 | if (!v8Program.constGet()->Run(getContext()).ToLocal(&result)) { | 1193 | if (!v8Program.constGet()->Run(getContext()).ToLocal(&result)) { |
| 1186 | Q_ASSERT(tryCatchRun.HasCaught()); | 1194 | Q_ASSERT(tryCatchRun.HasCaught()); |
| 1187 | auto runError = tryCatchRun.Message(); | 1195 | auto runError = tryCatchRun.Message(); |
| 1188 | errorValue = ScriptValue(new ScriptValueV8Wrapper(this, V8ScriptValue(_v8Isolate, runError->Get()))); | 1196 | errorValue = ScriptValue(new ScriptValueV8Wrapper(this, V8ScriptValue(this, runError->Get()))); |
| 1189 | raiseException(errorValue); | 1197 | raiseException(errorValue); |
| 1190 | maybeEmitUncaughtException("evaluate"); | 1198 | maybeEmitUncaughtException("evaluate"); |
| 1191 | hasFailed = true; | 1199 | hasFailed = true; |
| @@ -1195,7 +1203,7 @@ Q_INVOKABLE ScriptValue ScriptEngineV8::evaluate(const ScriptProgramPointer& pro · 3 unmodified lines | |||
| 1195 | } | 1203 | } |
| 1196 | } | 1204 | } |
| 1197 | if(!hasFailed) { | 1205 | if(!hasFailed) { |
| 1198 | V8ScriptValue resultValueV8(_v8Isolate, result); | 1206 | V8ScriptValue resultValueV8(this, result); |
| 1199 | resultValue = ScriptValue(new ScriptValueV8Wrapper(this, std::move(resultValueV8))); | 1207 | resultValue = ScriptValue(new ScriptValueV8Wrapper(this, std::move(resultValueV8))); |
| 1200 | } | 1208 | } |
| 1201 | } | 1209 | } |
| @@ -1225,12 +1233,12 @@ void ScriptEngineV8::updateMemoryCost(const qint64& deltaSize) { · 23 unmodified lines | |||
| 1225 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 1233 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1226 | // ScriptEngine implementation | 1234 | // ScriptEngine implementation |
| 1227 | 1235 | ||
| 1228 | ScriptValue ScriptEngineV8::globalObject() const { | 1236 | ScriptValue ScriptEngineV8::globalObject() { |
| 1229 | v8::Locker locker(_v8Isolate); | 1237 | v8::Locker locker(_v8Isolate); |
| 1230 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1238 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1231 | v8::HandleScope handleScope(_v8Isolate); | 1239 | v8::HandleScope handleScope(_v8Isolate); |
| 1232 | v8::Context::Scope contextScope(getConstContext()); | 1240 | v8::Context::Scope contextScope(getConstContext()); |
| 1233 | V8ScriptValue global(_v8Isolate, getConstContext()->Global());// = QScriptEngine::globalObject(); // can't cache the value as it may change | 1241 | V8ScriptValue global(this, getConstContext()->Global());// = QScriptEngine::globalObject(); // can't cache the value as it may change |
| 1234 | return ScriptValue(new ScriptValueV8Wrapper(const_cast<ScriptEngineV8*>(this), std::move(global))); | 1242 | return ScriptValue(new ScriptValueV8Wrapper(const_cast<ScriptEngineV8*>(this), std::move(global))); |
| 1235 | } | 1243 | } |
| 1236 | 1244 | ||
| @@ -1243,7 +1251,7 @@ ScriptValue ScriptEngineV8::newArray(uint length) { · 6 unmodified lines | |||
| 1243 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1251 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1244 | v8::HandleScope handleScope(_v8Isolate); | 1252 | v8::HandleScope handleScope(_v8Isolate); |
| 1245 | v8::Context::Scope contextScope(getContext()); | 1253 | v8::Context::Scope contextScope(getContext()); |
| 1246 | V8ScriptValue result(_v8Isolate, v8::Array::New(_v8Isolate, static_cast<int>(length))); | 1254 | V8ScriptValue result(this, v8::Array::New(_v8Isolate, static_cast<int>(length))); |
| 1247 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1255 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1248 | } | 1256 | } |
| 1249 | 1257 | ||
| @@ -1262,7 +1270,7 @@ ScriptValue ScriptEngineV8::newArrayBuffer(const QByteArray& message) { · 12 unmodified lines | |||
| 1262 | if (!array) { | 1270 | if (!array) { |
| 1263 | return undefinedValue(); | 1271 | return undefinedValue(); |
| 1264 | }*/ | 1272 | }*/ |
| 1265 | V8ScriptValue result(_v8Isolate, arrayBuffer);//QScriptEngine::newObject(array, data); | 1273 | V8ScriptValue result(this, arrayBuffer);//QScriptEngine::newObject(array, data); |
| 1266 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1274 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1267 | } | 1275 | } |
| 1268 | 1276 | ||
| @@ -1280,7 +1288,7 @@ ScriptValue ScriptEngineV8::newObject() { · 11 unmodified lines | |||
| 1280 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1288 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1281 | v8::HandleScope handleScope(_v8Isolate); | 1289 | v8::HandleScope handleScope(_v8Isolate); |
| 1282 | v8::Context::Scope contextScope(getContext()); | 1290 | v8::Context::Scope contextScope(getContext()); |
| 1283 | V8ScriptValue resultV8 = V8ScriptValue(_v8Isolate, v8::Object::New(_v8Isolate)); | 1291 | V8ScriptValue resultV8 = V8ScriptValue(this, v8::Object::New(_v8Isolate)); |
| 1284 | result = ScriptValue(new ScriptValueV8Wrapper(this, std::move(resultV8))); | 1292 | result = ScriptValue(new ScriptValueV8Wrapper(this, std::move(resultV8))); |
| 1285 | } | 1293 | } |
| 1286 | /*if (is_isolate_exit_needed) { | 1294 | /*if (is_isolate_exit_needed) { |
| @@ -1328,7 +1336,7 @@ ScriptValue ScriptEngineV8::newValue(bool value) { · 41 unmodified lines | |||
| 1328 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1336 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1329 | v8::HandleScope handleScope(_v8Isolate); | 1337 | v8::HandleScope handleScope(_v8Isolate); |
| 1330 | v8::Context::Scope contextScope(getContext()); | 1338 | v8::Context::Scope contextScope(getContext()); |
| 1331 | V8ScriptValue result(_v8Isolate, v8::Boolean::New(_v8Isolate, value)); | 1339 | V8ScriptValue result(this, v8::Boolean::New(_v8Isolate, value)); |
| 1332 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1340 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1333 | } | 1341 | } |
| 1334 | 1342 | ||
| @@ -1337,7 +1345,7 @@ ScriptValue ScriptEngineV8::newValue(int value) { · 2 unmodified lines | |||
| 1337 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1345 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1338 | v8::HandleScope handleScope(_v8Isolate); | 1346 | v8::HandleScope handleScope(_v8Isolate); |
| 1339 | v8::Context::Scope contextScope(getContext()); | 1347 | v8::Context::Scope contextScope(getContext()); |
| 1340 | V8ScriptValue result(_v8Isolate, v8::Integer::New(_v8Isolate, value)); | 1348 | V8ScriptValue result(this, v8::Integer::New(_v8Isolate, value)); |
| 1341 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1349 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1342 | } | 1350 | } |
| 1343 | 1351 | ||
| @@ -1346,7 +1354,7 @@ ScriptValue ScriptEngineV8::newValue(uint value) { · 2 unmodified lines | |||
| 1346 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1354 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1347 | v8::HandleScope handleScope(_v8Isolate); | 1355 | v8::HandleScope handleScope(_v8Isolate); |
| 1348 | v8::Context::Scope contextScope(getContext()); | 1356 | v8::Context::Scope contextScope(getContext()); |
| 1349 | V8ScriptValue result(_v8Isolate, v8::Uint32::New(_v8Isolate, value)); | 1357 | V8ScriptValue result(this, v8::Uint32::New(_v8Isolate, value)); |
| 1350 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1358 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1351 | } | 1359 | } |
| 1352 | 1360 | ||
| @@ -1355,7 +1363,7 @@ ScriptValue ScriptEngineV8::newValue(double value) { · 2 unmodified lines | |||
| 1355 | v8::Isolate::Scope isolateScope(_v8Isolate); | 1363 | v8::Isolate::Scope isolateScope(_v8Isolate); |
| 1356 | v8::HandleScope handleScope(_v8Isolate); | 1364 | v8::HandleScope handleScope(_v8Isolate); |
| 1357 | v8::Context::Scope contextScope(getContext()); | 1365 | v8::Context::Scope contextScope(getContext()); |
| 1358 | V8ScriptValue result(_v8Isolate, v8::Number::New(_v8Isolate, value)); | 1366 | V8ScriptValue result(this, v8::Number::New(_v8Isolate, value)); |
| 1359 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1367 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1360 | } | 1368 | } |
| 1361 | 1369 | ||
| @@ -1365,7 +1373,7 @@ ScriptValue ScriptEngineV8::newValue(const QString& value) { · 3 unmodified lines | |||
| 1365 | v8::HandleScope handleScope(_v8Isolate); | 1373 | v8::HandleScope handleScope(_v8Isolate); |
| 1366 | v8::Context::Scope contextScope(getContext()); | 1374 | v8::Context::Scope contextScope(getContext()); |
| 1367 | v8::Local<v8::String> valueV8 = v8::String::NewFromUtf8(_v8Isolate, value.toStdString().c_str(), v8::NewStringType::kNormal).ToLocalChecked(); | 1375 | v8::Local<v8::String> valueV8 = v8::String::NewFromUtf8(_v8Isolate, value.toStdString().c_str(), v8::NewStringType::kNormal).ToLocalChecked(); |
| 1368 | V8ScriptValue result(_v8Isolate, valueV8); | 1376 | V8ScriptValue result(this, valueV8); |
| 1369 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1377 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1370 | } | 1378 | } |
| 1371 | 1379 | ||
| @@ -1375,7 +1383,7 @@ ScriptValue ScriptEngineV8::newValue(const QLatin1String& value) { · 3 unmodified lines | |||
| 1375 | v8::HandleScope handleScope(_v8Isolate); | 1383 | v8::HandleScope handleScope(_v8Isolate); |
| 1376 | v8::Context::Scope contextScope(getContext()); | 1384 | v8::Context::Scope contextScope(getContext()); |
| 1377 | v8::Local<v8::String> valueV8 = v8::String::NewFromUtf8(_v8Isolate, value.latin1(), v8::NewStringType::kNormal).ToLocalChecked(); | 1385 | v8::Local<v8::String> valueV8 = v8::String::NewFromUtf8(_v8Isolate, value.latin1(), v8::NewStringType::kNormal).ToLocalChecked(); |
| 1378 | V8ScriptValue result(_v8Isolate, valueV8); | 1386 | V8ScriptValue result(this, valueV8); |
| 1379 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1387 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1380 | } | 1388 | } |
| 1381 | 1389 | ||
| @@ -1385,7 +1393,7 @@ ScriptValue ScriptEngineV8::newValue(const char* value) { · 3 unmodified lines | |||
| 1385 | v8::HandleScope handleScope(_v8Isolate); | 1393 | v8::HandleScope handleScope(_v8Isolate); |
| 1386 | v8::Context::Scope contextScope(getContext()); | 1394 | v8::Context::Scope contextScope(getContext()); |
| 1387 | v8::Local<v8::String> valueV8 = v8::String::NewFromUtf8(_v8Isolate, value, v8::NewStringType::kNormal).ToLocalChecked(); | 1395 | v8::Local<v8::String> valueV8 = v8::String::NewFromUtf8(_v8Isolate, value, v8::NewStringType::kNormal).ToLocalChecked(); |
| 1388 | V8ScriptValue result(_v8Isolate, valueV8); | 1396 | V8ScriptValue result(this, valueV8); |
| 1389 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); | 1397 | return ScriptValue(new ScriptValueV8Wrapper(this, std::move(result))); |
| 1390 | } | 1398 | } |
| 1391 | 1399 | ||
| @@ -1463,6 +1471,7 @@ ScriptValue ScriptEngineV8::newFunction(ScriptEngine::FunctionSignature fun, int · 71 unmodified lines | |||
| 1463 | v8::HandleScope handleScope(info.GetIsolate()); | 1471 | v8::HandleScope handleScope(info.GetIsolate()); |
| 1464 | auto context = info.GetIsolate()->GetCurrentContext(); | 1472 | auto context = info.GetIsolate()->GetCurrentContext(); |
| 1465 | v8::Context::Scope contextScope(context); | 1473 | v8::Context::Scope contextScope(context); |
| 1474 | Q_ASSERT(info.Data()->IsObject()); | ||
| 1466 | auto object = v8::Local<v8::Object>::Cast(info.Data()); | 1475 | auto object = v8::Local<v8::Object>::Cast(info.Data()); |
| 1467 | Q_ASSERT(object->InternalFieldCount() == 2); | 1476 | Q_ASSERT(object->InternalFieldCount() == 2); |
| 1468 | auto function = reinterpret_cast<ScriptEngine::FunctionSignature> | 1477 | auto function = reinterpret_cast<ScriptEngine::FunctionSignature> |
| @@ -1493,7 +1502,7 @@ ScriptValue ScriptEngineV8::newFunction(ScriptEngine::FunctionSignature fun, int · 24 unmodified lines | |||
| 1493 | auto v8Function = v8::Function::New(getContext(), v8FunctionCallback, functionData, length).ToLocalChecked(); | 1502 | auto v8Function = v8::Function::New(getContext(), v8FunctionCallback, functionData, length).ToLocalChecked(); |
| 1494 | //auto functionObjectTemplate = functionTemplate->InstanceTemplate(); | 1503 | //auto functionObjectTemplate = functionTemplate->InstanceTemplate(); |
| 1495 | //auto function = | 1504 | //auto function = |
| 1496 | V8ScriptValue result(_v8Isolate, v8Function); // = QScriptEngine::newFunction(innerFunc, length); | 1505 | V8ScriptValue result(this, v8Function); // = QScriptEngine::newFunction(innerFunc, length); |
| 1497 | //auto funAddr = QScriptEngine::newVariant(QVariant(reinterpret_cast<qulonglong>(fun))); | 1506 | //auto funAddr = QScriptEngine::newVariant(QVariant(reinterpret_cast<qulonglong>(fun))); |
| 1498 | // V8TODO | 1507 | // V8TODO |
| 1499 | //result.setProperty("_func", funAddr, V8ScriptValue::PropertyFlags(V8ScriptValue::ReadOnly + V8ScriptValue::Undeletable + V8ScriptValue::SkipInEnumeration)); | 1508 | //result.setProperty("_func", funAddr, V8ScriptValue::PropertyFlags(V8ScriptValue::ReadOnly + V8ScriptValue::Undeletable + V8ScriptValue::SkipInEnumeration)); |
| @@ -1685,4 +1694,20 @@ QString ScriptEngineV8::scriptValueDebugDetailsV8(const V8ScriptValue &v8Value) · 185 unmodified lines | |||
| 1685 | v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(_v8Isolate, n); | 1694 | v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(_v8Isolate, n); |
| 1686 | 1695 | ||
| 1687 | } | 1696 | } |
| 1688 | }*/ | 1697 | }*/ |
| 1698 | |||
| 1699 | QStringList ScriptEngineV8::getCurrentScriptURLs() const { | ||
| 1700 | auto isolate = _v8Isolate; | ||
| 1701 | v8::Locker locker(isolate); | ||
| 1702 | v8::Isolate::Scope isolateScope(isolate); | ||
| 1703 | v8::HandleScope handleScope(isolate); | ||
| 1704 | v8::Context::Scope contextScope(_v8Isolate->GetCurrentContext()); | ||
| 1705 | v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(isolate, 100); | ||
| 1706 | QStringList scriptURLs; | ||
| 1707 | //V8TODO nicer formatting | ||
| 1708 | for (int i = 0; i < stackTrace->GetFrameCount(); i++) { | ||
| 1709 | v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(isolate, i); | ||
| 1710 | scriptURLs.append(QString(*v8::String::Utf8Value(isolate, stackFrame->GetScriptNameOrSourceURL()))); | ||
| 1711 | } | ||
| 1712 | return scriptURLs; | ||
| 1713 | } | ||