proposal-record-tuple icon indicating copy to clipboard operation
proposal-record-tuple copied to clipboard

Ensure correct behavior of Tuple methods that refer to the definition of Array methods

Open nicolo-ribaudo opened this issue 3 years ago • 1 comments

Some of the tuple methods, such as Tuple.prototype.map, are defined with explicit steps and, when they have a callback, they pass the result of thisTupleValue(this) as the last parameter. Other tuple methods, such as Tuple.prototype.forEach, are defined as a diff from the relative Array method, with references to this replaced with thisTupleVaue(this). However, array methods call ToObject(this) (which thus ends up being ToObject(thisTupleVaue(this)))) and pass the resulting object as the last parameter to the callback function.

In practice, this means that #[1].forEach((v, i, tup) => console.log(typeof tup)) logs "object" instead of "tuple": we should fix how we define those methods to make sure that the last parameter is correctly a primitive tuple.

Ref https://github.com/tc39/proposal-record-tuple/pull/317#discussion_r920270217

nicolo-ribaudo avatar Jul 13 '22 20:07 nicolo-ribaudo

I think the longer term approach is to actually have explicit spec steps instead of the indirect "x, but replace step y with z" approach.

ljharb avatar Jul 13 '22 20:07 ljharb