~bjornt/lazr-js/prefetch-yui-3.5

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/dump/dump-debug.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-01-14 23:32:29 UTC
  • mfrom: (197.1.7 yui-3.3.0)
  • Revision ID: launchpad@pqm.canonical.com-20110114233229-r6i4cazdiiw18o7p
Upgrade to YUI 3.3.0 [r=mars]

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
5
 
version: 3.2.0
6
 
build: 2676
 
5
version: 3.3.0
 
6
build: 3167
7
7
*/
8
8
YUI.add('dump', function(Y) {
9
9
 
18
18
 * @module dump
19
19
 */
20
20
 
21
 
    var L=Y.Lang, OBJ='{...}', FUN='f(){...}', COMMA=', ', ARROW=' => ',
 
21
    var L = Y.Lang,
 
22
        OBJ = '{...}',
 
23
        FUN = 'f(){...}',
 
24
        COMMA = ', ',
 
25
        ARROW = ' => ',
22
26
 
23
27
    /**
24
28
     * The following methods are added to the YUI instance
31
35
     * are expected to be indexed.  Use object notation for
32
36
     * associative arrays.
33
37
     *
34
 
     * @TODO dumping a window is causing an unhandled exception in
35
 
     * FireFox.
36
 
     *
37
38
     * This method is in the 'dump' module, which is not bundled with
38
39
     * the core YUI object
39
40
     *
40
41
     * @method dump
41
 
     * @param o {object} The object to dump
42
 
     * @param d {int} How deep to recurse child objects, default 3
43
 
     * @return {string} the dump result
 
42
     * @param {object} o The object to dump.
 
43
     * @param {int} d How deep to recurse child objects, default 3.
 
44
     * @return {string} the dump result.
44
45
     */
45
46
    dump = function(o, d) {
46
47
        var i, len, s = [], type = L.type(o);
47
48
 
48
49
        // Cast non-objects to string
49
50
        // Skip dates because the std toString is what we want
50
 
        // Skip HTMLElement-like objects because trying to dump 
 
51
        // Skip HTMLElement-like objects because trying to dump
51
52
        // an element will cause an unhandled exception in FF 2.x
52
53
        if (!L.isObject(o)) {
53
 
            return o + "";
54
 
        } else if (type == "date") {
 
54
            return o + '';
 
55
        } else if (type == 'date') {
55
56
            return o;
56
57
        } else if (o.nodeType && o.tagName) {
57
58
            return o.tagName + '#' + o.id;
59
60
            return 'window';
60
61
        } else if (o.location && o.body) {
61
62
            return 'document';
62
 
        } else if (type == "function") {
 
63
        } else if (type == 'function') {
63
64
            return FUN;
64
65
        }
65
66
 
67
68
        d = (L.isNumber(d)) ? d : 3;
68
69
 
69
70
        // arrays [1, 2, 3]
70
 
        if (type == "array") {
71
 
            s.push("[");
72
 
            for (i=0,len=o.length;i<len;i=i+1) {
 
71
        if (type == 'array') {
 
72
            s.push('[');
 
73
            for (i = 0, len = o.length; i < len; i = i + 1) {
73
74
                if (L.isObject(o[i])) {
74
 
                    s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
 
75
                    s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
75
76
                } else {
76
77
                    s.push(o[i]);
77
78
                }
80
81
            if (s.length > 1) {
81
82
                s.pop();
82
83
            }
83
 
            s.push("]");
 
84
            s.push(']');
84
85
        // regexp /foo/
85
 
        } else if (type == "regexp") {
 
86
        } else if (type == 'regexp') {
86
87
            s.push(o.toString());
87
88
        // objects {k1 => v1, k2 => v2}
88
89
        } else {
89
 
            s.push("{");
 
90
            s.push('{');
90
91
            for (i in o) {
91
92
                if (o.hasOwnProperty(i)) {
92
93
                    try {
93
94
                        s.push(i + ARROW);
94
95
                        if (L.isObject(o[i])) {
95
 
                            s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
 
96
                            s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
96
97
                        } else {
97
98
                            s.push(o[i]);
98
99
                        }
99
100
                        s.push(COMMA);
100
 
                    } catch(e) {
 
101
                    } catch (e) {
101
102
                        s.push('Error: ' + e.message);
102
103
                    }
103
104
                }
105
106
            if (s.length > 1) {
106
107
                s.pop();
107
108
            }
108
 
            s.push("}");
 
109
            s.push('}');
109
110
        }
110
111
 
111
 
        return s.join("");
 
112
        return s.join('');
112
113
    };
113
114
 
114
115
    Y.dump = dump;
116
117
 
117
118
 
118
119
 
119
 
}, '3.2.0' );
 
120
}, '3.3.0' );