|
40 | 40 | var strTag = global.Symbol && global.Symbol.toStringTag;
|
41 | 41 | var blobSupported = false;
|
42 | 42 | var blobSupportsArrayBufferView = false;
|
43 |
| - var arrayBufferSupported = !!global.ArrayBuffer; |
44 | 43 | var blobBuilderSupported = BlobBuilder
|
45 | 44 | && BlobBuilder.prototype.append
|
46 | 45 | && BlobBuilder.prototype.getBlob;
|
|
255 | 254 | : stringDecode;
|
256 | 255 |
|
257 | 256 | function FakeBlobBuilder () {
|
258 |
| - function isDataView (obj) { |
259 |
| - return obj && Object.prototype.isPrototypeOf.call(DataView.prototype, obj); |
260 |
| - } |
261 | 257 | function bufferClone (buf) {
|
262 | 258 | var view = new Array(buf.byteLength);
|
263 | 259 | var array = new Uint8Array(buf);
|
|
307 | 303 | return new c();
|
308 | 304 | };
|
309 | 305 |
|
310 |
| - if (arrayBufferSupported) { |
311 |
| - var viewClasses = [ |
312 |
| - "[object Int8Array]", |
313 |
| - "[object Uint8Array]", |
314 |
| - "[object Uint8ClampedArray]", |
315 |
| - "[object Int16Array]", |
316 |
| - "[object Uint16Array]", |
317 |
| - "[object Int32Array]", |
318 |
| - "[object Uint32Array]", |
319 |
| - "[object Float32Array]", |
320 |
| - "[object Float64Array]" |
321 |
| - ]; |
322 |
| - |
323 |
| - var isArrayBufferView = ArrayBuffer.isView || function (obj) { |
324 |
| - return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1; |
325 |
| - }; |
| 306 | + function getObjectTypeName (o) { |
| 307 | + return Object.prototype.toString.call(o).slice(8, -1); |
| 308 | + } |
| 309 | + |
| 310 | + function isPrototypeOf(c, o) { |
| 311 | + return typeof c === "object" && Object.prototype.isPrototypeOf.call(c.prototype, o); |
| 312 | + } |
| 313 | + |
| 314 | + function isDataView (o) { |
| 315 | + return getObjectTypeName(o) === "DataView" || isPrototypeOf(global.DataView, o); |
| 316 | + } |
| 317 | + |
| 318 | + var arrayBufferClassNames = [ |
| 319 | + "Int8Array", |
| 320 | + "Uint8Array", |
| 321 | + "Uint8ClampedArray", |
| 322 | + "Int16Array", |
| 323 | + "Uint16Array", |
| 324 | + "Int32Array", |
| 325 | + "Uint32Array", |
| 326 | + "Float32Array", |
| 327 | + "Float64Array", |
| 328 | + "ArrayBuffer" |
| 329 | + ]; |
| 330 | + |
| 331 | + function includes(a, v) { |
| 332 | + return a.indexOf(v) !== -1; |
| 333 | + } |
| 334 | + |
| 335 | + function isArrayBuffer(o) { |
| 336 | + return includes(arrayBufferClassNames, getObjectTypeName(o)) || isPrototypeOf(global.ArrayBuffer, o); |
326 | 337 | }
|
327 | 338 |
|
328 | 339 | function concatTypedarrays (chunks) {
|
|
352 | 363 | chunks[i] = chunk._buffer;
|
353 | 364 | } else if (typeof chunk === "string") {
|
354 | 365 | chunks[i] = textEncode(chunk);
|
355 |
| - } else if ( |
356 |
| - arrayBufferSupported && ( |
357 |
| - Object.prototype.isPrototypeOf.call(ArrayBuffer.prototype, chunk) |
358 |
| - || isArrayBufferView(chunk) |
359 |
| - || toString.call(chunk) === "[object ArrayBuffer]")) { |
360 |
| - chunks[i] = bufferClone(chunk); |
361 |
| - } else if (arrayBufferSupported && isDataView(chunk)) { |
| 366 | + } else if (isDataView(chunk)) { |
362 | 367 | chunks[i] = bufferClone(chunk.buffer);
|
| 368 | + } else if (isArrayBuffer(chunk)) { |
| 369 | + chunks[i] = bufferClone(chunk); |
363 | 370 | } else {
|
364 | 371 | chunks[i] = textEncode(String(chunk));
|
365 | 372 | }
|
|
0 commit comments