You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
Do you want TA.p.subarray to create length-tracking TAs? #91
My original intention was that subarray does not change its semantics at all and does not create a length-tracking TA.
The reasoning is pretty weak though, which is that if a programmers have the mental model that ta.subarray(i) means ta.subarray(i, ta.length - 1), then ta.subarray(i) returning length-tracking TAs would be surprising. However, one can also argue easily enough that programmers' mental model of ta.subarray(i) is that it's closer to new TypedArray(ta.buffer, i), in which case non-length-tracking TAs would be surprising.
I can go either way on this and don't feel strongly. Do you have a preference?
After some discussion and light polling, I'm currently leaning towards having subarray return length-tracking TAs if the source TA is also length tracking, and no end is provided.
An interesting question is, if subarray(n) create a tracking array from n to the end, how to create a tracking array from n to length-m? Would people expect subarray(n, -m) return a tracking array from n to length-m? Consider subarray actually create a view/slice, it seems there may be use cases of the view which involve the index from the end, for example, last five elements: subarray(-5)?
how to create a tracking array from n to length-m? Would people expect subarray(n, -m) return a tracking array from n to length-m?
I guess you mean you'd like to have an array that is always 5 elements less than the end of ArrayBuffer, regardless of how large the ArrayBuffer is? I.e. something like an "offset from end"? It's not possible to do that today with this proposal, and I think we shouldn't add those kinds of sliding windows. They are too complex, and without a compelling use case I see no reason to add them given the implementation and security tradeoffs we have to make.
Activity
syg commentedon Feb 14, 2022
My original intention was that
subarraydoes not change its semantics at all and does not create a length-tracking TA.The reasoning is pretty weak though, which is that if a programmers have the mental model that
ta.subarray(i)meansta.subarray(i, ta.length - 1), thenta.subarray(i)returning length-tracking TAs would be surprising. However, one can also argue easily enough that programmers' mental model ofta.subarray(i)is that it's closer tonew TypedArray(ta.buffer, i), in which case non-length-tracking TAs would be surprising.I can go either way on this and don't feel strongly. Do you have a preference?
syg commentedon Mar 3, 2022
After some discussion and light polling, I'm currently leaning towards having
subarrayreturn length-tracking TAs if the source TA is also length tracking, and no end is provided.hax commentedon Apr 28, 2022
An interesting question is, if
subarray(n)create a tracking array fromnto the end, how to create a tracking array fromntolength-m? Would people expectsubarray(n, -m)return a tracking array fromntolength-m? Consider subarray actually create a view/slice, it seems there may be use cases of the view which involve the index from the end, for example, last five elements:subarray(-5)?syg commentedon Apr 28, 2022
I guess you mean you'd like to have an array that is always 5 elements less than the end of ArrayBuffer, regardless of how large the ArrayBuffer is? I.e. something like an "offset from end"? It's not possible to do that today with this proposal, and I think we shouldn't add those kinds of sliding windows. They are too complex, and without a compelling use case I see no reason to add them given the implementation and security tradeoffs we have to make.