@samitouri / QOS-React-2 / commits / 49af88991c

Fix DevTools crash when inspecting document.all (#19619)

* Add html_all_collection type to correct typeof document.all * process HTMLAllCollection like HTMLElement + fix flow issue * fix lint * move flow fix comment * Make it work with iframes too * optimize how we get html_all_collection type * use once Object.prototype.toString.call

6h057 committed Aug 21, 2020 at 15:31 UTC 49af88991c3a3e79e663e495458fad12d3162894
2 files changed +16 -2
packages/react-devtools-shared/src/hydration.js
+1
@@ -222,6 +222,7 @@ export function dehydrate(
222 ),
223 );
224
225 + case 'html_all_collection':
226 case 'typed_array':
227 case 'iterator':
228 isPathAllowedCheck = isPathAllowed(path);
packages/react-devtools-shared/src/utils.js
+15 -2
@@ -372,6 +372,7 @@ export type DataType =
372 | 'data_view'
373 | 'date'
374 | 'function'
375 + | 'html_all_collection'
376 | 'html_element'
377 | 'infinity'
378 | 'iterator'
@@ -438,14 +439,26 @@ export function getDataType(data: Object): DataType {
439 return 'iterator';
440 } else if (data.constructor && data.constructor.name === 'RegExp') {
441 return 'regexp';
441 - } else if (Object.prototype.toString.call(data) === '[object Date]') {
442 - return 'date';
442 + } else {
443 + const toStringValue = Object.prototype.toString.call(data);
444 + if (toStringValue === '[object Date]') {
445 + return 'date';
446 + } else if (toStringValue === '[object HTMLAllCollection]') {
447 + return 'html_all_collection';
448 + }
449 }
450 return 'object';
451 case 'string':
452 return 'string';
453 case 'symbol':
454 return 'symbol';
455 + case 'undefined':
456 + if (
457 + Object.prototype.toString.call(data) === '[object HTMLAllCollection]'
458 + ) {
459 + return 'html_all_collection';
460 + }
461 + return 'undefined';
462 default:
463 return 'unknown';
464 }