Skip to content

Conversation

gibson042
Copy link
Member

Split from #3629 as requested at #3629 (comment)

1. If _array_ has a [[TypedArrayName]] internal slot, then
1. Let _taRecord_ be MakeTypedArrayWithBufferWitnessRecord(_array_, ~seq-cst~).
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
1. Let _taRecord_ be ? ValidateTypedArray(_array_, ~seq-cst~).
Copy link
Member

Choose a reason for hiding this comment

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

This seems worse to me. Every existing use of ValidateTypedArray is passed an object which is not yet known to be a TA.

I'd be OK with introducing a new AO for this - GetInBoundsTALengthWitness or something, maybe - and then using it ValidateTypedArray and in callsites such as this. But I really don't like re-using ValidateTypedArray for this.

Copy link
Contributor

@syg syg Oct 6, 2025

Choose a reason for hiding this comment

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

I agree with Kevin's preferred approach over the current one in the PR. As a general thing I prefer AO preconditions to never be superfluous at callsites. If there are superfluous checks, a refactoring of the kind Kevin laid out is best for clarity, so as not to raise questions for future readers.

Edit: To be clearer, the questions I'm interested in not raising for future readers are like "why is this AO called here if it doesn't need to check these conditions?" (because of the expectation that the spec strives to be as "exact" in its verbiage as it can be) and if the answer after spec archaeology is "because it was convenient" I think that's a net negative on the readability.

1. Else,
1. Let _type_ be TypedArrayElementType(_typedArray_).
1. If IsUnclampedIntegerElementType(_type_) is *false* and IsBigIntElementType(_type_) is *false*, throw a *TypeError* exception.
1. Let _type_ be TypedArrayElementType(_typedArray_).
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the else guard? There's no reason to do this check when _waitable_ is *true*, since it is implied by the checks in that branch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants