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

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

Powered by Google App Engine
This is Rietveld 408576698