Skip to content

Commit 445ac65

Browse files
committed
Fixes #382, allow using optimizer as JS object in rhino (and xpcshell)
1 parent 771369f commit 445ac65

File tree

14 files changed

+85
-0
lines changed

14 files changed

+85
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ build/tests/transform/results
8181
env/xpcshell
8282
tests/node/node_modules
8383
tests/node/embedded/node_modules
84+
tests/rhino/main-built.js
85+
tests/xpcshell/main-built.js

build/jslib/x.js

+9
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ var requirejs, require, define, xpcUtil;
374374
setBaseUrl(location.href);
375375
createRjsApi();
376376
return;
377+
} else if ((env === 'rhino' || env === 'xpconnect') &&
378+
//User sets up requirejsAsLib variable to indicate it is loaded
379+
//via load() to be used as a library.
380+
typeof requirejsAsLib !== 'undefined' && requirejsAsLib) {
381+
//This script is loaded via rhino's load() method, expose the
382+
//API and get out.
383+
setBaseUrl(fileName);
384+
createRjsApi();
385+
return;
377386
}
378387

379388
if (commandOption === 'o') {

tests/rhino/a.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define({
2+
name: 'a'
3+
});
4+

tests/rhino/build.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var requirejsAsLib = true;
2+
load('../../r.js');
3+
4+
requirejs.optimize({
5+
name: 'main',
6+
out: 'main-built.js',
7+
optimize: 'none'
8+
}, function (results) {
9+
print(results);
10+
}, function (err) {
11+
print('GOT ERROR: ' + err);
12+
});
13+

tests/rhino/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
java -classpath ../../lib/rhino/js.jar:../../lib/closure.compiler.jar org.mozilla.javascript.tools.shell.Main build.js

tests/rhino/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
define(['a'], function (a) {
2+
return {
3+
name: 'main',
4+
a: a
5+
};
6+
});

tests/rhino/run.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var requirejsAsLib = true;
2+
load('../../r.js');
3+
4+
requirejs(['main'], function (main) {
5+
print('main\'s name is: ' + main.name);
6+
print('a\'s name is: ' + main.a.name);
7+
});
8+

tests/rhino/run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
java -classpath ../../lib/rhino/js.jar:../../lib/closure.compiler.jar org.mozilla.javascript.tools.shell.Main run.js

tests/xpcshell/a.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define({
2+
name: 'a'
3+
});
4+

tests/xpcshell/build.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var requirejsAsLib = true;
2+
load('../../r.js');
3+
4+
requirejs.optimize({
5+
name: 'main',
6+
out: 'main-built.js',
7+
optimize: 'none'
8+
}, function (results) {
9+
print(results);
10+
}, function (err) {
11+
print('GOT ERROR: ' + err);
12+
});
13+

tests/xpcshell/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
../../env/xpcshell/xpcshell build.js

tests/xpcshell/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
define(['a'], function (a) {
2+
return {
3+
name: 'main',
4+
a: a
5+
};
6+
});

tests/xpcshell/run.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var requirejsAsLib = true;
2+
load('../../r.js');
3+
4+
requirejs(['main'], function (main) {
5+
print('main\'s name is: ' + main.name);
6+
print('a\'s name is: ' + main.a.name);
7+
});
8+

tests/xpcshell/run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
../../env/xpcshell/xpcshell run.js

0 commit comments

Comments
 (0)