diff --git a/lib/tls.js b/lib/tls.js index 781f4c53922..291c31cedcf 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -216,9 +216,23 @@ CryptoStream.prototype._done = function() { }; -CryptoStream.prototype.fd = -1; -CryptoStream.prototype.__defineGetter__('readyState', - net.Socket.prototype.__lookupGetter__('readyState')); +// readyState is deprecated. Don't use it. +Object.defineProperty(CryptoStream.prototype, 'readyState', { + get: function() { + if (this._connecting) { + return 'opening'; + } else if (this.readable && this.writable) { + return 'open'; + } else if (this.readable && !this.writable) { + return 'readOnly'; + } else if (!this.readable && this.writable) { + return 'writeOnly'; + } else { + return 'closed'; + } + } +}); + // Move decrypted, clear data out into the application. // From the user's perspective this occurs as a 'data' event diff --git a/test/simple/test-tls-set-encoding.js b/test/simple/test-tls-set-encoding.js index 6634110fee6..2956eec0e28 100644 --- a/test/simple/test-tls-set-encoding.js +++ b/test/simple/test-tls-set-encoding.js @@ -54,6 +54,11 @@ server.listen(common.PORT, function() { client.on('close', function() { + // readyState is deprecated but we want to make + // sure this isn't triggering an assert in lib/net.js + // See issue #1069. + assert.equal('closed', client.readyState); + assert.equal(buffer, message); console.log(message); server.close();