Repository: facebook/react
File: packages/shared/ReactPerformanceTrackProperties.js (JavaScript)

Code before:
            'Only ' +
            OBJECT_WIDTH_LIMIT +
            ' properties are shown. React will not log more properties of this object.',
          '',
        ]);
        break;
      }
    }
  }
}

export function addValueToProperties(
  propertyName: string,
  value: mixed,
  properties: Array<[string, string]>,
  indent: number,
  prefix: string,
): void {
  let desc;
  switch (typeof value) {
    case 'object':
      if (value === null) {
        desc = 'null';
        break;
      } else {
        // $FlowFixMe[method-unbinding]
        const objectToString = Object.prototype.toString.call(value);
        let objectName = objectToString.slice(
          '[object '.length,
          objectToString.length - 1,
        );
        if (objectName === 'Array') {
          const array: Array<any> = (value: any);
          const didTruncate = array.length > OBJECT_WIDTH_LIMIT;
          const kind = getArrayKind(array);
          if (kind === PRIMITIVE_ARRAY || kind === EMPTY_ARRAY) {
            desc = JSON.stringify(
              didTruncate
                ? array.slice(0, OBJECT_WIDTH_LIMIT).concat('…')
                : array,
            );
            break;
          } else if (kind === ENTRIES_ARRAY) {
            properties.push([
              prefix + '\xa0\xa0'.repeat(indent) + propertyName,
              '',
            ]);
            for (let i = 0; i < array.length && i < OBJECT_WIDTH_LIMIT; i++) {
              const entry = array[i];
              addValueToProperties(
                entry[0],

Review comment (suggestion):
Moved this logic into the block where we already know it's an Object and would've used `in` and `hasOwnProperty` anyway in `addObjectToProperties`.

Code after:
            'Only ' +
            OBJECT_WIDTH_LIMIT +
            ' properties are shown. React will not log more properties of this object.',
          '',
        ]);
        break;
      }
    }
  }
}

function readReactElementTypeof(value: Object): mixed {
  // Prevents dotting into $$typeof in opaque origin windows.
  return '$$typeof' in value && hasOwnProperty.call(value, '$$typeof')
    ? value.$$typeof
    : undefined;
}

export function addValueToProperties(
  propertyName: string,
  value: mixed,
  properties: Array<[string, string]>,
  indent: number,
  prefix: string,
): void {
  let desc;
  switch (typeof value) {
    case 'object':
      if (value === null) {
        desc = 'null';
        break;
      } else {
        if (readReactElementTypeof(value) === REACT_ELEMENT_TYPE) {
          // JSX
          const typeName = getComponentNameFromType(value.type) || '\u2026';
          const key = value.key;
          const props: any = value.props;
          const propsKeys = Object.keys(props);
          const propsLength = propsKeys.length;
          if (key == null && propsLength === 0) {
            desc = '<' + typeName + ' />';
            break;
          }
          if (
            indent < 3 ||
            (propsLength === 1 && propsKeys[0] === 'children' && key == null)
          ) {
            desc = '<' + typeName + ' \u2026 />';
            break;
          }
          properties.push([