History

Code cleanup

ksuprynowicz committed 3 years ago

Commit 5050cc91 parent d24038629 files · +57 −951Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp+7−383
@@ -24,12 +24,7 @@ · 23 unmodified lines
2424 #include "ScriptValueV8Wrapper.h"
2525 #include "ScriptEngineLoggingV8.h"
2626
27−//V8TODO: is this needed for anything? It could cause trouble with multithreading if V8ScriptContext is v8::Persistent
28−//Q_DECLARE_METATYPE(V8ScriptContext*)
29−
3027 Q_DECLARE_METATYPE(ScriptValue)
31−//V8TODO: default constructor would be needed
32−//Q_DECLARE_METATYPE(V8ScriptValue)
3328
3429 Q_DECLARE_METATYPE(QSharedPointer<ScriptObjectV8Proxy>)
3530 Q_DECLARE_METATYPE(QSharedPointer<ScriptVariantV8Proxy>)
@@ -76,7 +71,6 @@ private: // storage · 40 unmodified lines
7671
7772 ScriptObjectV8Proxy::ScriptObjectV8Proxy(ScriptEngineV8* engine, QObject* object, bool ownsObject, const ScriptEngine::QObjectWrapOptions& options) :
7873 _engine(engine), _wrapOptions(options), _ownsObject(ownsObject), _object(object) {
79− //_v8ObjectTemplate(engine->getIsolate(), v8::ObjectTemplate::New(engine->getIsolate())
8074 Q_ASSERT(_engine != nullptr);
8175 investigate();
8276 }
@@ -90,11 +84,9 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o · 7 unmodified lines
9084 ScriptEngineV8::ObjectWrapperMap::const_iterator lookup = engine->_qobjectWrapperMap.find(object);
9185 if (lookup != engine->_qobjectWrapperMap.end()) {
9286 QSharedPointer<ScriptObjectV8Proxy> proxy = lookup.value().lock();
93− // V8TODO: is conversion to QVariant and back needed?
9487 if (proxy) {
9588 return V8ScriptValue(engine, proxy.get()->toV8Value());
9689 }
97− //if (proxy) return engine->newObject(proxy.get(), engine->newVariant(QVariant::fromValue(proxy)));;
9890 }
9991 }
10092
@@ -125,12 +117,10 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o · 24 unmodified lines
125117 ScriptEngineV8::ObjectWrapperMap::const_iterator lookup = engine->_qobjectWrapperMap.find(object);
126118 if (lookup != engine->_qobjectWrapperMap.end()) {
127119 QSharedPointer<ScriptObjectV8Proxy> proxy = lookup.value().lock();
128− //if (proxy) return qengine->newObject(proxy.get(), qengine->newVariant(QVariant::fromValue(proxy)));;
129120 if (proxy) {
130121 return V8ScriptValue(engine, proxy.get()->toV8Value());
131122 }
132123 }
133− // V8TODO add a V8 callback that removes pointer for the script engine owned ob from the map so that it gets deleted
134124 // register the wrapper with the engine and make sure it cleans itself up
135125 engine->_qobjectWrapperMap.insert(object, proxy);
136126 engine->_qobjectWrapperMapV8.insert(object, proxy);
@@ -146,13 +136,10 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o · 9 unmodified lines
146136 if (lookupV8 != enginePtr->_qobjectWrapperMapV8.end()) {
147137 enginePtr->_qobjectWrapperMapV8.erase(lookupV8);
148138 }
149− //qDebug() << "ScriptObjectV8Proxy::newQObject object deleted, object count: " << enginePtr->_qobjectWrapperMapV8.size();
150139 });
151− //qDebug() << "ScriptObjectV8Proxy::newQObject object count: " << engine->_qobjectWrapperMapV8.size();
152140 }
153141
154142 return V8ScriptValue(engine, proxy.get()->toV8Value());
155− //return qengine->newObject(proxy.get(), qengine->newVariant(QVariant::fromValue(proxy)));
156143 }
157144
158145 ScriptObjectV8Proxy* ScriptObjectV8Proxy::unwrapProxy(const V8ScriptValue& val) {
@@ -162,20 +149,17 @@ ScriptObjectV8Proxy* ScriptObjectV8Proxy::unwrapProxy(const V8ScriptValue& val) · 3 unmodified lines
162149 v8::HandleScope handleScope(isolate);
163150 v8::Local<v8::Context> context = val.constGetContext();
164151 v8::Context::Scope contextScope(context);
165− //V8TODO This shouldn't cause problems but I'm not sure if it's ok
166− //v8::HandleScope handleScope(const_cast<v8::Isolate*>(val.constGetIsolate()));
167152 auto v8Value = val.constGet();
168153 Q_ASSERT(!v8Value.IsEmpty());
154+
169155 if (v8Value->IsNullOrUndefined()) {
170156 return nullptr;
171157 }
172158 if (!v8Value->IsObject()) {
173− //qCDebug(scriptengine_v8) << "Cannot unwrap proxy - value is not an object";
174159 return nullptr;
175160 }
176161 v8::Local<v8::Object> v8Object = v8::Local<v8::Object>::Cast(v8Value);
177162 if (v8Object->InternalFieldCount() != 3) {
178− //qCDebug(scriptengine_v8) << "Cannot unwrap proxy - wrong number of internal fields";
179163 return nullptr;
180164 }
181165 if (v8Object->GetAlignedPointerFromInternalField(0) != internalPointsToQObjectProxy) {
@@ -189,20 +173,16 @@ ScriptObjectV8Proxy* ScriptObjectV8Proxy::unwrapProxy(v8::Isolate* isolate, v8:: · 7 unmodified lines
189173 v8::Locker locker(isolate);
190174 v8::Isolate::Scope isolateScope(isolate);
191175 v8::HandleScope handleScope(isolate);
192− //V8TODO: shouldn't there be context scope here?
193− //v8::Local<v8::Context> context = val.constGetContext();
194− //v8::Context::Scope contextScope(context);
176+ //V8TODO: should there be context scope here?
177+
195178 if (value->IsNullOrUndefined()) {
196− //qCDebug(scriptengine_v8) << "Cannot unwrap proxy - value is not an object";
197179 return nullptr;
198180 }
199181 if (!value->IsObject()) {
200− //qCDebug(scriptengine_v8) << "Cannot unwrap proxy - value is not an object";
201182 return nullptr;
202183 }
203184 v8::Local<v8::Object> v8Object = v8::Local<v8::Object>::Cast(value);
204185 if (v8Object->InternalFieldCount() != 3) {
205− //qCDebug(scriptengine_v8) << "Cannot unwrap proxy - wrong number of internal fields";
206186 return nullptr;
207187 }
208188 if (v8Object->GetAlignedPointerFromInternalField(0) != internalPointsToQObjectProxy) {
@@ -257,13 +237,8 @@ void ScriptObjectV8Proxy::investigate() { · 48 unmodified lines
257237
258238 const QMetaObject* metaObject = qobject->metaObject();
259239
260− //auto objectTemplate = _v8ObjectTemplate.Get(_engine->getIsolate());
261240 auto objectTemplate = _engine->getObjectProxyTemplate();
262− /*auto objectTemplate = v8::ObjectTemplate::New(_engine->getIsolate());
263− objectTemplate->SetInternalFieldCount(3);
264− objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set, nullptr, nullptr, v8GetPropertyNames));*/
265241
266− //qCDebug(scriptengine_v8) << "Investigate: " << metaObject->className();
267242 if (QString("ConsoleScriptingInterface") == metaObject->className()) {
268243 printf("ConsoleScriptingInterface");
269244 }
@@ -274,7 +249,6 @@ void ScriptObjectV8Proxy::investigate() { · 4 unmodified lines
274249 QMetaProperty prop = metaObject->property(idx);
275250 if (!prop.isScriptable()) continue;
276251
277− //qCDebug(scriptengine_v8) << "Investigate: " << metaObject->className() << " Property: " << prop.name();
278252 // always exclude child objects (at least until we decide otherwise)
279253 int metaTypeId = prop.userType();
280254 if (metaTypeId != QMetaType::UnknownType) {
@@ -284,7 +258,6 @@ void ScriptObjectV8Proxy::investigate() { · 3 unmodified lines
284258 }
285259 }
286260
287− //auto v8Name = v8::String::NewFromUtf8(_engine->getIsolate(), prop.name()).ToLocalChecked();
288261 PropertyDef& propDef = _props.insert(idx, PropertyDef(prop.name(), idx)).value();
289262 _propNameMap.insert(prop.name(), &propDef);
290263 propDef.flags = ScriptValue::Undeletable | ScriptValue::PropertyGetter | ScriptValue::PropertySetter |
@@ -298,7 +271,6 @@ void ScriptObjectV8Proxy::investigate() { · 7 unmodified lines
298271 QHash<QString, int> methodNames;
299272 for (int idx = startIdx; idx < num; ++idx) {
300273 QMetaMethod method = metaObject->method(idx);
301− //qCDebug(scriptengine_v8) << "Investigate: " << metaObject->className() << " Method: " << method.name();
302274
303275 // perhaps keep this comment? Calls (like AudioScriptingInterface::playSound) seem to expect non-public methods to be script-accessible
304276 /* if (method.access() != QMetaMethod::Public) continue;*/
@@ -333,9 +305,6 @@ void ScriptObjectV8Proxy::investigate() { · 28 unmodified lines
333305 signalDef.name = szName;
334306 signalDef.signal = method;
335307 _signalNameMap.insert(szName, &signalDef);
336− //qCDebug(scriptengine_v8) << "Utf8Value 1: " << QString(*v8::String::Utf8Value(const_cast<v8::Isolate*>(_engine->getIsolate()), nameString));
337− //qCDebug(scriptengine_v8) << "Utf8Value 2: " << QString(*v8::String::Utf8Value(const_cast<v8::Isolate*>(_engine->getIsolate()), name.constGet()));
338− //qCDebug(scriptengine_v8) << "toQString: " << name.toQString();
339308 methodNames.insert(szName, idx);
340309 } else {
341310 int originalMethodId = nameLookup.value();
@@ -376,10 +345,6 @@ void ScriptObjectV8Proxy::investigate() { · 34 unmodified lines
376345 }
377346
378347 v8::Local<v8::Object> v8Object = objectTemplate->NewInstance(_engine->getContext()).ToLocalChecked();
379− /*if (QString(metaObject->className()) == QString("TestQObject")) {
380− //qDebug() << "TestQObject investigate: _methods.size: " << _methods.size();
381− return;
382− }*/
383348
384349 v8Object->SetAlignedPointerInInternalField(0, const_cast<void*>(internalPointsToQObjectProxy));
385350 v8Object->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(this));
@@ -406,9 +371,6 @@ void ScriptObjectV8Proxy::investigate() { · 20 unmodified lines
406371 }
407372
408373 void ScriptObjectV8Proxy::weakHandleCallback(const v8::WeakCallbackInfo<ScriptObjectV8Proxy>& info) {
409− //V8TODO: does the object need to be moved to script engine thread?
410− //V8TODO: why does this never get called?
411− //qDebug(scriptengine_v8) << "ScriptObjectV8Proxy::weakHandleCallback";
412374 auto proxy = info.GetParameter();
413375 proxy->_v8Object.Reset();
414376 info.GetParameter()->_object->deleteLater();
@@ -423,41 +385,24 @@ QString ScriptObjectV8Proxy::name() const { · 8 unmodified lines
423385 return _object->metaObject()->className();
424386 }
425387
426−// V8TODO: check if it would be more optimal to use V8ScriptString& name or QString name
427388 ScriptObjectV8Proxy::QueryFlags ScriptObjectV8Proxy::queryProperty(const V8ScriptValue& object, const V8ScriptString& name, QueryFlags flags, uint* id) {
428389 auto isolate = _engine->getIsolate();
429390 v8::Locker locker(isolate);
430391 v8::Isolate::Scope isolateScope(isolate);
431392 v8::HandleScope handleScope(isolate);
432− // V8TODO: this might be inefficient when there's large number of properties
433393 v8::Local<v8::Context> context = _engine->getContext();
434394 v8::Context::Scope contextScope(context);
435395 QString nameStr(*v8::String::Utf8Value(isolate, name.constGet()));
436396
437397 // check for methods
438− /*for (MethodDefMap::const_iterator trans = _methods.cbegin(); trans != _methods.cend(); ++trans) {
439− v8::String::Utf8Value methodNameStr(isolate, trans.value().name.constGet());
440− //qCDebug(scriptengine_v8) << "queryProperty : " << *nameStr << " method: " << *methodNameStr;
441− if (!(trans.value().name == name)) continue;
442− *id = trans.key() | METHOD_TYPE;
443− return flags & (HandlesReadAccess | HandlesWriteAccess);
444− }*/
445398 MethodNameMap::const_iterator method = _methodNameMap.find(nameStr);
446399 if (method != _methodNameMap.cend()) {
447− //v8::String::Utf8Value methodNameStr(isolate, trans.value().name.constGet());
448− //qCDebug(scriptengine_v8) << "queryProperty : " << *nameStr << " method: " << *methodNameStr;
449400 const MethodDef* methodDef = method.value();
450401 *id = methodDef->_id | METHOD_TYPE;
451402 return flags & (HandlesReadAccess | HandlesWriteAccess);
452403 }
453404
454405 // check for properties
455− /*for (PropertyDefMap::const_iterator trans = _props.cbegin(); trans != _props.cend(); ++trans) {
456− const PropertyDef& propDef = trans.value();
457− if (!(propDef.name == name)) continue;
458− *id = trans.key() | PROPERTY_TYPE;
459− return flags & (HandlesReadAccess | HandlesWriteAccess);
460− }*/
461406 PropertyNameMap::const_iterator prop = _propNameMap.find(nameStr);
462407 if (prop != _propNameMap.cend()) {
463408 const PropertyDef* propDef = prop.value();
@@ -505,9 +450,7 @@ ScriptValue::PropertyFlags ScriptObjectV8Proxy::propertyFlags(const V8ScriptValu · 41 unmodified lines
505450
506451 void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
507452 v8::HandleScope handleScope(info.GetIsolate());
508− //V8TODO: should there be a context scope here?
509453 v8::String::Utf8Value utf8Value(info.GetIsolate(), name);
510− //qCDebug(scriptengine_v8) << "Get: " << *utf8Value;
511454 v8::Local<v8::Value> objectV8 = info.This();
512455 ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(info.GetIsolate(), objectV8);
513456 if (!proxy) {
@@ -521,17 +464,7 @@ void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCall · 7 unmodified lines
521464 Q_ASSERT(false);
522465 }
523466 v8::Local<v8::String> v8NameString;
524− /*if (name->IsString()) {
525− v8NameString = v8::Local<v8::String>::Cast(name);
526− } else {
527− if (!name->ToString(info.GetIsolate()->GetCurrentContext()).ToLocal(&v8NameString)) {
528− Q_ASSERT(false);
529− }
530− }
531467
532− if (name->IsSymbol()) {
533− qCDebug(scriptengine_v8) << "ScriptObjectV8Proxy::v8Set: symbol: " + nameString.toQString();
534− }*/
535468 if (name->IsString()) {
536469 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
537470 uint id;
@@ -553,9 +486,7 @@ void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCall · 15 unmodified lines
553486
554487 void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
555488 v8::HandleScope handleScope(info.GetIsolate());
556− //V8TODO: should there be a context scope here?
557489 v8::String::Utf8Value utf8Value(info.GetIsolate(), name);
558− //qCDebug(scriptengine_v8) << "Set: " << *utf8Value;
559490 v8::Local<v8::Value> objectV8 = info.This();
560491 ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(info.GetIsolate(), objectV8);
561492 if (!proxy) {
@@ -568,18 +499,7 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v · 6 unmodified lines
568499 qCDebug(scriptengine_v8) << notStringMessage;
569500 Q_ASSERT(false);
570501 }
571− /*v8::Local<v8::String> v8NameString;
572− if (name->IsString()) {
573− v8NameString = v8::Local<v8::String>::Cast(name);
574− } else {
575− if (!name->ToString(info.GetIsolate()->GetCurrentContext()).ToLocal(&v8NameString)) {
576− Q_ASSERT(false);
577− }
578− }
579− if (name->IsSymbol()) {
580− qCDebug(scriptengine_v8) << "ScriptObjectV8Proxy::v8Set: symbol: " + nameString.toQString();
581− }*/
582− //V8ScriptString nameString(info.GetIsolate(), name->ToString(proxy->_engine->getContext()).ToLocalChecked());
502+
583503 if (name->IsString()) {
584504 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
585505 uint id;
@@ -590,7 +510,7 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v · 4 unmodified lines
590510 return;
591511 }
592512 }
593− // V8TODO: Should it be v8::Object or v8::Local<v8::Object>?
513+
594514 if (info.This()->GetInternalField(2).As<v8::Object>()->Set(proxy->_engine->getContext(), name, value).FromMaybe(false)) {
595515 info.GetReturnValue().Set(value);
596516 } else {
@@ -599,7 +519,6 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v · 2 unmodified lines
599519 }
600520
601521 void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) {
602− //qCDebug(scriptengine_v8) << "ScriptObjectV8Proxy::v8GetPropertyNames called";
603522 v8::HandleScope handleScope(info.GetIsolate());
604523 auto context = info.GetIsolate()->GetCurrentContext();
605524 v8::Context::Scope contextScope(context);
@@ -610,7 +529,6 @@ void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8:: · 4 unmodified lines
610529 return;
611530 }
612531 V8ScriptValue object(proxy->_engine, objectV8);
613− //uint id;
614532 v8::Local<v8::Array> properties = proxy->getPropertyNames();
615533 v8::Local<v8::Array> objectProperties;
616534 uint32_t propertiesLength = properties->Length();
@@ -695,7 +613,6 @@ V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V · 78 unmodified lines
695613 qCDebug(scriptengine_v8) << "Method with QMetaType::UnknownType " << metaObject->className() << " " << (*iter).name();
696614 }
697615 } //V8TODO: is new method created during every call? It needs to be cached instead
698− //bool isMethodDefined = false;
699616 v8::Local<v8::Value> property;
700617 if(_v8Object.Get(isolate)->GetInternalField(2).As<v8::Object>()->Get(_engine->getContext(), name.constGet()).ToLocal(&property)) {
701618 if (!property->IsUndefined()) {
@@ -725,7 +642,6 @@ V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V · 23 unmodified lines
725642 // It's not necessarily new, newQObject looks for it first in object wrapper map
726643 // V8TODO: won't ScriptEngine::ScriptOwnership cause trouble here?
727644 return ScriptObjectV8Proxy::newQObject(_engine, proxy, ScriptEngine::ScriptOwnership, options);
728− //return _engine->newQObject(proxy, ScriptEngine::ScriptOwnership, options);
729645 }
730646 }
731647 return V8ScriptValue(_engine, v8::Null(isolate));
@@ -777,8 +693,6 @@ ScriptVariantV8Proxy::ScriptVariantV8Proxy(ScriptEngineV8* engine, const QVarian · 45 unmodified lines
777693 v8::HandleScope handleScope(isolate);
778694 v8::Context::Scope contextScope(engine->getContext());
779695 auto variantDataTemplate = _engine->getVariantDataTemplate();
780− //auto variantDataTemplate = v8::ObjectTemplate::New(isolate);
781− //variantDataTemplate->SetInternalFieldCount(2);
782696 auto variantData = variantDataTemplate->NewInstance(engine->getContext()).ToLocalChecked();
783697 variantData->SetAlignedPointerInInternalField(0, const_cast<void*>(internalPointsToQVariantInProxy));
784698 // Internal field doesn't point directly to QVariant, because then alignment would need to be guaranteed in all compilers
@@ -793,7 +707,6 @@ ScriptVariantV8Proxy::~ScriptVariantV8Proxy() { · 8 unmodified lines
793707 v8::Isolate::Scope isolateScope(isolate);
794708 v8::HandleScope handleScope(isolate);
795709 // V8TODO: Add similar deletion handling as for object proxy
796− //_v8ObjectTemplate.Reset();
797710 _v8Object.Reset();
798711 }
799712
@@ -814,9 +727,6 @@ V8ScriptValue ScriptVariantV8Proxy::newVariant(ScriptEngineV8* engine, const QVa · 14 unmodified lines
814727 auto proxy = new ScriptVariantV8Proxy(engine, variant, proto, protoProxy);
815728
816729 auto variantProxyTemplate = engine->getVariantProxyTemplate();
817− //auto variantProxyTemplate = v8::ObjectTemplate::New(isolate);
818− //variantProxyTemplate->SetInternalFieldCount(2);
819− //variantProxyTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set, nullptr, nullptr, v8GetPropertyNames));
820730 auto variantProxy = variantProxyTemplate->NewInstance(engine->getContext()).ToLocalChecked();
821731 variantProxy->SetAlignedPointerInInternalField(0, const_cast<void*>(internalPointsToQVariantProxy));
822732 variantProxy->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(proxy));
@@ -905,13 +815,6 @@ void ScriptVariantV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCal · 82 unmodified lines
905815 }
906816
907817 qCDebug(scriptengine_v8) << "Value not found: " << *utf8Name;
908− // V8TODO: this is done differently for variant proxy - use internal field of _v8Object instead?
909− /*v8::Local<v8::Value> property;
910− if(info.This()->GetInternalField(2).As<v8::Object>()->Get(proxy->_engine->getContext(), name).ToLocal(&property)) {
911− info.GetReturnValue().Set(property);
912− } else {
913− qCDebug(scriptengine_v8) << "Value not found: " << *utf8Value;
914− }*/
915818 }
916819
917820 void ScriptVariantV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
@@ -941,18 +844,11 @@ void ScriptVariantV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> · 23 unmodified lines
941844 return;
942845 }
943846 }
944− // V8TODO: this is done differently for variant proxy - use internal field of _v8Object instead?
945− /*if (info.This()->GetInternalField(2).As<v8::Object>()->Set(proxy->_engine->getContext(), name, value).FromMaybe(false)) {
946− info.GetReturnValue().Set(value);
947− } else {
948− qCDebug(scriptengine_v8) << "Set failed: " << *utf8Name;
949− }*/
950847 qCDebug(scriptengine_v8) << "Set failed: " << *utf8Name;
951848 }
952849
953850 void ScriptVariantV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) {
954851 //V8TODO: Only methods from the prototype should be listed.
955− //qCDebug(scriptengine_v8) << "ScriptObjectV8Proxy::v8GetPropertyNames called";
956852 v8::HandleScope handleScope(info.GetIsolate());
957853 auto context = info.GetIsolate()->GetCurrentContext();
958854 v8::Context::Scope contextScope(context);
@@ -965,15 +861,6 @@ void ScriptVariantV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8: · 6 unmodified lines
965861 V8ScriptValue object(proxy->_engine, objectV8);
966862 v8::Local<v8::Array> properties = proxy->_proto->getPropertyNames();
967863 v8::Local<v8::Array> objectProperties;
968− // V8TODO: this is done differently for variant proxy - use internal field of _v8Object instead?
969− /*uint32_t propertiesLength = properties->Length();
970− if (info.This()->GetInternalField(2).As<v8::Object>()->GetPropertyNames(context).ToLocal(&objectProperties)) {
971− for (uint32_t n = 0; n < objectProperties->Length(); n++) {
972− if(!properties->Set(context, propertiesLength+n, objectProperties->Get(context, n).ToLocalChecked()).FromMaybe(false)) {
973− qCDebug(scriptengine_v8) << "ScriptObjectV8Proxy::v8GetPropertyNames: Cannot add member name";
974− }
975− }
976− }*/
977864 info.GetReturnValue().Set(properties);
978865 }
979866
@@ -996,7 +883,6 @@ ScriptMethodV8Proxy::ScriptMethodV8Proxy(ScriptEngineV8* engine, QObject* object · 16 unmodified lines
996883 }
997884
998885 ScriptMethodV8Proxy::~ScriptMethodV8Proxy() {
999− //qCDebug(scriptengine_v8) << "ScriptMethodV8Proxy destroyed";
1000886 auto isolate = _engine->getIsolate();
1001887 v8::Locker locker(isolate);
1002888 v8::Isolate::Scope isolateScope(isolate);
@@ -1005,7 +891,6 @@ ScriptMethodV8Proxy::~ScriptMethodV8Proxy() { · 2 unmodified lines
1005891 }
1006892
1007893 void ScriptMethodV8Proxy::weakHandleCallback(const v8::WeakCallbackInfo<ScriptMethodV8Proxy>& info) {
1008− //qDebug(scriptengine_v8) << "ScriptMethodV8Proxy::weakHandleCallback";
1009894 auto proxy = info.GetParameter();
1010895 proxy->_objectLifetime.Reset();
1011896 info.GetParameter()->deleteLater();
@@ -1019,12 +904,8 @@ V8ScriptValue ScriptMethodV8Proxy::newMethod(ScriptEngineV8* engine, QObject* ob · 7 unmodified lines
1019904 v8::HandleScope handleScope(isolate);
1020905 v8::Context::Scope contextScope(engine->getContext());
1021906 auto methodDataTemplate = engine->getMethodDataTemplate();
1022− //auto methodDataTemplate = v8::ObjectTemplate::New(isolate);
1023− //methodDataTemplate->SetInternalFieldCount(2);
1024907 auto methodData = methodDataTemplate->NewInstance(engine->getContext()).ToLocalChecked();
1025908 methodData->SetAlignedPointerInInternalField(0, const_cast<void*>(internalPointsToMethodProxy));
1026− // V8TODO it needs to be deleted somehow on object destruction
1027− // weak persistent callback would do this
1028909 methodData->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(new ScriptMethodV8Proxy(engine, object, lifetime, metas, numMaxParams)));
1029910 auto v8Function = v8::Function::New(engine->getContext(), callback, methodData, numMaxParams).ToLocalChecked();
1030911 return V8ScriptValue(engine, v8Function);
@@ -1042,31 +923,16 @@ QString ScriptMethodV8Proxy::fullName() const { · 11 unmodified lines
1042923 return QString("%1::%2").arg(_object->metaObject()->className(), firstMethod.name());
1043924 }
1044925
1045−// V8TODO
1046−/*bool ScriptMethodV8Proxy::supportsExtension(Extension extension) const {
1047− switch (extension) {
1048− case Callable:
1049− return true;
1050− default:
1051− return false;
1052− }
1053−}*/
1054−
1055926 void ScriptMethodV8Proxy::callback(const v8::FunctionCallbackInfo<v8::Value>& arguments) {
1056927 v8::Locker locker(arguments.GetIsolate());
1057928 v8::Isolate::Scope isolateScope(arguments.GetIsolate());
1058929 v8::HandleScope handleScope(arguments.GetIsolate());
1059− //Q_ASSERT(!arguments.GetIsolate()->GetCurrentContext().IsEmpty());
1060930 v8::Context::Scope contextScope(arguments.GetIsolate()->GetCurrentContext());
1061931 if (!arguments.Data()->IsObject()) {
1062932 arguments.GetIsolate()->ThrowError("Method value is not an object");
1063933 return;
1064934 }
1065935 v8::Local<v8::Object> data = v8::Local<v8::Object>::Cast(arguments.Data());
1066− /*if (!arguments.Data()->IsCallable()) {
1067− arguments.GetIsolate()->ThrowError("Method value is not callable");
1068− return;
1069− }*/
1070936 if (data->InternalFieldCount() != 2) {
1071937 arguments.GetIsolate()->ThrowError("Incorrect number of internal fields during method call");
1072938 return;
@@ -1092,8 +958,6 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 19 unmodified lines
1092958 return;
1093959 }
1094960
1095− //v8::HandleScope handleScope(_engine->getIsolate());
1096−
1097961 int scriptNumArgs = arguments.Length();
1098962 int numArgs = std::min(scriptNumArgs, _numMaxParams);
1099963
@@ -1113,7 +977,6 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 13 unmodified lines
1113977 int bestMeta = 0;
1114978 int bestConversionPenaltyScore = 0;
1115979
1116−
1117980 for (int i = 0; i < num_metas; i++) {
1118981 const QMetaMethod& meta = _metas[i];
1119982 int methodNumArgs = meta.parameterCount();
@@ -1208,16 +1071,6 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 88 unmodified lines
12081071 return;
12091072 } else if (returnTypeId == scriptValueTypeId) {
12101073 ScriptValue result;
1211− /*if (_metas.front().name() == "createGarbageCollectorDebuggingObject") {
1212− //qDebug() << "createGarbageCollectorDebuggingObject";
1213− return;
1214− }*/
1215− /*const char* typeName = meta.typeName();
1216− QVariant qRetVal(returnTypeId, static_cast<void*>(NULL));
1217− QGenericReturnArgument sRetVal(typeName, const_cast<void*>(qRetVal.constData()));
1218− bool success = meta.invoke(qobject, Qt::DirectConnection, sRetVal, qGenArgs[0],
1219− qGenArgs[1], qGenArgs[2], qGenArgs[3], qGenArgs[4], qGenArgs[5], qGenArgs[6],
1220− qGenArgs[7], qGenArgs[8], qGenArgs[9]);*/
12211074 bool success = meta.invoke(qobject, Qt::DirectConnection, Q_RETURN_ARG(ScriptValue, result), qGenArgs[0],
12221075 qGenArgs[1], qGenArgs[2], qGenArgs[3], qGenArgs[4], qGenArgs[5], qGenArgs[6],
12231076 qGenArgs[7], qGenArgs[8], qGenArgs[9]);
@@ -1226,7 +1079,6 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 2 unmodified lines
12261079 return;
12271080 }
12281081 V8ScriptValue v8Result = ScriptValueV8Wrapper::fullUnwrap(_engine, result);
1229− //V8ScriptValue v8Result = _engine->castVariantToValue(qRetVal);
12301082 arguments.GetReturnValue().Set(v8Result.get());
12311083 return;
12321084 } else {
@@ -1271,8 +1123,6 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 38 unmodified lines
12711123 .arg(fullName()).arg(arg+1).arg(argTypeName, methodTypeName);
12721124 qCDebug(scriptengine_v8) << errorMessage << "\n Backtrace:" << _engine->currentContext()->backtrace();
12731125 isolate->ThrowError(v8::String::NewFromUtf8(isolate, errorMessage.toStdString().c_str()).ToLocalChecked());
1274− //context->throwError(V8ScriptContext::TypeError, QString("Native call of %1 failed: Cannot convert parameter %2 from %3 to %4")
1275− // .arg(fullName()).arg(arg+1).arg(argTypeName, methodTypeName));
12761126 return;
12771127 }
12781128 }
@@ -1280,179 +1130,10 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 1 unmodified line
12801130 QString errorMessage = QString("Native call of %1 failed: could not locate an overload with the requested arguments").arg(fullName());
12811131 qCDebug(scriptengine_v8) << errorMessage;
12821132 isolate->ThrowError(v8::String::NewFromUtf8(isolate, errorMessage.toStdString().c_str()).ToLocalChecked());
1283− // V8TODO: it happens sometimes for some reason
12841133 Q_ASSERT(false); // really shouldn't have gotten here -- it didn't work before and it's working now?
12851134 return;
12861135 }
12871136
1288−//V8TODO: was this used anywhere?
1289−/*QVariant ScriptMethodV8Proxy::extension(Extension extension, const QVariant& argument) {
1290− if (extension != Callable) return QVariant();
1291− V8ScriptContext* context = qvariant_cast<V8ScriptContext*>(argument);
1292−
1293− QObject* qobject = _object;
1294− if (!qobject) {
1295− context->throwError(V8ScriptContext::ReferenceError, "Referencing deleted native object");
1296− return QVariant();
1297− }
1298−
1299− int scriptNumArgs = context->argumentCount();
1300− int numArgs = std::min(scriptNumArgs, _numMaxParams);
1301−
1302− const int scriptValueTypeId = qMetaTypeId<ScriptValue>();
1303−
1304− int parameterConversionFailureId = 0;
1305− int parameterConversionFailureCount = 0;
1306−
1307− int num_metas = _metas.size();
1308− QVector< QList<ScriptValue> > qScriptArgLists;
1309− QVector< QVector <QGenericArgument> > qGenArgsVectors;
1310− QVector< QList<QVariant> > qVarArgLists;
1311− qScriptArgLists.resize(num_metas);
1312− qGenArgsVectors.resize(num_metas);
1313− qVarArgLists.resize(num_metas);
1314− bool isValidMetaSelected = false;
1315− int bestMeta = 0;
1316− int bestConversionPenaltyScore = 0;
1317−
1318− for (int i = 0; i < num_metas; i++) {
1319− const QMetaMethod& meta = _metas[i];
1320− int methodNumArgs = meta.parameterCount();
1321− if (methodNumArgs != numArgs) {
1322− continue;
1323− }
1324−
1325− qGenArgsVectors[i].resize(10);
1326− int conversionPenaltyScore = 0;
1327− int conversionFailures = 0;
1328−
1329− for (int arg = 0; arg < numArgs; ++arg) {
1330− int methodArgTypeId = meta.parameterType(arg);
1331− Q_ASSERT(methodArgTypeId != QMetaType::UnknownType);
1332− V8ScriptValue argVal = context->argument(arg);
1333− if (methodArgTypeId == scriptValueTypeId) {
1334− qScriptArgLists[i].append(ScriptValue(new ScriptValueV8Wrapper(_engine, argVal)));
1335− qGenArgsVectors[i][arg] = Q_ARG(ScriptValue, qScriptArgLists[i].back());
1336− } else if (methodArgTypeId == QMetaType::QVariant) {
1337− qVarArgLists[i].append(argVal.toVariant());
1338− qGenArgsVectors[i][arg] = Q_ARG(QVariant, qVarArgLists[i].back());
1339− } else {
1340− QVariant varArgVal;
1341− if (!_engine->castValueToVariant(argVal, varArgVal, methodArgTypeId)) {
1342− conversionFailures++;
1343− } else {
1344− qVarArgLists[i].append(varArgVal);
1345− const QVariant& converted = qVarArgLists[i].back();
1346− conversionPenaltyScore = _engine->computeCastPenalty(argVal, methodArgTypeId);
1347−
1348− // a lot of type conversion assistance thanks to https://stackoverflow.com/questions/28457819/qt-invoke-method-with-qvariant
1349− // A const_cast is needed because calling data() would detach the QVariant.
1350− qGenArgsVectors[i][arg] =
1351− QGenericArgument(QMetaType::typeName(converted.userType()), const_cast<void*>(converted.constData()));
1352− }
1353− }
1354− }
1355− if (conversionFailures) {
1356− if (conversionFailures < parameterConversionFailureCount || !parameterConversionFailureCount) {
1357− parameterConversionFailureCount = conversionFailures;
1358− parameterConversionFailureId = meta.methodIndex();
1359− }
1360− continue;
1361− }
1362−
1363− if (!isValidMetaSelected) {
1364− isValidMetaSelected = true;
1365− bestMeta = i;
1366− bestConversionPenaltyScore = conversionPenaltyScore;
1367− }
1368− if (isValidMetaSelected && bestConversionPenaltyScore > conversionPenaltyScore) {
1369− bestMeta = i;
1370− bestConversionPenaltyScore = conversionPenaltyScore;
1371− }
1372− }
1373−
1374− if (isValidMetaSelected) {
1375− ScriptContextV8Wrapper ourContext(_engine, context);
1376− ScriptContextGuard guard(&ourContext);
1377− const QMetaMethod& meta = _metas[bestMeta];
1378− int returnTypeId = meta.returnType();
1379− QVector <QGenericArgument> &qGenArgs = qGenArgsVectors[bestMeta];
1380−
1381− // The Qt MOC engine will automatically call qRegisterMetaType on invokable parameters and properties, but there's
1382− // nothing in there for return values so these need to be explicitly runtime-registered!
1383− Q_ASSERT(returnTypeId != QMetaType::UnknownType);
1384− if (returnTypeId == QMetaType::UnknownType) {
1385− _engine->getIsolate()->ThrowError(v8::String::NewFromUtf8(_engine->getIsolate(), QString("Cannot call native function %1, its return value has not been registered with Qt").arg(fullName()).toStdString().c_str()).ToLocalChecked());
1386− return QVariant();
1387− } else if (returnTypeId == QMetaType::Void) {
1388− bool success = meta.invoke(qobject, Qt::DirectConnection, qGenArgs[0], qGenArgs[1], qGenArgs[2], qGenArgs[3],
1389− qGenArgs[4], qGenArgs[5], qGenArgs[6], qGenArgs[7], qGenArgs[8], qGenArgs[9]);
1390− if (!success) {
1391− _engine->getIsolate()->ThrowError(v8::String::NewFromUtf8(_engine->getIsolate(), QString("Unexpected: Native call of %1 failed").arg(fullName()).toStdString().c_str()).ToLocalChecked());
1392− }
1393− return QVariant();
1394− } else if (returnTypeId == scriptValueTypeId) {
1395− ScriptValue result;
1396− bool success = meta.invoke(qobject, Qt::DirectConnection, Q_RETURN_ARG(ScriptValue, result), qGenArgs[0],
1397− qGenArgs[1], qGenArgs[2], qGenArgs[3], qGenArgs[4], qGenArgs[5], qGenArgs[6],
1398− qGenArgs[7], qGenArgs[8], qGenArgs[9]);
1399− if (!success) {
1400− _engine->getIsolate()->ThrowError(v8::String::NewFromUtf8(_engine->getIsolate(), QString("Unexpected: Native call of %1 failed").arg(fullName()).toStdString().c_str()).ToLocalChecked());
1401− return QVariant();
1402− }
1403− V8ScriptValue qResult = ScriptValueV8Wrapper::fullUnwrap(_engine, result);
1404− return QVariant::fromValue(qResult);
1405− } else {
1406− // a lot of type conversion assistance thanks to https://stackoverflow.com/questions/28457819/qt-invoke-method-with-qvariant
1407− const char* typeName = meta.typeName();
1408− QVariant qRetVal(returnTypeId, static_cast<void*>(NULL));
1409− QGenericReturnArgument sRetVal(typeName, const_cast<void*>(qRetVal.constData()));
1410−
1411− bool success =
1412− meta.invoke(qobject, Qt::DirectConnection, sRetVal, qGenArgs[0], qGenArgs[1], qGenArgs[2], qGenArgs[3],
1413− qGenArgs[4], qGenArgs[5], qGenArgs[6], qGenArgs[7], qGenArgs[8], qGenArgs[9]);
1414− if (!success) {
1415− _engine->getIsolate()->ThrowError(v8::String::NewFromUtf8(_engine->getIsolate(), QString("Unexpected: Native call of %1 failed").arg(fullName()).toStdString().c_str()).ToLocalChecked());
1416− return QVariant();
1417− }
1418− V8ScriptValue qResult = _engine->castVariantToValue(qRetVal);
1419− return QVariant::fromValue(qResult);
1420− }
1421− }
1422−
1423− // we failed to convert the call to C++, try to create a somewhat sane error message
1424− if (parameterConversionFailureCount == 0) {
1425− _engine->getIsolate()->ThrowError(v8::String::NewFromUtf8(_engine->getIsolate(), QString("Native call of %1 failed: unexpected parameter count").arg(fullName()).toStdString().c_str()).ToLocalChecked());
1426− return QVariant();
1427− }
1428−
1429− const QMetaMethod& meta = _object->metaObject()->method(parameterConversionFailureId);
1430− int methodNumArgs = meta.parameterCount();
1431− Q_ASSERT(methodNumArgs == numArgs);
1432−
1433− for (int arg = 0; arg < numArgs; ++arg) {
1434− int methodArgTypeId = meta.parameterType(arg);
1435− Q_ASSERT(methodArgTypeId != QMetaType::UnknownType);
1436− V8ScriptValue argVal = context->argument(arg);
1437− if (methodArgTypeId != scriptValueTypeId && methodArgTypeId != QMetaType::QVariant) {
1438− QVariant varArgVal;
1439− if (!_engine->castValueToVariant(argVal, varArgVal, methodArgTypeId)) {
1440− QByteArray methodTypeName = QMetaType(methodArgTypeId).name();
1441− QByteArray argTypeName = _engine->valueType(argVal).toLatin1();
1442− _engine->getIsolate()->ThrowError(v8::String::NewFromUtf8(_engine->getIsolate(), QString("Native call of %1 failed: Cannot convert parameter %2 from %3 to %4")
1443− .arg(fullName()).arg(arg+1).arg(argTypeName, methodTypeName).toStdString().c_str()).ToLocalChecked());
1444− context->throwError(V8ScriptContext::TypeError, QString("Native call of %1 failed: Cannot convert parameter %2 from %3 to %4")
1445− .arg(fullName()).arg(arg+1).arg(argTypeName, methodTypeName));
1446− return QVariant();
1447− }
1448− }
1449− }
1450−
1451− context->throwError(QString("Native call of %1 failed: could not locate an overload with the requested arguments").arg(fullName()));
1452− Q_ASSERT(false); // really shouldn't have gotten here -- it didn't work before and it's working now?
1453− return QVariant();
1454−}*/
1455−
14561137 ScriptSignalV8Proxy::ScriptSignalV8Proxy(ScriptEngineV8* engine, QObject* object, V8ScriptValue lifetime, const QMetaMethod& meta) :
14571138 _engine(engine), _object(object), _meta(meta), _metaCallId(discoverMetaCallIdx()) {
14581139 auto isolate = _engine->getIsolate();
@@ -1475,7 +1156,6 @@ ScriptSignalV8Proxy::~ScriptSignalV8Proxy() { · 16 unmodified lines
14751156 }
14761157
14771158 void ScriptSignalV8Proxy::weakHandleCallback(const v8::WeakCallbackInfo<ScriptSignalV8Proxy>& info) {
1478− //qDebug(scriptengine_v8) << "ScriptSignalV8Proxy::weakHandleCallback";
14791159 auto proxy = info.GetParameter();
14801160 proxy->_objectLifetime.Reset();
14811161 proxy->deleteLater();
@@ -1512,17 +1192,6 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu · 30 unmodified lines
15121192 v8::Locker locker(isolate);
15131193 v8::Isolate::Scope isolateScope(isolate);
15141194
1515− //V8ScriptValueList args(isolate, v8::Null(isolate));
1516− // Moved to inside of the lock - could it cause crashes if left here?
1517− /*v8::Local<v8::Value> args[Q_METAMETHOD_INVOKE_MAX_ARGS];
1518− int numArgs = _meta.parameterCount();
1519− for (int arg = 0; arg < numArgs; ++arg) {
1520− int methodArgTypeId = _meta.parameterType(arg);
1521− Q_ASSERT(methodArgTypeId != QMetaType::UnknownType);
1522− QVariant argValue(methodArgTypeId, arguments[arg+1]);
1523− args[arg] = _engine->castVariantToValue(argValue).get();
1524− }*/
1525−
15261195 QList<Connection> connections;
15271196 withReadLock([&]{
15281197 connections = _connections;
@@ -1530,9 +1199,7 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu · 1 unmodified line
15301199
15311200 // V8TODO: this may cause deadlocks on connect/disconnect, so the connect/disconnect procedure needs to be reworked.
15321201 // It should probably add events to a separate list that would be processed before and after all the events for the signal.
1533− //withReadLock([&]{
15341202 {
1535− // V8TODO: check all other lambda functions to make sure they have handle scope - could they cause crashes otherwise?
15361203 v8::HandleScope handleScope(isolate);
15371204 // V8TODO: should we use function creation context, or context in which connect happened?
15381205 auto context = _engine->getContext();
@@ -1545,23 +1212,9 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu · 6 unmodified lines
15451212 QVariant argValue(methodArgTypeId, arguments[arg + 1]);
15461213 args[arg] = _engine->castVariantToValue(argValue).get();
15471214 }
1548− //for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) {
15491215 for (ConnectionList::iterator iter = connections.begin(); iter != connections.end(); ++iter) {
15501216 Connection& conn = *iter;
15511217 {
1552− /*if (!conn.callback.get()->IsFunction()) {
1553− auto stringV8 = conn.callback.get()->ToDetailString(context).ToLocalChecked();
1554− QString error = *v8::String::Utf8Value(_engine->getIsolate(), stringV8);
1555− qCDebug(scriptengine_v8) << error;
1556− Q_ASSERT(false);
1557− }
1558− v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
1559− auto functionContext = callback->CreationContext();
1560− v8::Context::Scope functionContextScope(functionContext);
1561− _engine->pushContext(functionContext);*/
1562− /*auto functionContext = _v8Context.Get(_engine->getIsolate());
1563− _engine->pushContext(functionContext);
1564− v8::Context::Scope functionContextScope(functionContext);*/
15651218 auto functionContext = context;
15661219
15671220 Q_ASSERT(!conn.callback.get().IsEmpty());
@@ -1595,11 +1248,9 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu · 27 unmodified lines
15951248
15961249 _engine->setUncaughtException(tryCatch, "Error in signal proxy");
15971250 }
1598− //_engine->popContext();
15991251 }
16001252 }
16011253 }
1602− //});
16031254
16041255 #ifdef SCRIPT_EVENT_PERFORMANCE_STATISTICS
16051256 _totalCallTime_s += callTimer.elapsed() / 1000.0f;
@@ -1630,10 +1281,6 @@ ScriptSignalV8Proxy::ConnectionList::iterator ScriptSignalV8Proxy::findConnectio · 24 unmodified lines
16301281 return iterOut;
16311282 }
16321283
1633−/*void ScriptSignalV8Proxy::connect(ScriptValue arg0) {
1634− connect(arg0, ScriptValue(_engine->getIsolate(), v8::Undefined(_engine->getIsolate())));
1635−}*/
1636−
16371284 void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) {
16381285 v8::Isolate *isolate = _engine->getIsolate();
16391286 v8::Locker locker(isolate);
@@ -1646,8 +1293,6 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) { · 6 unmodified lines
16461293 return;
16471294 }
16481295
1649− //v8::HandleScope handleScope(isolate);
1650−
16511296 // untangle the arguments
16521297 V8ScriptValue callback(_engine, v8::Null(isolate));
16531298 V8ScriptValue callbackThis(_engine, v8::Null(isolate));
@@ -1697,15 +1342,12 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) { · 43 unmodified lines
16971342 ScriptSignalV8Proxy* thisProxy = dynamic_cast<ScriptSignalV8Proxy*>(ScriptObjectV8Proxy::unwrapProxy(v8ThisObject)->toQObject());
16981343 Q_ASSERT(thisProxy);
16991344 qCDebug(scriptengine_v8) << "ScriptSignalV8Proxy::connect: " << thisProxy->fullName() << " fullName: " << fullName();
1700− //Q_ASSERT(destFunction->InternalFieldCount() == 4);
1701− //Q_ASSERT(destData.get()->IsArray());
1702− //v8::Local<v8::Value> destData = destFunction->GetInternalField(3);
17031345 if (!destFunction->Get(destFunctionContext, destDataName).ToLocal(&destData)) {
17041346 Q_ASSERT(false);
17051347 }
17061348 if (destData->IsArray()) {
17071349 v8::Local<v8::Array> destArray = v8::Local<v8::Array>::Cast(destData);
1708− int length = destArray->Length();//destData.property("length").toInteger();
1350+ int length = destArray->Length();
17091351 // V8TODO: Maybe copying array is unnecessary?
17101352 v8::Local<v8::Array> newArray = v8::Array::New(isolate, length + 1);
17111353 bool foundIt = false;
@@ -1726,7 +1368,6 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) { · 14 unmodified lines
17261368 }
17271369 }
17281370 if (!newArray->Set(destFunctionContext, length, v8ThisObject.get()).FromMaybe(false)) {
1729− //if (!newArray->Set(destFunctionContext, length, v8ThisObject.get()).FromMaybe(false)) {
17301371 Q_ASSERT(false);
17311372 }
17321373 if (!destFunction->Set(destFunctionContext, destDataName, newArray).FromMaybe(false)) {
@@ -1741,16 +1382,9 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) { · 8 unmodified lines
17411382 Q_ASSERT(false);
17421383 }
17431384 }
1744− /*{
1745− V8ScriptValueList args;
1746− args << thisObject();
1747− destData.property("push").call(destData, args);
1748− }*/
17491385
17501386 // add this to our internal list of connections
17511387 Connection newConnection(callbackThis, callback);
1752− //newConn.callback = callback;
1753− //newConn.thisValue = callbackThis;
17541388
17551389 withWriteLock([&]{
17561390 _connections.append(newConnection);
@@ -1764,10 +1398,6 @@ void ScriptSignalV8Proxy::connect(ScriptValue arg0, ScriptValue arg1) { · 7 unmodified lines
17641398 }
17651399 }
17661400
1767−/*void ScriptSignalV8Proxy::disconnect(ScriptValue arg0) {
1768− disconnect(arg0, V8ScriptValue(_engine->getIsolate(), v8::Undefined(_engine->getIsolate())));
1769−}*/
1770−
17711401 void ScriptSignalV8Proxy::disconnect(ScriptValue arg0, ScriptValue arg1) {
17721402 QObject* qobject = _object;
17731403 v8::Isolate *isolate = _engine->getIsolate();
@@ -1832,18 +1462,15 @@ void ScriptSignalV8Proxy::disconnect(ScriptValue arg0, ScriptValue arg1) { · 58 unmodified lines
18321462 ScriptSignalV8Proxy* thisProxy = dynamic_cast<ScriptSignalV8Proxy*>(ScriptObjectV8Proxy::unwrapProxy(v8ThisObject)->toQObject());
18331463 Q_ASSERT(thisProxy);
18341464 qCDebug(scriptengine_v8) << "ScriptSignalV8Proxy::disconnect: " << thisProxy->fullName() << " fullName: " << fullName();
1835− //V8ScriptValue destData = callback.data();
1836− //Q_ASSERT(destData->IsArray());
18371465 if (!destFunction->Get(destFunctionContext, destDataName).ToLocal(&destData)) {
18381466 Q_ASSERT(false);
18391467 }
18401468 if (destData->IsArray()) {
18411469 v8::Local<v8::Array> destArray = v8::Local<v8::Array>::Cast(destData);
1842− int length = destArray->Length();//destData.property("length").toInteger();
1470+ int length = destArray->Length();
18431471 v8::Local<v8::Array> newArray = v8::Array::New(isolate, length - 1);
18441472 bool foundIt = false;
18451473 int newIndex = 0;
1846− //for (int idx = 0; idx < length && !foundIt; ++idx) {
18471474 for (int idx = 0; idx < length; ++idx) {
18481475 v8::Local<v8::Value> entry = destArray->Get(destFunctionContext, idx).ToLocalChecked();
18491476 // For debugging:
@@ -1863,9 +1490,6 @@ void ScriptSignalV8Proxy::disconnect(ScriptValue arg0, ScriptValue arg1) { · 13 unmodified lines
18631490 //V8TODO: compare proxies instead?
18641491 foundIt = true;
18651492 qCDebug(scriptengine_v8) << "ScriptSignalV8Proxy::disconnect foundIt";
1866− //V8ScriptValueList args;
1867− //args << idx << 1;
1868− //destData.property("splice").call(destData, args);
18691493 } else {
18701494 if (!newArray->Set(destFunctionContext, newIndex, entry).FromMaybe(false)) {
18711495 Q_ASSERT(false);