bootstrap.js
1.73 KB
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
function emit() {
var args = Array.prototype.slice.call(arguments);
console.log(JSON.stringify({
jsonrpc: '2.0',
method: 'emit',
params: args
}));
}
phantom.onError = function bootstrapOnError(msg, trace) {
emit('error', msg, trace);
phantom.exit(1);
};
// source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
Function.prototype.bind = function (oThis) {
/* jshint newcap: false, laxbreak: true */
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
var options = phantom.casperArgs.options;
phantom.requireBase = options.spooky_lib + 'node_modules/';
var emit = require(options.spooky_lib + 'lib/bootstrap/emit').emit;
var transport = (options.transport || '').toLowerCase();
var server;
if (transport === 'http') {
server = require(options.spooky_lib + 'lib/bootstrap/http-server');
} else if (transport === 'stdio') {
server = require(options.spooky_lib + 'lib/bootstrap/stdio-server');
} else {
throw new Error('Unknown transport: ' + transport);
}
require(options.spooky_lib + 'lib/bootstrap/casper').provideAll(server);
emit('ready');