From 94e8419ed5b2f57393f1354d655a845322f7e6d2 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Fri, 14 Jun 2024 10:43:05 +0000 Subject: [PATCH] Fix WASM QtLoader environment variable warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a function throwIfEnvUsedButNotExported in qtloader.js that is intended to warn the user when they attempt to use environment variables without adding ENV to EXPORTED_RUNTIME_METHODS. (Presumably) through various changes this function no longer works. This change fixes it and adds to the warning to give Qt/CMake relevant advice. Pick-to: 6.7 Change-Id: Ia04c087d43bfe5ba988e0cf98230d796f1aaa069 Reviewed-by: Morten Johan Sørvig (cherry picked from commit 8e04cb27357ab5dffa3d1fd00a416635c7881bc6) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qtloader.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index 8d1706eaa67..dc7f4583da8 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -73,12 +73,15 @@ async function qtLoad(config) { const throwIfEnvUsedButNotExported = (instance, config) => { - const environment = config.environment; + const environment = config.qt.environment; if (!environment || Object.keys(environment).length === 0) return; - const isEnvExported = typeof instance.ENV === 'object'; - if (!isEnvExported) - throw new Error('ENV must be exported if environment variables are passed'); + const descriptor = Object.getOwnPropertyDescriptor(instance, 'ENV'); + const isEnvExported = typeof descriptor.value === 'object'; + if (!isEnvExported) { + throw new Error('ENV must be exported if environment variables are passed, ' + + 'add it to the QT_WASM_EXTRA_EXPORTED_METHODS CMake target property'); + } }; if (typeof config !== 'object')