summaryrefslogtreecommitdiff
path: root/lib/crypto.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-04-08 08:43:20 -0700
committerFedor Indutny <fedor.indutny@gmail.com>2013-04-21 09:33:10 -0400
commit4bf1d1007fbd249d1d07b662278a5a34c6be12fd (patch)
treec18161401dd3dd47d054c352085e2752020400d5 /lib/crypto.js
parentc4379a5554e421c55a38baaee4775b5c13a288d3 (diff)
downloadnodejs-4bf1d1007fbd249d1d07b662278a5a34c6be12fd.tar.gz
nodejs-4bf1d1007fbd249d1d07b662278a5a34c6be12fd.tar.bz2
nodejs-4bf1d1007fbd249d1d07b662278a5a34c6be12fd.zip
crypto: LazyTransform on properties, not methods
It needs to apply the Transform class when the _readableState, _writableState, or _transformState properties are accessed, otherwise things like setEncoding and on('data') don't work properly. Also, the methods wrappers are no longer needed, since they're only problematic because they access the undefined properties.
Diffstat (limited to 'lib/crypto.js')
-rw-r--r--lib/crypto.js34
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/crypto.js b/lib/crypto.js
index 1ae4c7aae..8793c5c48 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -155,19 +155,27 @@ function LazyTransform(options) {
}
util.inherits(LazyTransform, stream.Transform);
-var transformMethods = ['read', 'write', 'end', 'pipe', 'unpipe',
- 'setEncoding', 'pause', 'resume'];
-
-transformMethods.forEach(function(action, i, actions) {
- LazyTransform.prototype[action] = function() {
- stream.Transform.call(this, this._options);
-
- actions.forEach(function(action) {
- this[action] = stream.Transform.prototype[action];
- }, this);
-
- return this[action].apply(this, arguments);
- };
+[
+ '_readableState',
+ '_writableState',
+ '_transformState'
+].forEach(function(prop, i, props) {
+ Object.defineProperty(LazyTransform.prototype, prop, {
+ get: function() {
+ stream.Transform.call(this, this._options);
+ return this[prop];
+ },
+ set: function(val) {
+ Object.defineProperty(this, prop, {
+ value: val,
+ enumerable: true,
+ configurable: true,
+ writable: true
+ });
+ },
+ configurable: true,
+ enumerable: true
+ });
});