From: Pawel Andruszkiewicz
Date: Fri, 2 Oct 2015 14:01:15 +0000 (+0200)
Subject: [Common] Implementation of long long and unsigned long long conversions.
X-Git-Tag: submit/tizen/20151026.073646^2^2~55^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9fd57798d790e0ccdf63aa82cd6143f50bbcb305;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Common] Implementation of long long and unsigned long long conversions.
Currently, only MediaController uses such conversions.
[Verification] TCT pass rate (r47): 100% (162/162/0/0/0).
Change-Id: I589c1f66f204f90c5eb2f50948f4e04d9f6c256b
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index dc70f761..9263c325 100755
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -384,8 +384,12 @@ Converter.prototype.toLong = function(val, nullable) {
};
function _toLongLong(val) {
- // TODO: how to implement this?
- return _toLong(val);
+ // According to WebIDL specification this will not be a precise representation
+ // of requested val. We're converting the val to signed long and then pass it
+ // to C++ to get the value in required range.
+ return native_.getResultObject(native_.callSync('Utils_toLongLong', {
+ n : _toLong(val)
+ }));
}
Converter.prototype.toLongLong = function(val, nullable) {
@@ -401,8 +405,12 @@ Converter.prototype.toUnsignedLong = function(val, nullable) {
};
function _toUnsignedLongLong(val) {
- // TODO: how to implement this?
- return _toUnsignedLong(val);
+ // According to WebIDL specification this will not be a precise representation
+ // of requested val. We're converting the val to signed long and then pass it
+ // to C++ to get the value in required range.
+ return native_.getResultObject(native_.callSync('Utils_toUnsignedLongLong', {
+ n : _toLong(val)
+ }));
}
Converter.prototype.toUnsignedLongLong = function(val, nullable) {
diff --git a/src/utils/utils_instance.cc b/src/utils/utils_instance.cc
index 45b0fb32..71d7aca9 100644
--- a/src/utils/utils_instance.cc
+++ b/src/utils/utils_instance.cc
@@ -31,6 +31,8 @@ UtilsInstance::UtilsInstance() {
REGISTER_SYNC("Utils_getPkgApiVersion", GetPkgApiVersion);
REGISTER_SYNC("Utils_checkPrivilegeAccess", CheckPrivilegeAccess);
REGISTER_SYNC("Utils_checkBackwardCompabilityPrivilegeAccess", CheckBackwardCompabilityPrivilegeAccess);
+ REGISTER_SYNC("Utils_toLongLong", ToLongLong);
+ REGISTER_SYNC("Utils_toUnsignedLongLong", ToUnsignedLongLong);
#undef REGISTER_SYNC
#undef REGISTER_ASYNC
@@ -116,5 +118,56 @@ void UtilsInstance::CheckBackwardCompabilityPrivilegeAccess(const picojson::valu
ReportSuccess(out);
}
+namespace {
+
+template int sgn(T val) {
+ return (T(0) < val) - (val < T(0));
+}
+
+const double kTwoPow63 = 9223372036854775808.0;
+const double kTwoPow64 = 18446744073709551616.0;
+
+} // namespace
+
+void UtilsInstance::ToLongLong(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Entered");
+
+ const auto& n = args.get("n");
+ long long output = 0;
+
+ if (n.is()) {
+ auto d = n.get();
+ d = sgn(d) * std::floor(std::fabs(d));
+ d = std::fmod(d, kTwoPow64);
+ if (d > kTwoPow63) {
+ d -= kTwoPow64;
+ }
+ output = static_cast(d);
+ }
+
+ ReportSuccess(picojson::value(static_cast(output)), out);
+}
+
+void UtilsInstance::ToUnsignedLongLong(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Entered");
+
+ const auto& n = args.get("n");
+ unsigned long long output = 0;
+
+ if (n.is()) {
+ auto d = n.get();
+ d = sgn(d) * std::floor(std::fabs(d));
+ d = std::fmod(d, kTwoPow64);
+ if (d < 0.0) {
+ d += kTwoPow64;
+ }
+ output = static_cast(d);
+ }
+
+ ReportSuccess(picojson::value(static_cast(output)), out);
+}
+
} // namespace utils
} // namespace extension
diff --git a/src/utils/utils_instance.h b/src/utils/utils_instance.h
index 723f8c1e..5c5e1d31 100644
--- a/src/utils/utils_instance.h
+++ b/src/utils/utils_instance.h
@@ -20,6 +20,9 @@ class UtilsInstance : public common::ParsedInstance {
void GetPkgApiVersion(const picojson::value& args, picojson::object& out);
void CheckPrivilegeAccess(const picojson::value& args, picojson::object& out);
void CheckBackwardCompabilityPrivilegeAccess(const picojson::value& args, picojson::object& out);
+
+ void ToLongLong(const picojson::value& args, picojson::object& out);
+ void ToUnsignedLongLong(const picojson::value& args, picojson::object& out);
};
} // namespace utils
} // namespace extension