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>
This commit is contained in:
parent
e8e6a5f795
commit
f10d51709d
@ -481,57 +481,44 @@ void dumpAttributes(std::ostream& out, rtl::Reference<TypeManager> const& manage
|
|||||||
{
|
{
|
||||||
for (auto const& attr : entity->getDirectAttributes())
|
for (auto const& attr : entity->getDirectAttributes())
|
||||||
{
|
{
|
||||||
out << " .function(\"get" << attr.name << "\", ";
|
out << " .property<";
|
||||||
if (baseTrail.empty())
|
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)
|
out << ")";
|
||||||
<< "> const & the_self) { return ";
|
}
|
||||||
|
out << ".get" << attr.name << "(); }";
|
||||||
|
if (!attr.readOnly)
|
||||||
|
{
|
||||||
|
out << ", +[](" << cppName(name) << " & the_self, ";
|
||||||
|
dumpType(out, manager, attr.type);
|
||||||
|
if (passByReference(manager, attr.type))
|
||||||
|
{
|
||||||
|
out << " const &";
|
||||||
|
}
|
||||||
|
out << " the_value) { ";
|
||||||
for (auto const& base : baseTrail)
|
for (auto const& base : baseTrail)
|
||||||
{
|
{
|
||||||
out << "static_cast<" << cppName(base) << " *>(";
|
out << "static_cast<" << cppName(base) << " &>(";
|
||||||
}
|
}
|
||||||
out << "the_self.get()";
|
out << "the_self";
|
||||||
for (std::size_t i = 0; i != baseTrail.size(); ++i)
|
for (std::size_t i = 0; i != baseTrail.size(); ++i)
|
||||||
{
|
{
|
||||||
out << ")";
|
out << ")";
|
||||||
}
|
}
|
||||||
out << "->get" << attr.name << "(); }";
|
out << ".set" << attr.name << "(the_value); }";
|
||||||
}
|
|
||||||
out << ", ::emscripten::pure_virtual())\n";
|
|
||||||
if (!attr.readOnly)
|
|
||||||
{
|
|
||||||
out << " .function(\"set" << attr.name << "\", ";
|
|
||||||
if (baseTrail.empty())
|
|
||||||
{
|
|
||||||
out << "&" << cppName(name) << "::set" << attr.name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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 << ", ::emscripten::pure_virtual())\n";
|
|
||||||
}
|
}
|
||||||
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,22 +688,22 @@ Module.addOnPostRun(function() {
|
|||||||
css.task.XJobExecutor.query(obj).trigger('from JS');
|
css.task.XJobExecutor.query(obj).trigger('from JS');
|
||||||
{
|
{
|
||||||
const attrs = Module.uno.org.libreoffice.embindtest.XAttributes.query(obj);
|
const attrs = Module.uno.org.libreoffice.embindtest.XAttributes.query(obj);
|
||||||
console.assert(attrs.getLongAttribute() === -123456);
|
console.assert(attrs.LongAttribute === -123456);
|
||||||
attrs.setLongAttribute(789);
|
attrs.LongAttribute = 789;
|
||||||
console.assert(attrs.getLongAttribute() === 789);
|
console.assert(attrs.LongAttribute === 789);
|
||||||
console.assert(attrs.getStringAttribute() === 'hä');
|
console.assert(attrs.StringAttribute === 'hä');
|
||||||
attrs.setStringAttribute('foo');
|
attrs.StringAttribute = 'foo';
|
||||||
console.assert(attrs.getStringAttribute() === 'foo');
|
console.assert(attrs.StringAttribute === 'foo');
|
||||||
console.assert(attrs.getReadOnlyAttribute() === 1); //TODO: true
|
console.assert(attrs.ReadOnlyAttribute === 1); //TODO: true
|
||||||
try {
|
try {
|
||||||
attrs.setReadOnlyAttribute(false);
|
attrs.ReadOnlyAttribute = false;
|
||||||
console.assert(false);
|
console.assert(false);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
console.assert(test.checkAttributes(attrs));
|
console.assert(test.checkAttributes(attrs));
|
||||||
}
|
}
|
||||||
console.assert(test.getStringAttribute() === 'hä');
|
console.assert(test.StringAttribute === 'hä');
|
||||||
test.setStringAttribute('foo');
|
test.StringAttribute = 'foo';
|
||||||
console.assert(test.getStringAttribute() === 'foo');
|
console.assert(test.StringAttribute === 'foo');
|
||||||
|
|
||||||
const args = new Module.uno_Sequence_any(
|
const args = new Module.uno_Sequence_any(
|
||||||
[new Module.uno_Any(Module.uno_Type.Interface('com.sun.star.uno.XInterface'), test)]);
|
[new Module.uno_Any(Module.uno_Type.Interface('com.sun.star.uno.XInterface'), test)]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user