1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <sal/config.h>
15 #include <bridges/emscriptencxxabi/cxxabi.hxx>
16 #include <com/sun/star/uno/RuntimeException.hpp>
17 #include <cppu/unotype.hxx>
18 #include <rtl/ustring.hxx>
19 #include <typelib/typeclass.h>
20 #include <typelib/typedescription.h>
22 #include <uno/mapping.h>
26 abi_wasm::StructKind
abi_wasm::getKind(typelib_CompoundTypeDescription
const* type
)
28 if (type
->nMembers
> 1)
30 return StructKind::General
;
32 auto k
= StructKind::Empty
;
33 if (type
->pBaseTypeDescription
!= nullptr)
35 k
= getKind(type
->pBaseTypeDescription
);
37 if (type
->nMembers
== 0)
41 if (k
!= StructKind::Empty
)
43 return StructKind::General
;
45 switch (type
->ppTypeRefs
[0]->eTypeClass
)
47 case typelib_TypeClass_BOOLEAN
:
48 case typelib_TypeClass_BYTE
:
49 case typelib_TypeClass_SHORT
:
50 case typelib_TypeClass_UNSIGNED_SHORT
:
51 case typelib_TypeClass_LONG
:
52 case typelib_TypeClass_UNSIGNED_LONG
:
53 case typelib_TypeClass_CHAR
:
54 case typelib_TypeClass_ENUM
:
55 return StructKind::I32
;
56 case typelib_TypeClass_HYPER
:
57 case typelib_TypeClass_UNSIGNED_HYPER
:
58 return StructKind::I64
;
59 case typelib_TypeClass_FLOAT
:
60 return StructKind::F32
;
61 case typelib_TypeClass_DOUBLE
:
62 return StructKind::F64
;
64 return StructKind::General
;
68 void abi_wasm::mapException(__cxxabiv1::__cxa_exception
* exception
, std::type_info
const* type
,
69 uno_Any
* any
, uno_Mapping
* mapping
)
71 assert(exception
!= nullptr);
72 assert(type
!= nullptr);
73 OUString
unoName(emscriptencxxabi::toUnoName(type
->name()));
74 typelib_TypeDescription
* td
= nullptr;
75 typelib_typedescription_getByName(&td
, unoName
.pData
);
78 css::uno::RuntimeException
e("exception type not found: " + unoName
);
79 uno_type_any_constructAndConvert(
80 any
, &e
, cppu::UnoType
<css::uno::RuntimeException
>::get().getTypeLibType(), mapping
);
84 uno_any_constructAndConvert(any
, exception
->adjustedPtr
, td
, mapping
);
85 typelib_typedescription_release(td
);
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */