OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --harmony-generators | 28 // Flags: --harmony-generators |
29 | 29 |
30 // Test aspects of the generator runtime. | 30 // Test aspects of the generator runtime. |
31 | 31 |
32 // FIXME(wingo): Replace this reference with a more official link. | |
33 // See: | 32 // See: |
34 // http://wiki.ecmascript.org/lib/exe/fetch.php?cache=cache&media=harmony:es6_ge
nerator_object_model_3-29-13.png | 33 // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-ob
jects |
35 | 34 |
36 function f() { } | 35 function f() { } |
37 function* g() { yield 1; } | 36 function* g() { yield 1; } |
38 var GeneratorFunctionPrototype = Object.getPrototypeOf(g); | 37 var GeneratorFunctionPrototype = Object.getPrototypeOf(g); |
39 var GeneratorFunction = GeneratorFunctionPrototype.constructor; | 38 var GeneratorFunction = GeneratorFunctionPrototype.constructor; |
40 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 39 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
41 | 40 |
42 // A generator function should have the same set of properties as any | 41 // A generator function should have the same set of properties as any |
43 // other function. | 42 // other function. |
44 function TestGeneratorFunctionInstance() { | 43 function TestGeneratorFunctionInstance() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 Object.getPrototypeOf((function*(){yield 1}).prototype)); | 93 Object.getPrototypeOf((function*(){yield 1}).prototype)); |
95 | 94 |
96 var expected_property_names = ["next", "throw", "constructor"]; | 95 var expected_property_names = ["next", "throw", "constructor"]; |
97 var found_property_names = | 96 var found_property_names = |
98 Object.getOwnPropertyNames(GeneratorObjectPrototype); | 97 Object.getOwnPropertyNames(GeneratorObjectPrototype); |
99 | 98 |
100 expected_property_names.sort(); | 99 expected_property_names.sort(); |
101 found_property_names.sort(); | 100 found_property_names.sort(); |
102 | 101 |
103 assertArrayEquals(expected_property_names, found_property_names); | 102 assertArrayEquals(expected_property_names, found_property_names); |
| 103 |
| 104 iterator_desc = Object.getOwnPropertyDescriptor(GeneratorObjectPrototype, |
| 105 Symbol.iterator); |
| 106 assertTrue(iterator_desc !== undefined); |
| 107 assertFalse(iterator_desc.writable); |
| 108 assertFalse(iterator_desc.enumerable); |
| 109 assertFalse(iterator_desc.configurable); |
| 110 |
| 111 // The generator object's "iterator" function is just the identity. |
| 112 assertSame(iterator_desc.value.call(42), 42); |
104 } | 113 } |
105 TestGeneratorObjectPrototype(); | 114 TestGeneratorObjectPrototype(); |
106 | 115 |
107 | 116 |
108 // This tests the object that would be called "GeneratorFunction", if it were | 117 // This tests the object that would be called "GeneratorFunction", if it were |
109 // like "Function". | 118 // like "Function". |
110 function TestGeneratorFunction() { | 119 function TestGeneratorFunction() { |
111 assertSame(GeneratorFunctionPrototype, GeneratorFunction.prototype); | 120 assertSame(GeneratorFunctionPrototype, GeneratorFunction.prototype); |
112 assertTrue(g instanceof GeneratorFunction); | 121 assertTrue(g instanceof GeneratorFunction); |
113 | 122 |
(...skipping 16 matching lines...) Expand all Loading... |
130 assertTrue((function*(){}).prototype !== (function*(){}).prototype); | 139 assertTrue((function*(){}).prototype !== (function*(){}).prototype); |
131 assertTrue((function*(){}).prototype !== g.prototype); | 140 assertTrue((function*(){}).prototype !== g.prototype); |
132 assertTrue(g.prototype instanceof GeneratorFunctionPrototype); | 141 assertTrue(g.prototype instanceof GeneratorFunctionPrototype); |
133 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype)); | 142 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype)); |
134 assertTrue(!(g.prototype instanceof Function)); | 143 assertTrue(!(g.prototype instanceof Function)); |
135 assertSame(typeof (g.prototype), "object"); | 144 assertSame(typeof (g.prototype), "object"); |
136 | 145 |
137 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype)); | 146 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype)); |
138 } | 147 } |
139 TestPerGeneratorPrototype(); | 148 TestPerGeneratorPrototype(); |
OLD | NEW |