archives

« Bugzilla Issues Index

#3229 — Have common code for Array#forEach and TypedArray#forEach


I think that 22.2.3.12 specifies enough requirements in prose that having common code that can be shared with Array.prototype.forEach would be useful.

Here an example:

%TypedArray%.prototype.forEach

1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
3. If O does not have a [[TypedArrayName]] internal slot, then throw a TypeError exception.
4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
5. If buffer is undefined, then throw a TypeError exception.
6. If IsDetachededBuffer(buffer) is true, throw a TypeError exception.
7. Let length be the value of O’s [[ArrayLength]] internal slot.
8. Return the result of GenericForEach(O, length, callbackfn, thisArg)

Step 1 to 7 are actually shared with %TypedArray%.protoype.filter

Array.prototype.forEach

1. Let O be the result of calling ToObject passing the this value as the argument.
2. ReturnIfAbrupt(O).
3. Let lenValue be Get(O, "length").
4. Let len be ToLength(lenValue).
5. ReturnIfAbrupt(len).
5. Return the result of GenericForEach(0, length, callbackfn, thisArg)


fixed in rev31 editor's draft

sorta... Added a common validation abstract operation that is used by most of the typed array methods. (It can't be used everywhere because of legacy issues). Also implified the the "not generic" boiler plate by referencing that abstract operation

Not going to further breakout common Array/TypedArray algorithms in this edition.


In Rev31