Repair errors that made Bytes (and Bytes.from) non-idempotent

This commit is contained in:
Tony Garnock-Jones 2018-12-08 14:04:13 +00:00
parent cbbd6ffd0c
commit d826aa9116
1 changed files with 3 additions and 1 deletions

View File

@ -133,8 +133,10 @@ function Bytes(maybeByteIterable) {
_installView.call(this, new Uint8Array(maybeByteIterable));
} else if (typeof maybeByteIterable.length === 'number') {
_installView.call(this, Uint8Array.from(maybeByteIterable));
} else if (maybeByteIterable instanceof Bytes) {
_installView.call(this, maybeByteIterable._view);
} else if (typeof maybeByteIterable.size === 'number') {
_installView.call(this, new ArrayBuffer(maybeByteIterable.size));
_installView.call(this, new Uint8Array(maybeByteIterable.size));
for (let i = 0; i < this.size; i++) { this._view[i] = maybeByteIterable.get(i); }
} else {
const e = new TypeError("Attempt to initialize Bytes from unsupported value");