Showing the changes to libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp (1 of 9 files). Show all
Unified · Split
| @@ -146,7 +146,9 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o · 145 unmodified lines | ||
| 146 | 146 | if (lookupV8 != enginePtr->_qobjectWrapperMapV8.end()) { |
| 147 | 147 | enginePtr->_qobjectWrapperMapV8.erase(lookupV8); |
| 148 | 148 | } |
| 149 | + qDebug() << "ScriptObjectV8Proxy::newQObject object deleted, object count: " << enginePtr->_qobjectWrapperMapV8.size(); | |
| 149 | 150 | }); |
| 151 | + //qDebug() << "ScriptObjectV8Proxy::newQObject object count: " << engine->_qobjectWrapperMapV8.size(); | |
| 150 | 152 | } |
| 151 | 153 | |
| 152 | 154 | return V8ScriptValue(engine, proxy.get()->toV8Value()); |
| @@ -373,6 +375,10 @@ void ScriptObjectV8Proxy::investigate() { · 220 unmodified lines | ||
| 373 | 375 | v8::Local<v8::Object> propertiesObject = v8::Object::New(_engine->getIsolate()); |
| 374 | 376 | v8Object->SetInternalField(2, propertiesObject); |
| 375 | 377 | _v8Object.Reset(_engine->getIsolate(), v8Object); |
| 378 | + if (_ownsObject) { | |
| 379 | + qDebug(scriptengine_v8) << "ScriptObjectV8Proxy::investigate SetWeak"; | |
| 380 | + _v8Object.SetWeak(this, weakHandleCallback, v8::WeakCallbackType::kParameter); | |
| 381 | + } | |
| 376 | 382 | |
| 377 | 383 | // Add all the methods objects as properties - this allows adding properties to a given method later. Is used by Script.request. |
| 378 | 384 | // V8TODO: Should these be deleted when the script-owned object is destroyed? It needs checking if script-owned objects will be garbage-collected, or will self-referencing prevent it. |
| @@ -383,7 +389,13 @@ void ScriptObjectV8Proxy::investigate() { · 4 unmodified lines | ||
| 383 | 389 | Q_ASSERT(false); |
| 384 | 390 | } |
| 385 | 391 | } |
| 392 | +} | |
| 386 | 393 | |
| 394 | +void ScriptObjectV8Proxy::weakHandleCallback(const v8::WeakCallbackInfo<ScriptObjectV8Proxy>& info) { | |
| 395 | + //V8TODO: does the object need to be moved to script engine thread? | |
| 396 | + //V8TODO: why does this never get called? | |
| 397 | + qDebug(scriptengine_v8) << "ScriptObjectV8Proxy::weakHandleCallback"; | |
| 398 | + info.GetParameter()->_object->deleteLater(); | |
| 387 | 399 | } |
| 388 | 400 | |
| 389 | 401 | QString ScriptObjectV8Proxy::name() const { |
| @@ -690,6 +702,7 @@ V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V · 300 unmodified lines | ||
| 690 | 702 | //V8TODO ScriptEngine::ExcludeDeleteLater | |
| 691 | 703 | ScriptEngine::PreferExistingWrapperObject; |
| 692 | 704 | // It's not necessarily new, newQObject looks for it first in object wrapper map |
| 705 | + // V8TODO: won't ScriptEngine::ScriptOwnership cause trouble here? | |
| 693 | 706 | return ScriptObjectV8Proxy::newQObject(_engine, proxy, ScriptEngine::ScriptOwnership, options); |
| 694 | 707 | //return _engine->newQObject(proxy, ScriptEngine::ScriptOwnership, options); |
| 695 | 708 | } |