include/static/unoembindhelpers/PrimaryBindings.hxx |    1 
 static/source/embindmaker/embindmaker.cxx           |    1 
 static/source/unoembindhelpers/PrimaryBindings.cxx  |   35 ++++++++++++++++++--
 unotest/source/embindtest/embindtest.js             |   18 +++++-----
 4 files changed, 44 insertions(+), 11 deletions(-)

New commits:
commit 893af92ae990909d477434d48d97dae0814e7e58
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Fri Mar 1 15:34:48 2024 +0100
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Mon Mar 4 21:43:18 2024 +0100

    Add Embind'ing of UNO Any getter for sequences
    
    Change-Id: I5b81ad3d5f1351062aef43105ea7ec4678045a90
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164360
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/include/static/unoembindhelpers/PrimaryBindings.hxx 
b/include/static/unoembindhelpers/PrimaryBindings.hxx
index 13ddd05cce26..259c9c2944f8 100644
--- a/include/static/unoembindhelpers/PrimaryBindings.hxx
+++ b/include/static/unoembindhelpers/PrimaryBindings.hxx
@@ -125,6 +125,7 @@ template <typename T> void registerSequence(char const* 
name)
             checkSequenceAccess(self, index);
             self.getArray()[index] = value;
         });
+    registerUnoType<css::uno::Sequence<T>>();
 }
 }
 
diff --git a/static/source/embindmaker/embindmaker.cxx 
b/static/source/embindmaker/embindmaker.cxx
index 36b1f56fd5a3..a0ea41eddf97 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -864,6 +864,7 @@ SAL_IMPLEMENT_MAIN()
                    << jsName(str) << "\")";
             dumpStructMembers(cppOut, mgr, str, strEnt);
             cppOut << ";
";
+            cppOut << "    ::unoembindhelpers::registerUnoType<" << 
cppName(str) << ">();
";
             dumpRegisterFunctionEpilog(cppOut, n);
             for (auto const& mem : strEnt->getDirectMembers())
             {
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx 
b/static/source/unoembindhelpers/PrimaryBindings.cxx
index 7cf99c523f0d..21fe4c1cd66f 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -26,7 +26,10 @@
 #include <sfx2/viewsh.hxx>
 #include <static/unoembindhelpers/PrimaryBindings.hxx>
 #include <typelib/typedescription.h>
+#include <typelib/typedescription.hxx>
+#include <uno/data.h>
 
+#include <cassert>
 #include <cstdint>
 #include <stdexcept>
 #include <string>
@@ -151,6 +154,21 @@ OString toUtf8(OUString const& string)
     return s;
 }
 
+void copyStruct(typelib_CompoundTypeDescription* desc, void const* source, 
void* dest)
+{
+    if (desc->pBaseTypeDescription != nullptr)
+    {
+        copyStruct(desc->pBaseTypeDescription, source, dest);
+    }
+    for (sal_Int32 i = 0; i != desc->nMembers; ++i)
+    {
+        uno_type_copyData(
+            static_cast<char*>(dest) + desc->pMemberOffsets[i],
+            const_cast<char*>(static_cast<char const*>(source) + 
desc->pMemberOffsets[i]),
+            desc->ppTypeRefs[i], cpp_acquire);
+    }
+}
+
 template <typename T> void registerInOutParam(char const* name)
 {
     
class_<unoembindhelpers::UnoInOutParam<T>>(name).constructor().constructor<T>().property(
@@ -287,7 +305,11 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
                 case css::uno::TypeClass_TYPE:
                     return 
emscripten::val(*o3tl::forceAccess<css::uno::Type>(self));
                 case css::uno::TypeClass_SEQUENCE:
-                    return emscripten::val::undefined(); //TODO
+                {
+                    emscripten::internal::WireTypePack argv(self.getValue());
+                    return emscripten::val::take_ownership(
+                        _emval_take_value(getTypeId(self.getValueType()), 
argv));
+                }
                 case css::uno::TypeClass_ENUM:
                 {
                     emscripten::internal::WireTypePack argv(
@@ -296,7 +318,16 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
                         _emval_take_value(getTypeId(self.getValueType()), 
argv));
                 }
                 case css::uno::TypeClass_STRUCT:
-                    return emscripten::val::undefined(); //TODO
+                {
+                    css::uno::TypeDescription 
desc(self.getValueType().getTypeLibType());
+                    assert(desc.is());
+                    auto const td = 
reinterpret_cast<typelib_StructTypeDescription*>(desc.get());
+                    auto const copy = std::malloc(td->aBase.aBase.nSize);
+                    copyStruct(&td->aBase, self.getValue(), copy);
+                    emscripten::internal::WireTypePack argv(std::move(copy));
+                    return emscripten::val::take_ownership(
+                        _emval_take_value(getTypeId(self.getValueType()), 
argv));
+                }
                 case css::uno::TypeClass_EXCEPTION:
                     return emscripten::val::undefined(); //TODO
                 case css::uno::TypeClass_INTERFACE:
diff --git a/unotest/source/embindtest/embindtest.js 
b/unotest/source/embindtest/embindtest.js
index d391f5bd15f5..cc9e691a65d6 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -248,12 +248,12 @@ Module.addOnPostRun(function() {
     {
         let v = test.getAnySequence();
         console.log(v);
-        //TODO: let x = v.get();
-        //TODO: console.assert(x.size() === 3);
-        //TODO: console.assert(x.get(0) === 'foo');
-        //TODO: console.assert(x.get(1) === 'barr');
-        //TODO: console.assert(x.get(2) === 'bazzz');
-        //TODO: x.delete();
+        let x = v.get();
+        console.assert(x.size() === 3);
+        console.assert(x.get(0) === 'foo');
+        console.assert(x.get(1) === 'barr');
+        console.assert(x.get(2) === 'bazzz');
+        x.delete();
         console.assert(test.isAnySequence(v));
         v.delete();
         let s = new Module.uno_Sequence_string(["foo", "barr", "bazzz"]);
@@ -276,9 +276,9 @@ Module.addOnPostRun(function() {
     {
         let v = test.getAnyStruct();
         console.log(v);
-        //TODO: console.assert(v.get().m1 === -123456);
-        //TODO: console.assert(v.get().m2 === 100.5);
-        //TODO: console.assert(v.get().m3 === 'hä');
+        console.assert(v.get().m1 === -123456);
+        console.assert(v.get().m2 === 100.5);
+        console.assert(v.get().m3 === 'hä');
         console.assert(test.isAnyStruct(v));
         v.delete();
         //TODO: let a = new Module.Any(

Reply via email to