diff options
Diffstat (limited to 'node_modules/montage/require')
-rwxr-xr-x | node_modules/montage/require/browser.js | 90 | ||||
-rw-r--r-- | node_modules/montage/require/node.js | 49 | ||||
-rwxr-xr-x | node_modules/montage/require/require.js | 205 |
3 files changed, 206 insertions, 138 deletions
diff --git a/node_modules/montage/require/browser.js b/node_modules/montage/require/browser.js index 3fdd58d4..f4a11d97 100755 --- a/node_modules/montage/require/browser.js +++ b/node_modules/montage/require/browser.js | |||
@@ -47,7 +47,9 @@ Require.read = function (url) { | |||
47 | 47 | ||
48 | try { | 48 | try { |
49 | request.open(GET, url, true); | 49 | request.open(GET, url, true); |
50 | request.overrideMimeType(APPLICATION_JAVASCRIPT_MIMETYPE); | 50 | if (request.overrideMimeType) { |
51 | request.overrideMimeType(APPLICATION_JAVASCRIPT_MIMETYPE); | ||
52 | } | ||
51 | request.onreadystatechange = function () { | 53 | request.onreadystatechange = function () { |
52 | if (request.readyState === 4) { | 54 | if (request.readyState === 4) { |
53 | onload(); | 55 | onload(); |
@@ -76,7 +78,7 @@ var globalEval = /*this.execScript ||*/eval; | |||
76 | // For Firebug evaled code isn't debuggable otherwise | 78 | // For Firebug evaled code isn't debuggable otherwise |
77 | // http://code.google.com/p/fbug/issues/detail?id=2198 | 79 | // http://code.google.com/p/fbug/issues/detail?id=2198 |
78 | if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) { | 80 | if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) { |
79 | globalEval = new Function("evalString", "return eval(evalString)"); | 81 | globalEval = new Function("_", "return eval(_)"); |
80 | } | 82 | } |
81 | 83 | ||
82 | var __FILE__String = "__FILE__", | 84 | var __FILE__String = "__FILE__", |
@@ -89,6 +91,8 @@ Require.Compiler = function (config) { | |||
89 | return function(module) { | 91 | return function(module) { |
90 | if (module.factory || module.text === void 0) | 92 | if (module.factory || module.text === void 0) |
91 | return module; | 93 | return module; |
94 | if (config.define) | ||
95 | throw new Error("Can't use eval."); | ||
92 | 96 | ||
93 | // Here we use a couple tricks to make debugging better in various browsers: | 97 | // Here we use a couple tricks to make debugging better in various browsers: |
94 | // TODO: determine if these are all necessary / the best options | 98 | // TODO: determine if these are all necessary / the best options |
@@ -117,4 +121,86 @@ Require.Compiler = function (config) { | |||
117 | } | 121 | } |
118 | }; | 122 | }; |
119 | 123 | ||
124 | Require.XhrLoader = function (config) { | ||
125 | return function (url, module) { | ||
126 | return Require.read(url) | ||
127 | .then(function (text) { | ||
128 | module.type = "javascript"; | ||
129 | module.text = text; | ||
130 | module.location = url; | ||
131 | }); | ||
132 | }; | ||
133 | }; | ||
134 | |||
135 | var definitions = {}; | ||
136 | var getDefinition = function (hash, id) { | ||
137 | definitions[hash] = definitions[hash] || {}; | ||
138 | definitions[hash][id] = definitions[hash][id] || Promise.defer(); | ||
139 | return definitions[hash][id]; | ||
140 | }; | ||
141 | define = function (hash, id, module) { | ||
142 | getDefinition(hash, id).resolve(module); | ||
143 | }; | ||
144 | |||
145 | Require.ScriptLoader = function (config) { | ||
146 | var hash = config.packageDescription.hash; | ||
147 | return function (location, module) { | ||
148 | return Promise.call(function () { | ||
149 | |||
150 | // short-cut by predefinition | ||
151 | if (definitions[hash] && definitions[hash][module.id]) { | ||
152 | return definitions[hash][module.id].promise; | ||
153 | } | ||
154 | |||
155 | if (/\.js$/.test(location)) { | ||
156 | location = location.replace(/\.js/, ".load.js"); | ||
157 | } else { | ||
158 | location += ".load.js"; | ||
159 | } | ||
160 | |||
161 | var script = document.createElement("script"); | ||
162 | script.onload = function() { | ||
163 | script.parentNode.removeChild(script); | ||
164 | }; | ||
165 | script.onerror = function (error) { | ||
166 | script.parentNode.removeChild(script); | ||
167 | }; | ||
168 | script.src = location; | ||
169 | script.defer = true; | ||
170 | document.getElementsByTagName("head")[0].appendChild(script); | ||
171 | |||
172 | return getDefinition(hash, module.id).promise | ||
173 | }) | ||
174 | .then(function (definition) { | ||
175 | delete definitions[hash][module.id]; | ||
176 | for (var name in definition) { | ||
177 | module[name] = definition[name]; | ||
178 | } | ||
179 | module.location = location; | ||
180 | module.directory = URL.resolve(location, "."); | ||
181 | }); | ||
182 | }; | ||
183 | }; | ||
184 | |||
185 | Require.makeLoader = function (config) { | ||
186 | if (config.define) { | ||
187 | Loader = Require.ScriptLoader; | ||
188 | } else { | ||
189 | Loader = Require.XhrLoader; | ||
190 | } | ||
191 | return Require.MappingsLoader( | ||
192 | config, | ||
193 | Require.ExtensionsLoader( | ||
194 | config, | ||
195 | Require.PathsLoader( | ||
196 | config, | ||
197 | Require.MemoizedLoader( | ||
198 | config, | ||
199 | Loader(config) | ||
200 | ) | ||
201 | ) | ||
202 | ) | ||
203 | ); | ||
204 | }; | ||
205 | |||
120 | }); | 206 | }); |
diff --git a/node_modules/montage/require/node.js b/node_modules/montage/require/node.js index 9fcea3f5..3ba5a322 100644 --- a/node_modules/montage/require/node.js +++ b/node_modules/montage/require/node.js | |||
@@ -40,10 +40,13 @@ Require.Compiler = function (config) { | |||
40 | var names = ["require", "exports", "module"]; | 40 | var names = ["require", "exports", "module"]; |
41 | var scopeNames = Object.keys(config.scope); | 41 | var scopeNames = Object.keys(config.scope); |
42 | names.push.apply(names, scopeNames); | 42 | names.push.apply(names, scopeNames); |
43 | return function(module) { | 43 | return function (module) { |
44 | if (module.factory) | 44 | if (module.factory) { |
45 | return module; | 45 | return module; |
46 | if (!module.factory && module.text !== void 0) { | 46 | } else if ( |
47 | module.text !== void 0 && | ||
48 | module.type === "javascript" | ||
49 | ) { | ||
47 | var factory = globalEval( | 50 | var factory = globalEval( |
48 | "(function(" + names.join(",") + "){" + | 51 | "(function(" + names.join(",") + "){" + |
49 | module.text + | 52 | module.text + |
@@ -59,18 +62,41 @@ Require.Compiler = function (config) { | |||
59 | // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope | 62 | // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope |
60 | //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path); | 63 | //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path); |
61 | } | 64 | } |
62 | return module; | ||
63 | }; | 65 | }; |
64 | }; | 66 | }; |
65 | 67 | ||
66 | Require.DefaultLoaderConstructor = function(config) { | 68 | Require.Loader = function (config, load) { |
69 | return function (url, module) { | ||
70 | return Require.read(url) | ||
71 | .then(function (text) { | ||
72 | module.type = "javascript"; | ||
73 | module.text = text; | ||
74 | module.location = url; | ||
75 | }, function (reason, error, rejection) { | ||
76 | return load(url, module); | ||
77 | }); | ||
78 | }; | ||
79 | }; | ||
80 | |||
81 | Require.NodeLoader = function (config) { | ||
82 | return function (url, module) { | ||
83 | var id = url.slice(config.location.length); | ||
84 | return { | ||
85 | type: "native", | ||
86 | exports: require(id), | ||
87 | location: url | ||
88 | } | ||
89 | }; | ||
90 | }; | ||
91 | |||
92 | Require.makeLoader = function(config) { | ||
67 | return Require.MappingsLoader( | 93 | return Require.MappingsLoader( |
68 | config, | 94 | config, |
69 | Require.ExtensionsLoader( | 95 | Require.ExtensionsLoader( |
70 | config, | 96 | config, |
71 | Require.PathsLoader( | 97 | Require.PathsLoader( |
72 | config, | 98 | config, |
73 | Require.CachingLoader( | 99 | Require.MemoizedLoader( |
74 | config, | 100 | config, |
75 | Require.Loader( | 101 | Require.Loader( |
76 | config, | 102 | config, |
@@ -82,17 +108,6 @@ Require.DefaultLoaderConstructor = function(config) { | |||
82 | ); | 108 | ); |
83 | }; | 109 | }; |
84 | 110 | ||
85 | Require.NodeLoader = function (config) { | ||
86 | return function (url, module) { | ||
87 | var id = url.slice(config.location.length); | ||
88 | return { | ||
89 | type: "native", | ||
90 | exports: require(id), | ||
91 | location: url | ||
92 | } | ||
93 | }; | ||
94 | } | ||
95 | |||
96 | Require.main = function () { | 111 | Require.main = function () { |
97 | var require = Require.Sandbox(); | 112 | var require = Require.Sandbox(); |
98 | require.async(process.argv[2]).end(); | 113 | require.async(process.argv[2]).end(); |
diff --git a/node_modules/montage/require/require.js b/node_modules/montage/require/require.js index 8273b660..aad6cef7 100755 --- a/node_modules/montage/require/require.js +++ b/node_modules/montage/require/require.js | |||
@@ -33,45 +33,46 @@ | |||
33 | if (!this) | 33 | if (!this) |
34 | throw new Error("Require does not work in strict mode."); | 34 | throw new Error("Require does not work in strict mode."); |
35 | 35 | ||
36 | var global = this; | ||
37 | var globalEval = eval; // reassigning causes eval to not use lexical scope. | 36 | var globalEval = eval; // reassigning causes eval to not use lexical scope. |
38 | 37 | ||
39 | // Non-CommonJS speced extensions should be marked with an "// EXTENSION" comment. | 38 | // Non-CommonJS speced extensions should be marked with an "// EXTENSION" comment. |