fix(utils): Fix false-positive circular references when normalizing Event
objects
#3864
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
captureException
is passed a non-Error
object, we do our best to extract as much data as we can from that object. (That's what leads to the much-maligned "Non-Error exception [or promise rejection] captured with keys x, y, and z" error message.)A common case in which this occurs is when code of the form
Promise.reject(someEvent)
runs - common enough, in fact, that we handleEvent
objects separately. Specifically, we capture the event'stype
,target
(the element which caused the event), andcurrentTarget
(the element with the event listener on it) properties (none of which are enumerable), along with anything else on the event which is enumerable. For most events, that "anything else" includes only one property:isTrusted
, a boolean indicating whether or not the event is the result of a user action.For a long time, though,
isTrusted
has been showing up not as a boolean but as[Circular ~]
. It turns out that's because when we try to grab the enumerable property values, we end up grabbing the entire event instead. (It's only shown up in theisTrusted
value, but only because that's the only enumerable property on mostEvent
s.) This fixes that, and adds a test for pulling data out ofEvent
objects.