@@ -37,6 +37,15 @@ const L = require('internal/linkedlist');
37
37
const kInspect = require ( 'internal/util' ) . customInspectSymbol ;
38
38
const { inherits } = require ( 'util' ) ;
39
39
40
+ const {
41
+ ERR_INVALID_CALLBACK ,
42
+ ERR_INVALID_ARG_VALUE ,
43
+ ERR_INVALID_ARG_TYPE ,
44
+ ERR_INVALID_OPT_VALUE ,
45
+ ERR_VALID_PERFORMANCE_ENTRY_TYPE ,
46
+ ERR_INVALID_PERFORMANCE_MARK
47
+ } = require ( 'internal/errors' ) . codes ;
48
+
40
49
const kHandle = Symbol ( 'handle' ) ;
41
50
const kMap = Symbol ( 'map' ) ;
42
51
const kCallback = Symbol ( 'callback' ) ;
@@ -126,14 +135,6 @@ function collectHttp2Stats(entry) {
126
135
}
127
136
}
128
137
129
-
130
- let errors ;
131
- function lazyErrors ( ) {
132
- if ( errors === undefined )
133
- errors = require ( 'internal/errors' ) . codes ;
134
- return errors ;
135
- }
136
-
137
138
function now ( ) {
138
139
const hr = process . hrtime ( ) ;
139
140
return hr [ 0 ] * 1000 + hr [ 1 ] / 1e6 ;
@@ -284,8 +285,7 @@ let gcTrackingIsEnabled = false;
284
285
class PerformanceObserver extends AsyncResource {
285
286
constructor ( callback ) {
286
287
if ( typeof callback !== 'function' ) {
287
- const errors = lazyErrors ( ) ;
288
- throw new errors . ERR_INVALID_CALLBACK ( ) ;
288
+ throw new ERR_INVALID_CALLBACK ( ) ;
289
289
}
290
290
super ( 'PerformanceObserver' ) ;
291
291
Object . defineProperties ( this , {
@@ -331,16 +331,15 @@ class PerformanceObserver extends AsyncResource {
331
331
}
332
332
333
333
observe ( options ) {
334
- const errors = lazyErrors ( ) ;
335
334
if ( typeof options !== 'object' || options == null ) {
336
- throw new errors . ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
335
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
337
336
}
338
337
if ( ! Array . isArray ( options . entryTypes ) ) {
339
- throw new errors . ERR_INVALID_OPT_VALUE ( 'entryTypes' , options ) ;
338
+ throw new ERR_INVALID_OPT_VALUE ( 'entryTypes' , options ) ;
340
339
}
341
340
const entryTypes = options . entryTypes . filter ( filterTypes ) . map ( mapTypes ) ;
342
341
if ( entryTypes . length === 0 ) {
343
- throw new errors . ERR_VALID_PERFORMANCE_ENTRY_TYPE ( ) ;
342
+ throw new ERR_VALID_PERFORMANCE_ENTRY_TYPE ( ) ;
344
343
}
345
344
if ( entryTypes . includes ( NODE_PERFORMANCE_ENTRY_TYPE_GC ) &&
346
345
! gcTrackingIsEnabled ) {
@@ -393,8 +392,7 @@ class Performance {
393
392
startMark = startMark !== undefined ? `${ startMark } ` : '' ;
394
393
const marks = this [ kIndex ] [ kMarks ] ;
395
394
if ( ! marks . has ( endMark ) && ! ( endMark in nodeTiming ) ) {
396
- const errors = lazyErrors ( ) ;
397
- throw new errors . ERR_INVALID_PERFORMANCE_MARK ( endMark ) ;
395
+ throw new ERR_INVALID_PERFORMANCE_MARK ( endMark ) ;
398
396
}
399
397
_measure ( name , startMark , endMark ) ;
400
398
}
@@ -412,8 +410,7 @@ class Performance {
412
410
413
411
timerify ( fn ) {
414
412
if ( typeof fn !== 'function' ) {
415
- const errors = lazyErrors ( ) ;
416
- throw new errors . ERR_INVALID_ARG_TYPE ( 'fn' , 'Function' , fn ) ;
413
+ throw new ERR_INVALID_ARG_TYPE ( 'fn' , 'Function' , fn ) ;
417
414
}
418
415
if ( fn [ kTimerified ] )
419
416
return fn [ kTimerified ] ;
@@ -567,13 +564,11 @@ class ELDHistogram {
567
564
get stddev ( ) { return this [ kHandle ] . stddev ( ) ; }
568
565
percentile ( percentile ) {
569
566
if ( typeof percentile !== 'number' ) {
570
- const errors = lazyErrors ( ) ;
571
- throw new errors . ERR_INVALID_ARG_TYPE ( 'percentile' , 'number' , percentile ) ;
567
+ throw new ERR_INVALID_ARG_TYPE ( 'percentile' , 'number' , percentile ) ;
572
568
}
573
569
if ( percentile <= 0 || percentile > 100 ) {
574
- const errors = lazyErrors ( ) ;
575
- throw new errors . ERR_INVALID_ARG_VALUE . RangeError ( 'percentile' ,
576
- percentile ) ;
570
+ throw new ERR_INVALID_ARG_VALUE . RangeError ( 'percentile' ,
571
+ percentile ) ;
577
572
}
578
573
return this [ kHandle ] . percentile ( percentile ) ;
579
574
}
@@ -597,18 +592,15 @@ class ELDHistogram {
597
592
598
593
function monitorEventLoopDelay ( options = { } ) {
599
594
if ( typeof options !== 'object' || options === null ) {
600
- const errors = lazyErrors ( ) ;
601
- throw new errors . ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
595
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
602
596
}
603
597
const { resolution = 10 } = options ;
604
598
if ( typeof resolution !== 'number' ) {
605
- const errors = lazyErrors ( ) ;
606
- throw new errors . ERR_INVALID_ARG_TYPE ( 'options.resolution' ,
607
- 'number' , resolution ) ;
599
+ throw new ERR_INVALID_ARG_TYPE ( 'options.resolution' ,
600
+ 'number' , resolution ) ;
608
601
}
609
602
if ( resolution <= 0 || ! Number . isSafeInteger ( resolution ) ) {
610
- const errors = lazyErrors ( ) ;
611
- throw new errors . ERR_INVALID_OPT_VALUE . RangeError ( 'resolution' , resolution ) ;
603
+ throw new ERR_INVALID_OPT_VALUE . RangeError ( 'resolution' , resolution ) ;
612
604
}
613
605
return new ELDHistogram ( new _ELDHistogram ( resolution ) ) ;
614
606
}
0 commit comments