[Common] Moved StringToArray function to utils and applied auto-format 06/248506/2 accepted/tizen/unified/20201210.124550 submit/tizen/20201209.085808
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Fri, 27 Nov 2020 07:28:17 +0000 (08:28 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 9 Dec 2020 06:03:56 +0000 (06:03 +0000)
[Verification] TCT filesystem 100% passrate.
Checked metadata features in chrome console.

Change-Id: I807d8514bfda1afccd136fe74b37f80ff45190ca

src/common/extension.h
src/common/logger.h
src/filesystem/js/common.js
src/filesystem/js/file_handle.js
src/filesystem/js/file_stream.js
src/mediacontroller/mediacontroller_instance.cc
src/metadata/metadata_api.js
src/utils/utils_api.js

index f35c822..404e3f7 100644 (file)
@@ -93,7 +93,8 @@ class Instance {
   Instance();
   virtual ~Instance();
 
-  static void DoAndPostMessage(Instance* that, const std::function<void()>& work, const picojson::value& json);
+  static void DoAndPostMessage(Instance* that, const std::function<void()>& work,
+                               const picojson::value& json);
   static void PostMessage(Instance* that, const char* msg);
   static void PostMessage(Instance* that, const picojson::value& json);
   void PostMessage(const char* msg);
index f2a1ef6..e4a6f3c 100644 (file)
@@ -112,8 +112,8 @@ int _printf_format_checker(const char* fmt, ...) {
 #define LOGGER_IF(priority, condition) \
   !(condition) ? (void)0 : LogMessageVoidify() & (LOGGER(priority))
 
-#define DEPRECATION_WARN(log, version)                          \
-  /* For public code, warning should be always shown */         \
+#define DEPRECATION_WARN(log, version)                  \
+  /* For public code, warning should be always shown */ \
   LoggerW("DEPRECATION WARNING: %s", log);
 
 // This class more or less represents a particular log message.
index 602abe9..f1aa9b4 100644 (file)
@@ -23,20 +23,6 @@ var types_ = validator_.Types;
 var native_ = new xwalk.utils.NativeManager(extension);
 
 /*
- * Create new array-like object of numbers: UTF-16 char codes from string.
- * As type pass Array, Uint8Array, etc.
- * Useful for passing data through crosswalk.
- */
-function StringToArray(str, type) {
-    var len = str.length;
-    var output = new type(len);
-    for (var i = 0; i < len; i++) {
-        output[i] = str.charCodeAt(i);
-    }
-    return output;
-}
-
-/*
  * Pass array-like object of numbers (Array, Uint8Array, etc.), returns string.
  * Each char has codepoint equal to value from array cropped with & 0xFF
  * Useful for passing data through crosswalk.
index 3356350..c8d4e42 100644 (file)
@@ -295,7 +295,7 @@ FileHandle.prototype.readBlob = function() {
         throw native_.getErrorObject(result);
     }
     var encodedData = native_.getResultObject(result);
-    var data = StringToArray(encodedData, Uint8Array);
+    var data = privUtils_.StringToArray(encodedData, Uint8Array);
     return new Blob([data]);
 };
 
@@ -330,7 +330,7 @@ FileHandle.prototype.readBlobNonBlocking = function() {
             native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
         } else {
             var encodedData = native_.getResultObject(result);
-            var data = StringToArray(encodedData, Uint8Array);
+            var data = privUtils_.StringToArray(encodedData, Uint8Array);
             native_.callIfPossible(args.successCallback, new Blob([data]));
         }
     };
@@ -464,7 +464,7 @@ FileHandle.prototype.readData = function() {
         throw native_.getErrorObject(result);
     }
     var encodedData = native_.getResultObject(result);
-    var data = StringToArray(encodedData, Uint8Array);
+    var data = privUtils_.StringToArray(encodedData, Uint8Array);
     return new Uint8Array(data);
 };
 
@@ -511,7 +511,7 @@ FileHandle.prototype.readDataNonBlocking = function() {
             native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
         } else {
             var data_out = new Uint8Array(
-                StringToArray(native_.getResultObject(result), Uint8Array)
+                privUtils_.StringToArray(native_.getResultObject(result), Uint8Array)
             );
             native_.callIfPossible(args.successCallback, data_out);
         }
index 5364490..cd89d98 100644 (file)
@@ -185,7 +185,7 @@ function readBytes() {
         throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Could not read');
     }
 
-    var decoded = StringToArray(native_.getResultObject(result), Array);
+    var decoded = privUtils_.StringToArray(native_.getResultObject(result), Array);
 
     if (decoded.length) {
         can_change_size = true;
index 2c8c095..f3cf189 100644 (file)
@@ -716,7 +716,8 @@ void MediaControllerInstance::MediaControllerServerDeletePlaylist(const picojson
       LogAndReportError(result, &response_obj, ("Failed: server_->DeletePlaylist"));
     }
 
-    if (MEDIA_CONTROLLER_ERROR_NONE != mc_playlist_destroy(server_playlist_map_[serverName][name])) {
+    if (MEDIA_CONTROLLER_ERROR_NONE !=
+        mc_playlist_destroy(server_playlist_map_[serverName][name])) {
       LoggerE("Unable to destroy playlist %s", name.c_str());
     }
 
@@ -2140,9 +2141,8 @@ void MediaControllerInstance::MediaControllerPlaylistsGetPlaylist(const picojson
 
   mc_playlist_h handle = nullptr;
   if (server_playlist_map_.find(app_id) != server_playlist_map_.end() &&
-      server_playlist_map_[app_id].find(playlist_name) !=
-          server_playlist_map_[app_id].end()) {
-            LoggerD("Using saved handle");
+      server_playlist_map_[app_id].find(playlist_name) != server_playlist_map_[app_id].end()) {
+    LoggerD("Using saved handle");
     handle = server_playlist_map_[app_id][playlist_name];
   }
 
index 62790de..f054add 100755 (executable)
@@ -19,7 +19,7 @@ var validator_ = privUtils_.validator;
 var types_ = validator_.Types;
 var native_ = new xwalk.utils.NativeManager(extension);
 
-var DEFAULT_BLOB_MIME_TYPE = "image/jpeg"
+var DEFAULT_BLOB_MIME_TYPE = 'image/jpeg';
 
 var MetadataType = {
     ALBUM: 'ALBUM',
@@ -127,23 +127,6 @@ MetadataFileHandle.prototype.release = function() {
     return native_.getResultObject(result);
 };
 
-// below section copied from filesystem
-// TODO move this to utils?
-/*
- * Create new array-like object of numbers: UTF-16 char codes from string.
- * As type pass Array, Uint8Array, etc.
- * Useful for passing data through crosswalk.
- */
-function StringToArray(str, type) {
-    var len = str.length;
-    var output = new type(len);
-    for (var i = 0; i < len; i++) {
-        output[i] = str.charCodeAt(i);
-    }
-    return output;
-}
-////////////////////////////////////////////////////
-
 MetadataFileHandle.prototype.getArtwork = function() {
     var data = {
         uri: this.uri,
@@ -155,7 +138,7 @@ MetadataFileHandle.prototype.getArtwork = function() {
         throw native_.getErrorObject(result);
     }
     var resultData = native_.getResultObject(result);
-    var encodedData = StringToArray(resultData.encodedData, Uint8Array);
+    var encodedData = privUtils_.StringToArray(resultData.encodedData, Uint8Array);
 
     return new Blob([encodedData], { type: resultData.mimeType });
 };
@@ -170,7 +153,10 @@ MetadataFileHandle.prototype.getThumbnailFrame = function() {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-    var encodedData = StringToArray(native_.getResultObject(result), Uint8Array);
+    var encodedData = privUtils_.StringToArray(
+        native_.getResultObject(result),
+        Uint8Array
+    );
 
     return new Blob([encodedData], { type: DEFAULT_BLOB_MIME_TYPE });
 };
@@ -192,7 +178,10 @@ MetadataFileHandle.prototype.getFrameAtTime = function() {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-    var encodedData = StringToArray(native_.getResultObject(result), Uint8Array);
+    var encodedData = privUtils_.StringToArray(
+        native_.getResultObject(result),
+        Uint8Array
+    );
 
     return new Blob([encodedData], { type: DEFAULT_BLOB_MIME_TYPE });
 };
index 33ee00b..76a2d67 100644 (file)
@@ -385,6 +385,20 @@ Utils.prototype.printDeprecationWarningFor = function(name, replacement) {
     }
 };
 
+/*
+ * Create new array-like object of numbers: UTF-16 char codes from string.
+ * As type pass Array, Uint8Array, etc.
+ * Useful for passing data through crosswalk.
+ */
+Utils.prototype.StringToArray = function(str, type) {
+    var len = str.length;
+    var output = new type(len);
+    for (var i = 0; i < len; i++) {
+        output[i] = str.charCodeAt(i);
+    }
+    return output;
+};
+
 /////////////////////////////////////////////////////////////////////////////
 /** @constructor */
 var Type = function() {};