Add a toDelete parameter to Module.throwUnoException
...as there can be situations (cf. the newly added test code in embindtest.js)
where objects that need to be deleted are passed as payload of the exception
value to be thrown. So there now is a (mandatory, as Embind doesn't allow to
implicitly pass undefined) third parameter now that must be an array of objects
on which to call .delete().
(75fe059974
"Embind: throwUnoException from JS"
had deliberately made throwUnoException take two arguments, because if it
"directly took a css::uno::Any argument, JS client code would need to create one
with `new Module.uno_Any(...)` and call .delete() on it, but there is no place
where it could call .delete()". There now would be such a place, but it would
probably still be tedious most of the time to explicitly construct a new uno_Any
to pass into throwUnoException both as the exception and in the toDelete array.
So keep that design decision to have throwUnoException take individual type and
value arguments.)
Change-Id: Idec029d9e500457b02d20d899b9a2328cd7a5d7e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171024
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Tested-by: Jenkins
This commit is contained in:
parent
532a8d7ac2
commit
ac175a43c9
2 changed files with 33 additions and 3 deletions
|
@ -34,6 +34,7 @@
|
|||
#include <uno/data.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
@ -407,8 +408,15 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
|
|||
|
||||
function("getCurrentModelFromViewSh", &getCurrentModelFromViewSh);
|
||||
function("getUnoComponentContext", &comphelper::getProcessComponentContext);
|
||||
function("throwUnoException", +[](css::uno::Type const& type, emscripten::val const& value) {
|
||||
cppu::throwException(constructAny(type, value));
|
||||
function("throwUnoException", +[](css::uno::Type const& type, emscripten::val const& value,
|
||||
emscripten::val const& toDelete) {
|
||||
auto const any = constructAny(type, value);
|
||||
auto const len = toDelete["length"].as<std::size_t>();
|
||||
for (std::size_t i = 0; i != len; ++i)
|
||||
{
|
||||
toDelete[i].call<void>("delete");
|
||||
}
|
||||
cppu::throwException(any);
|
||||
});
|
||||
function("sameUnoObject",
|
||||
+[](css::uno::Reference<css::uno::XInterface> const& ref1,
|
||||
|
|
|
@ -645,6 +645,28 @@ Module.uno_init.then(function() {
|
|||
console.assert(exc.Message.startsWith('test'));
|
||||
any.delete();
|
||||
}
|
||||
try {
|
||||
const wrapped = new Module.uno_Any(
|
||||
Module.uno_Type.Exception('com.sun.star.uno.RuntimeException'),
|
||||
{Message: 'test', Context: test});
|
||||
Module.throwUnoException(
|
||||
Module.uno_Type.Exception('com.sun.star.lang.WrappedTargetException'),
|
||||
{Message: 'wrapped', Context: test, TargetException: wrapped}, [wrapped]);
|
||||
console.assert(false);
|
||||
} catch (e) {
|
||||
const any = Module.catchUnoException(e);
|
||||
console.assert(any.getType() == 'com.sun.star.lang.WrappedTargetException');
|
||||
const exc = any.get();
|
||||
console.assert(exc.Message.startsWith('wrapped'));
|
||||
console.assert(Module.sameUnoObject(exc.Context, test));
|
||||
const wrappedAny = exc.TargetException;
|
||||
console.assert(wrappedAny.getType() == 'com.sun.star.uno.RuntimeException');
|
||||
const wrappedExc = wrappedAny.get();
|
||||
console.assert(wrappedExc.Message.startsWith('test'));
|
||||
console.assert(Module.sameUnoObject(wrappedExc.Context, test));
|
||||
any.delete();
|
||||
wrappedAny.delete();
|
||||
}
|
||||
const obj = Module.unoObject(
|
||||
['com.sun.star.task.XJob', 'com.sun.star.task.XJobExecutor',
|
||||
'org.libreoffice.embindtest.XAttributes'],
|
||||
|
@ -653,7 +675,7 @@ Module.uno_init.then(function() {
|
|||
if (args.size() !== 1 || args.get(0).Name !== 'name') {
|
||||
Module.throwUnoException(
|
||||
Module.uno_Type.Exception('com.sun.star.lang.IllegalArgumentException'),
|
||||
{Message: 'bad args', Context: null, ArgumentPosition: 0});
|
||||
{Message: 'bad args', Context: null, ArgumentPosition: 0}, []);
|
||||
}
|
||||
console.log('Hello ' + args.get(0).Value.get());
|
||||
return new Module.uno_Any(Module.uno_Type.Void(), undefined);
|
||||
|
|
Loading…
Reference in a new issue