From d0ed21531ae1465389bb11589faecbd4d261f542 Mon Sep 17 00:00:00 2001 From: Will Holen Date: Fri, 22 Nov 2019 16:11:39 -0800 Subject: [PATCH] If getters throw, replace value with a placeholder Summary: Currently, if you try to inspect globals in the debugger and they have properties that throw exceptions, the app redscreens. In particular, inspecting any function triggers the bug because of `arguments` and `caller`. This diff catches the exception and shows a placeholder instead. Changelog: [Internal] Reviewed By: mhorowitz Differential Revision: D18664765 fbshipit-source-id: 0c662f3d97b21a29c57a1dd724e63d17a3b4e263 --- .../hermes/inspector/chrome/Connection.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ReactCommon/hermes/inspector/chrome/Connection.cpp b/ReactCommon/hermes/inspector/chrome/Connection.cpp index dce5c288f13..13460fa6b42 100644 --- a/ReactCommon/hermes/inspector/chrome/Connection.cpp +++ b/ReactCommon/hermes/inspector/chrome/Connection.cpp @@ -646,9 +646,21 @@ Connection::Impl::makePropsFromValue( m::runtime::PropertyDescriptor desc; desc.name = propName.utf8(runtime); - jsi::Value propValue = obj.getProperty(runtime, propName); - desc.value = m::runtime::makeRemoteObject( - runtime, propValue, objTable_, objectGroup); + try { + // Currently, we fetch the property even if it runs code. + // Chrome instead detects getters and makes you click to invoke. + jsi::Value propValue = obj.getProperty(runtime, propName); + desc.value = m::runtime::makeRemoteObject( + runtime, propValue, objTable_, objectGroup); + } catch (const jsi::JSError &err) { + // We fetched a property with a getter that threw. Show a placeholder. + // We could have added additional info, but the UI quickly gets messy. + desc.value = m::runtime::makeRemoteObject( + runtime, + jsi::String::createFromUtf8(runtime, "(Exception)"), + objTable_, + objectGroup); + } result.emplace_back(std::move(desc)); }