static/emscripten/uno.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
New commits: commit 91842724235bca73690d67d8084ec7581512d791 Author: Stephan Bergmann <[email protected]> AuthorDate: Fri Aug 30 16:19:10 2024 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Sat Aug 31 08:29:23 2024 +0200 Explicitly .delete() type and interface objects in uno.js These objects use smart proxies, so Embind adds them to a JS finalizer (in JS runtimes where FinalizationRegistry is available), so it shouldn't be necessary to manually .delete() them, but Embind then emits "Embind found a leaked C++ instance..." warnings about them, which clutter the JS console. While it is probably impractical for client code to manually .delete() all such instances, we can at least explicitly .delete() those that occur in uno.js itself. Change-Id: Ia21ca5f0bdb246cc5ea272599befd9a16bc970a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172661 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/static/emscripten/uno.js b/static/emscripten/uno.js index fb634cc63c9d..6591a7441220 100644 --- a/static/emscripten/uno.js +++ b/static/emscripten/uno.js @@ -46,7 +46,10 @@ Module.unoObject = function(interfaces, obj) { obj.impl_interfaces[obj.impl_typemap[i]])); } } - return new Module.uno_Any(Module.uno_Type.Void(), undefined); + const ty = Module.uno_Type.Void(); + const ret = new Module.uno_Any(ty, undefined); + ty.delete(); + return ret; }; obj.acquire = function() { ++obj.impl_refcount; }; obj.release = function() { @@ -59,7 +62,9 @@ Module.unoObject = function(interfaces, obj) { obj.getTypes = function() { const types = new Module.uno_Sequence_type(interfaces.length, Module.uno_Sequence.FromSize); for (let i = 0; i !== interfaces.length; ++i) { - types.set(i, Module.uno_Type.Interface(interfaces[i])); + const type = Module.uno_Type.Interface(interfaces[i]); + types.set(i, type); + type.delete(); } return types; }; @@ -76,23 +81,32 @@ Module.unoObject = function(interfaces, obj) { throw new Error('not a UNO interface type: ' + name); } obj.impl_typemap[name] = impl; - const bases = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2.query(td) - .getBaseTypes(); + const itd = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2.query(td); + const bases = itd.getBaseTypes(); + itd.delete(); for (let i = 0; i !== bases.size(); ++i) { walk(bases.get(i), impl); } bases.delete(); } + td.delete(); }; - const tdmAny = Module.getUnoComponentContext().getValueByName( + const ctx = Module.getUnoComponentContext(); + const tdmAny = ctx.getValueByName( '/singletons/com.sun.star.reflection.theTypeDescriptionManager'); - const tdm = Module.uno.com.sun.star.container.XHierarchicalNameAccess.query(tdmAny.get()); + ctx.delete(); + const ifc = tdmAny.get(); + tdmAny.delete(); + const tdm = Module.uno.com.sun.star.container.XHierarchicalNameAccess.query(ifc); + ifc.delete(); interfaces.forEach((i) => { const td = tdm.getByHierarchicalName(i); - walk(Module.uno.com.sun.star.reflection.XTypeDescription.query(td.get()), i); + const ifc = td.get(); td.delete(); + walk(Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc), i); + ifc.delete(); }) - tdmAny.delete(); + tdm.delete(); return Module.uno.com.sun.star.uno.XInterface.reference( obj.impl_interfaces[obj.impl_typemap['com.sun.star.uno.XInterface']]); };
