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.
This commit is contained in:
Ryan X. Charles 2014-07-15 17:14:04 -07:00
parent 86da48a25d
commit 9122807ecb
3 changed files with 11 additions and 5 deletions

View File

@ -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);

View File

@ -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;
};

View File

@ -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);
};