wasm: use emscripten::val for specialHTMLTargets

We need to add specialHTMLTargets to EXPORTED_RUNTIME_METHODS in order
to use it, as Emscripten does not export it.

Also, EM_ASM is not allowed for SIDE_MODULES, so it's better to use
emscripten::val methods.

Change-Id: I9b352ac98e2a961157f5bb36456bec3e35891270
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Lorn Potter 2022-04-13 13:58:44 +10:00
parent 830b1550de
commit 0ec75f4b99
2 changed files with 9 additions and 7 deletions

View File

@ -3,7 +3,7 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
target_link_options("${wasmTarget}" INTERFACE target_link_options("${wasmTarget}" INTERFACE
"SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1" "SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1"
"SHELL:-s EXPORTED_RUNTIME_METHODS=[UTF16ToString,stringToUTF16]" "SHELL:-s EXPORTED_RUNTIME_METHODS=[UTF16ToString,stringToUTF16,specialHTMLTargets]"
"SHELL:-s USE_WEBGL2=1" "SHELL:-s USE_WEBGL2=1"
"--bind" "--bind"
"SHELL:-s FETCH=1") "SHELL:-s FETCH=1")

View File

@ -104,9 +104,10 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas)
// apps/ages only, since Emscripten uses the main document to look up the element. // apps/ages only, since Emscripten uses the main document to look up the element.
// As a workaround for this, Emscripten supports registering custom mappings in the // As a workaround for this, Emscripten supports registering custom mappings in the
// "specialHTMLTargets" object. Add a mapping for the canvas for this screen. // "specialHTMLTargets" object. Add a mapping for the canvas for this screen.
EM_ASM({ emscripten::val specialHtmlTargets = emscripten::val::module_property("specialHTMLTargets");
specialHTMLTargets["!qtcanvas_" + $0] = Emval.toValue($1);
}, uint32_t(this), m_canvas.as_handle()); std::string id = std::string("!qtcanvas_") + std::to_string(uint32_t(this));
specialHtmlTargets.set(id, m_canvas.as_handle());
// Install event handlers on the container/canvas. This must be // Install event handlers on the container/canvas. This must be
// done after the canvas has been created above. // done after the canvas has been created above.
@ -118,9 +119,10 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas)
QWasmScreen::~QWasmScreen() QWasmScreen::~QWasmScreen()
{ {
EM_ASM({ emscripten::val specialHtmlTargets = emscripten::val::module_property("specialHTMLTargets");
specialHTMLTargets["!qtcanvas_" + $0] = undefined;
}, uint32_t(this)); std::string id = std::string("!qtcanvas_") + std::to_string(uint32_t(this));
specialHtmlTargets.set(id, emscripten::val::undefined());
m_canvas.set(m_canvasResizeObserverCallbackContextPropertyName, emscripten::val(intptr_t(0))); m_canvas.set(m_canvasResizeObserverCallbackContextPropertyName, emscripten::val(intptr_t(0)));
destroy(); destroy();