From 2a94da7db33f06575410f40dd4a45d4ed28294ea Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Fri, 22 Feb 2019 11:03:35 -0800 Subject: [PATCH] Best-effort fix for crash Summary: The keys in WeakMaps have to be Objects (i.e. can't be primitives) as they have to be fall under the responsibility of the GC. Without this check, we may get "TypeError: Invalid value used as weak map key" as we accept `any` as `data` for the inspector. I'm not entirely confident if this check is enough, but I also don't have a way of reproducing the error we got reported. Reviewed By: jknoxville Differential Revision: D14182463 fbshipit-source-id: 3397678935f08513e485bf5654377b54053ee32f --- src/ui/components/data-inspector/DataInspector.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ui/components/data-inspector/DataInspector.js b/src/ui/components/data-inspector/DataInspector.js index db5cc19b5..518d88027 100644 --- a/src/ui/components/data-inspector/DataInspector.js +++ b/src/ui/components/data-inspector/DataInspector.js @@ -203,7 +203,15 @@ function getRootContextMenu(data: Object): Array { }, }, ]; - rootContextMenuCache.set(data, menu); + if (data instanceof Object) { + rootContextMenuCache.set(data, menu); + } else { + console.error( + '[data-inspector] Ignoring unsupported data type for cache: ', + data, + typeof data, + ); + } return menu; }