Tests for 15.4.4.11, Array.prototype.sort

Paul Ruizendaal pnr at planet.nl
Thu Apr 11 14:46:03 PDT 2013


Last of this series, this time for sort(). Safari seems to get it right, Chrome does not throw, but does not sort either; Firefox throws, but also on cases that should pass considering the SameValue exception to non-writable Puts. The last one is debatable, because the spec allows for any transient changes, I think. Perhaps Allen can comment?

Suggesting to add the following three tests to make sure that 'true' is passed to Put and Delete respectively, and that SameValue is respected. Testing for the value of 'a' after the exception occurred is not relevant because the spec justly does not specify a sorting algorithm, only its end result when no exception occurs.

function test() {
  var a = [4,3,2,1];
  Object.defineProperty(a, '3', {value:1, writable:false});
  try {
    a.sort();
    return false;
  } catch(e) {
    if( e.name!=='TypeError' ) return false;
    return true;
  }
}

function test() {
  var a = [4,4,4,4];
  Object.defineProperty(a, '3', {value:4, writable:false});
  try {,
    a.sort();
    return true;
  } catch(e) {
    return false;
  }
}

function test() {
  var a = [];
  Object.defineProperty(a, '3', {value:1, configurable:false});
  try {
    a.sort();
    return false;
  } catch(e) {
    if( e.name!=='TypeError' ) return false;
    return true;
  }
}



More information about the test262-discuss mailing list