summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-02-14 15:29:13 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-02-15 10:58:47 +0100
commit52a22b6863c08b071361fa9c212b886e1e48500b (patch)
treede69cb08405df05cad983d6035d418163c68b472 /static
parentb7e4078033b064bfc3847db0916a4df389117817 (diff)
Fold registeroustring.js into PrimaryBindings.cxx
Change-Id: I2e1aa828f194a104d354741518e8cb20015ac276 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163385 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/emscripten/registeroustring.js56
-rw-r--r--static/source/unoembindhelpers/PrimaryBindings.cxx58
2 files changed, 55 insertions, 59 deletions
diff --git a/static/emscripten/registeroustring.js b/static/emscripten/registeroustring.js
deleted file mode 100644
index 0abd522ca98e..000000000000
--- a/static/emscripten/registeroustring.js
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-if (!('preRun' in Module)) Module['preRun'] = [];
-Module.preRun.push(function() {
- // Wait until Embind is set up:
- Module.addOnPreMain(function() {
- Module.registerType(Module.getOUStringRawType(), {
- name: 'rtl::OUString',
- 'fromWireType'(ptr) {
- let data = Module.HEAPU32[ptr >> 2];
- let length = Module.HEAPU32[(data >> 2) + 1];
- let buffer = data + 8;
- let str = '';
- for (let i = 0; i < length; ++i) {
- let c = Module.HEAPU16[(buffer >> 1) + i];
- str += String.fromCharCode(c);
- }
- Module.rtl_uString_release(data);
- Module._free(ptr);
- return str;
- },
- 'toWireType'(destructors, value) {
- if (typeof value != 'string') {
- Module.throwBindingError('Cannot pass non-string to C++ OUString');
- }
- let data = Module._malloc(8 + (value.length + 1) * 2);
- Module.HEAPU32[data >> 2] = 1;
- Module.HEAPU32[(data >> 2) + 1] = value.length;
- let buffer = data + 8;
- for (let i = 0; i < value.length; ++i) {
- Module.HEAPU16[(buffer >> 1) + i] = value.charCodeAt(i);
- }
- Module.HEAPU16[(buffer >> 1) + value.length] = 0;
- let ptr = Module._malloc(4);
- Module.HEAPU32[ptr >> 2] = data;
- if (destructors !== null) {
- destructors.push(Module._free, ptr);
- }
- return ptr;
- },
- 'argPackAdvance': 8,
- 'readValueFromPointer'(pointer) {
- return this['fromWireType'](Module.HEAPU32[((pointer)>>2)]);
- },
- destructorFunction(ptr) {
- Module._free(ptr);
- },
- });
- });
-});
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx
index ee4998988c19..0a27162c3ef1 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -9,6 +9,7 @@
#ifdef EMSCRIPTEN
#include <com/sun/star/frame/XModel.hpp>
+#include <emscripten.h>
#include <emscripten/bind.h>
#include <comphelper/processfactory.hxx>
@@ -22,6 +23,58 @@
using namespace emscripten;
using namespace css::uno;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Winvalid-pp-token"
+EM_JS(void, jsRegisterString, (std::type_info const* raw),
+// clang-format off
+{
+ Module.registerType(raw, {
+ name: 'rtl::OUString',
+ fromWireType(ptr) {
+ let data = Module.HEAPU32[ptr >> 2];
+ let length = Module.HEAPU32[(data >> 2) + 1];
+ let buffer = data + 8;
+ let str = '';
+ for (let i = 0; i < length; ++i) {
+ let c = Module.HEAPU16[(buffer >> 1) + i];
+ str += String.fromCharCode(c);
+ }
+ Module.rtl_uString_release(data);
+ Module._free(ptr);
+ return str;
+ },
+ toWireType(destructors, value) {
+ if (typeof value != 'string') {
+ Module.throwBindingError('Cannot pass non-string to C++ OUString');
+ }
+ let data = Module._malloc(8 + (value.length + 1) * 2);
+ Module.HEAPU32[data >> 2] = 1;
+ Module.HEAPU32[(data >> 2) + 1] = value.length;
+ let buffer = data + 8;
+ for (let i = 0; i < value.length; ++i) {
+ Module.HEAPU16[(buffer >> 1) + i] = value.charCodeAt(i);
+ }
+ Module.HEAPU16[(buffer >> 1) + value.length] = 0;
+ let ptr = Module._malloc(4);
+ Module.HEAPU32[ptr >> 2] = data;
+ if (destructors !== null) {
+ destructors.push(Module._free, ptr);
+ }
+ return ptr;
+ },
+ argPackAdvance: 8,
+ readValueFromPointer(pointer) {
+ return this.fromWireType(Module.HEAPU32[((pointer)>>2)]);
+ },
+ destructorFunction(ptr) {
+ Module._free(ptr);
+ },
+ });
+}
+// clang-format on
+);
+#pragma clang diagnostic pop
+
namespace
{
template <typename T> void registerInOutParam(char const* name)
@@ -30,8 +83,6 @@ template <typename T> void registerInOutParam(char const* name)
"val", &unoembindhelpers::UnoInOutParam<T>::get, &unoembindhelpers::UnoInOutParam<T>::set);
}
-std::uintptr_t getOUStringRawType() { return reinterpret_cast<std::uintptr_t>(&typeid(OUString)); }
-
Reference<css::frame::XModel> getCurrentModelFromViewSh()
{
SfxViewShell* pSh = nullptr;
@@ -112,10 +163,11 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
registerInOutParam<char16_t>("uno_InOutParam_char");
function("getCurrentModelFromViewSh", &getCurrentModelFromViewSh);
- function("getOUStringRawType", &getOUStringRawType);
function("getUnoComponentContext", &comphelper::getProcessComponentContext);
function("rtl_uString_release",
+[](std::uintptr_t ptr) { rtl_uString_release(reinterpret_cast<rtl_uString*>(ptr)); });
+
+ jsRegisterString(&typeid(OUString));
}
#endif