diff options
author | Ulf Hermann <[email protected]> | 2022-07-12 16:08:17 +0200 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2022-07-19 10:52:31 +0200 |
commit | ef057772c41e84e9813f0ed113fc55224013404c (patch) | |
tree | 80d1a7247825bcfccb577ce2ab6c0f248d435439 /src/qml/jsruntime/qv4arrayobject_p.h | |
parent | b335d8311f7c0be9261305d5b41bbcbf94cd3d27 (diff) |
Fix array-like methods on V4 sequences
We need to properly convert value type lists on assignment and we need
to add the "length" property to the own properties. Furthermore, the V4
sequence methods were confused about integer type ranges. We teach
them about qsizetype, properly range check everything, and drop the
artificial limitation to INT_MAX.
Pick-to: 6.4
Task-number: QTBUG-82443
Change-Id: Ie5af1130c9e78e412c171e6fa26a28a6a7a5d498
Reviewed-by: Fabian Kosmale <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4arrayobject_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4arrayobject_p.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject_p.h b/src/qml/jsruntime/qv4arrayobject_p.h index f6b95e2413..b07e27b24f 100644 --- a/src/qml/jsruntime/qv4arrayobject_p.h +++ b/src/qml/jsruntime/qv4arrayobject_p.h @@ -20,6 +20,31 @@ QT_BEGIN_NAMESPACE +inline bool qIsAtMostUintLimit(qsizetype length, uint limit = std::numeric_limits<uint>::max()) +{ + // Use the type with the larger positive range to do the comparison. + + Q_ASSERT(length >= 0); + if constexpr (sizeof(qsizetype) > sizeof(uint)) { + return length <= qsizetype(limit); + } else { + return uint(length) <= limit; + } +} + +inline bool qIsAtMostSizetypeLimit(uint length, qsizetype limit = std::numeric_limits<qsizetype>::max()) +{ + // Use the type with the larger positive range to do the comparison. + + Q_ASSERT(limit >= 0); + if constexpr (sizeof(qsizetype) > sizeof(uint)) { + return qsizetype(length) <= limit; + } else { + return length <= uint(limit); + } +} + + namespace QV4 { namespace Heap { |