From 0add2d07e6a5a1445a5a677c3b64f046f0810738 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Wed, 6 Jul 2011 07:39:49 +0000 Subject: [PATCH] Move Zotero.varDump to Zotero.Utilities --- chrome/content/zotero/xpcom/db.js | 2 +- chrome/content/zotero/xpcom/debug.js | 2 +- chrome/content/zotero/xpcom/utilities.js | 48 +++++++++++++++++++++++- chrome/content/zotero/xpcom/zotero.js | 46 ----------------------- 4 files changed, 48 insertions(+), 50 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index 625a0aede..845bef524 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -345,7 +345,7 @@ Zotero.DBConnection.prototype.getStatement = function (sql, params, checkParams) } else { var msg = 'Invalid bound parameter ' + params[i] - + ' in ' + Zotero.varDump(params) + + ' in ' + Zotero.Utilities.varDump(params) + ' [QUERY: ' + sql + ']'; Zotero.debug(msg); throw(msg); diff --git a/chrome/content/zotero/xpcom/debug.js b/chrome/content/zotero/xpcom/debug.js index 0b488cd97..845087933 100644 --- a/chrome/content/zotero/xpcom/debug.js +++ b/chrome/content/zotero/xpcom/debug.js @@ -52,7 +52,7 @@ Zotero.Debug = new function () { } if (typeof message != 'string') { - message = Zotero.varDump(message); + message = Zotero.Utilities.varDump(message); } if (!level) { diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 3b5b8da5d..e81ddc024 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -737,8 +737,8 @@ Zotero.Utilities = { }, /** - * Generate a random string of length 'len' (defaults to 8) - **/ + * Generate a random string of length 'len' (defaults to 8) + **/ "randomString":function(len, chars) { if (!chars) { chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; @@ -752,6 +752,50 @@ Zotero.Utilities = { randomstring += chars.substring(rnum,rnum+1); } return randomstring; + }, + + /** + * PHP var_dump equivalent for JS + * + * Adapted from http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html + */ + "varDump":function(arr,level) { + var dumped_text = ""; + if (!level){ + level = 0; + } + + // The padding given at the beginning of the line. + var level_padding = ""; + for (var j=0;j function(...){...} \n"; + } + else if (typeof value == 'number') { + dumped_text += level_padding + "'" + item + "' => " + value + "\n"; + } + else { + dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; + } + } + } + } + else { // Stings/Chars/Numbers etc. + dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; + } + return dumped_text; } } diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index efe91531b..1a4f7bace 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -73,7 +73,6 @@ if(appInfo.platformVersion[0] >= 2) { this.logError = logError; this.getErrors = getErrors; this.getSystemInfo = getSystemInfo; - this.varDump = varDump; this.safeDebug = safeDebug; this.getString = getString; this.localeJoin = localeJoin; @@ -1284,51 +1283,6 @@ if(appInfo.platformVersion[0] >= 2) { } - /** - * PHP var_dump equivalent for JS - * - * Adapted from http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html - */ - function varDump(arr,level) { - var dumped_text = ""; - if (!level){ - level = 0; - } - - // The padding given at the beginning of the line. - var level_padding = ""; - for (var j=0;j function(...){...} \n"; - } - else if (typeof value == 'number') { - dumped_text += level_padding + "'" + item + "' => " + value + "\n"; - } - else { - dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; - } - } - } - } - else { // Stings/Chars/Numbers etc. - dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; - } - return dumped_text; - } - - function safeDebug(obj){ for (var i in obj){ try {