You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/10 15:34:28 UTC
js commit: [all] Use argscheck in Entry.js
Updated Branches:
refs/heads/master 94a42b138 -> fdf0d8545
[all] Use argscheck in Entry.js
Saves 500 bytes
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/fdf0d854
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/fdf0d854
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/fdf0d854
Branch: refs/heads/master
Commit: fdf0d8545285a02ce816b94b54ca3c53e531beb4
Parents: 94a42b1
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Jan 8 16:30:28 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jan 10 09:34:25 2013 -0500
----------------------------------------------------------------------
lib/common/plugin/Entry.js | 83 +++++++++++++++------------------------
1 files changed, 32 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/fdf0d854/lib/common/plugin/Entry.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/Entry.js b/lib/common/plugin/Entry.js
index 1b141a1..06f195f 100644
--- a/lib/common/plugin/Entry.js
+++ b/lib/common/plugin/Entry.js
@@ -19,7 +19,8 @@
*
*/
-var exec = require('cordova/exec'),
+var argscheck = require('cordova/argscheck'),
+ exec = require('cordova/exec'),
FileError = require('cordova/plugin/FileError'),
Metadata = require('cordova/plugin/Metadata');
@@ -38,8 +39,8 @@ var exec = require('cordova/exec'),
* (readonly)
*/
function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
- this.isFile = (typeof isFile != 'undefined'?isFile:false);
- this.isDirectory = (typeof isDirectory != 'undefined'?isDirectory:false);
+ this.isFile = !!isFile;
+ this.isDirectory = !!isDirectory;
this.name = name || '';
this.fullPath = fullPath || '';
this.filesystem = fileSystem || null;
@@ -54,15 +55,16 @@ function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
* {Function} is called with a FileError
*/
Entry.prototype.getMetadata = function(successCallback, errorCallback) {
- var success = typeof successCallback !== 'function' ? null : function(lastModified) {
- var metadata = new Metadata(lastModified);
- successCallback(metadata);
- };
- var fail = typeof errorCallback !== 'function' ? null : function(code) {
- errorCallback(new FileError(code));
- };
+ argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
+ var success = successCallback && function(lastModified) {
+ var metadata = new Metadata(lastModified);
+ successCallback(metadata);
+ };
+ var fail = errorCallback && function(code) {
+ errorCallback(new FileError(code));
+ };
- exec(success, fail, "File", "getMetadata", [this.fullPath]);
+ exec(success, fail, "File", "getMetadata", [this.fullPath]);
};
/**
@@ -76,8 +78,8 @@ Entry.prototype.getMetadata = function(successCallback, errorCallback) {
* {Object} keys and values to set
*/
Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataObject) {
-
- exec(successCallback, errorCallback, "File", "setMetadata", [this.fullPath, metadataObject]);
+ argscheck.checkArgs('FFO', 'Entry.setMetadata', arguments);
+ exec(successCallback, errorCallback, "File", "setMetadata", [this.fullPath, metadataObject]);
};
/**
@@ -93,36 +95,25 @@ Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataO
* {Function} called with a FileError
*/
Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
- var fail = function(code) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(code));
- }
+ argscheck.checkArgs('oSFF', 'Entry.moveTo', arguments);
+ var fail = errorCallback && function(code) {
+ errorCallback(new FileError(code));
};
- // user must specify parent Entry
- if (!parent) {
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
// source path
var srcPath = this.fullPath,
// entry name
name = newName || this.name,
success = function(entry) {
if (entry) {
- if (typeof successCallback === 'function') {
+ if (successCallback) {
// create appropriate Entry object
var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
+ successCallback(result);
}
}
else {
// no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
+ fail && fail(FileError.NOT_FOUND_ERR);
}
};
@@ -143,18 +134,11 @@ Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallbac
* {Function} called with a FileError
*/
Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
- var fail = function(code) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(code));
- }
+ argscheck.checkArgs('oSFF', 'Entry.copyTo', arguments);
+ var fail = errorCallback && function(code) {
+ errorCallback(new FileError(code));
};
- // user must specify parent Entry
- if (!parent) {
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
-
// source path
var srcPath = this.fullPath,
// entry name
@@ -162,20 +146,15 @@ Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallbac
// success callback
success = function(entry) {
if (entry) {
- if (typeof successCallback === 'function') {
+ if (successCallback) {
// create appropriate Entry object
var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
+ successCallback(result);
}
}
else {
// no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
+ fail && fail(FileError.NOT_FOUND_ERR);
}
};
@@ -212,7 +191,8 @@ Entry.prototype.toURI = function(mimeType) {
* @param errorCallback {Function} called with a FileError
*/
Entry.prototype.remove = function(successCallback, errorCallback) {
- var fail = typeof errorCallback !== 'function' ? null : function(code) {
+ argscheck.checkArgs('FF', 'Entry.remove', arguments);
+ var fail = errorCallback && function(code) {
errorCallback(new FileError(code));
};
exec(successCallback, fail, "File", "remove", [this.fullPath]);
@@ -225,12 +205,13 @@ Entry.prototype.remove = function(successCallback, errorCallback) {
* @param errorCallback {Function} called with a FileError
*/
Entry.prototype.getParent = function(successCallback, errorCallback) {
- var win = typeof successCallback !== 'function' ? null : function(result) {
+ argscheck.checkArgs('FF', 'Entry.getParent', arguments);
+ var win = successCallback && function(result) {
var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
var entry = new DirectoryEntry(result.name, result.fullPath);
successCallback(entry);
};
- var fail = typeof errorCallback !== 'function' ? null : function(code) {
+ var fail = errorCallback && function(code) {
errorCallback(new FileError(code));
};
exec(win, fail, "File", "getParent", [this.fullPath]);