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

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

Issue 3037008: Fix issue 785. For-in now works on strings: for (var i in "asdf") now works... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/handles.cc ('k') | no next file » | 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 for (var j = 0; j < 10; ++j) { 57 for (var j = 0; j < 10; ++j) {
58 assertTrue(for_in_undefined()); 58 assertTrue(for_in_undefined());
59 gc(); 59 gc();
60 } 60 }
61 61
62 assertEquals(10, i); 62 assertEquals(10, i);
63 assertEquals(10, j); 63 assertEquals(10, j);
64 64
65
66 function Accumulate(x) {
67 var accumulator = "";
68 for (var i in x) {
69 accumulator += i;
70 }
71 return accumulator;
72 }
73
74 for (var i = 0; i < 3; ++i) {
75 var elements = Accumulate("abcd");
76 // We do not assume that for-in enumerates elements in order.
77 assertTrue(-1 != elements.indexOf("0"));
78 assertTrue(-1 != elements.indexOf("1"));
79 assertTrue(-1 != elements.indexOf("2"));
80 assertTrue(-1 != elements.indexOf("3"));
81 assertEquals(4, elements.length);
82 }
83
84 function for_in_string_prototype() {
85
86 var x = new String("abc");
87 x.foo = 19;
88 function B() {
89 this.bar = 5;
90 this[7] = 4;
91 }
92 B.prototype = x;
93
94 var y = new B();
95 y.gub = 13;
96
97 var elements = Accumulate(y);
98 var elements1 = Accumulate(y);
99 // If for-in returns elements in a different order on multiple calls, this
100 // assert will fail. If that happens, consider if that behavior is OK.
101 assertEquals(elements, elements1, "For-in elements not the same both times.");
102 // We do not assume that for-in enumerates elements in order.
103 assertTrue(-1 != elements.indexOf("0"));
104 assertTrue(-1 != elements.indexOf("1"));
105 assertTrue(-1 != elements.indexOf("2"));
106 assertTrue(-1 != elements.indexOf("7"));
107 assertTrue(-1 != elements.indexOf("foo"));
108 assertTrue(-1 != elements.indexOf("bar"));
109 assertTrue(-1 != elements.indexOf("gub"));
110 assertEquals(13, elements.length);
111
112 elements = Accumulate(x);
113 assertTrue(-1 != elements.indexOf("0"));
114 assertTrue(-1 != elements.indexOf("1"));
115 assertTrue(-1 != elements.indexOf("2"));
116 assertTrue(-1 != elements.indexOf("foo"));
117 assertEquals(6, elements.length);
118 }
119
120 for_in_string_prototype();
121 for_in_string_prototype();
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698