1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15var arr = []; 16for (let i = 0, j = 0; i < 10; j++) 17{ 18 arr[i] = function() { return i + j; } 19 i++; 20} 21 22for (let i = 0; i < 10; i++) 23 assert(arr[i]() === (i * 2 + 1)); 24 25var j = 0, k = 0; 26for (let i = 0; j = i, i < 10; i++) 27{ 28 let i = -3; 29 assert(i === -3); 30 assert(j === k); 31 k++; 32} 33 34var j = 0, k = 0; 35for (let i = 0; eval("j = i"), i < 10; i++) 36{ 37 let i = -3; 38 assert(i === -3); 39 assert(j === k); 40 k++; 41} 42 43var arr = []; 44for (let i in { x:1, y:1, z:1 }) 45{ 46 let str = "P"; 47 arr.push(function () { return str + i; }); 48} 49 50assert(arr[0]() === "Px"); 51assert(arr[1]() === "Py"); 52assert(arr[2]() === "Pz"); 53 54try { 55 for (let i in (function() { return i; })()) {} 56 assert(false); 57} catch (e) { 58 assert(e instanceof ReferenceError); 59} 60 61try { 62 for (let i = 0, j = 0; i < 5; i++, j++) 63 { 64 if (i === 3) 65 { 66 eval("throw -42") 67 } 68 } 69 assert(false); 70} catch (e) { 71 assert(e === -42); 72} 73 74exit: { 75 for (let i = 0, j = 0; i < 5; i++, j++) 76 { 77 if (eval("i === 3")) { 78 assert(i === 3); 79 break exit; 80 } 81 } 82 assert(false); 83} 84 85var f = null, g = null, h = null; 86 87for (let i = 0; 88 f = function() { return i }, i < 1; 89 i++, g = function() { return i }) 90{ 91 h = function() { return i }; 92} 93assert(f() === 1); 94assert(g() === 1); 95assert(h() === 0); 96 97var arr = []; 98for (const i in { aa:4, bb:5, cc:6 }) 99{ 100 arr.push(function () { return i }); 101} 102 103assert(arr[0]() === "aa"); 104assert(arr[1]() === "bb"); 105assert(arr[2]() === "cc"); 106