diff options
Diffstat (limited to 'src/qml/jsruntime/qv4value_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 144 |
1 files changed, 17 insertions, 127 deletions
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 4e901721cb..eaa57a36aa 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QV4VALUE_P_H #define QV4VALUE_P_H @@ -70,9 +34,8 @@ namespace Heap { struct Base; } -struct Q_QML_PRIVATE_EXPORT Value : public StaticValue +struct Q_QML_EXPORT Value : public StaticValue { - using HeapBasePtr = Heap::Base *; using ManagedPtr = Managed *; Value() = default; @@ -83,53 +46,6 @@ struct Q_QML_PRIVATE_EXPORT Value : public StaticValue return {staticValue._val}; } -#if QT_POINTER_SIZE == 8 - QML_NEARLY_ALWAYS_INLINE HeapBasePtr m() const - { - HeapBasePtr b; -#ifdef __ia64 -// Restore bits 49-47 to bits 63-61, undoing the workaround explained in -// setM below. - quint64 _tmp; - - _tmp = _val & (7L << 47); // 0x3800000000000 - _tmp = (_tmp << 14) | (_val ^ _tmp); - memcpy(&b, &_tmp, 8); -#else - memcpy(&b, &_val, 8); -#endif - return b; - } - QML_NEARLY_ALWAYS_INLINE void setM(HeapBasePtr b) - { - memcpy(&_val, &b, 8); -#ifdef __ia64 -// On ia64, bits 63-61 in a 64-bit pointer are used to store the virtual region -// number. Since this implementation is not 64-bit clean, we move bits 63-61 -// to bits 49-47 and hope for the best. This is undone in *m(), above. - _val |= ((_val & (7L << 61)) >> 14); - _val &= ((1L << 50)-1); -#endif - } -#elif QT_POINTER_SIZE == 4 - QML_NEARLY_ALWAYS_INLINE HeapBasePtr m() const - { - Q_STATIC_ASSERT(sizeof(HeapBasePtr) == sizeof(quint32)); - HeapBasePtr b; - quint32 v = value(); - memcpy(&b, &v, 4); - return b; - } - QML_NEARLY_ALWAYS_INLINE void setM(HeapBasePtr b) - { - quint32 v; - memcpy(&v, &b, 4); - setTagValue(Managed_Type_Internal, v); - } -#else -# error "unsupported pointer size" -#endif - inline bool isString() const; inline bool isStringOrSymbol() const; inline bool isSymbol() const; @@ -190,8 +106,11 @@ struct Q_QML_PRIVATE_EXPORT Value : public StaticValue inline double toNumber() const; static double toNumberImpl(Value v); double toNumberImpl() const { return toNumberImpl(*this); } + QString toQStringNoThrow() const; QString toQString() const; + QString toQString(bool *ok) const; + Heap::String *toString(ExecutionEngine *e) const { if (isString()) return reinterpret_cast<Heap::String *>(m()); @@ -308,7 +227,7 @@ struct Q_QML_PRIVATE_EXPORT Value : public StaticValue template<typename T> Value &operator=(const Scoped<T> &t); }; -Q_STATIC_ASSERT(std::is_trivial<Value>::value); +Q_STATIC_ASSERT(std::is_trivial_v<Value>); Q_STATIC_ASSERT(sizeof(Value) == sizeof(StaticValue)); template<> @@ -390,7 +309,10 @@ inline bool Value::isObject() const inline bool Value::isFunctionObject() const { HeapBasePtr b = heapObject(); - return b && b->internalClass->vtable->isFunctionObject; + if (!b) + return false; + const VTable *vtable = b->internalClass->vtable; + return vtable->call || vtable->callAsConstructor; } inline bool Value::isPrimitive() const @@ -434,9 +356,9 @@ inline int Value::toInt32() const return int_32(); if (Q_LIKELY(isDouble())) - return Double::toInt32(doubleValue()); + return QJSNumberCoercion::toInteger(doubleValue()); - return Double::toInt32(toNumberImpl()); + return QJSNumberCoercion::toInteger(toNumberImpl()); } inline unsigned int Value::toUInt32() const @@ -480,7 +402,7 @@ inline double Value::toInteger() const template <size_t o> struct HeapValue : Value { - static Q_CONSTEXPR size_t offset = o; + static constexpr size_t offset = o; HeapBasePtr base() { HeapBasePtr base = reinterpret_cast<HeapBasePtr>(this) - (offset/sizeof(Heap::Base)); Q_ASSERT(base->inUse()); @@ -497,7 +419,7 @@ struct HeapValue : Value { template <size_t o> struct ValueArray { - static Q_CONSTEXPR size_t offset = o; + static constexpr size_t offset = o; uint size; uint alloc; Value values[1]; @@ -523,41 +445,9 @@ struct ValueArray { return values; } - void insertData(EngineBase *e, uint index, Value v) { - for (uint i = size - 1; i > index; --i) { - values[i] = values[i - 1]; - } - set(e, index, v); - } - void removeData(EngineBase *e, uint index, int n = 1) { - Q_UNUSED(e); - for (uint i = index; i < size - n; ++i) { - values[i] = values[i + n]; - } - } - void mark(MarkStack *markStack) { - Value *v = values; - const Value *end = v + alloc; - if (alloc > 32*1024) { - // drain from time to time to avoid overflows in the js stack - Value::HeapBasePtr *currentBase = markStack->top; - while (v < end) { - v->mark(markStack); - ++v; - if (markStack->top >= currentBase + 32*1024) { - Value::HeapBasePtr *oldBase = markStack->base; - markStack->base = currentBase; - markStack->drain(); - markStack->base = oldBase; - } - } - } else { - while (v < end) { - v->mark(markStack); - ++v; - } - } + for (Value *v = values, *end = values + alloc; v < end; ++v) + v->mark(markStack); } }; |