-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#430: fix reversions with legacy generators, restore/new tests
- Loading branch information
Showing
16 changed files
with
190 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function f1(g=((function () { return 4; }) for (x of [1]))) { | ||
return g.next()(); | ||
} | ||
assertEq(f1(), 4); |
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,7 @@ | ||
// No 'arguments' binding in genexprs at toplevel. | ||
|
||
load(libdir + "asserts.js"); | ||
|
||
delete this.arguments; // it is defined in the shell | ||
var iter = (arguments for (x of [1])); | ||
assertThrowsInstanceOf(() => iter.next(), ReferenceError); |
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,4 @@ | ||
// 'arguments' is lexically scoped in genexprs at toplevel. | ||
|
||
var arguments = 8; | ||
assertEq((arguments for (x of [1])).next(), 8); |
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,6 @@ | ||
// 'arguments' is lexically scoped in genexpr in toplevel let-block. | ||
|
||
{ | ||
let arguments = []; | ||
assertEq((arguments for (p in {a: 1})).next(), arguments); | ||
} |
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,7 @@ | ||
// 'arguments' is lexically scoped in genexpr in function. | ||
|
||
function f() { | ||
assertEq((arguments for (x of [0])).next(), | ||
(arguments for (y of [1])).next()); | ||
} | ||
f(); |
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,8 @@ | ||
// 'arguments' binding can be closed over and outlives the function activation. | ||
|
||
function f() { | ||
return (arguments for (x of [1])); | ||
} | ||
|
||
var args = f("ponies").next(); | ||
assertEq(args[0], "ponies"); |
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,12 @@ | ||
// 'arguments' works in nested genexprs. | ||
|
||
function f() { | ||
return ((((((arguments for (u of [0])) | ||
for (v of [1])) | ||
for (w of [2])) | ||
for (x of [3])) | ||
for (y of [4])) | ||
for (z of [5])); | ||
} | ||
var args = f("ponies").next().next().next().next().next().next(); | ||
assertEq(args[0], "ponies"); |
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,10 @@ | ||
// 'this' in generator-expression in strict-mode toplevel | ||
// is the same as global 'this'. | ||
|
||
"use strict"; | ||
|
||
var it1 = (this for (x of [0])); | ||
assertEq(it1.next(), this); | ||
|
||
var it2 = (this for (x of (this for (y of (this for (z of [0])))))); | ||
assertEq(it2.next(), this); |
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,11 @@ | ||
// 'this' in escaping generator-expression in a method | ||
// is the same as 'this' in the enclosing method. | ||
|
||
var obj = { | ||
f: function () { | ||
assertEq(this, obj); | ||
return (this for (x of [0])); | ||
} | ||
}; | ||
|
||
assertEq(obj.f().next(), obj); |
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,11 @@ | ||
// 'this' in escaping generator-expression in a method | ||
// is the same as 'this' in the enclosing method | ||
// even if the method does not otherwise use 'this'. | ||
|
||
var obj = { | ||
f: function () { | ||
return (this for (x of [0])); | ||
} | ||
}; | ||
|
||
assertEq(obj.f().next(), obj); |
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,13 @@ | ||
// 'this' in a generator-expression non-strict function produces the expected | ||
// object. | ||
|
||
Number.prototype.iters = function () { | ||
return [(this for (x of [0])), | ||
(this for (y of [0]))]; | ||
}; | ||
|
||
var [a, b] = (3).iters(); | ||
var three = a.next(); | ||
assertEq(Object.prototype.toString.call(three), '[object Number]'); | ||
assertEq(+three, 3); | ||
assertEq(b.next(), three); |
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,14 @@ | ||
// array comprehensions | ||
var data = "abcdefg"; | ||
var hexString = [ | ||
data.charCodeAt(i) for (i in data) if (data.charCodeAt(i) < 100) | ||
].join(","); | ||
assertEq(hexString, "97,98,99"); | ||
|
||
// generator comprehensions | ||
var it = [1, 2, 3, 5, 8, 10, 13]; | ||
var w = (i*2 for (i of it) if (i & 1)); | ||
assertEq(w.next(), 2); | ||
assertEq(w.next(), 6); | ||
assertEq(w.next(), 10); | ||
assertEq(w.next(), 26); |
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,30 @@ | ||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
var BUGNUMBER = 380237; | ||
var summary = 'Decompilation of generator expressions'; | ||
var actual = ''; | ||
var expect = ''; | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
test(); | ||
//----------------------------------------------------------------------------- | ||
|
||
function test() | ||
{ | ||
enterFunc ('test'); | ||
printBugNumber(BUGNUMBER); | ||
printStatus (summary); | ||
|
||
var f = function() { g = (d for (d in [0])); g.next(); }; | ||
expect = 'function() { g = (d for (d in [0])); g.next(); }'; | ||
actual = f + ''; | ||
compareSource(expect, actual, summary); | ||
|
||
exitFunc ('test'); | ||
} |