See https://github.com/qmlweb/qmlweb/pull/166, we could implement something similar in a cleaner way.