summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-07-16 10:27:10 +0200
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-07-16 12:48:49 +0200
commitf10d51709d08bdafdbd5c92f73ddb62cb217b6dd (patch)
tree979359e5fe78c4cc0d5a8420f58150974f9bc70c
parente8e6a5f7951da0cf94171fd4b9457864e9528a08 (diff)
Embind: Implement UNO interface attributes as JS accessor properties
Change-Id: I39b1f5676b2e5ba6071b39bf031c10d9c85f1ad1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170566 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
-rw-r--r--static/source/embindmaker/embindmaker.cxx67
-rw-r--r--unotest/source/embindtest/embindtest.js22
2 files changed, 38 insertions, 51 deletions
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index 78bc94b9087d..9953512a8bf0 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -481,57 +481,44 @@ void dumpAttributes(std::ostream& out, rtl::Reference<TypeManager> const& manage
{
for (auto const& attr : entity->getDirectAttributes())
{
- out << " .function(\"get" << attr.name << "\", ";
- if (baseTrail.empty())
+ out << " .property<";
+ dumpType(out, manager, attr.type);
+ out << ">(\"" << attr.name << "\", +[](" << cppName(name) << " const & the_self) { return ";
+ for (auto const& base : baseTrail)
{
- out << "&" << cppName(name) << "::get" << attr.name;
+ out << "static_cast<" << cppName(base) << " &>(";
}
- else
+ out << "const_cast<" << cppName(name) << " &>(the_self)";
+ for (std::size_t i = 0; i != baseTrail.size(); ++i)
{
- out << "+[](::com::sun::star::uno::Reference<" << cppName(name)
- << "> const & the_self) { return ";
- for (auto const& base : baseTrail)
- {
- out << "static_cast<" << cppName(base) << " *>(";
- }
- out << "the_self.get()";
- for (std::size_t i = 0; i != baseTrail.size(); ++i)
- {
- out << ")";
- }
- out << "->get" << attr.name << "(); }";
+ out << ")";
}
- out << ", ::emscripten::pure_virtual())\n";
+ out << ".get" << attr.name << "(); }";
if (!attr.readOnly)
{
- out << " .function(\"set" << attr.name << "\", ";
- if (baseTrail.empty())
+ out << ", +[](" << cppName(name) << " & the_self, ";
+ dumpType(out, manager, attr.type);
+ if (passByReference(manager, attr.type))
{
- out << "&" << cppName(name) << "::set" << attr.name;
+ out << " const &";
}
- else
+ out << " the_value) { ";
+ for (auto const& base : baseTrail)
{
- out << "+[](::com::sun::star::uno::Reference<" << cppName(name)
- << "> const & the_self, ";
- dumpType(out, manager, attr.type);
- if (passByReference(manager, attr.type))
- {
- out << " const &";
- }
- out << " the_value) { ";
- for (auto const& base : baseTrail)
- {
- out << "static_cast<" << cppName(base) << " *>(";
- }
- out << "the_self.get()";
- for (std::size_t i = 0; i != baseTrail.size(); ++i)
- {
- out << ")";
- }
- out << "->set" << attr.name << "(the_value); }";
+ out << "static_cast<" << cppName(base) << " &>(";
+ }
+ out << "the_self";
+ for (std::size_t i = 0; i != baseTrail.size(); ++i)
+ {
+ out << ")";
}
- out << ", ::emscripten::pure_virtual())\n";
+ out << ".set" << attr.name << "(the_value); }";
}
+ out << "/*only supported since "
+ "<https://github.com/emscripten-core/emscripten/commit/"
+ "09b765f76e052e6bfcf741ed6d2bae1788200734> \"[embind] Return value policy support "
+ "for properties. (#21935)\" towards emsdk 3.1.62: , "
+ "::emscripten::pure_virtual()*/)\n";
}
}
diff --git a/unotest/source/embindtest/embindtest.js b/unotest/source/embindtest/embindtest.js
index e923a4f85d0a..bb4d2716ee5d 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -688,22 +688,22 @@ Module.addOnPostRun(function() {
css.task.XJobExecutor.query(obj).trigger('from JS');
{
const attrs = Module.uno.org.libreoffice.embindtest.XAttributes.query(obj);
- console.assert(attrs.getLongAttribute() === -123456);
- attrs.setLongAttribute(789);
- console.assert(attrs.getLongAttribute() === 789);
- console.assert(attrs.getStringAttribute() === 'hä');
- attrs.setStringAttribute('foo');
- console.assert(attrs.getStringAttribute() === 'foo');
- console.assert(attrs.getReadOnlyAttribute() === 1); //TODO: true
+ console.assert(attrs.LongAttribute === -123456);
+ attrs.LongAttribute = 789;
+ console.assert(attrs.LongAttribute === 789);
+ console.assert(attrs.StringAttribute === 'hä');
+ attrs.StringAttribute = 'foo';
+ console.assert(attrs.StringAttribute === 'foo');
+ console.assert(attrs.ReadOnlyAttribute === 1); //TODO: true
try {
- attrs.setReadOnlyAttribute(false);
+ attrs.ReadOnlyAttribute = false;
console.assert(false);
} catch (e) {}
console.assert(test.checkAttributes(attrs));
}
- console.assert(test.getStringAttribute() === 'hä');
- test.setStringAttribute('foo');
- console.assert(test.getStringAttribute() === 'foo');
+ console.assert(test.StringAttribute === 'hä');
+ test.StringAttribute = 'foo';
+ console.assert(test.StringAttribute === 'foo');
const args = new Module.uno_Sequence_any(
[new Module.uno_Any(Module.uno_Type.Interface('com.sun.star.uno.XInterface'), test)]);