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
This commit is contained in:
Will Holen
2019-11-22 16:13:57 -08:00
committed by Facebook Github Bot
parent 1610c08a67
commit d0ed21531a
@@ -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));
}