diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-02-22 10:36:24 +0100 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-02-22 15:45:51 +0100 |
commit | 2c3121adb9a53142a003ba668821e77e9555c629 (patch) | |
tree | 4708f24501715febe0ec3ebb0329d9b521a5b2cd /static | |
parent | b3bca02d58f71d2413b673ff113a346e237ef92f (diff) |
Embind: Add UNO char support
Change-Id: I4ced49774baafdf620ae167c53794932766aca86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163741
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r-- | static/source/unoembindhelpers/PrimaryBindings.cxx | 34 |
1 files changed, 34 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 |