Debian Codegraph @

rhino/testsrc/tests/js1_7/geniter/regress-366941.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 var gTestfile = 'regress-366941.js';
7
8 //-----------------------------------------------------------------------------
9 var BUGNUMBER = 366941;
10 var summary = 'Destructuring enumerations, iterations';
11 var actual = '';
12 var expect = '';
13
14
15 //-----------------------------------------------------------------------------
16 test();
17 //-----------------------------------------------------------------------------
18
19 function test()
20 {
21 enterFunc ('test');
22 printBugNumber(BUGNUMBER);
23 printStatus (summary);
24
25 var list1 = [[1,2],[3,4],[5,6]];
26 var list2 = [[1,2,3],[4,5,6],[7,8,9]];
27
28 expect = '1,2;3,4;5,6;';
29 actual = '';
30
31 for each (var [foo, bar] in list1) {
32 actual += foo + "," + bar + ";";
33 }
34
35 reportCompare(expect, actual, summary + ': 1');
36
37 expect = '1,2,3;4,5,6;7,8,9;';
38 actual = '';
39 for each (var [foo, bar, baz] in list2) {
40 actual += foo + "," + bar + "," + baz + ";";
41 }
42
43 reportCompare(expect, actual, summary + ': 2');
44
45 function gen(list) {
46 for each (var test in list) {
47 yield test;
48 }
49 }
50
51 var iter1 = gen(list1);
52
53 expect = '1,2;3,4;5,6;';
54 actual = '';
55
56 for (var [foo, bar] in iter1) {
57 actual += foo + "," + bar + ";";
58 }
59
60 reportCompare(expect, actual, summary + ': 3');
61
62 // syntax error in js17
63 var iter2 = gen(list2);
64 expect = /SyntaxError: (invalid for.in left-hand side|Left hand side of for..in loop must be an array of length 2 to accept key.value pair.)/;
65 actual = '';
66
67 try
68 {
69 eval('for (var [foo, bar, baz] in iter2) {' +
70 'actual += foo + "," + bar + "," + baz + ";";' +
71 '}');
72 actual = 'No Error';
73 }
74 catch(ex)
75 {
76 actual = ex + '';
77 }
78
79 reportMatch(expect, actual, summary + ': 4');
80
81 exitFunc ('test');
82 }