aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-01-04 22:32:13 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-09 07:46:50 +0100
commit6e05ab2bc4598b86082766e5a51ad3a6c9e637b7 (patch)
treef51441e052be395b2f0aa6acb5f7a339bc2c394c
parentff18885e0a7f7527eb96a9f2047507e7f418db45 (diff)
Add Object::hasOwnProperty()
This allows us to remove more getOwnProperty calls. This will be required later on to extend our array handling. Change-Id: I7b7f5887990cd443accf51891644fdfbb849cf35 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/jsapi/qjsvalue.cpp2
-rw-r--r--src/qml/jsruntime/qv4context.cpp9
-rw-r--r--src/qml/jsruntime/qv4object.cpp10
-rw-r--r--src/qml/jsruntime/qv4object_p.h3
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp2
5 files changed, 16 insertions, 10 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp
index 6a0cf0cf6d..8e1ac38f4f 100644
--- a/src/qml/jsapi/qjsvalue.cpp
+++ b/src/qml/jsapi/qjsvalue.cpp
@@ -1049,7 +1049,7 @@ bool QJSValue::hasOwnProperty(const QString &name) const
return false;
ScopedString s(scope, engine->newIdentifier(name));
- return o->__getOwnProperty__(s);
+ return o->hasOwnProperty(s);
}
/*!
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index f5d8106f06..35ed8fe0f3 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -362,16 +362,9 @@ void ExecutionContext::setProperty(const StringRef name, const ValueRef value)
}
if (activation) {
- if (ctx->type == Type_QmlContext) {
+ if (ctx->type == Type_QmlContext || activation->hasOwnProperty(name)) {
activation->put(name, value);
return;
- } else {
- PropertyAttributes attrs;
- Property *p = activation->__getOwnProperty__(name, &attrs);
- if (p) {
- activation->putValue(p, attrs, value);
- return;
- }
}
}
}
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index fc54933aca..53db957189 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -420,6 +420,16 @@ bool Object::__hasProperty__(uint index) const
return false;
}
+bool Object::hasOwnProperty(const StringRef name) const
+{
+ return const_cast<Object *>(this)->__getOwnProperty__(name) != 0;
+}
+
+bool Object::hasOwnProperty(uint index) const
+{
+ return const_cast<Object *>(this)->__getOwnProperty__(index) != 0;
+}
+
ReturnedValue Object::get(Managed *m, const StringRef name, bool *hasProperty)
{
return static_cast<Object *>(m)->internalGet(name, hasProperty);
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index 5f6cd879de..b172ddb7cd 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -143,6 +143,9 @@ struct Q_QML_EXPORT Object: Managed {
bool __hasProperty__(const StringRef name) const;
bool __hasProperty__(uint index) const;
+ bool hasOwnProperty(const StringRef name) const;
+ bool hasOwnProperty(uint index) const;
+
bool __defineOwnProperty__(ExecutionContext *ctx, Property *current, const StringRef member, const Property &p, PropertyAttributes attrs);
bool __defineOwnProperty__(ExecutionContext *ctx, const StringRef name, const Property &p, PropertyAttributes attrs);
bool __defineOwnProperty__(ExecutionContext *ctx, uint index, const Property &p, PropertyAttributes attrs);
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 31287d0e9f..6bce8a965c 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -448,7 +448,7 @@ ReturnedValue ObjectPrototype::method_hasOwnProperty(CallContext *ctx)
Scoped<Object> O(scope, ctx->callData->thisObject, Scoped<Object>::Convert);
if (scope.engine->hasException)
return Encode::undefined();
- bool r = O->__getOwnProperty__(P) != 0;
+ bool r = O->hasOwnProperty(P);
if (!r)
r = !O->query(P).isEmpty();
return Encode(r);