Skip to content

Commit

Permalink
lib: fixing isStackOverflowError to account for different JS engines
Browse files Browse the repository at this point in the history
Assumption that stack overflow exception has name == "RangeError" is
v8-specific.  Updated logic to dynamically capture error name when
capturing error message.
  • Loading branch information
Mike Kaufman committed Mar 30, 2018
1 parent 83d44be commit 01b9afb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ function dnsException(err, syscall, hostname) {
return ex;
}

let MAX_STACK_MESSAGE;
let MAX_STACK_ERROR_NAME;
let MAX_STACK_ERROR_MESSAGE;
/**
* Returns true if `err` is a `RangeError` with an engine-specific message.
* "Maximum call stack size exceeded" in V8.
Expand All @@ -581,16 +582,18 @@ let MAX_STACK_MESSAGE;
* @returns {boolean}
*/
function isStackOverflowError(err) {
if (MAX_STACK_MESSAGE === undefined) {
if (MAX_STACK_ERROR_MESSAGE === undefined) {
try {
function overflowStack() { overflowStack(); }
overflowStack();
} catch (err) {
MAX_STACK_MESSAGE = err.message;
MAX_STACK_ERROR_MESSAGE = err.message;
MAX_STACK_ERROR_NAME = err.name;
}
}

return err.name === 'RangeError' && err.message === MAX_STACK_MESSAGE;
return err.name === MAX_STACK_ERROR_NAME &&
err.message === MAX_STACK_ERROR_MESSAGE;
}

module.exports = exports = {
Expand Down

0 comments on commit 01b9afb

Please sign in to comment.