Skip to content

Commit 01b9afb

Browse files
author
Mike Kaufman
committed
lib: fixing isStackOverflowError to account for different JS engines
Assumption that stack overflow exception has name == "RangeError" is v8-specific. Updated logic to dynamically capture error name when capturing error message.
1 parent 83d44be commit 01b9afb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/internal/errors.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ function dnsException(err, syscall, hostname) {
572572
return ex;
573573
}
574574

575-
let MAX_STACK_MESSAGE;
575+
let MAX_STACK_ERROR_NAME;
576+
let MAX_STACK_ERROR_MESSAGE;
576577
/**
577578
* Returns true if `err` is a `RangeError` with an engine-specific message.
578579
* "Maximum call stack size exceeded" in V8.
@@ -581,16 +582,18 @@ let MAX_STACK_MESSAGE;
581582
* @returns {boolean}
582583
*/
583584
function isStackOverflowError(err) {
584-
if (MAX_STACK_MESSAGE === undefined) {
585+
if (MAX_STACK_ERROR_MESSAGE === undefined) {
585586
try {
586587
function overflowStack() { overflowStack(); }
587588
overflowStack();
588589
} catch (err) {
589-
MAX_STACK_MESSAGE = err.message;
590+
MAX_STACK_ERROR_MESSAGE = err.message;
591+
MAX_STACK_ERROR_NAME = err.name;
590592
}
591593
}
592594

593-
return err.name === 'RangeError' && err.message === MAX_STACK_MESSAGE;
595+
return err.name === MAX_STACK_ERROR_NAME &&
596+
err.message === MAX_STACK_ERROR_MESSAGE;
594597
}
595598

596599
module.exports = exports = {

0 commit comments

Comments
 (0)