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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/testLet.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,343 @@
     1.4 +var otherGlobal = newGlobal();
     1.5 +
     1.6 +function test(str, arg, result)
     1.7 +{
     1.8 +    arg = arg || 'ponies';
     1.9 +    result = result || 'ponies';
    1.10 +
    1.11 +    var fun = new Function('x', str);
    1.12 +
    1.13 +    var got = fun.toSource();
    1.14 +    var expect = '(function anonymous(x) {\n' + str + '\n})';
    1.15 +    if (got !== expect) {
    1.16 +        print("GOT:    " + got);
    1.17 +        print("EXPECT: " + expect);
    1.18 +        assertEq(got, expect);
    1.19 +    }
    1.20 +
    1.21 +    // test reflection logic
    1.22 +    Reflect.parse(got);
    1.23 +
    1.24 +    // test xdr by cloning a cross-compartment function
    1.25 +    var code = "(function (x) { " + str + " })";
    1.26 +    var c = clone(otherGlobal.evaluate(code, {compileAndGo: false}));
    1.27 +    assertEq(c.toSource(), eval(code).toSource());
    1.28 +
    1.29 +    var got = fun(arg);
    1.30 +    var expect = result;
    1.31 +    if (got !== expect) {
    1.32 +        print("GOT:" + got);
    1.33 +        print("EXPECT: " + expect);
    1.34 +        assertEq(got, expect);
    1.35 +    }
    1.36 +}
    1.37 +
    1.38 +function isError(str)
    1.39 +{
    1.40 +    var caught = false;
    1.41 +    try {
    1.42 +        new Function(str);
    1.43 +    } catch(e) {
    1.44 +        assertEq(String(e).indexOf('TypeError') == 0 || String(e).indexOf('SyntaxError') == 0, true);
    1.45 +        caught = true;
    1.46 +    }
    1.47 +    assertEq(caught, true);
    1.48 +}
    1.49 +
    1.50 +// let expr
    1.51 +test('return let (y) x;');
    1.52 +test('return let (x) "" + x;', 'unicorns', 'undefined');
    1.53 +test('return let (y = x) (y++, "" + y);', 'unicorns', 'NaN');
    1.54 +test('return let (y = 1) (y = x, y);');
    1.55 +test('return let ([] = x) x;');
    1.56 +test('return let (x = {a: x}) x.a;');
    1.57 +test('return let ({a: x} = {a: x}) x;');
    1.58 +test('return let ([x] = {0: x}) x;');
    1.59 +test('return let ({0: x} = [x]) x;');
    1.60 +test('return let ({0: []} = []) x;');
    1.61 +test('return let ([, ] = x) x;');
    1.62 +test('return let ([, , , , ] = x) x;');
    1.63 +test('return let ([[]] = x) x;');
    1.64 +test('return let ([[[[[[[[[[[[[]]]]]]]]]]]]] = x) x;');
    1.65 +test('return let ([[], []] = x) x;');
    1.66 +test('return let ([[[[]]], [], , [], [[]]] = x) x;');
    1.67 +test('return let ({x: []} = x) x;');
    1.68 +test('return let ({x: [], y: {x: []}} = x) "ponies";', {y:{}});
    1.69 +test('return let ({x: []} = x, [{x: []}] = x) "ponies";');
    1.70 +test('return let (x = x) x;');
    1.71 +test('return let (x = eval("x")) x;');
    1.72 +test('return let (x = (let (x = x + 1) x) + 1) x;', 1, 3);
    1.73 +test('return let (x = (let (x = eval("x") + 1) eval("x")) + 1) eval("x");', 1, 3);
    1.74 +test('return let (x = x + 1, y = x) y;');
    1.75 +test('return let (x = x + 1, [] = x, [[, , ]] = x, y = x) y;');
    1.76 +test('return let ([{a: x}] = x, [, {b: y}] = x) let (x = x + 1, y = y + 2) x + y;', [{a:"p"},{b:"p"}], "p1p2");
    1.77 +test('return let ([] = []) x;');
    1.78 +test('return let ([] = [x]) x;');
    1.79 +test('return let ([a] = (1, [x])) a;');
    1.80 +test('return let ([a] = (1, x, 1, x)) a;', ['ponies']);
    1.81 +test('return let ([x] = [x]) x;');
    1.82 +test('return let ([[a, [b, c]]] = [[x, []]]) a;');
    1.83 +test('return let ([x, y] = [x, x + 1]) x + y;', 1, 3);
    1.84 +test('return let ([x, y, z] = [x, x + 1, x + 2]) x + y + z;', 1, 6);
    1.85 +test('return let ([[x]] = [[x]]) x;');
    1.86 +test('return let ([x, y] = [x, x + 1]) x;');
    1.87 +test('return let ([x, [y, z]] = [x, x + 1]) x;');
    1.88 +test('return let ([{x: [x]}, {y1: y, z1: z}] = [x, x + 1]) x;',{x:['ponies']});
    1.89 +test('return let (x = (3, x)) x;');
    1.90 +test('return let (x = x + "s") x;', 'ponie');
    1.91 +test('return let ([x] = (3, [x])) x;');
    1.92 +test('return let ([] = [[]] = {}) x;');
    1.93 +test('return let (y = x) function () {return eval("y");}();');
    1.94 +test('return eval("let (y = x) y");');
    1.95 +test('return let (y = x) (eval("var y = 2"), y);', 'ponies', 2);
    1.96 +test('"use strict";return let (y = x) (eval("var y = 2"), y);');
    1.97 +test('this.y = x;return let (y = 1) this.eval("y");');
    1.98 +test('try {let (x = x) eval("throw x");} catch (e) {return e;}');
    1.99 +test('try {return let (x = eval("throw x")) x;} catch (e) {return e;}');
   1.100 +isError('let (x = 1, x = 2) x');
   1.101 +isError('let ([x, y] = a, {a:x} = b) x');
   1.102 +isError('let ([x, y, x] = a) x');
   1.103 +isError('let ([x, [y, [x]]] = a) x');
   1.104 +isError('let (x = function() { return x}) x()return x;');
   1.105 +isError('(let (x = function() { return x}) x())return x;');
   1.106 +
   1.107 +// let block
   1.108 +test('let (y) {return x;}');
   1.109 +test('let (y = x) {y++;return "" + y;}', 'unicorns', 'NaN');
   1.110 +test('let (y = 1) {y = x;return y;}');
   1.111 +test('let (x) {return "" + x;}', 'unicorns', 'undefined');
   1.112 +test('let ([] = x) {return x;}');
   1.113 +test('let (x) {}return x;');
   1.114 +test('let (x = {a: x}) {return x.a;}');
   1.115 +test('let ({a: x} = {a: x}) {return x;}');
   1.116 +test('let ([x] = {0: x}) {return x;}');
   1.117 +test('let ({0: x} = [x]) {return x;}');
   1.118 +test('let ({0: []} = []) {return x;}');
   1.119 +test('let ([, ] = x) {return x;}');
   1.120 +test('let ([, , , , ] = x) {return x;}');
   1.121 +test('let ([[]] = x) {return x;}');
   1.122 +test('let ([[[[[[[[[[[[[]]]]]]]]]]]]] = x) {return x;}');
   1.123 +test('let ([[], []] = x) {return x;}');
   1.124 +test('let ([[[[]]], [], , [], [[]]] = x) {return x;}');
   1.125 +test('let ({x: []} = x) {return x;}');
   1.126 +test('let ({x: [], y: {x: []}} = x) {return "ponies";}', {y:{}});
   1.127 +test('let ({x: []} = x, [{x: []}] = x) {return "ponies";}');
   1.128 +test('let (x = x) {return x;}');
   1.129 +test('let (x = eval("x")) {return x;}');
   1.130 +test('let (x = (let (x = x + 1) x) + 1) {return x;}', 1, 3);
   1.131 +test('let (x = (let (x = eval("x") + 1) eval("x")) + 1) {return eval("x");}', 1, 3);
   1.132 +test('let (x = x + 1, y = x) {return y;}');
   1.133 +test('let (x = x + 1, [] = x, [[, , ]] = x, y = x) {return y;}');
   1.134 +test('let ([{a: x}] = x, [, {b: y}] = x) {let (x = x + 1, y = y + 2) {return x + y;}}', [{a:"p"},{b:"p"}], "p1p2");
   1.135 +test('let ([] = []) {return x;}');
   1.136 +test('let ([] = [x]) {return x;}');
   1.137 +test('let ([a] = (1, [x])) {return a;}');
   1.138 +test('let ([a] = (1, x, 1, x)) {return a;}', ['ponies']);
   1.139 +test('let ([x] = [x]) {return x;}');
   1.140 +test('let ([[a, [b, c]]] = [[x, []]]) {return a;}');
   1.141 +test('let ([x, y] = [x, x + 1]) {return x + y;}', 1, 3);
   1.142 +test('let ([x, y, z] = [x, x + 1, x + 2]) {return x + y + z;}', 1, 6);
   1.143 +test('let ([[x]] = [[x]]) {return x;}');
   1.144 +test('let ([x, y] = [x, x + 1]) {return x;}');
   1.145 +test('let ([x, [y, z]] = [x, x + 1]) {return x;}');
   1.146 +test('let ([{x: [x]}, {y1: y, z1: z}] = [x, x + 1]) {return x;}',{x:['ponies']});
   1.147 +test('let (y = x[1]) {let (x = x[0]) {try {let (y = "unicorns") {throw y;}} catch (e) {return x + y;}}}', ['pon','ies']);
   1.148 +test('let (x = x) {try {let (x = "unicorns") eval("throw x");} catch (e) {return x;}}');
   1.149 +test('let ([] = [[]] = {}) {return x;}');
   1.150 +test('let (y = x) {return function () {return eval("y");}();}');
   1.151 +test('return eval("let (y = x) {y;}");');
   1.152 +test('let (y = x) {eval("var y = 2");return y;}', 'ponies', 2);
   1.153 +test('"use strict";let (y = x) {eval("var y = 2");return y;}');
   1.154 +test('this.y = x;let (y = 1) {return this.eval("y");}');
   1.155 +isError('let (x = 1, x = 2) {x}');
   1.156 +isError('let ([x, y] = a, {a:x} = b) {x}');
   1.157 +isError('let ([x, y, x] = a) {x}');
   1.158 +isError('let ([x, [y, [x]]] = a) {x}');
   1.159 +
   1.160 +// var declarations
   1.161 +test('var y;return x;');
   1.162 +test('var y = x;return x;');
   1.163 +test('var [] = x;return x;');
   1.164 +test('var [, ] = x;return x;');
   1.165 +test('var [, , , , ] = x;return x;');
   1.166 +test('var [[]] = x;return x;');
   1.167 +test('var [[[[[[[[[[[[[]]]]]]]]]]]]] = x;return x;');
   1.168 +test('var [[], []] = x;return x;');
   1.169 +test('var [[[[]]], [], , [], [[]]] = x;return x;');
   1.170 +test('var {x: []} = x;return x;');
   1.171 +test('var {x: [], y: {x: []}} = x;return "ponies";', {y:{}});
   1.172 +test('var {x: []} = x, [{x: []}] = x;return "ponies";');
   1.173 +test('var x = x;return x;');
   1.174 +test('var y = y;return "" + y;', 'unicorns', 'undefined');
   1.175 +test('var x = eval("x");return x;');
   1.176 +test('var x = (let (x = x + 1) x) + 1;return x;', 1, 3);
   1.177 +test('var x = (let (x = eval("x") + 1) eval("x")) + 1;return eval("x");', 1, 3);
   1.178 +test('var X = x + 1, y = x;return y;');
   1.179 +test('var X = x + 1, [] = X, [[, , ]] = X, y = x;return y;');
   1.180 +test('var [{a: X}] = x, [, {b: y}] = x;var X = X + 1, y = y + 2;return X + y;', [{a:"p"},{b:"p"}], "p1p2");
   1.181 +test('var [x] = [x];return x;');
   1.182 +test('var [[a, [b, c]]] = [[x, []]];return a;');
   1.183 +test('var [y] = [x];return y;');
   1.184 +test('var [a] = (1, [x]);return a;');
   1.185 +test('var [a] = (1, x, 1, x);return a;', ['ponies']);
   1.186 +test('var [x, y] = [x, x + 1];return x + y;', 1, 3);
   1.187 +test('var [x, y, z] = [x, x + 1, x + 2];return x + y + z;', 1, 6);
   1.188 +test('var [[x]] = [[x]];return x;');
   1.189 +test('var [x, y] = [x, x + 1];return x;');
   1.190 +test('var [x, [y, z]] = [x, x + 1];return x;');
   1.191 +test('var [{x: [x]}, {y1: y, z1: z}] = [x, x + 1];return x;',{x:['ponies']});
   1.192 +test('var [] = [[]] = {};return x;');
   1.193 +test('if (x) {var y = x;return x;}');
   1.194 +test('if (x) {y = x;var y = y;return y;}');
   1.195 +test('if (x) {var z = y;var [y] = x;z += y;}return z;', ['-'], 'undefined-');
   1.196 +
   1.197 +// let declaration in context
   1.198 +test('if (x) {let y;return x;}');
   1.199 +test('if (x) {let x;return "" + x;}', 'unicorns', 'undefined');
   1.200 +test('if (x) {let y = x;return x;}');
   1.201 +test('if (x) {y = x;let y = y;return y;}');
   1.202 +test('if (x) {var z = y;let [y] = x;z += y;}return z;', ['-'], 'undefined-');
   1.203 +test('if (x) {let y = x;return x;}');
   1.204 +test('if (x) {let [] = x;return x;}');
   1.205 +test('if (x) {let [, ] = x;return x;}');
   1.206 +test('if (x) {let [, , , , ] = x;return x;}');
   1.207 +test('if (x) {let [[]] = x;return x;}');
   1.208 +test('if (x) {let [[[[[[[[[[[[[]]]]]]]]]]]]] = x;return x;}');
   1.209 +test('if (x) {let [[], []] = x;return x;}');
   1.210 +test('if (x) {let [[[[]]], [], , [], [[]]] = x;return x;}');
   1.211 +test('if (x) {let {x: []} = x;return x;}');
   1.212 +test('if (x) {let {x: [], y: {x: []}} = x;return "ponies";}', {y:{}});
   1.213 +test('if (x) {let {x: []} = x, [{x: []}] = x;return "ponies";}');
   1.214 +test('if (x) {let x = x;return "" + x;}', 'unicorns', 'undefined');
   1.215 +test('if (x) {let y = y;return "" + y;}', 'unicorns', 'undefined');
   1.216 +test('if (x) {let x = eval("x");return "" + x;}', 'unicorns', 'undefined');
   1.217 +test('if (x) {let y = (let (x = x + 1) x) + 1;return y;}', 1, 3);
   1.218 +test('if (x) {let y = (let (x = eval("x") + 1) eval("x")) + 1;return eval("y");}', 1, 3);
   1.219 +test('if (x) {let X = x + 1, y = x;return y;}');
   1.220 +test('if (x) {let X = x + 1, [] = X, [[, , ]] = X, y = x;return y;}');
   1.221 +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");
   1.222 +test('if (x) {let [[a, [b, c]]] = [[x, []]];return a;}');
   1.223 +test('if (x) {let [X] = [x];return X;}');
   1.224 +test('if (x) {let [y] = [x];return y;}');
   1.225 +test('if (x) {let [a] = (1, [x]);return a;}');
   1.226 +test('if (x) {let [a] = (1, x, 1, x);return a;}', ['ponies']);
   1.227 +test('if (x) {let [X, y] = [x, x + 1];return X + y;}', 1, 3);
   1.228 +test('if (x) {let [X, y, z] = [x, x + 1, x + 2];return X + y + z;}', 1, 6);
   1.229 +test('if (x) {let [[X]] = [[x]];return X;}');
   1.230 +test('if (x) {let [X, y] = [x, x + 1];return X;}');
   1.231 +test('if (x) {let [X, [y, z]] = [x, x + 1];return X;}');
   1.232 +test('if (x) {let [{x: [X]}, {y1: y, z1: z}] = [x, x + 1];return X;}',{x:['ponies']});
   1.233 +test('if (x) {let y = x;try {let x = 1;throw 2;} catch (e) {return y;}}');
   1.234 +test('if (x) {let [] = [[]] = {};return x;}');
   1.235 +test('let (y, [] = x) {}try {let a = b(), b;} catch (e) {return x;}');
   1.236 +test('try {let x = 1;throw 2;} catch (e) {return x;}');
   1.237 +test('let (y = x) {let x;return y;}');
   1.238 +test('let (y = x) {let x = y;return x;}');
   1.239 +test('let ([y, z] = x) {let a = x, b = y;return a;}');
   1.240 +test('let ([y, z] = x, a = x, [] = x) {let b = x, c = y;return a;}');
   1.241 +test('function f() {return unicorns;}try {let (x = 1) {let a, b;f();}} catch (e) {return x;}');
   1.242 +test('function f() {return unicorns;}try {let (x = 1) {let a, b;}f();} catch (e) {return x;}');
   1.243 +test('x.foo;{let y = x;return y;}');
   1.244 +test('x.foo;if (x) {x.bar;let y = x;return y;}');
   1.245 +test('if (x) {let y = x;return function () {return eval("y");}();}');
   1.246 +test('return eval("let y = x; y");');
   1.247 +test('if (x) {let y = x;eval("var y = 2");return y;}', 'ponies', 2);
   1.248 +test('"use strict";if (x) {let y = x;eval("var y = 2");return y;}');
   1.249 +test('"use strict";if (x) {let y = x;eval("let y = 2");return y;}');
   1.250 +test('"use strict";if (x) {let y = 1;return eval("let y = x;y;");}');
   1.251 +test('this.y = x;if (x) {let y = 1;return this.eval("y");}');
   1.252 +isError('if (x) {let (x = 1, x = 2) {x}}');
   1.253 +isError('if (x) {let ([x, y] = a, {a:x} = b) {x}}');
   1.254 +isError('if (x) {let ([x, y, x] = a) {x}}');
   1.255 +isError('if (x) {let ([x, [y, [x]]] = a) {x}}');
   1.256 +isError('let ([x, y] = x) {let x;}');
   1.257 +
   1.258 +// for(;;)
   1.259 +test('for (;;) {return x;}');
   1.260 +test('for (let y = 1;;) {return x;}');
   1.261 +test('for (let y = 1;; ++y) {return x;}');
   1.262 +test('for (let y = 1; ++y;) {return x;}');
   1.263 +test('for (let (x = 1) x; x != 1; ++x) {return x;}');
   1.264 +test('for (let [, {a: [], b: []}] = x, [] = x; x;) {return x;}');
   1.265 +test('for (let x = 1, [y, z] = x, a = x; z < 4; ++z) {return x + y;}', [2,3], 3);
   1.266 +test('for (let (x = 1, [{a: b, c: d}] = [{a: 1, c: 2}]) x; x != 1; ++x) {return x;}');
   1.267 +test('for (let [[a, [b, c]]] = [[x, []]];;) {return a;}');
   1.268 +test('var sum = 0;for (let y = x; y < 4; ++y) {sum += y;}return sum;', 1, 6);
   1.269 +test('var sum = 0;for (let x = x, y = 10; x < 4; ++x) {sum += x;}return sum;', 1, 6);
   1.270 +test('var sum = 0;for (let x = x; x < 4; ++x) {sum += x;}return x;', 1, 1);
   1.271 +test('var sum = 0;for (let x = eval("x"); x < 4; ++x) {sum += x;}return sum;', 1, 6);
   1.272 +test('var sum = 0;for (let x = x; eval("x") < 4; ++x) {sum += eval("x");}return sum;', 1, 6);
   1.273 +test('var sum = 0;for (let x = eval("x"); eval("x") < 4; ++x) {sum += eval("x");}return sum;', 1, 6);
   1.274 +test('for (var y = 1;;) {return x;}');
   1.275 +test('for (var y = 1;; ++y) {return x;}');
   1.276 +test('for (var y = 1; ++y;) {return x;}');
   1.277 +test('for (var [, {a: [], b: []}] = x, [] = x; x;) {return x;}');
   1.278 +test('for (var X = 1, [y, z] = x, a = x; z < 4; ++z) {return X + y;}', [2,3], 3);
   1.279 +test('var sum = 0;for (var y = x; y < 4; ++y) {sum += y;}return sum;', 1, 6);
   1.280 +test('var sum = 0;for (var X = x, y = 10; X < 4; ++X) {sum += X;}return sum;', 1, 6);
   1.281 +test('var sum = 0;for (var X = x; X < 4; ++X) {sum += X;}return x;', 1, 1);
   1.282 +test('var sum = 0;for (var X = eval("x"); X < 4; ++X) {sum += X;}return sum;', 1, 6);
   1.283 +test('var sum = 0;for (var X = x; eval("X") < 4; ++X) {sum += eval("X");}return sum;', 1, 6);
   1.284 +test('var sum = 0;for (var X = eval("x"); eval("X") < 4; ++X) {sum += eval("X");}return sum;', 1, 6);
   1.285 +test('try {for (let x = eval("throw x");;) {}} catch (e) {return e;}');
   1.286 +test('try {for (let x = x + "s"; eval("throw x");) {}} catch (e) {return e;}', 'ponie');
   1.287 +test('for (let y = x;;) {let x;return y;}');
   1.288 +test('for (let y = x;;) {let y;return x;}');
   1.289 +test('for (let y;;) {let y;return x;}');
   1.290 +test('for (let a = x;;) {let c = x, d = x;return c;}');
   1.291 +test('for (let [a, b] = x;;) {let c = x, d = x;return c;}');
   1.292 +test('for (let [] = [[]] = {};;) {return x;}');
   1.293 +test('for (let [a] = (1, [x]);;) {return a;}');
   1.294 +test('for (let [a] = (1, x, 1, x);;) {return a;}', ['ponies']);
   1.295 +isError('for (let x = 1, x = 2;;) {}');
   1.296 +isError('for (let [x, y] = a, {a:x} = b;;) {}');
   1.297 +isError('for (let [x, y, x] = a;;) {}');
   1.298 +isError('for (let [x, [y, [x]]] = a;;) {}');
   1.299 +
   1.300 +// for(in)
   1.301 +test('for (let i in x) {return x;}');
   1.302 +test('for (let i in x) {let y;return x;}');
   1.303 +test('for each (let [a, b] in x) {let y;return x;}');
   1.304 +test('for (let i in x) {let (i = x) {return i;}}');
   1.305 +test('for (let i in x) {let i = x;return i;}');
   1.306 +test('for each (let [x, y] in x) {return x + y;}', [['ponies', '']]);
   1.307 +test('for each (let [{0: x, 1: y}, z] in x) {return x + y + z;}', [[['po','nies'], '']]);
   1.308 +test('var s = "";for (let a in x) {for (let b in x) {s += a + b;}}return s;', [1,2], '00011011');
   1.309 +test('var res = "";for (let i in x) {res += x[i];}return res;');
   1.310 +test('var res = "";for (var i in x) {res += x[i];}return res;');
   1.311 +test('for each (let {x: y, y: x} in [{x: x, y: x}]) {return y;}');
   1.312 +test('for (let x in eval("x")) {return x;}', {ponies:true});
   1.313 +test('for (let x in x) {return eval("x");}', {ponies:true});
   1.314 +test('for (let x in eval("x")) {return eval("x");}', {ponies:true});
   1.315 +test('for ((let (x = {y: true}) x).y in eval("x")) {return eval("x");}');
   1.316 +test('for (let i in x) {break;}return x;');
   1.317 +test('for (let i in x) {break;}return eval("x");');
   1.318 +test('for (let x in x) {break;}return x;');
   1.319 +test('for (let x in x) {break;}return eval("x");');
   1.320 +test('a:for (let i in x) {for (let j in x) {break a;}}return x;');
   1.321 +test('a:for (let i in x) {for (let j in x) {break a;}}return eval("x");');
   1.322 +test('var j;for (let i in x) {j = i;break;}return j;', {ponies:true});
   1.323 +test('try {for (let x in eval("throw x")) {}} catch (e) {return e;}');
   1.324 +test('try {for each (let x in x) {eval("throw x");}} catch (e) {return e;}', ['ponies']);
   1.325 +isError('for (let [x, x] in o) {}');
   1.326 +isError('for (let [x, y, x] in o) {}');
   1.327 +isError('for (let [x, [y, [x]]] in o) {}');
   1.328 +
   1.329 +// genexps
   1.330 +test('return (i for (i in x)).next();', {ponies:true});
   1.331 +test('return (eval("i") for (i in x)).next();', {ponies:true});
   1.332 +test('return (eval("i") for (i in eval("x"))).next();', {ponies:true});
   1.333 +test('try {return (eval("throw i") for (i in x)).next();} catch (e) {return e;}', {ponies:true});
   1.334 +
   1.335 +// array comprehension
   1.336 +test('return [i for (i in x)][0];', {ponies:true});
   1.337 +test('return [eval("i") for (i in x)][0];', {ponies:true});
   1.338 +test('return [eval("i") for (i in eval("x"))][0];', {ponies:true});
   1.339 +test('try {return [eval("throw i") for (i in x)][0];} catch (e) {return e;}', {ponies:true});
   1.340 +
   1.341 +// don't forget about switch craziness
   1.342 +test('var y = 3;switch (function () {return eval("y");}()) {case 3:let y;return x;default:;}');
   1.343 +test('switch (x) {case 3:let y;return 3;case 4:let z;return 4;default:return x;}');
   1.344 +test('switch (x) {case 3:let x;break;default:if (x === undefined) {return "ponies";}}');
   1.345 +test('switch (x) {case 3:default:let y;let (y = x) {return y;}}');
   1.346 +isError('switch (x) {case 3:let y;return 3;case 4:let y;return 4;default:;}');

mercurial