| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
//----------------------------------------------------------------------------- |
| 7 |
var BUGNUMBER = 'none'; |
| 8 |
var summary = 'Test destructuring assignments for differing scopes'; |
| 9 |
var actual = ''; |
| 10 |
var expect = ''; |
| 11 |
|
| 12 |
printBugNumber(BUGNUMBER); |
| 13 |
printStatus (summary); |
| 14 |
|
| 15 |
function f() { |
| 16 |
var x = 3; |
| 17 |
if (x > 0) { |
| 18 |
let {a:x} = {a:7}; |
| 19 |
if (x != 7) |
| 20 |
throw "fail"; |
| 21 |
} |
| 22 |
if (x != 3) |
| 23 |
throw "fail"; |
| 24 |
} |
| 25 |
|
| 26 |
function g() { |
| 27 |
// Before JS1.7's destructuring for…in was fixed to match JS1.8's, |
| 28 |
// the expected values were a == "x" and b == 7. |
| 29 |
for (var [a,b] in {x:7}) { |
| 30 |
if (a !== "x" || typeof b !== "undefined") |
| 31 |
throw "fail"; |
| 32 |
} |
| 33 |
|
| 34 |
{ |
| 35 |
// Before JS1.7's destructuring for…in was fixed to match JS1.8's, |
| 36 |
// the expected values were a == "y" and b == 8. |
| 37 |
for (let [a,b] in {y:8}) { |
| 38 |
if (a !== "y" || typeof b !== "undefined") |
| 39 |
throw "fail"; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
if (a !== "x" || typeof b !== "undefined") |
| 44 |
throw "fail"; |
| 45 |
} |
| 46 |
|
| 47 |
f(); |
| 48 |
g(); |
| 49 |
|
| 50 |
if (typeof a != "undefined" || typeof b != "undefined" || typeof x != "undefined") |
| 51 |
throw "fail"; |
| 52 |
|
| 53 |
function h() { |
| 54 |
// Before JS1.7's destructuring for…in was fixed to match JS1.8's, |
| 55 |
// the expected values were a == "x" and b == 9. |
| 56 |
for ([a,b] in {z:9}) { |
| 57 |
if (a !== "z" || typeof b !== "undefined") |
| 58 |
throw "fail"; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
h(); |
| 63 |
|
| 64 |
if (a !== "z" || typeof b !== "undefined") |
| 65 |
throw "fail"; |
| 66 |
|
| 67 |
reportCompare(expect, actual, summary); |