OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-arrays | 5 // Flags: --harmony-arrays |
6 (function() { | 6 (function() { |
7 | 7 |
8 assertEquals(1, Array.from.length); | 8 assertEquals(1, Array.from.length); |
9 | 9 |
10 function assertArrayLikeEquals(value, expected, type) { | 10 function assertArrayLikeEquals(value, expected, type) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 141 |
142 testArrayFrom(Array, Array); | 142 testArrayFrom(Array, Array); |
143 testArrayFrom(null, Array); | 143 testArrayFrom(null, Array); |
144 testArrayFrom({}, Array); | 144 testArrayFrom({}, Array); |
145 testArrayFrom(Object, Object); | 145 testArrayFrom(Object, Object); |
146 testArrayFrom(Other, Other); | 146 testArrayFrom(Other, Other); |
147 testArrayFrom(Math.cos, Array); | 147 testArrayFrom(Math.cos, Array); |
148 testArrayFrom(Math.cos.bind(Math), Array); | 148 testArrayFrom(Math.cos.bind(Math), Array); |
149 testArrayFrom(boundFn, boundFn); | 149 testArrayFrom(boundFn, boundFn); |
150 | 150 |
151 // Assert that [[DefineOwnProperty]] is used in ArrayFrom, meaning a | |
152 // setter isn't called, and a failed [[DefineOwnProperty]] will throw. | |
153 var setterCalled = 0; | |
154 function exotic() { | |
155 Object.defineProperty(this, '0', { | |
156 get: function() { return 2; }, | |
157 set: function() { setterCalled++; } | |
158 }); | |
159 } | |
160 // Check that exotic was defined right | |
arv (Not doing code reviews)
2015/06/11 16:41:30
I would remove this (line 160-165). We have plent
Dan Ehrenberg
2015/06/11 17:25:44
Done.
| |
161 var instance = new exotic(); | |
162 assertEquals(2, instance[0]); | |
163 instance[0] = 1; | |
164 assertEquals(2, instance[0]); | |
165 assertEquals(1, setterCalled); | |
166 // Accessor properties can't be overwritten with DefineOwnProperty | |
arv (Not doing code reviews)
2015/06/11 16:41:31
This comment is wrong. The reason why is because y
Dan Ehrenberg
2015/06/11 17:25:44
Done.
| |
167 assertThrows(function () { Array.from.call(exotic, [1]); }, TypeError); | |
168 assertEquals(1, setterCalled); | |
169 | |
170 // Check that array properties defined are writable, enumerable, configurable | |
171 function ordinary() { } | |
172 var x = Array.from.call(ordinary, [2]); | |
173 var xlength = Object.getOwnPropertyDescriptor(x, 'length'); | |
174 assertEquals(1, xlength.value); | |
175 assertEquals(true, xlength.writable); | |
176 assertEquals(true, xlength.enumerable); | |
177 assertEquals(true, xlength.configurable); | |
178 var x0 = Object.getOwnPropertyDescriptor(x, 0); | |
179 assertEquals(2, x0.value); | |
180 assertEquals(true, xlength.writable); | |
181 assertEquals(true, xlength.enumerable); | |
182 assertEquals(true, xlength.configurable); | |
183 | |
151 })(); | 184 })(); |
OLD | NEW |