diff options
author | Dan Kaplun <dbkaplun@gmail.com> | 2018-03-18 00:36:53 -0400 |
---|---|---|
committer | Trivikram <16024985+trivikr@users.noreply.github.com> | 2018-03-25 20:03:17 -0700 |
commit | d49661bb80dd6d9c012dc718bcec45c89fe2e3e1 (patch) | |
tree | 34db1900e570ef927864572d9f0b45d88e85cc1d /lib | |
parent | cde98ce14743c4f2b80ac7825fc52fb179feeef6 (diff) | |
download | android-node-v8-d49661bb80dd6d9c012dc718bcec45c89fe2e3e1.tar.gz android-node-v8-d49661bb80dd6d9c012dc718bcec45c89fe2e3e1.tar.bz2 android-node-v8-d49661bb80dd6d9c012dc718bcec45c89fe2e3e1.zip |
console: don't swallow call stack exceeded errors
Fixes test/parallel/test-console-no-swallow-stack-exceeded.js
PR-URL: https://github.com/nodejs/node/pull/19423
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/console.js | 17 | ||||
-rw-r--r-- | lib/internal/errors.js | 22 |
2 files changed, 27 insertions, 12 deletions
diff --git a/lib/console.js b/lib/console.js index b77832b987..d70a6b30b7 100644 --- a/lib/console.js +++ b/lib/console.js @@ -21,15 +21,16 @@ 'use strict'; -const { ERR_CONSOLE_WRITABLE_STREAM } = require('internal/errors').codes; +const { + isStackOverflowError, + codes: { ERR_CONSOLE_WRITABLE_STREAM }, +} = require('internal/errors'); const util = require('util'); const kCounts = Symbol('counts'); // Track amount of indentation required via `console.group()`. const kGroupIndent = Symbol('groupIndent'); -let MAX_STACK_MESSAGE; - function Console(stdout, stderr, ignoreErrors = true) { if (!(this instanceof Console)) { return new Console(stdout, stderr, ignoreErrors); @@ -113,17 +114,9 @@ function write(ignoreErrors, stream, string, errorhandler, groupIndent) { stream.write(string, errorhandler); } catch (e) { - if (MAX_STACK_MESSAGE === undefined) { - try { - // eslint-disable-next-line no-unused-vars - function a() { a(); } - } catch (err) { - MAX_STACK_MESSAGE = err.message; - } - } // console is a debugging utility, so it swallowing errors is not desirable // even in edge cases such as low stack space. - if (e.message === MAX_STACK_MESSAGE && e.name === 'RangeError') + if (isStackOverflowError(e)) throw e; // Sorry, there's no proper way to pass along the error here. } finally { diff --git a/lib/internal/errors.js b/lib/internal/errors.js index a8c4bfb3c3..16b4cd2416 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -569,11 +569,33 @@ function dnsException(err, syscall, hostname) { return ex; } +let MAX_STACK_MESSAGE; +/** + * Returns true if `err` is a `RangeError` with an engine-specific message. + * "Maximum call stack size exceeded" in V8. + * + * @param {Error} err + * @returns {boolean} + */ +function isStackOverflowError(err) { + if (MAX_STACK_MESSAGE === undefined) { + try { + function overflowStack() { overflowStack(); } + overflowStack(); + } catch (err) { + MAX_STACK_MESSAGE = err.message; + } + } + + return err.name === 'RangeError' && err.message === MAX_STACK_MESSAGE; +} + module.exports = exports = { dnsException, errnoException, exceptionWithHostPort, uvException, + isStackOverflowError, message, AssertionError, SystemError, |