|
| 1 | +//------------------------------------------------------------------------------------------------------- |
| 2 | +// Copyright (C) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
| 4 | +//------------------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); |
| 7 | + |
| 8 | + |
| 9 | +function testGen(func, values, count) |
| 10 | +{ |
| 11 | + const gen = func(); |
| 12 | + let counter = 0; |
| 13 | + for (const value of gen) |
| 14 | + { |
| 15 | + assert.isTrue(value == values[counter]); |
| 16 | + ++counter; |
| 17 | + } |
| 18 | + assert.areEqual(counter, count); |
| 19 | +} |
| 20 | + |
| 21 | + |
| 22 | +const tests = [ |
| 23 | + { |
| 24 | + name : "For - in with Arrow function sloppy", |
| 25 | + body : function () { |
| 26 | + const arr = [0,1,2,5]; |
| 27 | + for (var a = () => { return "a"} in {}); |
| 28 | + assert.areEqual(a(), "a"); |
| 29 | + for (var a = () => { return "a"} in arr); |
| 30 | + assert.isTrue(a == "3"); |
| 31 | + } |
| 32 | + }, |
| 33 | + { |
| 34 | + name : "For - in with Arrow function strict", |
| 35 | + body : function () { |
| 36 | + "use strict"; |
| 37 | + assert.throws(()=>{eval("for (var a = () => { return 'a'} in {});")}, SyntaxError); |
| 38 | + } |
| 39 | + }, |
| 40 | + { |
| 41 | + name : "For - in with yield - sloppy", |
| 42 | + body : function () { |
| 43 | + function* gen1() |
| 44 | + { |
| 45 | + for (var a = yield 'a' in {b: 1}) { |
| 46 | + assert.isTrue(a == "b"); |
| 47 | + } |
| 48 | + } |
| 49 | + testGen(gen1, ["a"], 1); |
| 50 | + function* gen2() |
| 51 | + { |
| 52 | + for (var a = yield in {c: 1}) { |
| 53 | + assert.isTrue(a == "c"); |
| 54 | + } |
| 55 | + } |
| 56 | + testGen(gen2, [undefined], 1); |
| 57 | + function* gen3() |
| 58 | + { |
| 59 | + for (var a = yield 'd' in {} in {a: 1}) { |
| 60 | + assert.isTrue(false, "shouldn't reach here"); |
| 61 | + } |
| 62 | + } |
| 63 | + testGen(gen3, ['d'], 1); |
| 64 | + } |
| 65 | + }, |
| 66 | + { |
| 67 | + name : "For - in with yield - strict", |
| 68 | + body : function () { |
| 69 | + "use strict"; |
| 70 | + assert.throws(()=>{eval(`function* gen1() |
| 71 | + { |
| 72 | + for (var a = yield 'a' in {b: 1}) { |
| 73 | + assert.isTrue(a == "b"); |
| 74 | + } |
| 75 | + }`)}, SyntaxError); |
| 76 | + } |
| 77 | + } |
| 78 | +]; |
| 79 | + |
| 80 | +testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
0 commit comments