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 a = 1; 16var b = 2; 17 18function f(x = eval("eval('var a = 3; function b() { return 4 } () => a')"), y = b) { 19 eval("eval('var a = 5; function b() { return 6 }')"); 20 21 assert(a === 5); 22 assert(b() === 6); 23 24 assert(x() === 3); 25 assert(y() === 4); 26 27 delete a; 28 delete b; 29 30 assert(a === 3); 31 assert(b() === 4); 32 33 assert(x() === 3); 34 assert(y() === 4); 35 36 delete a; 37 delete b; 38 39 assert(a === 1); 40 assert(b === 2); 41 42 assert(x() === 1); 43 assert(y() === 4); 44} 45f() 46 47function g() { 48 'use strict' 49 50 function h(x, y = function() { return x }) { 51 var x = 2; 52 53 /* This should not overwrite y. */ 54 eval("var y = 3; assert (y === 3)"); 55 56 assert(x === 2); 57 assert(typeof y === "function"); 58 assert(y() === 1); 59 } 60 h(1); 61} 62g(); 63 64function h(a, get = () => a, set = (v) => a = v) { 65 assert(a === 1); 66 67 var a = 2; 68 69 assert(a === 2); 70 assert(get() === 1); 71 72 set(3) 73 a = 4; 74 75 assert(a === 4); 76 assert(get() === 3); 77} 78h(1); 79 80function i([a], get = () => a, set = (v) => a = v) { 81 assert(a === 1); 82 83 var a; 84 assert(a === 1); 85 86 a = 2; 87 88 assert(a === 2); 89 assert(get() === 1); 90 91 set(3) 92 a = 4; 93 94 assert(a === 4); 95 assert(get() === 3); 96} 97i([1]); 98 99function j(a = eval()) { 100 var a = 3.14; 101 102 try { 103 eval("throw 1; function a() { return 8; }") 104 assert(false) 105 } catch (e) { 106 assert(e === 1) 107 } 108 109 assert(a() === 8) 110} 111j() 112