yield-in-object-destr-function.js (4013B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 6 // Destructuring binding patterns with var. 7 (function() { 8 var {a: yield} = {a: "yield-with-name"}; 9 assertEq(yield, "yield-with-name"); 10 11 var {yield} = {yield: "yield-with-shorthand"}; 12 assertEq(yield, "yield-with-shorthand"); 13 14 var {yield = 0} = {yield: "yield-with-coverinitname"}; 15 assertEq(yield, "yield-with-coverinitname"); 16 })(); 17 18 assertThrowsInstanceOf(() => eval(` 19 "use strict"; 20 function f() { 21 var {a: yield} = {}; 22 } 23 `), SyntaxError); 24 25 assertThrowsInstanceOf(() => eval(` 26 "use strict"; 27 function f() { 28 var {yield} = {}; 29 } 30 `), SyntaxError); 31 32 assertThrowsInstanceOf(() => eval(` 33 "use strict"; 34 function f() { 35 var {yield = 0} = {}; 36 } 37 `), SyntaxError); 38 39 40 // Destructuring binding patterns with let. 41 (function(){ 42 let {a: yield} = {a: "yield-with-name"}; 43 assertEq(yield, "yield-with-name"); 44 })(); 45 46 (function() { 47 let {yield} = {yield: "yield-with-shorthand"}; 48 assertEq(yield, "yield-with-shorthand"); 49 })(); 50 51 (function() { 52 let {yield = 0} = {yield: "yield-with-coverinitname"}; 53 assertEq(yield, "yield-with-coverinitname"); 54 })(); 55 56 assertThrowsInstanceOf(() => eval(` 57 "use strict"; 58 function f() { 59 let {a: yield} = {}; 60 } 61 `), SyntaxError); 62 63 assertThrowsInstanceOf(() => eval(` 64 "use strict"; 65 function f() { 66 let {yield} = {}; 67 } 68 `), SyntaxError); 69 70 assertThrowsInstanceOf(() => eval(` 71 "use strict"; 72 function f() { 73 let {yield = 0} = {}; 74 } 75 `), SyntaxError); 76 77 78 // Destructuring binding patterns with const. 79 (function() { 80 const {a: yield} = {a: "yield-with-name"}; 81 assertEq(yield, "yield-with-name"); 82 })(); 83 84 (function() { 85 const {yield} = {yield: "yield-with-shorthand"}; 86 assertEq(yield, "yield-with-shorthand"); 87 })(); 88 89 (function() { 90 const {yield = 0} = {yield: "yield-with-coverinitname"}; 91 assertEq(yield, "yield-with-coverinitname"); 92 })(); 93 94 assertThrowsInstanceOf(() => eval(` 95 "use strict"; 96 function f() { 97 const {a: yield} = {}; 98 } 99 `), SyntaxError); 100 101 assertThrowsInstanceOf(() => eval(` 102 "use strict"; 103 function f() { 104 const {yield} = {}; 105 } 106 `), SyntaxError); 107 108 assertThrowsInstanceOf(() => eval(` 109 "use strict"; 110 function f() { 111 const {yield = 0} = {}; 112 } 113 `), SyntaxError); 114 115 116 // Destructuring binding patterns in parameters. 117 (function({a: yield} = {a: "yield-with-name"}) { 118 assertEq(yield, "yield-with-name"); 119 })(); 120 121 (function({yield} = {yield: "yield-with-shorthand"}) { 122 assertEq(yield, "yield-with-shorthand"); 123 })(); 124 125 (function({yield = 0} = {yield: "yield-with-coverinitname"}) { 126 assertEq(yield, "yield-with-coverinitname"); 127 })(); 128 129 assertThrowsInstanceOf(() => eval(` 130 "use strict"; 131 function f({a: yield} = {}) { } 132 `), SyntaxError); 133 134 assertThrowsInstanceOf(() => eval(` 135 "use strict"; 136 function f({yield} = {}) { } 137 `), SyntaxError); 138 139 assertThrowsInstanceOf(() => eval(` 140 "use strict"; 141 function f({yield = 0} = {}) { } 142 `), SyntaxError); 143 144 145 // Destructuring assignment pattern. 146 (function() { 147 var a, yield; 148 149 ({a: yield} = {a: "yield-with-name"}); 150 assertEq(yield, "yield-with-name"); 151 152 ({yield} = {yield: "yield-with-shorthand"}); 153 assertEq(yield, "yield-with-shorthand"); 154 155 ({yield = 0} = {yield: "yield-with-coverinitname"}); 156 assertEq(yield, "yield-with-coverinitname"); 157 })(); 158 159 assertThrowsInstanceOf(() => eval(` 160 "use strict"; 161 function f() { 162 ({a: yield} = {}); 163 } 164 `), SyntaxError); 165 166 assertThrowsInstanceOf(() => eval(` 167 "use strict"; 168 function f() { 169 ({yield} = {}); 170 } 171 `), SyntaxError); 172 173 assertThrowsInstanceOf(() => eval(` 174 "use strict"; 175 function f() { 176 ({yield = 0} = {}); 177 } 178 `), SyntaxError); 179 180 181 if (typeof reportCompare === "function") 182 reportCompare(0, 0, "ok");