From db0a1919f3198fd4cfda7bcf687bc0dc559c75fd Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 4 Nov 2011 04:08:18 +0800 Subject: [PATCH] Remove PhoneGap.stringify, replace with JSON.stringify Since we don't support Android 1.5/1.6 anymore we don't need to check to see if JSON.stringify is around as it is included in Android 2.1+. By removing this check for JSON.stringify we remove two conditional checks on each call to PhoneGap.exec. As well we get rid of 60 lines of code which are currently bloating phonegap.js.base. --- framework/assets/js/phonegap.js.base | 61 +--------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/framework/assets/js/phonegap.js.base b/framework/assets/js/phonegap.js.base index d9478325..3c1c6c65 100755 --- a/framework/assets/js/phonegap.js.base +++ b/framework/assets/js/phonegap.js.base @@ -547,65 +547,6 @@ PhoneGap.fireWindowEvent = function(type, data) { window.dispatchEvent(e); }; -/** - * If JSON not included, use our own stringify. (Android 1.6) - * The restriction on ours is that it must be an array of simple types. - * - * @param args - * @return {String} - */ -PhoneGap.stringify = function(args) { - if (typeof JSON === "undefined") { - var s = "["; - var i, type, start, name, nameType, a; - for (i = 0; i < args.length; i++) { - if (args[i] !== null) { - if (i > 0) { - s = s + ","; - } - type = typeof args[i]; - if ((type === "number") || (type === "boolean")) { - s = s + args[i]; - } else if (args[i] instanceof Array) { - s = s + "[" + args[i] + "]"; - } else if (args[i] instanceof Object) { - start = true; - s = s + '{'; - for (name in args[i]) { - if (args[i][name] !== null) { - if (!start) { - s = s + ','; - } - s = s + '"' + name + '":'; - nameType = typeof args[i][name]; - if ((nameType === "number") || (nameType === "boolean")) { - s = s + args[i][name]; - } else if ((typeof args[i][name]) === 'function') { - // don't copy the functions - s = s + '""'; - } else if (args[i][name] instanceof Object) { - s = s + PhoneGap.stringify(args[i][name]); - } else { - s = s + '"' + args[i][name] + '"'; - } - start = false; - } - } - s = s + '}'; - } else { - a = args[i].replace(/\\/g, '\\\\'); - a = a.replace(/"/g, '\\"'); - s = s + '"' + a + '"'; - } - } - } - s = s + "]"; - return s; - } else { - return JSON.stringify(args); - } -}; - /** * Does a deep clone of the object. * @@ -684,7 +625,7 @@ PhoneGap.exec = function(success, fail, service, action, args) { PhoneGap.callbacks[callbackId] = {success:success, fail:fail}; } - var r = prompt(PhoneGap.stringify(args), "gap:"+PhoneGap.stringify([service, action, callbackId, true])); + var r = prompt(JSON.stringify(args), "gap:"+JSON.stringify([service, action, callbackId, true])); // If a result was returned if (r.length > 0) {