Make Object::hasProperty() inline
authorLars Knoll <lars.knoll@digia.com>
Thu, 7 Mar 2013 09:57:48 +0000 (10:57 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 7 Mar 2013 11:30:30 +0000 (12:30 +0100)
Simply call getPropertyDescriptor instead

Change-Id: I9e156a45dd10bf250fa156820ec2f3d5bbe80bbc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qv4object.cpp
src/v4/qv4object.h
src/v4/qv4stringobject.cpp
src/v4/qv4stringobject.h

index 6b80ec9..bc0fade 100644 (file)
@@ -281,14 +281,14 @@ PropertyDescriptor *Object::__getOwnProperty__(ExecutionContext *ctx, uint index
 }
 
 // Section 8.12.2
-PropertyDescriptor *Object::__getPropertyDescriptor__(ExecutionContext *ctx, String *name)
+PropertyDescriptor *Object::__getPropertyDescriptor__(const ExecutionContext *ctx, String *name) const
 {
     uint idx = name->asArrayIndex();
     if (idx != UINT_MAX)
         return __getPropertyDescriptor__(ctx, idx);
 
 
-    Object *o = this;
+    const Object *o = this;
     while (o) {
         uint idx = o->internalClass->find(name);
         if (idx < UINT_MAX)
@@ -299,15 +299,15 @@ PropertyDescriptor *Object::__getPropertyDescriptor__(ExecutionContext *ctx, Str
     return 0;
 }
 
-PropertyDescriptor *Object::__getPropertyDescriptor__(ExecutionContext *ctx, uint index)
+PropertyDescriptor *Object::__getPropertyDescriptor__(const ExecutionContext *ctx, uint index) const
 {
-    Object *o = this;
+    const Object *o = this;
     while (o) {
         PropertyDescriptor *p = o->arrayAt(index);
         if(p && p->type != PropertyDescriptor::Generic)
             return p;
         if (o->isStringObject()) {
-            p = static_cast<StringObject *>(o)->getIndex(ctx, index);
+            p = static_cast<const StringObject *>(o)->getIndex(ctx, index);
             if (p)
                 return p;
         }
@@ -520,30 +520,6 @@ void Object::__put__(ExecutionContext *ctx, uint index, const Value &value)
         ctx->throwTypeError();
 }
 
-// Section 8.12.6
-bool Object::__hasProperty__(const ExecutionContext *ctx, String *name) const
-{
-    uint idx = name->asArrayIndex();
-    if (idx != UINT_MAX)
-        return __hasProperty__(ctx, idx);
-
-    name->makeIdentifier(ctx);
-
-    if (internalClass->find(name) != UINT_MAX)
-        return true;
-
-    return prototype ? prototype->__hasProperty__(ctx, name) : false;
-}
-
-bool Object::__hasProperty__(const ExecutionContext *ctx, uint index) const
-{
-    const PropertyDescriptor *p = arrayAt(index);
-    if (p && p->type != PropertyDescriptor::Generic)
-        return true;
-
-    return prototype ? prototype->__hasProperty__(ctx, index) : false;
-}
-
 // Section 8.12.7
 bool Object::__delete__(ExecutionContext *ctx, String *name)
 {
index 93fe8bf..e392739 100644 (file)
@@ -128,17 +128,26 @@ struct Q_V4_EXPORT Object: Managed {
 
     PropertyDescriptor *__getOwnProperty__(ExecutionContext *ctx, String *name);
     PropertyDescriptor *__getOwnProperty__(ExecutionContext *ctx, uint index);
-    PropertyDescriptor *__getPropertyDescriptor__(ExecutionContext *ctx, String *name);
-    PropertyDescriptor *__getPropertyDescriptor__(ExecutionContext *ctx, uint index);
+
+    // -> vtable
+    PropertyDescriptor *__getPropertyDescriptor__(const ExecutionContext *ctx, String *name) const;
+    PropertyDescriptor *__getPropertyDescriptor__(const ExecutionContext *ctx, uint index) const;
 
     Value __get__(ExecutionContext *ctx, String *name, bool *hasProperty = 0);
     Value __get__(ExecutionContext *ctx, uint index, bool *hasProperty = 0);
 
+    // -> vtable
     void __put__(ExecutionContext *ctx, String *name, const Value &value);
     void __put__(ExecutionContext *ctx, uint index, const Value &value);
 
-    bool __hasProperty__(const ExecutionContext *ctx, String *name) const;
-    bool __hasProperty__(const ExecutionContext *ctx, uint index) const;
+    bool __hasProperty__(const ExecutionContext *ctx, String *name) const {
+        PropertyDescriptor *pd = __getPropertyDescriptor__(ctx, name);
+        return pd && pd->type != PropertyDescriptor::Generic;
+    }
+    bool __hasProperty__(const ExecutionContext *ctx, uint index) const {
+        PropertyDescriptor *pd = __getPropertyDescriptor__(ctx, index);
+        return pd && pd->type != PropertyDescriptor::Generic;
+    }
     bool __delete__(ExecutionContext *ctx, String *name);
     bool __delete__(ExecutionContext *ctx, uint index);
     bool __defineOwnProperty__(ExecutionContext *ctx, PropertyDescriptor *current, const PropertyDescriptor *desc);
index eab6989..93d9e9d 100644 (file)
@@ -93,7 +93,7 @@ StringObject::StringObject(ExecutionContext *ctx, const Value &value)
     defineReadonlyProperty(ctx->engine->id_length, Value::fromUInt32(value.stringValue()->toQString().length()));
 }
 
-PropertyDescriptor *StringObject::getIndex(ExecutionContext *ctx, uint index)
+PropertyDescriptor *StringObject::getIndex(const ExecutionContext *ctx, uint index) const
 {
     QString str = value.stringValue()->toQString();
     if (index >= (uint)str.length())
index 0ee72a0..67a5943 100644 (file)
@@ -52,10 +52,10 @@ namespace VM {
 
 struct StringObject: Object {
     Value value;
-    PropertyDescriptor tmpProperty;
+    mutable PropertyDescriptor tmpProperty;
     StringObject(ExecutionContext *ctx, const Value &value);
 
-    PropertyDescriptor *getIndex(ExecutionContext *ctx, uint index);
+    PropertyDescriptor *getIndex(const ExecutionContext *ctx, uint index) const;
 
 protected:
     static const ManagedVTable static_vtbl;