5#include <QtCore/qrect.h>
7#include <emscripten/val.h>
10#error This is a wasm-only file.
16
17
18
19
20
21
22
23
24QRectF QRectF::fromDOMRect(emscripten::val domRect)
26 Q_ASSERT_X(domRect[
"constructor"][
"name"].as<std::string>() ==
"DOMRect", Q_FUNC_INFO,
27 "Passed object is not a DOMRect");
29 return QRectF(domRect[
"left"].as<qreal>(), domRect[
"top"].as<qreal>(),
30 domRect[
"width"].as<qreal>(), domRect[
"height"].as<qreal>());
34
35
36
37
38
39
40
41emscripten::val QRectF::toDOMRect()
const
43 return emscripten::val::global(
"DOMRect").new_(left(), top(), width(), height());
47
48
49
50
51
52
53
54
55QString QString::fromEcmaString(emscripten::val jsString)
57 Q_ASSERT_X(jsString.isString(), Q_FUNC_INFO,
"Passed object is not a string");
60 return QString::fromStdU16String(jsString.as<std::u16string>());
63 const double length = jsString[
"length"].as<
double>();
65 Q_ASSERT_X((
double(uint64_t(length)) !=
double(uint64_t(length) - 1)
66 &&
double(uint64_t(length)) !=
double(uint64_t(length) + 1))
67 || !std::numeric_limits<
double>::is_iec559,
68 Q_FUNC_INFO,
"The floating-point length cannot precisely represent an integer");
70 constexpr int zeroTerminatorLength = 1;
71 const auto lengthOfUtf16 = (length + zeroTerminatorLength) * 2;
73 Q_ASSERT_X((
double(uint64_t(lengthOfUtf16)) !=
double(uint64_t(lengthOfUtf16) - 1)
74 &&
double(uint64_t(lengthOfUtf16)) !=
double(uint64_t(lengthOfUtf16) + 1))
75 || !std::numeric_limits<
double>::is_iec559,
77 "The floating-point lengthOfUtf16 cannot precisely represent an integer");
79 const QString result(uint64_t(length), Qt::Uninitialized);
81 static const emscripten::val stringToUTF16(emscripten::val::module_property(
"stringToUTF16"));
82 stringToUTF16(jsString, emscripten::val(quintptr(result.data())),
83 emscripten::val(lengthOfUtf16));
88
89
90
91
92
93
94
95
96emscripten::val QString::toEcmaString()
const
99 return emscripten::val::u16string(toStdU16String().c_str());
101 static const emscripten::val UTF16ToString(emscripten::val::module_property(
"UTF16ToString"));
102 return UTF16ToString(emscripten::val(quintptr(utf16())));
\inmodule QtCore\reentrant