[DataSync] Change validation methods
authorPawel Czajkowski <p.czajkowski@samsung.com>
Wed, 17 Dec 2014 11:34:44 +0000 (12:34 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 19 Dec 2014 12:36:46 +0000 (21:36 +0900)
[Validation]
    1. Load tizen module in node.
    2. Run 'dlogutil node' command in another console.
    3. Paste sample code:
        var person = {};
        try {tizen.datasync.stopSync(person); } catch (e) { console.log(e.name) }
    3. You should find in dlog 'TypeError'.

Change-Id: I7a6040a1ff56ab2970f39f2e1d3a9c2237dfb3bc
Signed-off-by: Pawel Czajkowski <p.czajkowski@samsung.com>
src/datasync/datasync_api.js

index 530f2d2e1f0838be000ea5cfcb6b755eff7101a8..c3b20e3a817f99e1c48416dcaf4a35164c9ea63d 100644 (file)
@@ -10,6 +10,7 @@ var callbackId = 0;
 var callbacks = {};
 var hideProtectedProporties = true;
 var native_ = new xwalk.utils.NativeManager(extension);
+var validator_ = new xwalk.utils.validator;
 
 // for the time of serialization 'write-only' and 'read-only' properties
 // should be able to run with correct value
@@ -482,11 +483,11 @@ DataSynchronizationManager.prototype.update = function(profile) {
 };
 
 DataSynchronizationManager.prototype.remove = function(profileId) {
-  if (typeof profileId !== 'string') {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
+  var args = validator_.validateArgs(arguments, [
+    {name: 'profileId', type: types_.STRING}
+  ]);
   var msg = native_.callSync('Datasync_remove', {
-    arg: profileId
+    profileId: args.profileId
   });
 
   if (native_.isFailure(msg)) {
@@ -513,11 +514,11 @@ DataSynchronizationManager.prototype.getProfilesNum = function() {
 };
 
 DataSynchronizationManager.prototype.get = function(profileId) {
-  if (typeof profileId !== 'string') {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
+  var args = validator_.validateArgs(arguments, [
+    {name: 'profileId', type: types_.STRING}
+  ]);
   var msg = native_.callSync('Datasync_get', {
-    arg: profileId
+    profileId: args.profileId
   });
 
   if (native_.isFailure(msg)) {
@@ -545,9 +546,9 @@ DataSynchronizationManager.prototype.getAll = function() {
 };
 
 DataSynchronizationManager.prototype.startSync = function(profileId, progressCallback) {
-  if (typeof profileId !== 'string') {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
+  var args = validator_.validateArgs(arguments, [
+    {name: 'profileId', type: types_.STRING}
+  ]);
   if (arguments.length > 1) {
     // Array is an object, should not accept Array
     if (progressCallback instanceof Array) {
@@ -562,18 +563,21 @@ DataSynchronizationManager.prototype.startSync = function(profileId, progressCal
   }
 
   var msg = native_.callSync('Datasync_startSync',{
-    arg: profileId
+    profileId: args.profileId
   });
+  if (native_.isFailure(msg)) {
+      throw native_.getErrorObject(msg);
+  }
 
   return postSyncMessageWithCallback(msg, progressCallback);
 };
 
 DataSynchronizationManager.prototype.stopSync = function(profileId) {
-  if (typeof profileId !== 'string') {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
+  var args = validator_.validateArgs(arguments, [
+    {name: 'profileId', type: types_.STRING}
+  ]);
   var msg = native_.callSync('Datasync_stopSync',{
-    arg: profileId
+    profileId: args.profileId
   });
   if (native_.isFailure(msg)) {
       throw native_.getErrorObject(msg);
@@ -582,11 +586,11 @@ DataSynchronizationManager.prototype.stopSync = function(profileId) {
 };
 
 DataSynchronizationManager.prototype.getLastSyncStatistics = function(profileId) {
-  if (typeof profileId !== 'string') {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
+  var args = validator_.validateArgs(arguments, [
+    {name: 'profileId', type: types_.STRING}
+  ]);
   var msg = native_.callSync('Datasync_getLastSyncStatistics', {
-    arg: profileId
+    profileId: args.profileId
   });
   var result = native_.getResultObject(msg);
   return convertToSyncStatistics(result);