Skip to content

Commit 4ca4b54

Browse files
ZYSzystargos
authored andcommitted
test: remove util.inherits() usage
PR-URL: #25245 Refs: #24755 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 1be566b commit 4ca4b54

13 files changed

+38
-31
lines changed

test/common/arraystream.js

+2-2
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
function noop() {}
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/fixtures/repl-tab-completion-nested-repls.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
'use strict';
88

99
const { Stream } = require('stream');
10-
const { inherits } = require('util');
1110
function noop() {}
1211

1312
// A stream to push an array into a REPL
@@ -19,7 +18,8 @@ function ArrayStream() {
1918
};
2019
}
2120

22-
inherits(ArrayStream, Stream);
21+
Object.setPrototypeOf(ArrayStream.prototype, Stream.prototype);
22+
Object.setPrototypeOf(ArrayStream, Stream);
2323
ArrayStream.prototype.readable = true;
2424
ArrayStream.prototype.writable = true;
2525
ArrayStream.prototype.pause = noop;
@@ -47,4 +47,4 @@ putIn.run([
4747
]);
4848

4949
// In Node.js 10.11.0, this next line will terminate the repl silently...
50-
testMe.complete('inner.o', () => { throw new Error('fhqwhgads'); });
50+
testMe.complete('inner.o', () => { throw new Error('fhqwhgads'); });

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ common.expectsError(() => {
3131

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

3635
delete EventEmitter.prototype.prependListener;
3736

3837
function Writable() {
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
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
const w = new Writable();
5152
const r = new Readable();

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525
const EventEmitter = require('events').EventEmitter;
26-
const util = require('util');
2726

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

3030
function MyEE(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
function ErrorEE() {
4344
this.emit('error', new Error('blerg'));
4445
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
require('../common');
2525
const assert = require('assert');
2626

27-
const util = require('util');
2827
const net = require('net');
2928
const http = 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
function writeReq(socket, data, encoding) {

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

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

87
{
98
const duplex = new Duplex({
@@ -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
new MyDuplex();
196196
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
require('../common');
2626
const stream = require('stream');
2727
const assert = require('assert');
28-
const util = require('util');
2928

3029
function Writable() {
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
function Duplex() {
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
let i = 0;
5759
const limit = 100;

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
require('../common');
2424
const stream = require('stream');
2525
const assert = require('assert');
26-
const util = require('util');
2726

2827
function Writable() {
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
function Readable() {
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
let passed = false;
4142

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

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

87
{
98
const read = new Readable({
@@ -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
new MyReadable();
166166
}

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

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

87
{
98
const write = new Writable({
@@ -173,7 +172,8 @@ const { inherits } = require('util');
173172
Writable.call(this);
174173
}
175174

176-
inherits(MyWritable, Writable);
175+
Object.setPrototypeOf(MyWritable.prototype, Writable.prototype);
176+
Object.setPrototypeOf(MyWritable, Writable);
177177

178178
new MyWritable();
179179
}

test/parallel/test-util-format.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ function BadCustomError(msg) {
304304
Object.defineProperty(this, 'name',
305305
{ value: 'BadCustomError', enumerable: false });
306306
}
307-
util.inherits(BadCustomError, Error);
307+
Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
308+
Object.setPrototypeOf(BadCustomError, Error);
308309
assert.strictEqual(util.format(new BadCustomError('foo')),
309310
'[BadCustomError: foo]');

test/parallel/test-util-inspect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
599599
Object.defineProperty(this, 'name',
600600
{ value: 'BadCustomError', enumerable: false });
601601
}
602-
util.inherits(BadCustomError, Error);
602+
Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
603+
Object.setPrototypeOf(BadCustomError, Error);
603604
assert.strictEqual(
604605
util.inspect(new BadCustomError('foo')),
605606
'[BadCustomError: foo]'

test/parallel/test-zlib-deflate-raw-inherits.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
require('../common');
44
const { DeflateRaw } = require('zlib');
5-
const { inherits } = require('util');
65
const { Readable } = require('stream');
76

87
// validates that zlib.DeflateRaw can be inherited
9-
// with util.inherits
8+
// with Object.setPrototypeOf
109

1110
function NotInitialized(options) {
1211
DeflateRaw.call(this, options);
1312
this.prop = true;
1413
}
15-
inherits(NotInitialized, DeflateRaw);
14+
Object.setPrototypeOf(NotInitialized.prototype, DeflateRaw.prototype);
15+
Object.setPrototypeOf(NotInitialized, DeflateRaw);
1616

1717
const dest = new NotInitialized();
1818

0 commit comments

Comments
 (0)