test: handle stringbytes allocation failures

Buffer.allocUnsafe() can throw ERR_MEMORY_ALLOCATION_FAILED under
memory pressure. Accept it alongside the V8 allocation-failure
message so the tests take their intended low-memory skip.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66887
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
This commit is contained in:
Filip Skokan authored and Antoine du Hamel committed 2026-11-12 17:45:21 +01:00
1 parent 5fd81baf19
commit 08428bebf4
8 files changed
+16 -8

No files matched your search

@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -18,7 +18,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}