Move Zotero.varDump to Zotero.Utilities

This commit is contained in:
Simon Kornblith 2011-07-06 07:39:49 +00:00
parent c8d5e0b8c6
commit 0add2d07e6
4 changed files with 48 additions and 50 deletions

View file

@ -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);

View file

@ -52,7 +52,7 @@ Zotero.Debug = new function () {
}
if (typeof message != 'string') {
message = Zotero.varDump(message);
message = Zotero.Utilities.varDump(message);
}
if (!level) {

View file

@ -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<level+1;j++){
level_padding += " ";
}
if (typeof(arr) == 'object') { // Array/Hashes/Objects
for (var item in arr) {
var value = arr[item];
if (typeof(value) == 'object') { // If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += arguments.callee(value,level+1);
}
else {
if (typeof value == 'function'){
dumped_text += level_padding + "'" + item + "' => 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;
}
}

View file

@ -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<level+1;j++){
level_padding += " ";
}
if (typeof(arr) == 'object') { // Array/Hashes/Objects
for (var item in arr) {
var value = arr[item];
if (typeof(value) == 'object') { // If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += arguments.callee(value,level+1);
}
else {
if (typeof value == 'function'){
dumped_text += level_padding + "'" + item + "' => 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 {