From 152a86c6aa9b13d112bffef9e29274f8f71caf1c Mon Sep 17 00:00:00 2001 From: Mike Kaufman Date: Fri, 30 Mar 2018 10:07:49 -0700 Subject: [PATCH] lib: make isStackOverflowError() engine-agnostic Assumption that stack overflow exception has name == "RangeError" is v8-specific. Updated logic to dynamically capture error name when capturing error message. PR-URL: https://github.com/nodejs/node/pull/19705 Reviewed-By: Colin Ihrig Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Rich Trott Reviewed-By: James M Snell --- lib/internal/errors.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 833246c8a5ff66..ec5b0effe78932 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -445,25 +445,29 @@ function dnsException(err, syscall, hostname) { return ex; } -let MAX_STACK_MESSAGE; +let maxStack_ErrorName; +let maxStack_ErrorMessage; /** - * Returns true if `err` is a `RangeError` with an engine-specific message. + * Returns true if `err.name` and `err.message` are equal to engine-specific + * values indicating max call stack size has been exceeded. * "Maximum call stack size exceeded" in V8. * * @param {Error} err * @returns {boolean} */ function isStackOverflowError(err) { - if (MAX_STACK_MESSAGE === undefined) { + if (maxStack_ErrorMessage === undefined) { try { function overflowStack() { overflowStack(); } overflowStack(); } catch (err) { - MAX_STACK_MESSAGE = err.message; + maxStack_ErrorMessage = err.message; + maxStack_ErrorName = err.name; } } - return err.name === 'RangeError' && err.message === MAX_STACK_MESSAGE; + return err.name === maxStack_ErrorName && + err.message === maxStack_ErrorMessage; } module.exports = exports = {