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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1410953003: [Interpreter] Adds delete operator to interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added more tests for delete and addressed review comments Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/control-flow-builders.h" 8 #include "src/interpreter/control-flow-builders.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 switch (expr->op()) { 1352 switch (expr->op()) {
1353 case Token::Value::NOT: 1353 case Token::Value::NOT:
1354 VisitNot(expr); 1354 VisitNot(expr);
1355 break; 1355 break;
1356 case Token::Value::TYPEOF: 1356 case Token::Value::TYPEOF:
1357 VisitTypeOf(expr); 1357 VisitTypeOf(expr);
1358 break; 1358 break;
1359 case Token::Value::VOID: 1359 case Token::Value::VOID:
1360 VisitVoid(expr); 1360 VisitVoid(expr);
1361 break; 1361 break;
1362 case Token::Value::DELETE:
1363 VisitDelete(expr);
1364 break;
1362 case Token::Value::BIT_NOT: 1365 case Token::Value::BIT_NOT:
1363 case Token::Value::DELETE: 1366 case Token::Value::ADD:
1364 UNIMPLEMENTED(); 1367 case Token::Value::SUB:
1368 // These operators are converted to an equivalent binary operators in
1369 // the parser. These operators are not expected to be visited here.
1370 UNREACHABLE();
1365 default: 1371 default:
1366 UNREACHABLE(); 1372 UNREACHABLE();
1367 } 1373 }
1368 } 1374 }
1369 1375
1370 1376
1377 void BytecodeGenerator::VisitDelete(UnaryOperation* expr) {
1378 if (expr->expression()->IsProperty()) {
1379 // Delete of an object property is allowed both in sloppy
1380 // and strict modes.
1381 Property* property = expr->expression()->AsProperty();
1382 Register object = VisitForRegisterValue(property->obj());
1383 VisitForAccumulatorValue(property->key());
1384 builder()->Delete(object, language_mode());
1385 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.
1386 } else if (expr->expression()->IsVariableProxy()) {
1387 // Delete of an unqualified identifier is allowed in sloppy mode but is
1388 // not allowed in strict mode. Deleting 'this' is allowed in both modes.
1389 VariableProxy* proxy = expr->expression()->AsVariableProxy();
1390 Variable* variable = proxy->var();
1391 DCHECK(is_sloppy(language_mode()) || variable->HasThisName(isolate()));
1392 switch (variable->location()) {
1393 case VariableLocation::GLOBAL:
1394 case VariableLocation::UNALLOCATED: {
1395 // 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.
1396 TemporaryRegisterScope temporary_register_scope(builder());
1397 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.
1398 builder()->LoadContextSlot(execution_context()->reg(),
1399 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.
1400 .StoreAccumulatorInRegister(global_object)
1401 .LoadLiteral(variable->name())
1402 .Delete(global_object, language_mode());
1403 execution_result()->SetResultInAccumulator();
1404 break;
1405 }
1406 case VariableLocation::PARAMETER:
1407 case VariableLocation::LOCAL:
1408 case VariableLocation::CONTEXT: {
1409 // 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.
1410 // does not have any effect.
1411 if (variable->HasThisName(isolate())) {
1412 builder()->LoadTrue();
1413 } else {
1414 builder()->LoadFalse();
1415 }
1416 execution_result()->SetResultInAccumulator();
1417 break;
1418 }
1419 case VariableLocation::LOOKUP: {
1420 UNIMPLEMENTED();
1421 break;
1422 }
1423 default:
1424 UNREACHABLE();
1425 }
1426 } else {
1427 // Delete of an unresolvable reference returns true.
1428 VisitForEffect(expr->expression());
1429 builder()->LoadTrue();
1430 execution_result()->SetResultInAccumulator();
1431 }
1432 }
1433
1434
1371 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { 1435 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
1372 DCHECK(expr->expression()->IsValidReferenceExpressionOrThis()); 1436 DCHECK(expr->expression()->IsValidReferenceExpressionOrThis());
1373 1437
1374 // Left-hand side can only be a property, a global or a variable slot. 1438 // Left-hand side can only be a property, a global or a variable slot.
1375 Property* property = expr->expression()->AsProperty(); 1439 Property* property = expr->expression()->AsProperty();
1376 LhsKind assign_type = Property::GetAssignType(property); 1440 LhsKind assign_type = Property::GetAssignType(property);
1377 1441
1378 // TODO(rmcilroy): Set is_postfix to false if visiting for effect. 1442 // TODO(rmcilroy): Set is_postfix to false if visiting for effect.
1379 bool is_postfix = expr->is_postfix(); 1443 bool is_postfix = expr->is_postfix();
1380 1444
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 } 1880 }
1817 1881
1818 1882
1819 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 1883 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
1820 return info()->feedback_vector()->GetIndex(slot); 1884 return info()->feedback_vector()->GetIndex(slot);
1821 } 1885 }
1822 1886
1823 } // namespace interpreter 1887 } // namespace interpreter
1824 } // namespace internal 1888 } // namespace internal
1825 } // namespace v8 1889 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698