      1 pockets.experimental = {};
      2
      3 pockets.experimental.trace = function() {
      4   var callstack = [];
      5   var currentFunction = arguments.callee.caller;
      6   while (currentFunction) {
      7     var fn = currentFunction.toString();
      8     var fname = currentFunction['__name__'] || fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")).replace(/ +/, '') || "anonymous";
      9     callstack.push(fname);
     10     currentFunction = currentFunction.caller;
     11   }
     12   return callstack;
     13 };
     14
     15 pockets.experimental.addNames = function(root, prefix, depth) {
     16   if (depth === undefined) depth = 0;
     17   if (depth > 3) return;
     18
     19   prefix = prefix || '';
     20   for (var property in root) {
     21     var o = root[property];
     22     if (!o || o === window.document || o === window || o.__name__ || o['__beenHereBefore__']) continue;
     23
     24     o['__beenHereBefore__'] = true;
     25     pockets.experimental.addNames(o, prefix + property + '.', depth + 1);
     26     delete o['__beenHereBefore__'];
     27
     28     if (typeof o == 'function') {
     29       o.__name__ = prefix + property;
     30     }
     31   }
     32 };
     33
     34 pockets.experimental.info = function() {
     35   pockets.experimental._log.apply(pockets, ["info"].concat($A(arguments)));
     36 };
     37
     38 pockets.experimental.error = function() {
     39   pockets.experimental._log.apply(pockets, ["error"].concat($A(arguments)));
     40 };
     41
     42 /** crashes the emulator!!!! :( */
     43 pockets.experimental._log = function(level, varargs) {
     44   if (!pockets.inPalmHost() && Mojo.Log[level]) {
     45     var objectsToJsonify = [];
     46     var message = "";
     47     for (var i = 1; i < arguments.length; i++) {
     48       if (i > 1) message += ", ";
     49       if (typeof arguments[i] === "object") {
     50         message += "%j";
     51         objectsToJsonify.push(arguments[i]);
     52       } else {
     53         message += arguments[i];
     54       }
     55     }
     56     Mojo.Log[level].apply(Mojo.Log, [message].concat(objectsToJsonify));
     57   } else if (console && console[level]) {
     58     console[level].apply(console, $A(arguments).slice(1));
     59   }
     60 };
     61