test: remove util.inherits() usage

PR-URL: https://github.com/nodejs/node/pull/25245
Refs: https://github.com/nodejs/node/pull/24755
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
ZYSzys 2018-12-28 12:10:45 +08:00 committed by Rich Trott
parent a2f81df5a7
commit 2f981cdd58
13 changed files with 38 additions and 31 deletions

View File

@ -2,7 +2,6 @@
'use strict'; 'use strict';
const { Stream } = require('stream'); const { Stream } = require('stream');
const { inherits } = require('util');
function noop() {} function noop() {}
// A stream to push an array into a REPL // A stream to push an array into a REPL
@ -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.readable = true;
ArrayStream.prototype.writable = true; ArrayStream.prototype.writable = true;
ArrayStream.prototype.pause = noop; ArrayStream.prototype.pause = noop;

View File

@ -7,7 +7,6 @@
'use strict'; 'use strict';
const { Stream } = require('stream'); const { Stream } = require('stream');
const { inherits } = require('util');
function noop() {} function noop() {}
// A stream to push an array into a REPL // A stream to push an array into a REPL
@ -19,7 +18,8 @@ function ArrayStream() {
}; };
} }
inherits(ArrayStream, Stream); Object.setPrototypeOf(ArrayStream.prototype, Stream.prototype);
Object.setPrototypeOf(ArrayStream, Stream);
ArrayStream.prototype.readable = true; ArrayStream.prototype.readable = true;
ArrayStream.prototype.writable = true; ArrayStream.prototype.writable = true;
ArrayStream.prototype.pause = noop; ArrayStream.prototype.pause = noop;

View File

@ -31,7 +31,6 @@ common.expectsError(() => {
// Test fallback if prependListener is undefined. // Test fallback if prependListener is undefined.
const stream = require('stream'); const stream = require('stream');
const util = require('util');
delete EventEmitter.prototype.prependListener; delete EventEmitter.prototype.prependListener;
@ -39,13 +38,15 @@ function Writable() {
this.writable = true; this.writable = true;
stream.Stream.call(this); stream.Stream.call(this);
} }
util.inherits(Writable, stream.Stream); Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Writable, stream.Stream);
function Readable() { function Readable() {
this.readable = true; this.readable = true;
stream.Stream.call(this); 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 w = new Writable();
const r = new Readable(); const r = new Readable();

View File

@ -23,9 +23,9 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const EventEmitter = require('events').EventEmitter; 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) { function MyEE(cb) {
this.once(1, cb); this.once(1, cb);
@ -38,7 +38,8 @@ const myee = new MyEE(common.mustCall());
myee.hasOwnProperty('usingDomains'); myee.hasOwnProperty('usingDomains');
util.inherits(ErrorEE, EventEmitter); Object.setPrototypeOf(ErrorEE.prototype, EventEmitter.prototype);
Object.setPrototypeOf(ErrorEE, EventEmitter);
function ErrorEE() { function ErrorEE() {
this.emit('error', new Error('blerg')); this.emit('error', new Error('blerg'));
} }

View File

@ -24,7 +24,6 @@
require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const util = require('util');
const net = require('net'); const net = require('net');
const http = require('http'); const http = require('http');
@ -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) { function writeReq(socket, data, encoding) {

View File

@ -3,7 +3,6 @@
const common = require('../common'); const common = require('../common');
const { Duplex } = require('stream'); const { Duplex } = require('stream');
const assert = require('assert'); const assert = require('assert');
const { inherits } = require('util');
{ {
const duplex = new Duplex({ const duplex = new Duplex({
@ -190,7 +189,8 @@ const { inherits } = require('util');
Duplex.call(this); Duplex.call(this);
} }
inherits(MyDuplex, Duplex); Object.setPrototypeOf(MyDuplex.prototype, Duplex.prototype);
Object.setPrototypeOf(MyDuplex, Duplex);
new MyDuplex(); new MyDuplex();
} }

View File

@ -25,14 +25,14 @@
require('../common'); require('../common');
const stream = require('stream'); const stream = require('stream');
const assert = require('assert'); const assert = require('assert');
const util = require('util');
function Writable() { function Writable() {
this.writable = true; this.writable = true;
this.endCalls = 0; this.endCalls = 0;
stream.Stream.call(this); 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() { Writable.prototype.end = function() {
this.endCalls++; this.endCalls++;
}; };
@ -45,13 +45,15 @@ function Readable() {
this.readable = true; this.readable = true;
stream.Stream.call(this); stream.Stream.call(this);
} }
util.inherits(Readable, stream.Stream); Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Readable, stream.Stream);
function Duplex() { function Duplex() {
this.readable = true; this.readable = true;
Writable.call(this); Writable.call(this);
} }
util.inherits(Duplex, Writable); Object.setPrototypeOf(Duplex.prototype, Writable.prototype);
Object.setPrototypeOf(Duplex, Writable);
let i = 0; let i = 0;
const limit = 100; const limit = 100;

View File

@ -23,19 +23,20 @@
require('../common'); require('../common');
const stream = require('stream'); const stream = require('stream');
const assert = require('assert'); const assert = require('assert');
const util = require('util');
function Writable() { function Writable() {
this.writable = true; this.writable = true;
stream.Stream.call(this); stream.Stream.call(this);
} }
util.inherits(Writable, stream.Stream); Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Writable, stream.Stream);
function Readable() { function Readable() {
this.readable = true; this.readable = true;
stream.Stream.call(this); stream.Stream.call(this);
} }
util.inherits(Readable, stream.Stream); Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Readable, stream.Stream);
let passed = false; let passed = false;

View File

@ -3,7 +3,6 @@
const common = require('../common'); const common = require('../common');
const { Readable } = require('stream'); const { Readable } = require('stream');
const assert = require('assert'); const assert = require('assert');
const { inherits } = require('util');
{ {
const read = new Readable({ const read = new Readable({
@ -160,7 +159,8 @@ const { inherits } = require('util');
Readable.call(this); Readable.call(this);
} }
inherits(MyReadable, Readable); Object.setPrototypeOf(MyReadable.prototype, Readable.prototype);
Object.setPrototypeOf(MyReadable, Readable);
new MyReadable(); new MyReadable();
} }

View File

@ -3,7 +3,6 @@
const common = require('../common'); const common = require('../common');
const { Writable } = require('stream'); const { Writable } = require('stream');
const assert = require('assert'); const assert = require('assert');
const { inherits } = require('util');
{ {
const write = new Writable({ const write = new Writable({
@ -173,7 +172,8 @@ const { inherits } = require('util');
Writable.call(this); Writable.call(this);
} }
inherits(MyWritable, Writable); Object.setPrototypeOf(MyWritable.prototype, Writable.prototype);
Object.setPrototypeOf(MyWritable, Writable);
new MyWritable(); new MyWritable();
} }

View File

@ -308,7 +308,8 @@ function BadCustomError(msg) {
Object.defineProperty(this, 'name', Object.defineProperty(this, 'name',
{ value: 'BadCustomError', enumerable: false }); { 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')), assert.strictEqual(util.format(new BadCustomError('foo')),
'[BadCustomError: foo]'); '[BadCustomError: foo]');

View File

@ -599,7 +599,8 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
Object.defineProperty(this, 'name', Object.defineProperty(this, 'name',
{ value: 'BadCustomError', enumerable: false }); { value: 'BadCustomError', enumerable: false });
} }
util.inherits(BadCustomError, Error); Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
Object.setPrototypeOf(BadCustomError, Error);
assert.strictEqual( assert.strictEqual(
util.inspect(new BadCustomError('foo')), util.inspect(new BadCustomError('foo')),
'[BadCustomError: foo]' '[BadCustomError: foo]'

View File

@ -2,17 +2,17 @@
require('../common'); require('../common');
const { DeflateRaw } = require('zlib'); const { DeflateRaw } = require('zlib');
const { inherits } = require('util');
const { Readable } = require('stream'); const { Readable } = require('stream');
// validates that zlib.DeflateRaw can be inherited // validates that zlib.DeflateRaw can be inherited
// with util.inherits // with Object.setPrototypeOf
function NotInitialized(options) { function NotInitialized(options) {
DeflateRaw.call(this, options); DeflateRaw.call(this, options);
this.prop = true; this.prop = true;
} }
inherits(NotInitialized, DeflateRaw); Object.setPrototypeOf(NotInitialized.prototype, DeflateRaw.prototype);
Object.setPrototypeOf(NotInitialized, DeflateRaw);
const dest = new NotInitialized(); const dest = new NotInitialized();