static/emscripten/uno.js                  |    4 +++-
 static/source/embindmaker/embindmaker.cxx |   19 ++++++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

New commits:
commit ee63aeb69a0d5758a1f7acb65167c0a251e2da9a
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Fri Jul 12 09:30:18 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Fri Jul 12 11:47:26 2024 +0200

    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.bergm...@allotropia.de>

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
";
             std::exit(EXIT_FAILURE);
         }
-        jsOut << "function init_unoembind_" << name
-              << "(instance) {
"
-                 "    return {
";
+        jsOut << "function init_unoembind_" << name << "(instance, tagSymbol) {
";
+        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 
<< "'};
";
+            }
+        }
+        jsOut << "    return {
";
         writeJsMap(jsOut, *module, "        ");
         jsOut << "    };
"
                  "};
";

Reply via email to