summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/statements/for-in-with-destructuring-assignments.js
blob: 6741c885e56659b211262f7f8e0ca11fbf26bb07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

var gTestfile = "for-in-with-destructuring-assignments.js";
var BUGNUMBER = 1164741;
var summary = "|for (var <pat> = ... in ...)| is invalid syntax";

print(BUGNUMBER + ": " + summary);

/**************
 * BEGIN TEST *
 **************/

// This is a total grab-bag of junk originally in tests changed when this
// syntax was removed.  Avert your eyes!

assertThrowsInstanceOf(() => eval(`
   for (var [x] = x>>x in [[]<[]])
   {
     [];
   }`),
 SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(function() {
  // Abandon all hope, ye who try to read this.
  eval(`
    (function () {
      for
      (var [x] = function(){}
       in
       (function m(a) {
         if (a < 1) {
           x;
           return;
         }
         return m(a - 1) + m(a - 2);
       })(7)(eval(""))
      )
      {
        [];
      }
    })
  `)();
}, SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval(`
  for (var [e] = [] in (eval("for (b = 0; b < 6; ++b) gc()"))) {}
`), SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval("for (var [ v , c ] = 0 in undefined) { }"),
                       SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval("var b = e; for (var [e] = b in w) c"),
                       SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval("for (var {a: []} = 2 in []) { }"),
                       SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval(`try
  {
    for (var [,{y}] = 1 in []) {}
  }
  catch(ex)
  {
  }`),
SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval("for (var [x] = [] in null);"),
                       SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval("for (var [x] = x in y) var x;"),
                       SyntaxError);

/******************************************************************************/

assertThrowsInstanceOf(() => eval(`
  for (var [arguments] = ({ get y(){} }) in y ) (x);
`),
SyntaxError);

/******************************************************************************/

if (typeof evalcx == 'function') {
  var src = 'try {\n' +
  '    for (var [e] = /x/ in d) {\n' +
  '        (function () {});\n' +
  '    }\n' +
  '} catch (e) {}\n' +
  'try {\n' +
  '    let(x = Object.freeze(this, /x/))\n' +
  '    e = {}.toString\n' +
  '    function y() {}\n' +
  '} catch (e) {}';

  try
  {
    evalcx(src);
    throw new Error("didn't throw");
  }
  catch (e)
  {
    assertEq(e.name === "SyntaxError", true,
             "expected invalid syntax, got " + e);
  }
}

/******************************************************************************/

if (typeof reportCompare === "function")
  reportCompare(true, true);

print("Tests complete");