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) { if (websocket) {
websocket.send(msg); websocket.send(msg);
} }
if (typeof window == 'undefined') { if (typeof window === 'undefined') {
print(msg); print(msg);
} else if (window.dump) { } else if (window.dump) {
window.dump(msg); window.dump(msg);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,12 +18,12 @@ if (!String.fromCodePoint) {
} }
if (!String.prototype.endsWith) { 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) { if (!String.prototype.startsWith) {
String.prototype.startsWith = function (str) { 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) { if (!Array.prototype.has) {
Array.prototype.has = function (v) { 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 methodName = random.key(methodHash);
var methodArgs = methodHash[methodName]; var methodArgs = methodHash[methodName];
if (typeof(methodArgs) == "function") { // Todo: Hmmmm.. if (typeof(methodArgs) === "function") { // Todo: Hmmmm..
return methodArgs(); return methodArgs();
} }
return objectName + "." + methodName + utils.script.methodHead(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 + "}"; return "for (var i = 0; i < " + (max || make.number.rangeNumber()) + "; i++) {" + s + "}";
}, },
makeArray: function (type, arrayLength, cb) { makeArray: function (type, arrayLength, cb) {
if (type == null || type === undefined) { if (type === null || type === undefined) {
type = random.index(["Uint8", "Float32"]); type = random.index(["Uint8", "Float32"]);
} }
switch (random.number(8)) { switch (random.number(8)) {