~ubuntu-branches/ubuntu/precise/maas/precise-security

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/base-core/base-core.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('base-core', function(Y) {
 
8
 
 
9
    /**
 
10
     * The base module provides the Base class, which objects requiring attribute and custom event support can extend. 
 
11
     * The module also provides two ways to reuse code - It augments Base with the Plugin.Host interface which provides 
 
12
     * plugin support and also provides the BaseCore.build method which provides a way to build custom classes using extensions.
 
13
     *
 
14
     * @module base
 
15
     */
 
16
 
 
17
    /**
 
18
     * <p>The base-core module provides the BaseCore class, the lightest version of Base, 
 
19
     * which provides Base's basic lifecycle management and ATTRS construction support, 
 
20
     * but doesn't fire init/destroy or attribute change events.</p> 
 
21
     * 
 
22
     * <p>It mixes in AttributeCore, which is the lightest version of Attribute</p>
 
23
     *
 
24
     * @module base
 
25
     * @submodule base-core
 
26
     */
 
27
    var O = Y.Object,
 
28
        L = Y.Lang,
 
29
        DOT = ".",
 
30
        INITIALIZED = "initialized",
 
31
        DESTROYED = "destroyed",
 
32
        INITIALIZER = "initializer",
 
33
        OBJECT_CONSTRUCTOR = Object.prototype.constructor,
 
34
        DEEP = "deep",
 
35
        SHALLOW = "shallow",
 
36
        DESTRUCTOR = "destructor",
 
37
 
 
38
        AttributeCore = Y.AttributeCore,
 
39
 
 
40
        _wlmix = function(r, s, wlhash) {
 
41
            var p;
 
42
            for (p in s) {
 
43
                if(wlhash[p]) { 
 
44
                    r[p] = s[p];
 
45
                }
 
46
            }
 
47
            return r;
 
48
        };
 
49
 
 
50
    /**
 
51
     * The BaseCore class, is the lightest version of Base, and provides Base's 
 
52
     * basic lifecycle management and ATTRS construction support, but doesn't 
 
53
     * fire init/destroy or attribute change events.
 
54
     *
 
55
     * BaseCore also handles the chaining of initializer and destructor methods across 
 
56
     * the hierarchy as part of object construction and destruction. Additionally, attributes 
 
57
     * configured through the static <a href="#property_BaseCore.ATTRS">ATTRS</a> 
 
58
     * property for each class in the hierarchy will be initialized by BaseCore.
 
59
     *
 
60
     * Classes which require attribute support, but don't intend to use/expose attribute 
 
61
     * change events can extend BaseCore instead of Base for optimal kweight and 
 
62
     * runtime performance.
 
63
     * 
 
64
     * @class BaseCore
 
65
     * @constructor
 
66
     * @uses AttributeCore
 
67
     * @param {Object} cfg Object with configuration property name/value pairs. 
 
68
     * The object can be used to provide initial values for the objects published 
 
69
     * attributes.
 
70
     */
 
71
    function BaseCore(cfg) {
 
72
        if (!this._BaseInvoked) {
 
73
            this._BaseInvoked = true;
 
74
 
 
75
            this._initBase(cfg);
 
76
        }
 
77
    }
 
78
 
 
79
    /**
 
80
     * The list of properties which can be configured for each attribute 
 
81
     * (e.g. setter, getter, writeOnce, readOnly etc.)
 
82
     *
 
83
     * @property _ATTR_CFG
 
84
     * @type Array
 
85
     * @static
 
86
     * @private
 
87
     */
 
88
    BaseCore._ATTR_CFG = AttributeCore._ATTR_CFG.concat("cloneDefaultValue");
 
89
    BaseCore._ATTR_CFG_HASH = Y.Array.hash(BaseCore._ATTR_CFG);
 
90
 
 
91
    /**
 
92
     * The array of non-attribute configuration properties supported by this class. 
 
93
     * 
 
94
     * For example `BaseCore` defines a "plugins" configuration property which 
 
95
     * should not be set up as an attribute. This property is primarily required so 
 
96
     * that when <a href="#property__allowAdHocAttrs">`_allowAdHocAttrs`</a> is enabled by a class, 
 
97
     * non-attribute configuration properties don't get added as ad-hoc attributes.  
 
98
     *
 
99
     * @property _NON_ATTRS_CFG
 
100
     * @type Array
 
101
     * @static
 
102
     * @private
 
103
     */
 
104
    BaseCore._NON_ATTRS_CFG = ["plugins"];
 
105
 
 
106
    /**
 
107
     * This property controls whether or not instances of this class should
 
108
     * allow users to add ad-hoc attributes through the constructor configuration 
 
109
     * hash.
 
110
     *
 
111
     * AdHoc attributes are attributes which are not defined by the class, and are 
 
112
     * not handled by the MyClass._NON_ATTRS_CFG  
 
113
     * 
 
114
     * @property _allowAdHocAttrs
 
115
     * @type boolean
 
116
     * @default undefined (false)
 
117
     * @protected
 
118
     */
 
119
 
 
120
    /**
 
121
     * The string to be used to identify instances of this class.
 
122
     * 
 
123
     * Classes extending BaseCore, should define their own
 
124
     * static NAME property, which should be camelCase by
 
125
     * convention (e.g. MyClass.NAME = "myClass";).
 
126
     *
 
127
     * @property NAME
 
128
     * @type String
 
129
     * @static
 
130
     */
 
131
    BaseCore.NAME = "baseCore";
 
132
 
 
133
    /**
 
134
     * The default set of attributes which will be available for instances of this class, and 
 
135
     * their configuration. In addition to the configuration properties listed by 
 
136
     * AttributeCore's <a href="AttributeCore.html#method_addAttr">addAttr</a> method, 
 
137
     * the attribute can also be configured with a "cloneDefaultValue" property, which 
 
138
     * defines how the statically defined value field should be protected 
 
139
     * ("shallow", "deep" and false are supported values). 
 
140
     *
 
141
     * By default if the value is an object literal or an array it will be "shallow" 
 
142
     * cloned, to protect the default value.
 
143
     *
 
144
     * @property ATTRS
 
145
     * @type Object
 
146
     * @static
 
147
     */
 
148
    BaseCore.ATTRS = {
 
149
        /**
 
150
         * Flag indicating whether or not this object
 
151
         * has been through the init lifecycle phase.
 
152
         *
 
153
         * @attribute initialized
 
154
         * @readonly
 
155
         * @default false
 
156
         * @type boolean
 
157
         */
 
158
        initialized: {
 
159
            readOnly:true,
 
160
            value:false
 
161
        },
 
162
 
 
163
        /**
 
164
         * Flag indicating whether or not this object
 
165
         * has been through the destroy lifecycle phase.
 
166
         *
 
167
         * @attribute destroyed
 
168
         * @readonly
 
169
         * @default false
 
170
         * @type boolean
 
171
         */
 
172
        destroyed: {
 
173
            readOnly:true,
 
174
            value:false
 
175
        }
 
176
    };
 
177
 
 
178
    BaseCore.prototype = {
 
179
 
 
180
        /**
 
181
         * Internal construction logic for BaseCore.
 
182
         *
 
183
         * @method _initBase
 
184
         * @param {Object} config The constructor configuration object
 
185
         * @private
 
186
         */
 
187
        _initBase : function(config) {
 
188
 
 
189
            Y.stamp(this);
 
190
 
 
191
            this._initAttribute(config);
 
192
 
 
193
            // If Plugin.Host has been augmented [ through base-pluginhost ], setup it's
 
194
            // initial state, but don't initialize Plugins yet. That's done after initialization.
 
195
            var PluginHost = Y.Plugin && Y.Plugin.Host;
 
196
            if (this._initPlugins && PluginHost) {
 
197
                PluginHost.call(this);
 
198
            }
 
199
 
 
200
            if (this._lazyAddAttrs !== false) { this._lazyAddAttrs = true; }
 
201
 
 
202
            /**
 
203
             * The string used to identify the class of this object.
 
204
             *
 
205
             * @deprecated Use this.constructor.NAME
 
206
             * @property name
 
207
             * @type String
 
208
             */
 
209
            this.name = this.constructor.NAME;
 
210
    
 
211
            this.init.apply(this, arguments);
 
212
        },
 
213
 
 
214
        /**
 
215
         * Initializes AttributeCore 
 
216
         * 
 
217
         * @method _initAttribute
 
218
         * @private
 
219
         */
 
220
        _initAttribute: function() {
 
221
            AttributeCore.apply(this);
 
222
        },
 
223
 
 
224
        /**
 
225
         * Init lifecycle method, invoked during construction. Sets up attributes 
 
226
         * and invokes initializers for the class hierarchy.
 
227
         *
 
228
         * @method init
 
229
         * @chainable
 
230
         * @param {Object} cfg Object with configuration property name/value pairs
 
231
         * @return {BaseCore} A reference to this object
 
232
         */
 
233
        init: function(cfg) {
 
234
 
 
235
            this._baseInit(cfg);
 
236
 
 
237
            return this;
 
238
        },
 
239
 
 
240
        /**
 
241
         * Internal initialization implementation for BaseCore
 
242
         *
 
243
         * @method _baseInit
 
244
         * @private
 
245
         */
 
246
        _baseInit: function(cfg) {
 
247
            this._initHierarchy(cfg);
 
248
 
 
249
            if (this._initPlugins) {
 
250
                // Need to initPlugins manually, to handle constructor parsing, static Plug parsing
 
251
                this._initPlugins(cfg);
 
252
            }
 
253
            this._set(INITIALIZED, true);
 
254
        },
 
255
 
 
256
        /**
 
257
         * Destroy lifecycle method. Invokes destructors for the class hierarchy.
 
258
         *
 
259
         * @method destroy
 
260
         * @return {BaseCore} A reference to this object
 
261
         * @chainable
 
262
         */
 
263
        destroy: function() {
 
264
            this._baseDestroy();
 
265
            return this;
 
266
        },
 
267
 
 
268
        /**
 
269
         * Internal destroy implementation for BaseCore
 
270
         *
 
271
         * @method _baseDestroy
 
272
         * @private
 
273
         */
 
274
        _baseDestroy : function() {
 
275
            if (this._destroyPlugins) {
 
276
                this._destroyPlugins();
 
277
            }
 
278
            this._destroyHierarchy();
 
279
            this._set(DESTROYED, true);
 
280
        },
 
281
 
 
282
        /**
 
283
         * Returns the class hierarchy for this object, with BaseCore being the last class in the array.
 
284
         *
 
285
         * @method _getClasses
 
286
         * @protected
 
287
         * @return {Function[]} An array of classes (constructor functions), making up the class hierarchy for this object.
 
288
         * This value is cached the first time the method, or _getAttrCfgs, is invoked. Subsequent invocations return the 
 
289
         * cached value.
 
290
         */
 
291
        _getClasses : function() {
 
292
            if (!this._classes) {
 
293
                this._initHierarchyData();
 
294
            }
 
295
            return this._classes;
 
296
        },
 
297
 
 
298
        /**
 
299
         * Returns an aggregated set of attribute configurations, by traversing 
 
300
         * the class hierarchy.
 
301
         *
 
302
         * @method _getAttrCfgs
 
303
         * @protected
 
304
         * @return {Object} The hash of attribute configurations, aggregated across classes in the hierarchy
 
305
         * This value is cached the first time the method, or _getClasses, is invoked. Subsequent invocations return
 
306
         * the cached value.
 
307
         */
 
308
        _getAttrCfgs : function() {
 
309
            if (!this._attrs) {
 
310
                this._initHierarchyData();
 
311
            }
 
312
            return this._attrs;
 
313
        },
 
314
 
 
315
        /**
 
316
         * A helper method used when processing ATTRS across the class hierarchy during 
 
317
         * initialization. Returns a disposable object with the attributes defined for 
 
318
         * the provided class, extracted from the set of all attributes passed in.
 
319
         *
 
320
         * @method _filterAttrCfs
 
321
         * @private
 
322
         *
 
323
         * @param {Function} clazz The class for which the desired attributes are required.
 
324
         * @param {Object} allCfgs The set of all attribute configurations for this instance. 
 
325
         * Attributes will be removed from this set, if they belong to the filtered class, so
 
326
         * that by the time all classes are processed, allCfgs will be empty.
 
327
         * 
 
328
         * @return {Object} The set of attributes belonging to the class passed in, in the form
 
329
         * of an object with attribute name/configuration pairs.
 
330
         */
 
331
        _filterAttrCfgs : function(clazz, allCfgs) {
 
332
            var cfgs = null, attr, attrs = clazz.ATTRS;
 
333
 
 
334
            if (attrs) {
 
335
                for (attr in attrs) {
 
336
                    if (allCfgs[attr]) {
 
337
                        cfgs = cfgs || {};
 
338
                        cfgs[attr] = allCfgs[attr];
 
339
                        allCfgs[attr] = null;
 
340
                    }
 
341
                }
 
342
            }
 
343
 
 
344
            return cfgs;
 
345
        },
 
346
 
 
347
        /**
 
348
         * @method _filterAdHocAttrs
 
349
         * @private
 
350
         *
 
351
         * @param {Object} allAttrs The set of all attribute configurations for this instance. 
 
352
         * Attributes will be removed from this set, if they belong to the filtered class, so
 
353
         * that by the time all classes are processed, allCfgs will be empty.
 
354
         * @param {Object} userVals The config object passed in by the user, from which adhoc attrs are to be filtered.
 
355
         * @return {Object} The set of adhoc attributes passed in, in the form
 
356
         * of an object with attribute name/configuration pairs.
 
357
         */
 
358
        _filterAdHocAttrs : function(allAttrs, userVals) {
 
359
            var adHocs,
 
360
                nonAttrs = this._nonAttrs,
 
361
                attr;
 
362
 
 
363
            if (userVals) {
 
364
                adHocs = {};
 
365
                for (attr in userVals) {
 
366
                    if (!allAttrs[attr] && !nonAttrs[attr] && userVals.hasOwnProperty(attr)) {
 
367
                        adHocs[attr] = {
 
368
                            value:userVals[attr]
 
369
                        };
 
370
                    }
 
371
                }
 
372
            }
 
373
 
 
374
            return adHocs;
 
375
        },
 
376
 
 
377
        /**
 
378
         * A helper method used by _getClasses and _getAttrCfgs, which determines both
 
379
         * the array of classes and aggregate set of attribute configurations
 
380
         * across the class hierarchy for the instance.
 
381
         *
 
382
         * @method _initHierarchyData
 
383
         * @private
 
384
         */
 
385
        _initHierarchyData : function() {
 
386
            var c = this.constructor,
 
387
                i,
 
388
                l,
 
389
                nonAttrsCfg,
 
390
                nonAttrs = (this._allowAdHocAttrs) ? {} : null,
 
391
                classes = [],
 
392
                attrs = [];
 
393
 
 
394
            while (c) {
 
395
                // Add to classes
 
396
                classes[classes.length] = c;
 
397
 
 
398
                // Add to attributes
 
399
                if (c.ATTRS) {
 
400
                    attrs[attrs.length] = c.ATTRS;
 
401
                }
 
402
 
 
403
                if (this._allowAdHocAttrs) {
 
404
                    nonAttrsCfg = c._NON_ATTRS_CFG; 
 
405
                    if (nonAttrsCfg) {
 
406
                        for (i = 0, l = nonAttrsCfg.length; i < l; i++) {
 
407
                            nonAttrs[nonAttrsCfg[i]] = true;
 
408
                        }
 
409
                    }
 
410
                }
 
411
 
 
412
                c = c.superclass ? c.superclass.constructor : null;
 
413
            }
 
414
 
 
415
            this._classes = classes;
 
416
            this._nonAttrs = nonAttrs;
 
417
            this._attrs = this._aggregateAttrs(attrs);
 
418
        },
 
419
 
 
420
        /**
 
421
         * Utility method to define the attribute hash used to filter/whitelist property mixes for 
 
422
         * this class. 
 
423
         * 
 
424
         * @method _attrCfgHash
 
425
         * @private
 
426
         */
 
427
        _attrCfgHash: function() {
 
428
            return BaseCore._ATTR_CFG_HASH;
 
429
        },
 
430
 
 
431
        /**
 
432
         * A helper method, used by _initHierarchyData to aggregate 
 
433
         * attribute configuration across the instances class hierarchy.
 
434
         *
 
435
         * The method will protect the attribute configuration value to protect the statically defined 
 
436
         * default value in ATTRS if required (if the value is an object literal, array or the 
 
437
         * attribute configuration has cloneDefaultValue set to shallow or deep).
 
438
         *
 
439
         * @method _aggregateAttrs
 
440
         * @private
 
441
         * @param {Array} allAttrs An array of ATTRS definitions across classes in the hierarchy 
 
442
         * (subclass first, Base last)
 
443
         * @return {Object} The aggregate set of ATTRS definitions for the instance
 
444
         */
 
445
        _aggregateAttrs : function(allAttrs) {
 
446
            var attr,
 
447
                attrs,
 
448
                cfg,
 
449
                val,
 
450
                path,
 
451
                i,
 
452
                clone,
 
453
                cfgPropsHash = this._attrCfgHash(),
 
454
                aggAttrs = {};
 
455
 
 
456
            if (allAttrs) {
 
457
                for (i = allAttrs.length-1; i >= 0; --i) {
 
458
                    attrs = allAttrs[i];
 
459
 
 
460
                    for (attr in attrs) {
 
461
                        if (attrs.hasOwnProperty(attr)) {
 
462
 
 
463
                            // Protect config passed in
 
464
                            //cfg = Y.mix({}, attrs[attr], true, cfgProps);
 
465
                            //cfg = Y.Object(attrs[attr]);
 
466
                            cfg = _wlmix({}, attrs[attr], cfgPropsHash);
 
467
 
 
468
                            val = cfg.value;
 
469
                            clone = cfg.cloneDefaultValue;
 
470
 
 
471
                            if (val) {
 
472
                                if ( (clone === undefined && (OBJECT_CONSTRUCTOR === val.constructor || L.isArray(val))) || clone === DEEP || clone === true) {
 
473
                                    cfg.value = Y.clone(val);
 
474
                                } else if (clone === SHALLOW) {
 
475
                                    cfg.value = Y.merge(val);
 
476
                                }
 
477
                                // else if (clone === false), don't clone the static default value. 
 
478
                                // It's intended to be used by reference.
 
479
                            }
 
480
 
 
481
                            path = null;
 
482
                            if (attr.indexOf(DOT) !== -1) {
 
483
                                path = attr.split(DOT);
 
484
                                attr = path.shift();
 
485
                            }
 
486
 
 
487
                            if (path && aggAttrs[attr] && aggAttrs[attr].value) {
 
488
                                O.setValue(aggAttrs[attr].value, path, val);
 
489
                            } else if (!path) {
 
490
                                if (!aggAttrs[attr]) {
 
491
                                    aggAttrs[attr] = cfg;
 
492
                                } else {
 
493
                                    _wlmix(aggAttrs[attr], cfg, cfgPropsHash);
 
494
                                }
 
495
                            }
 
496
                        }
 
497
                    }
 
498
                }
 
499
            }
 
500
 
 
501
            return aggAttrs;
 
502
        },
 
503
 
 
504
        /**
 
505
         * Initializes the class hierarchy for the instance, which includes 
 
506
         * initializing attributes for each class defined in the class's 
 
507
         * static <a href="#property_BaseCore.ATTRS">ATTRS</a> property and 
 
508
         * invoking the initializer method on the prototype of each class in the hierarchy.
 
509
         *
 
510
         * @method _initHierarchy
 
511
         * @param {Object} userVals Object with configuration property name/value pairs
 
512
         * @private
 
513
         */
 
514
        _initHierarchy : function(userVals) {
 
515
            var lazy = this._lazyAddAttrs,
 
516
                constr,
 
517
                constrProto,
 
518
                ci,
 
519
                ei,
 
520
                el,
 
521
                extProto,
 
522
                exts,
 
523
                classes = this._getClasses(),
 
524
                attrCfgs = this._getAttrCfgs(),
 
525
                cl = classes.length - 1;
 
526
 
 
527
            for (ci = cl; ci >= 0; ci--) {
 
528
 
 
529
                constr = classes[ci];
 
530
                constrProto = constr.prototype;
 
531
                exts = constr._yuibuild && constr._yuibuild.exts; 
 
532
 
 
533
                if (exts) {
 
534
                    for (ei = 0, el = exts.length; ei < el; ei++) {
 
535
                        exts[ei].apply(this, arguments);
 
536
                    }
 
537
                }
 
538
 
 
539
                this.addAttrs(this._filterAttrCfgs(constr, attrCfgs), userVals, lazy);
 
540
 
 
541
                if (this._allowAdHocAttrs && ci === cl) {                
 
542
                    this.addAttrs(this._filterAdHocAttrs(attrCfgs, userVals), userVals, lazy);
 
543
                }
 
544
 
 
545
                // Using INITIALIZER in hasOwnProperty check, for performance reasons (helps IE6 avoid GC thresholds when
 
546
                // referencing string literals). Not using it in apply, again, for performance "." is faster. 
 
547
                if (constrProto.hasOwnProperty(INITIALIZER)) {
 
548
                    constrProto.initializer.apply(this, arguments);
 
549
                }
 
550
 
 
551
                if (exts) {
 
552
                    for (ei = 0; ei < el; ei++) {
 
553
                        extProto = exts[ei].prototype;
 
554
                        if (extProto.hasOwnProperty(INITIALIZER)) {
 
555
                            extProto.initializer.apply(this, arguments);
 
556
                        }
 
557
                    }
 
558
                }
 
559
            }
 
560
        },
 
561
 
 
562
        /**
 
563
         * Destroys the class hierarchy for this instance by invoking
 
564
         * the destructor method on the prototype of each class in the hierarchy.
 
565
         *
 
566
         * @method _destroyHierarchy
 
567
         * @private
 
568
         */
 
569
        _destroyHierarchy : function() {
 
570
            var constr,
 
571
                constrProto,
 
572
                ci, cl, ei, el, exts, extProto,
 
573
                classes = this._getClasses();
 
574
 
 
575
            for (ci = 0, cl = classes.length; ci < cl; ci++) {
 
576
                constr = classes[ci];
 
577
                constrProto = constr.prototype;
 
578
                exts = constr._yuibuild && constr._yuibuild.exts; 
 
579
 
 
580
                if (exts) {
 
581
                    for (ei = 0, el = exts.length; ei < el; ei++) {
 
582
                        extProto = exts[ei].prototype;
 
583
                        if (extProto.hasOwnProperty(DESTRUCTOR)) {
 
584
                            extProto.destructor.apply(this, arguments);
 
585
                        }
 
586
                    }
 
587
                }
 
588
 
 
589
                if (constrProto.hasOwnProperty(DESTRUCTOR)) {
 
590
                    constrProto.destructor.apply(this, arguments);
 
591
                }
 
592
            }
 
593
        },
 
594
 
 
595
        /**
 
596
         * Default toString implementation. Provides the constructor NAME
 
597
         * and the instance guid, if set.
 
598
         *
 
599
         * @method toString
 
600
         * @return {String} String representation for this object
 
601
         */
 
602
        toString: function() {
 
603
            return this.name + "[" + Y.stamp(this, true) + "]";
 
604
        }
 
605
    };
 
606
 
 
607
    // Straightup augment, no wrapper functions
 
608
    Y.mix(BaseCore, AttributeCore, false, null, 1);
 
609
 
 
610
    // Fix constructor
 
611
    BaseCore.prototype.constructor = BaseCore;
 
612
 
 
613
    Y.BaseCore = BaseCore;
 
614
 
 
615
 
 
616
}, '3.5.1' ,{requires:['attribute-core']});