OLD | NEW |
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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 | 1036 |
1037 TEST(LoadGlobal) { | 1037 TEST(LoadGlobal) { |
1038 InitializedHandleScope handle_scope; | 1038 InitializedHandleScope handle_scope; |
1039 BytecodeGeneratorHelper helper; | 1039 BytecodeGeneratorHelper helper; |
1040 | 1040 |
1041 ExpectedSnippet<int> snippets[] = { | 1041 ExpectedSnippet<int> snippets[] = { |
1042 { | 1042 { |
1043 "var a = 1;\nfunction f() { return a; }\nf()", | 1043 "var a = 1;\nfunction f() { return a; }\nf()", |
1044 0, | 1044 0, |
1045 1, | 1045 1, |
1046 3, | 1046 4, |
1047 { | 1047 { |
1048 B(LdaGlobal), _, // | 1048 B(LdaGlobal), _, _, // |
1049 B(Return) // | 1049 B(Return) // |
1050 }, | 1050 }, |
1051 }, | 1051 }, |
1052 { | 1052 { |
1053 "function t() { }\nfunction f() { return t; }\nf()", | 1053 "function t() { }\nfunction f() { return t; }\nf()", |
1054 0, | 1054 0, |
1055 1, | 1055 1, |
1056 3, | 1056 4, |
1057 { | 1057 { |
1058 B(LdaGlobal), _, // | 1058 B(LdaGlobal), _, _, // |
1059 B(Return) // | 1059 B(Return) // |
1060 }, | 1060 }, |
1061 }, | 1061 }, |
1062 }; | 1062 }; |
1063 | 1063 |
1064 for (size_t i = 0; i < arraysize(snippets); i++) { | 1064 for (size_t i = 0; i < arraysize(snippets); i++) { |
1065 Handle<BytecodeArray> bytecode_array = | 1065 Handle<BytecodeArray> bytecode_array = |
1066 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1066 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
1067 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1067 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
1068 } | 1068 } |
1069 } | 1069 } |
1070 | 1070 |
1071 | 1071 |
1072 TEST(StoreGlobal) { | 1072 TEST(StoreGlobal) { |
1073 InitializedHandleScope handle_scope; | 1073 InitializedHandleScope handle_scope; |
1074 BytecodeGeneratorHelper helper; | 1074 BytecodeGeneratorHelper helper; |
1075 | 1075 |
1076 ExpectedSnippet<InstanceType> snippets[] = { | 1076 ExpectedSnippet<InstanceType> snippets[] = { |
1077 { | 1077 { |
1078 "var a = 1;\nfunction f() { a = 2; }\nf()", | 1078 "var a = 1;\nfunction f() { a = 2; }\nf()", |
1079 0, | 1079 0, |
1080 1, | 1080 1, |
1081 6, | 1081 7, |
1082 { | 1082 { |
1083 B(LdaSmi8), U8(2), // | 1083 B(LdaSmi8), U8(2), // |
1084 B(StaGlobalSloppy), _, // | 1084 B(StaGlobalSloppy), _, _, // |
1085 B(LdaUndefined), // | 1085 B(LdaUndefined), // |
1086 B(Return) // | 1086 B(Return) // |
1087 }, | 1087 }, |
1088 }, | 1088 }, |
1089 { | 1089 { |
1090 "var a = \"test\"; function f(b) { a = b; }\nf(\"global\")", | 1090 "var a = \"test\"; function f(b) { a = b; }\nf(\"global\")", |
1091 0, | 1091 0, |
1092 2, | 1092 2, |
1093 6, | 1093 7, |
1094 { | 1094 { |
1095 B(Ldar), R(helper.kLastParamIndex), // | 1095 B(Ldar), R(helper.kLastParamIndex), // |
1096 B(StaGlobalSloppy), _, // | 1096 B(StaGlobalSloppy), _, _, // |
1097 B(LdaUndefined), // | 1097 B(LdaUndefined), // |
1098 B(Return) // | 1098 B(Return) // |
1099 }, | 1099 }, |
1100 }, | 1100 }, |
1101 { | 1101 { |
1102 "'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()", | 1102 "'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()", |
1103 0, | 1103 0, |
1104 1, | 1104 1, |
1105 6, | 1105 7, |
1106 { | 1106 { |
1107 B(LdaSmi8), U8(2), // | 1107 B(LdaSmi8), U8(2), // |
1108 B(StaGlobalStrict), _, // | 1108 B(StaGlobalStrict), _, _, // |
1109 B(LdaUndefined), // | 1109 B(LdaUndefined), // |
1110 B(Return) // | 1110 B(Return) // |
1111 }, | 1111 }, |
1112 }, | 1112 }, |
1113 }; | 1113 }; |
1114 | 1114 |
1115 for (size_t i = 0; i < arraysize(snippets); i++) { | 1115 for (size_t i = 0; i < arraysize(snippets); i++) { |
1116 Handle<BytecodeArray> bytecode_array = | 1116 Handle<BytecodeArray> bytecode_array = |
1117 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1117 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
1118 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1118 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
1119 } | 1119 } |
1120 } | 1120 } |
1121 | 1121 |
1122 | 1122 |
1123 TEST(CallGlobal) { | 1123 TEST(CallGlobal) { |
1124 InitializedHandleScope handle_scope; | 1124 InitializedHandleScope handle_scope; |
1125 BytecodeGeneratorHelper helper; | 1125 BytecodeGeneratorHelper helper; |
1126 | 1126 |
1127 ExpectedSnippet<int> snippets[] = { | 1127 ExpectedSnippet<int> snippets[] = { |
1128 { | 1128 { |
1129 "function t() { }\nfunction f() { return t(); }\nf()", | 1129 "function t() { }\nfunction f() { return t(); }\nf()", |
1130 2 * kPointerSize, | 1130 2 * kPointerSize, |
1131 1, | 1131 1, |
1132 12, | 1132 13, |
1133 { | 1133 { |
1134 B(LdaUndefined), // | 1134 B(LdaUndefined), // |
1135 B(Star), R(1), // | 1135 B(Star), R(1), // |
1136 B(LdaGlobal), _, // | 1136 B(LdaGlobal), _, _, // |
1137 B(Star), R(0), // | 1137 B(Star), R(0), // |
1138 B(Call), R(0), R(1), U8(0), // | 1138 B(Call), R(0), R(1), U8(0), // |
1139 B(Return) // | 1139 B(Return) // |
1140 }, | 1140 }, |
1141 }, | 1141 }, |
1142 { | 1142 { |
1143 "function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", | 1143 "function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", |
1144 5 * kPointerSize, | 1144 5 * kPointerSize, |
1145 1, | 1145 1, |
1146 24, | 1146 25, |
1147 { | 1147 { |
1148 B(LdaUndefined), // | 1148 B(LdaUndefined), // |
1149 B(Star), R(1), // | 1149 B(Star), R(1), // |
1150 B(LdaGlobal), _, // | 1150 B(LdaGlobal), _, _, // |
1151 B(Star), R(0), // | 1151 B(Star), R(0), // |
1152 B(LdaSmi8), U8(1), // | 1152 B(LdaSmi8), U8(1), // |
1153 B(Star), R(2), // | 1153 B(Star), R(2), // |
1154 B(LdaSmi8), U8(2), // | 1154 B(LdaSmi8), U8(2), // |
1155 B(Star), R(3), // | 1155 B(Star), R(3), // |
1156 B(LdaSmi8), U8(3), // | 1156 B(LdaSmi8), U8(3), // |
1157 B(Star), R(4), // | 1157 B(Star), R(4), // |
1158 B(Call), R(0), R(1), U8(3), // | 1158 B(Call), R(0), R(1), U8(3), // |
1159 B(Return) // | 1159 B(Return) // |
1160 }, | 1160 }, |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 B(LdaZero), // | 1549 B(LdaZero), // |
1550 B(Star), R(2), // | 1550 B(Star), R(2), // |
1551 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 1551 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
1552 B(LdaUndefined), // | 1552 B(LdaUndefined), // |
1553 B(Return) // | 1553 B(Return) // |
1554 }, | 1554 }, |
1555 -1}, | 1555 -1}, |
1556 {"var a = 1;\na=2;", | 1556 {"var a = 1;\na=2;", |
1557 5 * kPointerSize, | 1557 5 * kPointerSize, |
1558 1, | 1558 1, |
1559 52, | 1559 53, |
1560 { | 1560 { |
1561 B(Ldar), R(Register::function_closure().index()), // | 1561 B(Ldar), R(Register::function_closure().index()), // |
1562 B(Star), R(2), // | 1562 B(Star), R(2), // |
1563 B(LdaConstant), U8(0), // | 1563 B(LdaConstant), U8(0), // |
1564 B(Star), R(3), // | 1564 B(Star), R(3), // |
1565 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | 1565 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // |
1566 B(PushContext), R(1), // | 1566 B(PushContext), R(1), // |
1567 B(LdaConstant), U8(1), // | 1567 B(LdaConstant), U8(1), // |
1568 B(Star), R(2), // | 1568 B(Star), R(2), // |
1569 B(LdaZero), // | 1569 B(LdaZero), // |
1570 B(Star), R(3), // | 1570 B(Star), R(3), // |
1571 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | 1571 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // |
1572 B(LdaConstant), U8(2), // | 1572 B(LdaConstant), U8(2), // |
1573 B(Star), R(2), // | 1573 B(Star), R(2), // |
1574 B(LdaZero), // | 1574 B(LdaZero), // |
1575 B(Star), R(3), // | 1575 B(Star), R(3), // |
1576 B(LdaSmi8), U8(1), // | 1576 B(LdaSmi8), U8(1), // |
1577 B(Star), R(4), // | 1577 B(Star), R(4), // |
1578 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // | 1578 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // |
1579 U8(3), // | 1579 U8(3), // |
1580 B(LdaSmi8), U8(2), // | 1580 B(LdaSmi8), U8(2), // |
1581 B(StaGlobalSloppy), _, // | 1581 B(StaGlobalSloppy), _, _, // |
1582 B(Star), R(0), // | 1582 B(Star), R(0), // |
1583 B(Ldar), R(0), // | 1583 B(Ldar), R(0), // |
1584 B(Return) // | 1584 B(Return) // |
1585 }, | 1585 }, |
1586 -1}, | 1586 -1}, |
1587 {"function f() {}\nf();", | 1587 {"function f() {}\nf();", |
1588 4 * kPointerSize, | 1588 4 * kPointerSize, |
1589 1, | 1589 1, |
1590 43, | 1590 44, |
1591 { | 1591 { |
1592 B(Ldar), R(Register::function_closure().index()), // | 1592 B(Ldar), R(Register::function_closure().index()), // |
1593 B(Star), R(2), // | 1593 B(Star), R(2), // |
1594 B(LdaConstant), U8(0), // | 1594 B(LdaConstant), U8(0), // |
1595 B(Star), R(3), // | 1595 B(Star), R(3), // |
1596 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | 1596 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // |
1597 B(PushContext), R(1), // | 1597 B(PushContext), R(1), // |
1598 B(LdaConstant), U8(1), // | 1598 B(LdaConstant), U8(1), // |
1599 B(Star), R(2), // | 1599 B(Star), R(2), // |
1600 B(LdaZero), // | 1600 B(LdaZero), // |
1601 B(Star), R(3), // | 1601 B(Star), R(3), // |
1602 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | 1602 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // |
1603 B(LdaUndefined), // | 1603 B(LdaUndefined), // |
1604 B(Star), R(3), // | 1604 B(Star), R(3), // |
1605 B(LdaGlobal), _, // | 1605 B(LdaGlobal), _, _, // |
1606 B(Star), R(2), // | 1606 B(Star), R(2), // |
1607 B(Call), R(2), R(3), U8(0), // | 1607 B(Call), R(2), R(3), U8(0), // |
1608 B(Star), R(0), // | 1608 B(Star), R(0), // |
1609 B(Ldar), R(0), // | 1609 B(Ldar), R(0), // |
1610 B(Return) // | 1610 B(Return) // |
1611 }, | 1611 }, |
1612 -1}, | 1612 -1}, |
1613 }; | 1613 }; |
1614 | 1614 |
1615 for (size_t i = 0; i < arraysize(snippets); i++) { | 1615 for (size_t i = 0; i < arraysize(snippets); i++) { |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2678 for (size_t i = 0; i < arraysize(snippets); i++) { | 2678 for (size_t i = 0; i < arraysize(snippets); i++) { |
2679 Handle<BytecodeArray> bytecode_array = | 2679 Handle<BytecodeArray> bytecode_array = |
2680 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2680 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2681 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2681 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2682 } | 2682 } |
2683 } | 2683 } |
2684 | 2684 |
2685 } // namespace interpreter | 2685 } // namespace interpreter |
2686 } // namespace internal | 2686 } // namespace internal |
2687 } // namespace v8 | 2687 } // namespace v8 |
OLD | NEW |