Drop some needless mappings to identical strings
[LibreOffice.git] / static / emscripten / uno.js
blob714dbf20dc3a86bcb90f3e09ec7c0bcc33ed8684
1 /* -*- Mode: JS; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 Module.unoTagSymbol = Symbol('unoTag');
12 Module.uno_init = new Promise(function (resolve, reject) {
13 Module.uno_init$resolve = function() {
14 Module.uno = init_unoembind_uno(Module, Module.unoTagSymbol);
15 resolve();
17 Module.uno_init$reject = reject;
18 });
20 Module.uno_main = new Promise(function (resolve, reject) {
21 Module.uno_main$resolve = resolve;
22 Module.uno_main$reject = reject;
23 });
25 Module.catchUnoException = function(exception) {
26 // Rethrow non-C++ exceptions (non-UNO C++ exceptions are mapped to css.uno.RuntimeException in
27 // Module.getUnoExceptionFromCxaException):
28 if (!(exception instanceof WebAssembly.Exception && exception.is(getCppExceptionTag()))) {
29 throw exception;
31 const any = Module.getUnoExceptionFromCxaException(
32 getCppExceptionThrownObjectFromWebAssemblyException(exception));
33 decrementExceptionRefcount(exception);
34 return any;
37 Module.unoObject = function(interfaces, obj) {
38 interfaces = ['com.sun.star.lang.XTypeProvider'].concat(interfaces);
39 obj.impl_refcount = 0;
40 obj.queryInterface = function(type) {
41 for (const i in obj.impl_typemap) {
42 if (i === type.toString()) {
43 const ifc = Module['uno_Type_' + i.replace(/\./g, '$')].reference(
44 obj.impl_interfaces[obj.impl_typemap[i]]);
45 try {
46 return new Module.uno_Any(type, ifc);
47 } finally {
48 ifc.delete();
52 const ty = Module.uno_Type.Void();
53 const ret = new Module.uno_Any(ty, undefined);
54 ty.delete();
55 return ret;
57 obj.acquire = function() { ++obj.impl_refcount; };
58 obj.release = function() {
59 if (--obj.impl_refcount === 0) {
60 for (const i in obj.impl_interfaces) {
61 obj.impl_interfaces[i].delete();
65 obj.getTypes = function() {
66 const types = new Module.uno_Sequence_type(interfaces.length, Module.uno_Sequence.FromSize);
67 for (let i = 0; i !== interfaces.length; ++i) {
68 const type = Module.uno_Type.Interface(interfaces[i]);
69 types.set(i, type);
70 type.delete();
72 return types;
74 obj.getImplementationId = function() { return new Module.uno_Sequence_byte([]) };
75 obj.impl_interfaces = {};
76 interfaces.forEach((i) => {
77 obj.impl_interfaces[i] = Module['uno_Type_' + i.replace(/\./g, '$')].implement(obj);
78 });
79 obj.impl_typemap = {};
80 const walk = function(td, impl) {
81 const name = td.getName();
82 if (!Object.hasOwn(obj.impl_typemap, name)) {
83 if (td.getTypeClass() != Module.uno.com.sun.star.uno.TypeClass.INTERFACE) {
84 throw new Error('not a UNO interface type: ' + name);
86 obj.impl_typemap[name] = impl;
87 const itd = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2.query(td);
88 const bases = itd.getBaseTypes();
89 itd.delete();
90 for (let i = 0; i !== bases.size(); ++i) {
91 walk(bases.get(i), impl);
93 bases.delete();
95 td.delete();
97 const ctx = Module.getUnoComponentContext();
98 const tdmAny = ctx.getValueByName(
99 '/singletons/com.sun.star.reflection.theTypeDescriptionManager');
100 ctx.delete();
101 const ifc = tdmAny.get();
102 tdmAny.delete();
103 const tdm = Module.uno.com.sun.star.container.XHierarchicalNameAccess.query(ifc);
104 ifc.delete();
105 interfaces.forEach((i) => {
106 const td = tdm.getByHierarchicalName(i);
107 const ifc = td.get();
108 td.delete();
109 walk(Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc), i);
110 ifc.delete();
112 tdm.delete();
113 return Module.uno.com.sun.star.uno.XInterface.reference(
114 obj.impl_interfaces[obj.impl_typemap['com.sun.star.uno.XInterface']]);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */