summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-07-12 09:30:18 +0200
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-07-12 11:47:26 +0200
commitee63aeb69a0d5758a1f7acb65167c0a251e2da9a (patch)
tree229ad4c9a109406c093af35e05229d41270f9510 /static
parenta9f3c11375525a7708378dd3648febc40db1ad20 (diff)
A mechanism for annotating the embindmaker-generated JS UNOIDL data
As we need to generate data upfront for all the UNOIDL entities anyway, we might just as well extend that with annotations (keyed to some new Module.unoTagSymbol) that are useful at runtime. The general idea is to let such annotations be objects with certain well-known keys, the main one being a string-valued `kind` representing the UNOIDL kind of the annotated data. As a first thing, individual UNOIDL enum type enumerators are annotated with a `type` representing the UNOIDL enum type they belong to. That turns out to be useful for some experimental approach of mine where I wrap the Embind-based JS binding in something that makes the result more idiomatic JS. Change-Id: Iec466bab05ba3d1b56b2398e5c361465af49dc13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170398 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/emscripten/uno.js4
-rw-r--r--static/source/embindmaker/embindmaker.cxx19
2 files changed, 19 insertions, 4 deletions
diff --git a/static/emscripten/uno.js b/static/emscripten/uno.js
index bd1e693a6e77..6a9c4cd5cb6e 100644
--- a/static/emscripten/uno.js
+++ b/static/emscripten/uno.js
@@ -9,9 +9,11 @@
'use strict';
+Module.unoTagSymbol = Symbol('unoTag');
+
Module.initUno = function() {
if (Module.uno === undefined) {
- Module.uno = init_unoembind_uno(Module);
+ Module.uno = init_unoembind_uno(Module, Module.unoTagSymbol);
}
};
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index 9727161ff859..78bc94b9087d 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -1213,9 +1213,22 @@ SAL_IMPLEMENT_MAIN()
std::cerr << "Cannot open \"" << jsPathname << "\" for writing\n";
std::exit(EXIT_FAILURE);
}
- jsOut << "function init_unoembind_" << name
- << "(instance) {\n"
- " return {\n";
+ jsOut << "function init_unoembind_" << name << "(instance, tagSymbol) {\n";
+ for (auto const& enm : enums)
+ {
+ auto const ent = mgr->getManager()->findEntity(enm);
+ if (!ent.is() || ent->getSort() != unoidl::Entity::SORT_ENUM_TYPE)
+ {
+ throw CannotDumpException("bad enum type \"" + enm + "\"");
+ }
+ for (auto const& mem :
+ static_cast<unoidl::EnumTypeEntity const*>(ent.get())->getMembers())
+ {
+ jsOut << " instance.uno_Type_" << enm.replace('.', '$') << "." << mem.name
+ << "[tagSymbol] = {kind: 'enumerator', type: '" << enm << "'};\n";
+ }
+ }
+ jsOut << " return {\n";
writeJsMap(jsOut, *module, " ");
jsOut << " };\n"
"};\n";