Chromium Code Reviews| Index: test/mjsunit/harmony/array-from.js |
| diff --git a/test/mjsunit/harmony/array-from.js b/test/mjsunit/harmony/array-from.js |
| index e8dde163fc227bb21bdeaab6d14ff944cec65b96..26bd473f7e210f658936aab856876b87cc1bf94e 100644 |
| --- a/test/mjsunit/harmony/array-from.js |
| +++ b/test/mjsunit/harmony/array-from.js |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -// Flags: --harmony-arrays --harmony-generators |
| +// Flags: --harmony-arrays |
| (function() { |
| assertEquals(1, Array.from.length); |
| @@ -91,21 +91,52 @@ function testArrayFrom(thisArg, constructor) { |
| return x.toUpperCase(); |
| }), ['T', 'E', 'S', 'T'], constructor); |
| - this.thisArg = thisArg; |
| - assertThrows('Array.from.call(thisArg, null)', TypeError); |
| - assertThrows('Array.from.call(thisArg, undefined)', TypeError); |
| - assertThrows('Array.from.call(thisArg, [], null)', TypeError); |
| - assertThrows('Array.from.call(thisArg, [], "noncallable")', TypeError); |
| + assertThrows(function() { Array.from.call(thisArg, null); }, TypeError); |
| + assertThrows(function() { Array.from.call(thisArg, undefined); }, TypeError); |
| + assertThrows(function() { Array.from.call(thisArg, [], null); }, TypeError); |
| + assertThrows(function() { Array.from.call(thisArg, [], "noncallable"); }, |
| + TypeError); |
| - this.nullIterator = {}; |
| + var nullIterator = {}; |
| nullIterator[Symbol.iterator] = null; |
| - assertThrows('Array.from.call(thisArg, nullIterator)', TypeError); |
| + assertArrayLikeEquals(Array.from.call(thisArg, nullIterator), [], |
| + constructor); |
| - this.nonObjIterator = {}; |
| + var nonObjIterator = {}; |
| nonObjIterator[Symbol.iterator] = function() { return "nonObject"; }; |
| - assertThrows('Array.from.call(thisArg, nonObjIterator)', TypeError); |
| - |
| - assertThrows('Array.from.call(thisArg, [], null)', TypeError); |
| + assertThrows(function() { Array.from.call(thisArg, nonObjIterator); }, |
| + TypeError); |
| + |
| + assertThrows(function() { Array.from.call(thisArg, [], null); }, TypeError); |
| + |
| + // Ensure iterator is only accessed once, and only invoked once |
| + var called = false; |
| + var arr = [1,2,3]; |
|
arv (Not doing code reviews)
2015/01/22 21:14:58
ws after ,
|
| + var obj = {}; |
| + |
| + // Test order --- only get iterator method once |
| + function testIterator() { |
| + if (!called) { |
|
arv (Not doing code reviews)
2015/01/22 21:14:58
Maybe use assertFalse instead?
|
| + called = true; |
| + assertEquals(obj, this); |
| + return arr[Symbol.iterator](); |
| + } |
| + assertUnreachable("@@iterator should be called only once"); |
| + } |
| + var getCalled = false; |
| + Object.defineProperty(obj, Symbol.iterator, { |
| + get: function() { |
| + if (!getCalled) { |
| + getCalled = true; |
| + return testIterator; |
| + } |
| + assertUnreachable("@@iterator should be accessed only once"); |
| + }, |
| + set: function() { |
| + assertUnreachable("@@iterator should not be set"); |
| + } |
| + }); |
| + assertArrayLikeEquals(Array.from.call(thisArg, obj), [1,2,3], constructor); |
|
arv (Not doing code reviews)
2015/01/22 21:14:58
ws
|
| } |
| function Other() {} |