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

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

Issue 1634153002: [Interpreter] Adds support for const/let variables to interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed rebase errors. Created 4 years, 10 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
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"
11 #include "test/cctest/cctest.h" 11 #include "test/cctest/cctest.h"
12 #include "test/cctest/test-feedback-vector.h" 12 #include "test/cctest/test-feedback-vector.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 namespace interpreter { 16 namespace interpreter {
17 17
18 class BytecodeGeneratorHelper { 18 class BytecodeGeneratorHelper {
19 public: 19 public:
20 const char* kFunctionName = "f"; 20 const char* kFunctionName = "f";
21 21
22 static const int kLastParamIndex = 22 static const int kLastParamIndex =
23 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; 23 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
24 24
25 BytecodeGeneratorHelper() { 25 BytecodeGeneratorHelper() {
26 i::FLAG_ignition = true; 26 i::FLAG_ignition = true;
27 i::FLAG_ignition_filter = StrDup(kFunctionName); 27 i::FLAG_ignition_filter = StrDup(kFunctionName);
28 i::FLAG_always_opt = false; 28 i::FLAG_always_opt = false;
29 i::FLAG_allow_natives_syntax = true; 29 i::FLAG_allow_natives_syntax = true;
30 i::FLAG_legacy_const = true;
31 CcTest::i_isolate()->interpreter()->Initialize(); 30 CcTest::i_isolate()->interpreter()->Initialize();
32 } 31 }
33 32
34 Isolate* isolate() { return CcTest::i_isolate(); } 33 Isolate* isolate() { return CcTest::i_isolate(); }
35 Factory* factory() { return CcTest::i_isolate()->factory(); } 34 Factory* factory() { return CcTest::i_isolate()->factory(); }
36 35
37 Handle<BytecodeArray> MakeTopLevelBytecode(const char* source) { 36 Handle<BytecodeArray> MakeTopLevelBytecode(const char* source) {
38 const char* old_ignition_filter = i::FLAG_ignition_filter; 37 const char* old_ignition_filter = i::FLAG_ignition_filter;
39 i::FLAG_ignition_filter = "*"; 38 i::FLAG_ignition_filter = "*";
40 Local<v8::Script> script = v8_compile(source); 39 Local<v8::Script> script = v8_compile(source);
(...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 B(Ldar), R(0), // 2283 B(Ldar), R(0), //
2285 B(Return), // 2284 B(Return), //
2286 }}, 2285 }},
2287 {"outer: {\n" 2286 {"outer: {\n"
2288 " let y = 10;" 2287 " let y = 10;"
2289 " function f() { return y; }\n" 2288 " function f() { return y; }\n"
2290 " break outer;\n" 2289 " break outer;\n"
2291 "}\n", 2290 "}\n",
2292 5 * kPointerSize, 2291 5 * kPointerSize,
2293 1, 2292 1,
2294 39, 2293 50,
2295 { 2294 {
2296 B(LdaConstant), U8(0), // 2295 B(LdaConstant), U8(0), //
2297 B(Star), R(3), // 2296 B(Star), R(3), //
2298 B(Ldar), R(closure), // 2297 B(Ldar), R(closure), //
2299 B(Star), R(4), // 2298 B(Star), R(4), //
2300 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // 2299 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), //
2301 B(PushContext), R(2), // 2300 B(PushContext), R(2), //
2302 B(LdaTheHole), // 2301 B(LdaTheHole), //
2303 B(StaContextSlot), R(context), U8(4), // 2302 B(StaContextSlot), R(context), U8(4), //
2304 B(CreateClosure), U8(1), U8(0), // 2303 B(CreateClosure), U8(1), U8(0), //
2305 B(Star), R(0), // 2304 B(Star), R(0), //
2306 B(LdaSmi8), U8(10), // 2305 B(LdaSmi8), U8(10), //
2307 B(StaContextSlot), R(context), U8(4), // 2306 B(StaContextSlot), R(context), U8(4), //
2308 B(Ldar), R(0), // 2307 B(Ldar), R(0), //
2309 B(Star), R(1), // 2308 B(JumpIfNotHole), U8(11), //
2310 B(Jump), U8(2), // 2309 B(LdaConstant), U8(2), //
2311 B(PopContext), R(2), // 2310 B(Star), R(3), //
2312 B(LdaUndefined), // 2311 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
2313 B(Return), // 2312 B(Star), R(1), //
2313 B(Jump), U8(2), //
2314 B(PopContext), R(2), //
2315 B(LdaUndefined), //
2316 B(Return), //
2314 }, 2317 },
2315 2, 2318 3,
2316 {InstanceType::FIXED_ARRAY_TYPE, 2319 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
2317 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2320 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2318 {"let x = 1;\n" 2321 {"let x = 1;\n"
2319 "outer: {\n" 2322 "outer: {\n"
2320 " inner: {\n" 2323 " inner: {\n"
2321 " let y = 2;\n" 2324 " let y = 2;\n"
2322 " function f() { return x + y; }\n" 2325 " function f() { return x + y; }\n"
2323 " if (y) break outer;\n" 2326 " if (y) break outer;\n"
2324 " y = 3;\n" 2327 " y = 3;\n"
2325 " }\n" 2328 " }\n"
2326 "}\n" 2329 "}\n"
2327 "x = 4;", 2330 "x = 4;",
2328 6 * kPointerSize, 2331 6 * kPointerSize,
2329 1, 2332 1,
2330 72, 2333 130,
2331 { 2334 {
2332 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // 2335 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
2333 U8(1), // 2336 U8(1), //
2334 B(PushContext), R(2), // 2337 B(PushContext), R(2), //
2335 B(LdaTheHole), // 2338 B(LdaTheHole), //
2336 B(StaContextSlot), R(context), U8(4), // 2339 B(StaContextSlot), R(context), U8(4), //
2337 B(LdaSmi8), U8(1), // 2340 B(LdaSmi8), U8(1), //
2338 B(StaContextSlot), R(context), U8(4), // 2341 B(StaContextSlot), R(context), U8(4), //
2339 B(LdaConstant), U8(0), // 2342 B(LdaConstant), U8(0), //
2340 B(Star), R(4), // 2343 B(Star), R(4), //
2341 B(Ldar), R(closure), // 2344 B(Ldar), R(closure), //
2342 B(Star), R(5), // 2345 B(Star), R(5), //
2343 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // 2346 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
2344 B(PushContext), R(3), // 2347 B(PushContext), R(3), //
2345 B(LdaTheHole), // 2348 B(LdaTheHole), //
2346 B(StaContextSlot), R(context), U8(4), // 2349 B(StaContextSlot), R(context), U8(4), //
2347 B(CreateClosure), U8(1), U8(0), // 2350 B(CreateClosure), U8(1), U8(0), //
2348 B(Star), R(0), // 2351 B(Star), R(0), //
2349 B(LdaSmi8), U8(2), // 2352 B(LdaSmi8), U8(2), //
2350 B(StaContextSlot), R(context), U8(4), // 2353 B(StaContextSlot), R(context), U8(4), //
2351 B(Ldar), R(0), // 2354 B(Ldar), R(0), //
2352 B(Star), R(1), // 2355 B(JumpIfNotHole), U8(11), //
2353 B(LdaContextSlot), R(context), U8(4), // 2356 B(LdaConstant), U8(2), //
2354 B(JumpIfToBooleanFalse), U8(6), // 2357 B(Star), R(4), //
2355 B(PopContext), R(3), // 2358 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
2356 B(Jump), U8(9), // 2359 B(Star), R(1), //
2357 B(LdaSmi8), U8(3), // 2360 B(LdaContextSlot), R(context), U8(4), //
2358 B(StaContextSlot), R(context), U8(4), // 2361 B(JumpIfNotHole), U8(11), //
2359 B(PopContext), R(3), // 2362 B(LdaConstant), U8(3), //
2360 B(LdaSmi8), U8(4), // 2363 B(Star), R(4), //
2361 B(StaContextSlot), R(context), U8(4), // 2364 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
2362 B(LdaUndefined), // 2365 B(JumpIfToBooleanFalse), U8(6), //
2363 B(Return), // 2366 B(PopContext), R(3), //
2364 }, 2367 B(Jump), U8(27), //
2365 2, 2368 B(LdaSmi8), U8(3), //
2366 {InstanceType::FIXED_ARRAY_TYPE, 2369 B(Star), R(4), //
2367 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2370 B(LdaContextSlot), R(context), U8(4), //
2371 B(JumpIfNotHole), U8(11), //
2372 B(LdaConstant), U8(3), //
2373 B(Star), R(5), //
2374 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), //
2375 B(Ldar), R(4), //
2376 B(StaContextSlot), R(context), U8(4), //
2377 B(PopContext), R(3), //
2378 B(LdaSmi8), U8(4), //
2379 B(Star), R(4), //
2380 B(LdaContextSlot), R(context), U8(4), //
2381 B(JumpIfNotHole), U8(11), //
2382 B(LdaConstant), U8(4), //
2383 B(Star), R(5), //
2384 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), //
2385 B(Ldar), R(4), //
2386 B(StaContextSlot), R(context), U8(4), //
2387 B(LdaUndefined), //
2388 B(Return), //
2389 },
2390 5,
2391 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
2392 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2393 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2394 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2368 }; 2395 };
2369 2396
2370 for (size_t i = 0; i < arraysize(snippets); i++) { 2397 for (size_t i = 0; i < arraysize(snippets); i++) {
2371 Handle<BytecodeArray> bytecode_array = 2398 Handle<BytecodeArray> bytecode_array =
2372 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2399 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2373 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2400 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2374 } 2401 }
2375 } 2402 }
2376 2403
2377 2404
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2990 B(Inc), // 3017 B(Inc), //
2991 B(Star), R(1), // 3018 B(Star), R(1), //
2992 B(Jump), U8(-26), // 3019 B(Jump), U8(-26), //
2993 B(Ldar), R(0), // 3020 B(Ldar), R(0), //
2994 B(Return), // 3021 B(Return), //
2995 }, 3022 },
2996 0}, 3023 0},
2997 {"var a = 0;\n" 3024 {"var a = 0;\n"
2998 "while (a) {\n" 3025 "while (a) {\n"
2999 " { \n" 3026 " { \n"
3000 " let z = 1;\n" 3027 " let z = 1;\n"
3001 " function f() { z = 2; }\n" 3028 " function f() { z = 2; }\n"
3002 " if (z) continue;\n" 3029 " if (z) continue;\n"
3003 " z++;\n" 3030 " z++;\n"
3004 " }\n" 3031 " }\n"
3005 "}\n", 3032 "}\n",
3006 6 * kPointerSize, 3033 7 * kPointerSize,
3007 1, 3034 1,
3008 65, 3035 116,
3009 { 3036 {
3010 B(LdaZero), // 3037 B(LdaZero), //
3011 B(Star), R(1), // 3038 B(Star), R(1), //
3012 B(Ldar), R(1), // 3039 B(Ldar), R(1), //
3013 B(JumpIfToBooleanFalse), U8(58), // 3040 B(JumpIfToBooleanFalse), U8(109), //
3014 B(LdaConstant), U8(0), // 3041 B(LdaConstant), U8(0), //
3015 B(Star), R(4), // 3042 B(Star), R(4), //
3016 B(Ldar), R(closure), // 3043 B(Ldar), R(closure), //
3017 B(Star), R(5), // 3044 B(Star), R(5), //
3018 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // 3045 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
3019 B(PushContext), R(3), // 3046 B(PushContext), R(3), //
3020 B(LdaTheHole), // 3047 B(LdaTheHole), //
3021 B(StaContextSlot), R(context), U8(4), // 3048 B(StaContextSlot), R(context), U8(4), //
3022 B(CreateClosure), U8(1), U8(0), // 3049 B(CreateClosure), U8(1), U8(0), //
3023 B(Star), R(0), // 3050 B(Star), R(0), //
3024 B(LdaSmi8), U8(1), // 3051 B(LdaSmi8), U8(1), //
3025 B(StaContextSlot), R(context), U8(4), // 3052 B(StaContextSlot), R(context), U8(4), //
3026 B(Ldar), R(0), // 3053 B(Ldar), R(0), //
3027 B(Star), R(2), // 3054 B(JumpIfNotHole), U8(11), //
3028 B(LdaContextSlot), R(context), U8(4), // 3055 B(LdaConstant), U8(2), //
3029 B(JumpIfToBooleanFalse), U8(6), // 3056 B(Star), R(4), //
3030 B(PopContext), R(3), // 3057 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3031 B(Jump), U8(-44), // 3058 B(Star), R(2), //
3032 B(LdaContextSlot), R(context), U8(4), // 3059 B(LdaContextSlot), R(context), U8(4), //
3033 B(ToNumber), // 3060 B(JumpIfNotHole), U8(11), //
3034 B(Star), R(4), // 3061 B(LdaConstant), U8(3), //
3035 B(Inc), // 3062 B(Star), R(4), //
3036 B(StaContextSlot), R(context), U8(4), // 3063 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3037 B(PopContext), R(3), // 3064 B(JumpIfToBooleanFalse), U8(6), //
3038 B(Jump), U8(-58), // 3065 B(PopContext), R(3), //
3039 B(LdaUndefined), // 3066 B(Jump), U8(-66), //
3040 B(Return), // 3067 B(LdaContextSlot), R(context), U8(4), //
3041 }, 3068 B(JumpIfNotHole), U8(11), //
3042 2, 3069 B(LdaConstant), U8(3), //
3043 {InstanceType::FIXED_ARRAY_TYPE, 3070 B(Star), R(4), //
3044 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 3071 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3072 B(ToNumber), //
3073 B(Star), R(4), //
3074 B(Inc), //
3075 B(Star), R(5), //
3076 B(LdaContextSlot), R(context), U8(4), //
3077 B(JumpIfNotHole), U8(11), //
3078 B(LdaConstant), U8(3), //
3079 B(Star), R(6), //
3080 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(6), U8(1), //
3081 B(Ldar), R(5), //
3082 B(StaContextSlot), R(context), U8(4), //
3083 B(PopContext), R(3), //
3084 B(Jump), U8(-109), //
3085 B(LdaUndefined), //
3086 B(Return), //
3087 },
3088 4,
3089 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
3090 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
3091 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3045 }; 3092 };
3046 3093
3047 for (size_t i = 0; i < arraysize(snippets); i++) { 3094 for (size_t i = 0; i < arraysize(snippets); i++) {
3048 Handle<BytecodeArray> bytecode_array = 3095 Handle<BytecodeArray> bytecode_array =
3049 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3096 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3050 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3097 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3051 } 3098 }
3052 } 3099 }
3053 3100
3054 3101
(...skipping 2563 matching lines...) Expand 10 before | Expand all | Expand 10 after
5618 }; 5665 };
5619 5666
5620 for (size_t i = 0; i < arraysize(snippets); i++) { 5667 for (size_t i = 0; i < arraysize(snippets); i++) {
5621 Handle<BytecodeArray> bytecode_array = 5668 Handle<BytecodeArray> bytecode_array =
5622 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 5669 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
5623 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5670 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5624 } 5671 }
5625 } 5672 }
5626 5673
5627 TEST(IllegalRedeclaration) { 5674 TEST(IllegalRedeclaration) {
5675 bool old_legacy_const_flag = FLAG_legacy_const;
5676 FLAG_legacy_const = true;
5677
5628 InitializedHandleScope handle_scope; 5678 InitializedHandleScope handle_scope;
5629 BytecodeGeneratorHelper helper; 5679 BytecodeGeneratorHelper helper;
5630 5680
5631 CHECK_GE(MessageTemplate::kVarRedeclaration, 128); 5681 CHECK_GE(MessageTemplate::kVarRedeclaration, 128);
5632 // Must adapt bytecode if this changes. 5682 // Must adapt bytecode if this changes.
5633 5683
5634 ExpectedSnippet<Handle<Object>, 2> snippets[] = { 5684 ExpectedSnippet<Handle<Object>, 2> snippets[] = {
5635 {"const a = 1; { var a = 2; }", 5685 {"const a = 1; { var a = 2; }",
5636 3 * kPointerSize, 5686 3 * kPointerSize,
5637 1, 5687 1,
5638 14, 5688 14,
5639 { 5689 {
5640 B(LdaConstant), U8(0), // 5690 B(LdaConstant), U8(0), //
5641 B(Star), R(1), // 5691 B(Star), R(1), //
5642 B(LdaConstant), U8(1), // 5692 B(LdaConstant), U8(1), //
5643 B(Star), R(2), // 5693 B(Star), R(2), //
5644 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), // 5694 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), //
5645 B(Throw), // 5695 B(Throw), //
5646 }, 5696 },
5647 2, 5697 2,
5648 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), 5698 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration),
5649 helper.factory()->NewStringFromAsciiChecked("a")}}, 5699 helper.factory()->NewStringFromAsciiChecked("a")}},
5650 }; 5700 };
5651 5701
5652 for (size_t i = 0; i < arraysize(snippets); i++) { 5702 for (size_t i = 0; i < arraysize(snippets); i++) {
5653 Handle<BytecodeArray> bytecode_array = 5703 Handle<BytecodeArray> bytecode_array =
5654 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 5704 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
5655 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5705 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5656 } 5706 }
5707
5708 FLAG_legacy_const = old_legacy_const_flag;
5657 } 5709 }
5658 5710
5659 5711
5660 TEST(ForIn) { 5712 TEST(ForIn) {
5661 InitializedHandleScope handle_scope; 5713 InitializedHandleScope handle_scope;
5662 BytecodeGeneratorHelper helper; 5714 BytecodeGeneratorHelper helper;
5663 Zone zone; 5715 Zone zone;
5664 5716
5665 int simple_flags = 5717 int simple_flags =
5666 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; 5718 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
6542 6594
6543 6595
6544 TEST(ThisFunction) { 6596 TEST(ThisFunction) {
6545 InitializedHandleScope handle_scope; 6597 InitializedHandleScope handle_scope;
6546 BytecodeGeneratorHelper helper; 6598 BytecodeGeneratorHelper helper;
6547 6599
6548 int closure = Register::function_closure().index(); 6600 int closure = Register::function_closure().index();
6549 6601
6550 ExpectedSnippet<int> snippets[] = { 6602 ExpectedSnippet<int> snippets[] = {
6551 {"var f;\n f = function f() { }", 6603 {"var f;\n f = function f() { }",
6552 1 * kPointerSize, 6604 2 * kPointerSize,
6553 1, 6605 1,
6554 9, 6606 18,
6555 { 6607 {
6556 B(LdaTheHole), // 6608 B(LdaTheHole), //
6557 B(Star), R(0), // 6609 B(Star), R(0), //
6558 B(Ldar), R(closure), // 6610 B(Ldar), R(closure), //
6559 B(Star), R(0), // 6611 B(Star), R(1), //
6560 B(LdaUndefined), // 6612 B(Ldar), R(0), //
6561 B(Return), // 6613 B(JumpIfNotHole), U8(5), //
6614 B(Mov), R(1), R(0), //
6615 B(Ldar), R(1), //
6616 B(LdaUndefined), //
6617 B(Return), //
6562 }}, 6618 }},
6563 {"var f;\n f = function f() { return f; }", 6619 {"var f;\n f = function f() { return f; }",
6564 1 * kPointerSize, 6620 2 * kPointerSize,
6565 1, 6621 1,
6566 8, 6622 22,
6567 { 6623 {
6568 B(LdaTheHole), // 6624 B(LdaTheHole), //
6569 B(Star), R(0), // 6625 B(Star), R(0), //
6570 B(Ldar), R(closure), // 6626 B(Ldar), R(closure), //
6571 B(Star), R(0), // 6627 B(Star), R(1), //
6572 B(Return), // 6628 B(Ldar), R(0), //
6629 B(JumpIfNotHole), U8(5), //
6630 B(Mov), R(1), R(0), //
6631 B(Ldar), R(1), //
6632 B(Ldar), R(0), //
6633 B(JumpIfNotHole), U8(3), //
6634 B(LdaUndefined), //
6635 B(Return), //
6573 }}, 6636 }},
6574 }; 6637 };
6575 6638
6576 for (size_t i = 0; i < arraysize(snippets); i++) { 6639 for (size_t i = 0; i < arraysize(snippets); i++) {
6577 Handle<BytecodeArray> bytecode_array = 6640 Handle<BytecodeArray> bytecode_array =
6578 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 6641 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
6579 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 6642 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6580 } 6643 }
6581 } 6644 }
6582 6645
6583 6646
6584 TEST(NewTarget) { 6647 TEST(NewTarget) {
6585 InitializedHandleScope handle_scope; 6648 InitializedHandleScope handle_scope;
6586 BytecodeGeneratorHelper helper; 6649 BytecodeGeneratorHelper helper;
6587 6650
6588 int new_target = Register::new_target().index(); 6651 int new_target = Register::new_target().index();
6589 6652
6590 ExpectedSnippet<int> snippets[] = { 6653 ExpectedSnippet<InstanceType> snippets[] = {
6591 {"return new.target;", 6654 {"return new.target;",
6592 1 * kPointerSize, 6655 2 * kPointerSize,
6593 1, 6656 1,
6594 5, 6657 16,
6595 { 6658 {
6596 B(Ldar), R(new_target), // 6659 B(Ldar), R(new_target), //
6597 B(Star), R(0), // 6660 B(Star), R(0), //
6598 B(Return), // 6661 B(JumpIfNotHole), U8(11), //
6599 }}, 6662 B(LdaConstant), U8(0), //
6663 B(Star), R(1), //
6664 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
6665 B(Return), //
6666 },
6667 1,
6668 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
6600 {"new.target;", 6669 {"new.target;",
6601 1 * kPointerSize, 6670 2 * kPointerSize,
6602 1, 6671 1,
6603 6, 6672 17,
6604 { 6673 {
6605 B(Ldar), R(new_target), // 6674 B(Ldar), R(new_target), //
6606 B(Star), R(0), // 6675 B(Star), R(0), //
6607 B(LdaUndefined), // 6676 B(JumpIfNotHole), U8(11), //
6608 B(Return), // 6677 B(LdaConstant), U8(0), //
6609 }}, 6678 B(Star), R(1), //
6610 }; 6679 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
6680 B(LdaUndefined), //
6681 B(Return), //
6682 },
6683 1,
6684 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}};
6611 6685
6612 for (size_t i = 0; i < arraysize(snippets); i++) { 6686 for (size_t i = 0; i < arraysize(snippets); i++) {
6613 Handle<BytecodeArray> bytecode_array = 6687 Handle<BytecodeArray> bytecode_array =
6614 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 6688 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
6615 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 6689 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6616 } 6690 }
6617 } 6691 }
6618 6692
6619 6693
6620 TEST(RemoveRedundantLdar) { 6694 TEST(RemoveRedundantLdar) {
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
7626 BytecodeGeneratorHelper helper; 7700 BytecodeGeneratorHelper helper;
7627 7701
7628 for (size_t i = 0; i < arraysize(snippets); ++i) { 7702 for (size_t i = 0; i < arraysize(snippets); ++i) {
7629 std::string body = prologue + snippets[i].code_snippet; 7703 std::string body = prologue + snippets[i].code_snippet;
7630 Handle<BytecodeArray> bytecode_array = 7704 Handle<BytecodeArray> bytecode_array =
7631 helper.MakeBytecodeForFunctionBody(body.c_str()); 7705 helper.MakeBytecodeForFunctionBody(body.c_str());
7632 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 7706 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7633 } 7707 }
7634 } 7708 }
7635 7709
7710 TEST(ConstVariable) {
7711 InitializedHandleScope handle_scope;
7712 BytecodeGeneratorHelper helper;
7713
rmcilroy 2016/02/04 15:19:39 nit - please add // clang-format off and at th
mythria 2016/02/04 16:08:00 Done.
7714 ExpectedSnippet<const char*> snippets[] = {
7715 {"const x = 10;",
7716 1 * kPointerSize,
7717 1,
7718 9,
7719 {
7720 B(LdaTheHole), //
7721 B(Star), R(0), //
7722 B(LdaSmi8), U8(10), //
7723 B(Star), R(0), //
7724 B(LdaUndefined), //
7725 B(Return) //
7726 },
7727 0},
7728 {"const x = 10; return x;",
7729 2 * kPointerSize,
7730 1,
7731 19,
7732 {
7733 B(LdaTheHole), //
7734 B(Star), R(0), //
7735 B(LdaSmi8), U8(10), //
7736 B(Star), R(0), //
7737 B(JumpIfNotHole), U8(11), //
7738 B(LdaConstant), U8(0), //
7739 B(Star), R(1), //
7740 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
7741 B(Return) //
7742 },
7743 1,
7744 {"x"}},
7745 {"const x = ( x = 20);",
7746 3 * kPointerSize,
7747 1,
7748 31,
7749 {
7750 B(LdaTheHole), //
7751 B(Star), R(0), //
7752 B(LdaSmi8), U8(20), //
7753 B(Star), R(1), //
7754 B(Ldar), R(0), //
7755 B(JumpIfNotHole), U8(11), //
7756 B(LdaConstant), U8(0), //
7757 B(Star), R(2), //
7758 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7759 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
7760 U8(0), //
rmcilroy 2016/02/04 15:19:39 /* */ U8(0) (and below).
mythria 2016/02/04 16:07:59 Done.
7761 B(Ldar), R(1), //
7762 B(Star), R(0), //
7763 B(LdaUndefined), //
7764 B(Return) //
7765 },
7766 1,
7767 {"x"}},
7768 {"const x = 10; x = 20;",
7769 3 * kPointerSize,
7770 1,
7771 35,
7772 {
7773 B(LdaTheHole), //
7774 B(Star), R(0), //
7775 B(LdaSmi8), U8(10), //
7776 B(Star), R(0), //
7777 B(LdaSmi8), U8(20), //
7778 B(Star), R(1), //
7779 B(Ldar), R(0), //
7780 B(JumpIfNotHole), U8(11), //
7781 B(LdaConstant), U8(0), //
7782 B(Star), R(2), //
7783 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7784 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
7785 U8(0), //
7786 B(Ldar), R(1), //
7787 B(Star), R(0), //
7788 B(LdaUndefined), //
7789 B(Return) //
7790 },
7791 1,
7792 {"x"}},
7793 };
7794
7795 for (size_t i = 0; i < arraysize(snippets); i++) {
7796 Handle<BytecodeArray> bytecode_array =
7797 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7798 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7799 }
7800 }
7801
7802 TEST(LetVariable) {
7803 InitializedHandleScope handle_scope;
7804 BytecodeGeneratorHelper helper;
7805
rmcilroy 2016/02/04 15:19:39 ditto
mythria 2016/02/04 16:08:00 Done.
7806 ExpectedSnippet<const char*> snippets[] = {
7807 {"let x = 10;",
7808 1 * kPointerSize,
7809 1,
7810 9,
7811 {
7812 B(LdaTheHole), //
7813 B(Star), R(0), //
7814 B(LdaSmi8), U8(10), //
7815 B(Star), R(0), //
7816 B(LdaUndefined), //
7817 B(Return) //
7818 },
7819 0},
7820 {"let x = 10; return x;",
7821 2 * kPointerSize,
7822 1,
7823 19,
7824 {
7825 B(LdaTheHole), //
7826 B(Star), R(0), //
7827 B(LdaSmi8), U8(10), //
7828 B(Star), R(0), //
7829 B(JumpIfNotHole), U8(11), //
7830 B(LdaConstant), U8(0), //
7831 B(Star), R(1), //
7832 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
7833 B(Return) //
7834 },
7835 1,
7836 {"x"}},
7837 {"let x = (x = 20);",
7838 3 * kPointerSize,
7839 1,
7840 26,
7841 {
7842 B(LdaTheHole), //
7843 B(Star), R(0), //
7844 B(LdaSmi8), U8(20), //
7845 B(Star), R(1), //
7846 B(Ldar), R(0), //
7847 B(JumpIfNotHole), U8(11), //
7848 B(LdaConstant), U8(0), //
7849 B(Star), R(2), //
7850 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7851 B(Ldar), R(1), //
7852 B(Star), R(0), //
7853 B(LdaUndefined), //
7854 B(Return) //
7855 },
7856 1,
7857 {"x"}},
7858 {"let x = 10; x = 20;",
7859 3 * kPointerSize,
7860 1,
7861 30,
7862 {
7863 B(LdaTheHole), //
7864 B(Star), R(0), //
7865 B(LdaSmi8), U8(10), //
7866 B(Star), R(0), //
7867 B(LdaSmi8), U8(20), //
7868 B(Star), R(1), //
7869 B(Ldar), R(0), //
7870 B(JumpIfNotHole), U8(11), //
7871 B(LdaConstant), U8(0), //
7872 B(Star), R(2), //
7873 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7874 B(Ldar), R(1), //
7875 B(Star), R(0), //
7876 B(LdaUndefined), //
7877 B(Return) //
7878 },
7879 1,
7880 {"x"}},
7881 };
7882
7883 for (size_t i = 0; i < arraysize(snippets); i++) {
7884 Handle<BytecodeArray> bytecode_array =
7885 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7886 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7887 }
7888 }
7889
7890 TEST(LegacyConstVariable) {
7891 bool old_legacy_const_flag = FLAG_legacy_const;
7892 FLAG_legacy_const = true;
7893
7894 InitializedHandleScope handle_scope;
7895 BytecodeGeneratorHelper helper;
7896
7897 ExpectedSnippet<const char*> snippets[] = {
7898 {"const x = 10;",
7899 2 * kPointerSize,
7900 1,
7901 18,
7902 {
7903 B(LdaTheHole), //
7904 B(Star), R(0), //
7905 B(LdaSmi8), U8(10), //
7906 B(Star), R(1), //
7907 B(Ldar), R(0), //
7908 B(JumpIfNotHole), U8(5), //
7909 B(Mov), R(1), R(0), //
7910 B(Ldar), R(1), //
7911 B(LdaUndefined), //
7912 B(Return) //
7913 },
7914 0},
7915 {"const x = 10; return x;",
7916 2 * kPointerSize,
7917 1,
7918 22,
7919 {
7920 B(LdaTheHole), //
7921 B(Star), R(0), //
7922 B(LdaSmi8), U8(10), //
7923 B(Star), R(1), //
7924 B(Ldar), R(0), //
7925 B(JumpIfNotHole), U8(5), //
7926 B(Mov), R(1), R(0), //
7927 B(Ldar), R(1), //
7928 B(Ldar), R(0), //
7929 B(JumpIfNotHole), U8(3), //
7930 B(LdaUndefined), //
7931 B(Return) //
7932 },
7933 0},
7934 {"const x = ( x = 20);",
7935 2 * kPointerSize,
7936 1,
7937 22,
7938 {
7939 B(LdaTheHole), //
7940 B(Star), R(0), //
7941 B(LdaSmi8), U8(20), //
7942 B(Star), R(1), //
7943 B(Ldar), R(0), //
7944 B(Ldar), R(1), //
7945 B(Ldar), R(0), //
7946 B(JumpIfNotHole), U8(5), //
7947 B(Mov), R(1), R(0), //
7948 B(Ldar), R(1), //
7949 B(LdaUndefined), //
7950 B(Return) //
7951 },
7952 0},
7953 {"const x = 10; x = 20;",
7954 2 * kPointerSize,
7955 1,
7956 26,
7957 {
7958 B(LdaTheHole), //
7959 B(Star), R(0), //
7960 B(LdaSmi8), U8(10), //
7961 B(Star), R(1), //
7962 B(Ldar), R(0), //
7963 B(JumpIfNotHole), U8(5), //
7964 B(Mov), R(1), R(0), //
7965 B(Ldar), R(1), //
7966 B(LdaSmi8), U8(20), //
7967 B(Star), R(1), //
7968 B(Ldar), R(0), //
7969 B(Ldar), R(1), //
7970 B(LdaUndefined), //
7971 B(Return) //
7972 },
7973 0},
7974 };
7975
7976 for (size_t i = 0; i < arraysize(snippets); i++) {
7977 Handle<BytecodeArray> bytecode_array =
7978 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7979 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7980 }
7981
7982 FLAG_legacy_const = old_legacy_const_flag;
7983 }
7984
7985 TEST(ConstVariableContextSlot) {
7986 InitializedHandleScope handle_scope;
7987 BytecodeGeneratorHelper helper;
7988
7989 int closure = Register::function_closure().index();
7990 int context = Register::current_context().index();
7991
7992 // TODO(mythria): Add tests for initialization of this via super calls.
7993 // TODO(mythria): Add tests that walk the context chain.
rmcilroy 2016/02/04 15:19:39 ditto
mythria 2016/02/04 16:07:59 Done.
7994 ExpectedSnippet<InstanceType> snippets[] = {
7995 {"const x = 10; function f1() {return x;}",
7996 2 * kPointerSize,
7997 1,
7998 23,
7999 {
8000 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8001 U8(1), //
8002 B(PushContext), R(1), //
8003 B(LdaTheHole), //
8004 B(StaContextSlot), R(context), U8(4), //
8005 B(CreateClosure), U8(0), U8(0), //
8006 B(Star), R(0), //
8007 B(LdaSmi8), U8(10), //
8008 B(StaContextSlot), R(context), U8(4), //
8009 B(LdaUndefined), //
8010 B(Return) //
8011 },
8012 1,
8013 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
8014 {"const x = 10; function f1() {return x;} return x;",
8015 3 * kPointerSize,
8016 1,
8017 36,
8018 {
8019 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8020 U8(1), //
8021 B(PushContext), R(1), //
8022 B(LdaTheHole), //
8023 B(StaContextSlot), R(context), U8(4), //
8024 B(CreateClosure), U8(0), U8(0), //
8025 B(Star), R(0), //
8026 B(LdaSmi8), U8(10), //
8027 B(StaContextSlot), R(context), U8(4), //
8028 B(LdaContextSlot), R(context), U8(4), //
8029 B(JumpIfNotHole), U8(11), //
8030 B(LdaConstant), U8(1), //
8031 B(Star), R(2), //
8032 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8033 B(Return) //
8034 },
8035 2,
8036 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8037 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8038 {"const x = (x = 20); function f1() {return x;}",
8039 4 * kPointerSize,
8040 1,
8041 49,
8042 {
8043 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8044 U8(1), //
8045 B(PushContext), R(1), //
8046 B(LdaTheHole), //
8047 B(StaContextSlot), R(context), U8(4), //
8048 B(CreateClosure), U8(0), U8(0), //
8049 B(Star), R(0), //
8050 B(LdaSmi8), U8(20), //
8051 B(Star), R(2), //
8052 B(LdaContextSlot), R(context), U8(4), //
8053 B(JumpIfNotHole), U8(11), //
8054 B(LdaConstant), U8(1), //
8055 B(Star), R(3), //
8056 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8057 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
8058 U8(0), //
8059 B(Ldar), R(2), //
8060 B(StaContextSlot), R(context), U8(4), //
8061 B(StaContextSlot), R(context), U8(4), //
8062 B(LdaUndefined), //
8063 B(Return) //
8064 },
8065 2,
8066 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8067 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8068 {"const x = 10; x = 20; function f1() {return x;}",
8069 4 * kPointerSize,
8070 1,
8071 51,
8072 {
8073 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8074 U8(1), //
8075 B(PushContext), R(1), //
8076 B(LdaTheHole), //
8077 B(StaContextSlot), R(context), U8(4), //
8078 B(CreateClosure), U8(0), U8(0), //
8079 B(Star), R(0), //
8080 B(LdaSmi8), U8(10), //
8081 B(StaContextSlot), R(context), U8(4), //
8082 B(LdaSmi8), U8(20), //
8083 B(Star), R(2), //
8084 B(LdaContextSlot), R(context), U8(4), //
8085 B(JumpIfNotHole), U8(11), //
8086 B(LdaConstant), U8(1), //
8087 B(Star), R(3), //
8088 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8089 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
8090 U8(0), //
8091 B(Ldar), R(2), //
8092 B(StaContextSlot), R(context), U8(4), //
8093 B(LdaUndefined), //
8094 B(Return) //
8095 },
8096 2,
8097 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8098 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8099 };
8100
8101 for (size_t i = 0; i < arraysize(snippets); i++) {
8102 Handle<BytecodeArray> bytecode_array =
8103 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8104 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8105 }
8106 }
8107
8108 TEST(LetVariableContextSlot) {
8109 InitializedHandleScope handle_scope;
8110 BytecodeGeneratorHelper helper;
8111
8112 int closure = Register::function_closure().index();
8113 int context = Register::current_context().index();
8114
8115 ExpectedSnippet<InstanceType> snippets[] = {
rmcilroy 2016/02/04 15:19:39 ditto
mythria 2016/02/04 16:07:59 Done.
8116 {"let x = 10; function f1() {return x;}",
8117 2 * kPointerSize,
8118 1,
8119 23,
8120 {
8121 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8122 U8(1), //
8123 B(PushContext), R(1), //
8124 B(LdaTheHole), //
8125 B(StaContextSlot), R(context), U8(4), //
8126 B(CreateClosure), U8(0), U8(0), //
8127 B(Star), R(0), //
8128 B(LdaSmi8), U8(10), //
8129 B(StaContextSlot), R(context), U8(4), //
8130 B(LdaUndefined), //
8131 B(Return) //
8132 },
8133 1,
8134 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
8135 {"let x = 10; function f1() {return x;} return x;",
8136 3 * kPointerSize,
8137 1,
8138 36,
8139 {
8140 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8141 U8(1), //
8142 B(PushContext), R(1), //
8143 B(LdaTheHole), //
8144 B(StaContextSlot), R(context), U8(4), //
8145 B(CreateClosure), U8(0), U8(0), //
8146 B(Star), R(0), //
8147 B(LdaSmi8), U8(10), //
8148 B(StaContextSlot), R(context), U8(4), //
8149 B(LdaContextSlot), R(context), U8(4), //
8150 B(JumpIfNotHole), U8(11), //
8151 B(LdaConstant), U8(1), //
8152 B(Star), R(2), //
8153 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8154 B(Return) //
8155 },
8156 2,
8157 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8158 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8159 {"let x = (x = 20); function f1() {return x;}",
8160 4 * kPointerSize,
8161 1,
8162 44,
8163 {
8164 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8165 U8(1), //
8166 B(PushContext), R(1), //
8167 B(LdaTheHole), //
8168 B(StaContextSlot), R(context), U8(4), //
8169 B(CreateClosure), U8(0), U8(0), //
8170 B(Star), R(0), //
8171 B(LdaSmi8), U8(20), //
8172 B(Star), R(2), //
8173 B(LdaContextSlot), R(context), U8(4), //
8174 B(JumpIfNotHole), U8(11), //
8175 B(LdaConstant), U8(1), //
8176 B(Star), R(3), //
8177 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8178 B(Ldar), R(2), //
8179 B(StaContextSlot), R(context), U8(4), //
8180 B(StaContextSlot), R(context), U8(4), //
8181 B(LdaUndefined), //
8182 B(Return) //
8183 },
8184 2,
8185 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8186 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8187 {"let x = 10; x = 20; function f1() {return x;}",
8188 4 * kPointerSize,
8189 1,
8190 46,
8191 {
8192 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8193 U8(1), //
8194 B(PushContext), R(1), //
8195 B(LdaTheHole), //
8196 B(StaContextSlot), R(context), U8(4), //
8197 B(CreateClosure), U8(0), U8(0), //
8198 B(Star), R(0), //
8199 B(LdaSmi8), U8(10), //
8200 B(StaContextSlot), R(context), U8(4), //
8201 B(LdaSmi8), U8(20), //
8202 B(Star), R(2), //
8203 B(LdaContextSlot), R(context), U8(4), //
8204 B(JumpIfNotHole), U8(11), //
8205 B(LdaConstant), U8(1), //
8206 B(Star), R(3), //
8207 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8208 B(Ldar), R(2), //
8209 B(StaContextSlot), R(context), U8(4), //
8210 B(LdaUndefined), //
8211 B(Return) //
8212 },
8213 2,
8214 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8215 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8216 };
8217
8218 for (size_t i = 0; i < arraysize(snippets); i++) {
8219 Handle<BytecodeArray> bytecode_array =
8220 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8221 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8222 }
8223 }
8224
7636 TEST(DoExpression) { 8225 TEST(DoExpression) {
7637 bool old_flag = FLAG_harmony_do_expressions; 8226 bool old_flag = FLAG_harmony_do_expressions;
7638 FLAG_harmony_do_expressions = true; 8227 FLAG_harmony_do_expressions = true;
7639 8228
7640 InitializedHandleScope handle_scope; 8229 InitializedHandleScope handle_scope;
7641 BytecodeGeneratorHelper helper; 8230 BytecodeGeneratorHelper helper;
7642 8231
7643 ExpectedSnippet<const char*> snippets[] = { 8232 ExpectedSnippet<const char*> snippets[] = {
7644 {"var a = do { }; return a;", 8233 {"var a = do { }; return a;",
7645 2 * kPointerSize, 8234 2 * kPointerSize,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
7740 for (size_t i = 0; i < arraysize(snippets); i++) { 8329 for (size_t i = 0; i < arraysize(snippets); i++) {
7741 Handle<BytecodeArray> bytecode_array = 8330 Handle<BytecodeArray> bytecode_array =
7742 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 8331 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7743 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 8332 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7744 } 8333 }
7745 } 8334 }
7746 8335
7747 } // namespace interpreter 8336 } // namespace interpreter
7748 } // namespace internal 8337 } // namespace internal
7749 } // namespace v8 8338 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698