From 01a137725a66ca40726a6ec6f5dda459ff36006d Mon Sep 17 00:00:00 2001 From: Pawel Czajkowski Date: Wed, 17 Dec 2014 12:34:44 +0100 Subject: [PATCH] [DataSync] Change validation methods [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 --- src/datasync/datasync_api.js | 44 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/datasync/datasync_api.js b/src/datasync/datasync_api.js index 530f2d2e..c3b20e3a 100644 --- a/src/datasync/datasync_api.js +++ b/src/datasync/datasync_api.js @@ -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); -- 2.34.1