20 Commits
Author SHA1 Message Date
Stephan Bergmann 11d6547889 Handle missing default values in JS UNO structs
Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: I63b589645a8c1efc95b6fb023931c45b1d08b65e
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/7624
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 0e55d63d948f177f3b3dabf459000b576e169815)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208737
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-07-28 23:32:25 +02:00
Julien Nabet 773867d93a Fix license
Change-Id: I0604e442066403b3aef46c68bdf4d8483732b7a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205667
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-05-25 16:27:56 +02:00
Xisco Fauli e69c03a445 fix build with --enable-quickjs and --enable-werror
/mnt/4d311c06-5193-4f61-a3f6-53ca4d9ea1e1/libreoffice/jsuno/source/jsuno.cxx: In constructor ‘{anonymous}::ModuleData::ModuleData(JSContext*, const rtl::OUString&)’:
/mnt/4d311c06-5193-4f61-a3f6-53ca4d9ea1e1/libreoffice/jsuno/source/jsuno.cxx:238:48: error: declaration of ‘name’ shadows a member of ‘{anonymous}::ModuleData’ [-Werror=shadow]
  238 |     ModuleData(JSContext* ctx, const OUString& name)
      |                                ~~~~~~~~~~~~~~~~^~~~
/mnt/4d311c06-5193-4f61-a3f6-53ca4d9ea1e1/libreoffice/jsuno/source/jsuno.cxx:247:14: note: shadowed declaration is here
  247 |     OUString name;
      |              ^~~~
cc1plus: all warnings being treated as errors

Change-Id: Id4d4a366b455c7497170d00270c5328e00f97f19
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205655
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
2026-05-25 13:52:46 +02:00
Neil Roberts 023b634d62 jsuno: Free JSValues with JS_FreeValueRT
The ValueRef helper class now keeps a pointer to the JS_Runtime instead
of the JS_Context and uses that to free the JSValue instead. This is
needed if the ValueRef is kept alive until the end of the execution of
the script because in that case the JS_Context will be destroyed before
the final garbage collection is run. This can happen if the ValueRef is
being stored in the opaque data for an object such as is the case for
the WrapperData struct.

This was picked up in the following ubsan build:

https://ci.libreoffice.org/job/lo_ubsan/3913/consoleFull#-1184025599d893063f-7f3d-4b7e-b56f-4e0f225817cd

It is also picked up by running CppunitTest_jsuno_testuno under
valgrind.

Change-Id: Ic929fb8ab9015ddcbb9fd69a4a7985e9d2b18b0a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205353
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-05-19 14:02:13 +02:00
Neil Roberts 0016a7ccc4 jsuno: Implement a basic Rhino compatibility layer
Adds the following features in order to make the QuickJS engine slightly
more compatible with the Rhino engine:

Makes “Packages” be an alias for “uno.idl”

Adds an implementation of importClass. This tries to get the name of the
thing that is being imported and then sets a global variable with that
name to point to that thing. The name is retrieved by adding a
getImportClassName method to most of the objects returned by
moduleGetOwnProperty.

Inserts a com.sun.star.uno.UnoRuntime object with a hack on
moduleGetOwnProperty. This object has a method called “queryInterface”
to allow doing UnoRuntime.queryInterface(interface,obj). The
implementation just calls
obj.queryInterface(uno.type.interface(interface))

This is enough to run the HelloWorld example from the Rhino JavaScript
provider.

Change-Id: I569fe4dad4cd8cdc6029a60f8e5421a5de1588c2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204912
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-14 11:03:03 +02:00
Neil Roberts 6953efb07e jsuno: Split moduleGetOwnProperty out into uncached version
The main bulk of moduleGetOwnProperty is now split out into a helper
function that just directly returns the property value. The caller then
handles the caching. This makes it easier to add an early return with
different values in a later patch.

Change-Id: Ifaf346df7d1d576cc0a466eb3bd4a3dc2cfab732
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204911
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-14 11:02:54 +02:00
Neil Roberts 9069f5c462 jsuno: Use prototypes to implement toString methods
Instead of directly adding the toString method to an object every time
an instance of the appropriate class is created, the method is now added
to a prototype object and this is set on the class.

Change-Id: I7c69cb5294ba52a84a88aba354684263d4b3736c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204910
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-14 11:02:44 +02:00
Neil Roberts d08ca1f347 jsuno: Use get_own_property instead of get_property
get_property completely overrides the property resolution mechanism and
stops QuickJS from looking at the prototypes. If we replace it with
get_own_property, as well as fixing that it will make has_property work
correctly too. Sadly this also means we have to override the property
setter, which means we can’t just call JS_SetProperty on the object when
we want to cache the value. Instead, the wrapper and module classes now
have a struct as their opaque data and this contains an additional JS
Object to use as a hash table for the cache.

Change-Id: Ia1580ba2017d6376c6f8565ceff6bd46afa7ffc4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204909
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-14 11:02:35 +02:00
Neil Roberts ddd0b88a8f jsuno/testuno: Use the character version of endsWith
Now that endsWith has an overload that takes a single character, we
might as well use it here. This also uses the “rest” parameter to avoid
the if-statement.

Change-Id: I7b82e65a943715bb4a65574482944c846a696396
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204908
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-14 11:02:25 +02:00
Neil Roberts 0425d0c795 jsuno/testuno: Move the assertError function to a common utility file
More of the tests will later want to use the assertError function so
let’s move it to a shared helper file.

Change-Id: Ib19e51e659214f8d7f08cedd98bf54f4cf06d4ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204907
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-14 11:02:14 +02:00
Neil Roberts 443fe7e736 jsuno: Move JSValue out into a separate header file
This makes it easier to split the code into multiple files and share the
JSValue class.

Change-Id: I10149088a970392c0face4b8533aed9096f2e0b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204906
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-05-14 11:01:48 +02:00
Neil Roberts 0c207d3479 jsuno: Add a parameter to execute() to specify a list of global variables
Adds an optional parameter to jsuno::execute to specify a list of global
variables to define in the global scope of the running script. The
values are references to XInterfaces.

Change-Id: I03b7de9fb904f4a172324f0e54c11ff9b0d76134
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205120
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-13 09:06:12 +02:00
Stephan Bergmann f403d56b9a jsuno: Return script's last expression value (as JSON)
Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: I009d60d36a1279b42d12fa4e3b0369aeab4af51e
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2078
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
(cherry picked from commit daf47e0b734a0985fe5051ac1ce62c5fbed82802)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205119
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-13 09:05:59 +02:00
Stephan Bergmann 368792e83c jsuno: Throw css.script.provider.ScriptExceptionRaisedException on JS errors
Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: Ia5df077d78b1650e28bf73716a10fdbd024f6e8a
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/2077
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
(cherry picked from commit a4feac2f06bf3d1a6ed55a94dd5e05d01fc0f7c4)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205118
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-05-13 09:05:48 +02:00
Stephan Bergmann bedeae9485 jsuno: flush std::cout after each console.log line
...to better accommodate to scenarios where the engine's stdout is piped (e.g.,
under online's `make run | tee`)

Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: I991b206746723f206c84052c3440cd95b42fb9de
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/1832
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
(cherry picked from commit 695993c5dfb3f8126d9cc2cd89daa9e921f160a1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205117
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-05-13 09:05:38 +02:00
Stephan Bergmann faeda637f6 Add JS generator support for css.container.XEnumerationAccess
...similar to
<https://github.com/allotropia/zetajs/commit/ea7bfb5ac1ede0aa3ed92bb14e55ddaadcd23d22>
"Add JS generator support for css.container.XEnumerationAccess"

Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: I793045d534e3b2a62de24c44689797ec24d3d555
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/1612
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit ef35e615ea97b0cd6526b0935a7da5d57cd3a535)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205116
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-05-13 09:05:30 +02:00
Neil Roberts 67326438c6 jsuno: Fix the source header comments
I forgot to update the project name when cherry picking the jsuno code.

Change-Id: I2e2a58e514f605da00e12e598790bc45c9814e0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204612
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-04-30 18:45:27 +02:00
Neil Roberts b93ce63504 jsuno: Throw an exception instead of asserting when missing arguments
Previously the functions that have required arguments were checking that
the right number of arguments were passed with an assert. On debug
builds this would cause LibreOffice to just crash when an argument was
missing. You might think that the length parameter to JS_NewCFunction
would make QuickJS itself check that enough arguments were passed, but
instead that just makes sure that the array passed to the C function has
enough space for that many arguments.

This patch replaces those checks with an exception on failure.

Change-Id: Ief0f48bca684dd2b4379711ab7650edd548ceef4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204302
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-04-30 10:40:06 +02:00
Neil Roberts d1936ddbc5 testuno: Move the JavaScript source to an external file
This makes it a bit easier to edit.

Change-Id: I56b715bf1beeb31f0a8d133a44447c8f8ce4ee0c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204301
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
Tested-by: Jenkins
2026-04-30 10:39:53 +02:00
Stephan Bergmann 6b31c63ec7 QuickJS-based JS UNO support
Somewhat loosely based on <https://github.com/allotropia/zetajs>.

Main part that is still missing from this WIP commit is implementing UNO objects
in JS.  (And there are a number of TODOs throughout, mostly regarding error
handling.)

===
Comments from Neil Roberts:

This patch was cherry-picked from
1cd8ad398b38763cb3578f1305a28e7774163714 in Collabora’s repo. The
following changes were made in order to get it to pass the CI:

* The unit test has been modified to continue using embindtest instead
  of testuno.
* The name of the external library is quickjs instead of qjs because a
  different patch is used to add the external QuickJS package.
* The asserts on argc that were captured in the lambda function have been
  moved outside of the lambda function in order to avoid having an unused
  capture on release builds. The argc parameter has then been marked as
  [[maybe_unused]].
* The constructors for JSClassDef have been changed to consistently use
  { } brace initialisers because otherwise it fails to build on macOS.
===

Change-Id: I8810e43fe5f3e4b1a53a654070fe87e95f51231a
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/190
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203963
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-04-30 10:38:54 +02:00