Fix unsafe casting to target thisobject in class generator
authorSimon Hausmann <simon.hausmann@digia.com>
Wed, 8 May 2013 18:26:04 +0000 (20:26 +0200)
committerLars Knoll <lars.knoll@digia.com>
Thu, 9 May 2013 06:30:36 +0000 (08:30 +0200)
We must also check if the asFoo() on the managed object succeeds
before calling the method.

Change-Id: I26ed56fec044b54221ca44e7789a2e9d0acec9ec
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v4/v4classgen

index 019435b..f725cfc 100755 (executable)
@@ -32,7 +32,10 @@ class ParsedMethod():
         out.write("    QV4::Object *thatObject = ctx->thisObject.asObject();\n")
         out.write("    if (!thatObject)\n")
         out.write("        ctx->throwTypeError();\n")
-        out.write("    return thatObject->as%s()->%s_%s(ctx);\n" % (parsedClass.managedTypeName(), self.methodPrefix, self.name))
+        out.write("    %s *o = thatObject->as%s();\n" % (parsedClass.name, parsedClass.managedTypeName()))
+        out.write("    if (!o)\n")
+        out.write("        ctx->throwTypeError();\n")
+        out.write("    return o->%s_%s(ctx);\n" % (self.methodPrefix, self.name))
         out.write("}\n")
         out.write("\n")