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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/reflect-enumerate.js
diff --git a/test/mjsunit/for-in.js b/test/mjsunit/harmony/reflect-enumerate.js
similarity index 69%
copy from test/mjsunit/for-in.js
copy to test/mjsunit/harmony/reflect-enumerate.js
index 644c27a63277b25729734afb061a286f38e1e801..bbc364e7b97282c40915bff094b1a7d9e5fb472c 100644
--- a/test/mjsunit/for-in.js
+++ b/test/mjsunit/harmony/reflect-enumerate.js
@@ -1,4 +1,4 @@
-// Copyright 2008 the V8 project authors. All rights reserved.
+// Copyright 2008-2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -25,9 +25,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// This is adapted from mjsunit/for-in.js.
+
+// Flags: --harmony-reflect
+
+
function props(x) {
var array = [];
- for (var p in x) array.push(p);
+ for (var p of Reflect.enumerate(x)) array.push(p);
return array.sort();
}
@@ -65,60 +70,23 @@ assertEquals(2, props(a).length, "proplen2");
a[1] = 0;
assertEquals(3, props(a).length, "proplen3");
-for (var hest = 'hest' in {}) { }
-assertEquals('hest', hest, "empty-no-override");
-
var result = '';
-for (var p in {a : [0], b : 1}) { result += p; }
+for (var p of Reflect.enumerate({a : [0], b : 1})) { result += p; }
assertEquals('ab', result, "ab");
var result = '';
-for (var p in {a : {v:1}, b : 1}) { result += p; }
+for (var p of Reflect.enumerate({a : {v:1}, b : 1})) { result += p; }
assertEquals('ab', result, "ab-nodeep");
var result = '';
-for (var p in { get a() {}, b : 1}) { result += p; }
+for (var p of Reflect.enumerate({ get a() {}, b : 1})) { result += p; }
assertEquals('ab', result, "abget");
var result = '';
-for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; }
-assertEquals('ab', result, "abgetset");
-
-
-// Test that for-in in the global scope works with a keyed property as "each".
-// Test outside a loop and in a loop for multiple iterations.
-a = [1,2,3,4];
-x = {foo:5, bar:6, zip:7, glep:9, 10:11};
-delete x.bar;
-y = {}
-
-for (a[2] in x) {
- y[a[2]] = x[a[2]];
-}
-
-assertEquals(5, y.foo, "y.foo");
-assertEquals("undefined", typeof y.bar, "y.bar");
-assertEquals(7, y.zip, "y.zip");
-assertEquals(9, y.glep, "y.glep");
-assertEquals(11, y[10], "y[10]");
-assertEquals("undefined", typeof y[2], "y[2]");
-assertEquals("undefined", typeof y[0], "y[0]");
-
-for (i=0 ; i < 3; ++i) {
- y = {}
-
- for (a[2] in x) {
- y[a[2]] = x[a[2]];
- }
-
- assertEquals(5, y.foo, "y.foo");
- assertEquals("undefined", typeof y.bar, "y.bar");
- assertEquals(7, y.zip, "y.zip");
- assertEquals(9, y.glep, "y.glep");
- assertEquals(11, y[10], "y[10]");
- assertEquals("undefined", typeof y[2], "y[2]");
- assertEquals("undefined", typeof y[0], "y[0]");
+for (var p of Reflect.enumerate({ get a() {}, set a(x) {}, b : 1})) {
+ result += p;
}
+assertEquals('ab', result, "abgetset");
(function() {
var large_key = 2147483650;
@@ -126,7 +94,7 @@ for (i=0 ; i < 3; ++i) {
o[large_key] = 1;
o.__proto__[large_key] = 1;
var keys = [];
- for (var k in o) {
+ for (var k of Reflect.enumerate(o)) {
keys.push(k);
}
assertEquals(["2147483650"], keys);
« 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