OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Based on: https://hg.mozilla.org/mozilla-central/file/d0c3168c3c47/js/src/jit
-test/tests/collections/Array-of-generic-1.js |
| 6 |
| 7 // Flags: --harmony-arrays |
| 8 |
| 9 |
| 10 // Array.of can be transplanted to other classes. |
| 11 |
| 12 var hits = 0; |
| 13 function Bag() { |
| 14 hits++; |
| 15 } |
| 16 Bag.of = Array.of; |
| 17 |
| 18 hits = 0; |
| 19 var actual = Bag.of("zero", "one"); |
| 20 assertEquals(hits, 1); |
| 21 |
| 22 hits = 0; |
| 23 var expected = new Bag; |
| 24 expected[0] = "zero"; |
| 25 expected[1] = "one"; |
| 26 expected.length = 2; |
| 27 assertEquals(areSame(actual, expected), true); |
| 28 |
| 29 hits = 0; |
| 30 actual = Array.of.call(Bag, "zero", "one"); |
| 31 assertEquals(hits, 1); |
| 32 assertEquals(areSame(actual, expected), true); |
| 33 |
| 34 function areSame(object, array) { |
| 35 var result = object.length == array.length; |
| 36 for (var i = 0; i < object.length; i++) { |
| 37 result = result && object[i] == array[i]; |
| 38 } |
| 39 return result; |
| 40 } |
OLD | NEW |