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

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: Rebased the patch. 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"
(...skipping 11 matching lines...) Expand all
22 const char* kFunctionName = "f"; 22 const char* kFunctionName = "f";
23 23
24 static const int kLastParamIndex = 24 static const int kLastParamIndex =
25 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; 25 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
26 26
27 BytecodeGeneratorHelper() { 27 BytecodeGeneratorHelper() {
28 i::FLAG_ignition = true; 28 i::FLAG_ignition = true;
29 i::FLAG_ignition_filter = StrDup(kFunctionName); 29 i::FLAG_ignition_filter = StrDup(kFunctionName);
30 i::FLAG_always_opt = false; 30 i::FLAG_always_opt = false;
31 i::FLAG_allow_natives_syntax = true; 31 i::FLAG_allow_natives_syntax = true;
32 i::FLAG_legacy_const = true;
33 CcTest::i_isolate()->interpreter()->Initialize(); 32 CcTest::i_isolate()->interpreter()->Initialize();
34 } 33 }
35 34
36 Isolate* isolate() { return CcTest::i_isolate(); } 35 Isolate* isolate() { return CcTest::i_isolate(); }
37 Factory* factory() { return CcTest::i_isolate()->factory(); } 36 Factory* factory() { return CcTest::i_isolate()->factory(); }
38 37
39 Handle<BytecodeArray> MakeTopLevelBytecode(const char* source) { 38 Handle<BytecodeArray> MakeTopLevelBytecode(const char* source) {
40 const char* old_ignition_filter = i::FLAG_ignition_filter; 39 const char* old_ignition_filter = i::FLAG_ignition_filter;
41 i::FLAG_ignition_filter = "*"; 40 i::FLAG_ignition_filter = "*";
42 Local<v8::Script> script = v8_compile(source); 41 Local<v8::Script> script = v8_compile(source);
(...skipping 2489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 B(Ldar), R(0), // 2531 B(Ldar), R(0), //
2533 B(Return), // 2532 B(Return), //
2534 }}, 2533 }},
2535 {"outer: {\n" 2534 {"outer: {\n"
2536 " let y = 10;" 2535 " let y = 10;"
2537 " function f() { return y; }\n" 2536 " function f() { return y; }\n"
2538 " break outer;\n" 2537 " break outer;\n"
2539 "}\n", 2538 "}\n",
2540 5 * kPointerSize, 2539 5 * kPointerSize,
2541 1, 2540 1,
2542 40, 2541 51,
2543 { 2542 {
2544 B(StackCheck), // 2543 B(StackCheck), //
2545 B(LdaConstant), U8(0), // 2544 B(LdaConstant), U8(0), //
2546 B(Star), R(3), // 2545 B(Star), R(3), //
2547 B(Ldar), R(closure), // 2546 B(Ldar), R(closure), //
2548 B(Star), R(4), // 2547 B(Star), R(4), //
2549 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // 2548 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), //
2550 B(PushContext), R(2), // 2549 B(PushContext), R(2), //
2551 B(LdaTheHole), // 2550 B(LdaTheHole), //
2552 B(StaContextSlot), R(context), U8(4), // 2551 B(StaContextSlot), R(context), U8(4), //
2553 B(CreateClosure), U8(1), U8(0), // 2552 B(CreateClosure), U8(1), U8(0), //
2554 B(Star), R(0), // 2553 B(Star), R(0), //
2555 B(LdaSmi8), U8(10), // 2554 B(LdaSmi8), U8(10), //
2556 B(StaContextSlot), R(context), U8(4), // 2555 B(StaContextSlot), R(context), U8(4), //
2557 B(Ldar), R(0), // 2556 B(Ldar), R(0), //
2558 B(Star), R(1), // 2557 B(JumpIfNotHole), U8(11), //
2559 B(Jump), U8(2), // 2558 B(LdaConstant), U8(2), //
2560 B(PopContext), R(2), // 2559 B(Star), R(3), //
2561 B(LdaUndefined), // 2560 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
2562 B(Return), // 2561 B(Star), R(1), //
2562 B(Jump), U8(2), //
2563 B(PopContext), R(2), //
2564 B(LdaUndefined), //
2565 B(Return), //
2563 }, 2566 },
2564 2, 2567 3,
2565 {InstanceType::FIXED_ARRAY_TYPE, 2568 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
2566 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2569 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2567 {"let x = 1;\n" 2570 {"let x = 1;\n"
2568 "outer: {\n" 2571 "outer: {\n"
2569 " inner: {\n" 2572 " inner: {\n"
2570 " let y = 2;\n" 2573 " let y = 2;\n"
2571 " function f() { return x + y; }\n" 2574 " function f() { return x + y; }\n"
2572 " if (y) break outer;\n" 2575 " if (y) break outer;\n"
2573 " y = 3;\n" 2576 " y = 3;\n"
2574 " }\n" 2577 " }\n"
2575 "}\n" 2578 "}\n"
2576 "x = 4;", 2579 "x = 4;",
2577 6 * kPointerSize, 2580 6 * kPointerSize,
2578 1, 2581 1,
2579 73, 2582 131,
2580 { 2583 {
2581 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // 2584 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
2582 /* */ U8(1), // 2585 U8(1), //
2583 B(PushContext), R(2), // 2586 B(PushContext), R(2), //
2584 B(LdaTheHole), // 2587 B(LdaTheHole), //
2585 B(StaContextSlot), R(context), U8(4), // 2588 B(StaContextSlot), R(context), U8(4), //
2586 B(StackCheck), // 2589 B(StackCheck), //
2587 B(LdaSmi8), U8(1), // 2590 B(LdaSmi8), U8(1), //
2588 B(StaContextSlot), R(context), U8(4), // 2591 B(StaContextSlot), R(context), U8(4), //
2589 B(LdaConstant), U8(0), // 2592 B(LdaConstant), U8(0), //
2590 B(Star), R(4), // 2593 B(Star), R(4), //
2591 B(Ldar), R(closure), // 2594 B(Ldar), R(closure), //
2592 B(Star), R(5), // 2595 B(Star), R(5), //
2593 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // 2596 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
2594 B(PushContext), R(3), // 2597 B(PushContext), R(3), //
2595 B(LdaTheHole), // 2598 B(LdaTheHole), //
2596 B(StaContextSlot), R(context), U8(4), // 2599 B(StaContextSlot), R(context), U8(4), //
2597 B(CreateClosure), U8(1), U8(0), // 2600 B(CreateClosure), U8(1), U8(0), //
2598 B(Star), R(0), // 2601 B(Star), R(0), //
2599 B(LdaSmi8), U8(2), // 2602 B(LdaSmi8), U8(2), //
2600 B(StaContextSlot), R(context), U8(4), // 2603 B(StaContextSlot), R(context), U8(4), //
2601 B(Ldar), R(0), // 2604 B(Ldar), R(0), //
2602 B(Star), R(1), // 2605 B(JumpIfNotHole), U8(11), //
2603 B(LdaContextSlot), R(context), U8(4), // 2606 B(LdaConstant), U8(2), //
2604 B(JumpIfToBooleanFalse), U8(6), // 2607 B(Star), R(4), //
2605 B(PopContext), R(3), // 2608 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
2606 B(Jump), U8(9), // 2609 B(Star), R(1), //
2607 B(LdaSmi8), U8(3), // 2610 B(LdaContextSlot), R(context), U8(4), //
2608 B(StaContextSlot), R(context), U8(4), // 2611 B(JumpIfNotHole), U8(11), //
2609 B(PopContext), R(3), // 2612 B(LdaConstant), U8(3), //
2610 B(LdaSmi8), U8(4), // 2613 B(Star), R(4), //
2611 B(StaContextSlot), R(context), U8(4), // 2614 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
2612 B(LdaUndefined), // 2615 B(JumpIfToBooleanFalse), U8(6), //
2613 B(Return), // 2616 B(PopContext), R(3), //
2614 }, 2617 B(Jump), U8(27), //
2615 2, 2618 B(LdaSmi8), U8(3), //
2616 {InstanceType::FIXED_ARRAY_TYPE, 2619 B(Star), R(4), //
2617 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2620 B(LdaContextSlot), R(context), U8(4), //
2621 B(JumpIfNotHole), U8(11), //
2622 B(LdaConstant), U8(3), //
2623 B(Star), R(5), //
2624 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), //
2625 B(Ldar), R(4), //
2626 B(StaContextSlot), R(context), U8(4), //
2627 B(PopContext), R(3), //
2628 B(LdaSmi8), U8(4), //
2629 B(Star), R(4), //
2630 B(LdaContextSlot), R(context), U8(4), //
2631 B(JumpIfNotHole), U8(11), //
2632 B(LdaConstant), U8(4), //
2633 B(Star), R(5), //
2634 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), //
2635 B(Ldar), R(4), //
2636 B(StaContextSlot), R(context), U8(4), //
2637 B(LdaUndefined), //
2638 B(Return), //
2639 },
2640 5,
2641 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
2642 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2643 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2644 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2618 }; 2645 };
2619 // clang-format on 2646 // clang-format on
2620 2647
2621 for (size_t i = 0; i < arraysize(snippets); i++) { 2648 for (size_t i = 0; i < arraysize(snippets); i++) {
2622 Handle<BytecodeArray> bytecode_array = 2649 Handle<BytecodeArray> bytecode_array =
2623 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2650 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2624 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2651 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2625 } 2652 }
2626 } 2653 }
2627 2654
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
3276 B(Inc), // 3303 B(Inc), //
3277 B(Star), R(1), // 3304 B(Star), R(1), //
3278 B(Jump), U8(-27), // 3305 B(Jump), U8(-27), //
3279 B(Ldar), R(0), // 3306 B(Ldar), R(0), //
3280 B(Return), // 3307 B(Return), //
3281 }, 3308 },
3282 0}, 3309 0},
3283 {"var a = 0;\n" 3310 {"var a = 0;\n"
3284 "while (a) {\n" 3311 "while (a) {\n"
3285 " { \n" 3312 " { \n"
3286 " let z = 1;\n" 3313 " let z = 1;\n"
3287 " function f() { z = 2; }\n" 3314 " function f() { z = 2; }\n"
3288 " if (z) continue;\n" 3315 " if (z) continue;\n"
3289 " z++;\n" 3316 " z++;\n"
3290 " }\n" 3317 " }\n"
3291 "}\n", 3318 "}\n",
3292 6 * kPointerSize, 3319 7 * kPointerSize,
3293 1, 3320 1,
3294 67, 3321 118,
3295 { 3322 {
3296 B(StackCheck), // 3323 B(StackCheck), //
3297 B(LdaZero), // 3324 B(LdaZero), //
3298 B(Star), R(1), // 3325 B(Star), R(1), //
3299 B(Ldar), R(1), // 3326 B(Ldar), R(1), //
3300 B(JumpIfToBooleanFalse), U8(59), // 3327 B(JumpIfToBooleanFalse), U8(110), //
3301 B(StackCheck), // 3328 B(StackCheck), //
3302 B(LdaConstant), U8(0), // 3329 B(LdaConstant), U8(0), //
3303 B(Star), R(4), // 3330 B(Star), R(4), //
3304 B(Ldar), R(closure), // 3331 B(Ldar), R(closure), //
3305 B(Star), R(5), // 3332 B(Star), R(5), //
3306 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // 3333 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
3307 B(PushContext), R(3), // 3334 B(PushContext), R(3), //
3308 B(LdaTheHole), // 3335 B(LdaTheHole), //
3309 B(StaContextSlot), R(context), U8(4), // 3336 B(StaContextSlot), R(context), U8(4), //
3310 B(CreateClosure), U8(1), U8(0), // 3337 B(CreateClosure), U8(1), U8(0), //
3311 B(Star), R(0), // 3338 B(Star), R(0), //
3312 B(LdaSmi8), U8(1), // 3339 B(LdaSmi8), U8(1), //
3313 B(StaContextSlot), R(context), U8(4), // 3340 B(StaContextSlot), R(context), U8(4), //
3314 B(Ldar), R(0), // 3341 B(Ldar), R(0), //
3315 B(Star), R(2), // 3342 B(JumpIfNotHole), U8(11), //
3316 B(LdaContextSlot), R(context), U8(4), // 3343 B(LdaConstant), U8(2), //
3317 B(JumpIfToBooleanFalse), U8(6), // 3344 B(Star), R(4), //
3318 B(PopContext), R(3), // 3345 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3319 B(Jump), U8(-45), // 3346 B(Star), R(2), //
3320 B(LdaContextSlot), R(context), U8(4), // 3347 B(LdaContextSlot), R(context), U8(4), //
3321 B(ToNumber), // 3348 B(JumpIfNotHole), U8(11), //
3322 B(Star), R(4), // 3349 B(LdaConstant), U8(3), //
3323 B(Inc), // 3350 B(Star), R(4), //
3324 B(StaContextSlot), R(context), U8(4), // 3351 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3325 B(PopContext), R(3), // 3352 B(JumpIfToBooleanFalse), U8(6), //
3326 B(Jump), U8(-59), // 3353 B(PopContext), R(3), //
3327 B(LdaUndefined), // 3354 B(Jump), U8(-67), //
3328 B(Return), // 3355 B(LdaContextSlot), R(context), U8(4), //
3329 }, 3356 B(JumpIfNotHole), U8(11), //
3330 2, 3357 B(LdaConstant), U8(3), //
3331 {InstanceType::FIXED_ARRAY_TYPE, 3358 B(Star), R(4), //
3332 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 3359 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3360 B(ToNumber), //
3361 B(Star), R(4), //
3362 B(Inc), //
3363 B(Star), R(5), //
3364 B(LdaContextSlot), R(context), U8(4), //
3365 B(JumpIfNotHole), U8(11), //
3366 B(LdaConstant), U8(3), //
3367 B(Star), R(6), //
3368 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(6), U8(1), //
3369 B(Ldar), R(5), //
3370 B(StaContextSlot), R(context), U8(4), //
3371 B(PopContext), R(3), //
3372 B(Jump), U8(-110), //
3373 B(LdaUndefined), //
3374 B(Return), //
3375 },
3376 4,
3377 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
3378 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
3379 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3333 }; 3380 };
3334 // clang-format on 3381 // clang-format on
3335 3382
3336 for (size_t i = 0; i < arraysize(snippets); i++) { 3383 for (size_t i = 0; i < arraysize(snippets); i++) {
3337 Handle<BytecodeArray> bytecode_array = 3384 Handle<BytecodeArray> bytecode_array =
3338 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3385 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3339 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3386 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3340 } 3387 }
3341 } 3388 }
3342 3389
(...skipping 2755 matching lines...) Expand 10 before | Expand all | Expand 10 after
6098 // clang-format on 6145 // clang-format on
6099 6146
6100 for (size_t i = 0; i < arraysize(snippets); i++) { 6147 for (size_t i = 0; i < arraysize(snippets); i++) {
6101 Handle<BytecodeArray> bytecode_array = 6148 Handle<BytecodeArray> bytecode_array =
6102 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 6149 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
6103 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 6150 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6104 } 6151 }
6105 } 6152 }
6106 6153
6107 TEST(IllegalRedeclaration) { 6154 TEST(IllegalRedeclaration) {
6155 bool old_legacy_const_flag = FLAG_legacy_const;
6156 FLAG_legacy_const = true;
6157
6108 InitializedHandleScope handle_scope; 6158 InitializedHandleScope handle_scope;
6109 BytecodeGeneratorHelper helper; 6159 BytecodeGeneratorHelper helper;
6110 6160
6111 CHECK_GE(MessageTemplate::kVarRedeclaration, 128); 6161 CHECK_GE(MessageTemplate::kVarRedeclaration, 128);
6112 // Must adapt bytecode if this changes. 6162 // Must adapt bytecode if this changes.
6113 6163
6114 // clang-format off 6164 // clang-format off
6115 ExpectedSnippet<Handle<Object>, 2> snippets[] = { 6165 ExpectedSnippet<Handle<Object>, 2> snippets[] = {
6116 {"const a = 1; { var a = 2; }", 6166 {"const a = 1; { var a = 2; }",
6117 3 * kPointerSize, 6167 3 * kPointerSize,
(...skipping 11 matching lines...) Expand all
6129 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), 6179 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration),
6130 helper.factory()->NewStringFromAsciiChecked("a")}}, 6180 helper.factory()->NewStringFromAsciiChecked("a")}},
6131 }; 6181 };
6132 // clang-format on 6182 // clang-format on
6133 6183
6134 for (size_t i = 0; i < arraysize(snippets); i++) { 6184 for (size_t i = 0; i < arraysize(snippets); i++) {
6135 Handle<BytecodeArray> bytecode_array = 6185 Handle<BytecodeArray> bytecode_array =
6136 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 6186 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
6137 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 6187 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6138 } 6188 }
6189
6190 FLAG_legacy_const = old_legacy_const_flag;
6139 } 6191 }
6140 6192
6141 6193
6142 TEST(ForIn) { 6194 TEST(ForIn) {
6143 InitializedHandleScope handle_scope; 6195 InitializedHandleScope handle_scope;
6144 BytecodeGeneratorHelper helper; 6196 BytecodeGeneratorHelper helper;
6145 Zone zone; 6197 Zone zone;
6146 6198
6147 int simple_flags = 6199 int simple_flags =
6148 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; 6200 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
7087 7139
7088 TEST(ThisFunction) { 7140 TEST(ThisFunction) {
7089 InitializedHandleScope handle_scope; 7141 InitializedHandleScope handle_scope;
7090 BytecodeGeneratorHelper helper; 7142 BytecodeGeneratorHelper helper;
7091 7143
7092 int closure = Register::function_closure().index(); 7144 int closure = Register::function_closure().index();
7093 7145
7094 // clang-format off 7146 // clang-format off
7095 ExpectedSnippet<int> snippets[] = { 7147 ExpectedSnippet<int> snippets[] = {
7096 {"var f;\n f = function f() { }", 7148 {"var f;\n f = function f() { }",
7097 1 * kPointerSize, 7149 2 * kPointerSize,
7098 1, 7150 1,
7099 10, 7151 19,
7100 { 7152 {
7101 B(LdaTheHole), // 7153 B(LdaTheHole), //
7102 B(Star), R(0), // 7154 B(Star), R(0), //
7103 B(StackCheck), // 7155 B(StackCheck), //
7104 B(Ldar), R(closure), // 7156 B(Ldar), R(closure), //
7105 B(Star), R(0), // 7157 B(Star), R(1), //
7106 B(LdaUndefined), // 7158 B(Ldar), R(0), //
7107 B(Return), // 7159 B(JumpIfNotHole), U8(5), //
7160 B(Mov), R(1), R(0), //
7161 B(Ldar), R(1), //
7162 B(LdaUndefined), //
7163 B(Return), //
7108 }}, 7164 }},
7109 {"var f;\n f = function f() { return f; }", 7165 {"var f;\n f = function f() { return f; }",
7110 1 * kPointerSize, 7166 2 * kPointerSize,
7111 1, 7167 1,
7112 9, 7168 23,
7113 { 7169 {
7114 B(LdaTheHole), // 7170 B(LdaTheHole), //
7115 B(Star), R(0), // 7171 B(Star), R(0), //
7116 B(StackCheck), // 7172 B(StackCheck), //
7117 B(Ldar), R(closure), // 7173 B(Ldar), R(closure), //
7118 B(Star), R(0), // 7174 B(Star), R(1), //
7119 B(Return), // 7175 B(Ldar), R(0), //
7176 B(JumpIfNotHole), U8(5), //
7177 B(Mov), R(1), R(0), //
7178 B(Ldar), R(1), //
7179 B(Ldar), R(0), //
7180 B(JumpIfNotHole), U8(3), //
7181 B(LdaUndefined), //
7182 B(Return), //
7120 }}, 7183 }},
7121 }; 7184 };
7122 // clang-format on 7185 // clang-format on
7123 7186
7124 for (size_t i = 0; i < arraysize(snippets); i++) { 7187 for (size_t i = 0; i < arraysize(snippets); i++) {
7125 Handle<BytecodeArray> bytecode_array = 7188 Handle<BytecodeArray> bytecode_array =
7126 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 7189 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
7127 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 7190 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7128 } 7191 }
7129 } 7192 }
7130 7193
7131 7194
7132 TEST(NewTarget) { 7195 TEST(NewTarget) {
7133 InitializedHandleScope handle_scope; 7196 InitializedHandleScope handle_scope;
7134 BytecodeGeneratorHelper helper; 7197 BytecodeGeneratorHelper helper;
7135 7198
7136 int new_target = Register::new_target().index(); 7199 int new_target = Register::new_target().index();
7137 7200
7138 // clang-format off 7201 // clang-format off
7139 ExpectedSnippet<int> snippets[] = { 7202 ExpectedSnippet<InstanceType> snippets[] = {
7140 {"return new.target;", 7203 {"return new.target;",
7141 1 * kPointerSize, 7204 2 * kPointerSize,
7142 1, 7205 1,
7143 8, 7206 19,
7144 { 7207 {
7145 B(Ldar), R(new_target), // 7208 B(Ldar), R(new_target), //
7146 B(Star), R(0), // 7209 B(Star), R(0), //
7147 B(StackCheck), // 7210 B(StackCheck), //
7148 B(Ldar), R(0), // 7211 B(Ldar), R(0), //
7149 B(Return), // 7212 B(JumpIfNotHole), U8(11), //
7150 }}, 7213 B(LdaConstant), U8(0), //
7214 B(Star), R(1), //
7215 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
7216 B(Return), //
7217 },
7218 1,
7219 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
7151 {"new.target;", 7220 {"new.target;",
7152 1 * kPointerSize, 7221 2 * kPointerSize,
7153 1, 7222 1,
7154 9, 7223 20,
7155 { 7224 {
7156 B(Ldar), R(new_target), // 7225 B(Ldar), R(new_target), //
7157 B(Star), R(0), // 7226 B(Star), R(0), //
7158 B(StackCheck), // 7227 B(StackCheck), //
7159 B(Ldar), R(0), // 7228 B(Ldar), R(0), //
7160 B(LdaUndefined), // 7229 B(JumpIfNotHole), U8(11), //
7161 B(Return), // 7230 B(LdaConstant), U8(0), //
7162 }}, 7231 B(Star), R(1), //
7163 }; 7232 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
7233 B(LdaUndefined), //
7234 B(Return), //
7235 },
7236 1,
7237 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}};
7164 // clang-format on 7238 // clang-format on
7165 7239
7166 for (size_t i = 0; i < arraysize(snippets); i++) { 7240 for (size_t i = 0; i < arraysize(snippets); i++) {
7167 Handle<BytecodeArray> bytecode_array = 7241 Handle<BytecodeArray> bytecode_array =
7168 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 7242 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7169 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 7243 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7170 } 7244 }
7171 } 7245 }
7172 7246
7173 7247
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
8238 BytecodeGeneratorHelper helper; 8312 BytecodeGeneratorHelper helper;
8239 8313
8240 for (size_t i = 0; i < arraysize(snippets); ++i) { 8314 for (size_t i = 0; i < arraysize(snippets); ++i) {
8241 std::string body = prologue + snippets[i].code_snippet; 8315 std::string body = prologue + snippets[i].code_snippet;
8242 Handle<BytecodeArray> bytecode_array = 8316 Handle<BytecodeArray> bytecode_array =
8243 helper.MakeBytecodeForFunctionBody(body.c_str()); 8317 helper.MakeBytecodeForFunctionBody(body.c_str());
8244 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 8318 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8245 } 8319 }
8246 } 8320 }
8247 8321
8322 TEST(ConstVariable) {
8323 InitializedHandleScope handle_scope;
8324 BytecodeGeneratorHelper helper;
8325 // clang-format off
8326 ExpectedSnippet<const char*> snippets[] = {
8327 {"const x = 10;",
8328 1 * kPointerSize,
8329 1,
8330 10,
8331 {
8332 B(LdaTheHole), //
8333 B(Star), R(0), //
8334 B(StackCheck), //
8335 B(LdaSmi8), U8(10), //
8336 B(Star), R(0), //
8337 B(LdaUndefined), //
8338 B(Return) //
8339 },
8340 0},
8341 {"const x = 10; return x;",
8342 2 * kPointerSize,
8343 1,
8344 20,
8345 {
8346 B(LdaTheHole), //
8347 B(Star), R(0), //
8348 B(StackCheck), //
8349 B(LdaSmi8), U8(10), //
8350 B(Star), R(0), //
8351 B(JumpIfNotHole), U8(11), //
8352 B(LdaConstant), U8(0), //
8353 B(Star), R(1), //
8354 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
8355 B(Return) //
8356 },
8357 1,
8358 {"x"}},
8359 {"const x = ( x = 20);",
8360 3 * kPointerSize,
8361 1,
8362 32,
8363 {
8364 B(LdaTheHole), //
8365 B(Star), R(0), //
8366 B(StackCheck), //
8367 B(LdaSmi8), U8(20), //
8368 B(Star), R(1), //
8369 B(Ldar), R(0), //
8370 B(JumpIfNotHole), U8(11), //
8371 B(LdaConstant), U8(0), //
8372 B(Star), R(2), //
8373 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8374 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
8375 /* */ U8(0), //
8376 B(Ldar), R(1), //
8377 B(Star), R(0), //
8378 B(LdaUndefined), //
8379 B(Return) //
8380 },
8381 1,
8382 {"x"}},
8383 {"const x = 10; x = 20;",
8384 3 * kPointerSize,
8385 1,
8386 36,
8387 {
8388 B(LdaTheHole), //
8389 B(Star), R(0), //
8390 B(StackCheck), //
8391 B(LdaSmi8), U8(10), //
8392 B(Star), R(0), //
8393 B(LdaSmi8), U8(20), //
8394 B(Star), R(1), //
8395 B(Ldar), R(0), //
8396 B(JumpIfNotHole), U8(11), //
8397 B(LdaConstant), U8(0), //
8398 B(Star), R(2), //
8399 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8400 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
8401 /* */ U8(0), //
8402 B(Ldar), R(1), //
8403 B(Star), R(0), //
8404 B(LdaUndefined), //
8405 B(Return) //
8406 },
8407 1,
8408 {"x"}},
8409 };
8410 // clang-format on
8411
8412 for (size_t i = 0; i < arraysize(snippets); i++) {
8413 Handle<BytecodeArray> bytecode_array =
8414 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8415 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8416 }
8417 }
8418
8419 TEST(LetVariable) {
8420 InitializedHandleScope handle_scope;
8421 BytecodeGeneratorHelper helper;
8422
8423 // clang-format off
8424 ExpectedSnippet<const char*> snippets[] = {
8425 {"let x = 10;",
8426 1 * kPointerSize,
8427 1,
8428 10,
8429 {
8430 B(LdaTheHole), //
8431 B(Star), R(0), //
8432 B(StackCheck), //
8433 B(LdaSmi8), U8(10), //
8434 B(Star), R(0), //
8435 B(LdaUndefined), //
8436 B(Return) //
8437 },
8438 0},
8439 {"let x = 10; return x;",
8440 2 * kPointerSize,
8441 1,
8442 20,
8443 {
8444 B(LdaTheHole), //
8445 B(Star), R(0), //
8446 B(StackCheck), //
8447 B(LdaSmi8), U8(10), //
8448 B(Star), R(0), //
8449 B(JumpIfNotHole), U8(11), //
8450 B(LdaConstant), U8(0), //
8451 B(Star), R(1), //
8452 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
8453 B(Return) //
8454 },
8455 1,
8456 {"x"}},
8457 {"let x = (x = 20);",
8458 3 * kPointerSize,
8459 1,
8460 27,
8461 {
8462 B(LdaTheHole), //
8463 B(Star), R(0), //
8464 B(StackCheck), //
8465 B(LdaSmi8), U8(20), //
8466 B(Star), R(1), //
8467 B(Ldar), R(0), //
8468 B(JumpIfNotHole), U8(11), //
8469 B(LdaConstant), U8(0), //
8470 B(Star), R(2), //
8471 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8472 B(Ldar), R(1), //
8473 B(Star), R(0), //
8474 B(LdaUndefined), //
8475 B(Return) //
8476 },
8477 1,
8478 {"x"}},
8479 {"let x = 10; x = 20;",
8480 3 * kPointerSize,
8481 1,
8482 31,
8483 {
8484 B(LdaTheHole), //
8485 B(Star), R(0), //
8486 B(StackCheck), //
8487 B(LdaSmi8), U8(10), //
8488 B(Star), R(0), //
8489 B(LdaSmi8), U8(20), //
8490 B(Star), R(1), //
8491 B(Ldar), R(0), //
8492 B(JumpIfNotHole), U8(11), //
8493 B(LdaConstant), U8(0), //
8494 B(Star), R(2), //
8495 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8496 B(Ldar), R(1), //
8497 B(Star), R(0), //
8498 B(LdaUndefined), //
8499 B(Return) //
8500 },
8501 1,
8502 {"x"}},
8503 };
8504 // clang-format on
8505
8506 for (size_t i = 0; i < arraysize(snippets); i++) {
8507 Handle<BytecodeArray> bytecode_array =
8508 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8509 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8510 }
8511 }
8512
8513 TEST(LegacyConstVariable) {
8514 bool old_legacy_const_flag = FLAG_legacy_const;
8515 FLAG_legacy_const = true;
8516
8517 InitializedHandleScope handle_scope;
8518 BytecodeGeneratorHelper helper;
8519
8520 // clang-format off
8521 ExpectedSnippet<const char*> snippets[] = {
8522 {"const x = 10;",
8523 2 * kPointerSize,
8524 1,
8525 19,
8526 {
8527 B(LdaTheHole), //
8528 B(Star), R(0), //
8529 B(StackCheck), //
8530 B(LdaSmi8), U8(10), //
8531 B(Star), R(1), //
8532 B(Ldar), R(0), //
8533 B(JumpIfNotHole), U8(5), //
8534 B(Mov), R(1), R(0), //
8535 B(Ldar), R(1), //
8536 B(LdaUndefined), //
8537 B(Return) //
8538 },
8539 0},
8540 {"const x = 10; return x;",
8541 2 * kPointerSize,
8542 1,
8543 23,
8544 {
8545 B(LdaTheHole), //
8546 B(Star), R(0), //
8547 B(StackCheck), //
8548 B(LdaSmi8), U8(10), //
8549 B(Star), R(1), //
8550 B(Ldar), R(0), //
8551 B(JumpIfNotHole), U8(5), //
8552 B(Mov), R(1), R(0), //
8553 B(Ldar), R(1), //
8554 B(Ldar), R(0), //
8555 B(JumpIfNotHole), U8(3), //
8556 B(LdaUndefined), //
8557 B(Return) //
8558 },
8559 0},
8560 {"const x = ( x = 20);",
8561 2 * kPointerSize,
8562 1,
8563 23,
8564 {
8565 B(LdaTheHole), //
8566 B(Star), R(0), //
8567 B(StackCheck), //
8568 B(LdaSmi8), U8(20), //
8569 B(Star), R(1), //
8570 B(Ldar), R(0), //
8571 B(Ldar), R(1), //
8572 B(Ldar), R(0), //
8573 B(JumpIfNotHole), U8(5), //
8574 B(Mov), R(1), R(0), //
8575 B(Ldar), R(1), //
8576 B(LdaUndefined), //
8577 B(Return) //
8578 },
8579 0},
8580 {"const x = 10; x = 20;",
8581 2 * kPointerSize,
8582 1,
8583 27,
8584 {
8585 B(LdaTheHole), //
8586 B(Star), R(0), //
8587 B(StackCheck), //
8588 B(LdaSmi8), U8(10), //
8589 B(Star), R(1), //
8590 B(Ldar), R(0), //
8591 B(JumpIfNotHole), U8(5), //
8592 B(Mov), R(1), R(0), //
8593 B(Ldar), R(1), //
8594 B(LdaSmi8), U8(20), //
8595 B(Star), R(1), //
8596 B(Ldar), R(0), //
8597 B(Ldar), R(1), //
8598 B(LdaUndefined), //
8599 B(Return) //
8600 },
8601 0},
8602 };
8603 // clang-format on
8604
8605 for (size_t i = 0; i < arraysize(snippets); i++) {
8606 Handle<BytecodeArray> bytecode_array =
8607 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8608 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8609 }
8610
8611 FLAG_legacy_const = old_legacy_const_flag;
8612 }
8613
8614 TEST(ConstVariableContextSlot) {
8615 InitializedHandleScope handle_scope;
8616 BytecodeGeneratorHelper helper;
8617
8618 int closure = Register::function_closure().index();
8619 int context = Register::current_context().index();
8620
8621 // TODO(mythria): Add tests for initialization of this via super calls.
8622 // TODO(mythria): Add tests that walk the context chain.
8623 // clang-format off
8624 ExpectedSnippet<InstanceType> snippets[] = {
8625 {"const x = 10; function f1() {return x;}",
8626 2 * kPointerSize,
8627 1,
8628 24,
8629 {
8630 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8631 U8(1), //
8632 B(PushContext), R(1), //
8633 B(LdaTheHole), //
8634 B(StaContextSlot), R(context), U8(4), //
8635 B(CreateClosure), U8(0), U8(0), //
8636 B(Star), R(0), //
8637 B(StackCheck), //
8638 B(LdaSmi8), U8(10), //
8639 B(StaContextSlot), R(context), U8(4), //
8640 B(LdaUndefined), //
8641 B(Return) //
8642 },
8643 1,
8644 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
8645 {"const x = 10; function f1() {return x;} return x;",
8646 3 * kPointerSize,
8647 1,
8648 37,
8649 {
8650 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8651 U8(1), //
8652 B(PushContext), R(1), //
8653 B(LdaTheHole), //
8654 B(StaContextSlot), R(context), U8(4), //
8655 B(CreateClosure), U8(0), U8(0), //
8656 B(Star), R(0), //
8657 B(StackCheck), //
8658 B(LdaSmi8), U8(10), //
8659 B(StaContextSlot), R(context), U8(4), //
8660 B(LdaContextSlot), R(context), U8(4), //
8661 B(JumpIfNotHole), U8(11), //
8662 B(LdaConstant), U8(1), //
8663 B(Star), R(2), //
8664 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8665 B(Return) //
8666 },
8667 2,
8668 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8669 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8670 {"const x = (x = 20); function f1() {return x;}",
8671 4 * kPointerSize,
8672 1,
8673 50,
8674 {
8675 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8676 /* */ U8(1), //
8677 B(PushContext), R(1), //
8678 B(LdaTheHole), //
8679 B(StaContextSlot), R(context), U8(4), //
8680 B(CreateClosure), U8(0), U8(0), //
8681 B(Star), R(0), //
8682 B(StackCheck), //
8683 B(LdaSmi8), U8(20), //
8684 B(Star), R(2), //
8685 B(LdaContextSlot), R(context), U8(4), //
8686 B(JumpIfNotHole), U8(11), //
8687 B(LdaConstant), U8(1), //
8688 B(Star), R(3), //
8689 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8690 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
8691 U8(0), //
8692 B(Ldar), R(2), //
8693 B(StaContextSlot), R(context), U8(4), //
8694 B(StaContextSlot), R(context), U8(4), //
8695 B(LdaUndefined), //
8696 B(Return) //
8697 },
8698 2,
8699 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8700 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8701 {"const x = 10; x = 20; function f1() {return x;}",
8702 4 * kPointerSize,
8703 1,
8704 52,
8705 {
8706 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8707 /* */ U8(1), //
8708 B(PushContext), R(1), //
8709 B(LdaTheHole), //
8710 B(StaContextSlot), R(context), U8(4), //
8711 B(CreateClosure), U8(0), U8(0), //
8712 B(Star), R(0), //
8713 B(StackCheck), //
8714 B(LdaSmi8), U8(10), //
8715 B(StaContextSlot), R(context), U8(4), //
8716 B(LdaSmi8), U8(20), //
8717 B(Star), R(2), //
8718 B(LdaContextSlot), R(context), U8(4), //
8719 B(JumpIfNotHole), U8(11), //
8720 B(LdaConstant), U8(1), //
8721 B(Star), R(3), //
8722 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8723 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
8724 U8(0), //
8725 B(Ldar), R(2), //
8726 B(StaContextSlot), R(context), U8(4), //
8727 B(LdaUndefined), //
8728 B(Return) //
8729 },
8730 2,
8731 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8732 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8733 };
8734 // clang-format on
8735
8736 for (size_t i = 0; i < arraysize(snippets); i++) {
8737 Handle<BytecodeArray> bytecode_array =
8738 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8739 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8740 }
8741 }
8742
8743 TEST(LetVariableContextSlot) {
8744 InitializedHandleScope handle_scope;
8745 BytecodeGeneratorHelper helper;
8746
8747 int closure = Register::function_closure().index();
8748 int context = Register::current_context().index();
8749
8750 // clang-format off
8751 ExpectedSnippet<InstanceType> snippets[] = {
8752 {"let x = 10; function f1() {return x;}",
8753 2 * kPointerSize,
8754 1,
8755 24,
8756 {
8757 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8758 /* */ U8(1), //
8759 B(PushContext), R(1), //
8760 B(LdaTheHole), //
8761 B(StaContextSlot), R(context), U8(4), //
8762 B(CreateClosure), U8(0), U8(0), //
8763 B(Star), R(0), //
8764 B(StackCheck), //
8765 B(LdaSmi8), U8(10), //
8766 B(StaContextSlot), R(context), U8(4), //
8767 B(LdaUndefined), //
8768 B(Return) //
8769 },
8770 1,
8771 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
8772 {"let x = 10; function f1() {return x;} return x;",
8773 3 * kPointerSize,
8774 1,
8775 37,
8776 {
8777 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8778 /* */ U8(1), //
8779 B(PushContext), R(1), //
8780 B(LdaTheHole), //
8781 B(StaContextSlot), R(context), U8(4), //
8782 B(CreateClosure), U8(0), U8(0), //
8783 B(Star), R(0), //
8784 B(StackCheck), //
8785 B(LdaSmi8), U8(10), //
8786 B(StaContextSlot), R(context), U8(4), //
8787 B(LdaContextSlot), R(context), U8(4), //
8788 B(JumpIfNotHole), U8(11), //
8789 B(LdaConstant), U8(1), //
8790 B(Star), R(2), //
8791 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8792 B(Return) //
8793 },
8794 2,
8795 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8796 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8797 {"let x = (x = 20); function f1() {return x;}",
8798 4 * kPointerSize,
8799 1,
8800 45,
8801 {
8802 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8803 /* */ U8(1), //
8804 B(PushContext), R(1), //
8805 B(LdaTheHole), //
8806 B(StaContextSlot), R(context), U8(4), //
8807 B(CreateClosure), U8(0), U8(0), //
8808 B(Star), R(0), //
8809 B(StackCheck), //
8810 B(LdaSmi8), U8(20), //
8811 B(Star), R(2), //
8812 B(LdaContextSlot), R(context), U8(4), //
8813 B(JumpIfNotHole), U8(11), //
8814 B(LdaConstant), U8(1), //
8815 B(Star), R(3), //
8816 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8817 B(Ldar), R(2), //
8818 B(StaContextSlot), R(context), U8(4), //
8819 B(StaContextSlot), R(context), U8(4), //
8820 B(LdaUndefined), //
8821 B(Return) //
8822 },
8823 2,
8824 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8825 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8826 {"let x = 10; x = 20; function f1() {return x;}",
8827 4 * kPointerSize,
8828 1,
8829 47,
8830 {
8831 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8832 /* */ U8(1), //
8833 B(PushContext), R(1), //
8834 B(LdaTheHole), //
8835 B(StaContextSlot), R(context), U8(4), //
8836 B(CreateClosure), U8(0), U8(0), //
8837 B(Star), R(0), //
8838 B(StackCheck), //
8839 B(LdaSmi8), U8(10), //
8840 B(StaContextSlot), R(context), U8(4), //
8841 B(LdaSmi8), U8(20), //
8842 B(Star), R(2), //
8843 B(LdaContextSlot), R(context), U8(4), //
8844 B(JumpIfNotHole), U8(11), //
8845 B(LdaConstant), U8(1), //
8846 B(Star), R(3), //
8847 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8848 B(Ldar), R(2), //
8849 B(StaContextSlot), R(context), U8(4), //
8850 B(LdaUndefined), //
8851 B(Return) //
8852 },
8853 2,
8854 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8855 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8856 };
8857 // clang-format on
8858
8859 for (size_t i = 0; i < arraysize(snippets); i++) {
8860 Handle<BytecodeArray> bytecode_array =
8861 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8862 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8863 }
8864 }
8865
8248 TEST(DoExpression) { 8866 TEST(DoExpression) {
8249 bool old_flag = FLAG_harmony_do_expressions; 8867 bool old_flag = FLAG_harmony_do_expressions;
8250 FLAG_harmony_do_expressions = true; 8868 FLAG_harmony_do_expressions = true;
8251 8869
8252 InitializedHandleScope handle_scope; 8870 InitializedHandleScope handle_scope;
8253 BytecodeGeneratorHelper helper; 8871 BytecodeGeneratorHelper helper;
8254 8872
8255 // clang-format off 8873 // clang-format off
8256 ExpectedSnippet<const char*> snippets[] = { 8874 ExpectedSnippet<const char*> snippets[] = {
8257 {"var a = do { }; return a;", 8875 {"var a = do { }; return a;",
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
8592 for (size_t i = 0; i < arraysize(snippets); i++) { 9210 for (size_t i = 0; i < arraysize(snippets); i++) {
8593 Handle<BytecodeArray> bytecode_array = 9211 Handle<BytecodeArray> bytecode_array =
8594 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 9212 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8595 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 9213 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8596 } 9214 }
8597 } 9215 }
8598 9216
8599 } // namespace interpreter 9217 } // namespace interpreter
8600 } // namespace internal 9218 } // namespace internal
8601 } // namespace v8 9219 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-run-bytecode-graph-builder.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698