js/src/jit-test/tests/basic/testLet.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var otherGlobal = newGlobal();
michael@0 2
michael@0 3 function test(str, arg, result)
michael@0 4 {
michael@0 5 arg = arg || 'ponies';
michael@0 6 result = result || 'ponies';
michael@0 7
michael@0 8 var fun = new Function('x', str);
michael@0 9
michael@0 10 var got = fun.toSource();
michael@0 11 var expect = '(function anonymous(x) {\n' + str + '\n})';
michael@0 12 if (got !== expect) {
michael@0 13 print("GOT: " + got);
michael@0 14 print("EXPECT: " + expect);
michael@0 15 assertEq(got, expect);
michael@0 16 }
michael@0 17
michael@0 18 // test reflection logic
michael@0 19 Reflect.parse(got);
michael@0 20
michael@0 21 // test xdr by cloning a cross-compartment function
michael@0 22 var code = "(function (x) { " + str + " })";
michael@0 23 var c = clone(otherGlobal.evaluate(code, {compileAndGo: false}));
michael@0 24 assertEq(c.toSource(), eval(code).toSource());
michael@0 25
michael@0 26 var got = fun(arg);
michael@0 27 var expect = result;
michael@0 28 if (got !== expect) {
michael@0 29 print("GOT:" + got);
michael@0 30 print("EXPECT: " + expect);
michael@0 31 assertEq(got, expect);
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 function isError(str)
michael@0 36 {
michael@0 37 var caught = false;
michael@0 38 try {
michael@0 39 new Function(str);
michael@0 40 } catch(e) {
michael@0 41 assertEq(String(e).indexOf('TypeError') == 0 || String(e).indexOf('SyntaxError') == 0, true);
michael@0 42 caught = true;
michael@0 43 }
michael@0 44 assertEq(caught, true);
michael@0 45 }
michael@0 46
michael@0 47 // let expr
michael@0 48 test('return let (y) x;');
michael@0 49 test('return let (x) "" + x;', 'unicorns', 'undefined');
michael@0 50 test('return let (y = x) (y++, "" + y);', 'unicorns', 'NaN');
michael@0 51 test('return let (y = 1) (y = x, y);');
michael@0 52 test('return let ([] = x) x;');
michael@0 53 test('return let (x = {a: x}) x.a;');
michael@0 54 test('return let ({a: x} = {a: x}) x;');
michael@0 55 test('return let ([x] = {0: x}) x;');
michael@0 56 test('return let ({0: x} = [x]) x;');
michael@0 57 test('return let ({0: []} = []) x;');
michael@0 58 test('return let ([, ] = x) x;');
michael@0 59 test('return let ([, , , , ] = x) x;');
michael@0 60 test('return let ([[]] = x) x;');
michael@0 61 test('return let ([[[[[[[[[[[[[]]]]]]]]]]]]] = x) x;');
michael@0 62 test('return let ([[], []] = x) x;');
michael@0 63 test('return let ([[[[]]], [], , [], [[]]] = x) x;');
michael@0 64 test('return let ({x: []} = x) x;');
michael@0 65 test('return let ({x: [], y: {x: []}} = x) "ponies";', {y:{}});
michael@0 66 test('return let ({x: []} = x, [{x: []}] = x) "ponies";');
michael@0 67 test('return let (x = x) x;');
michael@0 68 test('return let (x = eval("x")) x;');
michael@0 69 test('return let (x = (let (x = x + 1) x) + 1) x;', 1, 3);
michael@0 70 test('return let (x = (let (x = eval("x") + 1) eval("x")) + 1) eval("x");', 1, 3);
michael@0 71 test('return let (x = x + 1, y = x) y;');
michael@0 72 test('return let (x = x + 1, [] = x, [[, , ]] = x, y = x) y;');
michael@0 73 test('return let ([{a: x}] = x, [, {b: y}] = x) let (x = x + 1, y = y + 2) x + y;', [{a:"p"},{b:"p"}], "p1p2");
michael@0 74 test('return let ([] = []) x;');
michael@0 75 test('return let ([] = [x]) x;');
michael@0 76 test('return let ([a] = (1, [x])) a;');
michael@0 77 test('return let ([a] = (1, x, 1, x)) a;', ['ponies']);
michael@0 78 test('return let ([x] = [x]) x;');
michael@0 79 test('return let ([[a, [b, c]]] = [[x, []]]) a;');
michael@0 80 test('return let ([x, y] = [x, x + 1]) x + y;', 1, 3);
michael@0 81 test('return let ([x, y, z] = [x, x + 1, x + 2]) x + y + z;', 1, 6);
michael@0 82 test('return let ([[x]] = [[x]]) x;');
michael@0 83 test('return let ([x, y] = [x, x + 1]) x;');
michael@0 84 test('return let ([x, [y, z]] = [x, x + 1]) x;');
michael@0 85 test('return let ([{x: [x]}, {y1: y, z1: z}] = [x, x + 1]) x;',{x:['ponies']});
michael@0 86 test('return let (x = (3, x)) x;');
michael@0 87 test('return let (x = x + "s") x;', 'ponie');
michael@0 88 test('return let ([x] = (3, [x])) x;');
michael@0 89 test('return let ([] = [[]] = {}) x;');
michael@0 90 test('return let (y = x) function () {return eval("y");}();');
michael@0 91 test('return eval("let (y = x) y");');
michael@0 92 test('return let (y = x) (eval("var y = 2"), y);', 'ponies', 2);
michael@0 93 test('"use strict";return let (y = x) (eval("var y = 2"), y);');
michael@0 94 test('this.y = x;return let (y = 1) this.eval("y");');
michael@0 95 test('try {let (x = x) eval("throw x");} catch (e) {return e;}');
michael@0 96 test('try {return let (x = eval("throw x")) x;} catch (e) {return e;}');
michael@0 97 isError('let (x = 1, x = 2) x');
michael@0 98 isError('let ([x, y] = a, {a:x} = b) x');
michael@0 99 isError('let ([x, y, x] = a) x');
michael@0 100 isError('let ([x, [y, [x]]] = a) x');
michael@0 101 isError('let (x = function() { return x}) x()return x;');
michael@0 102 isError('(let (x = function() { return x}) x())return x;');
michael@0 103
michael@0 104 // let block
michael@0 105 test('let (y) {return x;}');
michael@0 106 test('let (y = x) {y++;return "" + y;}', 'unicorns', 'NaN');
michael@0 107 test('let (y = 1) {y = x;return y;}');
michael@0 108 test('let (x) {return "" + x;}', 'unicorns', 'undefined');
michael@0 109 test('let ([] = x) {return x;}');
michael@0 110 test('let (x) {}return x;');
michael@0 111 test('let (x = {a: x}) {return x.a;}');
michael@0 112 test('let ({a: x} = {a: x}) {return x;}');
michael@0 113 test('let ([x] = {0: x}) {return x;}');
michael@0 114 test('let ({0: x} = [x]) {return x;}');
michael@0 115 test('let ({0: []} = []) {return x;}');
michael@0 116 test('let ([, ] = x) {return x;}');
michael@0 117 test('let ([, , , , ] = x) {return x;}');
michael@0 118 test('let ([[]] = x) {return x;}');
michael@0 119 test('let ([[[[[[[[[[[[[]]]]]]]]]]]]] = x) {return x;}');
michael@0 120 test('let ([[], []] = x) {return x;}');
michael@0 121 test('let ([[[[]]], [], , [], [[]]] = x) {return x;}');
michael@0 122 test('let ({x: []} = x) {return x;}');
michael@0 123 test('let ({x: [], y: {x: []}} = x) {return "ponies";}', {y:{}});
michael@0 124 test('let ({x: []} = x, [{x: []}] = x) {return "ponies";}');
michael@0 125 test('let (x = x) {return x;}');
michael@0 126 test('let (x = eval("x")) {return x;}');
michael@0 127 test('let (x = (let (x = x + 1) x) + 1) {return x;}', 1, 3);
michael@0 128 test('let (x = (let (x = eval("x") + 1) eval("x")) + 1) {return eval("x");}', 1, 3);
michael@0 129 test('let (x = x + 1, y = x) {return y;}');
michael@0 130 test('let (x = x + 1, [] = x, [[, , ]] = x, y = x) {return y;}');
michael@0 131 test('let ([{a: x}] = x, [, {b: y}] = x) {let (x = x + 1, y = y + 2) {return x + y;}}', [{a:"p"},{b:"p"}], "p1p2");
michael@0 132 test('let ([] = []) {return x;}');
michael@0 133 test('let ([] = [x]) {return x;}');
michael@0 134 test('let ([a] = (1, [x])) {return a;}');
michael@0 135 test('let ([a] = (1, x, 1, x)) {return a;}', ['ponies']);
michael@0 136 test('let ([x] = [x]) {return x;}');
michael@0 137 test('let ([[a, [b, c]]] = [[x, []]]) {return a;}');
michael@0 138 test('let ([x, y] = [x, x + 1]) {return x + y;}', 1, 3);
michael@0 139 test('let ([x, y, z] = [x, x + 1, x + 2]) {return x + y + z;}', 1, 6);
michael@0 140 test('let ([[x]] = [[x]]) {return x;}');
michael@0 141 test('let ([x, y] = [x, x + 1]) {return x;}');
michael@0 142 test('let ([x, [y, z]] = [x, x + 1]) {return x;}');
michael@0 143 test('let ([{x: [x]}, {y1: y, z1: z}] = [x, x + 1]) {return x;}',{x:['ponies']});
michael@0 144 test('let (y = x[1]) {let (x = x[0]) {try {let (y = "unicorns") {throw y;}} catch (e) {return x + y;}}}', ['pon','ies']);
michael@0 145 test('let (x = x) {try {let (x = "unicorns") eval("throw x");} catch (e) {return x;}}');
michael@0 146 test('let ([] = [[]] = {}) {return x;}');
michael@0 147 test('let (y = x) {return function () {return eval("y");}();}');
michael@0 148 test('return eval("let (y = x) {y;}");');
michael@0 149 test('let (y = x) {eval("var y = 2");return y;}', 'ponies', 2);
michael@0 150 test('"use strict";let (y = x) {eval("var y = 2");return y;}');
michael@0 151 test('this.y = x;let (y = 1) {return this.eval("y");}');
michael@0 152 isError('let (x = 1, x = 2) {x}');
michael@0 153 isError('let ([x, y] = a, {a:x} = b) {x}');
michael@0 154 isError('let ([x, y, x] = a) {x}');
michael@0 155 isError('let ([x, [y, [x]]] = a) {x}');
michael@0 156
michael@0 157 // var declarations
michael@0 158 test('var y;return x;');
michael@0 159 test('var y = x;return x;');
michael@0 160 test('var [] = x;return x;');
michael@0 161 test('var [, ] = x;return x;');
michael@0 162 test('var [, , , , ] = x;return x;');
michael@0 163 test('var [[]] = x;return x;');
michael@0 164 test('var [[[[[[[[[[[[[]]]]]]]]]]]]] = x;return x;');
michael@0 165 test('var [[], []] = x;return x;');
michael@0 166 test('var [[[[]]], [], , [], [[]]] = x;return x;');
michael@0 167 test('var {x: []} = x;return x;');
michael@0 168 test('var {x: [], y: {x: []}} = x;return "ponies";', {y:{}});
michael@0 169 test('var {x: []} = x, [{x: []}] = x;return "ponies";');
michael@0 170 test('var x = x;return x;');
michael@0 171 test('var y = y;return "" + y;', 'unicorns', 'undefined');
michael@0 172 test('var x = eval("x");return x;');
michael@0 173 test('var x = (let (x = x + 1) x) + 1;return x;', 1, 3);
michael@0 174 test('var x = (let (x = eval("x") + 1) eval("x")) + 1;return eval("x");', 1, 3);
michael@0 175 test('var X = x + 1, y = x;return y;');
michael@0 176 test('var X = x + 1, [] = X, [[, , ]] = X, y = x;return y;');
michael@0 177 test('var [{a: X}] = x, [, {b: y}] = x;var X = X + 1, y = y + 2;return X + y;', [{a:"p"},{b:"p"}], "p1p2");
michael@0 178 test('var [x] = [x];return x;');
michael@0 179 test('var [[a, [b, c]]] = [[x, []]];return a;');
michael@0 180 test('var [y] = [x];return y;');
michael@0 181 test('var [a] = (1, [x]);return a;');
michael@0 182 test('var [a] = (1, x, 1, x);return a;', ['ponies']);
michael@0 183 test('var [x, y] = [x, x + 1];return x + y;', 1, 3);
michael@0 184 test('var [x, y, z] = [x, x + 1, x + 2];return x + y + z;', 1, 6);
michael@0 185 test('var [[x]] = [[x]];return x;');
michael@0 186 test('var [x, y] = [x, x + 1];return x;');
michael@0 187 test('var [x, [y, z]] = [x, x + 1];return x;');
michael@0 188 test('var [{x: [x]}, {y1: y, z1: z}] = [x, x + 1];return x;',{x:['ponies']});
michael@0 189 test('var [] = [[]] = {};return x;');
michael@0 190 test('if (x) {var y = x;return x;}');
michael@0 191 test('if (x) {y = x;var y = y;return y;}');
michael@0 192 test('if (x) {var z = y;var [y] = x;z += y;}return z;', ['-'], 'undefined-');
michael@0 193
michael@0 194 // let declaration in context
michael@0 195 test('if (x) {let y;return x;}');
michael@0 196 test('if (x) {let x;return "" + x;}', 'unicorns', 'undefined');
michael@0 197 test('if (x) {let y = x;return x;}');
michael@0 198 test('if (x) {y = x;let y = y;return y;}');
michael@0 199 test('if (x) {var z = y;let [y] = x;z += y;}return z;', ['-'], 'undefined-');
michael@0 200 test('if (x) {let y = x;return x;}');
michael@0 201 test('if (x) {let [] = x;return x;}');
michael@0 202 test('if (x) {let [, ] = x;return x;}');
michael@0 203 test('if (x) {let [, , , , ] = x;return x;}');
michael@0 204 test('if (x) {let [[]] = x;return x;}');
michael@0 205 test('if (x) {let [[[[[[[[[[[[[]]]]]]]]]]]]] = x;return x;}');
michael@0 206 test('if (x) {let [[], []] = x;return x;}');
michael@0 207 test('if (x) {let [[[[]]], [], , [], [[]]] = x;return x;}');
michael@0 208 test('if (x) {let {x: []} = x;return x;}');
michael@0 209 test('if (x) {let {x: [], y: {x: []}} = x;return "ponies";}', {y:{}});
michael@0 210 test('if (x) {let {x: []} = x, [{x: []}] = x;return "ponies";}');
michael@0 211 test('if (x) {let x = x;return "" + x;}', 'unicorns', 'undefined');
michael@0 212 test('if (x) {let y = y;return "" + y;}', 'unicorns', 'undefined');
michael@0 213 test('if (x) {let x = eval("x");return "" + x;}', 'unicorns', 'undefined');
michael@0 214 test('if (x) {let y = (let (x = x + 1) x) + 1;return y;}', 1, 3);
michael@0 215 test('if (x) {let y = (let (x = eval("x") + 1) eval("x")) + 1;return eval("y");}', 1, 3);
michael@0 216 test('if (x) {let X = x + 1, y = x;return y;}');
michael@0 217 test('if (x) {let X = x + 1, [] = X, [[, , ]] = X, y = x;return y;}');
michael@0 218 test('if (x) {let [{a: X}] = x, [, {b: Y}] = x;var XX = X + 1, YY = Y + 2;return XX + YY;}', [{a:"p"},{b:"p"}], "p1p2");
michael@0 219 test('if (x) {let [[a, [b, c]]] = [[x, []]];return a;}');
michael@0 220 test('if (x) {let [X] = [x];return X;}');
michael@0 221 test('if (x) {let [y] = [x];return y;}');
michael@0 222 test('if (x) {let [a] = (1, [x]);return a;}');
michael@0 223 test('if (x) {let [a] = (1, x, 1, x);return a;}', ['ponies']);
michael@0 224 test('if (x) {let [X, y] = [x, x + 1];return X + y;}', 1, 3);
michael@0 225 test('if (x) {let [X, y, z] = [x, x + 1, x + 2];return X + y + z;}', 1, 6);
michael@0 226 test('if (x) {let [[X]] = [[x]];return X;}');
michael@0 227 test('if (x) {let [X, y] = [x, x + 1];return X;}');
michael@0 228 test('if (x) {let [X, [y, z]] = [x, x + 1];return X;}');
michael@0 229 test('if (x) {let [{x: [X]}, {y1: y, z1: z}] = [x, x + 1];return X;}',{x:['ponies']});
michael@0 230 test('if (x) {let y = x;try {let x = 1;throw 2;} catch (e) {return y;}}');
michael@0 231 test('if (x) {let [] = [[]] = {};return x;}');
michael@0 232 test('let (y, [] = x) {}try {let a = b(), b;} catch (e) {return x;}');
michael@0 233 test('try {let x = 1;throw 2;} catch (e) {return x;}');
michael@0 234 test('let (y = x) {let x;return y;}');
michael@0 235 test('let (y = x) {let x = y;return x;}');
michael@0 236 test('let ([y, z] = x) {let a = x, b = y;return a;}');
michael@0 237 test('let ([y, z] = x, a = x, [] = x) {let b = x, c = y;return a;}');
michael@0 238 test('function f() {return unicorns;}try {let (x = 1) {let a, b;f();}} catch (e) {return x;}');
michael@0 239 test('function f() {return unicorns;}try {let (x = 1) {let a, b;}f();} catch (e) {return x;}');
michael@0 240 test('x.foo;{let y = x;return y;}');
michael@0 241 test('x.foo;if (x) {x.bar;let y = x;return y;}');
michael@0 242 test('if (x) {let y = x;return function () {return eval("y");}();}');
michael@0 243 test('return eval("let y = x; y");');
michael@0 244 test('if (x) {let y = x;eval("var y = 2");return y;}', 'ponies', 2);
michael@0 245 test('"use strict";if (x) {let y = x;eval("var y = 2");return y;}');
michael@0 246 test('"use strict";if (x) {let y = x;eval("let y = 2");return y;}');
michael@0 247 test('"use strict";if (x) {let y = 1;return eval("let y = x;y;");}');
michael@0 248 test('this.y = x;if (x) {let y = 1;return this.eval("y");}');
michael@0 249 isError('if (x) {let (x = 1, x = 2) {x}}');
michael@0 250 isError('if (x) {let ([x, y] = a, {a:x} = b) {x}}');
michael@0 251 isError('if (x) {let ([x, y, x] = a) {x}}');
michael@0 252 isError('if (x) {let ([x, [y, [x]]] = a) {x}}');
michael@0 253 isError('let ([x, y] = x) {let x;}');
michael@0 254
michael@0 255 // for(;;)
michael@0 256 test('for (;;) {return x;}');
michael@0 257 test('for (let y = 1;;) {return x;}');
michael@0 258 test('for (let y = 1;; ++y) {return x;}');
michael@0 259 test('for (let y = 1; ++y;) {return x;}');
michael@0 260 test('for (let (x = 1) x; x != 1; ++x) {return x;}');
michael@0 261 test('for (let [, {a: [], b: []}] = x, [] = x; x;) {return x;}');
michael@0 262 test('for (let x = 1, [y, z] = x, a = x; z < 4; ++z) {return x + y;}', [2,3], 3);
michael@0 263 test('for (let (x = 1, [{a: b, c: d}] = [{a: 1, c: 2}]) x; x != 1; ++x) {return x;}');
michael@0 264 test('for (let [[a, [b, c]]] = [[x, []]];;) {return a;}');
michael@0 265 test('var sum = 0;for (let y = x; y < 4; ++y) {sum += y;}return sum;', 1, 6);
michael@0 266 test('var sum = 0;for (let x = x, y = 10; x < 4; ++x) {sum += x;}return sum;', 1, 6);
michael@0 267 test('var sum = 0;for (let x = x; x < 4; ++x) {sum += x;}return x;', 1, 1);
michael@0 268 test('var sum = 0;for (let x = eval("x"); x < 4; ++x) {sum += x;}return sum;', 1, 6);
michael@0 269 test('var sum = 0;for (let x = x; eval("x") < 4; ++x) {sum += eval("x");}return sum;', 1, 6);
michael@0 270 test('var sum = 0;for (let x = eval("x"); eval("x") < 4; ++x) {sum += eval("x");}return sum;', 1, 6);
michael@0 271 test('for (var y = 1;;) {return x;}');
michael@0 272 test('for (var y = 1;; ++y) {return x;}');
michael@0 273 test('for (var y = 1; ++y;) {return x;}');
michael@0 274 test('for (var [, {a: [], b: []}] = x, [] = x; x;) {return x;}');
michael@0 275 test('for (var X = 1, [y, z] = x, a = x; z < 4; ++z) {return X + y;}', [2,3], 3);
michael@0 276 test('var sum = 0;for (var y = x; y < 4; ++y) {sum += y;}return sum;', 1, 6);
michael@0 277 test('var sum = 0;for (var X = x, y = 10; X < 4; ++X) {sum += X;}return sum;', 1, 6);
michael@0 278 test('var sum = 0;for (var X = x; X < 4; ++X) {sum += X;}return x;', 1, 1);
michael@0 279 test('var sum = 0;for (var X = eval("x"); X < 4; ++X) {sum += X;}return sum;', 1, 6);
michael@0 280 test('var sum = 0;for (var X = x; eval("X") < 4; ++X) {sum += eval("X");}return sum;', 1, 6);
michael@0 281 test('var sum = 0;for (var X = eval("x"); eval("X") < 4; ++X) {sum += eval("X");}return sum;', 1, 6);
michael@0 282 test('try {for (let x = eval("throw x");;) {}} catch (e) {return e;}');
michael@0 283 test('try {for (let x = x + "s"; eval("throw x");) {}} catch (e) {return e;}', 'ponie');
michael@0 284 test('for (let y = x;;) {let x;return y;}');
michael@0 285 test('for (let y = x;;) {let y;return x;}');
michael@0 286 test('for (let y;;) {let y;return x;}');
michael@0 287 test('for (let a = x;;) {let c = x, d = x;return c;}');
michael@0 288 test('for (let [a, b] = x;;) {let c = x, d = x;return c;}');
michael@0 289 test('for (let [] = [[]] = {};;) {return x;}');
michael@0 290 test('for (let [a] = (1, [x]);;) {return a;}');
michael@0 291 test('for (let [a] = (1, x, 1, x);;) {return a;}', ['ponies']);
michael@0 292 isError('for (let x = 1, x = 2;;) {}');
michael@0 293 isError('for (let [x, y] = a, {a:x} = b;;) {}');
michael@0 294 isError('for (let [x, y, x] = a;;) {}');
michael@0 295 isError('for (let [x, [y, [x]]] = a;;) {}');
michael@0 296
michael@0 297 // for(in)
michael@0 298 test('for (let i in x) {return x;}');
michael@0 299 test('for (let i in x) {let y;return x;}');
michael@0 300 test('for each (let [a, b] in x) {let y;return x;}');
michael@0 301 test('for (let i in x) {let (i = x) {return i;}}');
michael@0 302 test('for (let i in x) {let i = x;return i;}');
michael@0 303 test('for each (let [x, y] in x) {return x + y;}', [['ponies', '']]);
michael@0 304 test('for each (let [{0: x, 1: y}, z] in x) {return x + y + z;}', [[['po','nies'], '']]);
michael@0 305 test('var s = "";for (let a in x) {for (let b in x) {s += a + b;}}return s;', [1,2], '00011011');
michael@0 306 test('var res = "";for (let i in x) {res += x[i];}return res;');
michael@0 307 test('var res = "";for (var i in x) {res += x[i];}return res;');
michael@0 308 test('for each (let {x: y, y: x} in [{x: x, y: x}]) {return y;}');
michael@0 309 test('for (let x in eval("x")) {return x;}', {ponies:true});
michael@0 310 test('for (let x in x) {return eval("x");}', {ponies:true});
michael@0 311 test('for (let x in eval("x")) {return eval("x");}', {ponies:true});
michael@0 312 test('for ((let (x = {y: true}) x).y in eval("x")) {return eval("x");}');
michael@0 313 test('for (let i in x) {break;}return x;');
michael@0 314 test('for (let i in x) {break;}return eval("x");');
michael@0 315 test('for (let x in x) {break;}return x;');
michael@0 316 test('for (let x in x) {break;}return eval("x");');
michael@0 317 test('a:for (let i in x) {for (let j in x) {break a;}}return x;');
michael@0 318 test('a:for (let i in x) {for (let j in x) {break a;}}return eval("x");');
michael@0 319 test('var j;for (let i in x) {j = i;break;}return j;', {ponies:true});
michael@0 320 test('try {for (let x in eval("throw x")) {}} catch (e) {return e;}');
michael@0 321 test('try {for each (let x in x) {eval("throw x");}} catch (e) {return e;}', ['ponies']);
michael@0 322 isError('for (let [x, x] in o) {}');
michael@0 323 isError('for (let [x, y, x] in o) {}');
michael@0 324 isError('for (let [x, [y, [x]]] in o) {}');
michael@0 325
michael@0 326 // genexps
michael@0 327 test('return (i for (i in x)).next();', {ponies:true});
michael@0 328 test('return (eval("i") for (i in x)).next();', {ponies:true});
michael@0 329 test('return (eval("i") for (i in eval("x"))).next();', {ponies:true});
michael@0 330 test('try {return (eval("throw i") for (i in x)).next();} catch (e) {return e;}', {ponies:true});
michael@0 331
michael@0 332 // array comprehension
michael@0 333 test('return [i for (i in x)][0];', {ponies:true});
michael@0 334 test('return [eval("i") for (i in x)][0];', {ponies:true});
michael@0 335 test('return [eval("i") for (i in eval("x"))][0];', {ponies:true});
michael@0 336 test('try {return [eval("throw i") for (i in x)][0];} catch (e) {return e;}', {ponies:true});
michael@0 337
michael@0 338 // don't forget about switch craziness
michael@0 339 test('var y = 3;switch (function () {return eval("y");}()) {case 3:let y;return x;default:;}');
michael@0 340 test('switch (x) {case 3:let y;return 3;case 4:let z;return 4;default:return x;}');
michael@0 341 test('switch (x) {case 3:let x;break;default:if (x === undefined) {return "ponies";}}');
michael@0 342 test('switch (x) {case 3:default:let y;let (y = x) {return y;}}');
michael@0 343 isError('switch (x) {case 3:let y;return 3;case 4:let y;return 4;default:;}');

mercurial