      1 pockets.DomPrettyPrinter = function() {
      2   jasmine.PrettyPrinter.call(this);
      3   this.dom = pockets.dom.create('div', {className: 'pretty-printed'});
      4   this.currentNode = this.dom;
      5 };
      6 jasmine.util.inherit(pockets.DomPrettyPrinter, jasmine.PrettyPrinter);
      7
      8 pockets.DomPrettyPrinter.prototype.append = function(node) {
      9   this.currentNode.appendChild(node);
     10   return node;
     11 };
     12
     13 pockets.DomPrettyPrinter.prototype.emitScalar = function(value) {
     14   this.append(document.createTextNode(value));
     15 };
     16
     17 pockets.DomPrettyPrinter.prototype.emitArray = function(array) {
     18   var table = this.append(pockets.dom.create('table', {className: 'array'},
     19     pockets.dom.create('tr', {},
     20       pockets.dom.create('th', {colSpan: 2}, 'Array[' + array.length + ']'))));
     21
     22   var prevCurrentNode = this.currentNode;
     23   for (var i = 0; i < array.length; i++) {
     24     var valueTd;
     25     var tr = pockets.dom.create('tr', {},
     26       pockets.dom.create('td', {}, '' + i),
     27       valueTd = pockets.dom.create('td')
     28       );
     29     table.appendChild(tr);
     30     this.currentNode = valueTd;
     31     this.format(array[i]);
     32   }
     33   this.currentNode = prevCurrentNode;
     34 };
     35
     36 pockets.DomPrettyPrinter.prototype.emitObject = function(obj) {
     37   var table = this.append(pockets.dom.create('table', {className: 'object'},
     38     pockets.dom.create('tr', {},
     39       pockets.dom.create('th', {colSpan: 2}, 'Object'))));
     40
     41   var prevCurrentNode = this.currentNode;
     42   this.iterateObject(obj, function(property, isGetter) {
     43     var isOwnProperty = obj.hasOwnProperty(property);
     44     var valueTd;
     45     table.appendChild(pockets.dom.create('tr', {},
     46       pockets.dom.create('td', {className: 'key ' + (isOwnProperty ? 'own' : 'prototype')}, property),
     47       valueTd = pockets.dom.create('td')
     48       ));
     49     if (isGetter) {
     50       valueTd.appendChild(pockets.dom.create('span', {className: 'getter'}, '<getter>'));
     51     } else {
     52       this.currentNode = valueTd;
     53       this.format(obj[property]);
     54     }
     55   }.bind(this));
     56   this.currentNode = prevCurrentNode;
     57 };
     58
     59