From 53cb29898bc80ed1daecbf3971e25de21c91a380 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 23 May 2025 22:45:46 +0200 Subject: [PATCH] test: fix missing edge case in test-blob-slice-with-large-size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Tobias Nießen Reviewed-By: LiviaMedeiros Reviewed-By: Michaël Zasso Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: Stefan Stojanovic --- test/pummel/test-blob-slice-with-large-size.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/pummel/test-blob-slice-with-large-size.js b/test/pummel/test-blob-slice-with-large-size.js index 639c2217db7..af38d6d5760 100644 --- a/test/pummel/test-blob-slice-with-large-size.js +++ b/test/pummel/test-blob-slice-with-large-size.js @@ -1,4 +1,7 @@ '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 @@ -14,8 +17,11 @@ try { const slicedBlob = blob.slice(size - 1, size); assert.strictEqual(slicedBlob.size, 1); } catch (e) { - if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') { - throw e; + if (e.code === 'ERR_MEMORY_ALLOCATION_FAILED') { + common.skip('insufficient space for Buffer.allocUnsafe'); } - 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; }