From 621322b6ac0bebab2f904b7fe8d040193a1f45ba Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 27 Feb 2024 21:59:37 +0100 Subject: Generate slightly more flexible JS init_unoembind_* functions ...that return the "hierarchical object", rather than setting it as a member of the passed-in instance Change-Id: I17ad7dd426114c7979f1ba6edaebe83b43eedfed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164064 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- static/README.wasm.md | 8 ++++---- static/source/embindmaker/embindmaker.cxx | 3 +-- unotest/source/embindtest/embindtest.js | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/static/README.wasm.md b/static/README.wasm.md index e37242508b72..f2abc8219ce8 100644 --- a/static/README.wasm.md +++ b/static/README.wasm.md @@ -223,8 +223,8 @@ improvement! ;) Some usage examples through javascript of the current implementation: ```js // inserts a string at the start of the Writer document. -init_unoembind_uno(Module); -let css = Module.unoembind_uno.com.sun.star; +let uno = init_unoembind_uno(Module); +let css = uno.com.sun.star; xModel = Module.getCurrentModelFromViewSh(); xTextDocument = new css.text.XTextDocument(xModel.$query()); xText = xTextDocument.getText(); @@ -238,8 +238,8 @@ xModel.delete(); xTextDocument.delete(); xText.delete(); xSimpleText.delete(); x ```js // changes each paragraph of the Writer document to a random color. -init_unoembind_uno(Module); -let css = Module.unoembind_uno.com.sun.star; +let uno = init_unoembind_uno(Module); +let css = uno.com.sun.star; xModel = Module.getCurrentModelFromViewSh(); xEnumAccess = new css.container.XEnumerationAccess(xText.$query()); xParaEnumeration = xEnumAccess.createEnumeration(); diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx index 335b7983503c..37175d100cdf 100644 --- a/static/source/embindmaker/embindmaker.cxx +++ b/static/source/embindmaker/embindmaker.cxx @@ -955,8 +955,7 @@ SAL_IMPLEMENT_MAIN() } jsOut << "function init_unoembind_" << name << "(instance) {\n" - " instance.unoembind_" - << name << " = {\n"; + " return {\n"; writeJsMap(jsOut, *module, " "); jsOut << " };\n" "};\n"; diff --git a/unotest/source/embindtest/embindtest.js b/unotest/source/embindtest/embindtest.js index 3d3196cc4c39..146be3fa545a 100644 --- a/unotest/source/embindtest/embindtest.js +++ b/unotest/source/embindtest/embindtest.js @@ -9,9 +9,8 @@ Module.addOnPostRun(function() { console.log('Running embindtest'); - init_unoembind_uno(Module); - let test = new Module.unoembind_uno.org.libreoffice.embindtest.Test( - Module.getUnoComponentContext()); + let uno = init_unoembind_uno(Module); + let test = new uno.org.libreoffice.embindtest.Test(Module.getUnoComponentContext()); console.assert(typeof test === 'object'); { let v = test.getBoolean(); -- cgit