Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2196)

Side by Side Diff: test/mjsunit/harmony/reflect-enumerate.js

Issue 1397443013: [es6] Implement Reflect.enumerate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/reflect.js ('k') | test/mjsunit/harmony/reflect-enumerate-delete.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008-2015 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // This is adapted from mjsunit/for-in.js.
29
30 // Flags: --harmony-reflect
31
32
28 function props(x) { 33 function props(x) {
29 var array = []; 34 var array = [];
30 for (var p in x) array.push(p); 35 for (var p of Reflect.enumerate(x)) array.push(p);
31 return array.sort(); 36 return array.sort();
32 } 37 }
33 38
34 assertEquals(0, props({}).length, "olen0"); 39 assertEquals(0, props({}).length, "olen0");
35 assertEquals(1, props({x:1}).length, "olen1"); 40 assertEquals(1, props({x:1}).length, "olen1");
36 assertEquals(2, props({x:1, y:2}).length, "olen2"); 41 assertEquals(2, props({x:1, y:2}).length, "olen2");
37 42
38 assertArrayEquals(["x"], props({x:1}), "x"); 43 assertArrayEquals(["x"], props({x:1}), "x");
39 assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy"); 44 assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy");
40 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom"); 45 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom");
(...skipping 17 matching lines...) Expand all
58 63
59 var a = []; 64 var a = [];
60 assertEquals(0, props(a).length, "proplen0"); 65 assertEquals(0, props(a).length, "proplen0");
61 a[Math.pow(2,30)-1] = 0; 66 a[Math.pow(2,30)-1] = 0;
62 assertEquals(1, props(a).length, "proplen1"); 67 assertEquals(1, props(a).length, "proplen1");
63 a[Math.pow(2,31)-1] = 0; 68 a[Math.pow(2,31)-1] = 0;
64 assertEquals(2, props(a).length, "proplen2"); 69 assertEquals(2, props(a).length, "proplen2");
65 a[1] = 0; 70 a[1] = 0;
66 assertEquals(3, props(a).length, "proplen3"); 71 assertEquals(3, props(a).length, "proplen3");
67 72
68 for (var hest = 'hest' in {}) { }
69 assertEquals('hest', hest, "empty-no-override");
70
71 var result = ''; 73 var result = '';
72 for (var p in {a : [0], b : 1}) { result += p; } 74 for (var p of Reflect.enumerate({a : [0], b : 1})) { result += p; }
73 assertEquals('ab', result, "ab"); 75 assertEquals('ab', result, "ab");
74 76
75 var result = ''; 77 var result = '';
76 for (var p in {a : {v:1}, b : 1}) { result += p; } 78 for (var p of Reflect.enumerate({a : {v:1}, b : 1})) { result += p; }
77 assertEquals('ab', result, "ab-nodeep"); 79 assertEquals('ab', result, "ab-nodeep");
78 80
79 var result = ''; 81 var result = '';
80 for (var p in { get a() {}, b : 1}) { result += p; } 82 for (var p of Reflect.enumerate({ get a() {}, b : 1})) { result += p; }
81 assertEquals('ab', result, "abget"); 83 assertEquals('ab', result, "abget");
82 84
83 var result = ''; 85 var result = '';
84 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } 86 for (var p of Reflect.enumerate({ get a() {}, set a(x) {}, b : 1})) {
87 result += p;
88 }
85 assertEquals('ab', result, "abgetset"); 89 assertEquals('ab', result, "abgetset");
86 90
87
88 // Test that for-in in the global scope works with a keyed property as "each".
89 // Test outside a loop and in a loop for multiple iterations.
90 a = [1,2,3,4];
91 x = {foo:5, bar:6, zip:7, glep:9, 10:11};
92 delete x.bar;
93 y = {}
94
95 for (a[2] in x) {
96 y[a[2]] = x[a[2]];
97 }
98
99 assertEquals(5, y.foo, "y.foo");
100 assertEquals("undefined", typeof y.bar, "y.bar");
101 assertEquals(7, y.zip, "y.zip");
102 assertEquals(9, y.glep, "y.glep");
103 assertEquals(11, y[10], "y[10]");
104 assertEquals("undefined", typeof y[2], "y[2]");
105 assertEquals("undefined", typeof y[0], "y[0]");
106
107 for (i=0 ; i < 3; ++i) {
108 y = {}
109
110 for (a[2] in x) {
111 y[a[2]] = x[a[2]];
112 }
113
114 assertEquals(5, y.foo, "y.foo");
115 assertEquals("undefined", typeof y.bar, "y.bar");
116 assertEquals(7, y.zip, "y.zip");
117 assertEquals(9, y.glep, "y.glep");
118 assertEquals(11, y[10], "y[10]");
119 assertEquals("undefined", typeof y[2], "y[2]");
120 assertEquals("undefined", typeof y[0], "y[0]");
121 }
122
123 (function() { 91 (function() {
124 var large_key = 2147483650; 92 var large_key = 2147483650;
125 var o = {__proto__: {}}; 93 var o = {__proto__: {}};
126 o[large_key] = 1; 94 o[large_key] = 1;
127 o.__proto__[large_key] = 1; 95 o.__proto__[large_key] = 1;
128 var keys = []; 96 var keys = [];
129 for (var k in o) { 97 for (var k of Reflect.enumerate(o)) {
130 keys.push(k); 98 keys.push(k);
131 } 99 }
132 assertEquals(["2147483650"], keys); 100 assertEquals(["2147483650"], keys);
133 })(); 101 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/reflect.js ('k') | test/mjsunit/harmony/reflect-enumerate-delete.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698