Skip to content
7 changes: 7 additions & 0 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export type DataType =
| 'html_element'
| 'infinity'
| 'iterator'
| 'opaque_iterator'
| 'nan'
| 'null'
| 'number'
Expand Down Expand Up @@ -437,6 +438,8 @@ export function getDataType(data: Object): DataType {
return 'array_buffer';
} else if (typeof data[Symbol.iterator] === 'function') {
return 'iterator';
} else if (data[Symbol.iterator] === 'data') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. Why would data[Symbol.iterator] return the string "data"?

return 'opaque_iterator';
} else if (data.constructor && data.constructor.name === 'RegExp') {
return 'regexp';
} else {
Expand Down Expand Up @@ -615,6 +618,7 @@ export function formatDataForPreview(
}
case 'iterator':
const name = data.constructor.name;

if (showFormattedValue) {
// TRICKY
// Don't use [...spread] syntax for this purpose.
Expand Down Expand Up @@ -653,6 +657,9 @@ export function formatDataForPreview(
} else {
return `${name}(${data.size})`;
}
case 'opaque_iterator': {
return `${data.constructor.name}(${data.size})`;
Copy link
Contributor

@bvaughn bvaughn Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will result in the string "(undefined)" (at least based on my testing, using a similar approach as mentioned in #19726).

data.constructor points at the generator function, which has no .name property. Maybe we should use data[Symbol.toStringTag] instead? Although that's just "Generator" in my testing, so maybe it's not really that useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just String(data) can work for all

Copy link
Contributor

@bvaughn bvaughn Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would result in a different format than we're looking for here ("[object Generator]")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${data.constructor.name}(${data.size}) I think we cannot have this format, because we cannot have the size of generator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know. That's what I commented above :)

}
case 'date':
return data.toString();
case 'object':
Expand Down