xlsxrb 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +57 -264
- data/Rakefile +137 -5
- data/benchmark.rb +23 -14
- data/docs/DEVELOPMENT.md +67 -0
- data/docs/coi-serviceworker.js +82 -0
- data/docs/office_thread.js +77 -0
- data/docs/preview.html +719 -0
- data/docs/visual/VisualGallery.md +0 -158
- data/docs/wasm/wasm_doc_helper.css +256 -94
- data/docs/wasm/wasm_doc_helper.js +261 -142
- data/docs/zeta.js +1107 -0
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +178 -24
- data/lib/xlsxrb/ooxml.rb +1 -1
- data/lib/xlsxrb/version.rb +1 -1
- metadata +6 -1
data/docs/zeta.js
ADDED
|
@@ -0,0 +1,1107 @@
|
|
|
1
|
+
/* -*- Mode: JS; tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2; fill-column: 100 -*- */
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Source: https://cdn.zetaoffice.net/zetaoffice_latest/zeta.js
|
|
4
|
+
// Project: ZetaOffice (https://www.zetaoffice.net/)
|
|
5
|
+
// Purpose: Integration JavaScript library for ZetaOffice WebAssembly.
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
Module.zetajs = new Promise(function (resolve, reject) {
|
|
10
|
+
Module.zetajs$resolve = function() {
|
|
11
|
+
// A FinalizationRegistry for zetajs objects that own Embind objects that, in turn, should
|
|
12
|
+
// be .delete()'d (so that Embind doesn't print any "Embind found a leaked C++ instance"
|
|
13
|
+
// warnings for them); it is tied to Module so it doesn't itself get GC'ed early:
|
|
14
|
+
Module.uno$zetajs_deleteRegistry = new FinalizationRegistry(function(value) {
|
|
15
|
+
value.forEach((val) => val.delete());
|
|
16
|
+
});
|
|
17
|
+
const getProxyTarget = Symbol('getProxyTarget');
|
|
18
|
+
const keepAlive = Symbol('keepAlive');
|
|
19
|
+
function gcWrap(obj) {
|
|
20
|
+
// Embind has already registered obj at some FinalizationRegistry that prints the
|
|
21
|
+
// "Embind found a leaked C++ instance" warning, which we want to suppress; and if we
|
|
22
|
+
// registered obj itself also at our deleting FinalizationRegistry, the Embind one might
|
|
23
|
+
// fire first and still print the warning; so instead wrap obj in a Proxy and register
|
|
24
|
+
// that:
|
|
25
|
+
const proxy = new Proxy(obj, {});
|
|
26
|
+
Module.uno$zetajs_deleteRegistry.register(proxy, [obj]);
|
|
27
|
+
return proxy
|
|
28
|
+
}
|
|
29
|
+
function getEmbindSequenceCtor(componentType) {
|
|
30
|
+
let typename = componentType.toString();
|
|
31
|
+
let name = 'uno_Sequence';
|
|
32
|
+
let n = 1;
|
|
33
|
+
while (typename.startsWith('[]')) {
|
|
34
|
+
typename = typename.substr(2);
|
|
35
|
+
++n;
|
|
36
|
+
}
|
|
37
|
+
if (n !== 1) {
|
|
38
|
+
name += n;
|
|
39
|
+
}
|
|
40
|
+
name += '_' + typename.replace(/ /g, '_').replace(/\./g, '$');
|
|
41
|
+
return Module[name];
|
|
42
|
+
};
|
|
43
|
+
function getTypeDescriptionManager() {
|
|
44
|
+
const ctx = Module.getUnoComponentContext();
|
|
45
|
+
const tdmAny = ctx.getValueByName(
|
|
46
|
+
'/singletons/com.sun.star.reflection.theTypeDescriptionManager');
|
|
47
|
+
ctx.delete();
|
|
48
|
+
const val = tdmAny.get();
|
|
49
|
+
tdmAny.delete();
|
|
50
|
+
const tdm = Module.uno.com.sun.star.container.XHierarchicalNameAccess.query(val);
|
|
51
|
+
val.delete();
|
|
52
|
+
return tdm;
|
|
53
|
+
};
|
|
54
|
+
function translateTypeDescription(td) {
|
|
55
|
+
switch (td.getTypeClass()) {
|
|
56
|
+
case Module.uno.com.sun.star.uno.TypeClass.VOID:
|
|
57
|
+
return Module.uno_Type.Void();
|
|
58
|
+
case Module.uno.com.sun.star.uno.TypeClass.BOOLEAN:
|
|
59
|
+
return Module.uno_Type.Boolean();
|
|
60
|
+
case Module.uno.com.sun.star.uno.TypeClass.BYTE:
|
|
61
|
+
return Module.uno_Type.Byte();
|
|
62
|
+
case Module.uno.com.sun.star.uno.TypeClass.SHORT:
|
|
63
|
+
return Module.uno_Type.Short();
|
|
64
|
+
case Module.uno.com.sun.star.uno.TypeClass.UNSIGNED_SHORT:
|
|
65
|
+
return Module.uno_Type.UnsignedShort();
|
|
66
|
+
case Module.uno.com.sun.star.uno.TypeClass.LONG:
|
|
67
|
+
return Module.uno_Type.Long();
|
|
68
|
+
case Module.uno.com.sun.star.uno.TypeClass.UNSIGNED_LONG:
|
|
69
|
+
return Module.uno_Type.UnsignedLong();
|
|
70
|
+
case Module.uno.com.sun.star.uno.TypeClass.HYPER:
|
|
71
|
+
return Module.uno_Type.Hyper();
|
|
72
|
+
case Module.uno.com.sun.star.uno.TypeClass.UNSIGNED_HYPER:
|
|
73
|
+
return Module.uno_Type.UnsignedHyper();
|
|
74
|
+
case Module.uno.com.sun.star.uno.TypeClass.FLOAT:
|
|
75
|
+
return Module.uno_Type.Float();
|
|
76
|
+
case Module.uno.com.sun.star.uno.TypeClass.DOUBLE:
|
|
77
|
+
return Module.uno_Type.Double();
|
|
78
|
+
case Module.uno.com.sun.star.uno.TypeClass.CHAR:
|
|
79
|
+
return Module.uno_Type.Char();
|
|
80
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRING:
|
|
81
|
+
return Module.uno_Type.String();
|
|
82
|
+
case Module.uno.com.sun.star.uno.TypeClass.TYPE:
|
|
83
|
+
return Module.uno_Type.Type();
|
|
84
|
+
case Module.uno.com.sun.star.uno.TypeClass.ANY:
|
|
85
|
+
return Module.uno_Type.Any();
|
|
86
|
+
case Module.uno.com.sun.star.uno.TypeClass.SEQUENCE:
|
|
87
|
+
{
|
|
88
|
+
const itd = Module.uno.com.sun.star.reflection.XIndirectTypeDescription.query(td);
|
|
89
|
+
const rtd = itd.getReferencedType();
|
|
90
|
+
itd.delete();
|
|
91
|
+
const type = translateTypeDescriptionAndDelete(rtd);
|
|
92
|
+
try {
|
|
93
|
+
return Module.uno_Type.Sequence(type);
|
|
94
|
+
} finally {
|
|
95
|
+
type.delete();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
case Module.uno.com.sun.star.uno.TypeClass.ENUM:
|
|
99
|
+
return Module.uno_Type.Enum(td.getName());
|
|
100
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRUCT:
|
|
101
|
+
return Module.uno_Type.Struct(td.getName());
|
|
102
|
+
case Module.uno.com.sun.star.uno.TypeClass.EXCEPTION:
|
|
103
|
+
return Module.uno_Type.Exception(td.getName());
|
|
104
|
+
case Module.uno.com.sun.star.uno.TypeClass.INTERFACE:
|
|
105
|
+
return Module.uno_Type.Interface(td.getName());
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(
|
|
108
|
+
'bad type description ' + td.getName() + ' type class ' + td.getTypeClass());
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function translateTypeDescriptionAndDelete(td) {
|
|
112
|
+
try {
|
|
113
|
+
return translateTypeDescription(td);
|
|
114
|
+
} finally {
|
|
115
|
+
td.delete();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function translateToEmbind(obj, type, toDelete) {
|
|
119
|
+
switch (type.getTypeClass()) {
|
|
120
|
+
case Module.uno.com.sun.star.uno.TypeClass.ANY:
|
|
121
|
+
{
|
|
122
|
+
const {any, owning} = translateToAny(obj, Module.uno_Type.Any());
|
|
123
|
+
if (owning) {
|
|
124
|
+
toDelete.push(any);
|
|
125
|
+
}
|
|
126
|
+
return any;
|
|
127
|
+
}
|
|
128
|
+
case Module.uno.com.sun.star.uno.TypeClass.SEQUENCE:
|
|
129
|
+
if (Array.isArray(obj)) {
|
|
130
|
+
const ctype = type.getSequenceComponentType();
|
|
131
|
+
const seq = new (getEmbindSequenceCtor(ctype))(
|
|
132
|
+
obj.length, Module.uno_Sequence.FromSize);
|
|
133
|
+
for (let i = 0; i !== obj.length; ++i) {
|
|
134
|
+
seq.set(i, translateToEmbind(obj[i], ctype, toDelete));
|
|
135
|
+
}
|
|
136
|
+
ctype.delete();
|
|
137
|
+
toDelete.push(seq);
|
|
138
|
+
return seq;
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRUCT:
|
|
142
|
+
case Module.uno.com.sun.star.uno.TypeClass.EXCEPTION:
|
|
143
|
+
{
|
|
144
|
+
const val = {};
|
|
145
|
+
function walk(td) {
|
|
146
|
+
const base = td.getBaseType();
|
|
147
|
+
if (base !== null) {
|
|
148
|
+
const td = Module.uno.com.sun.star.reflection.XCompoundTypeDescription
|
|
149
|
+
.query(base);
|
|
150
|
+
base.delete();
|
|
151
|
+
walk(td);
|
|
152
|
+
td.delete();
|
|
153
|
+
}
|
|
154
|
+
const types = td.getMemberTypes();
|
|
155
|
+
const names = td.getMemberNames();
|
|
156
|
+
for (let i = 0; i !== types.size(); ++i) {
|
|
157
|
+
const name = names.get(i);
|
|
158
|
+
const type = translateTypeDescriptionAndDelete(types.get(i));
|
|
159
|
+
val[name] = translateToEmbind(obj[name], type, toDelete);
|
|
160
|
+
type.delete();
|
|
161
|
+
}
|
|
162
|
+
types.delete();
|
|
163
|
+
names.delete();
|
|
164
|
+
};
|
|
165
|
+
const tdm = getTypeDescriptionManager();
|
|
166
|
+
const tdAny = tdm.getByHierarchicalName(type.toString());
|
|
167
|
+
tdm.delete();
|
|
168
|
+
const ifc = tdAny.get();
|
|
169
|
+
tdAny.delete();
|
|
170
|
+
const td = Module.uno.com.sun.star.reflection.XCompoundTypeDescription.query(
|
|
171
|
+
ifc);
|
|
172
|
+
ifc.delete();
|
|
173
|
+
walk(td);
|
|
174
|
+
td.delete();
|
|
175
|
+
return val;
|
|
176
|
+
}
|
|
177
|
+
case Module.uno.com.sun.star.uno.TypeClass.INTERFACE:
|
|
178
|
+
if (obj !== null) {
|
|
179
|
+
const target = obj[getProxyTarget];
|
|
180
|
+
const handle = target === undefined ? obj : target;
|
|
181
|
+
if (handle instanceof Module.ClassHandle) {
|
|
182
|
+
if (type.toString() === 'com.sun.star.uno.XInterface') {
|
|
183
|
+
return handle;
|
|
184
|
+
}
|
|
185
|
+
const embindType = 'uno_Type_' + type.toString().replace(/\./g, '$');
|
|
186
|
+
if (embindType === handle.$$.ptrType.registeredClass.name) {
|
|
187
|
+
return handle;
|
|
188
|
+
} else {
|
|
189
|
+
const ifc = Module[embindType].query(handle);
|
|
190
|
+
toDelete.push(ifc);
|
|
191
|
+
return ifc;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
return obj;
|
|
198
|
+
};
|
|
199
|
+
function translateToAny(obj, type) {
|
|
200
|
+
try {
|
|
201
|
+
let any;
|
|
202
|
+
let owning;
|
|
203
|
+
if (obj instanceof Module.uno_Any) {
|
|
204
|
+
any = obj;
|
|
205
|
+
owning = false;
|
|
206
|
+
} else {
|
|
207
|
+
let fromType;
|
|
208
|
+
let val;
|
|
209
|
+
if (type.getTypeClass() === Module.uno.com.sun.star.uno.TypeClass.ANY) {
|
|
210
|
+
fromType = getAnyType(obj);
|
|
211
|
+
if (fromType === undefined) {
|
|
212
|
+
throw new Error('bad UNO method call argument ' + obj);
|
|
213
|
+
}
|
|
214
|
+
val = fromAny(obj);
|
|
215
|
+
} else {
|
|
216
|
+
fromType = type;
|
|
217
|
+
val = obj;
|
|
218
|
+
}
|
|
219
|
+
const toDelete = [];
|
|
220
|
+
any = new Module.uno_Any(fromType, translateToEmbind(val, fromType, toDelete));
|
|
221
|
+
owning = true;
|
|
222
|
+
toDelete.forEach((val) => val.delete());
|
|
223
|
+
}
|
|
224
|
+
return {any, owning};
|
|
225
|
+
} finally {
|
|
226
|
+
type.delete();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function translateFromEmbind(val, type, precise, cleanUpVal) {
|
|
230
|
+
switch (type.getTypeClass()) {
|
|
231
|
+
case Module.uno.com.sun.star.uno.TypeClass.BOOLEAN:
|
|
232
|
+
return Boolean(val);
|
|
233
|
+
case Module.uno.com.sun.star.uno.TypeClass.TYPE:
|
|
234
|
+
return gcWrap(val);
|
|
235
|
+
case Module.uno.com.sun.star.uno.TypeClass.ANY:
|
|
236
|
+
{
|
|
237
|
+
const ty = gcWrap(val.getType());
|
|
238
|
+
let v;
|
|
239
|
+
try {
|
|
240
|
+
v = translateFromEmbind(val.get(), ty, precise, cleanUpVal);
|
|
241
|
+
} finally {
|
|
242
|
+
if (cleanUpVal) {
|
|
243
|
+
val.delete();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return precise ? new Any(ty, v) : v;
|
|
247
|
+
}
|
|
248
|
+
case Module.uno.com.sun.star.uno.TypeClass.SEQUENCE:
|
|
249
|
+
{
|
|
250
|
+
const td = type.getSequenceComponentType();
|
|
251
|
+
const arr = [];
|
|
252
|
+
for (let i = 0; i !== val.size(); ++i) {
|
|
253
|
+
arr.push(translateFromEmbind(val.get(i), td, precise, cleanUpVal));
|
|
254
|
+
}
|
|
255
|
+
if (cleanUpVal) {
|
|
256
|
+
val.delete();
|
|
257
|
+
}
|
|
258
|
+
td.delete();
|
|
259
|
+
return arr;
|
|
260
|
+
}
|
|
261
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRUCT:
|
|
262
|
+
case Module.uno.com.sun.star.uno.TypeClass.EXCEPTION:
|
|
263
|
+
{
|
|
264
|
+
const obj = {
|
|
265
|
+
[Module.unoTagSymbol]: {
|
|
266
|
+
kind: type.getTypeClass()
|
|
267
|
+
== Module.uno.com.sun.star.uno.TypeClass.STRUCT
|
|
268
|
+
? 'struct-instance' : 'exception-instance',
|
|
269
|
+
type: type.toString()
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
function walk(td) {
|
|
273
|
+
const base = td.getBaseType();
|
|
274
|
+
if (base !== null) {
|
|
275
|
+
const td = Module.uno.com.sun.star.reflection.XCompoundTypeDescription
|
|
276
|
+
.query(base);
|
|
277
|
+
base.delete();
|
|
278
|
+
walk(td);
|
|
279
|
+
td.delete();
|
|
280
|
+
}
|
|
281
|
+
const types = td.getMemberTypes();
|
|
282
|
+
const names = td.getMemberNames();
|
|
283
|
+
for (let i = 0; i !== types.size(); ++i) {
|
|
284
|
+
const name = names.get(i);
|
|
285
|
+
const td = translateTypeDescriptionAndDelete(types.get(i));
|
|
286
|
+
obj[name] = translateFromEmbind(val[name], td, precise, cleanUpVal);
|
|
287
|
+
td.delete();
|
|
288
|
+
}
|
|
289
|
+
types.delete();
|
|
290
|
+
names.delete();
|
|
291
|
+
};
|
|
292
|
+
const tdm = getTypeDescriptionManager();
|
|
293
|
+
const tdAny = tdm.getByHierarchicalName(type.toString());
|
|
294
|
+
tdm.delete();
|
|
295
|
+
const ifc = tdAny.get();
|
|
296
|
+
tdAny.delete();
|
|
297
|
+
const td = Module.uno.com.sun.star.reflection.XCompoundTypeDescription.query(
|
|
298
|
+
ifc);
|
|
299
|
+
ifc.delete();
|
|
300
|
+
walk(td);
|
|
301
|
+
td.delete();
|
|
302
|
+
return obj;
|
|
303
|
+
}
|
|
304
|
+
case Module.uno.com.sun.star.uno.TypeClass.INTERFACE:
|
|
305
|
+
return proxy(val);
|
|
306
|
+
default:
|
|
307
|
+
return val;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
function translateFromAny(any, type, precise) {
|
|
311
|
+
if (type.getTypeClass() === Module.uno.com.sun.star.uno.TypeClass.ANY) {
|
|
312
|
+
return translateFromEmbind(any, type, precise, false);
|
|
313
|
+
} else {
|
|
314
|
+
const td = any.getType();
|
|
315
|
+
const val = translateFromEmbind(any.get(), td, precise, true);
|
|
316
|
+
td.delete();
|
|
317
|
+
return val;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
function translateFromAnyAndDelete(any, type, precise) {
|
|
321
|
+
const val = translateFromAny(any, type, precise);
|
|
322
|
+
any.delete();
|
|
323
|
+
return val;
|
|
324
|
+
};
|
|
325
|
+
function proxy(unoObject) {
|
|
326
|
+
if (unoObject === null) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
const prox = {};
|
|
330
|
+
const toDelete = [unoObject];
|
|
331
|
+
Module.uno$zetajs_deleteRegistry.register(prox, toDelete);
|
|
332
|
+
prox[getProxyTarget] = unoObject;
|
|
333
|
+
prox.$precise = {[getProxyTarget]: unoObject, [keepAlive]: prox};
|
|
334
|
+
// css.script.XInvocation2::getInfo invents additional members (e.g., an attribute "Foo"
|
|
335
|
+
// if there is a method "getFoo"), so better determine the actual set of members via
|
|
336
|
+
// css.lang.XTypeProvider::getTypes:
|
|
337
|
+
const typeprov = Module.uno.com.sun.star.lang.XTypeProvider.query(unoObject);
|
|
338
|
+
if (typeprov !== null) {
|
|
339
|
+
const ty = Module.uno_Type.Interface('com.sun.star.uno.XInterface');
|
|
340
|
+
const arg = new Module.uno_Any(ty, unoObject);
|
|
341
|
+
ty.delete();
|
|
342
|
+
const args = new Module.uno_Sequence_any([arg]);
|
|
343
|
+
arg.delete();
|
|
344
|
+
const ctx = Module.getUnoComponentContext();
|
|
345
|
+
const serv = Module.uno.com.sun.star.script.Invocation.create(ctx);
|
|
346
|
+
ctx.delete();
|
|
347
|
+
const inst = serv.createInstanceWithArguments(args);
|
|
348
|
+
args.delete();
|
|
349
|
+
serv.delete();
|
|
350
|
+
const invoke = Module.uno.com.sun.star.script.XInvocation2.query(inst);
|
|
351
|
+
inst.delete();
|
|
352
|
+
toDelete.push(invoke);
|
|
353
|
+
function invokeMethod(name, args, precise) {
|
|
354
|
+
const info = invoke.getInfoForName(name, true);
|
|
355
|
+
try {
|
|
356
|
+
if (args.length != info.aParamTypes.size()) {
|
|
357
|
+
throw new Error(
|
|
358
|
+
'bad number of arguments in call to ' + name + ', expected ' +
|
|
359
|
+
info.aParamTypes.size() + ' vs. actual ' + args.length);
|
|
360
|
+
}
|
|
361
|
+
const unoArgs = new Module.uno_Sequence_any(
|
|
362
|
+
info.aParamTypes.size(), Module.uno_Sequence.FromSize);
|
|
363
|
+
const deleteArgs = [];
|
|
364
|
+
for (let i = 0; i !== info.aParamTypes.size(); ++i) {
|
|
365
|
+
switch (info.aParamModes.get(i)) {
|
|
366
|
+
case Module.uno.com.sun.star.reflection.ParamMode.IN:
|
|
367
|
+
{
|
|
368
|
+
const {any, owning} = translateToAny(
|
|
369
|
+
args[i], info.aParamTypes.get(i));
|
|
370
|
+
unoArgs.set(i, any);
|
|
371
|
+
if (owning) {
|
|
372
|
+
deleteArgs.push(any);
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case Module.uno.com.sun.star.reflection.ParamMode.INOUT:
|
|
377
|
+
{
|
|
378
|
+
const {any, owning} = translateToAny(
|
|
379
|
+
args[i].val, info.aParamTypes.get(i));
|
|
380
|
+
unoArgs.set(i, any);
|
|
381
|
+
if (owning) {
|
|
382
|
+
deleteArgs.push(any);
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const outparamindex_out = new Module.uno_InOutParam_sequence_short;
|
|
389
|
+
const outparam_out = new Module.uno_InOutParam_sequence_any;
|
|
390
|
+
let ret;
|
|
391
|
+
try {
|
|
392
|
+
ret = invoke.invoke(name, unoArgs, outparamindex_out, outparam_out);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
outparamindex_out.delete();
|
|
395
|
+
outparam_out.delete();
|
|
396
|
+
const exc = catchUnoException(e);
|
|
397
|
+
if (getAnyType(exc) ==
|
|
398
|
+
'com.sun.star.reflection.InvocationTargetException')
|
|
399
|
+
{
|
|
400
|
+
throwUnoException(exc.TargetException);
|
|
401
|
+
} else {
|
|
402
|
+
throwUnoException(exc);
|
|
403
|
+
}
|
|
404
|
+
} finally {
|
|
405
|
+
deleteArgs.forEach((arg) => arg.delete());
|
|
406
|
+
unoArgs.delete();
|
|
407
|
+
}
|
|
408
|
+
const outparamindex = outparamindex_out.val;
|
|
409
|
+
outparamindex_out.delete();
|
|
410
|
+
const outparam = outparam_out.val;
|
|
411
|
+
outparam_out.delete();
|
|
412
|
+
for (let i = 0; i !== outparamindex.size(); ++i) {
|
|
413
|
+
const j = outparamindex.get(i);
|
|
414
|
+
const ty = info.aParamTypes.get(j);
|
|
415
|
+
args[j].val = translateFromAnyAndDelete(outparam.get(i), ty, precise);
|
|
416
|
+
ty.delete();
|
|
417
|
+
}
|
|
418
|
+
outparamindex.delete();
|
|
419
|
+
outparam.delete();
|
|
420
|
+
return translateFromAnyAndDelete(ret, info.aType, precise);
|
|
421
|
+
} finally {
|
|
422
|
+
info.aType.delete();
|
|
423
|
+
info.aParamTypes.delete();
|
|
424
|
+
info.aParamModes.delete();
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
function invokeGetter(name, precise) {
|
|
428
|
+
const info = invoke.getInfoForName(name, true);
|
|
429
|
+
try {
|
|
430
|
+
const ret = invoke.getValue(name);
|
|
431
|
+
return translateFromAnyAndDelete(ret, info.aType, precise);
|
|
432
|
+
} finally {
|
|
433
|
+
info.aType.delete();
|
|
434
|
+
info.aParamTypes.delete();
|
|
435
|
+
info.aParamModes.delete();
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
function invokeSetter(name, value) {
|
|
439
|
+
const info = invoke.getInfoForName(name, true);
|
|
440
|
+
const deleteArgs = [];
|
|
441
|
+
const {any, owning} = translateToAny(value, info.aType);
|
|
442
|
+
if (owning) {
|
|
443
|
+
deleteArgs.push(any);
|
|
444
|
+
}
|
|
445
|
+
try {
|
|
446
|
+
invoke.setValue(name, any);
|
|
447
|
+
} finally {
|
|
448
|
+
// info.aType already deleted in translateToAny above
|
|
449
|
+
info.aParamTypes.delete();
|
|
450
|
+
info.aParamModes.delete();
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
prox.queryInterface = function() {
|
|
454
|
+
return invokeMethod('queryInterface', arguments, false); };
|
|
455
|
+
prox.$precise.queryInterface = function() {
|
|
456
|
+
return invokeMethod('queryInterface', arguments, true); };
|
|
457
|
+
const seen = {'com.sun.star.uno.XInterface': true};
|
|
458
|
+
function walk(td) {
|
|
459
|
+
const iname = td.getName();
|
|
460
|
+
if (!Object.hasOwn(seen, iname)) {
|
|
461
|
+
seen[iname] = true;
|
|
462
|
+
if (td.getTypeClass() !== Module.uno.com.sun.star.uno.TypeClass.INTERFACE) {
|
|
463
|
+
throw new Error('not a UNO interface type: ' + iname);
|
|
464
|
+
}
|
|
465
|
+
const itd = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2
|
|
466
|
+
.query(td);
|
|
467
|
+
const bases = itd.getBaseTypes();
|
|
468
|
+
for (let i = 0; i !== bases.size(); ++i) {
|
|
469
|
+
const base = bases.get(i);
|
|
470
|
+
walk(base);
|
|
471
|
+
base.delete();
|
|
472
|
+
}
|
|
473
|
+
bases.delete();
|
|
474
|
+
const mems = itd.getMembers();
|
|
475
|
+
for (let i = 0; i !== mems.size(); ++i) {
|
|
476
|
+
const mem = mems.get(i);
|
|
477
|
+
const name = mem.getMemberName();
|
|
478
|
+
const atd = Module.uno.com.sun.star.reflection
|
|
479
|
+
.XInterfaceAttributeTypeDescription.query(mem);
|
|
480
|
+
mem.delete();
|
|
481
|
+
if (atd !== null) {
|
|
482
|
+
Object.defineProperty(prox, name, {
|
|
483
|
+
enumerable: true,
|
|
484
|
+
get() { return invokeGetter(name, false); },
|
|
485
|
+
set: atd.isReadOnly()
|
|
486
|
+
? undefined
|
|
487
|
+
: function(value) { return invokeSetter(name, value); }});
|
|
488
|
+
Object.defineProperty(prox.$precise, name, {
|
|
489
|
+
enumerable: true,
|
|
490
|
+
get() { return invokeGetter(name, true); },
|
|
491
|
+
set: atd.isReadOnly()
|
|
492
|
+
? undefined
|
|
493
|
+
: function(value) { return invokeSetter(name, value); }});
|
|
494
|
+
atd.delete();
|
|
495
|
+
} else {
|
|
496
|
+
prox[name] = function() { return invokeMethod(name, arguments, false); };
|
|
497
|
+
prox.$precise[name] = function() { return invokeMethod(name, arguments, true); };
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
itd.delete();
|
|
501
|
+
mems.delete();
|
|
502
|
+
if (iname === 'com.sun.star.container.XEnumeration') {
|
|
503
|
+
prox[Symbol.iterator] = function*() {
|
|
504
|
+
while (prox.hasMoreElements()) {
|
|
505
|
+
yield prox.nextElement();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
prox.$precise[Symbol.iterator] = function*() {
|
|
509
|
+
while (prox.$precise.hasMoreElements()) {
|
|
510
|
+
yield prox.$precise.nextElement();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
const tdm = getTypeDescriptionManager();
|
|
517
|
+
const types = typeprov.getTypes();
|
|
518
|
+
typeprov.delete();
|
|
519
|
+
for (let i = 0; i != types.size(); ++i) {
|
|
520
|
+
const ty = types.get(i);
|
|
521
|
+
const td = tdm.getByHierarchicalName(ty.toString());
|
|
522
|
+
ty.delete();
|
|
523
|
+
const ifc1 = td.get();
|
|
524
|
+
td.delete();
|
|
525
|
+
const ifc2 = Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc1);
|
|
526
|
+
ifc1.delete();
|
|
527
|
+
walk(ifc2);
|
|
528
|
+
ifc2.delete();
|
|
529
|
+
}
|
|
530
|
+
tdm.delete();
|
|
531
|
+
types.delete();
|
|
532
|
+
}
|
|
533
|
+
return prox;
|
|
534
|
+
};
|
|
535
|
+
function singleton(name) {
|
|
536
|
+
return function(context) {
|
|
537
|
+
const any = context.getValueByName('/singletons/' + name);
|
|
538
|
+
if (getAnyType(any).getTypeClass() !==
|
|
539
|
+
Module.uno.com.sun.star.uno.TypeClass.INTERFACE
|
|
540
|
+
|| any === null)
|
|
541
|
+
{
|
|
542
|
+
throwUnoException(
|
|
543
|
+
new uno.com.sun.star.uno.DeploymentException(
|
|
544
|
+
{Message: 'cannot get singeleton ' + name}));
|
|
545
|
+
}
|
|
546
|
+
return fromAny(any);
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
function service(name, td) {
|
|
550
|
+
const obj = {};
|
|
551
|
+
const ctors = td.getConstructors();
|
|
552
|
+
for (let i = 0; i !== ctors.size(); ++i) {
|
|
553
|
+
const ctor = ctors.get(i);
|
|
554
|
+
if (ctor.isDefaultConstructor()) {
|
|
555
|
+
obj.create = function(context) {
|
|
556
|
+
const ifc = context.getServiceManager().createInstanceWithContext(
|
|
557
|
+
name, context);
|
|
558
|
+
if (ifc === null) {
|
|
559
|
+
throwUnoException(
|
|
560
|
+
new uno.com.sun.star.uno.DeploymentException(
|
|
561
|
+
{Message:
|
|
562
|
+
'cannot instantiate single-interface service ' + name}));
|
|
563
|
+
}
|
|
564
|
+
return ifc;
|
|
565
|
+
};
|
|
566
|
+
} else {
|
|
567
|
+
obj[ctor.getName()] = function() {
|
|
568
|
+
const context = arguments[0];
|
|
569
|
+
const args = [];
|
|
570
|
+
const params = ctor.getParameters();
|
|
571
|
+
for (let j = 0; j !== params.size(); ++j) {
|
|
572
|
+
const param = params.get(j);
|
|
573
|
+
if (param.isRestParameter()) {
|
|
574
|
+
for (; j + 1 < arguments.length; ++j) {
|
|
575
|
+
args.push(arguments[j + 1]);
|
|
576
|
+
}
|
|
577
|
+
break;
|
|
578
|
+
} else {
|
|
579
|
+
let arg = arguments[j + 1];
|
|
580
|
+
const ty = param.getType();
|
|
581
|
+
if (ty.getTypeClass() !== Module.uno.com.sun.star.uno.TypeClass.ANY)
|
|
582
|
+
{
|
|
583
|
+
arg = new Any(
|
|
584
|
+
gcWrap(translateTypeDescriptionAndDelete(param.getType())),
|
|
585
|
+
arg);
|
|
586
|
+
}
|
|
587
|
+
ty.delete();
|
|
588
|
+
args.push(arg);
|
|
589
|
+
}
|
|
590
|
+
param.delete();
|
|
591
|
+
}
|
|
592
|
+
params.delete();
|
|
593
|
+
const ifc = context.getServiceManager()
|
|
594
|
+
.createInstanceWithArgumentsAndContext(name, args, context);
|
|
595
|
+
if (ifc === null) {
|
|
596
|
+
throwUnoException(
|
|
597
|
+
new uno.com.sun.star.uno.DeploymentException(
|
|
598
|
+
{Message:
|
|
599
|
+
'cannot instantiate single-interface service ' + name}));
|
|
600
|
+
}
|
|
601
|
+
return ifc;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
ctors.delete();
|
|
606
|
+
return obj;
|
|
607
|
+
};
|
|
608
|
+
function defaultValue(type) {
|
|
609
|
+
switch (type.getTypeClass()) {
|
|
610
|
+
case Module.uno.com.sun.star.uno.TypeClass.BOOLEAN:
|
|
611
|
+
return false;
|
|
612
|
+
case Module.uno.com.sun.star.uno.TypeClass.BYTE:
|
|
613
|
+
case Module.uno.com.sun.star.uno.TypeClass.SHORT:
|
|
614
|
+
case Module.uno.com.sun.star.uno.TypeClass.UNSIGNED_SHORT:
|
|
615
|
+
case Module.uno.com.sun.star.uno.TypeClass.LONG:
|
|
616
|
+
case Module.uno.com.sun.star.uno.TypeClass.UNSIGNED_LONG:
|
|
617
|
+
case Module.uno.com.sun.star.uno.TypeClass.FLOAT:
|
|
618
|
+
case Module.uno.com.sun.star.uno.TypeClass.DOUBLE:
|
|
619
|
+
return 0;
|
|
620
|
+
case Module.uno.com.sun.star.uno.TypeClass.HYPER:
|
|
621
|
+
case Module.uno.com.sun.star.uno.TypeClass.UNSIGNED_HYPER:
|
|
622
|
+
return 0n;
|
|
623
|
+
case Module.uno.com.sun.star.uno.TypeClass.CHAR:
|
|
624
|
+
return '\0';
|
|
625
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRING:
|
|
626
|
+
return '';
|
|
627
|
+
case Module.uno.com.sun.star.uno.TypeClass.TYPE:
|
|
628
|
+
return Module.uno_Type.Void();
|
|
629
|
+
case Module.uno.com.sun.star.uno.TypeClass.ANY:
|
|
630
|
+
return undefined;
|
|
631
|
+
case Module.uno.com.sun.star.uno.TypeClass.SEQUENCE:
|
|
632
|
+
return [];
|
|
633
|
+
case Module.uno.com.sun.star.uno.TypeClass.ENUM:
|
|
634
|
+
{
|
|
635
|
+
const tdm = getTypeDescriptionManager();
|
|
636
|
+
const tdAny = tdm.getByHierarchicalName(type.toString());
|
|
637
|
+
tdm.delete();
|
|
638
|
+
const ifc = tdAny.get();
|
|
639
|
+
tdAny.delete();
|
|
640
|
+
const td = Module.uno.com.sun.star.reflection.XEnumTypeDescription.query(ifc);
|
|
641
|
+
ifc.delete();
|
|
642
|
+
const names = td.getEnumNames();
|
|
643
|
+
td.delete();
|
|
644
|
+
const first = names.get(0);
|
|
645
|
+
names.delete();
|
|
646
|
+
return Module['uno_Type_' + type.toString().replace(/\./g, '$')][first];
|
|
647
|
+
}
|
|
648
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRUCT:
|
|
649
|
+
{
|
|
650
|
+
//TODO: Make val an instanceof the corresponding struct constructor function:
|
|
651
|
+
const tdm = getTypeDescriptionManager();
|
|
652
|
+
const tdAny = tdm.getByHierarchicalName(type.toString());
|
|
653
|
+
tdm.delete();
|
|
654
|
+
const ifc = tdAny.get();
|
|
655
|
+
tdAny.delete();
|
|
656
|
+
const td = Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc);
|
|
657
|
+
ifc.delete();
|
|
658
|
+
const members = {};
|
|
659
|
+
computeMembers(td, members);
|
|
660
|
+
td.delete();
|
|
661
|
+
const val = {};
|
|
662
|
+
populate(val, [], members);
|
|
663
|
+
return val;
|
|
664
|
+
}
|
|
665
|
+
case Module.uno.com.sun.star.uno.TypeClass.INTERFACE:
|
|
666
|
+
return null;
|
|
667
|
+
default:
|
|
668
|
+
throw new Error('bad member type ' + type);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function TypeArgumentIndex(index) { this.index = index; };
|
|
672
|
+
function computeMembers(type, obj) {
|
|
673
|
+
const td = Module.uno.com.sun.star.reflection.XCompoundTypeDescription.query(type);
|
|
674
|
+
const base = td.getBaseType();
|
|
675
|
+
if (base !== null) {
|
|
676
|
+
computeMembers(base, obj);
|
|
677
|
+
base.delete();
|
|
678
|
+
}
|
|
679
|
+
const types = td.getMemberTypes();
|
|
680
|
+
const names = td.getMemberNames();
|
|
681
|
+
td.delete();
|
|
682
|
+
for (let i = 0; i !== types.size(); ++i) {
|
|
683
|
+
const memtype = types.get(i);
|
|
684
|
+
let val;
|
|
685
|
+
if (memtype.getTypeClass() === Module.uno.com.sun.star.uno.TypeClass.UNKNOWN) {
|
|
686
|
+
const paramName = memtype.getName();
|
|
687
|
+
const std = Module.uno.com.sun.star.reflection.XStructTypeDescription.query(
|
|
688
|
+
type);
|
|
689
|
+
const params = std.getTypeParameters();
|
|
690
|
+
std.delete();
|
|
691
|
+
let index = 0;
|
|
692
|
+
for (; index !== params.size(); ++index) {
|
|
693
|
+
if (params.get(index) === paramName) {
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
params.delete();
|
|
698
|
+
val = new TypeArgumentIndex(index);
|
|
699
|
+
} else {
|
|
700
|
+
const type = translateTypeDescription(memtype);
|
|
701
|
+
val = defaultValue(type);
|
|
702
|
+
type.delete();
|
|
703
|
+
}
|
|
704
|
+
memtype.delete();
|
|
705
|
+
obj[names.get(i)] = val;
|
|
706
|
+
}
|
|
707
|
+
types.delete();
|
|
708
|
+
names.delete();
|
|
709
|
+
};
|
|
710
|
+
function populate(obj, types, members, values) {
|
|
711
|
+
for (let i in members) {
|
|
712
|
+
let val;
|
|
713
|
+
if (values !== undefined && i in values) {
|
|
714
|
+
val = values[i];
|
|
715
|
+
} else {
|
|
716
|
+
val = members[i];
|
|
717
|
+
if (val instanceof TypeArgumentIndex) {
|
|
718
|
+
val = defaultValue(types[val.index]);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
obj[i] = val;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
function instantiationName(templateName, types) {
|
|
725
|
+
let name = templateName + '<';
|
|
726
|
+
for (let i = 0; i !== types.length; ++i) {
|
|
727
|
+
if (i !== 0) {
|
|
728
|
+
name += ',';
|
|
729
|
+
}
|
|
730
|
+
name += types[i];
|
|
731
|
+
}
|
|
732
|
+
return name + '>';
|
|
733
|
+
}
|
|
734
|
+
function unoidlProxy(path, embindObject) {
|
|
735
|
+
return new Proxy({}, {
|
|
736
|
+
get(target, prop) {
|
|
737
|
+
if (!Object.hasOwn(target, prop)) {
|
|
738
|
+
const name = path + '.' + prop;
|
|
739
|
+
const tdm = getTypeDescriptionManager();
|
|
740
|
+
const tdAny = tdm.getByHierarchicalName(name);
|
|
741
|
+
tdm.delete();
|
|
742
|
+
const ifc = tdAny.get();
|
|
743
|
+
tdAny.delete();
|
|
744
|
+
const td = Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc);
|
|
745
|
+
ifc.delete();
|
|
746
|
+
switch (td.getTypeClass()) {
|
|
747
|
+
case Module.uno.com.sun.star.uno.TypeClass.ENUM:
|
|
748
|
+
target[prop] = embindObject[prop];
|
|
749
|
+
target[prop][Module.unoTagSymbol] = {kind: 'enum', type: name};
|
|
750
|
+
break;
|
|
751
|
+
case Module.uno.com.sun.star.uno.TypeClass.STRUCT:
|
|
752
|
+
{
|
|
753
|
+
const members = {};
|
|
754
|
+
computeMembers(td, members);
|
|
755
|
+
const std = Module.uno.com.sun.star.reflection
|
|
756
|
+
.XStructTypeDescription.query(td);
|
|
757
|
+
const params = std.getTypeParameters();
|
|
758
|
+
std.delete();
|
|
759
|
+
const paramCount = params.size();
|
|
760
|
+
params.delete();
|
|
761
|
+
if (paramCount === 0) {
|
|
762
|
+
target[prop] = function(values) {
|
|
763
|
+
populate(this, [], members, values);
|
|
764
|
+
this[Module.unoTagSymbol] = {
|
|
765
|
+
kind: 'struct-instance', type: name};
|
|
766
|
+
};
|
|
767
|
+
} else {
|
|
768
|
+
target[prop] = function(types, values) {
|
|
769
|
+
if (types.length !== paramCount) {
|
|
770
|
+
throw new Error(
|
|
771
|
+
'bad number of type arguments in call to ' + name +
|
|
772
|
+
', expected ' + paramCount + ' vs. actual ' +
|
|
773
|
+
types.length);
|
|
774
|
+
}
|
|
775
|
+
populate(this, types, members, values);
|
|
776
|
+
this[Module.unoTagSymbol] = {
|
|
777
|
+
kind: 'struct-instance',
|
|
778
|
+
type: instantiationName(name, types)};
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
target[prop][Module.unoTagSymbol] = {kind: 'struct', type: name};
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
case Module.uno.com.sun.star.uno.TypeClass.EXCEPTION:
|
|
785
|
+
{
|
|
786
|
+
const members = {};
|
|
787
|
+
computeMembers(td, members);
|
|
788
|
+
target[prop] = function(values) {
|
|
789
|
+
populate(this, [], members, values);
|
|
790
|
+
this[Module.unoTagSymbol] = {
|
|
791
|
+
kind: 'exception-instance', type: name};
|
|
792
|
+
};
|
|
793
|
+
target[prop][Module.unoTagSymbol] = {kind: 'exception', type: name};
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
case Module.uno.com.sun.star.uno.TypeClass.INTERFACE:
|
|
797
|
+
target[prop] = {[Module.unoTagSymbol]: {kind: 'interface', type: name}};
|
|
798
|
+
break;
|
|
799
|
+
case Module.uno.com.sun.star.uno.TypeClass.MODULE:
|
|
800
|
+
target[prop] = unoidlProxy(name, embindObject[prop]);
|
|
801
|
+
break;
|
|
802
|
+
case Module.uno.com.sun.star.uno.TypeClass.SINGLETON:
|
|
803
|
+
target[prop] = singleton(name);
|
|
804
|
+
break;
|
|
805
|
+
case Module.uno.com.sun.star.uno.TypeClass.SERVICE:
|
|
806
|
+
{
|
|
807
|
+
const std = Module.uno.com.sun.star.reflection
|
|
808
|
+
.XServiceTypeDescription2.query(td);
|
|
809
|
+
if (std.isSingleInterfaceBased()) {
|
|
810
|
+
target[prop] = service(name, std);
|
|
811
|
+
}
|
|
812
|
+
std.delete();
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
case Module.uno.com.sun.star.uno.TypeClass.CONSTANTS:
|
|
816
|
+
target[prop] = embindObject[prop];
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
td.delete();
|
|
820
|
+
}
|
|
821
|
+
return target[prop];
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
};
|
|
825
|
+
function Any(type, val) {
|
|
826
|
+
this.type = type;
|
|
827
|
+
this.val = val;
|
|
828
|
+
};
|
|
829
|
+
function getAnyType(val) {
|
|
830
|
+
switch (typeof val) {
|
|
831
|
+
case 'undefined':
|
|
832
|
+
return gcWrap(Module.uno_Type.Void());
|
|
833
|
+
case 'boolean':
|
|
834
|
+
return gcWrap(Module.uno_Type.Boolean());
|
|
835
|
+
case 'number':
|
|
836
|
+
return gcWrap(
|
|
837
|
+
Number.isInteger(val) && val >= -0x80000000 && val < 0x80000000
|
|
838
|
+
? Module.uno_Type.Long()
|
|
839
|
+
: Number.isInteger(val) && val >= 0 && val < 0x100000000
|
|
840
|
+
? Module.uno_Type.UnsignedLong()
|
|
841
|
+
: Module.uno_Type.Double());
|
|
842
|
+
case 'bigint':
|
|
843
|
+
return gcWrap(
|
|
844
|
+
val < 0x8000000000000000n
|
|
845
|
+
? Module.uno_Type.Hyper() : Module.uno_Type.UnsignedHyper());
|
|
846
|
+
case 'string':
|
|
847
|
+
return gcWrap(Module.uno_Type.String());
|
|
848
|
+
case 'object':
|
|
849
|
+
if (val === null || Object.hasOwn(val, getProxyTarget)) {
|
|
850
|
+
return gcWrap(Module.uno_Type.Interface('com.sun.star.uno.XInterface'));
|
|
851
|
+
} else if (val instanceof Module.uno_Type) {
|
|
852
|
+
return gcWrap(Module.uno_Type.Type());
|
|
853
|
+
} else if (val instanceof Any) {
|
|
854
|
+
return val.type;
|
|
855
|
+
} else if (val instanceof Array) {
|
|
856
|
+
const t = Module.uno_Type.Any();
|
|
857
|
+
try {
|
|
858
|
+
return gcWrap(Module.uno_Type.Sequence(t));
|
|
859
|
+
} finally {
|
|
860
|
+
t.delete();
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
const tag = val[Module.unoTagSymbol];
|
|
864
|
+
if (tag !== undefined) {
|
|
865
|
+
if (tag.kind === 'enumerator') {
|
|
866
|
+
return gcWrap(Module.uno_Type.Enum(tag.type));
|
|
867
|
+
} else if (tag.kind === 'struct-instance') {
|
|
868
|
+
return gcWrap(Module.uno_Type.Struct(tag.type));
|
|
869
|
+
} else if (tag.kind === 'exception-instance') {
|
|
870
|
+
return gcWrap(Module.uno_Type.Exception(tag.type));
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
// fallthrough
|
|
875
|
+
default:
|
|
876
|
+
return undefined;
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
function fromAny(val) { return val instanceof Any ? val.val : val; };
|
|
880
|
+
function throwUnoException(exception) {
|
|
881
|
+
const type = gcWrap(Module.uno_Type.Exception(exception[Module.unoTagSymbol].type));
|
|
882
|
+
const toDelete = [];
|
|
883
|
+
const val = translateToEmbind(exception, type, toDelete);
|
|
884
|
+
Module.throwUnoException(type, val, toDelete);
|
|
885
|
+
};
|
|
886
|
+
function catchUnoException(exception) {
|
|
887
|
+
const td = Module.uno_Type.Any();
|
|
888
|
+
try {
|
|
889
|
+
return translateFromAnyAndDelete(Module.catchUnoException(exception), td);
|
|
890
|
+
} finally {
|
|
891
|
+
td.delete();
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
const uno = new Proxy({}, {
|
|
895
|
+
get(target, prop) {
|
|
896
|
+
if (!Object.hasOwn(target, prop)) {
|
|
897
|
+
const tdm = getTypeDescriptionManager();
|
|
898
|
+
const td = tdm.getByHierarchicalName(prop);
|
|
899
|
+
tdm.delete();
|
|
900
|
+
td.delete();
|
|
901
|
+
target[prop] = unoidlProxy(prop, Module.uno[prop]);
|
|
902
|
+
}
|
|
903
|
+
return target[prop];
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
const zetajs = {
|
|
907
|
+
type: {
|
|
908
|
+
void: gcWrap(Module.uno_Type.Void()),
|
|
909
|
+
boolean: gcWrap(Module.uno_Type.Boolean()),
|
|
910
|
+
byte: gcWrap(Module.uno_Type.Byte()),
|
|
911
|
+
short: gcWrap(Module.uno_Type.Short()),
|
|
912
|
+
unsigned_short: gcWrap(Module.uno_Type.UnsignedShort()),
|
|
913
|
+
long: gcWrap(Module.uno_Type.Long()),
|
|
914
|
+
unsigned_long: gcWrap(Module.uno_Type.UnsignedLong()),
|
|
915
|
+
hyper: gcWrap(Module.uno_Type.Hyper()),
|
|
916
|
+
unsigned_hyper: gcWrap(Module.uno_Type.UnsignedHyper()),
|
|
917
|
+
float: gcWrap(Module.uno_Type.Float()),
|
|
918
|
+
double: gcWrap(Module.uno_Type.Double()),
|
|
919
|
+
char: gcWrap(Module.uno_Type.Char()),
|
|
920
|
+
string: gcWrap(Module.uno_Type.String()),
|
|
921
|
+
type: gcWrap(Module.uno_Type.Type()),
|
|
922
|
+
any: gcWrap(Module.uno_Type.Any()),
|
|
923
|
+
sequence(type) { return gcWrap(Module.uno_Type.Sequence(type)); },
|
|
924
|
+
enum(name) {
|
|
925
|
+
if (typeof name === 'function' && Object.hasOwn(name, Module.unoTagSymbol)
|
|
926
|
+
&& name[Module.unoTagSymbol].kind === 'enum')
|
|
927
|
+
{
|
|
928
|
+
name = name[Module.unoTagSymbol].type;
|
|
929
|
+
}
|
|
930
|
+
return gcWrap(Module.uno_Type.Enum(name));
|
|
931
|
+
},
|
|
932
|
+
struct(name) {
|
|
933
|
+
if (typeof name === 'function' && Object.hasOwn(name, Module.unoTagSymbol)
|
|
934
|
+
&& name[Module.unoTagSymbol].kind === 'struct')
|
|
935
|
+
{
|
|
936
|
+
name = name[Module.unoTagSymbol].type;
|
|
937
|
+
}
|
|
938
|
+
return gcWrap(Module.uno_Type.Struct(name));
|
|
939
|
+
},
|
|
940
|
+
exception(name) {
|
|
941
|
+
if (typeof name === 'function' && Object.hasOwn(name, Module.unoTagSymbol)
|
|
942
|
+
&& name[Module.unoTagSymbol].kind === 'exception')
|
|
943
|
+
{
|
|
944
|
+
name = name[Module.unoTagSymbol].type;
|
|
945
|
+
}
|
|
946
|
+
return gcWrap(Module.uno_Type.Exception(name));
|
|
947
|
+
},
|
|
948
|
+
interface(name) {
|
|
949
|
+
if (typeof name === 'object' && Object.hasOwn(name, Module.unoTagSymbol)
|
|
950
|
+
&& name[Module.unoTagSymbol].kind === 'interface')
|
|
951
|
+
{
|
|
952
|
+
name = name[Module.unoTagSymbol].type;
|
|
953
|
+
}
|
|
954
|
+
return gcWrap(Module.uno_Type.Interface(name));
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
Any,
|
|
958
|
+
getAnyType,
|
|
959
|
+
fromAny,
|
|
960
|
+
sameUnoObject: function(obj1, obj2) {
|
|
961
|
+
const type = Module.uno_Type.Interface('com.sun.star.uno.XInterface');
|
|
962
|
+
const toDelete = [];
|
|
963
|
+
try {
|
|
964
|
+
return Module.sameUnoObject(
|
|
965
|
+
translateToEmbind(obj1, type, toDelete),
|
|
966
|
+
translateToEmbind(obj2, type, toDelete));
|
|
967
|
+
} finally {
|
|
968
|
+
type.delete();
|
|
969
|
+
toDelete.forEach((val) => val.delete());
|
|
970
|
+
}
|
|
971
|
+
},
|
|
972
|
+
getUnoComponentContext: function() {
|
|
973
|
+
return proxy(Module.getUnoComponentContext());
|
|
974
|
+
},
|
|
975
|
+
throwUnoException,
|
|
976
|
+
catchUnoException,
|
|
977
|
+
uno,
|
|
978
|
+
unoObject: function(interfaces, obj) {
|
|
979
|
+
const wrapper = {};
|
|
980
|
+
const toDelete = [];
|
|
981
|
+
Module.uno$zetajs_deleteRegistry.register(wrapper, toDelete);
|
|
982
|
+
const seen = {
|
|
983
|
+
'com.sun.star.lang.XTypeProvider': true, 'com.sun.star.uno.XInterface': true};
|
|
984
|
+
function walk(td) {
|
|
985
|
+
const iname = td.getName();
|
|
986
|
+
if (!Object.hasOwn(seen, iname)) {
|
|
987
|
+
seen[iname] = true;
|
|
988
|
+
if (td.getTypeClass() !== Module.uno.com.sun.star.uno.TypeClass.INTERFACE) {
|
|
989
|
+
throw new Error('not a UNO interface type: ' + iname);
|
|
990
|
+
}
|
|
991
|
+
const itd = Module.uno.com.sun.star.reflection.XInterfaceTypeDescription2
|
|
992
|
+
.query(td);
|
|
993
|
+
const bases = itd.getBaseTypes();
|
|
994
|
+
for (let i = 0; i !== bases.size(); ++i) {
|
|
995
|
+
const base = bases.get(i);
|
|
996
|
+
walk(base);
|
|
997
|
+
base.delete();
|
|
998
|
+
}
|
|
999
|
+
bases.delete();
|
|
1000
|
+
const mems = itd.getMembers();
|
|
1001
|
+
itd.delete();
|
|
1002
|
+
for (let i = 0; i !== mems.size(); ++i) {
|
|
1003
|
+
const ifc = mems.get(i);
|
|
1004
|
+
const atd = Module.uno.com.sun.star.reflection
|
|
1005
|
+
.XInterfaceAttributeTypeDescription.query(ifc);
|
|
1006
|
+
ifc.delete();
|
|
1007
|
+
if (atd !== null) {
|
|
1008
|
+
const aname = atd.getMemberName();
|
|
1009
|
+
const type = translateTypeDescriptionAndDelete(atd.getType());
|
|
1010
|
+
toDelete.push(type);
|
|
1011
|
+
wrapper['get' + aname] = function() {
|
|
1012
|
+
return translateToEmbind(
|
|
1013
|
+
obj['get' + aname].apply(obj), type, []);
|
|
1014
|
+
};
|
|
1015
|
+
if (!atd.isReadOnly()) {
|
|
1016
|
+
wrapper['set' + aname] = function() {
|
|
1017
|
+
obj['set' + aname].apply(
|
|
1018
|
+
obj, [translateFromEmbind(arguments[0], type, true, false)]);
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
atd.delete();
|
|
1022
|
+
} else {
|
|
1023
|
+
const ifc = mems.get(i);
|
|
1024
|
+
const mtd = Module.uno.com.sun.star.reflection
|
|
1025
|
+
.XInterfaceMethodTypeDescription.query(ifc);
|
|
1026
|
+
ifc.delete();
|
|
1027
|
+
const mname = mtd.getMemberName();
|
|
1028
|
+
const retType = translateTypeDescriptionAndDelete(
|
|
1029
|
+
mtd.getReturnType());
|
|
1030
|
+
toDelete.push(retType);
|
|
1031
|
+
const params = [];
|
|
1032
|
+
const descrs = mtd.getParameters();
|
|
1033
|
+
mtd.delete();
|
|
1034
|
+
for (let j = 0; j !== descrs.size(); ++j) {
|
|
1035
|
+
const descr = descrs.get(j);
|
|
1036
|
+
const type = translateTypeDescriptionAndDelete(descr.getType());
|
|
1037
|
+
toDelete.push(type);
|
|
1038
|
+
params.push({type, dirIn: descr.isIn(), dirOut: descr.isOut()});
|
|
1039
|
+
descr.delete();
|
|
1040
|
+
}
|
|
1041
|
+
descrs.delete();
|
|
1042
|
+
wrapper[mname] = function() {
|
|
1043
|
+
const args = [];
|
|
1044
|
+
for (let i = 0; i !== params.length; ++i) {
|
|
1045
|
+
let arg;
|
|
1046
|
+
if (params[i].dirOut) {
|
|
1047
|
+
arg = {};
|
|
1048
|
+
if (params[i].dirIn) {
|
|
1049
|
+
arg.val = translateFromEmbind(
|
|
1050
|
+
arguments[i].val, params[i].type, true, false);
|
|
1051
|
+
}
|
|
1052
|
+
} else {
|
|
1053
|
+
arg = translateFromEmbind(
|
|
1054
|
+
arguments[i], params[i].type, true, false);
|
|
1055
|
+
}
|
|
1056
|
+
args.push(arg);
|
|
1057
|
+
}
|
|
1058
|
+
const ret = translateToEmbind(
|
|
1059
|
+
obj[mname].apply(obj, args), retType, []);
|
|
1060
|
+
for (let i = 0; i !== params.length; ++i) {
|
|
1061
|
+
if (params[i].dirOut) {
|
|
1062
|
+
arguments[i].val = translateToEmbind(
|
|
1063
|
+
args[i].val, params[i].type, []);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return ret;
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
mems.delete();
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
const tdm = getTypeDescriptionManager();
|
|
1074
|
+
const interfaceNames = [];
|
|
1075
|
+
interfaces.forEach((i) => {
|
|
1076
|
+
let name = i;
|
|
1077
|
+
if (typeof name === 'object' && Object.hasOwn(name, Module.unoTagSymbol)
|
|
1078
|
+
&& name[Module.unoTagSymbol].kind === 'interface')
|
|
1079
|
+
{
|
|
1080
|
+
name = name[Module.unoTagSymbol].type;
|
|
1081
|
+
} else if (name instanceof Module.uno_Type
|
|
1082
|
+
&& (name.getTypeClass()
|
|
1083
|
+
=== Module.uno.com.sun.star.uno.TypeClass.INTERFACE))
|
|
1084
|
+
{
|
|
1085
|
+
name = name.toString();
|
|
1086
|
+
}
|
|
1087
|
+
interfaceNames.push(name);
|
|
1088
|
+
const tdAny = tdm.getByHierarchicalName(name);
|
|
1089
|
+
const ifc = tdAny.get();
|
|
1090
|
+
const td = Module.uno.com.sun.star.reflection.XTypeDescription.query(ifc);
|
|
1091
|
+
ifc.delete();
|
|
1092
|
+
walk(td);
|
|
1093
|
+
td.delete();
|
|
1094
|
+
})
|
|
1095
|
+
tdm.delete();
|
|
1096
|
+
return proxy(Module.unoObject(interfaceNames, wrapper));
|
|
1097
|
+
},
|
|
1098
|
+
mainPort: Module.uno_mainPort
|
|
1099
|
+
};
|
|
1100
|
+
resolve(zetajs);
|
|
1101
|
+
};
|
|
1102
|
+
Module.zetajs$reject = reject;
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
Module.uno_init.then(function() { Module.zetajs$resolve(); });
|
|
1106
|
+
|
|
1107
|
+
/* vim:set shiftwidth=2 softtabstop=2 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|