summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_8_5/extensions/is-generator.js
blob: 6c77adda83e03f5e2dc83869f8638bc311ce3f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

/*
 * Bug 648355: Function.prototype.isGenerator
 */

reportCompare(true, "isGenerator" in Function.prototype, "Function.prototype.isGenerator present");

reportCompare(false, (function(){}).isGenerator(), "lambda is not a generator fn");
reportCompare(false, Function.prototype.toString.isGenerator(), "native is not a generator fn");
reportCompare(false, (function(){with(obj){}}).isGenerator(), "heavyweight is not a generator fn");
reportCompare(false, (function(){obj}).isGenerator(), "upvar function is not a generator fn");

reportCompare(true, (function(){yield}).isGenerator(), "simple generator fn");
reportCompare(true, (function(){with(obj){yield}}).isGenerator(), "heavyweight generator fn");
reportCompare(true, (function(){yield; obj}).isGenerator(), "upvar generator fn");

reportCompare(false, Function.prototype.isGenerator.call(42), "number is not a generator fn");
reportCompare(false, Function.prototype.isGenerator.call({}), "vanilla object is not a generator fn");
reportCompare(false, Function.prototype.isGenerator.call(new Date()), "date object is not a generator fn");