aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-user/require
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage-user/require')
-rwxr-xr-xnode_modules/montage-user/require/browser.js112
-rw-r--r--node_modules/montage-user/require/node.js101
-rwxr-xr-xnode_modules/montage-user/require/require.js698
3 files changed, 0 insertions, 911 deletions
diff --git a/node_modules/montage-user/require/browser.js b/node_modules/montage-user/require/browser.js
deleted file mode 100755
index e249d355..00000000
--- a/node_modules/montage-user/require/browser.js
+++ /dev/null
@@ -1,112 +0,0 @@
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> */
6bootstrap("require/browser", function (require) {
7
8var Require = require("require/require");
9var Promise = require("core/promise").Promise;
10var URL = require("core/mini-url");
11
12var global = typeof global !== "undefined" ? global : window;
13
14Require.getLocation = function() {
15 return URL.resolve(window.location, ".");
16};
17
18Require.overlays = ["browser", "montage"];
19
20// Due to crazy variabile availability of new and old XHR APIs across
21// platforms, this implementation registers every known name for the event
22// listeners. The promise library ascertains that the returned promise
23// is resolved only by the first event.
24// http://dl.dropbox.com/u/131998/yui/misc/get/browser-capabilities.html
25Require.read = function (url) {
26
27 if (URL.resolve(window.location, url).indexOf("file:") === 0) {
28 throw new Error("XHR does not function for file: protocol");
29 }
30
31 var request = new XMLHttpRequest();
32 var response = Promise.defer();
33
34 function onload() {
35 if (xhrSuccess(request)) {
36 response.resolve(request.responseText);
37 } else {
38 onerror();
39 }
40 }
41
42 function onerror() {
43 response.reject("Can't XHR " + JSON.stringify(url));
44 }
45
46 try {
47 request.open("GET", url, true);
48 request.overrideMimeType("application/javascript");
49 request.onreadystatechange = function () {
50 if (request.readyState === 4) {
51 onload();
52 }
53 };
54 request.onload = request.load = onload;
55 request.onerror = request.error = onerror;
56 } catch (exception) {
57 response.reject(exception.message, exception);
58 }
59
60 request.send();
61 return response.promise;
62};
63
64// Determine if an XMLHttpRequest was successful
65// Some versions of WebKit return 0 for successful file:// URLs
66function xhrSuccess(req) {
67 return (req.status === 200 || (req.status === 0 && req.responseText));
68}
69
70// By using a named "eval" most browsers will execute in the global scope.
71// http://www.davidflanagan.com/2010/12/global-eval-in.html
72// Unfortunately execScript doesn't always return the value of the evaluated expression (at least in Chrome)
73var globalEval = /*this.execScript ||*/eval;
74// For Firebug evaled code isn't debuggable otherwise
75// http://code.google.com/p/fbug/issues/detail?id=2198
76if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) {
77 globalEval = new Function("evalString", "return eval(evalString)");
78}
79
80Require.Compiler = function (config) {
81 return function(module) {
82 if (module.factory || module.text === void 0)
83 return module;
84
85 // Here we use a couple tricks to make debugging better in various browsers:
86 // TODO: determine if these are all necessary / the best options
87 // 1. name the function with something inteligible since some debuggers display the first part of each eval (Firebug)
88 // 2. append the "//@ sourceURL=location" hack (Safari, Chrome, Firebug)
89 // * http://pmuellr.blogspot.com/2009/06/debugger-friendly.html
90 // * http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/
91 // TODO: investigate why this isn't working in Firebug.
92 // 3. set displayName property on the factory function (Safari, Chrome)
93
94 var displayName = "__FILE__"+module.location.replace(/\.\w+$|\W/g, "__");
95
96 try {
97 module.factory = globalEval("(function "+displayName+"(require, exports, module) {"+module.text+"//*/\n})"+"\n//@ sourceURL="+module.location);
98 } catch (exception) {
99 throw new SyntaxError("in " + module.location + ": " + exception.message);
100 }
101
102 // This should work and would be simpler, but Firebug does not show scripts executed via "new Function()" constructor.
103 // TODO: sniff browser?
104 // module.factory = new Function("require", "exports", "module", module.text + "\n//*/"+sourceURLComment);
105
106 module.factory.displayName = displayName;
107
108 return module;
109 }
110};
111
112});
diff --git a/node_modules/montage-user/require/node.js b/node_modules/montage-user/require/node.js
deleted file mode 100644
index 568410cf..00000000
--- a/node_modules/montage-user/require/node.js
+++ /dev/null
@@ -1,101 +0,0 @@
1
2var Require = require("./require");
3var URL = require("../core/url");
4var Promise = require("../core/promise").Promise;
5var FS = require("fs");
6
7var globalEval = eval;
8
9Require.getLocation = function () {
10 return URL.resolve("file:///", process.cwd() + "/");
11};
12
13var urlToPath = function (url) {
14 var parsed = URL.parse(url);
15 return parsed.path;
16};
17
18Require.read = function (url) {
19 var deferred = Promise.defer();
20 var path = urlToPath(url);
21 FS.readFile(path, "utf-8", function (error, text) {
22 if (error) {
23 deferred.reject(new Error(error));
24 } else {
25 deferred.resolve(text);
26 }
27 });
28 return deferred.promise;
29};
30
31// Compiles module text into a function.
32// Can be overriden by the platform to make the engine aware of the source path. Uses sourceURL hack by default.
33Require.Compiler = function (config) {
34 config.scope = config.scope || {};
35 var names = ["require", "exports", "module"];
36 var scopeNames = Object.keys(config.scope);
37 names.push.apply(names, scopeNames);
38 return function(module) {
39 if (module.factory)
40 return module;
41 if (!module.factory && module.text !== void 0) {
42 var factory = globalEval(
43 "(function(" + names.join(",") + "){" +
44 module.text +
45 "\n//*/\n})\n//@ sourceURL=" + module.location
46 );
47 module.factory = function (require, exports, module) {
48 Array.prototype.push.apply(arguments, scopeNames.map(function (name) {
49 return config.scope[name];
50 }));
51 return factory.apply(this, arguments);
52 };
53 // new Function will have its body reevaluated at every call, hence using eval instead
54 // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope
55 //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path);
56 }
57 return module;
58 };
59};
60
61Require.DefaultLoaderConstructor = function(config) {
62 return Require.MappingsLoader(
63 config,
64 Require.ExtensionsLoader(
65 config,
66 Require.PathsLoader(
67 config,
68 Require.CachingLoader(
69 config,
70 Require.Loader(
71 config,
72 Require.NodeLoader(config)
73 )
74 )
75 )
76 )
77 );
78};
79
80Require.NodeLoader = function (config) {
81 return function (url, module) {
82 var id = url.slice(config.location.length);
83 return {
84 type: "native",
85 exports: require(id),
86 location: url
87 }
88 };
89}
90
91Require.main = function () {
92 var require = Require.Sandbox();
93 require.async(process.argv[2]).end();
94};
95
96Require.overlays = ["node", "server", "montage"];
97
98if (require.main === module) {
99 Require.main();
100}
101
diff --git a/node_modules/montage-user/require/require.js b/node_modules/montage-user/require/require.js
deleted file mode 100755
index 8273b660..00000000
--- a/node_modules/montage-user/require/require.js
+++ /dev/null
@@ -1,698 +0,0 @@
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