js/src/builtin/Set.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:ecc83c3f91a1
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 /* ES6 20121122 draft 15.16.4.6. */
6
7 function SetForEach(callbackfn, thisArg = undefined) {
8 /* Step 1-2. */
9 var S = this;
10 if (!IsObject(S))
11 ThrowError(JSMSG_BAD_TYPE, typeof S);
12
13 /* Step 3-4. */
14 try {
15 callFunction(std_Set_has, S);
16 } catch (e) {
17 ThrowError(JSMSG_BAD_TYPE, typeof S);
18 }
19
20 /* Step 5-6. */
21 if (!IsCallable(callbackfn))
22 ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
23
24 /* Step 7-8. */
25 var values = callFunction(std_Set_iterator, S);
26 while (true) {
27 var result = callFunction(std_Set_iterator_next, values);
28 if (result.done)
29 break;
30 var value = result.value;
31 callFunction(callbackfn, thisArg, value, value, S);
32 }
33 }

mercurial