- add sources.
[platform/framework/web/crosswalk.git] / src / chrome_frame / cfinstall / src / miniclosure / base.js
1 // Copyright (c) 2011 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.
4
5 /**
6  * @fileoverview Implements a shim so that the CFInstall scripts can be compiled
7  * with or without Closure. In particular, chromeframe.js is used by the stub,
8  * the implementation, and the download site, so we need to provide an
9  * implementation of goog.provide.
10  **/
11
12 var goog = {};
13 goog.global = this;
14
15 /**
16  * From closure/base.js:goog.exportPath_ .
17  * @param {string} name
18  * @param {Object=} opt_object
19  */
20 goog.provide = function(name, opt_object) {
21   var parts = name.split('.');
22   var cur = goog.global;
23
24   // Internet Explorer exhibits strange behavior when throwing errors from
25   // methods externed in this manner.  See the testExportSymbolExceptions in
26   // base_test.html for an example.
27   if (!(parts[0] in cur) && cur.execScript)
28     cur.execScript('var ' + parts[0]);
29
30   // Certain browsers cannot parse code in the form for((a in b); c;);
31   // This pattern is produced by the JSCompiler when it collapses the
32   // statement above into the conditional loop below. To prevent this from
33   // happening, use a for-loop and reserve the init logic as below.
34
35   // Parentheses added to eliminate strict JS warning in Firefox.
36   for (var part; parts.length && (part = parts.shift());) {
37     if (!parts.length && opt_object !== undefined) {
38       // last part and we have an object; use it
39       cur[part] = opt_object;
40     } else if (cur[part]) {
41       cur = cur[part];
42     } else {
43       cur = cur[part] = {};
44     }
45   }
46 };
47
48 // The following line causes the closureBuilder script to recognize this as
49 // base.js .
50 goog.provide('goog');
51
52 /**
53  * From closure/base.js:goog.exportPath_ .
54  * @param {string} name
55  * @param {Object=} opt_object
56  */
57 goog.exportSymbol = goog.provide;
58
59 /**
60  * NO-OP
61  * @param {string} name
62  */
63 goog.require = function(name) {};
64
65 /**
66  * A simple form that supports only bound 'this', not arguments.
67  * @param {Function} fn A function to partially apply.
68  * @param {Object|undefined} selfObj Specifies the object which |this| should
69  *     point to when the function is run.
70  * @return {!Function} A partially-applied form of the function bind() was
71  *     invoked as a method of.
72  */
73 goog.bind = function(fn, selfObj) {
74   return function() {
75     return fn.apply(selfObj, arguments);
76   };
77 };