-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim.js
65 lines (57 loc) · 1.99 KB
/
sim.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
(function(exports, shellMode)
{
exports.config = undefined // will be set on init, and if somebody changes it on the network panel
exports.isEnabled = function(test)
{
return this.config[test] && this.config[test].active
}
exports.pointOfFailure = function(pointName, c)
{
if (this.config.disconnect && this.config.disconnect.active)
if (pointName === this.config.disconnect.pof)
if (c)
c.close()
if (this.config.exception && this.config.exception.active)
if (pointName === this.config.exception.pof)
throw new Error(this.config.exception.value)
if (this.config.stopWork && this.config.stopWork.active)
if (pointName === this.config.stopWork.pof)
return 'stopWork';
return undefined;
}
exports.delayedSection = function(action)
{
if (this.isEnabled('delayed'))
{
setTimeout(function()
{
if (action())
exports.delayedSection(action)
},
exports.config.delayed.value)
}
else
{
while(action()) {}
}
}
/*
* describe hidden arguments (take a look on the arguments docs)
*/
exports.log = function()
{
var argArray = Array.prototype.slice.call(arguments)
var category = argArray[0]
var level = argArray[1]
var desc = category
if (shellMode)
desc = '\n------------------------------------------------------------\n' + category
if (!this.config || this.config[category].active)
{
var remainingsArgs = JSON.parse(JSON.stringify(argArray.slice(2)))
var logArgs = [desc].concat(remainingsArgs)
console[level].apply(console, logArgs)
}
}
})
(typeof exports === 'undefined' ? this['sim']={} : exports, typeof exports !== 'undefined')