summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--static/source/unoembindhelpers/PrimaryBindings.cxx34
-rw-r--r--unotest/source/embindtest/embindtest.cxx4
-rw-r--r--unotest/source/embindtest/embindtest.idl2
-rw-r--r--unotest/source/embindtest/embindtest.js6
4 files changed, 46 insertions, 0 deletions
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx
index 0a27162c3ef1..a8e1000afd6f 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -23,6 +23,39 @@
using namespace emscripten;
using namespace css::uno;
+EM_JS(void, jsRegisterChar, (std::type_info const* raw),
+// clang-format off
+{
+ Module.registerType(raw, {
+ name: 'rtl::OUString',
+ fromWireType(ptr) {
+ let str = String.fromCharCode(Module.HEAPU16[ptr >> 1]);
+ return str;
+ },
+ toWireType(destructors, value) {
+ if (typeof value != 'string' || value.length !== 1) {
+ Module.throwBindingError(
+ 'Cannot pass anything but 1-element string to C++ char16_t');
+ }
+ let data = Module._malloc(2);
+ Module.HEAPU16[data >> 1] = value.charCodeAt(0);
+ if (destructors !== null) {
+ destructors.push(Module._free, data);
+ }
+ return data;
+ },
+ argPackAdvance: 8,
+ readValueFromPointer(pointer) {
+ return this.fromWireType(Module.HEAPU32[((pointer)>>2)]);
+ },
+ destructorFunction(ptr) {
+ Module._free(ptr);
+ },
+ });
+}
+// clang-format on
+);
+
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-pp-token"
EM_JS(void, jsRegisterString, (std::type_info const* raw),
@@ -167,6 +200,7 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
function("rtl_uString_release",
+[](std::uintptr_t ptr) { rtl_uString_release(reinterpret_cast<rtl_uString*>(ptr)); });
+ jsRegisterChar(&typeid(char16_t));
jsRegisterString(&typeid(OUString));
}
#endif
diff --git a/unotest/source/embindtest/embindtest.cxx b/unotest/source/embindtest/embindtest.cxx
index b1f819272931..9ab70656541d 100644
--- a/unotest/source/embindtest/embindtest.cxx
+++ b/unotest/source/embindtest/embindtest.cxx
@@ -68,6 +68,10 @@ public:
sal_Bool SAL_CALL isDouble(double value) override { return value == 100.5; }
+ sal_Unicode SAL_CALL getChar() override { return u'Ö'; }
+
+ sal_Bool SAL_CALL isChar(sal_Unicode value) override { return value == u'Ö'; }
+
OUString SAL_CALL getString() override { return u"hä"_ustr; }
sal_Bool SAL_CALL isString(OUString const& value) override { return value == u"hä"; }
diff --git a/unotest/source/embindtest/embindtest.idl b/unotest/source/embindtest/embindtest.idl
index 913cde39e12b..09e5c4096c50 100644
--- a/unotest/source/embindtest/embindtest.idl
+++ b/unotest/source/embindtest/embindtest.idl
@@ -36,6 +36,8 @@ interface XTest {
boolean isFloat([in] float value);
double getDouble();
boolean isDouble([in] double value);
+ char getChar();
+ boolean isChar([in] char value);
string getString();
boolean isString([in] string value);
Struct getStruct();
diff --git a/unotest/source/embindtest/embindtest.js b/unotest/source/embindtest/embindtest.js
index 805dd16bfe99..9d0349ffe7f2 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -74,6 +74,12 @@ Module.addOnPostRun(function() {
console.assert(test.isDouble(v));
}
{
+ let v = test.getChar();
+ console.log(v);
+ console.assert(v === 'Ö');
+ console.assert(test.isChar(v));
+ }
+ {
let v = test.getString();
console.log(v);
console.assert(v === 'hä');