summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-04-25 00:56:35 +0200
committerAnatoli Papirovski <apapirovski@mac.com>2018-04-28 08:20:51 +0200
commit16aee380a53bb839617bc2daf6c9b61564208906 (patch)
tree792e4a67efa623beed96bb0b86910eec69c60619 /lib
parent99d56a4749e7b167b4f312a4fbcc754b7a3a8894 (diff)
downloadandroid-node-v8-16aee380a53bb839617bc2daf6c9b61564208906.tar.gz
android-node-v8-16aee380a53bb839617bc2daf6c9b61564208906.tar.bz2
android-node-v8-16aee380a53bb839617bc2daf6c9b61564208906.zip
util: fix isInsideNodeModules inside error
When isInsideNodeModules gets called while already processing another stack trace, V8 will not call prepareStackTrace again. This used to cause Node.js to just crash — fix it by checking for expected return type of the stack (Array). PR-URL: https://github.com/nodejs/node/pull/20266 Fixes: https://github.com/nodejs/node/issues/20258 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/util.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js
index ce25317b77..071563a737 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;
}