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 8992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9003 }; | 9003 }; |
9004 // clang-format on | 9004 // clang-format on |
9005 | 9005 |
9006 Handle<BytecodeArray> bytecode_array = | 9006 Handle<BytecodeArray> bytecode_array = |
9007 helper.MakeBytecodeForFunctionBody(snippet.code_snippet); | 9007 helper.MakeBytecodeForFunctionBody(snippet.code_snippet); |
9008 CheckBytecodeArrayEqual(snippet, bytecode_array); | 9008 CheckBytecodeArrayEqual(snippet, bytecode_array); |
9009 } | 9009 } |
9010 | 9010 |
9011 // TODO(rmcilroy): Update expectations after switch to | 9011 // TODO(rmcilroy): Update expectations after switch to |
9012 // Runtime::kDefineDataPropertyInLiteral. | 9012 // Runtime::kDefineDataPropertyInLiteral. |
9013 DISABLED_TEST(ClassDeclarations) { | 9013 TEST(ClassDeclarations) { |
9014 InitializedHandleScope handle_scope; | 9014 InitializedHandleScope handle_scope; |
9015 BytecodeGeneratorHelper helper; | 9015 BytecodeGeneratorHelper helper; |
9016 | 9016 |
9017 int closure = Register::function_closure().index(); | 9017 int closure = Register::function_closure().index(); |
9018 int context = Register::current_context().index(); | 9018 int context = Register::current_context().index(); |
9019 | 9019 |
9020 // clang-format off | 9020 // clang-format off |
9021 ExpectedSnippet<InstanceType, 12> snippets[] = { | 9021 ExpectedSnippet<InstanceType, 12> snippets[] = { |
9022 {"class Person {\n" | 9022 {"class Person {\n" |
9023 " constructor(name) { this.name = name; }\n" | 9023 " constructor(name) { this.name = name; }\n" |
9024 " speak() { console.log(this.name + ' is speaking.'); }\n" | 9024 " speak() { console.log(this.name + ' is speaking.'); }\n" |
9025 "}\n", | 9025 "}\n", |
9026 8 * kPointerSize, | 9026 9 * kPointerSize, |
9027 1, | 9027 1, |
9028 61, | 9028 71, |
9029 { | 9029 { |
9030 B(LdaTheHole), // | 9030 B(LdaTheHole), // |
9031 B(Star), R(1), // | 9031 B(Star), R(1), // |
9032 B(StackCheck), // | 9032 B(StackCheck), // |
9033 B(LdaTheHole), // | 9033 B(LdaTheHole), // |
9034 B(Star), R(0), // | 9034 B(Star), R(0), // |
9035 B(LdaTheHole), // | 9035 B(LdaTheHole), // |
9036 B(Star), R(2), // | 9036 B(Star), R(2), // |
9037 B(CreateClosure), U8(0), U8(0), // | 9037 B(CreateClosure), U8(0), U8(0), // |
9038 B(Star), R(3), // | 9038 B(Star), R(3), // |
9039 B(LdaSmi8), U8(15), // | 9039 B(LdaSmi8), U8(15), // |
9040 B(Star), R(4), // | 9040 B(Star), R(4), // |
9041 B(LdaConstant), U8(1), // | 9041 B(LdaConstant), U8(1), // |
9042 B(Star), R(5), // | 9042 B(Star), R(5), // |
9043 B(CallRuntime), U16(Runtime::kDefineClass), R(2), U8(4), // | 9043 B(CallRuntime), U16(Runtime::kDefineClass), R(2), U8(4), // |
9044 B(Star), R(2), // | 9044 B(Star), R(2), // |
9045 B(LoadICSloppy), // | 9045 B(LoadICSloppy), R(2), U8(2), U8(1), // |
9046 B(Star), R(3), // | 9046 B(Star), R(3), // |
9047 B(Mov), R(3), R(4), // | 9047 B(Mov), R(3), R(4), // |
9048 B(LdaConstant), U8(2), // | 9048 B(LdaConstant), U8(3), // |
9049 B(Star), R(5), // | 9049 B(Star), R(5), // |
9050 B(CreateClosure), U8(3), U8(0), // | 9050 B(CreateClosure), U8(4), U8(0), // |
9051 B(Star), R(6), // | 9051 B(Star), R(6), // |
9052 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(4), U8(3), | 9052 B(LdaSmi8), U8(2), // |
| 9053 B(Star), R(7), // |
| 9054 B(LdaZero), // |
| 9055 B(Star), R(8), // |
| 9056 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(4), U8(5), |
9053 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(2), U8(2), // | 9057 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(2), U8(2), // |
9054 B(Star), R(0), // | 9058 B(Star), R(0), // |
9055 B(Star), R(1), // | 9059 B(Star), R(1), // |
9056 B(LdaUndefined), // | 9060 B(LdaUndefined), // |
9057 B(Return) // | 9061 B(Return) // |
9058 }, | 9062 }, |
9059 4, | 9063 5, |
9060 { InstanceType::SHARED_FUNCTION_INFO_TYPE, kInstanceTypeDontCare, | 9064 { InstanceType::SHARED_FUNCTION_INFO_TYPE, kInstanceTypeDontCare, |
9061 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 9065 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 9066 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
9062 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 9067 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
9063 {"class person {\n" | 9068 {"class person {\n" |
9064 " constructor(name) { this.name = name; }\n" | 9069 " constructor(name) { this.name = name; }\n" |
9065 " speak() { console.log(this.name + ' is speaking.'); }\n" | 9070 " speak() { console.log(this.name + ' is speaking.'); }\n" |
9066 "}\n", | 9071 "}\n", |
9067 8 * kPointerSize, | 9072 9 * kPointerSize, |
9068 1, | 9073 1, |
9069 61, | 9074 71, |
9070 { | 9075 { |
9071 B(LdaTheHole), // | 9076 B(LdaTheHole), // |
9072 B(Star), R(1), // | 9077 B(Star), R(1), // |
9073 B(StackCheck), // | 9078 B(StackCheck), // |
9074 B(LdaTheHole), // | 9079 B(LdaTheHole), // |
9075 B(Star), R(0), // | 9080 B(Star), R(0), // |
9076 B(LdaTheHole), // | 9081 B(LdaTheHole), // |
9077 B(Star), R(2), // | 9082 B(Star), R(2), // |
9078 B(CreateClosure), U8(0), U8(0), // | 9083 B(CreateClosure), U8(0), U8(0), // |
9079 B(Star), R(3), // | 9084 B(Star), R(3), // |
9080 B(LdaSmi8), U8(15), // | 9085 B(LdaSmi8), U8(15), // |
9081 B(Star), R(4), // | 9086 B(Star), R(4), // |
9082 B(LdaConstant), U8(1), // | 9087 B(LdaConstant), U8(1), // |
9083 B(Star), R(5), // | 9088 B(Star), R(5), // |
9084 B(CallRuntime), U16(Runtime::kDefineClass), R(2), U8(4), // | 9089 B(CallRuntime), U16(Runtime::kDefineClass), R(2), U8(4), // |
9085 B(Star), R(2), // | 9090 B(Star), R(2), // |
9086 B(LoadICSloppy), // | 9091 B(LoadICSloppy), R(2), U8(2), U8(1), // |
9087 B(Star), R(3), // | 9092 B(Star), R(3), // |
9088 B(Mov), R(3), R(4), // | 9093 B(Mov), R(3), R(4), // |
9089 B(LdaConstant), U8(2), // | 9094 B(LdaConstant), U8(3), // |
9090 B(Star), R(5), // | 9095 B(Star), R(5), // |
9091 B(CreateClosure), U8(3), U8(0), // | 9096 B(CreateClosure), U8(4), U8(0), // |
9092 B(Star), R(6), // | 9097 B(Star), R(6), // |
9093 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(4), U8(3), | 9098 B(LdaSmi8), U8(2), // |
| 9099 B(Star), R(7), // |
| 9100 B(LdaZero), // |
| 9101 B(Star), R(8), // |
| 9102 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(4), U8(5), |
9094 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(2), U8(2), // | 9103 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(2), U8(2), // |
9095 B(Star), R(0), // | 9104 B(Star), R(0), // |
9096 B(Star), R(1), // | 9105 B(Star), R(1), // |
9097 B(LdaUndefined), // | 9106 B(LdaUndefined), // |
9098 B(Return) // | 9107 B(Return) // |
9099 }, | 9108 }, |
9100 4, | 9109 5, |
9101 { InstanceType::SHARED_FUNCTION_INFO_TYPE, kInstanceTypeDontCare, | 9110 { InstanceType::SHARED_FUNCTION_INFO_TYPE, kInstanceTypeDontCare, |
9102 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 9111 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 9112 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
9103 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 9113 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
9104 {"var n0 = 'a';" | 9114 {"var n0 = 'a';" |
9105 "var n1 = 'b';" | 9115 "var n1 = 'b';" |
9106 "class N {\n" | 9116 "class N {\n" |
9107 " [n0]() { return n0; }\n" | 9117 " [n0]() { return n0; }\n" |
9108 " static [n1]() { return n1; }\n" | 9118 " static [n1]() { return n1; }\n" |
9109 "}\n", | 9119 "}\n", |
9110 9 * kPointerSize, | 9120 10 * kPointerSize, |
9111 1, | 9121 1, |
9112 110, | 9122 125, |
9113 { | 9123 { |
9114 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 9124 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
9115 /* */ U8(1), // | 9125 /* */ U8(1), // |
9116 B(PushContext), R(2), // | 9126 B(PushContext), R(2), // |
9117 B(LdaTheHole), // | 9127 B(LdaTheHole), // |
9118 B(Star), R(1), // | 9128 B(Star), R(1), // |
9119 B(StackCheck), // | 9129 B(StackCheck), // |
9120 B(LdaConstant), U8(0), // | 9130 B(LdaConstant), U8(0), // |
9121 B(StaContextSlot), R(context), U8(4), // | 9131 B(StaContextSlot), R(context), U8(4), // |
9122 B(LdaConstant), U8(1), // | 9132 B(LdaConstant), U8(1), // |
9123 B(StaContextSlot), R(context), U8(5), // | 9133 B(StaContextSlot), R(context), U8(5), // |
9124 B(LdaTheHole), // | 9134 B(LdaTheHole), // |
9125 B(Star), R(0), // | 9135 B(Star), R(0), // |
9126 B(LdaTheHole), // | 9136 B(LdaTheHole), // |
9127 B(Star), R(3), // | 9137 B(Star), R(3), // |
9128 B(CreateClosure), U8(2), U8(0), // | 9138 B(CreateClosure), U8(2), U8(0), // |
9129 B(Star), R(4), // | 9139 B(Star), R(4), // |
9130 B(LdaSmi8), U8(41), // | 9140 B(LdaSmi8), U8(41), // |
9131 B(Star), R(5), // | 9141 B(Star), R(5), // |
9132 B(LdaSmi8), U8(107), // | 9142 B(LdaSmi8), U8(107), // |
9133 B(Star), R(6), // | 9143 B(Star), R(6), // |
9134 B(CallRuntime), U16(Runtime::kDefineClass), R(3), U8(4), // | 9144 B(CallRuntime), U16(Runtime::kDefineClass), R(3), U8(4), // |
9135 B(Star), R(3), // | 9145 B(Star), R(3), // |
9136 B(LoadICSloppy), // | 9146 B(LoadICSloppy), R(3), U8(3), U8(1), // |
9137 B(Star), R(4), // | 9147 B(Star), R(4), // |
9138 B(Mov), R(4), R(5), // | 9148 B(Mov), R(4), R(5), // |
9139 B(LdaContextSlot), R(context), U8(4), // | 9149 B(LdaContextSlot), R(context), U8(4), // |
9140 B(ToName), // | 9150 B(ToName), // |
9141 B(Star), R(6), // | 9151 B(Star), R(6), // |
9142 B(CreateClosure), U8(3), U8(0), // | 9152 B(CreateClosure), U8(4), U8(0), // |
9143 B(Star), R(7), // | 9153 B(Star), R(7), // |
9144 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(5), U8(3), | 9154 B(LdaSmi8), U8(2), // |
| 9155 B(Star), R(8), // |
| 9156 B(LdaSmi8), U8(1), // |
| 9157 B(Star), R(9), // |
| 9158 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(5), U8(5), |
9145 B(Mov), R(3), R(5), // | 9159 B(Mov), R(3), R(5), // |
9146 B(LdaContextSlot), R(context), U8(5), // | 9160 B(LdaContextSlot), R(context), U8(5), // |
9147 B(ToName), // | 9161 B(ToName), // |
9148 B(Star), R(6), // | 9162 B(Star), R(6), // |
9149 B(LdaConstant), U8(4), // | 9163 B(LdaConstant), U8(3), // |
9150 B(TestEqualStrict), R(6), // | 9164 B(TestEqualStrict), R(6), // |
9151 B(JumpIfFalse), U8(7), // | 9165 B(JumpIfFalse), U8(7), // |
9152 B(CallRuntime), U16(Runtime::kThrowStaticPrototypeError), // | 9166 B(CallRuntime), U16(Runtime::kThrowStaticPrototypeError), // |
9153 /* */ R(0), U8(0), // | 9167 /* */ R(0), U8(0), // |
9154 B(CreateClosure), U8(5), U8(0), // | 9168 B(CreateClosure), U8(5), U8(0), // |
9155 B(Star), R(7), // | 9169 B(Star), R(7), // |
9156 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(5), U8(3), | 9170 B(LdaSmi8), U8(1), // |
| 9171 B(Star), R(9), // |
| 9172 B(CallRuntime), U16(Runtime::kDefineDataPropertyInLiteral), R(5), U8(5), |
9157 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(3), U8(2), // | 9173 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(3), U8(2), // |
9158 B(Star), R(0), // | 9174 B(Star), R(0), // |
9159 B(Star), R(1), // | 9175 B(Star), R(1), // |
9160 B(LdaUndefined), // | 9176 B(LdaUndefined), // |
9161 B(Return), // | 9177 B(Return), // |
9162 }, | 9178 }, |
9163 6, | 9179 6, |
9164 { InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 9180 { InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
9165 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | 9181 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
9166 InstanceType::SHARED_FUNCTION_INFO_TYPE, | 9182 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 9183 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
9167 InstanceType::SHARED_FUNCTION_INFO_TYPE, | 9184 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
9168 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | |
9169 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 9185 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
9170 {"var count = 0;\n" | 9186 {"var count = 0;\n" |
9171 "class C { constructor() { count++; }}\n" | 9187 "class C { constructor() { count++; }}\n" |
9172 "return new C();\n", | 9188 "return new C();\n", |
9173 9 * kPointerSize, | 9189 10 * kPointerSize, |
9174 1, | 9190 1, |
9175 60, | 9191 74, |
9176 { | 9192 { |
9177 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), U8(1), // | 9193 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), U8(1), // |
9178 B(PushContext), R(2), // | 9194 B(PushContext), R(2), // |
9179 B(LdaTheHole), // | 9195 B(LdaTheHole), // |
9180 B(Star), R(1), // | 9196 B(Star), R(1), // |
9181 B(StackCheck), // | 9197 B(StackCheck), // |
9182 B(LdaZero), // | 9198 B(LdaZero), // |
9183 B(StaContextSlot), R(context), U8(4), // | 9199 B(StaContextSlot), R(context), U8(4), // |
9184 B(LdaTheHole), // | 9200 B(LdaTheHole), // |
9185 B(Star), R(0), // | 9201 B(Star), R(0), // |
9186 B(LdaTheHole), // | 9202 B(LdaTheHole), // |
9187 B(Star), R(3), // | 9203 B(Star), R(3), // |
9188 B(CreateClosure), U8(0), U8(0), // | 9204 B(CreateClosure), U8(0), U8(0), // |
9189 B(Star), R(4), // | 9205 B(Star), R(4), // |
9190 B(LdaSmi8), U8(30), // | 9206 B(LdaSmi8), U8(30), // |
9191 B(Star), R(5), // | 9207 B(Star), R(5), // |
9192 B(LdaSmi8), U8(67), // | 9208 B(LdaSmi8), U8(67), // |
9193 B(Star), R(6), // | 9209 B(Star), R(6), // |
9194 B(CallRuntime), U16(Runtime::kDefineClass), R(3), U8(4), // | 9210 B(CallRuntime), U16(Runtime::kDefineClass), R(3), U8(4), // |
9195 B(Star), R(3), // | 9211 B(Star), R(3), // |
9196 B(LoadICSloppy), // | 9212 B(LoadICSloppy), R(3), U8(1), U8(1), // |
9197 B(Star), R(4), // | 9213 B(Star), R(4), // |
9198 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(3), U8(2), // | 9214 B(CallRuntime), U16(Runtime::kFinalizeClassDefinition), R(3), U8(2), // |
9199 B(Star), R(0), // | 9215 B(Star), R(0), // |
9200 B(Star), R(1), // | 9216 B(Star), R(1), // |
| 9217 B(JumpIfNotHole), U8(11), // |
| 9218 B(LdaConstant), U8(2), // |
| 9219 B(Star), R(4), // |
| 9220 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
9201 B(Star), R(3), // | 9221 B(Star), R(3), // |
9202 B(New), R(3), R(0), U8(0), // | 9222 B(New), R(3), R(0), U8(0), // |
9203 B(Return), // | 9223 B(Return), // |
9204 }, | 9224 }, |
9205 1, | 9225 3, |
9206 { InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 9226 { InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 9227 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 9228 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
9207 }; | 9229 }; |
9208 // clang-format on | 9230 // clang-format on |
9209 | 9231 |
9210 for (size_t i = 0; i < arraysize(snippets); i++) { | 9232 for (size_t i = 0; i < arraysize(snippets); i++) { |
9211 Handle<BytecodeArray> bytecode_array = | 9233 Handle<BytecodeArray> bytecode_array = |
9212 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 9234 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
9213 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 9235 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
9214 } | 9236 } |
9215 } | 9237 } |
9216 | 9238 |
9217 } // namespace interpreter | 9239 } // namespace interpreter |
9218 } // namespace internal | 9240 } // namespace internal |
9219 } // namespace v8 | 9241 } // namespace v8 |
OLD | NEW |