ADD oubli de certain fichier en rapport avec la page "about"
[euphorik.git] / js / debug.js
diff --git a/js/debug.js b/js/debug.js
new file mode 100644 (file)
index 0000000..a644d27
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+  * Affiche un objet quelconque sur la sortie du navigateur.
+  */
+var dumpObj = function(obj, name)
+{
+   if (typeof(dump) == "undefined")
+      return
+   
+   dump("---" + (name == undefined ? "" : " : " + name) + "\n")
+   dump(obj2text(obj))
+   dump("\n---\n")
+}
+
+var obj2text = function(obj, curDepth)
+{
+   if (curDepth == undefined)
+      curDepth = 0;
+   
+   var acc = ""
+
+   if (obj == undefined)
+   {
+      acc += "<undefined>"
+   }
+   else if (typeof(obj) == "string")
+   {
+      acc += "\"" + obj + "\""
+   }
+   else if (obj.length != undefined) // array
+   {
+      acc += "["
+      
+      var i = 0
+      for (; i < obj.length; i++)
+      {
+         if (i != 0) acc += ","
+         acc += "\n" + indent(curDepth + 1, obj2text(obj[i], curDepth + 1))
+      }
+      
+      acc += (i == 0 ? "]" : "\n" + indent(curDepth, "]"))
+   }
+   else if (typeof(obj) == "object")
+   {
+      acc += "{"
+      var i = 0
+      for (prop in obj)
+      {
+         if (i != 0) acc += ","
+         acc += "\n" + indent(curDepth + 1, prop + " : " + obj2text(obj[prop], curDepth + 1))
+         i += 1
+      }
+      acc += "\n" + indent(curDepth, "}")
+   }
+   else if (typeof(obj) == "function")
+   {
+      acc += "<function>"
+   }
+   else // value
+   {
+      acc += obj
+   }
+   
+   return acc
+}
+
+var indent = function(depth, text)
+{
+   var indentText = ""
+   for (var i = 0; i < depth * 3; i++)
+      indentText += " "
+   return indentText + text
+}