diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 4188d999f7fde7..9c6be6981f5b88 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -69,6 +69,8 @@ const { CountQueuingStrategy, } = require('internal/webstreams/queuingstrategies'); +const { queueMicrotask } = require('internal/process/task_queues'); + const kHandle = Symbol('kHandle'); const kType = Symbol('kType'); const kLength = Symbol('kLength'); @@ -284,7 +286,7 @@ class Blob { } if (buffer !== undefined) buffers.push(buffer); - readNext(); + queueMicrotask(() => readNext()); }); }; readNext(); diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index 68fd2d547a0e80..6b6ce70687660e 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -315,3 +315,16 @@ assert.throws(() => new Blob({}), { delete Object.prototype.type; } + +(async () => { + // Refs: https://github.com/nodejs/node/issues/47301 + + const random = Buffer.alloc(256).fill('0'); + const chunks = []; + + for (let i = 0; i < random.length; i += 2) { + chunks.push(random.subarray(i, i + 2)); + } + + await new Blob(chunks).arrayBuffer(); +})().then(common.mustCall());