Skip to content

eql does not work if an array item is undefined in IE8 #140

Description

@roberttod

The following test fails

describe('eql', function () {
  it('should not remove undefined', function () {
    var arr = []
    arr.push('1')
    arr.push('2')
    arr.push(undefined)
    expect(arr).to.eql(['1', '2', undefined])
  })
})

This is because the keys function used here will not iterate over an undefined array item in IE8 unless the value was pushed to the array.

If on line 941 the keys function is called on a duplicate of the array, this could be resolved.

try{
  var ka, kb, key, i;
  if (isArray(a) && isArray(b)) {
    ka = keys(cloneArray(a));
    kb = keys(cloneArray(b));
  } else {
    ka = keys(a);
    kb = keys(b);
  }
} catch (e) {//happens when one is a string literal and the other isn't
  return false;
}

function cloneArray (arr) {
  var clone = [];
  for (var i = 0; i < arr.length; i++) {
    clone.push(arr[i]);
  }
  return clone;
}

function isArray (obj) {
  return Object.prototype.toString.call(obj) === '[object Array]';
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions