1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
16 /** Platform, package, object property, and Event support. */
17 this.base
= (function() {
19 function mLog(text
, opt_indentLevel
) {
24 var indentLevel
= opt_indentLevel
|| 0;
25 for (var i
= 0; i
< indentLevel
; i
++)
27 console
.log(spacing
+ text
);
31 * Builds an object structure for the provided namespace path,
32 * ensuring that names that already exist are not overwritten. For
34 * 'a.b.c' -> a = {};a.b={};a.b.c={};
35 * @param {string} name Name of the object that this file defines.
36 * @param {*=} opt_object The object to expose at the end of the path.
37 * @param {Object=} opt_objectToExportTo The object to add the path to;
38 * default is {@code global}.
41 function exportPath(name
, opt_object
, opt_objectToExportTo
) {
42 var parts
= name
.split('.');
43 var cur
= opt_objectToExportTo
|| global
;
45 for (var part
; parts
.length
&& (part
= parts
.shift());) {
46 if (!parts
.length
&& opt_object
!== undefined) {
47 // last part and we have an object; use it
48 cur
[part
] = opt_object
;
49 } else if (part
in cur
) {
58 function exportTo(namespace, fn
) {
59 var obj
= exportPath(namespace);
63 console
.log('While running exports for ', name
, ':');
64 console
.log(e
.stack
|| e
);
68 for (var propertyName
in exports
) {
69 // Maybe we should check the prototype chain here? The current usage
70 // pattern is always using an object literal so we only care about own
72 var propertyDescriptor
= Object
.getOwnPropertyDescriptor(exports
,
74 if (propertyDescriptor
) {
75 Object
.defineProperty(obj
, propertyName
, propertyDescriptor
);
76 mLog(' +' + propertyName
);