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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1618693002: [Interpreter] Ensure context is popped when we break or continue (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 11 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
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 2306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 B(Ldar), R(0), // 2317 B(Ldar), R(0), //
2318 B(Star), R(1), // 2318 B(Star), R(1), //
2319 B(Jump), U8(2), // 2319 B(Jump), U8(2), //
2320 B(PopContext), R(context), // 2320 B(PopContext), R(context), //
2321 B(LdaUndefined), // 2321 B(LdaUndefined), //
2322 B(Return), // 2322 B(Return), //
2323 }, 2323 },
2324 2, 2324 2,
2325 {InstanceType::FIXED_ARRAY_TYPE, 2325 {InstanceType::FIXED_ARRAY_TYPE,
2326 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2326 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2327 {"let x = 1;\n"
2328 "outer: {\n"
2329 " inner: {\n"
2330 " let y = 2;\n"
2331 " function f() { return x + y; }\n"
2332 " if (y) break outer;\n"
2333 " y = 3;\n"
2334 " }\n"
2335 "}\n"
2336 "x = 4;",
2337 6 * kPointerSize,
2338 1,
2339 72,
2340 {
2341 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
2342 U8(1), //
2343 B(PushContext), R(2), //
2344 B(LdaTheHole), //
2345 B(StaContextSlot), R(2), U8(4), //
2346 B(LdaSmi8), U8(1), //
2347 B(StaContextSlot), R(2), U8(4), //
2348 B(LdaConstant), U8(0), //
2349 B(Star), R(4), //
2350 B(Ldar), R(closure), //
2351 B(Star), R(5), //
2352 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
2353 B(PushContext), R(3), //
2354 B(LdaTheHole), //
2355 B(StaContextSlot), R(3), U8(4), //
2356 B(CreateClosure), U8(1), U8(0), //
2357 B(Star), R(0), //
2358 B(LdaSmi8), U8(2), //
2359 B(StaContextSlot), R(3), U8(4), //
2360 B(Ldar), R(0), //
2361 B(Star), R(1), //
2362 B(LdaContextSlot), R(3), U8(4), //
2363 B(JumpIfToBooleanFalse), U8(6), //
2364 B(PopContext), R(2), //
2365 B(Jump), U8(9), //
2366 B(LdaSmi8), U8(3), //
2367 B(StaContextSlot), R(3), U8(4), //
2368 B(PopContext), R(2), //
2369 B(LdaSmi8), U8(4), //
2370 B(StaContextSlot), R(2), U8(4), //
2371 B(LdaUndefined), //
2372 B(Return), //
2373 },
2374 2,
2375 {InstanceType::FIXED_ARRAY_TYPE,
2376 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2327 }; 2377 };
2328 2378
2329 for (size_t i = 0; i < arraysize(snippets); i++) { 2379 for (size_t i = 0; i < arraysize(snippets); i++) {
2330 Handle<BytecodeArray> bytecode_array = 2380 Handle<BytecodeArray> bytecode_array =
2331 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2381 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2332 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2382 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2333 } 2383 }
2334 } 2384 }
2335 2385
2336 2386
2337 TEST(BasicLoops) { 2387 TEST(BasicLoops) {
2338 InitializedHandleScope handle_scope; 2388 InitializedHandleScope handle_scope;
2339 BytecodeGeneratorHelper helper; 2389 BytecodeGeneratorHelper helper;
2340 2390
2341 ExpectedSnippet<int> snippets[] = { 2391 int closure = Register::function_closure().index();
2392 int context = Register::function_context().index();
2393
2394 ExpectedSnippet<InstanceType> snippets[] = {
2342 {"var x = 0;\n" 2395 {"var x = 0;\n"
2343 "while (false) { x = 99; break; continue; }\n" 2396 "while (false) { x = 99; break; continue; }\n"
2344 "return x;", 2397 "return x;",
2345 1 * kPointerSize, 2398 1 * kPointerSize,
2346 1, 2399 1,
2347 4, 2400 4,
2348 { 2401 {
2349 B(LdaZero), // 2402 B(LdaZero), //
2350 B(Star), R(0), // 2403 B(Star), R(0), //
2351 B(Return) // 2404 B(Return) //
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 B(Jump), U8(10), // 2996 B(Jump), U8(10), //
2944 B(Ldar), R(1), // 2997 B(Ldar), R(1), //
2945 B(ToNumber), // 2998 B(ToNumber), //
2946 B(Inc), // 2999 B(Inc), //
2947 B(Star), R(1), // 3000 B(Star), R(1), //
2948 B(Jump), U8(-26), // 3001 B(Jump), U8(-26), //
2949 B(Ldar), R(0), // 3002 B(Ldar), R(0), //
2950 B(Return), // 3003 B(Return), //
2951 }, 3004 },
2952 0}, 3005 0},
3006 {"var a = 0;\n"
3007 "while (a) {\n"
3008 " { \n"
3009 " let z = 1;\n"
3010 " function f() { z = 2; }\n"
3011 " if (z) continue;\n"
3012 " z++;\n"
3013 " }\n"
3014 "}\n",
3015 6 * kPointerSize,
3016 1,
3017 65,
3018 {
3019 B(LdaZero), //
3020 B(Star), R(1), //
3021 B(Ldar), R(1), //
3022 B(JumpIfToBooleanFalse), U8(58), //
3023 B(LdaConstant), U8(0), //
3024 B(Star), R(4), //
3025 B(Ldar), R(closure), //
3026 B(Star), R(5), //
3027 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
3028 B(PushContext), R(3), //
3029 B(LdaTheHole), //
3030 B(StaContextSlot), R(3), U8(4), //
3031 B(CreateClosure), U8(1), U8(0), //
3032 B(Star), R(0), //
3033 B(LdaSmi8), U8(1), //
3034 B(StaContextSlot), R(3), U8(4), //
3035 B(Ldar), R(0), //
3036 B(Star), R(2), //
3037 B(LdaContextSlot), R(3), U8(4), //
3038 B(JumpIfToBooleanFalse), U8(6), //
3039 B(PopContext), R(context), //
3040 B(Jump), U8(-44), //
3041 B(LdaContextSlot), R(3), U8(4), //
3042 B(ToNumber), //
3043 B(Star), R(4), //
3044 B(Inc), //
3045 B(StaContextSlot), R(3), U8(4), //
3046 B(PopContext), R(context), //
3047 B(Jump), U8(-58), //
3048 B(LdaUndefined), //
3049 B(Return), //
3050 },
3051 2,
3052 {InstanceType::FIXED_ARRAY_TYPE,
3053 InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2953 }; 3054 };
2954 3055
2955 for (size_t i = 0; i < arraysize(snippets); i++) { 3056 for (size_t i = 0; i < arraysize(snippets); i++) {
2956 Handle<BytecodeArray> bytecode_array = 3057 Handle<BytecodeArray> bytecode_array =
2957 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3058 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2958 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3059 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2959 } 3060 }
2960 } 3061 }
2961 3062
2962 3063
(...skipping 3933 matching lines...) Expand 10 before | Expand all | Expand 10 after
6896 std::string(function_epilogue); 6997 std::string(function_epilogue);
6897 Handle<BytecodeArray> bytecode_array = 6998 Handle<BytecodeArray> bytecode_array =
6898 helper.MakeBytecode(script.c_str(), "*", "f"); 6999 helper.MakeBytecode(script.c_str(), "*", "f");
6899 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 7000 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6900 } 7001 }
6901 } 7002 }
6902 7003
6903 } // namespace interpreter 7004 } // namespace interpreter
6904 } // namespace internal 7005 } // namespace internal
6905 } // namespace v8 7006 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698