Skip to content

Commit f332265

Browse files
ZYSzysBethGriggs
authored andcommitted
test: remove util.inherits() usage
Backport-PR-URL: #28795 PR-URL: #25245 Refs: #24755 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 4a607fa commit f332265

12 files changed

+35
-28
lines changed

‎test/common/arraystream.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
const{ Stream }=require('stream');
5-
const{ inherits }=require('util');
65
functionnoop(){}
76

87
// A stream to push an array into a REPL
@@ -14,7 +13,8 @@ function ArrayStream(){
1413
};
1514
}
1615

17-
inherits(ArrayStream,Stream);
16+
Object.setPrototypeOf(ArrayStream.prototype,Stream.prototype);
17+
Object.setPrototypeOf(ArrayStream,Stream);
1818
ArrayStream.prototype.readable=true;
1919
ArrayStream.prototype.writable=true;
2020
ArrayStream.prototype.pause=noop;

‎test/parallel/test-event-emitter-prepend.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ common.expectsError(() =>{
3131

3232
// Test fallback if prependListener is undefined.
3333
conststream=require('stream');
34-
constutil=require('util');
3534

3635
deleteEventEmitter.prototype.prependListener;
3736

3837
functionWritable(){
3938
this.writable=true;
4039
stream.Stream.call(this);
4140
}
42-
util.inherits(Writable,stream.Stream);
41+
Object.setPrototypeOf(Writable.prototype,stream.Stream.prototype);
42+
Object.setPrototypeOf(Writable,stream.Stream);
4343

4444
functionReadable(){
4545
this.readable=true;
4646
stream.Stream.call(this);
4747
}
48-
util.inherits(Readable,stream.Stream);
48+
Object.setPrototypeOf(Readable.prototype,stream.Stream.prototype);
49+
Object.setPrototypeOf(Readable,stream.Stream);
4950

5051
constw=newWritable();
5152
constr=newReadable();

‎test/parallel/test-event-emitter-subclass.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
constcommon=require('../common');
2424
constassert=require('assert');
2525
constEventEmitter=require('events').EventEmitter;
26-
constutil=require('util');
2726

28-
util.inherits(MyEE,EventEmitter);
27+
Object.setPrototypeOf(MyEE.prototype,EventEmitter.prototype);
28+
Object.setPrototypeOf(MyEE,EventEmitter);
2929

3030
functionMyEE(cb){
3131
this.once(1,cb);
@@ -38,7 +38,8 @@ const myee = new MyEE(common.mustCall());
3838

3939
myee.hasOwnProperty('usingDomains');
4040

41-
util.inherits(ErrorEE,EventEmitter);
41+
Object.setPrototypeOf(ErrorEE.prototype,EventEmitter.prototype);
42+
Object.setPrototypeOf(ErrorEE,EventEmitter);
4243
functionErrorEE(){
4344
this.emit('error',newError('blerg'));
4445
}

‎test/parallel/test-http-upgrade-server.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
require('../common');
2525
constassert=require('assert');
2626

27-
constutil=require('util');
2827
constnet=require('net');
2928
consthttp=require('http');
3029

@@ -69,7 +68,8 @@ function testServer(){
6968
});
7069
}
7170

72-
util.inherits(testServer,http.Server);
71+
Object.setPrototypeOf(testServer.prototype,http.Server.prototype);
72+
Object.setPrototypeOf(testServer,http.Server);
7373

7474

7575
functionwriteReq(socket,data,encoding){

‎test/parallel/test-stream-duplex-destroy.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
constcommon=require('../common');
44
const{ Duplex }=require('stream');
55
constassert=require('assert');
6-
const{ inherits }=require('util');
76

87
{
98
constduplex=newDuplex({
@@ -190,7 +189,8 @@ const{inherits } = require('util');
190189
Duplex.call(this);
191190
}
192191

193-
inherits(MyDuplex,Duplex);
192+
Object.setPrototypeOf(MyDuplex.prototype,Duplex.prototype);
193+
Object.setPrototypeOf(MyDuplex,Duplex);
194194

195195
newMyDuplex();
196196
}

‎test/parallel/test-stream-pipe-cleanup.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
require('../common');
2626
conststream=require('stream');
2727
constassert=require('assert');
28-
constutil=require('util');
2928

3029
functionWritable(){
3130
this.writable=true;
3231
this.endCalls=0;
3332
stream.Stream.call(this);
3433
}
35-
util.inherits(Writable,stream.Stream);
34+
Object.setPrototypeOf(Writable.prototype,stream.Stream.prototype);
35+
Object.setPrototypeOf(Writable,stream.Stream);
3636
Writable.prototype.end=function(){
3737
this.endCalls++;
3838
};
@@ -45,13 +45,15 @@ function Readable(){
4545
this.readable=true;
4646
stream.Stream.call(this);
4747
}
48-
util.inherits(Readable,stream.Stream);
48+
Object.setPrototypeOf(Readable.prototype,stream.Stream.prototype);
49+
Object.setPrototypeOf(Readable,stream.Stream);
4950

5051
functionDuplex(){
5152
this.readable=true;
5253
Writable.call(this);
5354
}
54-
util.inherits(Duplex,Writable);
55+
Object.setPrototypeOf(Duplex.prototype,Writable.prototype);
56+
Object.setPrototypeOf(Duplex,Writable);
5557

5658
leti=0;
5759
constlimit=100;

‎test/parallel/test-stream-pipe-event.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
require('../common');
2424
conststream=require('stream');
2525
constassert=require('assert');
26-
constutil=require('util');
2726

2827
functionWritable(){
2928
this.writable=true;
3029
stream.Stream.call(this);
3130
}
32-
util.inherits(Writable,stream.Stream);
31+
Object.setPrototypeOf(Writable.prototype,stream.Stream.prototype);
32+
Object.setPrototypeOf(Writable,stream.Stream);
3333

3434
functionReadable(){
3535
this.readable=true;
3636
stream.Stream.call(this);
3737
}
38-
util.inherits(Readable,stream.Stream);
38+
Object.setPrototypeOf(Readable.prototype,stream.Stream.prototype);
39+
Object.setPrototypeOf(Readable,stream.Stream);
3940

4041
letpassed=false;
4142

‎test/parallel/test-stream-readable-destroy.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
constcommon=require('../common');
44
const{ Readable }=require('stream');
55
constassert=require('assert');
6-
const{ inherits }=require('util');
76

87
{
98
constread=newReadable({
@@ -160,7 +159,8 @@ const{inherits } = require('util');
160159
Readable.call(this);
161160
}
162161

163-
inherits(MyReadable,Readable);
162+
Object.setPrototypeOf(MyReadable.prototype,Readable.prototype);
163+
Object.setPrototypeOf(MyReadable,Readable);
164164

165165
newMyReadable();
166166
}

‎test/parallel/test-stream-writable-destroy.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
constcommon=require('../common');
44
const{ Writable }=require('stream');
55
constassert=require('assert');
6-
const{ inherits }=require('util');
76

87
{
98
constwrite=newWritable({
@@ -199,7 +198,8 @@ const{inherits } = require('util');
199198
Writable.call(this);
200199
}
201200

202-
inherits(MyWritable,Writable);
201+
Object.setPrototypeOf(MyWritable.prototype,Writable.prototype);
202+
Object.setPrototypeOf(MyWritable,Writable);
203203

204204
newMyWritable();
205205
}

‎test/parallel/test-util-format.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ function BadCustomError(msg){
312312
Object.defineProperty(this,'name',
313313
{value: 'BadCustomError',enumerable: false});
314314
}
315-
util.inherits(BadCustomError,Error);
315+
Object.setPrototypeOf(BadCustomError.prototype,Error.prototype);
316+
Object.setPrototypeOf(BadCustomError,Error);
316317
assert.strictEqual(util.format(newBadCustomError('foo')),
317318
'[BadCustomError: foo]');

0 commit comments

Comments
(0)