Skip to content
Richard L. Hudson edited this page Mar 5, 2014 · 1 revision

Array.prototype.scanPar ( callbackfn )

TBD: Should we note that this=undefined is not in the signature, following Array.reduce…

TBD: Make sure folks are OK with point 16 sub 4 where I appeal to reducePar to do all the interesting work.

callbackfn should be a function that takes two arguments. scanPar calls the callbackfn, as a function, using two elements selected from the original array or from elements produced by previous invocation of callbackfn.

The range of elements processed by scanPar is set before the first call to callbackfn. Elements which are appended to the array after the call to scanPar begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time scanPar visits them; elements that are deleted after the call to scanPar begins and before being visited are not visited.

scanPar does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn. Such mutation will defeat the parallel optimization and callbacks will be performed in an ascending left to right order.

The range of elements processed by scanPar is set before the first call to callbackfn. Elements which are appended to the array after the call to scanPar begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time scanPar visits them; elements that are deleted after the call to scanPar begins and before being visited are not visited.

When the scanPar method is called with one argument, the following steps are taken:

  1. Let O be the result of calling ToObject passing the this value as the argument.

  2. ReturnIfAbrupt(O).

  3. Let lenValue be the result of Get(O, "length")

  4. Let len be ToLength(lenValue).

  5. ReturnIfAbrupt(len).

  6. If IsCallable(callbackfn) is false, throw a TypeError exception.

  7. Let T be undefined.

  8. Let A be undefined.

  9. If O is not an exotic Array object, throw a TypeError exception.

  10. Let C be Get(O, "constructor").

  11. ReturnIfAbrupt(C).

  12. If IsConstructor(C) is true, then

    1. Let thisRealm be the running execution context’s Realm.

    2. If thisRealm and the value of A’s Realm internal slot are the same value, then

      1. Let A be the result of calling the Construct internal method of C with an argument list containing the single item len.
  13. If A is undefined, then

    1. Let A be the result of the abstract operation ArrayCreate with argument len.
  14. ReturnIfAbrupt(A).

  15. In an arbitrary order for each value k between 1 and len

    1. Let kPresent be the result of HasProperty(O, Pk).

    2. ReturnIfAbrupt(kPresent).

    3. If kPresent is true, then

    4. Let kValue be the result returned as if by calling reducePar(callbackfn) with an array consisting of the first k elements in O.

    5. ReturnIfAbrupt(kValue).

    6. Let Pk be ToString(k - 1)

    7. Let status be the result of CreateDataPropertyOrThrow (A, Pk, _ kValue _).

    8. ReturnIfAbrupt(status).

  16. Return A.

The length property of the scanPar method is 1.

Clone this wiki locally