diff --git a/lib/internal/util.js b/lib/internal/util.js index ce25317b778a3f..071563a737815b 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -356,16 +356,17 @@ function isInsideNodeModules() { // Iterate over all stack frames and look for the first one not coming // from inside Node.js itself: - for (const frame of stack) { - const filename = frame.getFileName(); - // If a filename does not start with / or contain \, - // it's likely from Node.js core. - if (!/^\/|\\/.test(filename)) - continue; - return kNodeModulesRE.test(filename); + if (Array.isArray(stack)) { + for (const frame of stack) { + const filename = frame.getFileName(); + // If a filename does not start with / or contain \, + // it's likely from Node.js core. + if (!/^\/|\\/.test(filename)) + continue; + return kNodeModulesRE.test(filename); + } } - - return false; // This should be unreachable. + return false; } diff --git a/test/parallel/test-buffer-constructor-deprecation-error.js b/test/parallel/test-buffer-constructor-deprecation-error.js new file mode 100644 index 00000000000000..46535e103b33ee --- /dev/null +++ b/test/parallel/test-buffer-constructor-deprecation-error.js @@ -0,0 +1,17 @@ +'use strict'; + +const common = require('../common'); + +const bufferWarning = 'Buffer() is deprecated due to security and usability ' + + 'issues. Please use the Buffer.alloc(), ' + + 'Buffer.allocUnsafe(), or Buffer.from() methods instead.'; + +common.expectWarning('DeprecationWarning', bufferWarning, 'DEP0005'); + +// This is used to make sure that a warning is only emitted once even though +// `new Buffer()` is called twice. +process.on('warning', common.mustCall()); + +Error.prepareStackTrace = (err, trace) => new Buffer(10); + +new Error().stack;