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

Avoid looking up @@isConcatSpreadable for tuples.

Open acutmore opened this issue 3 years ago • 1 comments

Right now the spec will check @@isConcatSpreadable on Tuple.prototype when passed a tuple, before defaulting to returning true for tuples:

1. If Type(O) is not Object or Tuple, return false.
2. Let spreadable be ? GetV(O, @@isConcatSpreadable).
3. If spreadable is not undefined, return ! ToBoolean(spreadable).
4. If ! IsTuple(O), return true.
5. Return ? IsArray(O).

This means that if someone creates Tuple.prototype[Symbol.isConcatSpreadable] and returns false, it would change how Tuples behave in concat. It might make sense to do an early return for IsTuple and always return true - keeping the behavior 'static'.

cc: @michaelficarra

acutmore avatar Jul 25 '22 13:07 acutmore

It would be confusing if someone did that, and Tuple concat still spreaded tuples but Array concat didnt. If both are hardcoding it, then it would still be confusing that primitive Tuple spread but boxed tuples dont.

I think they should just be looked up via the symbol.

ljharb avatar Jul 26 '22 09:07 ljharb