handle arguments better.

This commit is contained in:
Christopher Jeffrey 2016-06-13 03:17:28 -07:00
parent 87ce4e5583
commit 0080c3e519
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 48 additions and 16 deletions

View File

@ -324,8 +324,11 @@ Environment.prototype.mkdir = function mkdir(path, dirname) {
*/ */
Environment.prototype.debug = function debug() { Environment.prototype.debug = function debug() {
var args = Array.prototype.slice.call(arguments); var args = new Array(arguments.length);
var msg; var i, msg;
for (i = 0; i < args.length; i++)
args[i] = arguments[i];
if (this.logger) { if (this.logger) {
if (this.debugLogs) if (this.debugLogs)

View File

@ -625,12 +625,17 @@ utils.revHex = function revHex(s) {
*/ */
utils.merge = function merge(target) { utils.merge = function merge(target) {
var args = Array.prototype.slice.call(arguments, 1); var i, j, obj, keys, key;
args.forEach(function(obj) {
Object.keys(obj).forEach(function(key) { for (i = 1; i < arguments.length; i++) {
obj = arguments[i];
keys = Object.keys(obj);
for (j = 0; j < keys.length; j++) {
key = keys[j];
target[key] = obj[key]; target[key] = obj[key];
}); }
}); }
return target; return target;
}; };
@ -883,8 +888,11 @@ utils.format = function format(args, color) {
*/ */
utils.print = function print() { utils.print = function print() {
var args = Array.prototype.slice.call(arguments); var args = new Array(arguments.length);
var msg; var i, msg;
for (i = 0; i < args.length; i++)
args[i] = arguments[i];
if (utils.isBrowser) { if (utils.isBrowser) {
msg = typeof args[0] !== 'object' msg = typeof args[0] !== 'object'
@ -905,8 +913,11 @@ utils.print = function print() {
*/ */
utils.error = function error() { utils.error = function error() {
var args = Array.prototype.slice.call(arguments); var args = new Array(arguments.length);
var msg; var i, msg;
for (i = 0; i < args.length; i++)
args[i] = arguments[i];
if (utils.isBrowser) { if (utils.isBrowser) {
msg = typeof args[0] !== 'object' msg = typeof args[0] !== 'object'

View File

@ -296,12 +296,17 @@ WalletDB.prototype.unregister = function unregister(wallet) {
*/ */
WalletDB.prototype.fire = function fire(id) { WalletDB.prototype.fire = function fire(id) {
var args = Array.prototype.slice.call(arguments, 1);
var watcher = this.watchers[id]; var watcher = this.watchers[id];
var i, args;
if (!watcher) if (!watcher)
return; return;
args = new Array(arguments.length - 1);
for (i = 1; i < arguments.length; i++)
args[i - 1] = arguments[i];
watcher.wallet.emit.apply(watcher.wallet, args); watcher.wallet.emit.apply(watcher.wallet, args);
}; };

View File

@ -427,7 +427,12 @@ Worker.prototype.send = function send(job, name, items) {
*/ */
Worker.prototype.sendEvent = function sendEvent() { Worker.prototype.sendEvent = function sendEvent() {
var items = Array.prototype.slice.call(arguments); var items = new Array(arguments.length);
var i;
for (i = 0; i < items.length; i++)
items[i] = arguments[i];
return this.send(0, 'event', items); return this.send(0, 'event', items);
}; };
@ -590,7 +595,12 @@ Master.prototype.send = function send(job, name, items) {
*/ */
Master.prototype.sendEvent = function sendEvent() { Master.prototype.sendEvent = function sendEvent() {
var items = Array.prototype.slice.call(arguments); var items = new Array(arguments.length);
var i;
for (i = 0; i < items.length; i++)
items[i] = arguments[i];
return this.send(0, 'event', items); return this.send(0, 'event', items);
}; };
@ -601,12 +611,15 @@ Master.prototype.sendEvent = function sendEvent() {
*/ */
Master.prototype.debug = function debug() { Master.prototype.debug = function debug() {
var args, msg; var i, args, msg;
if (!this.options.debug) if (!this.options.debug)
return; return;
args = Array.prototype.slice.call(arguments); args = new Array(arguments.length);
for (i = 0; i < args.length; i++)
args[i] = arguments[i];
msg = utils.format(args, false); msg = utils.format(args, false);
msg = utils.format(['Worker %d: %s', this.id, msg], false); msg = utils.format(['Worker %d: %s', this.id, msg], false);