| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2015 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 // This is adapted from mjsunit/for-in.js. | |
| 29 | |
| 30 // Flags: --harmony-reflect | |
| 31 | |
| 32 | |
| 33 function props(x) { | |
| 34 var array = []; | |
| 35 for (var p of Reflect.enumerate(x)) array.push(p); | |
| 36 return array.sort(); | |
| 37 } | |
| 38 | |
| 39 assertEquals(0, props({}).length, "olen0"); | |
| 40 assertEquals(1, props({x:1}).length, "olen1"); | |
| 41 assertEquals(2, props({x:1, y:2}).length, "olen2"); | |
| 42 | |
| 43 assertArrayEquals(["x"], props({x:1}), "x"); | |
| 44 assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy"); | |
| 45 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom"); | |
| 46 | |
| 47 assertEquals(0, props([]).length, "alen0"); | |
| 48 assertEquals(1, props([1]).length, "alen1"); | |
| 49 assertEquals(2, props([1,2]).length, "alen2"); | |
| 50 | |
| 51 assertArrayEquals(["0"], props([1]), "0"); | |
| 52 assertArrayEquals(["0", "1"], props([1,2]), "01"); | |
| 53 assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012"); | |
| 54 | |
| 55 var o = {}; | |
| 56 var a = []; | |
| 57 for (var i = 0x0020; i < 0x01ff; i+=2) { | |
| 58 var s = 'char:' + String.fromCharCode(i); | |
| 59 a.push(s); | |
| 60 o[s] = i; | |
| 61 } | |
| 62 assertArrayEquals(a, props(o), "charcodes"); | |
| 63 | |
| 64 var a = []; | |
| 65 assertEquals(0, props(a).length, "proplen0"); | |
| 66 a[Math.pow(2,30)-1] = 0; | |
| 67 assertEquals(1, props(a).length, "proplen1"); | |
| 68 a[Math.pow(2,31)-1] = 0; | |
| 69 assertEquals(2, props(a).length, "proplen2"); | |
| 70 a[1] = 0; | |
| 71 assertEquals(3, props(a).length, "proplen3"); | |
| 72 | |
| 73 var result = ''; | |
| 74 for (var p of Reflect.enumerate({a : [0], b : 1})) { result += p; } | |
| 75 assertEquals('ab', result, "ab"); | |
| 76 | |
| 77 var result = ''; | |
| 78 for (var p of Reflect.enumerate({a : {v:1}, b : 1})) { result += p; } | |
| 79 assertEquals('ab', result, "ab-nodeep"); | |
| 80 | |
| 81 var result = ''; | |
| 82 for (var p of Reflect.enumerate({ get a() {}, b : 1})) { result += p; } | |
| 83 assertEquals('ab', result, "abget"); | |
| 84 | |
| 85 var result = ''; | |
| 86 for (var p of Reflect.enumerate({ get a() {}, set a(x) {}, b : 1})) { | |
| 87 result += p; | |
| 88 } | |
| 89 assertEquals('ab', result, "abgetset"); | |
| 90 | |
| 91 (function() { | |
| 92 var large_key = 2147483650; | |
| 93 var o = {__proto__: {}}; | |
| 94 o[large_key] = 1; | |
| 95 o.__proto__[large_key] = 1; | |
| 96 var keys = []; | |
| 97 for (var k of Reflect.enumerate(o)) { | |
| 98 keys.push(k); | |
| 99 } | |
| 100 assertEquals(["2147483650"], keys); | |
| 101 })(); | |
| OLD | NEW |