File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ function isAnyArrayBuffer(x) {
5555 return s === '[object ArrayBuffer]' || s === '[object SharedArrayBuffer]'
5656}
5757
58+ function isAnyUint8Array ( x ) {
59+ if ( x instanceof Uint8Array ) return true
60+ if ( ! x || ! ArrayBuffer . isView ( x ) || x . BYTES_PER_ELEMENT !== 1 ) return false
61+ return Object . prototype . toString . call ( x ) === '[object Uint8Array]'
62+ }
63+
5864const fromSource = ( x ) => {
5965 if ( x instanceof Uint8Array ) return x
6066 if ( ArrayBuffer . isView ( x ) ) return new Uint8Array ( x . buffer , x . byteOffset , x . byteLength )
@@ -217,7 +223,7 @@ export class TextEncoder {
217223
218224 encodeInto ( str , target ) {
219225 if ( typeof str !== 'string' ) str = `${ str } `
220- if ( ! ( target instanceof Uint8Array ) ) throw new TypeError ( 'Target must be an Uint8Array' )
226+ if ( ! isAnyUint8Array ( target ) ) throw new TypeError ( 'Target must be an Uint8Array' )
221227 if ( target . buffer . detached ) return { read : 0 , written : 0 } // Until https://github.com/whatwg/encoding/issues/324 is resolved
222228
223229 const tlen = target . length
You can’t perform that action at this time.
0 commit comments