From 89f585157af905d45012dbd9c079c48491e5211d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 19 Jun 2018 14:15:12 +0200 Subject: Move special handling of getOwnProperty for StringObject where it belongs Move the code into a virtual method of StringObject, bringing us closer in line with the ES7 spec. Change-Id: Iaf460f5a5517fe059a30be8c403d71625453b80a Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4object.cpp | 8 -------- src/qml/jsruntime/qv4stringobject.cpp | 20 ++++++++++++++++++++ src/qml/jsruntime/qv4stringobject_p.h | 5 +++-- 3 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index dff7555061..ba6d8f9c77 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -983,14 +983,6 @@ PropertyAttributes Object::getOwnProperty(Managed *m, Identifier id, Property *p if (o->arrayData()->getProperty(index, p, &attrs)) return attrs; } - if (o->isStringObject()) { - if (index >= static_cast(m)->length()) - return Attr_Invalid; - attrs = Attr_NotConfigurable|Attr_NotWritable; - if (p) - p->value = static_cast(o)->getIndex(index); - return attrs; - } } else { Q_ASSERT(id.asHeapObject()); diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index b1ae5a1ce5..b9e04db28f 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -137,6 +137,26 @@ void StringObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, return Object::advanceIterator(m, it, name, index, p, attrs); } +PropertyAttributes StringObject::getOwnProperty(Managed *m, Identifier id, Property *p) +{ + PropertyAttributes attributes = Object::getOwnProperty(m, id, p); + if (attributes != Attr_Invalid) + return attributes; + + Object *o = static_cast(m); + if (id.isArrayIndex()) { + uint index = id.asArrayIndex(); + if (o->isStringObject()) { + if (index >= static_cast(m)->length()) + return Attr_Invalid; + if (p) + p->value = static_cast(o)->getIndex(index); + return Attr_NotConfigurable|Attr_NotWritable; + } + } + return Attr_Invalid; +} + DEFINE_OBJECT_VTABLE(StringCtor); void Heap::StringCtor::init(QV4::ExecutionContext *scope) diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h index 407d617d57..b9e09ecff0 100644 --- a/src/qml/jsruntime/qv4stringobject_p.h +++ b/src/qml/jsruntime/qv4stringobject_p.h @@ -98,10 +98,11 @@ struct StringObject: Object { return d()->length(); } - static bool deleteIndexedProperty(Managed *m, uint index); - + using Object::getOwnProperty; protected: + static bool deleteIndexedProperty(Managed *m, uint index); static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attrs); + static PropertyAttributes getOwnProperty(Managed *m, Identifier id, Property *p); }; struct StringCtor: FunctionObject -- cgit v1.2.3