| 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 2170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2181 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 2181 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
| 2182 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2182 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2183 } | 2183 } |
| 2184 } | 2184 } |
| 2185 | 2185 |
| 2186 | 2186 |
| 2187 TEST(BreakableBlocks) { | 2187 TEST(BreakableBlocks) { |
| 2188 InitializedHandleScope handle_scope; | 2188 InitializedHandleScope handle_scope; |
| 2189 BytecodeGeneratorHelper helper; | 2189 BytecodeGeneratorHelper helper; |
| 2190 | 2190 |
| 2191 ExpectedSnippet<int> snippets[] = { | 2191 int closure = Register::function_closure().index(); |
| 2192 int context = Register::function_context().index(); |
| 2193 |
| 2194 ExpectedSnippet<InstanceType> snippets[] = { |
| 2192 {"var x = 0;\n" | 2195 {"var x = 0;\n" |
| 2193 "label: {\n" | 2196 "label: {\n" |
| 2194 " x = x + 1;\n" | 2197 " x = x + 1;\n" |
| 2195 " break label;\n" | 2198 " break label;\n" |
| 2196 " x = x + 1;\n" | 2199 " x = x + 1;\n" |
| 2197 "}\n" | 2200 "}\n" |
| 2198 "return x;", | 2201 "return x;", |
| 2199 2 * kPointerSize, | 2202 2 * kPointerSize, |
| 2200 1, | 2203 1, |
| 2201 16, | 2204 16, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 B(Star), R(2), // | 2262 B(Star), R(2), // |
| 2260 B(Jump), U8(-40), // | 2263 B(Jump), U8(-40), // |
| 2261 B(Ldar), R(1), // | 2264 B(Ldar), R(1), // |
| 2262 B(ToNumber), // | 2265 B(ToNumber), // |
| 2263 B(Inc), // | 2266 B(Inc), // |
| 2264 B(Star), R(1), // | 2267 B(Star), R(1), // |
| 2265 B(Jump), U8(-61), // | 2268 B(Jump), U8(-61), // |
| 2266 B(Ldar), R(0), // | 2269 B(Ldar), R(0), // |
| 2267 B(Return), // | 2270 B(Return), // |
| 2268 }}, | 2271 }}, |
| 2272 {"outer: {\n" |
| 2273 " let y = 10;" |
| 2274 " function f() { return y; }\n" |
| 2275 " break outer;\n" |
| 2276 "}\n", |
| 2277 5 * kPointerSize, |
| 2278 1, |
| 2279 39, |
| 2280 { |
| 2281 B(LdaConstant), U8(0), // |
| 2282 B(Star), R(3), // |
| 2283 B(Ldar), R(closure), // |
| 2284 B(Star), R(4), // |
| 2285 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // |
| 2286 B(PushContext), R(2), // |
| 2287 B(LdaTheHole), // |
| 2288 B(StaContextSlot), R(2), U8(4), // |
| 2289 B(CreateClosure), U8(1), U8(0), // |
| 2290 B(Star), R(0), // |
| 2291 B(LdaSmi8), U8(10), // |
| 2292 B(StaContextSlot), R(2), U8(4), // |
| 2293 B(Ldar), R(0), // |
| 2294 B(Star), R(1), // |
| 2295 B(Jump), U8(2), // |
| 2296 B(PopContext), R(context), // |
| 2297 B(LdaUndefined), // |
| 2298 B(Return), // |
| 2299 }, |
| 2300 2, |
| 2301 {InstanceType::FIXED_ARRAY_TYPE, |
| 2302 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2269 }; | 2303 }; |
| 2270 | 2304 |
| 2271 for (size_t i = 0; i < arraysize(snippets); i++) { | 2305 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2272 Handle<BytecodeArray> bytecode_array = | 2306 Handle<BytecodeArray> bytecode_array = |
| 2273 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2307 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 2274 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2308 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2275 } | 2309 } |
| 2276 } | 2310 } |
| 2277 | 2311 |
| 2278 | 2312 |
| (...skipping 4448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6727 std::string(function_epilogue); | 6761 std::string(function_epilogue); |
| 6728 Handle<BytecodeArray> bytecode_array = | 6762 Handle<BytecodeArray> bytecode_array = |
| 6729 helper.MakeBytecode(script.c_str(), "*", "f"); | 6763 helper.MakeBytecode(script.c_str(), "*", "f"); |
| 6730 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6764 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6731 } | 6765 } |
| 6732 } | 6766 } |
| 6733 | 6767 |
| 6734 } // namespace interpreter | 6768 } // namespace interpreter |
| 6735 } // namespace internal | 6769 } // namespace internal |
| 6736 } // namespace v8 | 6770 } // namespace v8 |
| OLD | NEW |