Browse Source

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.
patch-2
Ryan X. Charles 11 years ago
parent
commit
9122807ecb
  1. 2
      lib/SIN.js
  2. 12
      util/EncodedData.js
  3. 2
      util/VersionedData.js

2
lib/SIN.js

@ -8,7 +8,7 @@ function SIN(type, payload) {
return; return;
}; };
this.data = new Buffer(1 + 1 + payload.length); 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.prefix(0x0F); // SIN magic number, in numberspace
this.type(type); this.type(type);
this.payload(payload); this.payload(payload);

12
util/EncodedData.js

@ -8,9 +8,14 @@ var base58 = require('../lib/Base58').base58Check;
function EncodedData(data, encoding) { function EncodedData(data, encoding) {
this.data = data; this.data = data;
if (!encoding && (typeof data == 'string')) { 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 { } 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) { EncodedData.prototype.encoding = function(encoding) {
if (encoding && (encoding != this._encoding)) { if (encoding && (encoding != this._encoding)) {
this.data = this.as(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; return this._encoding;
}; };

2
util/VersionedData.js

@ -9,7 +9,7 @@ function VersionedData(version, payload) {
return; return;
}; };
this.data = new Buffer(payload.length + 1); this.data = new Buffer(payload.length + 1);
this.__proto__ = this.encodings['binary']; this.encoding('binary');
this.version(version); this.version(version);
this.payload(payload); this.payload(payload);
}; };

Loading…
Cancel
Save