From 5c296ee394c74194fb39bcd6bb3235d65cfd4217 Mon Sep 17 00:00:00 2001 From: "Jack Horton (CHAKRA)" Date: Wed, 11 Apr 2018 17:14:05 -0700 Subject: [PATCH] chakrashim: update Error.prepareStackTrace shim --- deps/chakrashim/lib/chakra_shim.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/deps/chakrashim/lib/chakra_shim.js b/deps/chakrashim/lib/chakra_shim.js index 1ecb18f6b65..a7da640d9f2 100644 --- a/deps/chakrashim/lib/chakra_shim.js +++ b/deps/chakrashim/lib/chakra_shim.js @@ -242,7 +242,17 @@ function stackGetter() { if (!isPrepared) { const prep = Error.prepareStackTrace || prepareStackTrace; - stackSetter(prep(err, ensureStackTrace())); + + // Prep can be re-entrant, of sorts, with regards to setting err.stack vs returning what err.stack should be + // We are trying to emulate the following behavior: + // Error.prepareStackTrace = function (err, frames) { err.stack = 1 } -> err.stack should be 1 + // Error.prepareStackTrace = function (err, frames) { console.log("Called prepare") } -> err.stack should be undefined + // Error.prepareStackTrace = function (err, frames) { return 2 } -> err.stack should be 2 + // Error.prepareStackTrace = function (err, frames) { err.stack = 1; return 2; } -> err.stack should be *1* + const preparedStack = prep(err, ensureStackTrace()); + if (!isPrepared) { + stackSetter(preparedStack); + } } return currentStack;