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)
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;
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());
// 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);
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()) {
*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);
}
return (unsigned short)number;
}
-Bool Value::toBoolean(ExecutionContext *ctx) const
-{
- return __qmljs_to_boolean(*this, ctx);
-}
-
double Value::toInteger(ExecutionContext *ctx) const
{
if (isConvertibleToInt())
#include <QtCore/QDebug>
#include "qv4managed.h"
+#include <wtf/MathExtras.h>
+
QT_BEGIN_NAMESPACE
namespace QQmlJS {
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;
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())
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);
}
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);
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;
}
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);
}
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);
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)) {
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();
}