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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Generators have an additional object interposed in the chain between | 71 // Generators have an additional object interposed in the chain between |
72 // themselves and Function.prototype. | 72 // themselves and Function.prototype. |
73 function TestGeneratorFunctionPrototype() { | 73 function TestGeneratorFunctionPrototype() { |
74 // Sanity check. | 74 // Sanity check. |
75 assertSame(Object.getPrototypeOf(f), Function.prototype); | 75 assertSame(Object.getPrototypeOf(f), Function.prototype); |
76 assertFalse(GeneratorFunctionPrototype === Function.prototype); | 76 assertFalse(GeneratorFunctionPrototype === Function.prototype); |
77 assertSame(Function.prototype, | 77 assertSame(Function.prototype, |
78 Object.getPrototypeOf(GeneratorFunctionPrototype)); | 78 Object.getPrototypeOf(GeneratorFunctionPrototype)); |
79 assertSame(GeneratorFunctionPrototype, | 79 assertSame(GeneratorFunctionPrototype, |
80 Object.getPrototypeOf(function* () {})); | 80 Object.getPrototypeOf(function* () {})); |
| 81 assertSame("object", typeof GeneratorFunctionPrototype); |
| 82 |
| 83 var constructor_desc = Object.getOwnPropertyDescriptor( |
| 84 GeneratorFunctionPrototype, "constructor"); |
| 85 assertTrue(constructor_desc !== undefined); |
| 86 assertSame(GeneratorFunction, constructor_desc.value); |
| 87 assertFalse(constructor_desc.writable); |
| 88 assertFalse(constructor_desc.enumerable); |
| 89 assertTrue(constructor_desc.configurable); |
| 90 |
| 91 var prototype_desc = Object.getOwnPropertyDescriptor( |
| 92 GeneratorFunctionPrototype, "prototype"); |
| 93 assertTrue(prototype_desc !== undefined); |
| 94 assertSame(GeneratorObjectPrototype, prototype_desc.value); |
| 95 assertFalse(prototype_desc.writable); |
| 96 assertFalse(prototype_desc.enumerable); |
| 97 assertTrue(prototype_desc.configurable); |
81 } | 98 } |
82 TestGeneratorFunctionPrototype(); | 99 TestGeneratorFunctionPrototype(); |
83 | 100 |
84 | 101 |
85 // Functions that we associate with generator objects are actually defined by | 102 // Functions that we associate with generator objects are actually defined by |
86 // a common prototype. | 103 // a common prototype. |
87 function TestGeneratorObjectPrototype() { | 104 function TestGeneratorObjectPrototype() { |
88 assertSame(Object.prototype, | 105 assertSame(Object.prototype, |
89 Object.getPrototypeOf(GeneratorObjectPrototype)); | 106 Object.getPrototypeOf(GeneratorObjectPrototype)); |
90 assertSame(GeneratorObjectPrototype, | 107 assertSame(GeneratorObjectPrototype, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 146 |
130 assertTrue((new GeneratorFunction()) instanceof GeneratorFunction); | 147 assertTrue((new GeneratorFunction()) instanceof GeneratorFunction); |
131 assertTrue(GeneratorFunction() instanceof GeneratorFunction); | 148 assertTrue(GeneratorFunction() instanceof GeneratorFunction); |
132 } | 149 } |
133 TestGeneratorFunction(); | 150 TestGeneratorFunction(); |
134 | 151 |
135 | 152 |
136 function TestPerGeneratorPrototype() { | 153 function TestPerGeneratorPrototype() { |
137 assertTrue((function*(){}).prototype !== (function*(){}).prototype); | 154 assertTrue((function*(){}).prototype !== (function*(){}).prototype); |
138 assertTrue((function*(){}).prototype !== g.prototype); | 155 assertTrue((function*(){}).prototype !== g.prototype); |
139 assertTrue(g.prototype instanceof GeneratorFunctionPrototype); | |
140 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype)); | 156 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype)); |
141 assertTrue(!(g.prototype instanceof Function)); | 157 assertTrue(!(g.prototype instanceof Function)); |
142 assertSame(typeof (g.prototype), "object"); | 158 assertSame(typeof (g.prototype), "object"); |
143 | 159 |
144 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype)); | 160 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype)); |
145 } | 161 } |
146 TestPerGeneratorPrototype(); | 162 TestPerGeneratorPrototype(); |
OLD | NEW |