diff options
Diffstat (limited to 'src/qml/jsruntime/qv4dataview.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4dataview.cpp | 91 |
1 files changed, 27 insertions, 64 deletions
diff --git a/src/qml/jsruntime/qv4dataview.cpp b/src/qml/jsruntime/qv4dataview.cpp index 264057e162..f4ca09a127 100644 --- a/src/qml/jsruntime/qv4dataview.cpp +++ b/src/qml/jsruntime/qv4dataview.cpp @@ -1,45 +1,8 @@ -/**************************************************************************** -** -** 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 #include "qv4dataview_p.h" #include "qv4arraybuffer_p.h" -#include "qv4string_p.h" #include "qv4symbol_p.h" #include <QtCore/private/qnumeric_p.h> @@ -79,13 +42,13 @@ ReturnedValue DataViewCtor::virtualCallAsConstructor(const FunctionObject *f, co if (!newTarget || !buffer) return scope.engine->throwTypeError(); - uint offset = ::toIndex(scope.engine, argc > 1 ? argv[1]: Value::undefinedValue()); + uint offset = ::toIndex(scope.engine, argc > 1 ? argv[1] : Value::undefinedValue()); if (scope.hasException()) return Encode::undefined(); - if (buffer->isDetachedBuffer()) + if (buffer->hasDetachedArrayData()) return scope.engine->throwTypeError(); - uint bufferLength = buffer->d()->data()->size; + uint bufferLength = buffer->arrayDataLength(); if (offset > bufferLength) return scope.engine->throwRangeError(QStringLiteral("DataView: constructor arguments out of range")); @@ -163,7 +126,7 @@ ReturnedValue DataViewPrototype::method_get_byteLength(const FunctionObject *b, if (!v) return b->engine()->throwTypeError(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return b->engine()->throwTypeError(); return Encode(v->d()->byteLength); @@ -175,7 +138,7 @@ ReturnedValue DataViewPrototype::method_get_byteOffset(const FunctionObject *b, if (!v) return b->engine()->throwTypeError(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return b->engine()->throwTypeError(); return Encode(v->d()->byteOffset); @@ -191,13 +154,13 @@ ReturnedValue DataViewPrototype::method_getChar(const FunctionObject *b, const V uint idx = ::toIndex(e, argc ? argv[0] : Value::undefinedValue()); if (e->hasException) return Encode::undefined(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return e->throwTypeError(); if (idx + sizeof(T) > v->d()->byteLength) return e->throwRangeError(QStringLiteral("index out of range")); idx += v->d()->byteOffset; - T t = T(v->d()->buffer->data()->data()[idx]); + T t = T(v->d()->buffer->constArrayData()[idx]); return Encode((int)t); } @@ -212,7 +175,7 @@ ReturnedValue DataViewPrototype::method_get(const FunctionObject *b, const Value uint idx = ::toIndex(e, argc ? argv[0] : Value::undefinedValue()); if (e->hasException) return Encode::undefined(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return e->throwTypeError(); if (idx + sizeof(T) > v->d()->byteLength) return e->throwRangeError(QStringLiteral("index out of range")); @@ -221,8 +184,8 @@ ReturnedValue DataViewPrototype::method_get(const FunctionObject *b, const Value bool littleEndian = argc < 2 ? false : argv[1].toBoolean(); T t = littleEndian - ? qFromLittleEndian<T>((uchar *)v->d()->buffer->data()->data() + idx) - : qFromBigEndian<T>((uchar *)v->d()->buffer->data()->data() + idx); + ? qFromLittleEndian<T>((const uchar *)v->d()->buffer->constArrayData() + idx) + : qFromBigEndian<T>((const uchar *)v->d()->buffer->constArrayData() + idx); return Encode(t); } @@ -237,7 +200,7 @@ ReturnedValue DataViewPrototype::method_getFloat(const FunctionObject *b, const uint idx = ::toIndex(e, argc ? argv[0] : Value::undefinedValue()); if (e->hasException) return Encode::undefined(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return e->throwTypeError(); if (idx + sizeof(T) > v->d()->byteLength) return e->throwRangeError(QStringLiteral("index out of range")); @@ -252,8 +215,8 @@ ReturnedValue DataViewPrototype::method_getFloat(const FunctionObject *b, const float f; } u; u.i = littleEndian - ? qFromLittleEndian<uint>((uchar *)v->d()->buffer->data()->data() + idx) - : qFromBigEndian<uint>((uchar *)v->d()->buffer->data()->data() + idx); + ? qFromLittleEndian<uint>((const uchar *)v->d()->buffer->constArrayData() + idx) + : qFromBigEndian<uint>((const uchar *)v->d()->buffer->constArrayData() + idx); return Encode(u.f); } else { Q_ASSERT(sizeof(T) == 8); @@ -262,8 +225,8 @@ ReturnedValue DataViewPrototype::method_getFloat(const FunctionObject *b, const double d; } u; u.i = littleEndian - ? qFromLittleEndian<quint64>((uchar *)v->d()->buffer->data()->data() + idx) - : qFromBigEndian<quint64>((uchar *)v->d()->buffer->data()->data() + idx); + ? qFromLittleEndian<quint64>((const uchar *)v->d()->buffer->constArrayData() + idx) + : qFromBigEndian<quint64>((const uchar *)v->d()->buffer->constArrayData() + idx); return Encode(u.d); } } @@ -281,14 +244,14 @@ ReturnedValue DataViewPrototype::method_setChar(const FunctionObject *b, const V int val = argc >= 2 ? argv[1].toInt32() : 0; - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return e->throwTypeError(); if (idx + sizeof(T) > v->d()->byteLength) return e->throwRangeError(QStringLiteral("index out of range")); idx += v->d()->byteOffset; - v->d()->buffer->data()->data()[idx] = (char)val; + v->d()->buffer->arrayData()[idx] = (char)val; RETURN_UNDEFINED(); } @@ -307,7 +270,7 @@ ReturnedValue DataViewPrototype::method_set(const FunctionObject *b, const Value int val = argc >= 2 ? argv[1].toInt32() : 0; bool littleEndian = argc < 3 ? false : argv[2].toBoolean(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return e->throwTypeError(); if (idx + sizeof(T) > v->d()->byteLength) @@ -316,9 +279,9 @@ ReturnedValue DataViewPrototype::method_set(const FunctionObject *b, const Value if (littleEndian) - qToLittleEndian<T>(val, (uchar *)v->d()->buffer->data()->data() + idx); + qToLittleEndian<T>(val, (uchar *)v->d()->buffer->arrayData() + idx); else - qToBigEndian<T>(val, (uchar *)v->d()->buffer->data()->data() + idx); + qToBigEndian<T>(val, (uchar *)v->d()->buffer->arrayData() + idx); RETURN_UNDEFINED(); } @@ -337,7 +300,7 @@ ReturnedValue DataViewPrototype::method_setFloat(const FunctionObject *b, const double val = argc >= 2 ? argv[1].toNumber() : qt_qnan(); bool littleEndian = argc < 3 ? false : argv[2].toBoolean(); - if (v->d()->buffer->isDetachedBuffer()) + if (v->d()->buffer->hasDetachedArrayData()) return e->throwTypeError(); if (idx + sizeof(T) > v->d()->byteLength) @@ -352,9 +315,9 @@ ReturnedValue DataViewPrototype::method_setFloat(const FunctionObject *b, const } u; u.f = val; if (littleEndian) - qToLittleEndian(u.i, (uchar *)v->d()->buffer->data()->data() + idx); + qToLittleEndian(u.i, (uchar *)v->d()->buffer->arrayData() + idx); else - qToBigEndian(u.i, (uchar *)v->d()->buffer->data()->data() + idx); + qToBigEndian(u.i, (uchar *)v->d()->buffer->arrayData() + idx); } else { Q_ASSERT(sizeof(T) == 8); union { @@ -363,9 +326,9 @@ ReturnedValue DataViewPrototype::method_setFloat(const FunctionObject *b, const } u; u.d = val; if (littleEndian) - qToLittleEndian(u.i, (uchar *)v->d()->buffer->data()->data() + idx); + qToLittleEndian(u.i, (uchar *)v->d()->buffer->arrayData() + idx); else - qToBigEndian(u.i, (uchar *)v->d()->buffer->data()->data() + idx); + qToBigEndian(u.i, (uchar *)v->d()->buffer->arrayData() + idx); } RETURN_UNDEFINED(); } |