Index: src/interpreter/bytecode-generator.cc |
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
index 8c791db5e3d9ddbab25e65145c45bccffcb413e1..4d4e328f6d4dec16ba8b991d9e661bb546ae166b 100644 |
--- a/src/interpreter/bytecode-generator.cc |
+++ b/src/interpreter/bytecode-generator.cc |
@@ -1359,15 +1359,79 @@ void BytecodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
case Token::Value::VOID: |
VisitVoid(expr); |
break; |
- case Token::Value::BIT_NOT: |
case Token::Value::DELETE: |
- UNIMPLEMENTED(); |
+ VisitDelete(expr); |
+ break; |
+ case Token::Value::BIT_NOT: |
+ case Token::Value::ADD: |
+ case Token::Value::SUB: |
+ // These operators are converted to an equivalent binary operators in |
+ // the parser. These operators are not expected to be visited here. |
+ UNREACHABLE(); |
default: |
UNREACHABLE(); |
} |
} |
+void BytecodeGenerator::VisitDelete(UnaryOperation* expr) { |
+ if (expr->expression()->IsProperty()) { |
+ // Delete of an object property is allowed both in sloppy |
+ // and strict modes. |
+ Property* property = expr->expression()->AsProperty(); |
+ Register object = VisitForRegisterValue(property->obj()); |
+ VisitForAccumulatorValue(property->key()); |
+ builder()->Delete(object, language_mode()); |
+ execution_result()->SetResultInAccumulator(); |
rmcilroy
2015/10/26 14:31:06
nit - do this once at the bottom of the function (
mythria
2015/10/27 10:50:48
Done.
|
+ } else if (expr->expression()->IsVariableProxy()) { |
+ // Delete of an unqualified identifier is allowed in sloppy mode but is |
+ // not allowed in strict mode. Deleting 'this' is allowed in both modes. |
+ VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
+ Variable* variable = proxy->var(); |
+ DCHECK(is_sloppy(language_mode()) || variable->HasThisName(isolate())); |
+ switch (variable->location()) { |
+ case VariableLocation::GLOBAL: |
+ case VariableLocation::UNALLOCATED: { |
+ // Global var, let, const or variables not explicitly declared |
rmcilroy
2015/10/26 14:31:06
nit - full stop at end of sentence
mythria
2015/10/27 10:50:48
Done.
|
+ TemporaryRegisterScope temporary_register_scope(builder()); |
+ Register global_object = temporary_register_scope.NewRegister(); |
rmcilroy
2015/10/26 14:31:07
nit - use exeuction_result()->NewRegister() (and r
mythria
2015/10/27 10:50:48
Done.
|
+ builder()->LoadContextSlot(execution_context()->reg(), |
+ Context::GLOBAL_OBJECT_INDEX) |
rmcilroy
2015/10/26 14:31:07
nit - indentation (did you run git cl format ? )
mythria
2015/10/27 10:50:48
Done.
|
+ .StoreAccumulatorInRegister(global_object) |
+ .LoadLiteral(variable->name()) |
+ .Delete(global_object, language_mode()); |
+ execution_result()->SetResultInAccumulator(); |
+ break; |
+ } |
+ case VariableLocation::PARAMETER: |
+ case VariableLocation::LOCAL: |
+ case VariableLocation::CONTEXT: { |
+ // Deleting Local var/let/const, context variables, and arguments |
rmcilroy
2015/10/26 14:31:06
nit - Local/local
mythria
2015/10/27 10:50:48
Done.
|
+ // does not have any effect. |
+ if (variable->HasThisName(isolate())) { |
+ builder()->LoadTrue(); |
+ } else { |
+ builder()->LoadFalse(); |
+ } |
+ execution_result()->SetResultInAccumulator(); |
+ break; |
+ } |
+ case VariableLocation::LOOKUP: { |
+ UNIMPLEMENTED(); |
+ break; |
+ } |
+ default: |
+ UNREACHABLE(); |
+ } |
+ } else { |
+ // Delete of an unresolvable reference returns true. |
+ VisitForEffect(expr->expression()); |
+ builder()->LoadTrue(); |
+ execution_result()->SetResultInAccumulator(); |
+ } |
+} |
+ |
+ |
void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { |
DCHECK(expr->expression()->IsValidReferenceExpressionOrThis()); |