Skip to content

Commit 210c538

Browse files
committed
Use ArrayBuffer.isView over instanceof ArrayBuffer. NFC
Its more compact and more accurate (since it works across iframes).
1 parent 975f97d commit 210c538

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/lib/libembind.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ var LibraryEmbind = {
452452
return str;
453453
},
454454
toWireType(destructors, value) {
455-
if (value instanceof ArrayBuffer) {
455+
if (!ArrayBuffer.isView(value)) {
456456
value = new Uint8Array(value);
457457
}
458458

src/lib/libmemfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ addToLibrary({
259259
write(stream, buffer, offset, length, position, canOwn) {
260260
#if ASSERTIONS
261261
// The data buffer should be a typed array view
262-
assert(!(buffer instanceof ArrayBuffer));
262+
assert(ArrayBuffer.isView(buffer));
263263
#endif
264264
#if ALLOW_MEMORY_GROWTH
265265
// If the buffer is located in main memory (HEAP), and if

src/parseTools.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ function getUnsharedTextDecoderView(heap, start, end) {
10511051
// a SAB, or can use .subarray() otherwise. Note: We compare with
10521052
// `ArrayBuffer` here to avoid referencing `SharedArrayBuffer` which could be
10531053
// undefined.
1054-
return `${heap}.buffer instanceof ArrayBuffer ? ${unshared} : ${shared}`;
1054+
return `ArrayBuffer.isView(${heap}) ? ${unshared} : ${shared}`;
10551055
}
10561056

10571057
function getEntryFunction() {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 552,
33
"a.html.gz": 373,
4-
"a.js": 7255,
5-
"a.js.gz": 3314,
4+
"a.js": 7252,
5+
"a.js.gz": 3309,
66
"a.wasm": 7315,
77
"a.wasm.gz": 3371,
8-
"total": 15122,
9-
"total_gz": 7058
8+
"total": 15119,
9+
"total_gz": 7053
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 552,
33
"a.html.gz": 373,
4-
"a.js": 5353,
5-
"a.js.gz": 2522,
4+
"a.js": 5350,
5+
"a.js.gz": 2517,
66
"a.wasm": 5953,
77
"a.wasm.gz": 2796,
8-
"total": 11858,
9-
"total_gz": 5691
8+
"total": 11855,
9+
"total_gz": 5686
1010
}

0 commit comments

Comments
 (0)