Reviewers: arv, Igor Sheludko,
Message:
One missing case for assignment.
PTAL, no platform ports yet.
Description:
Support for super assignments in for..in.
[email protected],[email protected]
BUG=v8:3330
LOG=N
Please review this at https://codereview.chromium.org/639243003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+86, -7 lines):
M src/ia32/full-codegen-ia32.cc
M test/mjsunit/harmony/super.js
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index
62cf71203b457710f084100d54c263e8f16f5b9c..3c2fc1515996deb0a71e723ea627947f1b2ede9f
100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -2432,14 +2432,8 @@ void FullCodeGenerator::EmitAssignment(Expression*
expr) {
// Left-hand side can only be a property, a global or a (parameter or
local)
// slot.
- enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
- LhsKind assign_type = VARIABLE;
Property* prop = expr->AsProperty();
- if (prop != NULL) {
- assign_type = (prop->key()->IsPropertyName())
- ? NAMED_PROPERTY
- : KEYED_PROPERTY;
- }
+ LhsKind assign_type = GetAssignType(prop);
switch (assign_type) {
case VARIABLE: {
@@ -2458,6 +2452,42 @@ void FullCodeGenerator::EmitAssignment(Expression*
expr) {
CallStoreIC();
break;
}
+ case NAMED_SUPER_PROPERTY: {
+ __ push(eax);
+ VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
+ EmitLoadHomeObject(prop->obj()->AsSuperReference());
+ // stack: value, this; eax: home_object
+ Register scratch = ecx;
+ Register scratch2 = edx;
+ __ mov(scratch, result_register()); // home_object
+ __ mov(scratch2, MemOperand(esp, kPointerSize)); // value
+ __ mov(eax, MemOperand(esp, 0)); // this
+ __ mov(MemOperand(esp, kPointerSize), eax); // this
+ __ mov(MemOperand(esp, 0), scratch); // home_object
+ __ mov(eax, scratch2);
+ // stack: this, home_object. eax: value
+ EmitNamedSuperPropertyStore(prop);
+ break;
+ }
+ case KEYED_SUPER_PROPERTY: {
+ __ push(eax);
+ VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
+ EmitLoadHomeObject(prop->obj()->AsSuperReference());
+ __ push(result_register());
+ VisitForAccumulatorValue(prop->key());
+ Register scratch = ecx;
+ Register scratch2 = edx;
+ __ mov(scratch2, MemOperand(esp, 2 * kPointerSize)); // value
+ // stack: value, this, home_object; eax: key, edx: value
+ __ mov(scratch, MemOperand(esp, kPointerSize)); // this
+ __ mov(MemOperand(esp, 2 * kPointerSize), scratch);
+ __ mov(scratch, MemOperand(esp, 0)); // home_object
+ __ mov(MemOperand(esp, kPointerSize), scratch);
+ __ mov(MemOperand(esp, 0), eax);
+ __ mov(eax, scratch2);
+ EmitKeyedSuperPropertyStore(prop);
+ break;
+ }
case KEYED_PROPERTY: {
__ push(eax); // Preserve value.
VisitForStackValue(prop->obj());
Index: test/mjsunit/harmony/super.js
diff --git a/test/mjsunit/harmony/super.js b/test/mjsunit/harmony/super.js
index
d1cba533d56f9c3dbee417572808f12b66f8021a..8939b5089f698dca509efee3eaa53deb0678a0ae
100644
--- a/test/mjsunit/harmony/super.js
+++ b/test/mjsunit/harmony/super.js
@@ -660,6 +660,55 @@
}());
+(function TestSetterInForIn() {
+ var setCalled = 0;
+ var getCalled = 0;
+ function Base() {}
+ Base.prototype = {
+ constructor: Base,
+ get x() {
+ getCalled++;
+ return 1;
+ },
+ set x(v) {
+ setCalled++;
+ this.x_.push(v);
+ },
+ };
+
+ function Derived() {
+ this.x_ = [];
+ }
+ Derived.prototype = {
+ __proto__: Base.prototype,
+ constructor: Derived,
+ };
+
+ Derived.prototype.testIter = function() {
+ setCalled = 0;
+ getCalled = 0;
+ for (super.x in [1,2,3]) {}
+ assertEquals(0, getCalled);
+ assertEquals(3, setCalled);
+ assertEquals(["0","1","2"], this.x_);
+ }.toMethod(Derived.prototype);
+
+ new Derived().testIter();
+
+ var x = 'x';
+ Derived.prototype.testIterKeyed = function() {
+ setCalled = 0;
+ getCalled = 0;
+ for (super[x] in [1,2,3]) {}
+ assertEquals(0, getCalled);
+ assertEquals(3, setCalled);
+ assertEquals(["0","1","2"], this.x_);
+ }.toMethod(Derived.prototype);
+
+ new Derived().testIterKeyed();
+}());
+
+
(function TestKeyedSetterCreatingOwnProperties() {
var ownReadOnly = 'ownReadOnly';
var ownReadonlyAccessor = 'ownReadonlyAccessor';
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.