Skip to content

objectSpread not working with boolean arguments #10482

@MengMengYan

Description

@MengMengYan

Hi,
We have a scenario where objectSpread throws an exception when the arguments list contains a boolean.

This particular piece of code

function _objectSpread(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = arguments[i] != null  ? arguments[i] : {};
    var ownKeys = Object.keys(source);

    if (typeof Object.getOwnPropertySymbols === 'function') {
      ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
        return Object.getOwnPropertyDescriptor(source, sym).enumerable;
      }));
    }

    ownKeys.forEach(function (key) {
      defineProperty(target, key, source[key]);
    });
  }

  return target;
}

gives an exception : Object.keys argument is not an object.

Shouldn't the check be like:
var source = arguments[i] != null && typeof arguments[i] === 'object' ? arguments[i] : {};

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions