Skip to content

Commit

Permalink
test: remove util.inherits() usage
Browse files Browse the repository at this point in the history
Backport-PR-URL: #28795
PR-URL: #25245
Refs: #24755
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
ZYSzys authored and BethGriggs committed Jul 25, 2019
1 parent 4a607fa commit f332265
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions test/common/arraystream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict';

const { Stream } = require('stream');
const { inherits } = require('util');
function noop() {}

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

inherits(ArrayStream, Stream);
Object.setPrototypeOf(ArrayStream.prototype, Stream.prototype);
Object.setPrototypeOf(ArrayStream, Stream);
ArrayStream.prototype.readable = true;
ArrayStream.prototype.writable = true;
ArrayStream.prototype.pause = noop;
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-event-emitter-prepend.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ common.expectsError(() => {

// Test fallback if prependListener is undefined.
const stream = require('stream');
const util = require('util');

delete EventEmitter.prototype.prependListener;

function Writable() {
this.writable = true;
stream.Stream.call(this);
}
util.inherits(Writable, stream.Stream);
Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Writable, stream.Stream);

function Readable() {
this.readable = true;
stream.Stream.call(this);
}
util.inherits(Readable, stream.Stream);
Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Readable, stream.Stream);

const w = new Writable();
const r = new Readable();
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-event-emitter-subclass.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
const common = require('../common');
const assert = require('assert');
const EventEmitter = require('events').EventEmitter;
const util = require('util');

util.inherits(MyEE, EventEmitter);
Object.setPrototypeOf(MyEE.prototype, EventEmitter.prototype);
Object.setPrototypeOf(MyEE, EventEmitter);

function MyEE(cb) {
this.once(1, cb);
Expand All @@ -38,7 +38,8 @@ const myee = new MyEE(common.mustCall());

myee.hasOwnProperty('usingDomains');

util.inherits(ErrorEE, EventEmitter);
Object.setPrototypeOf(ErrorEE.prototype, EventEmitter.prototype);
Object.setPrototypeOf(ErrorEE, EventEmitter);
function ErrorEE() {
this.emit('error', new Error('blerg'));
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-upgrade-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
require('../common');
const assert = require('assert');

const util = require('util');
const net = require('net');
const http = require('http');

Expand Down Expand Up @@ -69,7 +68,8 @@ function testServer() {
});
}

util.inherits(testServer, http.Server);
Object.setPrototypeOf(testServer.prototype, http.Server.prototype);
Object.setPrototypeOf(testServer, http.Server);


function writeReq(socket, data, encoding) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-duplex-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const common = require('../common');
const { Duplex } = require('stream');
const assert = require('assert');
const { inherits } = require('util');

{
const duplex = new Duplex({
Expand Down Expand Up @@ -190,7 +189,8 @@ const { inherits } = require('util');
Duplex.call(this);
}

inherits(MyDuplex, Duplex);
Object.setPrototypeOf(MyDuplex.prototype, Duplex.prototype);
Object.setPrototypeOf(MyDuplex, Duplex);

new MyDuplex();
}
10 changes: 6 additions & 4 deletions test/parallel/test-stream-pipe-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
require('../common');
const stream = require('stream');
const assert = require('assert');
const util = require('util');

function Writable() {
this.writable = true;
this.endCalls = 0;
stream.Stream.call(this);
}
util.inherits(Writable, stream.Stream);
Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Writable, stream.Stream);
Writable.prototype.end = function() {
this.endCalls++;
};
Expand All @@ -45,13 +45,15 @@ function Readable() {
this.readable = true;
stream.Stream.call(this);
}
util.inherits(Readable, stream.Stream);
Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Readable, stream.Stream);

function Duplex() {
this.readable = true;
Writable.call(this);
}
util.inherits(Duplex, Writable);
Object.setPrototypeOf(Duplex.prototype, Writable.prototype);
Object.setPrototypeOf(Duplex, Writable);

let i = 0;
const limit = 100;
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-stream-pipe-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
require('../common');
const stream = require('stream');
const assert = require('assert');
const util = require('util');

function Writable() {
this.writable = true;
stream.Stream.call(this);
}
util.inherits(Writable, stream.Stream);
Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Writable, stream.Stream);

function Readable() {
this.readable = true;
stream.Stream.call(this);
}
util.inherits(Readable, stream.Stream);
Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Readable, stream.Stream);

let passed = false;

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-readable-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const common = require('../common');
const { Readable } = require('stream');
const assert = require('assert');
const { inherits } = require('util');

{
const read = new Readable({
Expand Down Expand Up @@ -160,7 +159,8 @@ const { inherits } = require('util');
Readable.call(this);
}

inherits(MyReadable, Readable);
Object.setPrototypeOf(MyReadable.prototype, Readable.prototype);
Object.setPrototypeOf(MyReadable, Readable);

new MyReadable();
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-writable-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const common = require('../common');
const { Writable } = require('stream');
const assert = require('assert');
const { inherits } = require('util');

{
const write = new Writable({
Expand Down Expand Up @@ -199,7 +198,8 @@ const { inherits } = require('util');
Writable.call(this);
}

inherits(MyWritable, Writable);
Object.setPrototypeOf(MyWritable.prototype, Writable.prototype);
Object.setPrototypeOf(MyWritable, Writable);

new MyWritable();
}
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ function BadCustomError(msg) {
Object.defineProperty(this, 'name',
{ value: 'BadCustomError', enumerable: false });
}
util.inherits(BadCustomError, Error);
Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
Object.setPrototypeOf(BadCustomError, Error);
assert.strictEqual(util.format(new BadCustomError('foo')),
'[BadCustomError: foo]');
3 changes: 2 additions & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
Object.defineProperty(this, 'name',
{ value: 'BadCustomError', enumerable: false });
}
util.inherits(BadCustomError, Error);
Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
Object.setPrototypeOf(BadCustomError, Error);
assert.strictEqual(
util.inspect(new BadCustomError('foo')),
'[BadCustomError: foo]'
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-zlib-deflate-raw-inherits.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

require('../common');
const { DeflateRaw } = require('zlib');
const { inherits } = require('util');
const { Readable } = require('stream');

// validates that zlib.DeflateRaw can be inherited
// with util.inherits
// with Object.setPrototypeOf

function NotInitialized(options) {
DeflateRaw.call(this, options);
this.prop = true;
}
inherits(NotInitialized, DeflateRaw);
Object.setPrototypeOf(NotInitialized.prototype, DeflateRaw.prototype);
Object.setPrototypeOf(NotInitialized, DeflateRaw);

const dest = new NotInitialized();

Expand Down

0 comments on commit f332265

Please sign in to comment.