Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcore_wasm.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/qrect.h>
5
6#include <emscripten/val.h>
7
8#if !defined(Q_OS_WASM)
9#error This is a wasm-only file.
10#endif // !defined(Q_OS_WASM)
11
13
23QRectF QRectF::fromDOMRect(emscripten::val domRect)
24{
25 Q_ASSERT_X(domRect["constructor"]["name"].as<std::string>() == "DOMRect", Q_FUNC_INFO,
26 "Passed object is not a DOMRect");
27
28 return QRectF(domRect["left"].as<qreal>(), domRect["top"].as<qreal>(),
29 domRect["width"].as<qreal>(), domRect["height"].as<qreal>());
30}
31
40emscripten::val QRectF::toDOMRect() const
41{
42 return emscripten::val::global("DOMRect").new_(left(), top(), width(), height());
43}
44
54QString QString::fromEcmaString(emscripten::val jsString)
55{
56 Q_ASSERT_X(jsString.isString(), Q_FUNC_INFO, "Passed object is not a string");
57
58 const double length = jsString["length"].as<double>();
59
60 Q_ASSERT_X((double(uint64_t(length)) != double(uint64_t(length) - 1)
61 && double(uint64_t(length)) != double(uint64_t(length) + 1))
62 || !std::numeric_limits<double>::is_iec559,
63 Q_FUNC_INFO, "The floating-point length cannot precisely represent an integer");
64
65 constexpr int zeroTerminatorLength = 1;
66 const auto lengthOfUtf16 = (length + zeroTerminatorLength) * 2;
67
68 Q_ASSERT_X((double(uint64_t(lengthOfUtf16)) != double(uint64_t(lengthOfUtf16) - 1)
69 && double(uint64_t(lengthOfUtf16)) != double(uint64_t(lengthOfUtf16) + 1))
70 || !std::numeric_limits<double>::is_iec559,
72 "The floating-point lengthOfUtf16 cannot precisely represent an integer");
73
74 const QString result(uint64_t(length), Qt::Uninitialized);
75
76 static const emscripten::val stringToUTF16(emscripten::val::module_property("stringToUTF16"));
77 stringToUTF16(jsString, emscripten::val(quintptr(result.data())),
78 emscripten::val(lengthOfUtf16));
79 return result;
80}
81
91emscripten::val QString::toEcmaString() const
92{
93 static const emscripten::val UTF16ToString(emscripten::val::module_property("UTF16ToString"));
94 return UTF16ToString(emscripten::val(quintptr(utf16())));
95}
96
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr QRectF() noexcept
Constructs a null rectangle.
Definition qrect.h:486
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:497
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:498
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
Definition qstring.cpp:6995
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
#define Q_FUNC_INFO
GLenum GLuint GLenum GLsizei length
GLuint64EXT * result
[6]
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
size_t quintptr
Definition qtypes.h:167