-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpu.js
64 lines (63 loc) · 1.8 KB
/
util.cpu.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
/**
CPU - util
Dependency: core, socket
**/
(function() {
var modulename = "util";
var Module = (function(modulename) {
function Module(options) {
this.name = modulename;
if (!options) {
console.log("Can't load module \"" + this.name + "\"! You need to pass some options.");
return;
}
if (!options["cpu"]) {
console.log("Can't load module \"" + this.name + "\"! You need to pass the cpu object.");
return;
}
this.cpu = options["cpu"];
this.utils = options["utils"] || window.utils || undefined;
if (this.utils === undefined) {
console.log("Can't load module \"" + this.name + "\"! You need to pass the utils object.");
return;
}
};
Module.prototype.log = function() {
var message = this.utils.format.apply(null, arguments);
this.cpu.module("socket").emit("log", { 'log': message });
console.log(message);
};
Module.prototype.objequal = function(a, b) {
function equal(a, b) {
if (typeof a === "object" && typeof b === "object") {
for (var k in a) {
if (a.hasOwnProperty(k)) {
if (b.hasOwnProperty(k)) {
if (!this.objequal(a[k], b[k])) {
return false;
}
} else {
return false;
}
}
}
} else {
if (a != b) {
return false;
}
}
return true;
}
return equal(a, b) && equal(b, a);
};
return Module;
})(modulename);
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = Module;
} else {
if (!window.cpumodules) {
window.cpumodules = {};
}
window.cpumodules[modulename] = Module;
}
})();