add encodedData.isValid()

This commit is contained in:
Stephen Pair 2013-08-24 00:42:31 -04:00
parent ca35fa4506
commit 1fe60316a8
1 changed files with 10 additions and 0 deletions

View File

@ -42,6 +42,16 @@ function ClassSpec(b) {
this.withEncoding('binary');
};
// Boolean protocol for testing if valid
EncodedData.prototype.isValid = function() {
try {
this.validate();
return true;
} catch(e) {
return false;
}
};
// subclasses can override to do more stuff
EncodedData.prototype.validate = function() {
this._validate();