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:33:23 UTC

js commit: [all] Adds utils.typeName().

Updated Branches:
  refs/heads/master 984652af2 -> 46daf8446


[all] Adds utils.typeName().


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/46daf844
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/46daf844
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/46daf844

Branch: refs/heads/master
Commit: 46daf8446fa116803ed768798b81555d90d4975a
Parents: 984652a
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Dec 14 15:00:28 2012 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jan 10 09:33:06 2013 -0500

----------------------------------------------------------------------
 lib/common/argscheck.js |   10 ++++++----
 lib/common/utils.js     |    8 ++++++--
 2 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/46daf844/lib/common/argscheck.js
----------------------------------------------------------------------
diff --git a/lib/common/argscheck.js b/lib/common/argscheck.js
index 27bb5a1..edd47a5 100644
--- a/lib/common/argscheck.js
+++ b/lib/common/argscheck.js
@@ -20,6 +20,8 @@
 */
 
 var exec = require('cordova/exec');
+var utils = require('cordova/utils');
+
 var moduleExports = module.exports;
 
 var typeMap = {
@@ -40,7 +42,7 @@ function checkArgs(spec, functionName, args, opt_callee) {
         return;
     }
     var errMsg = null;
-    var type;
+    var typeName;
     for (var i = 0; i < spec.length; ++i) {
         var c = spec.charAt(i),
             cUpper = c.toUpperCase(),
@@ -49,17 +51,17 @@ function checkArgs(spec, functionName, args, opt_callee) {
         if (c == '*') {
             continue;
         }
-        type = Object.prototype.toString.call(arg).slice(8, -1);
+        typeName = utils.typeName(arg);
         if ((arg === null || arg === undefined) && c == cUpper) {
             continue;
         }
-        if (type != typeMap[cUpper]) {
+        if (typeName != typeMap[cUpper]) {
             errMsg = 'Expected ' + typeMap[cUpper];
             break;
         }
     }
     if (errMsg) {
-        errMsg += ', but got ' + type + '.';
+        errMsg += ', but got ' + typeName + '.';
         errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
         // Don't log when running jake test.
         if (typeof jasmine == 'undefined') {

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/46daf844/lib/common/utils.js
----------------------------------------------------------------------
diff --git a/lib/common/utils.js b/lib/common/utils.js
index 0861446..6389e62 100644
--- a/lib/common/utils.js
+++ b/lib/common/utils.js
@@ -56,18 +56,22 @@ utils.arrayRemove = function(a, item) {
     return index != -1;
 };
 
+utils.typeName = function(val) {
+    return Object.prototype.toString.call(val).slice(8, -1);
+};
+
 /**
  * Returns an indication of whether the argument is an array or not
  */
 utils.isArray = function(a) {
-    return Object.prototype.toString.call(a) == '[object Array]';
+    return utils.typeName(a) == 'Array';
 };
 
 /**
  * Returns an indication of whether the argument is a Date or not
  */
 utils.isDate = function(d) {
-    return Object.prototype.toString.call(d) == '[object Date]';
+    return utils.typeName(d) == 'Date';
 };
 
 /**