diff options
Diffstat (limited to 'node_modules/montage-user/require/require.js')
-rwxr-xr-x | node_modules/montage-user/require/require.js | 698 |
1 files changed, 698 insertions, 0 deletions
diff --git a/node_modules/montage-user/require/require.js b/node_modules/montage-user/require/require.js new file mode 100755 index 00000000..8273b660 --- /dev/null +++ b/node_modules/montage-user/require/require.js | |||
@@ -0,0 +1,698 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | (function (definition) { | ||
8 | |||
9 | // Boostrapping Browser | ||
10 | if (typeof bootstrap !== "undefined") { | ||
11 | bootstrap("require/require", function (require, exports) { | ||
12 | var Promise = require("core/promise").Promise; | ||
13 | var URL = require("core/mini-url"); | ||
14 | definition(exports, Promise, URL); | ||
15 | require("require/browser"); | ||
16 | }); | ||
17 | |||
18 | // Node Server | ||
19 | } else if (typeof process !== "undefined") { | ||
20 | var Promise = (require)("../core/promise").Promise; | ||
21 | var URL = (require)("../core/url"); | ||
22 | definition(exports, Promise, URL); | ||
23 | require("./node"); | ||
24 | if (require.main == module) | ||
25 | exports.main(); | ||
26 | |||
27 | } else { | ||
28 | throw new Error("Can't support require on this platform"); | ||
29 | } | ||
30 | |||
31 | })(function (Require, Promise, URL) { | ||
32 | |||
33 | if (!this) | ||
34 | throw new Error("Require does not work in strict mode."); | ||
35 | |||
36 | var global = this; | ||
37 | var globalEval = eval; // reassigning causes eval to not use lexical scope. | ||
38 | |||
39 | // Non-CommonJS speced extensions should be marked with an "// EXTENSION" comment. | ||
40 | |||
41 | // Sandbox is an instance of the loader system. Different sandboxes will have different instances of modules. | ||
42 | // Returns the root "require" function. If this root "require()" function is called the loader will be in synchronous mode. | ||
43 | // To get asynchronous loading you MUST call the root "require.async()". In async mode all subsequent calls to "require()" will | ||
44 | // be asynchronously loaded, and synchronously executed. | ||
45 | Require.Sandbox = function(config) { | ||
46 | // Configuration defaults: | ||
47 | config = config || {}; | ||
48 | config.location = URL.resolve(config.location || Require.getLocation(), "."); | ||
49 | config.lib = URL.resolve(config.location, config.lib || "."); | ||
50 | config.paths = config.paths || [config.lib]; | ||
51 | config.mappings = config.mappings || {}; // EXTENSION | ||
52 | config.exposedConfigs = config.exposedConfigs || Require.defaultExposedConfigs; | ||
53 | config.makeLoader = config.makeLoader || Require.DefaultLoaderConstructor; | ||
54 | config.load = config.load || config.makeLoader(config); | ||
55 | config.makeCompiler = config.makeCompiler || Require.DefaultCompilerConstructor; | ||
56 | config.compile = config.compile || config.makeCompiler(config); | ||
57 | |||
58 | // Sandbox state: | ||
59 | // Modules: { exports, id, location, directory, factory, dependencies, dependees, text, type } | ||
60 | var modules = config.modules = config.modules || {}; | ||
61 | // Mapping from canonical IDs to the initial top ID used to load module | ||
62 | var locationsToIds = {}; | ||
63 | |||
64 | function getModule(id) { | ||
65 | if (!has(modules, id)) { | ||
66 | modules[id] = { | ||
67 | id: id, | ||
68 | display: config.location + "#" + id // EXTENSION | ||
69 | }; | ||
70 | } | ||
71 | return modules[id]; | ||
72 | } | ||
73 | config.module = getModule; | ||
74 | |||
75 | function inject(id, exports) { | ||
76 | var module = getModule(id) | ||
77 | module.exports = exports; | ||
78 | module.location = URL.resolve(config.location, id); | ||
79 | module.directory = URL.resolve(module.location, "."); | ||
80 | } | ||
81 | |||
82 | // Ensures a module definition is loaded, compiled, analyzed | ||
83 | var load = memoize(function (topId, viaId) { | ||
84 | var module = getModule(topId); | ||
85 | return Promise.call(function () { | ||
86 | // already loaded, already instantiated, or redirection | ||
87 | if ( | ||
88 | module.factory !== void 0 || | ||
89 | module.exports !== void 0 || | ||
90 | module.redirect !== void 0 | ||
91 | ) { | ||
92 | return module; | ||
93 | // load | ||
94 | } else { | ||
95 | Require.progress.requiredModules.push(module.display); | ||
96 | return Promise.call(config.load, null, topId, module) | ||
97 | .then(function () { | ||
98 | Require.progress.loadedModules.push(module.display); | ||
99 | return module; | ||
100 | }); | ||
101 | } | ||
102 | }) | ||
103 | .then(function (module) { | ||
104 | // analyze dependencies | ||
105 | config.compile(module); | ||
106 | var dependencies = module.dependencies = module.dependencies || []; | ||
107 | if (module.redirect !== void 0) { | ||
108 | dependencies.push(module.redirect); | ||
109 | } | ||
110 | return module; | ||
111 | }); | ||
112 | }); | ||
113 | |||
114 | // Load a module definition, and the definitions of its transitive | ||
115 | // dependencies | ||
116 | function deepLoad(id, viaId, loading) { | ||
117 | // this is a memo of modules already being loaded so we don’t | ||
118 | // data-lock on a cycle of dependencies. | ||
119 | loading = loading || {}; | ||
120 | // has this all happened before? will it happen again? | ||
121 | if (has(loading, id)) | ||
122 | return; // break the cycle of violence. | ||
123 | loading[id] = true; // this has happened before | ||
124 | return load(id, viaId) | ||
125 | .then(function (module) { | ||
126 | // load the transitive dependencies using the magic of | ||
127 | // recursion. | ||
128 | return Promise.all(module.dependencies.map(function (depId) { | ||
129 | depId = resolve(depId, id) | ||
130 | // create dependees set, purely for debug purposes | ||
131 | var module = getModule(depId); | ||
132 | var dependees = module.dependees = module.dependees || {}; | ||
133 | dependees[id] = true; | ||
134 | return deepLoad(depId, id, loading); | ||
135 | })) | ||
136 | .then(function () { | ||
137 | return module; | ||
138 | }) | ||
139 | }) | ||
140 | } | ||
141 | |||
142 | // Initializes a module by executing the factory function with a new module "exports" object. | ||
143 | function getExports(topId, viaId) { | ||
144 | var module = getModule(topId); | ||
145 | |||
146 | // handle redirects | ||
147 | if (module.redirect !== void 0) { | ||
148 | return getExports(module.redirect, viaId); | ||
149 | } | ||
150 | |||
151 | // handle cross-package linkage | ||
152 | if (module.mappingRedirect !== void 0) { | ||
153 | return module.mappingRequire(module.mappingRedirect, viaId); | ||
154 | } | ||
155 | |||
156 | // do not reinitialize modules | ||
157 | if (module.exports !== void 0) { | ||
158 | return module.exports; | ||
159 | } | ||
160 | |||
161 | // do not initialize modules that do not define a factory function | ||
162 | if (module.factory === void 0) { | ||
163 | throw new Error("Can't require module " + JSON.stringify(topId) + " via " + JSON.stringify(viaId)); | ||
164 | } | ||
165 | |||
166 | module.directory = URL.resolve(module.location, "."); // EXTENSION | ||
167 | module.exports = {}; | ||
168 | |||
169 | // Execute the factory function: | ||
170 | var returnValue = module.factory.call( | ||
171 | // in the context of the module: | ||
172 | global, // this | ||
173 | makeRequire(topId), // require | ||
174 | module.exports, // exports | ||
175 | module // module | ||
176 | ); | ||
177 | |||
178 | // Modules should never have a return value. | ||
179 | if (returnValue !== void 0) { | ||
180 | console.warn('require: module "'+topId+'" returned a value.'); | ||
181 | } | ||
182 | |||
183 | // Update the list of modules that are ready to use | ||
184 | Require.progress.initializedModules.push(module.display); | ||
185 | |||
186 | return module.exports; | ||
187 | } | ||
188 | |||
189 | // Finds the internal identifier for a module in a subpackage | ||
190 | // The ``internal`` boolean parameter causes the function to return | ||
191 | // null instead of throwing an exception. I’m guessing that | ||
192 | // throwing exceptions *and* being recursive would be too much | ||
193 | // performance evil for one function. | ||
194 | function identify(id2, require2, internal) { | ||
195 | if (require2.location === config.location) | ||
196 | return id2; | ||
197 | var locations = {}; | ||
198 | for (var name in config.mappings) { | ||
199 | var mapping = config.mappings[name]; | ||
200 | var location = mapping.location; | ||
201 | var candidate = config.getPackage(location); | ||
202 | var id1 = candidate.identify(id2, require2, true); | ||
203 | if (id1 === null) { | ||
204 | continue | ||
205 | } else if (id1 === "") { | ||
206 | return name; | ||
207 | } else { | ||
208 | return name + "/" + id1; | ||
209 | } | ||
210 | } | ||
211 | if (internal) { | ||
212 | return null; | ||
213 | } else { | ||
214 | throw new Error("Can't identify " + id2 + " from " + require2.location); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | // Creates a unique require function for each module that encapsulates that module's id for resolving relative module IDs against. | ||