%TypedArray%.prototype.includes

# Domenic Denicola (10 years ago)

When implementing Array.prototype.includes for V8, we realized suddenly that we should probably do the same for typed arrays.

Looking at many of the %TypedArray%.prototype methods, it seems most of them are specified as basically "the same as Array, but with these minor tweaks." E.g.

A few though are specified in detail:

I was wondering if anyone knew why, so I can tell which to use as guidance for speccing %TypedArray%.prototype.includes?

As for process issues, I think it would be reasonable to add a supplement to the existing tc39/Array.prototype.includes repo tacking this on? Or would that be bad, and I should start a separate proposal?

# Allen Wirfs-Brock (10 years ago)

On Dec 4, 2014, at 2:25 PM, Domenic Denicola wrote:

When implementing Array.prototype.includes for V8, we realized suddenly that we should probably do the same for typed arrays.

Of course!

Looking at many of the %TypedArray%.prototype methods, it seems most of them are specified as basically "the same as Array, but with these minor tweaks." E.g.

A few though are specified in detail:

I was wondering if anyone knew why, so I can tell which to use as guidance for speccing %TypedArray%.prototype.includes?

Because some of the Array.prototype algorithms depend upon of the ability to an Array to dynamically grow its length or other characteristics that are not true of Typed Array instances. A new algorithm that is appropriate for a Typed Array implementation is specified for those cases. Otherwise, we just reference the Array.prototype algorithm.

For 'includes', you probably can get array with using the same algorithm as Array.prototype.includes.

As for process issues, I think it would be reasonable to add a supplement to the existing tc39/Array.prototype.includes repo tacking this on? Or would that be bad, and I should start a separate proposal?

Add it to the existing proposal. It's an oversight that it wasn't included and something that should have been caught by reviewers if we were paying attention. In general, we want Array and Typed Arrays to support the same set of methods.

# Domenic Denicola (10 years ago)

From: Allen Wirfs-Brock [mailto:allen at wirfs-brock.com]

Because some of the Array.prototype algorithms depend upon of the ability to an Array to dynamically grow its length or other characteristics that are not true of Typed Array instances. A new algorithm that is appropriate for a Typed Array implementation is specified for those cases. Otherwise, we just reference the Array.prototype algorithm.

Oh I see, that makes sense now that I realize how the return values of map and filter are created and filled. And yeah, agreed that the algorithm should be reusable for includes in particular.

Add it to the existing proposal. It's an oversight that it wasn't included and something that should have been caught by reviewers if we were paying attention. In general, we want Array and Typed Arrays to support the same set of methods.

Sounds good!