~ubuntu-branches/ubuntu/trusty/moodle/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/yui/3.4.1/build/dump/dump.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-07-19 08:52:46 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130719085246-yebwditc2exoap2r
Tags: 2.5.1-1
* New upstream version: 2.5.1.
  - Fixes security issues:
    CVE-2013-2242 CVE-2013-2243 CVE-2013-2244 CVE-2013-2245
    CVE-2013-2246
* Depend on apache2 instead of obsolete apache2-mpm-prefork.
* Use packaged libphp-phpmailer (closes: #429339), adodb,
  HTMLPurifier, PclZip.
* Update debconf translations, thanks Salvatore Merone, Pietro Tollot,
  Joe Hansen, Yuri Kozlov, Holger Wansing, Américo Monteiro,
  Adriano Rafael Gomes, victory, Michał Kułach.
  (closes: #716972, #716986, #717080, #717108, #717278)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('dump', function(Y) {
8
 
 
9
 
/**
10
 
 * Returns a simple string representation of the object or array.
11
 
 * Other types of objects will be returned unprocessed.  Arrays
12
 
 * are expected to be indexed.  Use object notation for
13
 
 * associative arrays.
14
 
 *
15
 
 * If included, the dump method is added to the YUI instance.
16
 
 *
17
 
 * @module dump
18
 
 */
19
 
 
20
 
    var L = Y.Lang,
21
 
        OBJ = '{...}',
22
 
        FUN = 'f(){...}',
23
 
        COMMA = ', ',
24
 
        ARROW = ' => ',
25
 
 
26
 
    /**
27
 
     * Returns a simple string representation of the object or array.
28
 
     * Other types of objects will be returned unprocessed.  Arrays
29
 
     * are expected to be indexed.
30
 
     *
31
 
     * @method dump
32
 
     * @param {Object} o The object to dump.
33
 
     * @param {Number} d How deep to recurse child objects, default 3.
34
 
     * @return {String} the dump result.
35
 
     * @for YUI
36
 
     */
37
 
    dump = function(o, d) {
38
 
        var i, len, s = [], type = L.type(o);
39
 
 
40
 
        // Cast non-objects to string
41
 
        // Skip dates because the std toString is what we want
42
 
        // Skip HTMLElement-like objects because trying to dump
43
 
        // an element will cause an unhandled exception in FF 2.x
44
 
        if (!L.isObject(o)) {
45
 
            return o + '';
46
 
        } else if (type == 'date') {
47
 
            return o;
48
 
        } else if (o.nodeType && o.tagName) {
49
 
            return o.tagName + '#' + o.id;
50
 
        } else if (o.document && o.navigator) {
51
 
            return 'window';
52
 
        } else if (o.location && o.body) {
53
 
            return 'document';
54
 
        } else if (type == 'function') {
55
 
            return FUN;
56
 
        }
57
 
 
58
 
        // dig into child objects the depth specifed. Default 3
59
 
        d = (L.isNumber(d)) ? d : 3;
60
 
 
61
 
        // arrays [1, 2, 3]
62
 
        if (type == 'array') {
63
 
            s.push('[');
64
 
            for (i = 0, len = o.length; i < len; i = i + 1) {
65
 
                if (L.isObject(o[i])) {
66
 
                    s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
67
 
                } else {
68
 
                    s.push(o[i]);
69
 
                }
70
 
                s.push(COMMA);
71
 
            }
72
 
            if (s.length > 1) {
73
 
                s.pop();
74
 
            }
75
 
            s.push(']');
76
 
        // regexp /foo/
77
 
        } else if (type == 'regexp') {
78
 
            s.push(o.toString());
79
 
        // objects {k1 => v1, k2 => v2}
80
 
        } else {
81
 
            s.push('{');
82
 
            for (i in o) {
83
 
                if (o.hasOwnProperty(i)) {
84
 
                    try {
85
 
                        s.push(i + ARROW);
86
 
                        if (L.isObject(o[i])) {
87
 
                            s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
88
 
                        } else {
89
 
                            s.push(o[i]);
90
 
                        }
91
 
                        s.push(COMMA);
92
 
                    } catch (e) {
93
 
                        s.push('Error: ' + e.message);
94
 
                    }
95
 
                }
96
 
            }
97
 
            if (s.length > 1) {
98
 
                s.pop();
99
 
            }
100
 
            s.push('}');
101
 
        }
102
 
 
103
 
        return s.join('');
104
 
    };
105
 
 
106
 
    Y.dump = dump;
107
 
    L.dump = dump;
108
 
 
109
 
 
110
 
 
111
 
}, '3.4.1' ,{requires:['yui-base']});