From 46526d6cadc611b57032b0f4423cc9220f7cc915 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 314c06c7b78f03..9c5087cf1d2fe0 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`