diff options
-rw-r--r-- | src/qml/jsruntime/qv4booleanobject.cpp | 43 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4booleanobject_p.h | 4 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp index 2d89366e74..eb83f902db 100644 --- a/src/qml/jsruntime/qv4booleanobject.cpp +++ b/src/qml/jsruntime/qv4booleanobject.cpp @@ -73,30 +73,39 @@ void BooleanPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(engine->id_valueOf(), method_valueOf); } -ReturnedValue BooleanPrototype::method_toString(const BuiltinFunction *b, CallData *callData) +static bool value(const Value *thisObject, bool *exception) { - ExecutionEngine *v4 = b->engine(); - bool result; - if (callData->thisObject.isBoolean()) { - result = callData->thisObject.booleanValue(); + *exception = false; + if (thisObject->isBoolean()) { + return thisObject->booleanValue(); } else { - const BooleanObject *thisObject = callData->thisObject.as<BooleanObject>(); - if (!thisObject) - return v4->throwTypeError(); - result = thisObject->value(); + const BooleanObject *that = thisObject->as<BooleanObject>(); + if (that) + return that->value(); } + *exception = true; + return false; +} + +ReturnedValue BooleanPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) +{ + bool exception; + bool result = ::value(thisObject, &exception); + ExecutionEngine *v4 = b->engine(); + if (exception) + return v4->throwTypeError(); return Encode(result ? v4->id_true() : v4->id_false()); } -ReturnedValue BooleanPrototype::method_valueOf(const BuiltinFunction *b, CallData *callData) +ReturnedValue BooleanPrototype::method_valueOf(const FunctionObject *b, const Value *thisObject, const Value *, int) { - if (callData->thisObject.isBoolean()) - return callData->thisObject.asReturnedValue(); - - const BooleanObject *thisObject = callData->thisObject.as<BooleanObject>(); - if (!thisObject) - return b->engine()->throwTypeError(); + bool exception; + bool result = ::value(thisObject, &exception); + if (exception) { + ExecutionEngine *v4 = b->engine(); + return v4->throwTypeError(); + } - return Encode(thisObject->value()); + return Encode(result); } diff --git a/src/qml/jsruntime/qv4booleanobject_p.h b/src/qml/jsruntime/qv4booleanobject_p.h index 7a686e0d53..3cf09b2667 100644 --- a/src/qml/jsruntime/qv4booleanobject_p.h +++ b/src/qml/jsruntime/qv4booleanobject_p.h @@ -79,8 +79,8 @@ struct BooleanPrototype: BooleanObject V4_PROTOTYPE(objectPrototype) void init(ExecutionEngine *engine, Object *ctor); - static ReturnedValue method_toString(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_valueOf(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; |