This repository was archived by the owner on Aug 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.js
More file actions
101 lines (89 loc) · 1.96 KB
/
Copy pathcommon.js
File metadata and controls
101 lines (89 loc) · 1.96 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var config = require('./configurator.js');
Object.defineProperty(global, '__stack', {
get: function () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) {
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
});
function error(e) {
var frame = __stack[1];
var line = frame.getLineNumber();
var file = frame.getFileName();
console.log("Error [" + file + ":" + line + "]: " + e);
}
function log(msg) {
var frame = __stack[1];
var line = frame.getLineNumber();
var file = frame.getFileName();
var logmsg = "Log [" + file + ":" + line + "]: " + msg;
if (config.isControl) {
// TODO: log to file!
console.log(logmsg);
} else {
config.rpcInterface.log(config.vmid, logmsg, function () {
});
}
}
function assert(val) {
if (!val) {
var frame = __stack[1];
var line = frame.getLineNumber();
var file = frame.getFileName();
var logmsg = "ASSERT FAIL!!! [" + file + ":" + line + "]";
if (config.isControl) {
// TODO: log to file!
console.log(logmsg);
} else {
config.rpcInterface.log(config.vmid, logmsg, function () {
});
}
}
}
function dlog(msg) {
// TODO: log to file!
console.log(msg);
}
function vlog(msg) {
var frame = __stack[1];
var line = frame.getLineNumber();
var file = frame.getFileName();
console.log("Log [" + file + ":" + line + "]: " + msg);
}
var VMStates = {
BUSY: 1,
FREE: 2,
READY: 3,
ERROR: 4,
name: function (val) {
return ['', 'BUSY', 'FREE', 'READY', 'ERROR'][val];
}
};
var BeliefState = {
CREATING: 0,
BOOTING: 1,
WAIT: 2,
FREE: 3,
READY: 4,
OCCUPIED: 5,
ERROR: 6,
KILLING: 7,
name: function (val) {
return ['CREATING', 'BOOTING', 'WAIT', 'FREE', 'READY', 'OCCUPIED', 'ERROR', 'KILLING'][val];
}
};
exports = module.exports = {
error: error,
log: log,
vlog: vlog,
dlog: dlog,
assert: assert,
VMStates: VMStates,
BeliefState: BeliefState
};