summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZYSzys <17367077526@163.com>2018-12-28 12:10:45 +0800
committerRich Trott <rtrott@gmail.com>2018-12-30 19:42:18 -0800
commit2f981cdd5824845aeaf0abb0412b64bb31f49225 (patch)
tree37ad8a5e06e8b3c133424a481c78bbec636d5591
parenta2f81df5a779d2d1414528a79925853eebf166a7 (diff)
downloadandroid-node-v8-2f981cdd5824845aeaf0abb0412b64bb31f49225.tar.gz
android-node-v8-2f981cdd5824845aeaf0abb0412b64bb31f49225.tar.bz2
android-node-v8-2f981cdd5824845aeaf0abb0412b64bb31f49225.zip
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>
-rw-r--r--test/common/arraystream.js4
-rw-r--r--test/fixtures/repl-tab-completion-nested-repls.js6
-rw-r--r--test/parallel/test-event-emitter-prepend.js7
-rw-r--r--test/parallel/test-event-emitter-subclass.js7
-rw-r--r--test/parallel/test-http-upgrade-server.js4
-rw-r--r--test/parallel/test-stream-duplex-destroy.js4
-rw-r--r--test/parallel/test-stream-pipe-cleanup.js10
-rw-r--r--test/parallel/test-stream-pipe-event.js7
-rw-r--r--test/parallel/test-stream-readable-destroy.js4
-rw-r--r--test/parallel/test-stream-writable-destroy.js4
-rw-r--r--test/parallel/test-util-format.js3
-rw-r--r--test/parallel/test-util-inspect.js3
-rw-r--r--test/parallel/test-zlib-deflate-raw-inherits.js6
13 files changed, 38 insertions, 31 deletions
diff --git a/test/common/arraystream.js b/test/common/arraystream.js
index dadd6ff048..9c497fcd9b 100644
--- a/test/common/arraystream.js
+++ b/test/common/arraystream.js
@@ -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
@@ -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;
diff --git a/test/fixtures/repl-tab-completion-nested-repls.js b/test/fixtures/repl-tab-completion-nested-repls.js
index 832734a22a..ceff6e7945 100644
--- a/test/fixtures/repl-tab-completion-nested-repls.js
+++ b/test/fixtures/repl-tab-completion-nested-repls.js
@@ -7,7 +7,6 @@
'use strict';
const { Stream } = require('stream');
-const { inherits } = require('util');
function noop() {}
// 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.writable = true;
ArrayStream.prototype.pause = noop;
@@ -47,4 +47,4 @@ putIn.run([
]);
// In Node.js 10.11.0, this next line will terminate the repl silently...
-testMe.complete('inner.o', () => { throw new Error('fhqwhgads'); });
+testMe.complete('inner.o', () => { throw new Error('fhqwhgads'); }); \ No newline at end of file
diff --git a/test/parallel/test-event-emitter-prepend.js b/test/parallel/test-event-emitter-prepend.js
index 3259ea47f9..c5cf009259 100644
--- a/test/parallel/test-event-emitter-prepend.js
+++ b/test/parallel/test-event-emitter-prepend.js
@@ -31,7 +31,6 @@ common.expectsError(() => {
// Test fallback if prependListener is undefined.
const stream = require('stream');
-const util = require('util');
delete EventEmitter.prototype.prependListener;
@@ -39,13 +38,15 @@ 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();
diff --git a/test/parallel/test-event-emitter-subclass.js b/test/parallel/test-event-emitter-subclass.js
index 094565197b..1157f33459 100644
--- a/test/parallel/test-event-emitter-subclass.js
+++ b/test/parallel/test-event-emitter-subclass.js
@@ -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);
@@ -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'));
}
diff --git a/test/parallel/test-http-upgrade-server.js b/test/parallel/test-http-upgrade-server.js
index 4271ad920d..dc97169041 100644
--- a/test/parallel/test-http-upgrade-server.js
+++ b/test/parallel/test-http-upgrade-server.js
@@ -24,7 +24,6 @@
require('../common');
const assert = require('assert');
-const util = require('util');
const net = require('net');
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) {
diff --git a/test/parallel/test-stream-duplex-destroy.js b/test/parallel/test-stream-duplex-destroy.js
index 518998fd18..1108413e72 100644
--- a/test/parallel/test-stream-duplex-destroy.js
+++ b/test/parallel/test-stream-duplex-destroy.js
@@ -3,7 +3,6 @@
const common = require('../common');
const { Duplex } = require('stream');
const assert = require('assert');
-const { inherits } = require('util');
{
const duplex = new Duplex({
@@ -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();
}
diff --git a/test/parallel/test-stream-pipe-cleanup.js b/test/parallel/test-stream-pipe-cleanup.js
index ac0a72a1da..cdb4d503d6 100644
--- a/test/parallel/test-stream-pipe-cleanup.js
+++ b/test/parallel/test-stream-pipe-cleanup.js
@@ -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++;
};
@@ -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;
diff --git a/test/parallel/test-stream-pipe-event.js b/test/parallel/test-stream-pipe-event.js
index 9054a5a166..d7772df6a1 100644
--- a/test/parallel/test-stream-pipe-event.js
+++ b/test/parallel/test-stream-pipe-event.js
@@ -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;
diff --git a/test/parallel/test-stream-readable-destroy.js b/test/parallel/test-stream-readable-destroy.js
index 3354a8755e..8ad375e68b 100644
--- a/test/parallel/test-stream-readable-destroy.js
+++ b/test/parallel/test-stream-readable-destroy.js
@@ -3,7 +3,6 @@
const common = require('../common');
const { Readable } = require('stream');
const assert = require('assert');
-const { inherits } = require('util');
{
const read = new Readable({
@@ -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();
}
diff --git a/test/parallel/test-stream-writable-destroy.js b/test/parallel/test-stream-writable-destroy.js
index 83c941f459..5fbb7ae19b 100644
--- a/test/parallel/test-stream-writable-destroy.js
+++ b/test/parallel/test-stream-writable-destroy.js
@@ -3,7 +3,6 @@
const common = require('../common');
const { Writable } = require('stream');
const assert = require('assert');
-const { inherits } = require('util');
{
const write = new Writable({
@@ -173,7 +172,8 @@ const { inherits } = require('util');
Writable.call(this);
}
- inherits(MyWritable, Writable);
+ Object.setPrototypeOf(MyWritable.prototype, Writable.prototype);
+ Object.setPrototypeOf(MyWritable, Writable);
new MyWritable();
}
diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js
index a90e52946b..9d6b43a52d 100644
--- a/test/parallel/test-util-format.js
+++ b/test/parallel/test-util-format.js
@@ -308,7 +308,8 @@ 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]');
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index 66887a10f4..1816e4db06 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -599,7 +599,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]'
diff --git a/test/parallel/test-zlib-deflate-raw-inherits.js b/test/parallel/test-zlib-deflate-raw-inherits.js
index a24726a3fb..bb53caa9b5 100644
--- a/test/parallel/test-zlib-deflate-raw-inherits.js
+++ b/test/parallel/test-zlib-deflate-raw-inherits.js
@@ -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();