From 3c90b1a278d7bba3c7470debd34b0392387b6f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 28 Sep 2020 15:57:45 +0200 Subject: [PATCH] errors: support possible deletion of globalThis.Error Do not crash trying to access prepareStackTrace on `undefined`. PR-URL: https://github.com/nodejs/node/pull/35499 Reviewed-By: Joyee Cheung Reviewed-By: Benjamin Gruenbaum Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Ujjwal Sharma Reviewed-By: Shingo Inoue --- lib/internal/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 59172ba7e41c5a..6c2e7b4c7ac79b 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -81,7 +81,7 @@ const maybeOverridePrepareStackTrace = (globalThis, error, trace) => { // https://crbug.com/v8/7848 // `globalThis` is the global that contains the constructor which // created `error`. - if (typeof globalThis.Error.prepareStackTrace === 'function') { + if (typeof globalThis.Error?.prepareStackTrace === 'function') { return globalThis.Error.prepareStackTrace(error, trace); } // We still have legacy usage that depends on the main context's `Error`