Correctly set the vtbl for Boolean and NumberObject
authorLars Knoll <lars.knoll@digia.com>
Fri, 11 Oct 2013 11:29:44 +0000 (13:29 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 11 Oct 2013 14:01:24 +0000 (16:01 +0200)
Also accept a boolean primitive as input to
Boolean.prototype.valueOf()

Change-Id: I5b94d8d65b86e26860b9844eb4bf823577c8e924
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4booleanobject.cpp
src/qml/jsruntime/qv4object_p.h

index d4d6201..025f983 100644 (file)
@@ -95,7 +95,9 @@ ReturnedValue BooleanPrototype::method_toString(SimpleCallContext *ctx)
 
 ReturnedValue BooleanPrototype::method_valueOf(SimpleCallContext *ctx)
 {
-    // ### Shouldn't this work for a boolean thisObject?
+    if (ctx->callData->thisObject.isBoolean())
+        return ctx->callData->thisObject.asReturnedValue();
+
     Scope scope(ctx);
     Scoped<BooleanObject> thisObject(scope, ctx->callData->thisObject);
     if (!thisObject)
index 032aadd..27ecf8b 100644 (file)
@@ -340,6 +340,7 @@ struct BooleanObject: Object {
 protected:
     BooleanObject(InternalClass *ic)
         : Object(ic) {
+        vtbl = &static_vtbl;
         type = Type_BooleanObject;
         value = Encode(false);
     }
@@ -357,6 +358,7 @@ struct NumberObject: Object {
 protected:
     NumberObject(InternalClass *ic)
         : Object(ic) {
+        vtbl = &static_vtbl;
         type = Type_NumberObject;
         value = Encode((int)0);
     }