Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: remove unreachable code #26906

Closed
wants to merge 1 commit into from
Closed

Conversation

Trott
Copy link
Member

@Trott Trott commented Mar 25, 2019

In the current code, line 497 checks if item is null or undefined.
However, item is guaranteed to be a non-null object or function at
that point.

  • Lines 484/485 set primitive to true if item is null or
    undefined.
  • Line 486 skips line 497 if primitive is true (which it will always
    be if item is null or undefined) and properties is undefined. So
    the only way to get to line 497 when item is null or undefined is if
    properties is specified.
  • Line 494 skips line 497 if primitive is true (which it will always
    be if item is null or undefined) and properties are specified
    (which will always be the case or else this else block is skipped.)

Here are the current lines 484 through 497:

  const primitive = item === null ||
      (typeof item !== 'function' && typeof item !== 'object');
  if (properties === undefined && primitive) {
    hasPrimitives = true;
    valuesKeyArray[i] = _inspect(item);
  } else {
    const keys = properties || ObjectKeys(item);
    for (const key of keys) {
      if (map[key] === undefined)
        map[key] = [];
      if ((primitive && properties) || !hasOwnProperty(item, key))
        map[key][i] = '';
      else
        map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

        map[key][i] = _inspect(item[key]);
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

In the current code, line 497 checks if `item` is `null` or `undefined`.
However, `item` is guaranteed to be a non-null object or function at
that point.

* Lines 484/485 set `primitive` to `true` if `item` is null or
  undefined.
* Line 486 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` is undefined. So
  the only way to get to line 497 when `item` is null or undefined is if
  `properties` is specified.
* Line 494 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` are specified
  (which will always be the case or else this `else` block is skipped.)

Here are the current lines 484 through 497:

      const primitive = item === null ||
          (typeof item !== 'function' && typeof item !== 'object');
      if (properties === undefined && primitive) {
        hasPrimitives = true;
        valuesKeyArray[i] = _inspect(item);
      } else {
        const keys = properties || ObjectKeys(item);
        for (const key of keys) {
          if (map[key] === undefined)
            map[key] = [];
          if ((primitive && properties) || !hasOwnProperty(item, key))
            map[key][i] = '';
          else
            map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

            map[key][i] = _inspect(item[key]);
@nodejs-github-bot nodejs-github-bot added the console Issues and PRs related to the console subsystem. label Mar 25, 2019
@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 25, 2019
@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member Author

Trott commented Mar 28, 2019

Landed in 86517c9

@Trott Trott closed this Mar 28, 2019
Trott added a commit to Trott/io.js that referenced this pull request Mar 28, 2019
In the current code, line 497 checks if `item` is `null` or `undefined`.
However, `item` is guaranteed to be a non-null object or function at
that point.

* Lines 484/485 set `primitive` to `true` if `item` is null or
  undefined.
* Line 486 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` is undefined. So
  the only way to get to line 497 when `item` is null or undefined is if
  `properties` is specified.
* Line 494 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` are specified
  (which will always be the case or else this `else` block is skipped.)

Here are the current lines 484 through 497:

      const primitive = item === null ||
          (typeof item !== 'function' && typeof item !== 'object');
      if (properties === undefined && primitive) {
        hasPrimitives = true;
        valuesKeyArray[i] = _inspect(item);
      } else {
        const keys = properties || ObjectKeys(item);
        for (const key of keys) {
          if (map[key] === undefined)
            map[key] = [];
          if ((primitive && properties) || !hasOwnProperty(item, key))
            map[key][i] = '';
          else
            map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

            map[key][i] = _inspect(item[key]);

PR-URL: nodejs#26906
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
targos pushed a commit that referenced this pull request Mar 28, 2019
In the current code, line 497 checks if `item` is `null` or `undefined`.
However, `item` is guaranteed to be a non-null object or function at
that point.

* Lines 484/485 set `primitive` to `true` if `item` is null or
  undefined.
* Line 486 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` is undefined. So
  the only way to get to line 497 when `item` is null or undefined is if
  `properties` is specified.
* Line 494 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` are specified
  (which will always be the case or else this `else` block is skipped.)

Here are the current lines 484 through 497:

      const primitive = item === null ||
          (typeof item !== 'function' && typeof item !== 'object');
      if (properties === undefined && primitive) {
        hasPrimitives = true;
        valuesKeyArray[i] = _inspect(item);
      } else {
        const keys = properties || ObjectKeys(item);
        for (const key of keys) {
          if (map[key] === undefined)
            map[key] = [];
          if ((primitive && properties) || !hasOwnProperty(item, key))
            map[key][i] = '';
          else
            map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

            map[key][i] = _inspect(item[key]);

PR-URL: #26906
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
targos pushed a commit that referenced this pull request Mar 29, 2019
In the current code, line 497 checks if `item` is `null` or `undefined`.
However, `item` is guaranteed to be a non-null object or function at
that point.

* Lines 484/485 set `primitive` to `true` if `item` is null or
  undefined.
* Line 486 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` is undefined. So
  the only way to get to line 497 when `item` is null or undefined is if
  `properties` is specified.
* Line 494 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` are specified
  (which will always be the case or else this `else` block is skipped.)

Here are the current lines 484 through 497:

      const primitive = item === null ||
          (typeof item !== 'function' && typeof item !== 'object');
      if (properties === undefined && primitive) {
        hasPrimitives = true;
        valuesKeyArray[i] = _inspect(item);
      } else {
        const keys = properties || ObjectKeys(item);
        for (const key of keys) {
          if (map[key] === undefined)
            map[key] = [];
          if ((primitive && properties) || !hasOwnProperty(item, key))
            map[key][i] = '';
          else
            map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

            map[key][i] = _inspect(item[key]);

PR-URL: #26906
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
targos pushed a commit that referenced this pull request Mar 30, 2019
In the current code, line 497 checks if `item` is `null` or `undefined`.
However, `item` is guaranteed to be a non-null object or function at
that point.

* Lines 484/485 set `primitive` to `true` if `item` is null or
  undefined.
* Line 486 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` is undefined. So
  the only way to get to line 497 when `item` is null or undefined is if
  `properties` is specified.
* Line 494 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` are specified
  (which will always be the case or else this `else` block is skipped.)

Here are the current lines 484 through 497:

      const primitive = item === null ||
          (typeof item !== 'function' && typeof item !== 'object');
      if (properties === undefined && primitive) {
        hasPrimitives = true;
        valuesKeyArray[i] = _inspect(item);
      } else {
        const keys = properties || ObjectKeys(item);
        for (const key of keys) {
          if (map[key] === undefined)
            map[key] = [];
          if ((primitive && properties) || !hasOwnProperty(item, key))
            map[key][i] = '';
          else
            map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

            map[key][i] = _inspect(item[key]);

PR-URL: #26906
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
BethGriggs pushed a commit that referenced this pull request Apr 5, 2019
In the current code, line 497 checks if `item` is `null` or `undefined`.
However, `item` is guaranteed to be a non-null object or function at
that point.

* Lines 484/485 set `primitive` to `true` if `item` is null or
  undefined.
* Line 486 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` is undefined. So
  the only way to get to line 497 when `item` is null or undefined is if
  `properties` is specified.
* Line 494 skips line 497 if `primitive` is true (which it will always
  be if `item` is null or undefined) and `properties` are specified
  (which will always be the case or else this `else` block is skipped.)

Here are the current lines 484 through 497:

      const primitive = item === null ||
          (typeof item !== 'function' && typeof item !== 'object');
      if (properties === undefined && primitive) {
        hasPrimitives = true;
        valuesKeyArray[i] = _inspect(item);
      } else {
        const keys = properties || ObjectKeys(item);
        for (const key of keys) {
          if (map[key] === undefined)
            map[key] = [];
          if ((primitive && properties) || !hasOwnProperty(item, key))
            map[key][i] = '';
          else
            map[key][i] = item == null ? item : _inspect(item[key]);

This change removes the unnecessary ternary in that final line,
simplifying it to:

            map[key][i] = _inspect(item[key]);

PR-URL: #26906
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
@BethGriggs BethGriggs mentioned this pull request Apr 9, 2019
@Trott Trott deleted the unreachable-table branch January 13, 2022 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. console Issues and PRs related to the console subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants