aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4typedarray.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-01 22:27:39 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-04 18:25:33 +0000
commita6ba4f044e3611fb66a6cce87bc06933c3e27070 (patch)
tree9fd8ff9f03dde62023e0b482935884d07be10c3f /src/qml/jsruntime/qv4typedarray.cpp
parentc71448dc97778b48824f081749fe4c270a34446f (diff)
Implement defineOwnProperty for TypedArrays
Change-Id: I2e7aa05a340d54e2f34ec4e59a69f3ce66be75d9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4typedarray.cpp')
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp
index d0125a3cfe..1d5ab5564e 100644
--- a/src/qml/jsruntime/qv4typedarray.cpp
+++ b/src/qml/jsruntime/qv4typedarray.cpp
@@ -514,6 +514,35 @@ bool TypedArray::virtualPut(Managed *m, PropertyKey id, const Value &value, Valu
return true;
}
+bool TypedArray::virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs)
+{
+ TypedArray *a = static_cast<TypedArray *>(m);
+ if (!id.isArrayIndex())
+ return Object::virtualDefineOwnProperty(m, id, p, attrs);
+ uint index = id.asArrayIndex();
+ if (index >= a->length() || attrs.isAccessor())
+ return false;
+
+ if (attrs.hasConfigurable() && attrs.isConfigurable())
+ return false;
+ if (attrs.hasEnumerable() && !attrs.isEnumerable())
+ return false;
+ if (attrs.hasWritable() && !attrs.isWritable())
+ return false;
+ if (!p->value.isEmpty()) {
+ ExecutionEngine *engine = a->engine();
+
+ Value v = Primitive::fromReturnedValue(p->value.convertedToNumber());
+ if (engine->hasException || a->d()->buffer->isDetachedBuffer())
+ return engine->throwTypeError();
+ uint bytesPerElement = a->d()->type->bytesPerElement;
+ uint byteOffset = a->d()->byteOffset + index * bytesPerElement;
+ Q_ASSERT(byteOffset + bytesPerElement <= (uint)a->d()->buffer->byteLength());
+ a->d()->type->write(a->d()->buffer->data->data() + byteOffset, v);
+ }
+ return true;
+}
+
void TypedArrayPrototype::init(ExecutionEngine *engine, TypedArrayCtor *ctor)
{
Scope scope(engine);