Skip to content

Commit

Permalink
use rest parameters instead of arguments
Browse files Browse the repository at this point in the history
now possible by dropping support for node older than v6
  • Loading branch information
brendankenny committed Jan 24, 2017
1 parent a17238a commit 4dd1150
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ module.exports = {
"valid-jsdoc": 0,
"comma-dangle": 0,
"arrow-parens": 0,
// Compat: support for rest params is behind a flag for node v5.x
"prefer-rest-params": 0,
},
"parserOptions": {
"ecmaVersion": 6,
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-cli/test/global-mocha-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Object.keys(assert)
.filter(key => typeof assert[key] === 'function')
.forEach(key => {
const _origFn = assert[key];
assert[key] = function() {
assert[key] = function(...args) {
if (currTest) {
currTest._assertions++;
}
return _origFn.apply(this, arguments);
return _origFn.apply(this, args);
};
}
);
Expand Down
6 changes: 2 additions & 4 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,9 @@ function captureJSCallUsage(funcRef, set) {
const originalFunc = funcRef;
const originalPrepareStackTrace = __nativeError.prepareStackTrace;

return function() {
return function(...args) {
// Note: this function runs in the context of the page that is being audited.

const args = [...arguments]; // callee's arguments.

// See v8's Stack Trace API https://github.com/v8/v8/wiki/Stack-Trace-API#customizing-stack-traces
__nativeError.prepareStackTrace = function(error, structStackTrace) {
// First frame is the function we injected (the one that just threw).
Expand Down Expand Up @@ -850,7 +848,7 @@ function captureJSCallUsage(funcRef, set) {
__nativeError.prepareStackTrace = originalPrepareStackTrace;

// eslint-disable-next-line no-invalid-this
return originalFunc.apply(this, arguments);
return originalFunc.apply(this, args);
};
}

Expand Down
12 changes: 6 additions & 6 deletions lighthouse-core/lib/console-quieter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class ConsoleQuieter {
static mute(opts) {
ConsoleQuieter._logs = ConsoleQuieter._logs || [];

console.log = function() {
ConsoleQuieter._logs.push({type: 'log', args: arguments, prefix: opts.prefix});
console.log = function(...args) {
ConsoleQuieter._logs.push({type: 'log', args: args, prefix: opts.prefix});
};
console.warn = function() {
ConsoleQuieter._logs.push({type: 'warn', args: arguments, prefix: opts.prefix});
console.warn = function(...args) {
ConsoleQuieter._logs.push({type: 'warn', args: args, prefix: opts.prefix});
};
console.error = function() {
ConsoleQuieter._logs.push({type: 'error', args: arguments, prefix: opts.prefix});
console.error = function(...args) {
ConsoleQuieter._logs.push({type: 'error', args: args, prefix: opts.prefix});
};
}

Expand Down
26 changes: 14 additions & 12 deletions lighthouse-core/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class Emitter extends EventEmitter {
* Fires off all status updates. Listen with
* `require('lib/log').events.addListener('status', callback)`
* @param {string} title
* @param {...*} args
*/
issueStatus(title, args) {
issueStatus(title, ...args) {
if (title === 'status' || title === 'statusEnd') {
this.emit(title, args);
}
Expand All @@ -50,8 +51,9 @@ class Emitter extends EventEmitter {
/**
* Fires off all warnings. Listen with
* `require('lib/log').events.addListener('warning', callback)`
* @param {...*} args
*/
issueWarning(args) {
issueWarning(...args) {
this.emit('warning', args);
}
}
Expand Down Expand Up @@ -113,23 +115,23 @@ class Log {
Log._logToStdErr(`${prefix}:${level || ''}`, [data.method, snippet]);
}

static log(title) {
Log.events.issueStatus(title, arguments);
return Log._logToStdErr(title, Array.from(arguments).slice(1));
static log(title, ...args) {
Log.events.issueStatus(title, ...args);
return Log._logToStdErr(title, args);
}

static warn(title) {
Log.events.issueWarning(arguments);
return Log._logToStdErr(`${title}:warn`, Array.from(arguments).slice(1));
static warn(title, ...args) {
Log.events.issueWarning(title, ...args);
return Log._logToStdErr(`${title}:warn`, args);
}

static error(title) {
return Log._logToStdErr(`${title}:error`, Array.from(arguments).slice(1));
static error(title, ...args) {
return Log._logToStdErr(`${title}:error`, args);
}

static verbose(title) {
static verbose(title, ...args) {
Log.events.issueStatus(title);
return Log._logToStdErr(`${title}:verbose`, Array.from(arguments).slice(1));
return Log._logToStdErr(`${title}:verbose`, args);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/report/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ class ReportGenerator {
});

// arg1 && arg2 && ... && argn
Handlebars.registerHelper('and', function() {
Handlebars.registerHelper('and', function(...args) {
let arg = false;
for (let i = 0, n = arguments.length - 1; i < n; i++) {
arg = arguments[i];
for (let i = 0, n = args.length - 1; i < n; i++) {
arg = args[i];
if (!arg) {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/global-mocha-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Object.keys(assert)
.filter(key => typeof assert[key] === 'function')
.forEach(key => {
const _origFn = assert[key];
assert[key] = function() {
assert[key] = function(...args) {
if (currTest) {
currTest._assertions++;
}
return _origFn.apply(this, arguments);
return _origFn.apply(this, args);
};
}
);
Expand Down

0 comments on commit 4dd1150

Please sign in to comment.