-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ons in for fixes #5203 Merge pull request #5219 from rhuanjl:fixYieldIn Attempt at fixing issue #5203 Based on #5216 Not 100% sure I've got this right but it passes the mentioned cases and doesn't regress anything I'm aware of. cc @zenparsing @akroshg
- Loading branch information
Showing
6 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
|
||
function testGen(func, values, count) | ||
{ | ||
const gen = func(); | ||
let counter = 0; | ||
for (const value of gen) | ||
{ | ||
assert.isTrue(value == values[counter]); | ||
++counter; | ||
} | ||
assert.areEqual(counter, count); | ||
} | ||
|
||
|
||
const tests = [ | ||
{ | ||
name : "For - in with Arrow function sloppy", | ||
body : function () { | ||
const arr = [0,1,2,5]; | ||
for (var a = () => { return "a"} in {}); | ||
assert.areEqual(a(), "a"); | ||
for (var a = () => { return "a"} in arr); | ||
assert.isTrue(a == "3"); | ||
} | ||
}, | ||
{ | ||
name : "For - in with Arrow function strict", | ||
body : function () { | ||
"use strict"; | ||
assert.throws(()=>{eval("for (var a = () => { return 'a'} in {});")}, SyntaxError); | ||
} | ||
}, | ||
{ | ||
name : "For - in with yield - sloppy", | ||
body : function () { | ||
function* gen1() | ||
{ | ||
for (var a = yield 'a' in {b: 1}) { | ||
assert.isTrue(a == "b"); | ||
} | ||
} | ||
testGen(gen1, ["a"], 1); | ||
function* gen2() | ||
{ | ||
for (var a = yield in {c: 1}) { | ||
assert.isTrue(a == "c"); | ||
} | ||
} | ||
testGen(gen2, [undefined], 1); | ||
function* gen3() | ||
{ | ||
for (var a = yield 'd' in {} in {a: 1}) { | ||
assert.isTrue(false, "shouldn't reach here"); | ||
} | ||
} | ||
testGen(gen3, ['d'], 1); | ||
} | ||
}, | ||
{ | ||
name : "For - in with yield - strict", | ||
body : function () { | ||
"use strict"; | ||
assert.throws(()=>{eval(`function* gen1() | ||
{ | ||
for (var a = yield 'a' in {b: 1}) { | ||
assert.isTrue(a == "b"); | ||
} | ||
}`)}, SyntaxError); | ||
} | ||
} | ||
]; | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,6 @@ catch (e) | |
{ | ||
print(e.message); | ||
} | ||
|
||
// Legal case, lambda in object inside for() | ||
for (var i = () => {} in {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters