|
5 | 5 | var clz32 = Math.clz32 || function(x) {return 31 - log(x >>> 0) / LN2 | 0}; |
6 | 6 | var fromCharCode = String.fromCharCode; |
7 | 7 | var Object_prototype_toString = ({}).toString; |
| 8 | + var NativeSharedArrayBuffer = window["SharedArrayBuffer"]; |
| 9 | + var sharedArrayBufferString = NativeSharedArrayBuffer ? Object_prototype_toString.call(NativeSharedArrayBuffer) : ""; |
8 | 10 | var NativeUint8Array = window.Uint8Array; |
9 | 11 | var patchedU8Array = NativeUint8Array || Array; |
10 | | - var ArrayBufferString = Object_prototype_toString.call((window.ArrayBuffer || patchedU8Array).prototype); |
| 12 | + var arrayBufferString = Object_prototype_toString.call((NativeUint8Array ? ArrayBuffer : patchedU8Array).prototype); |
11 | 13 | function decoderReplacer(encoded){ |
12 | 14 | var codePoint = encoded.charCodeAt(0) << 24; |
13 | 15 | var leadingOnes = clz32(~codePoint)|0; |
|
32 | 34 | return result; |
33 | 35 | } |
34 | 36 | function TextDecoder(){}; |
35 | | - TextDecoder.prototype.decode = function(inputArrayOrBuffer){ |
| 37 | + TextDecoder["prototype"]["decode"] = function(inputArrayOrBuffer){ |
36 | 38 | var buffer = (inputArrayOrBuffer && inputArrayOrBuffer.buffer) || inputArrayOrBuffer; |
37 | | - if (Object_prototype_toString.call(buffer) !== ArrayBufferString) |
| 39 | + var asObjectString = Object_prototype_toString.call(buffer); |
| 40 | + if (asObjectString !== arrayBufferString && asObjectString !== sharedArrayBufferString) |
38 | 41 | throw Error("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'"); |
39 | 42 | var inputAs8 = NativeUint8Array ? new patchedU8Array(buffer) : buffer; |
40 | 43 | var resultingString = ""; |
|
74 | 77 | ); |
75 | 78 | } |
76 | 79 | function TextEncoder(){}; |
77 | | - TextEncoder.prototype.encode = function(inputString){ |
| 80 | + TextEncoder["prototype"]["encode"] = function(inputString){ |
78 | 81 | // 0xc0 => 0b11000000; 0xff => 0b11111111; 0xc0-0xff => 0b11xxxxxx |
79 | 82 | // 0x80 => 0b10000000; 0xbf => 0b10111111; 0x80-0xbf => 0b10xxxxxx |
80 | 83 | var encodedString = inputString === void 0 ? "" : ("" + inputString).replace(/[\x80-\uD7ff\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]?/g, encoderReplacer); |
|
0 commit comments