Skip to content

Commit 4cbed56

Browse files
committed
v6.0.20211015
1 parent 8d4536f commit 4cbed56

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

Blob.js

+34-27
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
var strTag = global.Symbol && global.Symbol.toStringTag;
4141
var blobSupported = false;
4242
var blobSupportsArrayBufferView = false;
43-
var arrayBufferSupported = !!global.ArrayBuffer;
4443
var blobBuilderSupported = BlobBuilder
4544
&& BlobBuilder.prototype.append
4645
&& BlobBuilder.prototype.getBlob;
@@ -255,9 +254,6 @@
255254
: stringDecode;
256255

257256
function FakeBlobBuilder () {
258-
function isDataView (obj) {
259-
return obj && Object.prototype.isPrototypeOf.call(DataView.prototype, obj);
260-
}
261257
function bufferClone (buf) {
262258
var view = new Array(buf.byteLength);
263259
var array = new Uint8Array(buf);
@@ -307,22 +303,37 @@
307303
return new c();
308304
};
309305

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);
326337
}
327338

328339
function concatTypedarrays (chunks) {
@@ -352,14 +363,10 @@
352363
chunks[i] = chunk._buffer;
353364
} else if (typeof chunk === "string") {
354365
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)) {
362367
chunks[i] = bufferClone(chunk.buffer);
368+
} else if (isArrayBuffer(chunk)) {
369+
chunks[i] = bufferClone(chunk);
363370
} else {
364371
chunks[i] = textEncode(String(chunk));
365372
}

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# `blob-polyfill` CHANGELOG
22

3+
## v6.0.20211015
4+
* [Blob.js] Check object class names when determining Object types (@coclauso)
5+
* [Blob.js] Reduce redundancies in getting class names and prototype checks (@bjornstar)
6+
* [test] Add a test for round tripping data in ArrayBuffers (@coclauso)
7+
38
## v5.0.20210201
49
* [Blob.js] Blob.arrayBuffer() should return a promise that resolves with an ArrayBuffer (@bjornstar)
510
* [test] Add a test for Blob.arrayBuffer (@bjornstar)

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blob-polyfill",
3-
"version": "5.0.20210201",
3+
"version": "6.0.20211015",
44
"homepage": "https://github.com/bjornstar/blob-polyfill",
55
"authors": [
66
"Eli Grey <[email protected]>"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blob-polyfill",
3-
"version": "5.0.20210201",
3+
"version": "6.0.20211015",
44
"description": "Blob.js implements the W3C Blob interface in browsers that do not natively support it.",
55
"main": "Blob.js",
66
"scripts": {

test/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ describe("blob-polyfill", function () {
119119

120120

121121
function stringToArrayBuffer(string) {
122-
const buf = new ArrayBuffer(string.length * 2); // 2 bytes for each char
123-
const bufView = new Uint16Array(buf);
124-
for (let i = 0, strLen = string.length; i < strLen; i++) {
122+
var buf = new ArrayBuffer(string.length * 2); // 2 bytes for each char
123+
var bufView = new Uint16Array(buf);
124+
for (var i = 0; i < string.length; i+= 1) {
125125
bufView[i] = string.charCodeAt(i);
126126
}
127127
return buf;
128128
}
129129

130130
function arrayBufferToString(buffer) {
131-
const array = new Uint16Array(buffer);
131+
var array = new Uint16Array(buffer);
132132
return String.fromCharCode.apply(null, array);
133133
}

0 commit comments

Comments
 (0)