static/source/unoembindhelpers/PrimaryBindings.cxx | 55 ++++++++++++++------- unotest/source/embindtest/embindtest.js | 8 ++- 2 files changed, 45 insertions(+), 18 deletions(-)
New commits: commit ad7963f939c629657c1aca03765169ace14a5bbd Author: Stephan Bergmann <[email protected]> AuthorDate: Fri Mar 8 17:27:52 2024 +0100 Commit: Stephan Bergmann <[email protected]> CommitDate: Fri Mar 8 22:44:50 2024 +0100 Directly go via std::u16string Change-Id: I99d3322afc7876c37a7ace016c1c6af691f28406 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164591 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx index 54ce34d0724c..bfbf7d90b12d 100644 --- a/static/source/unoembindhelpers/PrimaryBindings.cxx +++ b/static/source/unoembindhelpers/PrimaryBindings.cxx @@ -18,9 +18,6 @@ #include <comphelper/processfactory.hxx> #include <o3tl/any.hxx> #include <o3tl/unreachable.hxx> -#include <rtl/string.hxx> -#include <rtl/textcvt.h> -#include <rtl/textenc.h> #include <rtl/ustring.hxx> #include <sal/log.hxx> #include <sfx2/viewsh.hxx> @@ -142,18 +139,6 @@ EM_JS(void, jsRegisterString, (std::type_info const* raw), namespace { -OString toUtf8(OUString const& string) -{ - OString s; - if (!string.convertToString(&s, RTL_TEXTENCODING_UTF8, - RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR - | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)) - { - throw css::uno::RuntimeException("cannot convert OUString to UTF-8"); - } - return s; -} - void copyStruct(typelib_CompoundTypeDescription* desc, void const* source, void* dest) { if (desc->pBaseTypeDescription != nullptr) @@ -258,8 +243,8 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) return css::uno::Type(css::uno::TypeClass_INTERFACE, OUString(name)); }) .function("toString", +[](css::uno::Type const& self) { - auto const name = toUtf8(self.getTypeName()); - return std::string(name.getStr(), name.getLength()); + auto const name = self.getTypeName(); + return std::u16string(name.getStr(), name.getLength()); }); // Any commit 747cfc7a021d8a4664462ddd6b0fad6c178da602 Author: Stephan Bergmann <[email protected]> AuthorDate: Fri Mar 8 17:20:52 2024 +0100 Commit: Stephan Bergmann <[email protected]> CommitDate: Fri Mar 8 22:44:37 2024 +0100 Improve Embind'ing of UNO Type Change-Id: Id93d7f48dedb362206828b5e3bd946525f95ea77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164590 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx index 985ebacc52b2..54ce34d0724c 100644 --- a/static/source/unoembindhelpers/PrimaryBindings.cxx +++ b/static/source/unoembindhelpers/PrimaryBindings.cxx @@ -221,6 +221,42 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) emscripten::class_<typelib_TypeDescriptionReference>("uno_Type") .smart_ptr<css::uno::Type>("uno_Type$") + .class_function("Void", +[]() { return cppu::UnoType<void>::get(); }) + .class_function("Boolean", +[]() { return cppu::UnoType<bool>::get(); }) + .class_function("Byte", +[]() { return cppu::UnoType<sal_Int8>::get(); }) + .class_function("Short", +[]() { return cppu::UnoType<sal_Int16>::get(); }) + .class_function("UnsignedShort", +[]() { return cppu::UnoType<sal_uInt16>::get(); }) + .class_function("Long", +[]() { return cppu::UnoType<sal_Int32>::get(); }) + .class_function("UnsignedLong", +[]() { return cppu::UnoType<sal_uInt32>::get(); }) + .class_function("Hyper", +[]() { return cppu::UnoType<sal_Int64>::get(); }) + .class_function("UnsignedHyper", +[]() { return cppu::UnoType<sal_uInt64>::get(); }) + .class_function("Float", +[]() { return cppu::UnoType<float>::get(); }) + .class_function("Double", +[]() { return cppu::UnoType<double>::get(); }) + .class_function("Char", +[]() { return cppu::UnoType<sal_Unicode>::get(); }) + .class_function("String", +[]() { return cppu::UnoType<OUString>::get(); }) + .class_function("Type", +[]() { return cppu::UnoType<css::uno::Type>::get(); }) + .class_function("Any", +[]() { return cppu::UnoType<css::uno::Any>::get(); }) + .class_function("Sequence", + +[](css::uno::Type const& type) { + return css::uno::Type(css::uno::TypeClass_SEQUENCE, + "[]" + type.getTypeName()); + }) + .class_function("Enum", + +[](std::u16string const& name) { + return css::uno::Type(css::uno::TypeClass_ENUM, OUString(name)); + }) + .class_function("Struct", + +[](std::u16string const& name) { + return css::uno::Type(css::uno::TypeClass_STRUCT, OUString(name)); + }) + .class_function("Exception", + +[](std::u16string const& name) { + return css::uno::Type(css::uno::TypeClass_EXCEPTION, OUString(name)); + }) + .class_function("Interface", + +[](std::u16string const& name) { + return css::uno::Type(css::uno::TypeClass_INTERFACE, OUString(name)); + }) .function("toString", +[](css::uno::Type const& self) { auto const name = toUtf8(self.getTypeName()); return std::string(name.getStr(), name.getLength()); diff --git a/unotest/source/embindtest/embindtest.js b/unotest/source/embindtest/embindtest.js index e238af32c003..a825946fee34 100644 --- a/unotest/source/embindtest/embindtest.js +++ b/unotest/source/embindtest/embindtest.js @@ -90,6 +90,7 @@ Module.addOnPostRun(function() { console.log(v); console.assert(v.toString() === 'long'); console.assert(test.isType(v)); + console.assert(test.isType(Module.uno_Type.Long())); } { let v = test.getEnum(); @@ -241,7 +242,7 @@ Module.addOnPostRun(function() { console.assert(v.get().toString() === 'long'); console.assert(test.isAnyType(v)); v.delete(); - //TODO: let a = new Module.Any(TODO, css.uno.TypeClass.TYPE); + //TODO: let a = new Module.Any(Module.uno_Type.Long(), css.uno.TypeClass.TYPE); //TODO: console.assert(test.isAnyType(a)); //TODO: a.delete(); } @@ -441,6 +442,11 @@ Module.addOnPostRun(function() { console.assert(v.get(2).toString() === '[]org.libreoffice.embindtest.Enum'); console.assert(test.isSequenceType(v)); v.delete(); + let s = new Module.uno_Sequence_type([ + Module.uno_Type.Long(), Module.uno_Type.Void(), + Module.uno_Type.Sequence(Module.uno_Type.Enum('org.libreoffice.embindtest.Enum'))]); + console.assert(test.isSequenceType(s)); + s.delete(); } { let v = test.getSequenceAny();
