From 9122807ecb3ed6d8a17933a04bd70b01cdc9381c Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 15 Jul 2014 17:14:04 -0700 Subject: [PATCH] remove __proto__ from EncodedData and family EncodedData was setting "converter" and "_encoding" by setting them on the prototype of the object. This was probably done to enable overriding these functions. However, overriding was never actually used anywhere, and setting the __proto__ is deprecated. So I have remove all instances of setting __proto__ for EncodedData-ish classes, and instead just set "convert" and "_encoding" on the object directly. --- lib/SIN.js | 2 +- util/EncodedData.js | 12 +++++++++--- util/VersionedData.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/SIN.js b/lib/SIN.js index f93ae90..dc69499 100644 --- a/lib/SIN.js +++ b/lib/SIN.js @@ -8,7 +8,7 @@ function SIN(type, payload) { return; }; this.data = new Buffer(1 + 1 + payload.length); - this.__proto__ = this.encodings['binary']; + this.encoding('binary'); this.prefix(0x0F); // SIN magic number, in numberspace this.type(type); this.payload(payload); diff --git a/util/EncodedData.js b/util/EncodedData.js index dcd33d0..87e25d2 100644 --- a/util/EncodedData.js +++ b/util/EncodedData.js @@ -8,9 +8,14 @@ var base58 = require('../lib/Base58').base58Check; function EncodedData(data, encoding) { this.data = data; if (!encoding && (typeof data == 'string')) { - this.__proto__ = this.encodings['base58']; + encoding = 'base58'; + this.converters = this.encodings[encoding].converters; + this._encoding = this.encodings[encoding]._encoding; } else { - this.__proto__ = this.encodings[encoding || 'binary']; + if (typeof this.encodings[encoding] === 'undefined') + encoding = 'binary'; + this.converters = this.encodings['binary'].converters; + this._encoding = this.encodings['binary']._encoding; } }; @@ -18,7 +23,8 @@ function EncodedData(data, encoding) { EncodedData.prototype.encoding = function(encoding) { if (encoding && (encoding != this._encoding)) { this.data = this.as(encoding); - this.__proto__ = this.encodings[encoding]; + this.converters = this.encodings[encoding].converters; + this._encoding = this.encodings[encoding]._encoding; } return this._encoding; }; diff --git a/util/VersionedData.js b/util/VersionedData.js index 8614b0f..fa0d348 100644 --- a/util/VersionedData.js +++ b/util/VersionedData.js @@ -9,7 +9,7 @@ function VersionedData(version, payload) { return; }; this.data = new Buffer(payload.length + 1); - this.__proto__ = this.encodings['binary']; + this.encoding('binary'); this.version(version); this.payload(payload); };