Skip to content

Conversation

@jasnell
Copy link
Collaborator

@jasnell jasnell commented Feb 4, 2026

No description provided.

@jasnell jasnell requested a review from ljharb February 4, 2026 04:26
@github-actions
Copy link

github-actions bot commented Feb 4, 2026

The rendered spec for this PR is available at https://tc39.es/proposal-typedarray-concat/pr/6.

@jasnell jasnell force-pushed the jasnell/spec-draft-text branch from bc7b5cd to 7672833 Compare February 4, 2026 05:04
1. Let _C_ be the *this* value.
1. If IsConstructor(_C_) is *false*, throw a *TypeError* exception.
1. If _C_ does not have a [[TypedArrayName]] internal slot, throw a *TypeError* exception.
1. Let _arrayList_ be ? IteratorToList(? GetIteratorFromMethod(_items_, ? GetMethod(_items_, %Symbol.iterator%))).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but is not idiomatic - the convention is to consume iterables as iterables, meaning that you'd be doing the ValidateTypedArray calls on each item as you consume the iterable, rather than deferring those checks until after the whole iterable has been consumed.

That said, there's arguably a reason to do it this way, which is that the iteration protocol calls user code, which could detach or resize a TypedArray that you've already looked at, which would be bad. Doing it this way ensures there's no user code running between the point at which you start computing the total length and the point at which you do the copies. If that's the intention, that's reasonable, but this should probably should be called out with a NOTE.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing it this way, however, means that it can still throw conceptually mid-iteration, and the iterator will have been exhausted.

iow, i think that the extra burden of checking for resizing or detachment is necessary if it's going to take an iterable, so that an error on an item in the middle doesn't exhaust the iterator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a tradeoff - I agree that in the error case that it is very slightly nicer to not exhaust the iterator, but if that comes at the cost of slowing down the happy case, as I think it might here, it's not necessarily worth it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I can see it both ways and really not sure which is best. I do have a slight preference towards not slowing down the happy path, particularly since this is largely a perf-motivated proposal. One possibility for now is that we can document this as a discussion point (creating a tracking issue) and discuss in committee... but also happy to go with whatever y'all recommend on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #7 to track.


### Differences from `set`

Per the current definition of `TypedArray.prototype.set` in the language specification, the user code is responsible for allocating the destination `TypedArray` in advance along with calculating and updating the offset at which each copied segment should go. Allocations can be expensive and the book keeping can be cumbersome, particularly when there are multiple input `TypedArrays`. The `set` algorithm is also written such that each element of the copied `TypedArray` is copied to the destination one element at a time, with no affordance given to allow the implementation to determine an alternative, more optimal copy strategy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with no affordance given to allow the implementation to determine an alternative, more optimal copy strategy

Implementations are always free to implement using any strategy which behaves as-if it was using the algorithm in the spec text. I strongly expect they'll implement this using exactly the same logic they use for TA.prototype.set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do an editorial clean up on this in a follow up pass

@jasnell
Copy link
Collaborator Author

jasnell commented Feb 11, 2026

Given that the conversation appears to have settled out, I'd like to get this draft text landed. Any objections?

@bakkot
Copy link
Member

bakkot commented Feb 11, 2026

I haven't done a detailed review and expect there will in any case be further normative changes, but this is fine as a draft for stage 2.

@jasnell jasnell merged commit 060d39f into main Feb 12, 2026
1 check passed
@jasnell jasnell deleted the jasnell/spec-draft-text branch February 12, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants