bug1273858-1.js (893B)
1 // |jit-test| --no-threads 2 3 function t1() { 4 let x = []; 5 6 for (let k = 0; k < 100; ++k) 7 x[k] = () => k; // Lexical capture 8 9 try { 10 eval("k"); 11 throw false; 12 } 13 catch (e) { 14 if (!(e instanceof ReferenceError)) 15 throw "Loop index escaped block"; 16 } 17 18 for (var i = 0; i < 100; ++i) 19 if (x[i]() != i) 20 throw "Bad let capture"; 21 } 22 t1(); 23 t1(); 24 t1(); 25 t1(); 26 27 function t2() { 28 let x = []; 29 let y = {}; 30 31 for (var i = 0; i < 100; ++i) 32 x[i] = i; 33 34 for (const k of x) 35 y[k] = () => k; // Lexical capture 36 37 try { 38 eval("k"); 39 throw false; 40 } 41 catch (e) { 42 if (!(e instanceof ReferenceError)) 43 throw "Loop index escaped block"; 44 } 45 46 for (var i = 0; i < 100; ++i) 47 if (y[i]() != i) 48 throw "Bad const capture"; 49 } 50 t2(); 51 t2(); 52 t2(); 53 t2();