desktop/source/app/appinit.cxx | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-)
New commits: commit 2933da20065af063bb06ef3d022dfe4a56f6d93a Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Wed Feb 19 15:14:40 2025 +0100 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Thu Feb 20 08:09:33 2025 +0100 Emscripten: Let runUnoScriptUrls handle all scripts in one go ...so that the !HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD case (introduced in bc60c54878185bcd7d95cc87e9b94a785a086915 "If necessary, fall back to an approximation of WorkerGlobalScope.importScripts") can make sure that one script is fully evaluated before the next is loaded, to avoid a race when some script depends on an earlier script Change-Id: I5fca4d7aa5d7e9b8d86b59667c599f62f1f3064c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181905 Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> Tested-by: Jenkins diff --git a/desktop/source/app/appinit.cxx b/desktop/source/app/appinit.cxx index 10867b75a5c0..5d575934063c 100644 --- a/desktop/source/app/appinit.cxx +++ b/desktop/source/app/appinit.cxx @@ -65,31 +65,41 @@ using namespace ::com::sun::star::ucb; namespace { -extern "C" void getUnoScriptUrls(std::vector<OUString> * urls) { +extern "C" void getUnoScriptUrls(std::vector<std::u16string> * urls) { assert(urls != nullptr); OUString const base(emscripten::val::global("document")["baseURI"].as<std::u16string>()); auto const val = emscripten::val::module_property("uno_scripts"); if (!val.isUndefined()) { auto const len = val["length"].as<std::uint32_t>(); for (std::uint32_t i = 0; i != len; ++i) { - urls->push_back(rtl::Uri::convertRelToAbs(base, OUString(val[i].as<std::u16string>()))); + urls->push_back( + std::u16string( + rtl::Uri::convertRelToAbs(base, OUString(val[i].as<std::u16string>())))); } } } #if HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD -EM_JS(void, runUnoScriptUrl, (char16_t const * url), { - importScripts(UTF16ToString(url)); +EM_JS(void, runUnoScriptUrls, (emscripten::EM_VAL handle), { + importScripts.apply(self, Emval.toValue(handle)); }); #else -EM_JS(void, runUnoScriptUrl, (char16_t const * url), { - fetch(UTF16ToString(url)).then(res => { - if (!res.ok) { - throw Error( - "Loading <" + res.url + "> failed with " + res.status + " " + res.statusText); +EM_JS(void, runUnoScriptUrls, (emscripten::EM_VAL handle), { + const urls = Emval.toValue(handle); + function step() { + if (urls.length !== 0) { + const url = urls.shift(); + fetch(url).then(res => { + if (!res.ok) { + throw Error( + "Loading <" + res.url + "> failed with " + res.status + " " + + res.statusText); + } + return res.blob(); + }).then(blob => blob.text()).then(text => { eval(text); step(); }); } - return res.blob(); - }).then(blob => blob.text()).then(text => eval(text)); + }; + step(); }); #endif @@ -125,14 +135,9 @@ extern "C" void resolveUnoMain(pthread_t id) { void initUno() { init_unoembind_uno(); - std::vector<OUString> urls; + std::vector<std::u16string> urls; emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_VI, getUnoScriptUrls, &urls); - for (auto const & url: urls) { - if (url.indexOf(' - throw std::invalid_argument("Module.uno_scripts element contains embedded NUL"); - } - runUnoScriptUrl(url.getStr()); - } + runUnoScriptUrls(emscripten::val::array(urls).as_handle()); setupMainChannel(); emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VI, resolveUnoMain, pthread_self()); }