Browse Source

lib: avoid using forEach in LazyTransform

PR-URL: https://github.com/nodejs/node/pull/11582
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6
James M Snell 8 years ago
parent
commit
4d090855c6
  1. 40
      lib/internal/streams/lazy_transform.js

40
lib/internal/streams/lazy_transform.js

@ -14,13 +14,8 @@ function LazyTransform(options) {
} }
util.inherits(LazyTransform, stream.Transform); util.inherits(LazyTransform, stream.Transform);
[ function makeGetter(name) {
'_readableState', return function() {
'_writableState',
'_transformState'
].forEach(function(prop, i, props) {
Object.defineProperty(LazyTransform.prototype, prop, {
get: function() {
stream.Transform.call(this, this._options); stream.Transform.call(this, this._options);
this._writableState.decodeStrings = false; this._writableState.decodeStrings = false;
@ -28,17 +23,38 @@ util.inherits(LazyTransform, stream.Transform);
this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING; this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING;
} }
return this[prop]; return this[name];
}, };
set: function(val) { }
Object.defineProperty(this, prop, {
function makeSetter(name) {
return function(val) {
Object.defineProperty(this, name, {
value: val, value: val,
enumerable: true, enumerable: true,
configurable: true, configurable: true,
writable: true writable: true
}); });
};
}
Object.defineProperties(LazyTransform.prototype, {
_readableState: {
get: makeGetter('_readableState'),
set: makeSetter('_readableState'),
configurable: true,
enumerable: true
}, },
_writableState: {
get: makeGetter('_writableState'),
set: makeSetter('_writableState'),
configurable: true, configurable: true,
enumerable: true enumerable: true
}); },
_transformState: {
get: makeGetter('_transformState'),
set: makeSetter('_transformState'),
configurable: true,
enumerable: true
}
}); });

Loading…
Cancel
Save