Skip to content

Commit

Permalink
Fix DevTools crash when inspecting document.all (#19619)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
omarsy committed Aug 21, 2020
1 parent d6e4338 commit 49af889
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/hydration.js
Expand Up @@ -222,6 +222,7 @@ export function dehydrate(
),
);

case 'html_all_collection':
case 'typed_array':
case 'iterator':
isPathAllowedCheck = isPathAllowed(path);
Expand Down
17 changes: 15 additions & 2 deletions packages/react-devtools-shared/src/utils.js
Expand Up @@ -372,6 +372,7 @@ export type DataType =
| 'data_view'
| 'date'
| 'function'
| 'html_all_collection'
| 'html_element'
| 'infinity'
| 'iterator'
Expand Down Expand Up @@ -438,14 +439,26 @@ export function getDataType(data: Object): DataType {
return 'iterator';
} else if (data.constructor && data.constructor.name === 'RegExp') {
return 'regexp';
} else if (Object.prototype.toString.call(data) === '[object Date]') {
return 'date';
} else {
const toStringValue = Object.prototype.toString.call(data);
if (toStringValue === '[object Date]') {
return 'date';
} else if (toStringValue === '[object HTMLAllCollection]') {
return 'html_all_collection';
}
}
return 'object';
case 'string':
return 'string';
case 'symbol':
return 'symbol';
case 'undefined':
if (
Object.prototype.toString.call(data) === '[object HTMLAllCollection]'
) {
return 'html_all_collection';
}
return 'undefined';
default:
return 'unknown';
}
Expand Down

0 comments on commit 49af889

Please sign in to comment.