From 5f9ee9f69fe18efece16f76e0a46969fd3076d4c Mon Sep 17 00:00:00 2001 From: kball Date: Fri, 21 Jun 2019 15:08:38 -0500 Subject: [PATCH] lib: fix stack overflow check to not break on primitives PR-URL: https://github.com/nodejs/node/pull/28338 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott Reviewed-By: Gireesh Punathil Reviewed-By: Trivikram Kamat --- lib/internal/errors.js | 2 +- test/parallel/test-console-log-throw-primitive.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-console-log-throw-primitive.js diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 56cb13f1cbeafc..8fa56e315e6a1a 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -582,7 +582,7 @@ function isStackOverflowError(err) { } } - return err.name === maxStack_ErrorName && + return err && err.name === maxStack_ErrorName && err.message === maxStack_ErrorMessage; } diff --git a/test/parallel/test-console-log-throw-primitive.js b/test/parallel/test-console-log-throw-primitive.js new file mode 100644 index 00000000000000..a1a9ca25726ab9 --- /dev/null +++ b/test/parallel/test-console-log-throw-primitive.js @@ -0,0 +1,14 @@ +'use strict'; +require('../common'); +const { Writable } = require('stream'); +const { Console } = require('console'); + +const stream = new Writable({ + write() { + throw null; // eslint-disable-line no-throw-literal + } +}); + +const console = new Console({ stdout: stream }); + +console.log('test'); // Should not throw