diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx index 186e3ee88057..50048a97ada6 100644 --- a/static/source/unoembindhelpers/PrimaryBindings.cxx +++ b/static/source/unoembindhelpers/PrimaryBindings.cxx @@ -12,17 +12,41 @@ #include #include +#include +#include #include +#include +#include +#include +#include #include #include #include +#include #include +#include #include using namespace emscripten; using namespace css::uno; +template <> struct emscripten::smart_ptr_trait +{ + using PointerType = css::uno::Type; + using element_type = typelib_TypeDescriptionReference; + static typelib_TypeDescriptionReference* get(css::uno::Type const& ptr) + { + return ptr.getTypeLibType(); + } + static sharing_policy get_sharing_policy() { return sharing_policy::INTRUSIVE; } + static css::uno::Type* share(typelib_TypeDescriptionReference* v) + { + return new css::uno::Type(v); + } + static css::uno::Type* construct_null() { return new css::uno::Type(); } +}; + EM_JS(void, jsRegisterChar, (std::type_info const* raw), // clang-format off { @@ -110,6 +134,18 @@ 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; +} + template void registerInOutParam(char const* name) { class_>(name).constructor().constructor().property( @@ -135,6 +171,13 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) enum_("uno_Sequence") .value("FromSize", unoembindhelpers::uno_Sequence::FromSize); + emscripten::class_("uno_Type") + .smart_ptr("uno_Type$") + .function("toString", +[](css::uno::Type const& self) { + auto const name = toUtf8(self.getTypeName()); + return std::string(name.getStr(), name.getLength()); + }); + // Any class_("Any").constructor(+[](const val& rObject, const TypeClass& rUnoType) -> Any { switch (rUnoType) diff --git a/udkapi/org/libreoffice/embindtest/XTest.idl b/udkapi/org/libreoffice/embindtest/XTest.idl index f64a3857e863..2ddfb41f2ead 100644 --- a/udkapi/org/libreoffice/embindtest/XTest.idl +++ b/udkapi/org/libreoffice/embindtest/XTest.idl @@ -34,6 +34,8 @@ interface XTest { boolean isChar([in] char value); string getString(); boolean isString([in] string value); + type getType(); + boolean isType([in] type value); Enum getEnum(); boolean isEnum([in] Enum value); Struct getStruct(); @@ -62,6 +64,8 @@ interface XTest { boolean isSequenceChar([in] sequence value); sequence getSequenceString(); boolean isSequenceString([in] sequence value); + sequence getSequenceType(); + boolean isSequenceType([in] sequence value); sequence > getSequenceSequenceString(); boolean isSequenceSequenceString([in] sequence > value); sequence getSequenceEnum(); diff --git a/unotest/source/embindtest/embindtest.cxx b/unotest/source/embindtest/embindtest.cxx index 2a9cdfc4de3a..8b131cd9f376 100644 --- a/unotest/source/embindtest/embindtest.cxx +++ b/unotest/source/embindtest/embindtest.cxx @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include #include @@ -76,6 +78,13 @@ public: sal_Bool SAL_CALL isString(OUString const& value) override { return value == u"hä"; } + css::uno::Type SAL_CALL getType() override { return cppu::UnoType::get(); } + + sal_Bool SAL_CALL isType(css::uno::Type const& value) override + { + return value == cppu::UnoType::get(); + } + org::libreoffice::embindtest::Enum SAL_CALL getEnum() override { return org::libreoffice::embindtest::Enum_E_2; @@ -213,6 +222,21 @@ public: return value == css::uno::Sequence{ u"foo"_ustr, u"barr"_ustr, u"bazzz"_ustr }; } + css::uno::Sequence SAL_CALL getSequenceType() override + { + return { cppu::UnoType::get(), cppu::UnoType::get(), + cppu::UnoType>::get() }; + } + + sal_Bool SAL_CALL isSequenceType(css::uno::Sequence const& value) override + { + return value + == css::uno::Sequence{ + cppu::UnoType::get(), cppu::UnoType::get(), + cppu::UnoType>::get() + }; + } + css::uno::Sequence> SAL_CALL getSequenceSequenceString() override { return { {}, { u"foo"_ustr, u"barr"_ustr }, { u"baz"_ustr } }; diff --git a/unotest/source/embindtest/embindtest.js b/unotest/source/embindtest/embindtest.js index 1978c9cc4ec7..422c1c1a421f 100644 --- a/unotest/source/embindtest/embindtest.js +++ b/unotest/source/embindtest/embindtest.js @@ -84,6 +84,12 @@ Module.addOnPostRun(function() { console.assert(v === 'hä'); console.assert(test.isString(v)); } + { + let v = test.getType(); + console.log(v); + console.assert(v.toString() === 'long'); + console.assert(test.isType(v)); + } { let v = test.getEnum(); console.log(v); @@ -218,6 +224,16 @@ Module.addOnPostRun(function() { console.assert(test.isSequenceString(v)); v.delete(); } + { + let v = test.getSequenceType(); + console.log(v); + console.assert(v.size() === 3); + console.assert(v.get(0).toString() === 'long'); + console.assert(v.get(1).toString() === 'void'); + console.assert(v.get(2).toString() === '[]org.libreoffice.embindtest.Enum'); + console.assert(test.isSequenceType(v)); + v.delete(); + } { let v = test.getSequenceSequenceString(); console.log(v);