All "stops calling callbackfn once the array is deleted during the call" tests are wrong


These tests (,,,,,, follow the same pattern (this is reduce) :
function testcase() {
function callbackfn(prevVal, curVal, idx, obj) {
    delete o.arr;
    return prevVal + curVal;
var o = new Object;
o.arr = ["1", 2, 3, 4, 5];
if (o.arr.reduce(callbackfn) === "12") {
    return true;
I think that, in this case, "delete" is misunderstood. The delete operator (ES5 11.4.1) calls the [[delete]] internal method (ES5 8.12.7) which removes from an object a property (if configurable). If this property happens to be an object, there is no reason that this object itself is deleted as long as a reference to this object is kept somewhere. In our case, the "obj" argument of callbackfn and the "this" keyword of reduce are both a reference to the array being traversed.
For that reason, I think that this these tests are wrong and should be removed from the test suite.


jwalden wrote Jan 1, 2011 at 9:52 PM

http://es5conform.codeplex.com/workitem/29141 has a patch that fixes this, but by adjusting the test to pass, not by deleting it. (I have no particular objection to deleting the test, but since it's basically written, better to coopt it for a useful purpose if possible, I think, even if it's a completely different purpose from the original one.)

jwalden wrote Jan 1, 2011 at 9:54 PM

This seems a dup of 25430, fwiw.

wrote Feb 13, 2013 at 2:09 AM