Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: test/mjsunit/es6/generators-runtime.js

Issue 1128233008: [es6] Iterators and generators should "extend" %IteratorPrototype% (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add missing files Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/string-iterator.js ('k') | test/mjsunit/es6/iterator-prototype.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 // Test aspects of the generator runtime. 28 // Test aspects of the generator runtime.
29 29
30 // See: 30 // See:
31 // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-ob jects 31 // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-ob jects
32 32
33 function f() { "use strict"; } 33 function f() { "use strict"; }
34 function* g() { yield 1; } 34 function* g() { yield 1; }
35 var GeneratorFunctionPrototype = Object.getPrototypeOf(g); 35 var GeneratorFunctionPrototype = Object.getPrototypeOf(g);
36 var GeneratorFunction = GeneratorFunctionPrototype.constructor; 36 var GeneratorFunction = GeneratorFunctionPrototype.constructor;
37 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; 37 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
38 var IteratorPrototype = Object.getPrototypeOf(GeneratorObjectPrototype);
38 39
39 // A generator function should have the same set of properties as any 40 // A generator function should have the same set of properties as any
40 // other function. 41 // other function.
41 function TestGeneratorFunctionInstance() { 42 function TestGeneratorFunctionInstance() {
42 var f_own_property_names = Object.getOwnPropertyNames(f); 43 var f_own_property_names = Object.getOwnPropertyNames(f);
43 var g_own_property_names = Object.getOwnPropertyNames(g); 44 var g_own_property_names = Object.getOwnPropertyNames(g);
44 45
45 f_own_property_names.sort(); 46 f_own_property_names.sort();
46 g_own_property_names.sort(); 47 g_own_property_names.sort();
47 48
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 assertFalse(prototype_desc.writable); 94 assertFalse(prototype_desc.writable);
94 assertFalse(prototype_desc.enumerable); 95 assertFalse(prototype_desc.enumerable);
95 assertTrue(prototype_desc.configurable); 96 assertTrue(prototype_desc.configurable);
96 } 97 }
97 TestGeneratorFunctionPrototype(); 98 TestGeneratorFunctionPrototype();
98 99
99 100
100 // Functions that we associate with generator objects are actually defined by 101 // Functions that we associate with generator objects are actually defined by
101 // a common prototype. 102 // a common prototype.
102 function TestGeneratorObjectPrototype() { 103 function TestGeneratorObjectPrototype() {
103 assertSame(Object.prototype, 104 assertSame(IteratorPrototype,
104 Object.getPrototypeOf(GeneratorObjectPrototype)); 105 Object.getPrototypeOf(GeneratorObjectPrototype));
105 assertSame(GeneratorObjectPrototype, 106 assertSame(GeneratorObjectPrototype,
106 Object.getPrototypeOf((function*(){yield 1}).prototype)); 107 Object.getPrototypeOf((function*(){yield 1}).prototype));
107 108
108 var expected_property_names = ["next", "throw", "constructor"]; 109 var expected_property_names = ["next", "throw", "constructor"];
109 var found_property_names = 110 var found_property_names =
110 Object.getOwnPropertyNames(GeneratorObjectPrototype); 111 Object.getOwnPropertyNames(GeneratorObjectPrototype);
111 112
112 expected_property_names.sort(); 113 expected_property_names.sort();
113 found_property_names.sort(); 114 found_property_names.sort();
(...skipping 13 matching lines...) Expand all
127 assertTrue(next_desc.writable); 128 assertTrue(next_desc.writable);
128 assertFalse(next_desc.enumerable); 129 assertFalse(next_desc.enumerable);
129 assertTrue(next_desc.configurable); 130 assertTrue(next_desc.configurable);
130 131
131 var throw_desc = Object.getOwnPropertyDescriptor(GeneratorObjectPrototype, 132 var throw_desc = Object.getOwnPropertyDescriptor(GeneratorObjectPrototype,
132 "throw"); 133 "throw");
133 assertTrue(throw_desc !== undefined); 134 assertTrue(throw_desc !== undefined);
134 assertTrue(throw_desc.writable); 135 assertTrue(throw_desc.writable);
135 assertFalse(throw_desc.enumerable); 136 assertFalse(throw_desc.enumerable);
136 assertTrue(throw_desc.configurable); 137 assertTrue(throw_desc.configurable);
137
138 var iterator_desc = Object.getOwnPropertyDescriptor(GeneratorObjectPrototype,
139 Symbol.iterator);
140 assertTrue(iterator_desc !== undefined);
141 assertFalse(iterator_desc.writable);
142 assertFalse(iterator_desc.enumerable);
143 assertFalse(iterator_desc.configurable);
144
145 // The generator object's "iterator" function is just the identity.
146 assertSame(iterator_desc.value.call(42), 42);
147 } 138 }
148 TestGeneratorObjectPrototype(); 139 TestGeneratorObjectPrototype();
149 140
150 141
151 // This tests the object that would be called "GeneratorFunction", if it were 142 // This tests the object that would be called "GeneratorFunction", if it were
152 // like "Function". 143 // like "Function".
153 function TestGeneratorFunction() { 144 function TestGeneratorFunction() {
154 assertSame(GeneratorFunctionPrototype, GeneratorFunction.prototype); 145 assertSame(GeneratorFunctionPrototype, GeneratorFunction.prototype);
155 assertTrue(g instanceof GeneratorFunction); 146 assertTrue(g instanceof GeneratorFunction);
156 147
(...skipping 15 matching lines...) Expand all
172 function TestPerGeneratorPrototype() { 163 function TestPerGeneratorPrototype() {
173 assertTrue((function*(){}).prototype !== (function*(){}).prototype); 164 assertTrue((function*(){}).prototype !== (function*(){}).prototype);
174 assertTrue((function*(){}).prototype !== g.prototype); 165 assertTrue((function*(){}).prototype !== g.prototype);
175 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype)); 166 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype));
176 assertTrue(!(g.prototype instanceof Function)); 167 assertTrue(!(g.prototype instanceof Function));
177 assertSame(typeof (g.prototype), "object"); 168 assertSame(typeof (g.prototype), "object");
178 169
179 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype)); 170 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype));
180 } 171 }
181 TestPerGeneratorPrototype(); 172 TestPerGeneratorPrototype();
OLDNEW
« no previous file with comments | « src/string-iterator.js ('k') | test/mjsunit/es6/iterator-prototype.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698