History

Work on fixing V8 memory leaks, memory leak test

ksuprynowicz committed 3 years ago

Commit 42704ea1 parent f016a199 files · +46 −3Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp+13−0
@@ -146,7 +146,9 @@ V8ScriptValue ScriptObjectV8Proxy::newQObject(ScriptEngineV8* engine, QObject* o · 145 unmodified lines
146 if (lookupV8 != enginePtr->_qobjectWrapperMapV8.end()) {146 if (lookupV8 != enginePtr->_qobjectWrapperMapV8.end()) {
147 enginePtr->_qobjectWrapperMapV8.erase(lookupV8);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 return V8ScriptValue(engine, proxy.get()->toV8Value());154 return V8ScriptValue(engine, proxy.get()->toV8Value());
@@ -373,6 +375,10 @@ void ScriptObjectV8Proxy::investigate() { · 220 unmodified lines
373 v8::Local<v8::Object> propertiesObject = v8::Object::New(_engine->getIsolate());375 v8::Local<v8::Object> propertiesObject = v8::Object::New(_engine->getIsolate());
374 v8Object->SetInternalField(2, propertiesObject);376 v8Object->SetInternalField(2, propertiesObject);
375 _v8Object.Reset(_engine->getIsolate(), v8Object);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 // Add all the methods objects as properties - this allows adding properties to a given method later. Is used by Script.request.383 // Add all the methods objects as properties - this allows adding properties to a given method later. Is used by Script.request.
378 // 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.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 Q_ASSERT(false);389 Q_ASSERT(false);
384 }390 }
385 }391 }
392}
386 393
394void 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
389QString ScriptObjectV8Proxy::name() const {401QString ScriptObjectV8Proxy::name() const {
@@ -690,6 +702,7 @@ V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V · 300 unmodified lines
690 //V8TODO ScriptEngine::ExcludeDeleteLater |702 //V8TODO ScriptEngine::ExcludeDeleteLater |
691 ScriptEngine::PreferExistingWrapperObject;703 ScriptEngine::PreferExistingWrapperObject;
692 // It's not necessarily new, newQObject looks for it first in object wrapper map704 // It's not necessarily new, newQObject looks for it first in object wrapper map
705 // V8TODO: won't ScriptEngine::ScriptOwnership cause trouble here?
693 return ScriptObjectV8Proxy::newQObject(_engine, proxy, ScriptEngine::ScriptOwnership, options);706 return ScriptObjectV8Proxy::newQObject(_engine, proxy, ScriptEngine::ScriptOwnership, options);
694 //return _engine->newQObject(proxy, ScriptEngine::ScriptOwnership, options);707 //return _engine->newQObject(proxy, ScriptEngine::ScriptOwnership, options);
695 }708 }