aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parentc71448dc97778b48824f081749fe4c270a34446f (diff)
Implement defineOwnProperty for TypedArrays
Change-Id: I2e7aa05a340d54e2f34ec4e59a69f3ce66be75d9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp29
-rw-r--r--src/qml/jsruntime/qv4typedarray_p.h2
2 files changed, 31 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);
diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h
index 909334adb0..f89d966974 100644
--- a/src/qml/jsruntime/qv4typedarray_p.h
+++ b/src/qml/jsruntime/qv4typedarray_p.h
@@ -168,6 +168,8 @@ struct Q_QML_PRIVATE_EXPORT TypedArray : Object
static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty);
static bool virtualHasProperty(const Managed *m, PropertyKey id);
static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver);
+ static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs);
+
};
struct IntrinsicTypedArrayCtor: FunctionObject