Fix all type coercion issues

This commit is contained in:
pyoor 2017-04-25 11:22:15 -04:00
parent aa6e9f567a
commit 2e65a4bea3
8 changed files with 24 additions and 24 deletions

View file

@ -24,7 +24,7 @@ var logger = (function () {
if (websocket) {
websocket.send(msg);
}
if (typeof window == 'undefined') {
if (typeof window === 'undefined') {
print(msg);
} else if (window.dump) {
window.dump(msg);

View file

@ -9,7 +9,7 @@ make.strings = {
string: function (maxlen) {
let s = "";
if (maxlen == null || maxlen === undefined) {
if (maxlen === null || maxlen === undefined) {
maxlen = make.number.rangeNumber();
}

View file

@ -10,7 +10,7 @@ var random = {
* @param {number|null|undefined} seed Value to initialize MersenneTwister.
*/
init: function (seed) {
if (seed == null || seed === undefined) {
if (seed === null || seed === undefined) {
seed = new Date().getTime();
}
this.twister = new MersenneTwister();
@ -18,10 +18,10 @@ var random = {
},
number: function (limit) {
// Returns an integer in [0, limit). Uniform distribution.
if (limit == 0) {
if (limit === 0) {
return limit;
}
if (limit == null || limit === undefined) {
if (limit === null || limit === undefined) {
limit = 0xffffffff;
}
let x = (0x100000000 / limit) >>> 0,
@ -48,7 +48,7 @@ var random = {
return Math.exp(this.float() * Math.log(limit));
},
item: function (list) {
if (!(list instanceof Array || (list !== undefined && typeof list != "string" && list.hasOwnProperty("length")))) {
if (!(list instanceof Array || (list !== undefined && typeof list !== "string" && list.hasOwnProperty("length")))) {
logger.traceback();
throw new TypeError("this.item() received a non array type: '" + list + "'");
}
@ -65,7 +65,7 @@ var random = {
return this.item([true, false]);
},
pick: function (obj) {
if (typeof obj == "function") {
if (typeof obj === "function") {
return obj();
}
if (obj instanceof Array) {
@ -74,14 +74,14 @@ var random = {
return obj;
},
chance: function (limit) {
if (limit == null || limit === undefined) {
if (limit === null || limit === undefined) {
limit = 2;
}
if (isNaN(limit)) {
logger.traceback();
throw new TypeError("random.chance() received a non number type: '" + limit + "'");
}
return this.number(limit) == 1;
return this.number(limit) === 1;
},
choose: function (list, flat) {
if (!(list instanceof Array)) {
@ -95,7 +95,7 @@ var random = {
let n = this.number(total);
for (let i = 0; i < list.length; i++) {
if (n < list[i][0]) {
if (flat == true) {
if (flat === true) {
return list[i][1];
} else {
return this.pick([list[i][1]]);
@ -103,7 +103,7 @@ var random = {
}
n = n - list[i][0];
}
if (flat == true) {
if (flat === true) {
return list[0][1];
}
return this.pick([list[0][1]]);

View file

@ -4,20 +4,20 @@
utils.block = {
block: function (list, optional) {
if (optional == true) {
if (optional === true) {
if (random.chance(6)) {
return '';
}
}
function go_deeper(item) {
if (item == null || item === undefined) {
if (item === null || item === undefined) {
return "";
}
if (typeof(item) == "function") {
if (typeof(item) === "function") {
return item();
}
if (typeof(item) == "string") {
if (typeof(item) === "string") {
return item;
}
if (item instanceof (Array)) {

View file

@ -53,7 +53,7 @@ utils.common = {
mergeHash: function (obj1, obj2) {
for (let p in obj2) {
try {
if (obj2[p].constructor == Object) {
if (obj2[p].constructor === Object) {
obj1[p] = utils.common.mergeHash(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];

View file

@ -46,7 +46,7 @@ Objects.prototype.pop = function (objectName) {
var self = this;
Utils.getKeysFromHash(this.container).forEach(function (category) {
self.container[category].forEach(function (obj) {
if (obj.name == objectName) {
if (obj.name === objectName) {
self.container[category].splice(self.container[category].indexOf(obj), 1);
}
});
@ -60,7 +60,7 @@ Objects.prototype.contains = function (categoryNames) {
categories.push(name);
}
});
return (categories.length == 0) ? null : categories;
return (categories.length === 0) ? null : categories;
};
Objects.prototype.show = function (category) {
@ -97,7 +97,7 @@ Objects.prototype.check = function (category) {
self.container[category].forEach(function (object) {
try {
var x = /*frame.contentWindow.*/eval(object.name);
if (x === undefined || x == null) {
if (x === undefined || x === null) {
self.pop(object.name);
}
} catch (e) {

View file

@ -18,12 +18,12 @@ if (!String.fromCodePoint) {
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function (str) { return (this.match(str + "$") == str) };
String.prototype.endsWith = function (str) { return (this.match(str + "$") === str) };
}
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (str) {
return (this.match("^" + str) == str)
return (this.match("^" + str) === str)
};
}
@ -41,7 +41,7 @@ if (!String.prototype.insert) {
if (!Array.prototype.has) {
Array.prototype.has = function (v) {
return this.indexOf(v) != -1;
return this.indexOf(v) !== -1;
};
}

View file

@ -20,7 +20,7 @@ utils.script = {
}
var methodName = random.key(methodHash);
var methodArgs = methodHash[methodName];
if (typeof(methodArgs) == "function") { // Todo: Hmmmm..
if (typeof(methodArgs) === "function") { // Todo: Hmmmm..
return methodArgs();
}
return objectName + "." + methodName + utils.script.methodHead(methodArgs);
@ -67,7 +67,7 @@ utils.script = {
return "for (var i = 0; i < " + (max || make.number.rangeNumber()) + "; i++) {" + s + "}";
},
makeArray: function (type, arrayLength, cb) {
if (type == null || type === undefined) {
if (type === null || type === undefined) {
type = random.index(["Uint8", "Float32"]);
}
switch (random.number(8)) {