forked from syndicate-lang/preserves
Repair errors that made Bytes (and Bytes.from) non-idempotent
This commit is contained in:
parent
cbbd6ffd0c
commit
d826aa9116
|
@ -133,8 +133,10 @@ function Bytes(maybeByteIterable) {
|
||||||
_installView.call(this, new Uint8Array(maybeByteIterable));
|
_installView.call(this, new Uint8Array(maybeByteIterable));
|
||||||
} else if (typeof maybeByteIterable.length === 'number') {
|
} else if (typeof maybeByteIterable.length === 'number') {
|
||||||
_installView.call(this, Uint8Array.from(maybeByteIterable));
|
_installView.call(this, Uint8Array.from(maybeByteIterable));
|
||||||
|
} else if (maybeByteIterable instanceof Bytes) {
|
||||||
|
_installView.call(this, maybeByteIterable._view);
|
||||||
} else if (typeof maybeByteIterable.size === 'number') {
|
} 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); }
|
for (let i = 0; i < this.size; i++) { this._view[i] = maybeByteIterable.get(i); }
|
||||||
} else {
|
} else {
|
||||||
const e = new TypeError("Attempt to initialize Bytes from unsupported value");
|
const e = new TypeError("Attempt to initialize Bytes from unsupported value");
|
||||||
|
|
Loading…
Reference in New Issue