lib: port errors to new system

This is a first batch of updates that touches non-underscored modules in
lib.

PR-URL: https://github.com/nodejs/node/pull/19034
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Michaël Zasso 2018-02-27 14:55:32 +01:00
parent 023f49c5a9
commit 1e8d110e64
31 changed files with 377 additions and 418 deletions

View file

@ -137,7 +137,7 @@ function collectHttp2Stats(entry) {
let errors;
function lazyErrors() {
if (errors === undefined)
errors = require('internal/errors');
errors = require('internal/errors').codes;
return errors;
}
@ -322,7 +322,7 @@ class PerformanceObserver extends AsyncResource {
constructor(callback) {
if (typeof callback !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_CALLBACK');
throw new errors.ERR_INVALID_CALLBACK();
}
super('PerformanceObserver');
Object.defineProperties(this, {
@ -370,15 +370,14 @@ class PerformanceObserver extends AsyncResource {
observe(options) {
const errors = lazyErrors();
if (typeof options !== 'object' || options == null) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
throw new errors.ERR_INVALID_ARG_TYPE('options', 'Object');
}
if (!Array.isArray(options.entryTypes)) {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'entryTypes', options);
throw new errors.ERR_INVALID_OPT_VALUE('entryTypes', options);
}
const entryTypes = options.entryTypes.filter(filterTypes).map(mapTypes);
if (entryTypes.length === 0) {
throw new errors.Error('ERR_VALID_PERFORMANCE_ENTRY_TYPE');
throw new errors.ERR_VALID_PERFORMANCE_ENTRY_TYPE();
}
this.disconnect();
this[kBuffer][kEntries] = [];
@ -408,7 +407,7 @@ class Performance extends PerformanceObserverEntryList {
set maxEntries(val) {
if (typeof val !== 'number' || val >>> 0 !== val) {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'val', 'number');
throw new errors.ERR_INVALID_ARG_TYPE('val', 'number');
}
this[kMaxCount] = Math.max(1, val >>> 0);
}
@ -488,7 +487,7 @@ class Performance extends PerformanceObserverEntryList {
const marks = this[kIndex][kMarks];
if (!marks.has(endMark) && !(endMark in nodeTiming)) {
const errors = lazyErrors();
throw new errors.Error('ERR_INVALID_PERFORMANCE_MARK', endMark);
throw new errors.ERR_INVALID_PERFORMANCE_MARK(endMark);
}
_measure(name, startMark, endMark);
}
@ -521,7 +520,7 @@ class Performance extends PerformanceObserverEntryList {
timerify(fn) {
if (typeof fn !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fn', 'Function');
throw new errors.ERR_INVALID_ARG_TYPE('fn', 'Function');
}
if (fn[kTimerified])
return fn[kTimerified];