Fix Object.prototype.isPrototypeOf()
authorLars Knoll <lars.knoll@digia.com>
Thu, 13 Dec 2012 00:15:44 +0000 (01:15 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 12 Dec 2012 23:00:05 +0000 (00:00 +0100)
Implement the method according to spec (15.2.4.6)

Change-Id: I84b943366dcb1048966d4ae2f60bcbf01c99e7ea
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qv4ecmaobjects.cpp

index daee93a..bb3cd5f 100644 (file)
@@ -823,9 +823,14 @@ Value ObjectPrototype::method_isPrototypeOf(ExecutionContext *ctx)
     if (! V.isObject())
         return Value::fromBoolean(false);
 
-    Value O = ctx->thisObject.toObject(ctx);
+    Object *O = ctx->thisObject.toObject(ctx).objectValue();
     Object *proto = V.objectValue()->prototype;
-    return Value::fromBoolean(proto && O.objectValue() == proto);
+    while (proto) {
+        if (O == proto)
+            return Value::fromBoolean(true);
+        proto = proto->prototype;
+    }
+    return Value::fromBoolean(false);
 }
 
 Value ObjectPrototype::method_propertyIsEnumerable(ExecutionContext *ctx)