OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value())); | 891 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value())); |
892 // Fall through. | 892 // Fall through. |
893 case ObjectLiteral::Property::COMPUTED: { | 893 case ObjectLiteral::Property::COMPUTED: { |
894 // It is safe to use [[Put]] here because the boilerplate already | 894 // It is safe to use [[Put]] here because the boilerplate already |
895 // contains computed properties with an uninitialized value. | 895 // contains computed properties with an uninitialized value. |
896 if (key->value()->IsInternalizedString()) { | 896 if (key->value()->IsInternalizedString()) { |
897 if (property->emit_store()) { | 897 if (property->emit_store()) { |
898 VisitForValue(property->value()); | 898 VisitForValue(property->value()); |
899 Node* value = environment()->Pop(); | 899 Node* value = environment()->Pop(); |
900 PrintableUnique<Name> name = MakeUnique(key->AsPropertyName()); | 900 PrintableUnique<Name> name = MakeUnique(key->AsPropertyName()); |
901 Node* store = | 901 Node* store = NewNode(javascript()->StoreNamed(strict_mode(), name), |
902 NewNode(javascript()->StoreNamed(name), literal, value); | 902 literal, value); |
903 PrepareFrameState(store, key->id()); | 903 PrepareFrameState(store, key->id()); |
904 } else { | 904 } else { |
905 VisitForEffect(property->value()); | 905 VisitForEffect(property->value()); |
906 } | 906 } |
907 break; | 907 break; |
908 } | 908 } |
909 environment()->Push(literal); // Duplicate receiver. | 909 environment()->Push(literal); // Duplicate receiver. |
910 VisitForValue(property->key()); | 910 VisitForValue(property->key()); |
911 VisitForValue(property->value()); | 911 VisitForValue(property->value()); |
912 Node* value = environment()->Pop(); | 912 Node* value = environment()->Pop(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 | 985 |
986 // Create nodes to evaluate all the non-constant subexpressions and to store | 986 // Create nodes to evaluate all the non-constant subexpressions and to store |
987 // them into the newly cloned array. | 987 // them into the newly cloned array. |
988 for (int i = 0; i < expr->values()->length(); i++) { | 988 for (int i = 0; i < expr->values()->length(); i++) { |
989 Expression* subexpr = expr->values()->at(i); | 989 Expression* subexpr = expr->values()->at(i); |
990 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 990 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
991 | 991 |
992 VisitForValue(subexpr); | 992 VisitForValue(subexpr); |
993 Node* value = environment()->Pop(); | 993 Node* value = environment()->Pop(); |
994 Node* index = jsgraph()->Constant(i); | 994 Node* index = jsgraph()->Constant(i); |
995 Node* store = NewNode(javascript()->StoreProperty(), literal, index, value); | 995 Node* store = NewNode(javascript()->StoreProperty(strict_mode()), literal, |
| 996 index, value); |
996 PrepareFrameState(store, expr->GetIdForElement(i)); | 997 PrepareFrameState(store, expr->GetIdForElement(i)); |
997 } | 998 } |
998 | 999 |
999 environment()->Pop(); // Array literal index. | 1000 environment()->Pop(); // Array literal index. |
1000 ast_context()->ProduceValue(environment()->Pop()); | 1001 ast_context()->ProduceValue(environment()->Pop()); |
1001 } | 1002 } |
1002 | 1003 |
1003 | 1004 |
1004 void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value) { | 1005 void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value) { |
1005 DCHECK(expr->IsValidReferenceExpression()); | 1006 DCHECK(expr->IsValidReferenceExpression()); |
(...skipping 10 matching lines...) Expand all Loading... |
1016 BuildVariableAssignment(var, value, Token::ASSIGN, BailoutId::None()); | 1017 BuildVariableAssignment(var, value, Token::ASSIGN, BailoutId::None()); |
1017 break; | 1018 break; |
1018 } | 1019 } |
1019 case NAMED_PROPERTY: { | 1020 case NAMED_PROPERTY: { |
1020 environment()->Push(value); | 1021 environment()->Push(value); |
1021 VisitForValue(property->obj()); | 1022 VisitForValue(property->obj()); |
1022 Node* object = environment()->Pop(); | 1023 Node* object = environment()->Pop(); |
1023 value = environment()->Pop(); | 1024 value = environment()->Pop(); |
1024 PrintableUnique<Name> name = | 1025 PrintableUnique<Name> name = |
1025 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); | 1026 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); |
1026 Node* store = NewNode(javascript()->StoreNamed(name), object, value); | 1027 Node* store = |
| 1028 NewNode(javascript()->StoreNamed(strict_mode(), name), object, value); |
1027 // TODO(jarin) Fill in the correct bailout id. | 1029 // TODO(jarin) Fill in the correct bailout id. |
1028 PrepareFrameState(store, BailoutId::None()); | 1030 PrepareFrameState(store, BailoutId::None()); |
1029 break; | 1031 break; |
1030 } | 1032 } |
1031 case KEYED_PROPERTY: { | 1033 case KEYED_PROPERTY: { |
1032 environment()->Push(value); | 1034 environment()->Push(value); |
1033 VisitForValue(property->obj()); | 1035 VisitForValue(property->obj()); |
1034 VisitForValue(property->key()); | 1036 VisitForValue(property->key()); |
1035 Node* key = environment()->Pop(); | 1037 Node* key = environment()->Pop(); |
1036 Node* object = environment()->Pop(); | 1038 Node* object = environment()->Pop(); |
1037 value = environment()->Pop(); | 1039 value = environment()->Pop(); |
1038 Node* store = NewNode(javascript()->StoreProperty(), object, key, value); | 1040 Node* store = NewNode(javascript()->StoreProperty(strict_mode()), object, |
| 1041 key, value); |
1039 // TODO(jarin) Fill in the correct bailout id. | 1042 // TODO(jarin) Fill in the correct bailout id. |
1040 PrepareFrameState(store, BailoutId::None()); | 1043 PrepareFrameState(store, BailoutId::None()); |
1041 break; | 1044 break; |
1042 } | 1045 } |
1043 } | 1046 } |
1044 } | 1047 } |
1045 | 1048 |
1046 | 1049 |
1047 void AstGraphBuilder::VisitAssignment(Assignment* expr) { | 1050 void AstGraphBuilder::VisitAssignment(Assignment* expr) { |
1048 DCHECK(expr->target()->IsValidReferenceExpression()); | 1051 DCHECK(expr->target()->IsValidReferenceExpression()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 case VARIABLE: { | 1112 case VARIABLE: { |
1110 Variable* variable = expr->target()->AsVariableProxy()->var(); | 1113 Variable* variable = expr->target()->AsVariableProxy()->var(); |
1111 BuildVariableAssignment(variable, value, expr->op(), | 1114 BuildVariableAssignment(variable, value, expr->op(), |
1112 expr->AssignmentId()); | 1115 expr->AssignmentId()); |
1113 break; | 1116 break; |
1114 } | 1117 } |
1115 case NAMED_PROPERTY: { | 1118 case NAMED_PROPERTY: { |
1116 Node* object = environment()->Pop(); | 1119 Node* object = environment()->Pop(); |
1117 PrintableUnique<Name> name = | 1120 PrintableUnique<Name> name = |
1118 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); | 1121 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); |
1119 Node* store = NewNode(javascript()->StoreNamed(name), object, value); | 1122 Node* store = |
| 1123 NewNode(javascript()->StoreNamed(strict_mode(), name), object, value); |
1120 PrepareFrameState(store, expr->AssignmentId()); | 1124 PrepareFrameState(store, expr->AssignmentId()); |
1121 break; | 1125 break; |
1122 } | 1126 } |
1123 case KEYED_PROPERTY: { | 1127 case KEYED_PROPERTY: { |
1124 Node* key = environment()->Pop(); | 1128 Node* key = environment()->Pop(); |
1125 Node* object = environment()->Pop(); | 1129 Node* object = environment()->Pop(); |
1126 Node* store = NewNode(javascript()->StoreProperty(), object, key, value); | 1130 Node* store = NewNode(javascript()->StoreProperty(strict_mode()), object, |
| 1131 key, value); |
1127 PrepareFrameState(store, expr->AssignmentId()); | 1132 PrepareFrameState(store, expr->AssignmentId()); |
1128 break; | 1133 break; |
1129 } | 1134 } |
1130 } | 1135 } |
1131 | 1136 |
1132 ast_context()->ProduceValue(value); | 1137 ast_context()->ProduceValue(value); |
1133 } | 1138 } |
1134 | 1139 |
1135 | 1140 |
1136 void AstGraphBuilder::VisitYield(Yield* expr) { | 1141 void AstGraphBuilder::VisitYield(Yield* expr) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 case VARIABLE: { | 1419 case VARIABLE: { |
1415 Variable* variable = expr->expression()->AsVariableProxy()->var(); | 1420 Variable* variable = expr->expression()->AsVariableProxy()->var(); |
1416 BuildVariableAssignment(variable, value, expr->op(), | 1421 BuildVariableAssignment(variable, value, expr->op(), |
1417 expr->AssignmentId()); | 1422 expr->AssignmentId()); |
1418 break; | 1423 break; |
1419 } | 1424 } |
1420 case NAMED_PROPERTY: { | 1425 case NAMED_PROPERTY: { |
1421 Node* object = environment()->Pop(); | 1426 Node* object = environment()->Pop(); |
1422 PrintableUnique<Name> name = | 1427 PrintableUnique<Name> name = |
1423 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); | 1428 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); |
1424 Node* store = NewNode(javascript()->StoreNamed(name), object, value); | 1429 Node* store = |
| 1430 NewNode(javascript()->StoreNamed(strict_mode(), name), object, value); |
1425 PrepareFrameState(store, expr->AssignmentId()); | 1431 PrepareFrameState(store, expr->AssignmentId()); |
1426 break; | 1432 break; |
1427 } | 1433 } |
1428 case KEYED_PROPERTY: { | 1434 case KEYED_PROPERTY: { |
1429 Node* key = environment()->Pop(); | 1435 Node* key = environment()->Pop(); |
1430 Node* object = environment()->Pop(); | 1436 Node* object = environment()->Pop(); |
1431 Node* store = NewNode(javascript()->StoreProperty(), object, key, value); | 1437 Node* store = NewNode(javascript()->StoreProperty(strict_mode()), object, |
| 1438 key, value); |
1432 PrepareFrameState(store, expr->AssignmentId()); | 1439 PrepareFrameState(store, expr->AssignmentId()); |
1433 break; | 1440 break; |
1434 } | 1441 } |
1435 } | 1442 } |
1436 | 1443 |
1437 // Restore old value for postfix expressions. | 1444 // Restore old value for postfix expressions. |
1438 if (is_postfix) value = environment()->Pop(); | 1445 if (is_postfix) value = environment()->Pop(); |
1439 | 1446 |
1440 ast_context()->ProduceValue(value); | 1447 ast_context()->ProduceValue(value); |
1441 } | 1448 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 | 1531 |
1525 void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 1532 void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
1526 DCHECK(globals()->is_empty()); | 1533 DCHECK(globals()->is_empty()); |
1527 AstVisitor::VisitDeclarations(declarations); | 1534 AstVisitor::VisitDeclarations(declarations); |
1528 if (globals()->is_empty()) return; | 1535 if (globals()->is_empty()) return; |
1529 Handle<FixedArray> data = | 1536 Handle<FixedArray> data = |
1530 isolate()->factory()->NewFixedArray(globals()->length(), TENURED); | 1537 isolate()->factory()->NewFixedArray(globals()->length(), TENURED); |
1531 for (int i = 0; i < globals()->length(); ++i) data->set(i, *globals()->at(i)); | 1538 for (int i = 0; i < globals()->length(); ++i) data->set(i, *globals()->at(i)); |
1532 int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | | 1539 int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | |
1533 DeclareGlobalsNativeFlag::encode(info()->is_native()) | | 1540 DeclareGlobalsNativeFlag::encode(info()->is_native()) | |
1534 DeclareGlobalsStrictMode::encode(info()->strict_mode()); | 1541 DeclareGlobalsStrictMode::encode(strict_mode()); |
1535 Node* flags = jsgraph()->Constant(encoded_flags); | 1542 Node* flags = jsgraph()->Constant(encoded_flags); |
1536 Node* pairs = jsgraph()->Constant(data); | 1543 Node* pairs = jsgraph()->Constant(data); |
1537 Operator* op = javascript()->Runtime(Runtime::kDeclareGlobals, 3); | 1544 Operator* op = javascript()->Runtime(Runtime::kDeclareGlobals, 3); |
1538 NewNode(op, current_context(), pairs, flags); | 1545 NewNode(op, current_context(), pairs, flags); |
1539 globals()->Rewind(0); | 1546 globals()->Rewind(0); |
1540 } | 1547 } |
1541 | 1548 |
1542 | 1549 |
1543 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { | 1550 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { |
1544 if (stmt == NULL) return; | 1551 if (stmt == NULL) return; |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 Node* AstGraphBuilder::BuildVariableAssignment(Variable* variable, Node* value, | 1838 Node* AstGraphBuilder::BuildVariableAssignment(Variable* variable, Node* value, |
1832 Token::Value op, | 1839 Token::Value op, |
1833 BailoutId bailout_id) { | 1840 BailoutId bailout_id) { |
1834 Node* the_hole = jsgraph()->TheHoleConstant(); | 1841 Node* the_hole = jsgraph()->TheHoleConstant(); |
1835 VariableMode mode = variable->mode(); | 1842 VariableMode mode = variable->mode(); |
1836 switch (variable->location()) { | 1843 switch (variable->location()) { |
1837 case Variable::UNALLOCATED: { | 1844 case Variable::UNALLOCATED: { |
1838 // Global var, const, or let variable. | 1845 // Global var, const, or let variable. |
1839 Node* global = BuildLoadGlobalObject(); | 1846 Node* global = BuildLoadGlobalObject(); |
1840 PrintableUnique<Name> name = MakeUnique(variable->name()); | 1847 PrintableUnique<Name> name = MakeUnique(variable->name()); |
1841 Operator* op = javascript()->StoreNamed(name); | 1848 Operator* op = javascript()->StoreNamed(strict_mode(), name); |
1842 Node* store = NewNode(op, global, value); | 1849 Node* store = NewNode(op, global, value); |
1843 PrepareFrameState(store, bailout_id); | 1850 PrepareFrameState(store, bailout_id); |
1844 return store; | 1851 return store; |
1845 } | 1852 } |
1846 case Variable::PARAMETER: | 1853 case Variable::PARAMETER: |
1847 case Variable::LOCAL: | 1854 case Variable::LOCAL: |
1848 // Local var, const, or let variable. | 1855 // Local var, const, or let variable. |
1849 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { | 1856 if (mode == CONST_LEGACY && op == Token::INIT_CONST_LEGACY) { |
1850 // Perform an initialization check for legacy const variables. | 1857 // Perform an initialization check for legacy const variables. |
1851 Node* current = environment()->Lookup(variable); | 1858 Node* current = environment()->Lookup(variable); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 | 2038 |
2032 // Continue with the original environment. | 2039 // Continue with the original environment. |
2033 set_environment(continuation_env); | 2040 set_environment(continuation_env); |
2034 NewNode(common()->Continuation()); | 2041 NewNode(common()->Continuation()); |
2035 } | 2042 } |
2036 } | 2043 } |
2037 | 2044 |
2038 } | 2045 } |
2039 } | 2046 } |
2040 } // namespace v8::internal::compiler | 2047 } // namespace v8::internal::compiler |
OLD | NEW |