Debian Codegraph @

js/src/tests/non262/Array/filter.js

raw
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = "364603";
8 var summary = "The value placed in a filtered array for an element is the " +
9 " element's value before the callback is run, not after";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 var failed = false;
20
21 function mutate(val, index, arr)
22 {
23 arr[index] = "mutated";
24 return true;
25 }
26
27 function assertEqual(v1, v2, msg)
28 {
29 if (v1 !== v2)
30 throw msg;
31 }
32
33 try
34 {
35 var a = [1, 2];
36 var m = a.filter(mutate);
37
38 assertEqual(a[0], "mutated", "Array a not mutated!");
39 assertEqual(a[1], "mutated", "Array a not mutated!");
40
41 assertEqual(m[0], 1, "Filtered value is value before callback is run");
42 assertEqual(m[1], 2, "Filtered value is value before callback is run");
43 }
44 catch (e)
45 {
46 failed = e;
47 }
48
49
50 expect = false;
51 actual = failed;
52
53 reportCompare(expect, actual, summary);