Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v14.x] stream: runtime deprecate Transform._transformState #33126

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/api/deprecations.md
Expand Up @@ -2695,6 +2695,18 @@ The `repl` module exports a `_builtinLibs` property that contains an array with
native modules. It was incomplete so far and instead it's better to rely upon
`require('module').builtinModules`.

<a id="DEP0XXX"></a>
### DEP0XXX: `Transform._transformState`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33126
description: Runtime deprecation.
-->
Type: Runtime
`Transform._transformState` will be removed in future versions where it is
no longer required due to simplification of the implementation.

[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
Expand Down
26 changes: 20 additions & 6 deletions lib/_stream_transform.js
Expand Up @@ -64,7 +64,9 @@
'use strict';

const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol
} = primordials;

module.exports = Transform;
Expand All @@ -75,12 +77,15 @@ const {
ERR_TRANSFORM_WITH_LENGTH_0
} = require('internal/errors').codes;
const Duplex = require('_stream_duplex');
const internalUtil = require('internal/util');

ObjectSetPrototypeOf(Transform.prototype, Duplex.prototype);
ObjectSetPrototypeOf(Transform, Duplex);

const kTransformState = Symbol('kTransformState');

function afterTransform(er, data) {
const ts = this._transformState;
const ts = this[kTransformState];
ts.transforming = false;

const cb = ts.writecb;
Expand Down Expand Up @@ -111,7 +116,7 @@ function Transform(options) {

Duplex.call(this, options);

this._transformState = {
this[kTransformState] = {
afterTransform: afterTransform.bind(this),
needTransform: false,
transforming: false,
Expand Down Expand Up @@ -147,8 +152,17 @@ function prefinish() {
}
}

ObjectDefineProperty(Transform.prototype, '_transformState', {
get: internalUtil.deprecate(function() {
return this[kTransformState];
}, 'Transform.prototype._transformState is deprecated', 'DEP0XXX'),
set: internalUtil.deprecate(function(val) {
this[kTransformState] = val;
}, 'Transform.prototype._transformState is deprecated', 'DEP0XXX')
});

Transform.prototype.push = function(chunk, encoding) {
this._transformState.needTransform = false;
this[kTransformState].needTransform = false;
return Duplex.prototype.push.call(this, chunk, encoding);
};

Expand All @@ -167,7 +181,7 @@ Transform.prototype._transform = function(chunk, encoding, cb) {
};

Transform.prototype._write = function(chunk, encoding, cb) {
const ts = this._transformState;
const ts = this[kTransformState];
ts.writecb = cb;
ts.writechunk = chunk;
ts.writeencoding = encoding;
Expand All @@ -184,7 +198,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
// _transform does all the work.
// That we got here means that the readable side wants more data.
Transform.prototype._read = function(n) {
const ts = this._transformState;
const ts = this[kTransformState];

if (ts.writechunk !== null && !ts.transforming) {
ts.transforming = true;
Expand Down Expand Up @@ -215,7 +229,7 @@ function done(stream, er, data) {
if (stream._writableState.length)
throw new ERR_TRANSFORM_WITH_LENGTH_0();

if (stream._transformState.transforming)
if (stream[kTransformState].transforming)
throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
return stream.push(null);
}