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

Side by Side Diff: test/mjsunit/for-in.js

Issue 8888006: Make more JS files beter match the coding standard. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/extra-commas.js ('k') | test/mjsunit/for-in-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 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
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 var a = []; 51 var a = [];
52 for (var i = 0x0020; i < 0x01ff; i+=2) { 52 for (var i = 0x0020; i < 0x01ff; i+=2) {
53 var s = 'char:' + String.fromCharCode(i); 53 var s = 'char:' + String.fromCharCode(i);
54 a.push(s); 54 a.push(s);
55 o[s] = i; 55 o[s] = i;
56 } 56 }
57 assertArrayEquals(a, props(o), "charcodes"); 57 assertArrayEquals(a, props(o), "charcodes");
58 58
59 var a = []; 59 var a = [];
60 assertEquals(0, props(a).length, "proplen0"); 60 assertEquals(0, props(a).length, "proplen0");
61 a[Math.pow(2,30)-1] = 0; 61 a[Math.pow(2, 30) - 1] = 0;
62 assertEquals(1, props(a).length, "proplen1"); 62 assertEquals(1, props(a).length, "proplen1");
63 a[Math.pow(2,31)-1] = 0; 63 a[Math.pow(2, 31) - 1] = 0;
64 assertEquals(2, props(a).length, "proplen2"); 64 assertEquals(2, props(a).length, "proplen2");
65 a[1] = 0; 65 a[1] = 0;
66 assertEquals(3, props(a).length, "proplen3"); 66 assertEquals(3, props(a).length, "proplen3");
67 67
68 for (var hest = 'hest' in {}) { } 68 for (var hest = 'hest' in {}) { }
69 assertEquals('hest', hest, "empty-no-override"); 69 assertEquals('hest', hest, "empty-no-override");
70 70
71 var result = ''; 71 var result = '';
72 for (var p in {a : [0], b : 1}) { result += p; } 72 for (var p in {a : [0], b : 1}) { result += p; }
73 assertEquals('ab', result, "ab"); 73 assertEquals('ab', result, "ab");
74 74
75 var result = ''; 75 var result = '';
76 for (var p in {a : {v:1}, b : 1}) { result += p; } 76 for (var p in {a : {v:1}, b : 1}) { result += p; }
77 assertEquals('ab', result, "ab-nodeep"); 77 assertEquals('ab', result, "ab-nodeep");
78 78
79 var result = ''; 79 var result = '';
80 for (var p in { get a() {}, b : 1}) { result += p; } 80 for (var p in { get a() {}, b : 1}) { result += p; }
81 assertEquals('ab', result, "abget"); 81 assertEquals('ab', result, "abget");
82 82
83 var result = ''; 83 var result = '';
84 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } 84 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; }
85 assertEquals('ab', result, "abgetset"); 85 assertEquals('ab', result, "abgetset");
86 86
87 87
88 // Test that for-in in the global scope works with a keyed property as "each". 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. 89 // Test outside a loop and in a loop for multiple iterations.
90 a = [1,2,3,4]; 90 a = [1, 2, 3, 4];
91 x = {foo:5, bar:6, zip:7, glep:9, 10:11}; 91 x = {foo: 5, bar: 6, zip: 7, glep: 9, 10: 11};
92 delete x.bar; 92 delete x.bar;
93 y = {} 93 y = {};
94 94
95 for (a[2] in x) { 95 for (a[2] in x) {
96 y[a[2]] = x[a[2]]; 96 y[a[2]] = x[a[2]];
97 } 97 }
98 98
99 assertEquals(5, y.foo, "y.foo"); 99 assertEquals(5, y.foo, "y.foo");
100 assertEquals("undefined", typeof y.bar, "y.bar"); 100 assertEquals("undefined", typeof y.bar, "y.bar");
101 assertEquals(7, y.zip, "y.zip"); 101 assertEquals(7, y.zip, "y.zip");
102 assertEquals(9, y.glep, "y.glep"); 102 assertEquals(9, y.glep, "y.glep");
103 assertEquals(11, y[10], "y[10]"); 103 assertEquals(11, y[10], "y[10]");
104 assertEquals("undefined", typeof y[2], "y[2]"); 104 assertEquals("undefined", typeof y[2], "y[2]");
105 assertEquals("undefined", typeof y[0], "y[0]"); 105 assertEquals("undefined", typeof y[0], "y[0]");
106 106
107 for (i=0 ; i < 3; ++i) { 107 for (i=0 ; i < 3; ++i) {
108 y = {} 108 y = {};
109 109
110 for (a[2] in x) { 110 for (a[2] in x) {
111 y[a[2]] = x[a[2]]; 111 y[a[2]] = x[a[2]];
112 } 112 }
113 113
114 assertEquals(5, y.foo, "y.foo"); 114 assertEquals(5, y.foo, "y.foo");
115 assertEquals("undefined", typeof y.bar, "y.bar"); 115 assertEquals("undefined", typeof y.bar, "y.bar");
116 assertEquals(7, y.zip, "y.zip"); 116 assertEquals(7, y.zip, "y.zip");
117 assertEquals(9, y.glep, "y.glep"); 117 assertEquals(9, y.glep, "y.glep");
118 assertEquals(11, y[10], "y[10]"); 118 assertEquals(11, y[10], "y[10]");
119 assertEquals("undefined", typeof y[2], "y[2]"); 119 assertEquals("undefined", typeof y[2], "y[2]");
120 assertEquals("undefined", typeof y[0], "y[0]"); 120 assertEquals("undefined", typeof y[0], "y[0]");
121 } 121 }
OLDNEW
« no previous file with comments | « test/mjsunit/extra-commas.js ('k') | test/mjsunit/for-in-delete.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698