Commit ec209c77 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Support count operations on super named properties.

R=ishell@chromium.org
BUG=v8:3330
LOG=N

Review URL: https://codereview.chromium.org/613673002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24290 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5b742b35
......@@ -2003,7 +2003,8 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
EmitNamedPropertyAssignment(expr);
break;
case NAMED_SUPER_PROPERTY:
EmitNamedSuperPropertyAssignment(expr);
EmitNamedSuperPropertyStore(property);
context()->Plug(r0);
break;
case KEYED_PROPERTY:
EmitKeyedPropertyAssignment(expr);
......@@ -2634,11 +2635,10 @@ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
}
void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
// Assignment to named property of super.
// r0 : value
// stack : receiver ('this'), home_object
Property* prop = expr->target()->AsProperty();
DCHECK(prop != NULL);
Literal* key = prop->key()->AsLiteral();
DCHECK(key != NULL);
......@@ -2648,7 +2648,6 @@ void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
__ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict
: Runtime::kStoreToSuper_Sloppy),
4);
context()->Plug(r0);
}
......@@ -4377,19 +4376,21 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Expression can only be a property, a global or a (parameter or local)
// slot.
enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
enum LhsKind {
VARIABLE,
NAMED_PROPERTY,
KEYED_PROPERTY,
NAMED_SUPER_PROPERTY
};
LhsKind assign_type = VARIABLE;
Property* prop = expr->expression()->AsProperty();
// In case of a property we use the uninitialized expression context
// of the key to detect a named property.
if (prop != NULL) {
assign_type =
(prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY;
if (prop->IsSuperAccess()) {
// throw exception.
VisitSuperReference(prop->obj()->AsSuperReference());
return;
}
(prop->key()->IsPropertyName())
? (prop->IsSuperAccess() ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
: KEYED_PROPERTY;
}
// Evaluate expression and get value.
......@@ -4408,6 +4409,15 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
VisitForStackValue(prop->obj());
__ ldr(LoadDescriptor::ReceiverRegister(), MemOperand(sp, 0));
EmitNamedPropertyLoad(prop);
} else if (assign_type == NAMED_SUPER_PROPERTY) {
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
EmitLoadHomeObject(prop->obj()->AsSuperReference());
__ Push(result_register());
const Register scratch = r1;
__ ldr(scratch, MemOperand(sp, kPointerSize));
__ Push(scratch);
__ Push(result_register());
EmitNamedSuperPropertyLoad(prop);
} else {
VisitForStackValue(prop->obj());
VisitForStackValue(prop->key());
......@@ -4448,6 +4458,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ str(r0, MemOperand(sp, kPointerSize));
break;
case NAMED_SUPER_PROPERTY:
__ str(r0, MemOperand(sp, 2 * kPointerSize));
break;
case KEYED_PROPERTY:
__ str(r0, MemOperand(sp, 2 * kPointerSize));
break;
......@@ -4478,6 +4491,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ str(r0, MemOperand(sp, kPointerSize));
break;
case NAMED_SUPER_PROPERTY:
__ str(r0, MemOperand(sp, 2 * kPointerSize));
break;
case KEYED_PROPERTY:
__ str(r0, MemOperand(sp, 2 * kPointerSize));
break;
......@@ -4536,6 +4552,17 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
break;
}
case NAMED_SUPER_PROPERTY: {
EmitNamedSuperPropertyStore(prop);
if (expr->is_postfix()) {
if (!context()->IsEffect()) {
context()->PlugTOS();
}
} else {
context()->Plug(r0);
}
break;
}
case KEYED_PROPERTY: {
__ Pop(StoreDescriptor::ReceiverRegister(),
StoreDescriptor::NameRegister());
......
......@@ -1980,7 +1980,8 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
EmitNamedPropertyAssignment(expr);
break;
case NAMED_SUPER_PROPERTY:
EmitNamedSuperPropertyAssignment(expr);
EmitNamedSuperPropertyStore(property);
context()->Plug(x0);
break;
case KEYED_PROPERTY:
EmitKeyedPropertyAssignment(expr);
......@@ -2297,11 +2298,10 @@ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
}
void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
// Assignment to named property of super.
// x0 : value
// stack : receiver ('this'), home_object
Property* prop = expr->target()->AsProperty();
DCHECK(prop != NULL);
Literal* key = prop->key()->AsLiteral();
DCHECK(key != NULL);
......@@ -2311,7 +2311,6 @@ void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
__ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict
: Runtime::kStoreToSuper_Sloppy),
4);
context()->Plug(x0);
}
......@@ -4042,19 +4041,21 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Expression can only be a property, a global or a (parameter or local)
// slot.
enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
enum LhsKind {
VARIABLE,
NAMED_PROPERTY,
KEYED_PROPERTY,
NAMED_SUPER_PROPERTY
};
LhsKind assign_type = VARIABLE;
Property* prop = expr->expression()->AsProperty();
// In case of a property we use the uninitialized expression context
// of the key to detect a named property.
if (prop != NULL) {
assign_type =
(prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY;
if (prop->IsSuperAccess()) {
// throw exception.
VisitSuperReference(prop->obj()->AsSuperReference());
return;
}
(prop->key()->IsPropertyName())
? (prop->IsSuperAccess() ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
: KEYED_PROPERTY;
}
// Evaluate expression and get value.
......@@ -4072,6 +4073,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
VisitForStackValue(prop->obj());
__ Peek(LoadDescriptor::ReceiverRegister(), 0);
EmitNamedPropertyLoad(prop);
} else if (assign_type == NAMED_SUPER_PROPERTY) {
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
EmitLoadHomeObject(prop->obj()->AsSuperReference());
__ Push(result_register());
const Register scratch = x10;
__ Peek(scratch, kPointerSize);
__ Push(scratch, result_register());
EmitNamedSuperPropertyLoad(prop);
} else {
// KEYED_PROPERTY
VisitForStackValue(prop->obj());
......@@ -4112,6 +4121,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ Poke(x0, kPointerSize);
break;
case NAMED_SUPER_PROPERTY:
__ Poke(x0, kPointerSize * 2);
break;
case KEYED_PROPERTY:
__ Poke(x0, kPointerSize * 2);
break;
......@@ -4142,6 +4154,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ Poke(x0, kXRegSize);
break;
case NAMED_SUPER_PROPERTY:
__ Poke(x0, 2 * kXRegSize);
break;
case KEYED_PROPERTY:
__ Poke(x0, 2 * kXRegSize);
break;
......@@ -4202,6 +4217,17 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
break;
}
case NAMED_SUPER_PROPERTY: {
EmitNamedSuperPropertyStore(prop);
if (expr->is_postfix()) {
if (!context()->IsEffect()) {
context()->PlugTOS();
}
} else {
context()->Plug(x0);
}
break;
}
case KEYED_PROPERTY: {
__ Pop(StoreDescriptor::NameRegister());
__ Pop(StoreDescriptor::ReceiverRegister());
......
......@@ -562,7 +562,7 @@ class FullCodeGenerator: public AstVisitor {
// Complete a super named property assignment. The right-hand-side value
// is expected in accumulator.
void EmitNamedSuperPropertyAssignment(Assignment* expr);
void EmitNamedSuperPropertyStore(Property* prop);
// Complete a keyed property assignment. The receiver and key are
// expected on top of the stack and the right-hand-side value in the
......
......@@ -1932,7 +1932,8 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
EmitNamedPropertyAssignment(expr);
break;
case NAMED_SUPER_PROPERTY:
EmitNamedSuperPropertyAssignment(expr);
EmitNamedSuperPropertyStore(property);
context()->Plug(eax);
break;
case KEYED_PROPERTY:
EmitKeyedPropertyAssignment(expr);
......@@ -2551,11 +2552,10 @@ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
}
void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
// Assignment to named property of super.
// eax : value
// stack : receiver ('this'), home_object
Property* prop = expr->target()->AsProperty();
DCHECK(prop != NULL);
Literal* key = prop->key()->AsLiteral();
DCHECK(key != NULL);
......@@ -2565,7 +2565,6 @@ void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
__ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict
: Runtime::kStoreToSuper_Sloppy),
4);
context()->Plug(eax);
}
......@@ -4335,19 +4334,21 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Expression can only be a property, a global or a (parameter or local)
// slot.
enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
enum LhsKind {
VARIABLE,
NAMED_PROPERTY,
KEYED_PROPERTY,
NAMED_SUPER_PROPERTY
};
LhsKind assign_type = VARIABLE;
Property* prop = expr->expression()->AsProperty();
// In case of a property we use the uninitialized expression context
// of the key to detect a named property.
if (prop != NULL) {
assign_type =
(prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY;
if (prop->IsSuperAccess()) {
// throw exception.
VisitSuperReference(prop->obj()->AsSuperReference());
return;
}
(prop->key()->IsPropertyName())
? (prop->IsSuperAccess() ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
: KEYED_PROPERTY;
}
// Evaluate expression and get value.
......@@ -4365,6 +4366,13 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
VisitForStackValue(prop->obj());
__ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0));
EmitNamedPropertyLoad(prop);
} else if (assign_type == NAMED_SUPER_PROPERTY) {
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
EmitLoadHomeObject(prop->obj()->AsSuperReference());
__ push(result_register());
__ push(MemOperand(esp, kPointerSize));
__ push(result_register());
EmitNamedSuperPropertyLoad(prop);
} else {
VisitForStackValue(prop->obj());
VisitForStackValue(prop->key());
......@@ -4403,6 +4411,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ mov(Operand(esp, kPointerSize), eax);
break;
case NAMED_SUPER_PROPERTY:
__ mov(Operand(esp, 2 * kPointerSize), eax);
break;
case KEYED_PROPERTY:
__ mov(Operand(esp, 2 * kPointerSize), eax);
break;
......@@ -4441,6 +4452,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ mov(Operand(esp, kPointerSize), eax);
break;
case NAMED_SUPER_PROPERTY:
__ mov(Operand(esp, 2 * kPointerSize), eax);
break;
case KEYED_PROPERTY:
__ mov(Operand(esp, 2 * kPointerSize), eax);
break;
......@@ -4500,6 +4514,17 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
break;
}
case NAMED_SUPER_PROPERTY: {
EmitNamedSuperPropertyStore(prop);
if (expr->is_postfix()) {
if (!context()->IsEffect()) {
context()->PlugTOS();
}
} else {
context()->Plug(eax);
}
break;
}
case KEYED_PROPERTY: {
__ pop(StoreDescriptor::NameRegister());
__ pop(StoreDescriptor::ReceiverRegister());
......
......@@ -1964,7 +1964,8 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
EmitNamedPropertyAssignment(expr);
break;
case NAMED_SUPER_PROPERTY:
EmitNamedSuperPropertyAssignment(expr);
EmitNamedSuperPropertyStore(property);
context()->Plug(rax);
break;
case KEYED_PROPERTY:
EmitKeyedPropertyAssignment(expr);
......@@ -2547,11 +2548,10 @@ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
}
void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) {
// Assignment to named property of super.
// rax : value
// stack : receiver ('this'), home_object
Property* prop = expr->target()->AsProperty();
DCHECK(prop != NULL);
Literal* key = prop->key()->AsLiteral();
DCHECK(key != NULL);
......@@ -2561,7 +2561,6 @@ void FullCodeGenerator::EmitNamedSuperPropertyAssignment(Assignment* expr) {
__ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict
: Runtime::kStoreToSuper_Sloppy),
4);
context()->Plug(rax);
}
......@@ -4348,19 +4347,21 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Expression can only be a property, a global or a (parameter or local)
// slot.
enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
enum LhsKind {
VARIABLE,
NAMED_PROPERTY,
KEYED_PROPERTY,
NAMED_SUPER_PROPERTY
};
LhsKind assign_type = VARIABLE;
Property* prop = expr->expression()->AsProperty();
// In case of a property we use the uninitialized expression context
// of the key to detect a named property.
if (prop != NULL) {
assign_type =
(prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY;
if (prop->IsSuperAccess()) {
// throw exception.
VisitSuperReference(prop->obj()->AsSuperReference());
return;
}
(prop->key()->IsPropertyName())
? (prop->IsSuperAccess() ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
: KEYED_PROPERTY;
}
// Evaluate expression and get value.
......@@ -4377,6 +4378,13 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
VisitForStackValue(prop->obj());
__ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0));
EmitNamedPropertyLoad(prop);
} else if (assign_type == NAMED_SUPER_PROPERTY) {
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
EmitLoadHomeObject(prop->obj()->AsSuperReference());
__ Push(result_register());
__ Push(MemOperand(rsp, kPointerSize));
__ Push(result_register());
EmitNamedSuperPropertyLoad(prop);
} else {
VisitForStackValue(prop->obj());
VisitForStackValue(prop->key());
......@@ -4416,6 +4424,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ movp(Operand(rsp, kPointerSize), rax);
break;
case NAMED_SUPER_PROPERTY:
__ movp(Operand(rsp, 2 * kPointerSize), rax);
break;
case KEYED_PROPERTY:
__ movp(Operand(rsp, 2 * kPointerSize), rax);
break;
......@@ -4451,6 +4462,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY:
__ movp(Operand(rsp, kPointerSize), rax);
break;
case NAMED_SUPER_PROPERTY:
__ movp(Operand(rsp, 2 * kPointerSize), rax);
break;
case KEYED_PROPERTY:
__ movp(Operand(rsp, 2 * kPointerSize), rax);
break;
......@@ -4510,6 +4524,17 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
break;
}
case NAMED_SUPER_PROPERTY: {
EmitNamedSuperPropertyStore(prop);
if (expr->is_postfix()) {
if (!context()->IsEffect()) {
context()->PlugTOS();
}
} else {
context()->Plug(rax);
}
break;
}
case KEYED_PROPERTY: {
__ Pop(StoreDescriptor::NameRegister());
__ Pop(StoreDescriptor::ReceiverRegister());
......
......@@ -225,10 +225,58 @@
}());
(function TestCountOperations() {
function Base() {}
Base.prototype = {
constructor: Base,
get x() {
return this._x;
},
set x(v) {
this._x = v;
},
_x: 1
};
function Derived() {}
Derived.__proto__ = Base;
Derived.prototype = {
__proto__: Base.prototype,
constructor: Derived,
_x: 2
};
Derived.prototype.testCounts = function() {
assertEquals(2, this._x);
assertEquals(2, super.x);
super.x++;
assertEquals(3, super.x);
++super.x;
assertEquals(4, super.x);
assertEquals(4, super.x++);
assertEquals(5, super.x);
assertEquals(6, ++super.x);
assertEquals(6, super.x);
assertEquals(6, this._x);
super.x--;
assertEquals(5, super.x);
--super.x;
assertEquals(4, super.x);
assertEquals(4, super.x--);
assertEquals(3, super.x);
assertEquals(2, --super.x);
assertEquals(2, super.x);
assertEquals(2, this._x);
}.toMethod(Derived.prototype);
new Derived().testCounts();
}());
(function TestUnsupportedCases() {
function f1(x) { return super[x]; }
function f2(x) { super[x] = 5; }
var o = {}
assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError);
function f2() { super.x++; }
assertThrows(function(){f2.toMethod(o)();}, ReferenceError);
assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError);
}());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment