summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-04-18 16:05:48 +0200
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-04-19 21:20:59 +0200
commit1c81f63e91d39187748ea070d064e996481dbd3d (patch)
tree5317699bd9716e27164c80d84a59a9d63baac510 /static
parent41706fcd962a38627d20f62488c6110967396ee7 (diff)
Embind: Consistently represent empty interface references as JS null
The existing code had two issues: For one, e.g. calling a function that returned a null interface reference mapped that to JS null, while querying an object for a non-supported interface via `new css.uno.X...(y)` mapped that to an "empty" JS object instead. (So checking for a non-null reference needed to be done as either `x !=== null` or as `x.is()`, depending on context.) And for another, while calling $is() on a non-"empty" object worked fine, it failed on such an "empty" object (as the Embind internals of that object lacked the $$ property). So change the querying mechanism from the `new css.uno.X...(y)` constructor to a `css.uno.X....query(y)` function call syntax, which now returns JS null when querying for a non-supported interface. (And drop the broken $is method.) Change-Id: I8fa488ab2892423f2a461d9b72db47e1d4df3b8d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166255 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/README.wasm.md14
-rw-r--r--static/source/embindmaker/embindmaker.cxx13
2 files changed, 12 insertions, 15 deletions
diff --git a/static/README.wasm.md b/static/README.wasm.md
index 19da4518030c..5397e2124d16 100644
--- a/static/README.wasm.md
+++ b/static/README.wasm.md
@@ -228,11 +228,11 @@ Some usage examples through javascript of the current implementation:
let uno = init_unoembind_uno(Module);
let css = uno.com.sun.star;
xModel = Module.getCurrentModelFromViewSh();
-xTextDocument = new css.text.XTextDocument(xModel);
+xTextDocument = css.text.XTextDocument.query(xModel);
xText = xTextDocument.getText();
-xSimpleText = new css.text.XSimpleText(xText);
+xSimpleText = css.text.XSimpleText.query(xText);
xTextCursor = xSimpleText.createTextCursor();
-xTextRange = new css.text.XTextRange(xTextCursor);
+xTextRange = css.text.XTextRange.query(xTextCursor);
xTextRange.setString("string here!");
xModel.delete(); xTextDocument.delete(); xText.delete(); xSimpleText.delete(); xTextCursor.delete(); xTextRange.delete();
```
@@ -242,13 +242,13 @@ xModel.delete(); xTextDocument.delete(); xText.delete(); xSimpleText.delete(); x
let uno = init_unoembind_uno(Module);
let css = uno.com.sun.star;
xModel = Module.getCurrentModelFromViewSh();
-xEnumAccess = new css.container.XEnumerationAccess(xText);
+xEnumAccess = css.container.XEnumerationAccess.query(xText);
xParaEnumeration = xEnumAccess.createEnumeration();
while (xParaEnumeration.hasMoreElements()) {
- xParagraph = new css.text.XTextRange(xParaEnumeration.nextElement().get());
- if (xParagraph.$is()) {
- xParaProps = new css.beans.XPropertySet(xParagraph);
+ xParagraph = css.text.XTextRange.query(xParaEnumeration.nextElement().get());
+ if (xParagraph !== null) {
+ xParaProps = css.beans.XPropertySet.query(xParagraph);
let color = new Module.uno_Any(
Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF));
xParaProps.setPropertyValue("CharColor", color);
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index 252d7b25451c..abce7e574f67 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -1082,18 +1082,15 @@ SAL_IMPLEMENT_MAIN()
" .smart_ptr<::com::sun::star::uno::Reference<"
<< cppName(ifc) << ">>(\"uno_Reference_" << jsName(ifc)
<< "\")\n"
+ " .class_function(\"query\", "
+ "+[](::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> "
+ "const & the_object) { return ::com::sun::star::uno::Reference<"
+ << cppName(ifc)
+ << ">(the_object, ::com::sun::star::uno::UNO_QUERY); })\n"
" .class_function(\"reference\", +[]("
<< cppName(ifc)
<< " * the_interface) { return ::com::sun::star::uno::Reference(the_interface); "
"}, ::emscripten::allow_raw_pointers())\n"
- " "
- ".constructor(+[](::com::sun::star::uno::Reference<::com::sun::star::uno::"
- "XInterface> const & the_object) { return ::com::sun::star::uno::Reference<"
- << cppName(ifc)
- << ">(the_object, ::com::sun::star::uno::UNO_QUERY); })\n"
- " .function(\"$is\", +[](::com::sun::star::uno::Reference<"
- << cppName(ifc)
- << "> const & the_self) { return the_self.is(); })\n"
" .function(\"$equals\", +[](::com::sun::star::uno::Reference<"
<< cppName(ifc)
<< "> const & the_self, "