Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
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

Closed

Description

@marjakh

lengthTracking.subarray(0); // no end index

-> should this create a length-tracking TA too? Currently it doesn't. It would maybe make sense if it did?

(It's easier to implement if it doesn't. But shouldn't be a big deal either way.)

Activity

  1. syg commented on Feb 14, 2022

    @syg
    Collaborator

    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?

  2. syg commented on Mar 3, 2022

    @syg
    Collaborator

    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.

  3. hax commented on Apr 28, 2022

    @hax
    Member

    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)?

  4. syg commented on Apr 28, 2022

    @syg
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions