forked from compat-table/compat-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhino.js
65 lines (55 loc) · 1.99 KB
/
rhino.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Node.js test runner for running data-*.js tests with Rhino's interpreter
* running in es6 mode (a.k.a.: -version 200).
*
* If the environment variable JAVA_HOME is defined it will use it to
* construct the path to 'java' as $JAVA_HOME/bin/java
*
* Reports discrepancies to console; fix them manually in data-*.js files.
* Expects a 'rhino.jar' file in this directory. Example:
*
* $ node rhino.js
*
* Any syntax tested that is unsupported by Rhino will output to stderr. To make the
* output of this file more useful, redirect stderr to /dev/null or elsewhere. Example:
*
* $ node rhino.js 2>/dev/null
*/
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
var runner_support = require('./runner_support');
var javaCommand = 'java';
var jdkBin = '';
// if JAVA_HOME is set then resolve to the bin
if (process.env.JAVA_HOME) {
var jdkBin = path.resolve(process.env.JAVA_HOME, 'bin');
javaCommand = path.resolve(jdkBin, 'java');
}
function executeScript(scriptName) {
return child_process.execFileSync(javaCommand, ['-jar', 'rhino.jar', '-version', '200', scriptName], {
encoding: 'utf-8'
});
}
// Key for .res (e.g. test.res.rhino1_7_13), automatic based on rhino version.
var rhinoKey = (function () {
var script = 'print(org.mozilla.javascript.ImplementationVersion.get());\n' +
'quit()\n';
fs.writeFileSync('rhinoversion.js', script);
var stdout = executeScript('rhinoversion.js');
console.log('rhino version is: ' + stdout);
var match = stdout.match(/Rhino (\d+)\.(\d+)\.(\d+)/);
return 'rhino' + match[1] + "_" + match[2] + "_" + match[3];
})();
console.log('rhino result key is: test.res.' + rhinoKey);
function rhinoRunner(testFilename) {
try {
var stdout = executeScript(testFilename);
return /^\[SUCCESS\]$/m.test(stdout);
} catch (e) {
return false;
}
}
runner_support.runTests(rhinoRunner, rhinoKey, 'Rhino', {
logCommand: 'print'
});