cleanup __qmljs_to_boolean vs Value.toBoolean()
authorLars Knoll <lars.knoll@digia.com>
Thu, 14 Feb 2013 22:16:50 +0000 (23:16 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 15 Feb 2013 06:45:44 +0000 (07:45 +0100)
Change-Id: Ic93eed2d4e68972d373bf1521387331ce26bac43
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/llvm_runtime.cpp
src/v4/moth/qv4vme_moth.cpp
src/v4/qmljs_runtime.cpp
src/v4/qmljs_runtime.h
src/v4/qmljs_value.cpp
src/v4/qmljs_value.h
src/v4/qv4arrayobject.cpp
src/v4/qv4booleanobject.cpp
src/v4/qv4isel_masm.cpp
src/v4/qv4objectproto.cpp

index 7e6f438..004a7f3 100644 (file)
@@ -101,7 +101,7 @@ void __qmljs_llvm_init_closure(ExecutionContext *ctx, Value *result,
 
 bool __qmljs_llvm_to_boolean(ExecutionContext *ctx, const Value *value)
 {
-    return __qmljs_to_boolean(*value, ctx);
+    return __qmljs_to_boolean(*value);
 }
 
 void __qmljs_llvm_bit_and(ExecutionContext *ctx, Value *result, Value *left, Value *right)
index 4fea463..290e4b5 100644 (file)
@@ -399,7 +399,7 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
     MOTH_END_INSTR(Jump)
 
     MOTH_BEGIN_INSTR(CJump)
-        uint cond = __qmljs_to_boolean(VALUE(instr.condition), context);
+        uint cond = __qmljs_to_boolean(VALUE(instr.condition));
         TRACE(condition, "%s", cond ? "TRUE" : "FALSE");
         if (cond)
             code = ((uchar *)&instr.offset) + instr.offset;
index 0b05f84..706775c 100644 (file)
@@ -487,6 +487,12 @@ Value __qmljs_object_default_value(ExecutionContext *ctx, Value object, int type
     return Value::undefinedValue();
 }
 
+Bool __qmljs_to_boolean(const Value &value)
+{
+    return value.toBoolean();
+}
+
+
 Object *__qmljs_convert_to_object(ExecutionContext *ctx, const Value &value)
 {
     assert(!value.isObject());
index 2176d59..3001f85 100644 (file)
@@ -167,7 +167,7 @@ Value __qmljs_get_thisObject(ExecutionContext *ctx);
 
 // type conversion and testing
 Value __qmljs_to_primitive(const Value &value, ExecutionContext *ctx, int typeHint);
-Bool __qmljs_to_boolean(const Value &value, ExecutionContext *ctx);
+Bool __qmljs_to_boolean(const Value &value);
 double __qmljs_to_number(const Value &value, ExecutionContext *ctx);
 Value __qmljs_to_string(const Value &value, ExecutionContext *ctx);
 Q_V4_EXPORT String *__qmljs_convert_to_string(ExecutionContext *ctx, const Value &value);
@@ -284,26 +284,6 @@ inline Value __qmljs_to_primitive(const Value &value, ExecutionContext *ctx, int
     return __qmljs_default_value(value, ctx, typeHint);
 }
 
-inline Bool __qmljs_to_boolean(const Value &value, ExecutionContext *ctx)
-{
-    switch (value.type()) {
-    case Value::Undefined_Type:
-    case Value::Null_Type:
-        return false;
-    case Value::Boolean_Type:
-    case Value::Integer_Type:
-        return (bool)value.int_32;
-    case Value::String_Type:
-        return value.stringValue()->toQString().length() > 0;
-    case Value::Object_Type:
-        return true;
-    default: // double
-        if (! value.doubleValue() || isnan(value.doubleValue()))
-            return false;
-        return true;
-    }
-}
-
 inline double __qmljs_to_number(const Value &value, ExecutionContext *ctx)
 {
     switch (value.type()) {
@@ -387,11 +367,11 @@ inline void __qmljs_compl(ExecutionContext *ctx, Value *result, const Value &val
     *result = Value::fromInt32(~n);
 }
 
-inline void __qmljs_not(ExecutionContext *ctx, Value *result, const Value &value)
+inline void __qmljs_not(ExecutionContext *, Value *result, const Value &value)
 {
     TRACE1(value);
 
-    bool b = __qmljs_to_boolean(value, ctx);
+    bool b = value.toBoolean();
     *result = Value::fromBoolean(!b);
 }
 
index e1bd2a6..91f4ec8 100644 (file)
@@ -74,11 +74,6 @@ int Value::toUInt16(ExecutionContext *ctx) const
     return (unsigned short)number;
 }
 
-Bool Value::toBoolean(ExecutionContext *ctx) const
-{
-    return __qmljs_to_boolean(*this, ctx);
-}
-
 double Value::toInteger(ExecutionContext *ctx) const
 {
     if (isConvertibleToInt())
index 62ca005..56d9094 100644 (file)
@@ -48,6 +48,8 @@
 #include <QtCore/QDebug>
 #include "qv4managed.h"
 
+#include <wtf/MathExtras.h>
+
 QT_BEGIN_NAMESPACE
 
 namespace QQmlJS {
@@ -205,7 +207,7 @@ struct Q_V4_EXPORT Value
     int toInt32(ExecutionContext *ctx) const;
     unsigned int toUInt32(ExecutionContext *ctx) const;
 
-    Bool toBoolean(ExecutionContext *ctx) const;
+    Bool toBoolean() const;
     double toInteger(ExecutionContext *ctx) const;
     double toNumber(ExecutionContext *ctx) const;
     String *toString(ExecutionContext *ctx) const;
@@ -353,6 +355,26 @@ inline Value Value::fromObject(Object *o)
     return v;
 }
 
+inline Bool Value::toBoolean() const
+{
+    switch (type()) {
+    case Value::Undefined_Type:
+    case Value::Null_Type:
+        return false;
+    case Value::Boolean_Type:
+    case Value::Integer_Type:
+        return (bool)int_32;
+    case Value::String_Type:
+        return stringValue()->toQString().length() > 0;
+    case Value::Object_Type:
+        return true;
+    default: // double
+        if (! doubleValue() || isnan(doubleValue()))
+            return false;
+        return true;
+    }
+}
+
 inline String *Value::toString(ExecutionContext *ctx) const
 {
     if (isString())
index 1878c15..04fbc1f 100644 (file)
@@ -642,7 +642,7 @@ Value ArrayPrototype::method_every(ExecutionContext *ctx)
         args[1] = Value::fromDouble(k);
         args[2] = ctx->thisObject;
         Value r = callback->call(ctx, thisArg, args, 3);
-        ok = __qmljs_to_boolean(r, ctx);
+        ok = r.toBoolean();
     }
     return Value::fromBoolean(ok);
 }
@@ -670,7 +670,7 @@ Value ArrayPrototype::method_some(ExecutionContext *ctx)
         args[1] = Value::fromDouble(k);
         args[2] = ctx->thisObject;
         Value r = callback->call(ctx, thisArg, args, 3);
-        if (__qmljs_to_boolean(r, ctx))
+        if (r.toBoolean())
             return Value::fromBoolean(true);
     }
     return Value::fromBoolean(false);
@@ -762,7 +762,7 @@ Value ArrayPrototype::method_filter(ExecutionContext *ctx)
         args[1] = Value::fromDouble(k);
         args[2] = ctx->thisObject;
         Value selected = callback->call(ctx, thisArg, args, 3);
-        if (__qmljs_to_boolean(selected, ctx)) {
+        if (selected.toBoolean()) {
             a->arraySet(to, v);
             ++to;
         }
index b2a72f1..8b1af93 100644 (file)
@@ -53,13 +53,13 @@ BooleanCtor::BooleanCtor(ExecutionContext *scope)
 
 Value BooleanCtor::construct(Managed *, ExecutionContext *ctx, Value *args, int argc)
 {
-    bool n = argc ? args[0].toBoolean(ctx) : false;
+    bool n = argc ? args[0].toBoolean() : false;
     return Value::fromObject(ctx->engine->newBooleanObject(Value::fromBoolean(n)));
 }
 
 Value BooleanCtor::call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc)
 {
-    bool value = argc ? argv[0].toBoolean(parentCtx) : 0;
+    bool value = argc ? argv[0].toBoolean() : 0;
     return Value::fromBoolean(value);
 }
 
index 7dfd8ed..2f2c9ce 100644 (file)
@@ -930,7 +930,7 @@ void InstructionSelection::visitCJump(IR::CJump *s)
 
         booleanConversion.link(_as);
         {
-            generateFunctionCall(Assembler::ReturnValueRegister, __qmljs_to_boolean, Assembler::PointerToValue(t), Assembler::ContextRegister);
+            generateFunctionCall(Assembler::ReturnValueRegister, __qmljs_to_boolean, Assembler::PointerToValue(t));
         }
 
         testBoolean.link(_as);
index 1cdf61c..21d6182 100644 (file)
@@ -475,11 +475,11 @@ void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Prope
 
     desc->enumberable = PropertyDescriptor::Undefined;
     if (o->__hasProperty__(ctx, ctx->engine->id_enumerable))
-        desc->enumberable = __qmljs_to_boolean(o->__get__(ctx, ctx->engine->id_enumerable), ctx) ? PropertyDescriptor::Enabled : PropertyDescriptor::Disabled;
+        desc->enumberable = o->__get__(ctx, ctx->engine->id_enumerable).toBoolean() ? PropertyDescriptor::Enabled : PropertyDescriptor::Disabled;
 
     desc->configurable = PropertyDescriptor::Undefined;
     if (o->__hasProperty__(ctx, ctx->engine->id_configurable))
-        desc->configurable = __qmljs_to_boolean(o->__get__(ctx, ctx->engine->id_configurable), ctx) ? PropertyDescriptor::Enabled : PropertyDescriptor::Disabled;
+        desc->configurable = o->__get__(ctx, ctx->engine->id_configurable).toBoolean() ? PropertyDescriptor::Enabled : PropertyDescriptor::Disabled;
 
     desc->get = 0;
     if (o->__hasProperty__(ctx, ctx->engine->id_get)) {
@@ -513,7 +513,7 @@ void ObjectPrototype::toPropertyDescriptor(ExecutionContext *ctx, Value v, Prope
     if (o->__hasProperty__(ctx, ctx->engine->id_writable)) {
         if (desc->isAccessor())
             ctx->throwTypeError();
-        desc->writable = __qmljs_to_boolean(o->__get__(ctx, ctx->engine->id_writable), ctx) ? PropertyDescriptor::Enabled : PropertyDescriptor::Disabled;
+        desc->writable = o->__get__(ctx, ctx->engine->id_writable).toBoolean() ? PropertyDescriptor::Enabled : PropertyDescriptor::Disabled;
         // writable forces it to be a data descriptor
         desc->value = Value::undefinedValue();
     }