diff --git a/logging/console.js b/logging/console.js index a0e49c1..03f0809 100644 --- a/logging/console.js +++ b/logging/console.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var Logger = (function () { +var logger = (function () { let color = { red: "\033[1;31m", green: "\033[1;32m", @@ -61,6 +61,16 @@ var Logger = (function () { dumpln(color.green + sep + color.clear); } + function traceback() { + error("===[ Traceback ]"); + try { + throw new Error(); + } catch (e) { + dump(e.stack || e.stacktrace || ""); + } + error("==="); + } + return { console: console, dump: dump, @@ -69,6 +79,7 @@ var Logger = (function () { dumpln: dumpln, comment: comment, testcase: testcase, - separator: separator + separator: separator, + traceback: traceback }; })(); diff --git a/random/random.js b/random/random.js index dede6aa..9bda73d 100644 --- a/random/random.js +++ b/random/random.js @@ -38,7 +38,7 @@ var random = { range: function (start, limit) { // Returns an integer in [start, limit]. Uniform distribution. if (isNaN(start) || isNaN(limit)) { - Utils.traceback(); + logger.traceback(); throw new TypeError("random.range() received a non number type: '" + start + "', '" + limit + "')"); } return this.number(limit - start + 1) + start; @@ -49,7 +49,7 @@ var random = { }, item: function (list) { if (!(list instanceof Array || (list !== undefined && typeof list != "string" && list.hasOwnProperty("length")))) { - //Utils.traceback(); + logger.traceback(); throw new TypeError("this.item() received a non array type: '" + list + "'"); } return list[this.number(list.length)]; @@ -78,14 +78,14 @@ var random = { limit = 2; } if (isNaN(limit)) { - Utils.traceback(); + logger.traceback(); throw new TypeError("random.chance() received a non number type: '" + limit + "'"); } return this.number(limit) == 1; }, choose: function (list, flat) { if (!(list instanceof Array)) { - Utils.traceback(); + logger.traceback(); throw new TypeError("random.choose() received a non-array type: '" + list + "'"); } let total = 0; @@ -137,7 +137,7 @@ var random = { }, subset: function (list, limit) { if (!(list instanceof Array)) { - Utils.traceback(); + logger.traceback(); throw new TypeError("random.some() received a non-array type: '" + list + "'"); } if (typeof limit !== 'number') { diff --git a/utils/common.js b/utils/common.js index ac297cc..d93ec6e 100644 --- a/utils/common.js +++ b/utils/common.js @@ -63,14 +63,5 @@ utils.common = { } } return obj1; - }, - traceback: function () { - Logger.error("===[ Traceback ]"); - try { - throw new Error(); - } catch (e) { - Logger.dump(e.stack || e.stacktrace || ""); - } - Logger.error("==="); } };