Implement code path for when TextDecoder() is not available

The primary purpose is to unbreak
https://github.com/cliqz-oss/adblocker/tree/master/bench/comparison
This commit is contained in:
Raymond Hill 2019-04-28 14:07:21 -04:00
parent a207daee89
commit 295f08da97
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 14 additions and 0 deletions

View File

@ -600,11 +600,25 @@
} while ( v !== 0 ); } while ( v !== 0 );
outbuf[j++] = 0x20 /* ' ' */; outbuf[j++] = 0x20 /* ' ' */;
} }
if ( typeof TextDecoder === 'undefined' ) {
return JSON.stringify(
Array.from(new Uint32Array(outbuf.buffer, 0, j >>> 2))
);
}
const textDecoder = new TextDecoder(); const textDecoder = new TextDecoder();
return textDecoder.decode(new Uint8Array(outbuf.buffer, 0, j)); return textDecoder.decode(new Uint8Array(outbuf.buffer, 0, j));
} }
decode(instr, arrbuf) { decode(instr, arrbuf) {
if ( instr.charCodeAt(0) === 0x5B /* '[' */ ) {
const inbuf = Array.isArray(instr);
if ( arrbuf instanceof ArrayBuffer === false ) {
return new Uint32Array(inbuf);
}
const outbuf = new Uint32Array(arrbuf);
outbuf.set(inbuf);
return outbuf;
}
if ( instr.startsWith(this.magic) === false ) { if ( instr.startsWith(this.magic) === false ) {
throw new Error('Invalid µBlock.base64 encoding'); throw new Error('Invalid µBlock.base64 encoding');
} }