mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
6f0ec79e42
Make virtual methods throw an ERR_METHOD_NOT_IMPLEMENTED error instead of emitting it. The error is not recoverable and the only way to handle it is to override the method. PR-URL: https://github.com/nodejs/node/pull/31912 Refs: https://github.com/nodejs/node/pull/31818#pullrequestreview-359403469 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
42 lines
785 B
JavaScript
42 lines
785 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
const { Writable } = require('stream');
|
|
|
|
const bufferBlerg = Buffer.from('blerg');
|
|
const w = new Writable();
|
|
|
|
assert.throws(
|
|
() => {
|
|
w.end(bufferBlerg);
|
|
},
|
|
{
|
|
name: 'Error',
|
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
|
message: 'The _write() method is not implemented'
|
|
}
|
|
);
|
|
|
|
const _write = common.mustCall((chunk, _, next) => {
|
|
next();
|
|
});
|
|
|
|
const _writev = common.mustCall((chunks, next) => {
|
|
assert.strictEqual(chunks.length, 2);
|
|
next();
|
|
});
|
|
|
|
const w2 = new Writable({ write: _write, writev: _writev });
|
|
|
|
assert.strictEqual(w2._write, _write);
|
|
assert.strictEqual(w2._writev, _writev);
|
|
|
|
w2.write(bufferBlerg);
|
|
|
|
w2.cork();
|
|
w2.write(bufferBlerg);
|
|
w2.write(bufferBlerg);
|
|
|
|
w2.end();
|