mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

The test only cares about whether a size outside the range of the 32-bit signed integers works with Blob.prototype.slice(). If it fails due to allocation failure when the system does not have enough memory, the test should just be skipped. The test previously only skipped the test when the allocation failure happens during allocation of the buffer source, but it could also happen during Blob.prototype.slice(). PR-URL: https://github.com/nodejs/node/pull/58414 Fixes: https://github.com/nodejs/node/issues/57235 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
27 lines
743 B
JavaScript
27 lines
743 B
JavaScript
'use strict';
|
|
|
|
// This tests that Blob.prototype.slice() works correctly when the size of the
|
|
// Blob is outside the range of 32-bit signed integers.
|
|
const common = require('../common');
|
|
|
|
// Buffer with size > INT32_MAX
|
|
common.skipIf32Bits();
|
|
|
|
const assert = require('assert');
|
|
|
|
const size = 2 ** 31;
|
|
|
|
try {
|
|
const buf = Buffer.allocUnsafe(size);
|
|
const blob = new Blob([buf]);
|
|
const slicedBlob = blob.slice(size - 1, size);
|
|
assert.strictEqual(slicedBlob.size, 1);
|
|
} catch (e) {
|
|
if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED') {
|
|
common.skip('insufficient space for Buffer.allocUnsafe');
|
|
}
|
|
if (/Array buffer allocation failed/.test(e.message)) {
|
|
common.skip('insufficient space for Blob.prototype.slice()');
|
|
}
|
|
throw e;
|
|
}
|