js/src/builtin/Map.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/builtin/Map.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,33 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/* ES6 20121122 draft 15.14.4.4. */
     1.9 +
    1.10 +function MapForEach(callbackfn, thisArg = undefined) {
    1.11 +    /* Step 1-2. */
    1.12 +    var M = this;
    1.13 +    if (!IsObject(M))
    1.14 +        ThrowError(JSMSG_BAD_TYPE, typeof M);
    1.15 +
    1.16 +    /* Step 3-4. */
    1.17 +    try {
    1.18 +        callFunction(std_Map_has, M);
    1.19 +    } catch (e) {
    1.20 +        ThrowError(JSMSG_BAD_TYPE, typeof M);
    1.21 +    }
    1.22 +
    1.23 +    /* Step 5. */
    1.24 +    if (!IsCallable(callbackfn))
    1.25 +        ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
    1.26 +
    1.27 +    /* Step 6-8. */
    1.28 +    var entries = callFunction(std_Map_iterator, M);
    1.29 +    while (true) {
    1.30 +        var result = callFunction(std_Map_iterator_next, entries);
    1.31 +        if (result.done)
    1.32 +            break;
    1.33 +        var entry = result.value;
    1.34 +        callFunction(callbackfn, thisArg, entry[1], entry[0], M);
    1.35 +    }
    1.36 +}

mercurial