Skip to content

Commit 01ccfb5

Browse files
committed
all tests passing in xpcshell
1 parent 23a9604 commit 01ccfb5

File tree

4 files changed

+235
-77
lines changed

4 files changed

+235
-77
lines changed

build/tests/allxpc.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
../../env/xpcshell/xpcshell ../../r.js all.js

build/tests/lib/moduleThenPlugin/expected.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ require(['sub1'], function (sub1) {});
77
define("main", function(){});
88

99
/**
10-
* @license RequireJS text 2.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
10+
* @license RequireJS text 2.0.5+ Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
1111
* Available via the MIT or new BSD license.
1212
* see: http://github.com/requirejs/text for details
1313
*/
1414
/*jslint regexp: true */
15-
/*global require: false, XMLHttpRequest: false, ActiveXObject: false,
16-
define: false, window: false, process: false, Packages: false,
17-
java: false, location: false */
15+
/*global require, XMLHttpRequest, ActiveXObject,
16+
define, window, process, Packages,
17+
java, location, Components, FileUtils */
1818

1919
define('text',['module'], function (module) {
2020

2121

22-
var text, fs,
22+
var text, fs, Cc, Ci,
2323
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
2424
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
2525
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
@@ -31,7 +31,7 @@ define('text',['module'], function (module) {
3131
masterConfig = (module.config && module.config()) || {};
3232

3333
text = {
34-
version: '2.0.5',
34+
version: '2.0.5+',
3535

3636
strip: function (content) {
3737
//Strips <?xml ...?> declarations so that external SVG and XML
@@ -334,8 +334,39 @@ define('text',['module'], function (module) {
334334
}
335335
callback(content);
336336
};
337-
}
337+
} else if (masterConfig.env === 'xpconnect' || (!masterConfig.env &&
338+
typeof Components !== 'undefined' && Components.classes &&
339+
Components.interfaces)) {
340+
//Avert your gaze!
341+
Cc = Components.classes,
342+
Ci = Components.interfaces;
343+
Components.utils['import']('resource://gre/modules/FileUtils.jsm');
344+
345+
text.get = function (url, callback) {
346+
var inStream, convertStream,
347+
readData = {},
348+
fileObj = new FileUtils.File(url);
338349

350+
//XPCOM, you so crazy
351+
try {
352+
inStream = Cc['@mozilla.org/network/file-input-stream;1']
353+
.createInstance(Ci.nsIFileInputStream);
354+
inStream.init(fileObj, 1, 0, false);
355+
356+
convertStream = Cc['@mozilla.org/intl/converter-input-stream;1']
357+
.createInstance(Ci.nsIConverterInputStream);
358+
convertStream.init(inStream, "utf-8", inStream.available(),
359+
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
360+
361+
convertStream.readString(inStream.available(), readData);
362+
convertStream.close();
363+
inStream.close();
364+
callback(readData.value);
365+
} catch (e) {
366+
throw new Error((fileObj && fileObj.path || '') + ': ' + e);
367+
}
368+
};
369+
}
339370
return text;
340371
});
341372

build/tests/lib/rhino-186/expected.js

Lines changed: 97 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11

22
/**
3-
* @license RequireJS text 2.0.0 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
3+
* @license RequireJS text 2.0.6 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
44
* Available via the MIT or new BSD license.
55
* see: http://github.com/requirejs/text for details
66
*/
7-
/*jslint */
8-
/*global require: false, XMLHttpRequest: false, ActiveXObject: false,
9-
define: false, window: false, process: false, Packages: false,
10-
java: false, location: false */
7+
/*jslint regexp: true */
8+
/*global require, XMLHttpRequest, ActiveXObject,
9+
define, window, process, Packages,
10+
java, location, Components, FileUtils */
1111

1212
define('text',['module'], function (module) {
1313

1414

15-
var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
15+
var text, fs, Cc, Ci,
16+
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
1617
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
1718
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
1819
hasLocation = typeof location !== 'undefined' && location.href,
1920
defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
2021
defaultHostName = hasLocation && location.hostname,
2122
defaultPort = hasLocation && (location.port || undefined),
2223
buildMap = [],
23-
masterConfig = module.config(),
24-
text, fs;
24+
masterConfig = (module.config && module.config()) || {};
2525

2626
text = {
27-
version: '2.0.0',
27+
version: '2.0.6',
2828

2929
strip: function (content) {
3030
//Strips <?xml ...?> declarations so that external SVG and XML
@@ -48,16 +48,18 @@ define('text',['module'], function (module) {
4848
.replace(/[\b]/g, "\\b")
4949
.replace(/[\n]/g, "\\n")
5050
.replace(/[\t]/g, "\\t")
51-
.replace(/[\r]/g, "\\r");
51+
.replace(/[\r]/g, "\\r")
52+
.replace(/[\u2028]/g, "\\u2028")
53+
.replace(/[\u2029]/g, "\\u2029");
5254
},
5355

54-
createXhr: function () {
56+
createXhr: masterConfig.createXhr || function () {
5557
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
5658
var xhr, i, progId;
5759
if (typeof XMLHttpRequest !== "undefined") {
5860
return new XMLHttpRequest();
5961
} else if (typeof ActiveXObject !== "undefined") {
60-
for (i = 0; i < 3; i++) {
62+
for (i = 0; i < 3; i += 1) {
6163
progId = progIds[i];
6264
try {
6365
xhr = new ActiveXObject(progId);
@@ -82,16 +84,30 @@ define('text',['module'], function (module) {
8284
* where strip is a boolean.
8385
*/
8486
parseName: function (name) {
85-
var strip = false, index = name.indexOf("."),
86-
modName = name.substring(0, index),
87+
var modName, ext, temp,
88+
strip = false,
89+
index = name.indexOf("."),
90+
isRelative = name.indexOf('./') === 0 ||
91+
name.indexOf('../') === 0;
92+
93+
if (index !== -1 && (!isRelative || index > 1)) {
94+
modName = name.substring(0, index);
8795
ext = name.substring(index + 1, name.length);
96+
} else {
97+
modName = name;
98+
}
8899

89-
index = ext.indexOf("!");
100+
temp = ext || modName;
101+
index = temp.indexOf("!");
90102
if (index !== -1) {
91103
//Pull off the strip arg.
92-
strip = ext.substring(index + 1, ext.length);
93-
strip = strip === "strip";
94-
ext = ext.substring(0, index);
104+
strip = temp.substring(index + 1) === "strip";
105+
temp = temp.substring(0, index);
106+
if (ext) {
107+
ext = temp;
108+
} else {
109+
modName = temp;
110+
}
95111
}
96112

97113
return {
@@ -112,8 +128,8 @@ define('text',['module'], function (module) {
112128
* @returns Boolean
113129
*/
114130
useXhr: function (url, protocol, hostname, port) {
115-
var match = text.xdRegExp.exec(url),
116-
uProtocol, uHostName, uPort;
131+
var uProtocol, uHostName, uPort,
132+
match = text.xdRegExp.exec(url);
117133
if (!match) {
118134
return true;
119135
}
@@ -125,7 +141,7 @@ define('text',['module'], function (module) {
125141
uHostName = uHostName[0];
126142

127143
return (!uProtocol || uProtocol === protocol) &&
128-
(!uHostName || uHostName === hostname) &&
144+
(!uHostName || uHostName.toLowerCase() === hostname.toLowerCase()) &&
129145
((!uPort && !uHostName) || uPort === port);
130146
},
131147

@@ -155,7 +171,8 @@ define('text',['module'], function (module) {
155171
masterConfig.isBuild = config.isBuild;
156172

157173
var parsed = text.parseName(name),
158-
nonStripName = parsed.moduleName + '.' + parsed.ext,
174+
nonStripName = parsed.moduleName +
175+
(parsed.ext ? '.' + parsed.ext : ''),
159176
url = req.toUrl(nonStripName),
160177
useXhr = (masterConfig.useXhr) ||
161178
text.useXhr;
@@ -193,11 +210,11 @@ define('text',['module'], function (module) {
193210

194211
writeFile: function (pluginName, moduleName, req, write, config) {
195212
var parsed = text.parseName(moduleName),
196-
nonStripName = parsed.moduleName + '.' + parsed.ext,
213+
extPart = parsed.ext ? '.' + parsed.ext : '',
214+
nonStripName = parsed.moduleName + extPart,
197215
//Use a '.js' file name so that it indicates it is a
198216
//script that can be loaded across domains.
199-
fileName = req.toUrl(parsed.moduleName + '.' +
200-
parsed.ext) + '.js';
217+
fileName = req.toUrl(parsed.moduleName + extPart) + '.js';
201218

202219
//Leverage own load() method to load plugin value, but only
203220
//write out values that do not have the strip argument,
@@ -218,9 +235,10 @@ define('text',['module'], function (module) {
218235
}
219236
};
220237

221-
if (typeof process !== "undefined" &&
222-
process.versions &&
223-
!!process.versions.node) {
238+
if (masterConfig.env === 'node' || (!masterConfig.env &&
239+
typeof process !== "undefined" &&
240+
process.versions &&
241+
!!process.versions.node)) {
224242
//Using special require.nodeRequire, something added by r.js.
225243
fs = require.nodeRequire('fs');
226244

@@ -232,11 +250,21 @@ define('text',['module'], function (module) {
232250
}
233251
callback(file);
234252
};
235-
} else if (text.createXhr()) {
236-
text.get = function (url, callback, errback) {
237-
var xhr = text.createXhr();
253+
} else if (masterConfig.env === 'xhr' || (!masterConfig.env &&
254+
text.createXhr())) {
255+
text.get = function (url, callback, errback, headers) {
256+
var xhr = text.createXhr(), header;
238257
xhr.open('GET', url, true);
239258

259+
//Allow plugins direct access to xhr headers
260+
if (headers) {
261+
for (header in headers) {
262+
if (headers.hasOwnProperty(header)) {
263+
xhr.setRequestHeader(header.toLowerCase(), headers[header]);
264+
}
265+
}
266+
}
267+
240268
//Allow overrides specified in config
241269
if (masterConfig.onXhr) {
242270
masterConfig.onXhr(xhr, url);
@@ -260,14 +288,15 @@ define('text',['module'], function (module) {
260288
};
261289
xhr.send(null);
262290
};
263-
} else if (typeof Packages !== 'undefined') {
291+
} else if (masterConfig.env === 'rhino' || (!masterConfig.env &&
292+
typeof Packages !== 'undefined' && typeof java !== 'undefined')) {
264293
//Why Java, why is this so awkward?
265294
text.get = function (url, callback) {
266-
var encoding = "utf-8",
295+
var stringBuffer, line,
296+
encoding = "utf-8",
267297
file = new java.io.File(url),
268298
lineSeparator = java.lang.System.getProperty("line.separator"),
269299
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
270-
stringBuffer, line,
271300
content = '';
272301
try {
273302
stringBuffer = new java.lang.StringBuffer();
@@ -298,8 +327,41 @@ define('text',['module'], function (module) {
298327
}
299328
callback(content);
300329
};
301-
}
330+
} else if (masterConfig.env === 'xpconnect' || (!masterConfig.env &&
331+
typeof Components !== 'undefined' && Components.classes &&
332+
Components.interfaces)) {
333+
//Avert your gaze!
334+
Cc = Components.classes,
335+
Ci = Components.interfaces;
336+
Components.utils['import']('resource://gre/modules/FileUtils.jsm');
302337

338+
text.get = function (url, callback) {
339+
var inStream, convertStream,
340+
readData = {},
341+
fileObj = new FileUtils.File(url);
342+
343+
//XPCOM, you so crazy
344+
try {
345+
inStream = Cc['@mozilla.org/network/file-input-stream;1']
346+
.createInstance(Ci.nsIFileInputStream);
347+
inStream.init(fileObj, 1, 0, false);
348+
349+
convertStream = Cc['@mozilla.org/intl/converter-input-stream;1']
350+
.createInstance(Ci.nsIConverterInputStream);
351+
convertStream.init(inStream, "utf-8", inStream.available(),
352+
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
353+
354+
convertStream.readString(inStream.available(), readData);
355+
convertStream.close();
356+
inStream.close();
357+
callback(readData.value);
358+
} catch (e) {
359+
throw new Error((fileObj && fileObj.path || '') + ': ' + e);
360+
}
361+
};
362+
363+
364+
}
303365
return text;
304366
});
305367

0 commit comments

Comments
 (0)