X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fstandards%2FTizen%2FTimeUtil%2FJSTimeDuration.cpp;h=bc624483f3590fe37581c6843467e055e90de520;hb=37fad6a43e6da3aa466886818d0c8a8c952f28f2;hp=cfb19711f5d5e2d805153ba3e0f436b40230e1ea;hpb=65d2bd12c33044282c41ce78c6e1bdbb441d1cff;p=profile%2Fivi%2Fwrt-plugins-tizen.git diff --git a/src/standards/Tizen/TimeUtil/JSTimeDuration.cpp b/src/standards/Tizen/TimeUtil/JSTimeDuration.cpp index cfb1971..bc62448 100755 --- a/src/standards/Tizen/TimeUtil/JSTimeDuration.cpp +++ b/src/standards/Tizen/TimeUtil/JSTimeDuration.cpp @@ -18,7 +18,7 @@ #include #include #include - +#include #include #include #include @@ -36,6 +36,7 @@ namespace Tizen1_0 { using namespace DPL; using namespace TizenApis::Commons; +using namespace TizenApis::Api::TimeUtil; using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; @@ -100,10 +101,9 @@ void JSTimeDuration::initialize(JSContextRef context, JSObjectRef object) if (!JSObjectGetPrivate(object)) { LogDebug("Private object not set... setting it."); DurationProperties durations; - std::auto_ptr durationProps(new DurationProperties( - durations)); - TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps.get()); - durationProps.release(); + DurationPropertiesPtr durationProps(new DurationProperties(durations)); + TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps); + if (!JSObjectSetPrivate(object, priv)) { delete priv; } @@ -157,35 +157,25 @@ bool JSTimeDuration::setProperty(JSContextRef context, JSObjectRef object, ThrowMsg(NullPointerException, "Private object not initialized"); } - DurationProperties *duration = privateObject->getObject(); + DurationPropertiesPtr duration = privateObject->getObject(); TimeUtilConverter convert(context); - if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) { - LogError("value is invald."); - ThrowMsg(ConversionException, "value is invald."); - } if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_TIMEDURATION_LENGTH)) { - if (!JSValueIsNumber(context, value)) { - LogError("value is invald."); - ThrowMsg(ConversionException, "value is invald."); - } duration->length = static_cast(convert.toDouble(value)); + if (std::isnan(duration->length) || std::isinf(duration->length)) + duration->length = 0; } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_TIMEDURATION_UNIT)) { - if (!JSValueIsString(context, value)) { - LogError("value is invald."); - ThrowMsg(ConversionException, "value is invald."); - } short unit = convert.toDurationUnit(convert.toString(value)); if (unit == 0xff) - ThrowMsg(InvalidArgumentException, "property doesn't exist."); + ThrowMsg(ConversionException, "property doesn't exist."); duration->unit = unit; } else - ThrowMsg(InvalidArgumentException, "property doesn't exist."); + return false; return true; } Catch (NullPointerException) { LogError("NullPointerException: " << _rethrown_exception.GetMessage()); - *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error"); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); } Catch (ConversionException) { LogError("ConversionException: " << _rethrown_exception.GetMessage()); *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); @@ -202,10 +192,9 @@ bool JSTimeDuration::setProperty(JSContextRef context, JSObjectRef object, JSObjectRef JSTimeDuration::createJSObject(JSContextRef context, const DurationProperties &durations) { - std::auto_ptr durationProps(new DurationProperties( - durations)); - TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps.get()); - durationProps.release(); + DurationPropertiesPtr durationProps(new DurationProperties(durations)); + TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps); + if (!priv) { ThrowMsg(NullPointerException, "Can not new an object"); } @@ -216,33 +205,30 @@ JSObjectRef JSTimeDuration::constructor(JSContextRef ctx, JSObjectRef constructo LogDebug("entered"); TimeUtilConverter convert(ctx); Try { - if ((argumentCount < 1) || (argumentCount > 2)) { - LogError("Wrong argument count"); - ThrowMsg(InvalidArgumentException, "Wrong TimeDuration argumentCount"); - } - TimeDurationPrivObject* mainPriv = static_cast(JSObjectGetPrivate(constructor)); JSContextRef global_context = mainPriv ? mainPriv->getContext() : ctx; DurationProperties duration; - if (JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0]) || !JSValueIsNumber(ctx, arguments[0])) { - ThrowMsg(ConversionException, "Argument(length) is invalid"); - } - duration.length = convert.toDouble(arguments[0]); - if (argumentCount == 2) { - if (JSValueIsUndefined(ctx, arguments[1]) || !JSValueIsString(ctx, arguments[1])) { - ThrowMsg(ConversionException, "Argument(unit) is invalid"); - } else if (!JSValueIsNull(ctx, arguments[1])) { + if (argumentCount == 0) + duration.length = convert.toDouble(JSValueMakeUndefined(ctx)); + else + duration.length = convert.toDouble(arguments[0]); + + if (std::isnan(duration.length) || std::isinf(duration.length)) + duration.length = 0; + + if (argumentCount > 1) { + if (!JSValueIsUndefined(ctx, arguments[1]) && !JSValueIsNull(ctx, arguments[1])) { std::string unit = convert.toString(arguments[1]); duration.unit = convert.toDurationUnit(unit); if (duration.unit == 0xff) - ThrowMsg(InvalidArgumentException, "Argument(unit) is invalid(wrong type unit)"); + ThrowMsg(ConversionException, "Argument(unit) is invalid(wrong type unit)"); } } - return createJSObject(global_context, duration); + return createJSObject(ctx, duration); } Catch(NullPointerException) { LogError("Exception: " << _rethrown_exception.GetMessage()); - *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error"); + *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); return NULL; } Catch(UnknownException) { LogError("Exception: " << _rethrown_exception.GetMessage()); @@ -274,33 +260,35 @@ bool JSTimeDuration::hasInstance(JSContextRef context, JSValueRef JSTimeDuration::diffTimeDuration(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type) { LogDebug("entered"); - TimeDurationPrivObject* privateObject = static_cast(JSObjectGetPrivate(thisObject)); + AceSecurityStatus status = TIMEUTIL_CHECK_ACCESS( + TIMEUTIL_FUNCTION_API_READ_FUNCS); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - if (argumentCount != 1) { - LogError("Wrong parameters"); - ThrowMsg(InvalidArgumentException, "Wrong parameters"); - } + TimeDurationPrivObject* privateObject = static_cast(JSObjectGetPrivate(thisObject)); + if (!privateObject) { + LogError("Private object is not set."); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); + } - AceSecurityStatus status = TIMEUTIL_CHECK_ACCESS( - privateObject->getContext(), - TIMEUTIL_FUNCTION_API_READ_FUNCS); - TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - - TimeUtilConverter converter(privateObject->getContext()); - - DurationProperties first = converter.getDurationPropertis(thisObject); - DurationProperties second = converter.getDurationPropertis(arguments[0]); - - DurationProperties diff; - if (first.unit > second.unit) { - long long firstLength = converter.convertDurationLength(first, second.unit); - diff.unit = second.unit; - diff.length = firstLength - second.length; - } else { - long long secondLength = converter.convertDurationLength(second, first.unit); - diff.unit = first.unit; - diff.length = first.length - secondLength; - } + TimeUtilConverter converter(context); + + DurationProperties first = converter.getDurationPropertis(thisObject); + DurationProperties second; + if (argumentCount == 0) + second= converter.getDurationPropertis(JSValueMakeUndefined(context)); + else + second= converter.getDurationPropertis(arguments[0]); + + DurationProperties diff; + if (first.unit > second.unit) { + long long firstLength = converter.convertDurationLength(first, second.unit); + diff.unit = second.unit; + diff.length = firstLength - second.length; + } else { + long long secondLength = converter.convertDurationLength(second, first.unit); + diff.unit = first.unit; + diff.length = first.length - secondLength; + } switch (type) { case EQUALSTO: