aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4arraybuffer.cpp
diff options
context:
space:
mode:
authorBenjamin Terrier <b.terrier@gmail.com>2022-06-01 02:26:23 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-08-25 23:57:11 +0000
commitb201b1d0b3d81eefd8f1e3b6e78f751ec84a61f3 (patch)
tree555b994e050c80e3dc4f29c7ee491f6cf3a2be19 /src/qml/jsruntime/qv4arraybuffer.cpp
parent79893e1773be9d04208243cb88c1daf793d830a4 (diff)
Fix error when calling byteLength on detached ArrayBuffer
ArrayBuffer constructed from en empty QByteArray are detached, calling byteLength should not throw an error. According to ECMA specifications the `byteLength` property of a detached ArrayBuffer should retrurn 0. See https://tc39.es/ecma262/multipage/structured-data.html#sec-get-arraybuffer.prototype.bytelength [ChangeLog][QtQml][Important Behavior Changes] ArrayBuffer.byteLength() now returns 0 on detached ArrayBuffers, conforming to ECMAScript 2021. Fixes: QTBUG-103925 Change-Id: Ib1c325eff25459980e10a1f3cd9fb7cb3b8eb5e5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4arraybuffer.cpp')
-rw-r--r--src/qml/jsruntime/qv4arraybuffer.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp
index 28e95a03d5..b8f6f61820 100644
--- a/src/qml/jsruntime/qv4arraybuffer.cpp
+++ b/src/qml/jsruntime/qv4arraybuffer.cpp
@@ -215,9 +215,12 @@ void ArrayBufferPrototype::init(ExecutionEngine *engine, Object *ctor)
ReturnedValue ArrayBufferPrototype::method_get_byteLength(const FunctionObject *f, const Value *thisObject, const Value *, int)
{
const ArrayBuffer *a = thisObject->as<ArrayBuffer>();
- if (!a || a->hasDetachedArrayData() || a->isSharedArrayBuffer())
+ if (!a || a->isSharedArrayBuffer())
return f->engine()->throwTypeError();
+ if (a->hasDetachedArrayData())
+ return Encode(0);
+
return Encode(a->arrayDataLength());
}