js/src/builtin/Map.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /* ES6 20121122 draft 15.14.4.4. */
michael@0 6
michael@0 7 function MapForEach(callbackfn, thisArg = undefined) {
michael@0 8 /* Step 1-2. */
michael@0 9 var M = this;
michael@0 10 if (!IsObject(M))
michael@0 11 ThrowError(JSMSG_BAD_TYPE, typeof M);
michael@0 12
michael@0 13 /* Step 3-4. */
michael@0 14 try {
michael@0 15 callFunction(std_Map_has, M);
michael@0 16 } catch (e) {
michael@0 17 ThrowError(JSMSG_BAD_TYPE, typeof M);
michael@0 18 }
michael@0 19
michael@0 20 /* Step 5. */
michael@0 21 if (!IsCallable(callbackfn))
michael@0 22 ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
michael@0 23
michael@0 24 /* Step 6-8. */
michael@0 25 var entries = callFunction(std_Map_iterator, M);
michael@0 26 while (true) {
michael@0 27 var result = callFunction(std_Map_iterator_next, entries);
michael@0 28 if (result.done)
michael@0 29 break;
michael@0 30 var entry = result.value;
michael@0 31 callFunction(callbackfn, thisArg, entry[1], entry[0], M);
michael@0 32 }
michael@0 33 }

mercurial