From: Pawel Czajkowski
Date: Wed, 17 Dec 2014 11:34:44 +0000 (+0100)
Subject: [DataSync] Change validation methods
X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~777
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01a137725a66ca40726a6ec6f5dda459ff36006d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[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
---
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);