|
24 | 24 | */ |
25 | 25 |
|
26 | 26 | /*jslint sloppy:true plusplus:true node:true rhino:true */ |
27 | | - |
28 | | -var fs, esprima, options, fnames, count; |
29 | | - |
30 | | -if (typeof require === 'function') { |
31 | | - fs = require('fs'); |
32 | | - esprima = require('esprima'); |
33 | | -} else if (typeof load === 'function') { |
34 | | - try { |
35 | | - load('esprima.js'); |
36 | | - } catch (e) { |
37 | | - load('../esprima.js'); |
| 27 | +/*global phantom:true */ |
| 28 | + |
| 29 | +var fs, system, esprima, options, fnames, count; |
| 30 | + |
| 31 | +if (typeof esprima === 'undefined') { |
| 32 | + // PhantomJS can only require() relative files |
| 33 | + if (typeof phantom === 'object') { |
| 34 | + fs = require('fs'); |
| 35 | + system = require('system'); |
| 36 | + esprima = require('./esprima'); |
| 37 | + } else if (typeof require === 'function') { |
| 38 | + fs = require('fs'); |
| 39 | + esprima = require('esprima'); |
| 40 | + } else if (typeof load === 'function') { |
| 41 | + try { |
| 42 | + load('esprima.js'); |
| 43 | + } catch (e) { |
| 44 | + load('../esprima.js'); |
| 45 | + } |
38 | 46 | } |
39 | 47 | } |
40 | 48 |
|
| 49 | +// Shims to Node.js objects when running under PhantomJS 1.7+. |
| 50 | +if (typeof phantom === 'object') { |
| 51 | + fs.readFileSync = fs.read; |
| 52 | + process = { |
| 53 | + argv: [].slice.call(system.args), |
| 54 | + exit: phantom.exit |
| 55 | + }; |
| 56 | + process.argv.unshift('phantomjs'); |
| 57 | +} |
| 58 | + |
41 | 59 | // Shims to Node.js objects when running under Rhino. |
42 | 60 | if (typeof console === 'undefined' && typeof process === 'undefined') { |
43 | 61 | console = { log: print }; |
@@ -164,3 +182,7 @@ if (options.format === 'junit') { |
164 | 182 | if (count > 0) { |
165 | 183 | process.exit(1); |
166 | 184 | } |
| 185 | + |
| 186 | +if (count === 0 && typeof phantom === 'object') { |
| 187 | + process.exit(0); |
| 188 | +} |
0 commit comments