Reviewers: Mads Ager,
Description:
Fix error in for-in on x64 platform using full compiler with keyed store IC.
BUG=v8:748 . issue=748 http://code.google.com/p/v8/issues/detail?id=748
Please review this at http://codereview.chromium.org/2810027/show
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/x64/full-codegen-x64.cc
M test/mjsunit/for-in.js
Index: src/x64/full-codegen-x64.cc
===================================================================
--- src/x64/full-codegen-x64.cc (revision 4940)
+++ src/x64/full-codegen-x64.cc (working copy)
@@ -1518,12 +1518,13 @@
case KEYED_PROPERTY: {
__ push(rax); // Preserve value.
VisitForValue(prop->obj(), kStack);
- VisitForValue(prop->key(), kStack);
- __ movq(rax, Operand(rsp, 2 * kPointerSize));
+ VisitForValue(prop->key(), kAccumulator);
+ __ movq(rcx, rax);
+ __ pop(rdx);
+ __ pop(rax);
Handle<Code>
ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize));
__ call(ic, RelocInfo::CODE_TARGET);
__ nop(); // Signal no inlined code.
- __ Drop(3); // Receiver, key, and extra copy of value.
break;
}
}
Index: test/mjsunit/for-in.js
===================================================================
--- test/mjsunit/for-in.js (revision 4940)
+++ test/mjsunit/for-in.js (working copy)
@@ -84,3 +84,38 @@
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]");
+}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev