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

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: Refactored VisitVariableAssignment. 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 26 matching lines...) Expand all
67 Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) { 66 Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) {
68 static const char kFormat[] = "function %s() { %s }\n%s();"; 67 static const char kFormat[] = "function %s() { %s }\n%s();";
69 static const int kFormatLength = arraysize(kFormat); 68 static const int kFormatLength = arraysize(kFormat);
70 int length = kFormatLength + 2 * StrLength(kFunctionName) + StrLength(body); 69 int length = kFormatLength + 2 * StrLength(kFunctionName) + StrLength(body);
71 ScopedVector<char> program(length); 70 ScopedVector<char> program(length);
72 length = SNPrintF(program, kFormat, kFunctionName, body, kFunctionName); 71 length = SNPrintF(program, kFormat, kFunctionName, body, kFunctionName);
73 CHECK_GT(length, 0); 72 CHECK_GT(length, 0);
74 return MakeBytecode(program.start(), kFunctionName); 73 return MakeBytecode(program.start(), kFunctionName);
75 } 74 }
76 75
76 Handle<BytecodeArray> MakeBytecodeForFunctionBodyWithLegacyConst(
77 const char* body) {
78 i::FLAG_legacy_const = true;
rmcilroy 2016/02/03 12:28:27 You can just set and restore these flags in the te
mythria 2016/02/04 10:28:53 Done.
79 Handle<BytecodeArray> bytecode_array = MakeBytecodeForFunctionBody(body);
80 i::FLAG_legacy_const = false;
81 return bytecode_array;
82 }
83
77 Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) { 84 Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) {
78 ScopedVector<char> program(3072); 85 ScopedVector<char> program(3072);
79 SNPrintF(program, "%s\n%s();", function, kFunctionName); 86 SNPrintF(program, "%s\n%s();", function, kFunctionName);
80 return MakeBytecode(program.start(), kFunctionName); 87 return MakeBytecode(program.start(), kFunctionName);
81 } 88 }
82 89
83 Handle<BytecodeArray> MakeBytecodeForFunctionNoFilter(const char* function) { 90 Handle<BytecodeArray> MakeBytecodeForFunctionNoFilter(const char* function) {
84 ScopedVector<char> program(3072); 91 ScopedVector<char> program(3072);
85 SNPrintF(program, "%s\n%s();", function, kFunctionName); 92 SNPrintF(program, "%s\n%s();", function, kFunctionName);
86 return MakeBytecode(program.start(), "*", kFunctionName); 93 return MakeBytecode(program.start(), "*", kFunctionName);
(...skipping 2198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 B(Ldar), R(0), // 2292 B(Ldar), R(0), //
2286 B(Return), // 2293 B(Return), //
2287 }}, 2294 }},
2288 {"outer: {\n" 2295 {"outer: {\n"
2289 " let y = 10;" 2296 " let y = 10;"
2290 " function f() { return y; }\n" 2297 " function f() { return y; }\n"
2291 " break outer;\n" 2298 " break outer;\n"
2292 "}\n", 2299 "}\n",
2293 5 * kPointerSize, 2300 5 * kPointerSize,
2294 1, 2301 1,
2295 39, 2302 50,
2296 { 2303 {
2297 B(LdaConstant), U8(0), // 2304 B(LdaConstant), U8(0), //
2298 B(Star), R(3), // 2305 B(Star), R(3), //
2299 B(Ldar), R(closure), // 2306 B(Ldar), R(closure), //
2300 B(Star), R(4), // 2307 B(Star), R(4), //
2301 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // 2308 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), //
2302 B(PushContext), R(2), // 2309 B(PushContext), R(2), //
2303 B(LdaTheHole), // 2310 B(LdaTheHole), //
2304 B(StaContextSlot), R(context), U8(4), // 2311 B(StaContextSlot), R(context), U8(4), //
2305 B(CreateClosure), U8(1), U8(0), // 2312 B(CreateClosure), U8(1), U8(0), //
2306 B(Star), R(0), // 2313 B(Star), R(0), //
2307 B(LdaSmi8), U8(10), // 2314 B(LdaSmi8), U8(10), //
2308 B(StaContextSlot), R(context), U8(4), // 2315 B(StaContextSlot), R(context), U8(4), //
2309 B(Ldar), R(0), // 2316 B(Ldar), R(0), //
2310 B(Star), R(1), // 2317 B(JumpIfNotHole), U8(11), //
2311 B(Jump), U8(2), // 2318 B(LdaConstant), U8(2), //
2312 B(PopContext), R(2), // 2319 B(Star), R(3), //
2313 B(LdaUndefined), // 2320 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
2314 B(Return), // 2321 B(Star), R(1), //
2322 B(Jump), U8(2), //
2323 B(PopContext), R(2), //
2324 B(LdaUndefined), //
2325 B(Return), //
2315 }, 2326 },
2316 2, 2327 3,
2317 {InstanceType::FIXED_ARRAY_TYPE, 2328 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
2318 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2329 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2319 {"let x = 1;\n" 2330 {"let x = 1;\n"
2320 "outer: {\n" 2331 "outer: {\n"
2321 " inner: {\n" 2332 " inner: {\n"
2322 " let y = 2;\n" 2333 " let y = 2;\n"
2323 " function f() { return x + y; }\n" 2334 " function f() { return x + y; }\n"
2324 " if (y) break outer;\n" 2335 " if (y) break outer;\n"
2325 " y = 3;\n" 2336 " y = 3;\n"
2326 " }\n" 2337 " }\n"
2327 "}\n" 2338 "}\n"
2328 "x = 4;", 2339 "x = 4;",
2329 6 * kPointerSize, 2340 6 * kPointerSize,
2330 1, 2341 1,
2331 72, 2342 130,
2332 { 2343 {
2333 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // 2344 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
2334 U8(1), // 2345 U8(1), //
2335 B(PushContext), R(2), // 2346 B(PushContext), R(2), //
2336 B(LdaTheHole), // 2347 B(LdaTheHole), //
2337 B(StaContextSlot), R(context), U8(4), // 2348 B(StaContextSlot), R(context), U8(4), //
2338 B(LdaSmi8), U8(1), // 2349 B(LdaSmi8), U8(1), //
2339 B(StaContextSlot), R(context), U8(4), // 2350 B(StaContextSlot), R(context), U8(4), //
2340 B(LdaConstant), U8(0), // 2351 B(LdaConstant), U8(0), //
2341 B(Star), R(4), // 2352 B(Star), R(4), //
2342 B(Ldar), R(closure), // 2353 B(Ldar), R(closure), //
2343 B(Star), R(5), // 2354 B(Star), R(5), //
2344 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // 2355 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
2345 B(PushContext), R(3), // 2356 B(PushContext), R(3), //
2346 B(LdaTheHole), // 2357 B(LdaTheHole), //
2347 B(StaContextSlot), R(context), U8(4), // 2358 B(StaContextSlot), R(context), U8(4), //
2348 B(CreateClosure), U8(1), U8(0), // 2359 B(CreateClosure), U8(1), U8(0), //
2349 B(Star), R(0), // 2360 B(Star), R(0), //
2350 B(LdaSmi8), U8(2), // 2361 B(LdaSmi8), U8(2), //
2351 B(StaContextSlot), R(context), U8(4), // 2362 B(StaContextSlot), R(context), U8(4), //
2352 B(Ldar), R(0), // 2363 B(Ldar), R(0), //
2353 B(Star), R(1), // 2364 B(JumpIfNotHole), U8(11), //
2354 B(LdaContextSlot), R(context), U8(4), // 2365 B(LdaConstant), U8(2), //
2355 B(JumpIfToBooleanFalse), U8(6), // 2366 B(Star), R(4), //
2356 B(PopContext), R(3), // 2367 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4),
2357 B(Jump), U8(9), // 2368 U8(1), // 58
rmcilroy 2016/02/03 12:28:27 Fix indenting and remove "58" Note: A way of inde
mythria 2016/02/04 10:28:53 Done. Sorry they were meant to be temporary offset
2358 B(LdaSmi8), U8(3), // 2369 B(Star), R(1), //
2359 B(StaContextSlot), R(context), U8(4), // 2370 B(LdaContextSlot), R(context), U8(4), //
2360 B(PopContext), R(3), // 2371 B(JumpIfNotHole), U8(11), //
2361 B(LdaSmi8), U8(4), // 2372 B(LdaConstant), U8(3), //
2362 B(StaContextSlot), R(context), U8(4), // 2373 B(Star), R(4), //
2363 B(LdaUndefined), // 2374 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
2364 B(Return), // 2375 B(JumpIfToBooleanFalse), U8(6), //
2365 }, 2376 B(PopContext), R(3), //
2366 2, 2377 B(Jump), U8(27), //
2367 {InstanceType::FIXED_ARRAY_TYPE, 2378 B(LdaSmi8), U8(3), //
2368 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2379 B(Star), R(4), //
2380 B(LdaContextSlot), R(context), U8(4), //
2381 B(JumpIfNotHole), U8(11), //
2382 B(LdaConstant), U8(3), //
2383 B(Star), R(5), //
2384 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), //
2385 B(Ldar), R(4), // 100
rmcilroy 2016/02/03 12:28:27 ditto
mythria 2016/02/04 10:28:53 Done.
2386 B(StaContextSlot), R(context), U8(4), //
2387 B(PopContext), R(3), //
2388 B(LdaSmi8), U8(4), //
2389 B(Star), R(4), //
2390 B(LdaContextSlot), R(context), U8(4), //
2391 B(JumpIfNotHole), U8(11), //
2392 B(LdaConstant), U8(4), //
2393 B(Star), R(5), //
2394 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), //
2395 B(Ldar), R(4), //
2396 B(StaContextSlot), R(context), U8(4), //
2397 B(LdaUndefined), //
2398 B(Return), //
2399 },
2400 5,
2401 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
2402 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2403 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
2404 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
2369 }; 2405 };
2370 2406
2371 for (size_t i = 0; i < arraysize(snippets); i++) { 2407 for (size_t i = 0; i < arraysize(snippets); i++) {
2372 Handle<BytecodeArray> bytecode_array = 2408 Handle<BytecodeArray> bytecode_array =
2373 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2409 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2374 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2410 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2375 } 2411 }
2376 } 2412 }
2377 2413
2378 2414
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2991 B(Inc), // 3027 B(Inc), //
2992 B(Star), R(1), // 3028 B(Star), R(1), //
2993 B(Jump), U8(-26), // 3029 B(Jump), U8(-26), //
2994 B(Ldar), R(0), // 3030 B(Ldar), R(0), //
2995 B(Return), // 3031 B(Return), //
2996 }, 3032 },
2997 0}, 3033 0},
2998 {"var a = 0;\n" 3034 {"var a = 0;\n"
2999 "while (a) {\n" 3035 "while (a) {\n"
3000 " { \n" 3036 " { \n"
3001 " let z = 1;\n" 3037 " let z = 1;\n"
3002 " function f() { z = 2; }\n" 3038 " function f() { z = 2; }\n"
3003 " if (z) continue;\n" 3039 " if (z) continue;\n"
3004 " z++;\n" 3040 " z++;\n"
3005 " }\n" 3041 " }\n"
3006 "}\n", 3042 "}\n",
3007 6 * kPointerSize, 3043 7 * kPointerSize,
3008 1, 3044 1,
3009 65, 3045 116,
3010 { 3046 {
3011 B(LdaZero), // 3047 B(LdaZero), //
3012 B(Star), R(1), // 3048 B(Star), R(1), //
3013 B(Ldar), R(1), // 3049 B(Ldar), R(1), //
3014 B(JumpIfToBooleanFalse), U8(58), // 3050 B(JumpIfToBooleanFalse), U8(109), //
3015 B(LdaConstant), U8(0), // 3051 B(LdaConstant), U8(0), //
3016 B(Star), R(4), // 3052 B(Star), R(4), //
3017 B(Ldar), R(closure), // 3053 B(Ldar), R(closure), //
3018 B(Star), R(5), // 3054 B(Star), R(5), //
3019 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // 3055 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), //
3020 B(PushContext), R(3), // 3056 B(PushContext), R(3), //
3021 B(LdaTheHole), // 3057 B(LdaTheHole), //
3022 B(StaContextSlot), R(context), U8(4), // 3058 B(StaContextSlot), R(context), U8(4), //
3023 B(CreateClosure), U8(1), U8(0), // 3059 B(CreateClosure), U8(1), U8(0), //
3024 B(Star), R(0), // 3060 B(Star), R(0), //
3025 B(LdaSmi8), U8(1), // 3061 B(LdaSmi8), U8(1), //
3026 B(StaContextSlot), R(context), U8(4), // 3062 B(StaContextSlot), R(context), U8(4), //
3027 B(Ldar), R(0), // 3063 B(Ldar), R(0), //
3028 B(Star), R(2), // 3064 B(JumpIfNotHole), U8(11), //
3029 B(LdaContextSlot), R(context), U8(4), // 3065 B(LdaConstant), U8(2), //
3030 B(JumpIfToBooleanFalse), U8(6), // 3066 B(Star), R(4), //
3031 B(PopContext), R(3), // 3067 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3032 B(Jump), U8(-44), // 3068 B(Star), R(2), //
3033 B(LdaContextSlot), R(context), U8(4), // 3069 B(LdaContextSlot), R(context), U8(4), //
3034 B(ToNumber), // 3070 B(JumpIfNotHole), U8(11), //
3035 B(Star), R(4), // 3071 B(LdaConstant), U8(3), //
3036 B(Inc), // 3072 B(Star), R(4), //
3037 B(StaContextSlot), R(context), U8(4), // 3073 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3038 B(PopContext), R(3), // 3074 B(JumpIfToBooleanFalse), U8(6), //
3039 B(Jump), U8(-58), // 3075 B(PopContext), R(3), //
3040 B(LdaUndefined), // 3076 B(Jump), U8(-66), //
3041 B(Return), // 3077 B(LdaContextSlot), R(context), U8(4), //
3042 }, 3078 B(JumpIfNotHole), U8(11), //
3043 2, 3079 B(LdaConstant), U8(3), //
3044 {InstanceType::FIXED_ARRAY_TYPE, 3080 B(Star), R(4), //
3045 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 3081 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), //
3082 B(ToNumber), //
3083 B(Star), R(4), //
3084 B(Inc), //
3085 B(Star), R(5), //
3086 B(LdaContextSlot), R(context), U8(4), //
3087 B(JumpIfNotHole), U8(11), //
3088 B(LdaConstant), U8(3), //
3089 B(Star), R(6), //
3090 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(6), U8(1), //
3091 B(Ldar), R(5), //
3092 B(StaContextSlot), R(context), U8(4), //
3093 B(PopContext), R(3), //
3094 B(Jump), U8(-109), //
3095 B(LdaUndefined), //
3096 B(Return), //
3097 },
3098 4,
3099 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE,
3100 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
3101 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3046 }; 3102 };
3047 3103
3048 for (size_t i = 0; i < arraysize(snippets); i++) { 3104 for (size_t i = 0; i < arraysize(snippets); i++) {
3049 Handle<BytecodeArray> bytecode_array = 3105 Handle<BytecodeArray> bytecode_array =
3050 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3106 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3051 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3107 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3052 } 3108 }
3053 } 3109 }
3054 3110
3055 3111
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after
5512 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), // 5568 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), //
5513 B(Throw), // 5569 B(Throw), //
5514 }, 5570 },
5515 2, 5571 2,
5516 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), 5572 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration),
5517 helper.factory()->NewStringFromAsciiChecked("a")}}, 5573 helper.factory()->NewStringFromAsciiChecked("a")}},
5518 }; 5574 };
5519 5575
5520 for (size_t i = 0; i < arraysize(snippets); i++) { 5576 for (size_t i = 0; i < arraysize(snippets); i++) {
5521 Handle<BytecodeArray> bytecode_array = 5577 Handle<BytecodeArray> bytecode_array =
5522 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 5578 helper.MakeBytecodeForFunctionBodyWithLegacyConst(
5579 snippets[i].code_snippet);
5523 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5580 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5524 } 5581 }
5525 } 5582 }
5526 5583
5527 5584
5528 TEST(ForIn) { 5585 TEST(ForIn) {
5529 InitializedHandleScope handle_scope; 5586 InitializedHandleScope handle_scope;
5530 BytecodeGeneratorHelper helper; 5587 BytecodeGeneratorHelper helper;
5531 Zone zone; 5588 Zone zone;
5532 5589
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
6410 6467
6411 6468
6412 TEST(ThisFunction) { 6469 TEST(ThisFunction) {
6413 InitializedHandleScope handle_scope; 6470 InitializedHandleScope handle_scope;
6414 BytecodeGeneratorHelper helper; 6471 BytecodeGeneratorHelper helper;
6415 6472
6416 int closure = Register::function_closure().index(); 6473 int closure = Register::function_closure().index();
6417 6474
6418 ExpectedSnippet<int> snippets[] = { 6475 ExpectedSnippet<int> snippets[] = {
6419 {"var f;\n f = function f() { }", 6476 {"var f;\n f = function f() { }",
6420 1 * kPointerSize, 6477 2 * kPointerSize,
6421 1, 6478 1,
6422 9, 6479 18,
6423 { 6480 {
6424 B(LdaTheHole), // 6481 B(LdaTheHole), //
6425 B(Star), R(0), // 6482 B(Star), R(0), //
6426 B(Ldar), R(closure), // 6483 B(Ldar), R(closure), //
6427 B(Star), R(0), // 6484 B(Star), R(1), //
6428 B(LdaUndefined), // 6485 B(Ldar), R(0), //
6429 B(Return), // 6486 B(JumpIfNotHole), U8(5), //
6487 B(Mov), R(1), R(0), //
6488 B(Ldar), R(1), //
6489 B(LdaUndefined), //
6490 B(Return), //
6430 }}, 6491 }},
6431 {"var f;\n f = function f() { return f; }", 6492 {"var f;\n f = function f() { return f; }",
6432 1 * kPointerSize, 6493 2 * kPointerSize,
6433 1, 6494 1,
6434 8, 6495 22,
6435 { 6496 {
6436 B(LdaTheHole), // 6497 B(LdaTheHole), //
6437 B(Star), R(0), // 6498 B(Star), R(0), //
6438 B(Ldar), R(closure), // 6499 B(Ldar), R(closure), //
6439 B(Star), R(0), // 6500 B(Star), R(1), //
6440 B(Return), // 6501 B(Ldar), R(0), //
6502 B(JumpIfNotHole), U8(5), //
6503 B(Mov), R(1), R(0), //
6504 B(Ldar), R(1), //
6505 B(Ldar), R(0), //
6506 B(JumpIfNotHole), U8(3), //
6507 B(LdaUndefined), //
6508 B(Return), //
6441 }}, 6509 }},
6442 }; 6510 };
6443 6511
6444 for (size_t i = 0; i < arraysize(snippets); i++) { 6512 for (size_t i = 0; i < arraysize(snippets); i++) {
6445 Handle<BytecodeArray> bytecode_array = 6513 Handle<BytecodeArray> bytecode_array =
6446 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 6514 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
6447 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 6515 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6448 } 6516 }
6449 } 6517 }
6450 6518
6451 6519
6452 TEST(NewTarget) { 6520 TEST(NewTarget) {
6453 InitializedHandleScope handle_scope; 6521 InitializedHandleScope handle_scope;
6454 BytecodeGeneratorHelper helper; 6522 BytecodeGeneratorHelper helper;
6455 6523
6456 int new_target = Register::new_target().index(); 6524 int new_target = Register::new_target().index();
6457 6525
6458 ExpectedSnippet<int> snippets[] = { 6526 ExpectedSnippet<InstanceType> snippets[] = {
6459 {"return new.target;", 6527 {"return new.target;",
6460 1 * kPointerSize, 6528 2 * kPointerSize,
6461 1, 6529 1,
6462 5, 6530 16,
6463 { 6531 {
6464 B(Ldar), R(new_target), // 6532 B(Ldar), R(new_target), //
6465 B(Star), R(0), // 6533 B(Star), R(0), //
6466 B(Return), // 6534 B(JumpIfNotHole), U8(11), //
6467 }}, 6535 B(LdaConstant), U8(0), //
6536 B(Star), R(1), //
6537 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
6538 B(Return), //
6539 },
6540 1,
6541 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
6468 {"new.target;", 6542 {"new.target;",
6469 1 * kPointerSize, 6543 2 * kPointerSize,
6470 1, 6544 1,
6471 6, 6545 17,
6472 { 6546 {
6473 B(Ldar), R(new_target), // 6547 B(Ldar), R(new_target), //
6474 B(Star), R(0), // 6548 B(Star), R(0), //
6475 B(LdaUndefined), // 6549 B(JumpIfNotHole), U8(11), //
6476 B(Return), // 6550 B(LdaConstant), U8(0), //
6477 }}, 6551 B(Star), R(1), //
6478 }; 6552 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
6553 B(LdaUndefined), //
6554 B(Return), //
6555 },
6556 1,
6557 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}};
6479 6558
6480 for (size_t i = 0; i < arraysize(snippets); i++) { 6559 for (size_t i = 0; i < arraysize(snippets); i++) {
6481 Handle<BytecodeArray> bytecode_array = 6560 Handle<BytecodeArray> bytecode_array =
6482 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 6561 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
6483 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 6562 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
6484 } 6563 }
6485 } 6564 }
6486 6565
6487 6566
6488 TEST(RemoveRedundantLdar) { 6567 TEST(RemoveRedundantLdar) {
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
7494 }}}; 7573 }}};
7495 7574
7496 for (size_t i = 0; i < arraysize(snippets); ++i) { 7575 for (size_t i = 0; i < arraysize(snippets); ++i) {
7497 std::string body = prologue + snippets[i].code_snippet; 7576 std::string body = prologue + snippets[i].code_snippet;
7498 Handle<BytecodeArray> bytecode_array = 7577 Handle<BytecodeArray> bytecode_array =
7499 helper.MakeBytecodeForFunctionBody(body.c_str()); 7578 helper.MakeBytecodeForFunctionBody(body.c_str());
7500 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 7579 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7501 } 7580 }
7502 } 7581 }
7503 7582
7583 TEST(ConstVariable) {
7584 InitializedHandleScope handle_scope;
7585 BytecodeGeneratorHelper helper;
7586
7587 ExpectedSnippet<const char*> snippets[] = {
7588 {
7589 "const x = 10;",
rmcilroy 2016/02/03 12:28:26 Fix indentation
mythria 2016/02/04 10:28:53 Done.
7590 1 * kPointerSize,
7591 1,
7592 9,
7593 {
7594 B(LdaTheHole), //
7595 B(Star), R(0), //
7596 B(LdaSmi8), U8(10), //
7597 B(Star), R(0), //
7598 B(LdaUndefined), //
7599 B(Return) //
7600 },
7601 0,
7602 },
7603 {"const x = 10; return x;",
7604 2 * kPointerSize,
7605 1,
7606 19,
7607 {
7608 B(LdaTheHole), //
7609 B(Star), R(0), //
7610 B(LdaSmi8), U8(10), //
7611 B(Star), R(0), //
7612 B(JumpIfNotHole), U8(11), //
7613 B(LdaConstant), U8(0), //
7614 B(Star), R(1), //
7615 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
7616 B(Return) //
7617 },
7618 1,
7619 {"x"}},
7620 {"const x = ( x = 20);",
7621 3 * kPointerSize,
7622 1,
7623 31,
7624 {
7625 B(LdaTheHole), //
7626 B(Star), R(0), //
7627 B(LdaSmi8), U8(20), //
7628 B(Star), R(1), //
7629 B(Ldar), R(0), //
7630 B(JumpIfNotHole), U8(11), //
7631 B(LdaConstant), U8(0), //
7632 B(Star), R(2), //
7633 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7634 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
7635 U8(0), //
7636 B(Ldar), R(1), //
7637 B(Star), R(0), //
7638 B(LdaUndefined), //
7639 B(Return) //
7640 },
7641 1,
7642 {"x"}},
7643 {"const x = 10; x = 20;",
7644 3 * kPointerSize,
7645 1,
7646 35,
7647 {
7648 B(LdaTheHole), //
7649 B(Star), R(0), //
7650 B(LdaSmi8), U8(10), //
7651 B(Star), R(0), //
7652 B(LdaSmi8), U8(20), //
7653 B(Star), R(1), //
7654 B(Ldar), R(0), //
7655 B(JumpIfNotHole), U8(11), //
7656 B(LdaConstant), U8(0), //
7657 B(Star), R(2), //
7658 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7659 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
7660 U8(0), //
7661 B(Ldar), R(1), //
7662 B(Star), R(0), //
7663 B(LdaUndefined), //
7664 B(Return) //
7665 },
7666 1,
7667 {"x"}},
7668 };
7669
7670 for (size_t i = 0; i < arraysize(snippets); i++) {
7671 Handle<BytecodeArray> bytecode_array =
7672 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7673 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7674 }
7675 }
7676
7677 TEST(LetVariable) {
7678 InitializedHandleScope handle_scope;
7679 BytecodeGeneratorHelper helper;
7680
7681 ExpectedSnippet<const char*> snippets[] = {
7682 {
7683 "let x = 10;",
rmcilroy 2016/02/03 12:28:27 Fix indentation
mythria 2016/02/04 10:28:53 Done.
7684 1 * kPointerSize,
7685 1,
7686 9,
7687 {
7688 B(LdaTheHole), //
7689 B(Star), R(0), //
7690 B(LdaSmi8), U8(10), //
7691 B(Star), R(0), //
7692 B(LdaUndefined), //
7693 B(Return) //
7694 },
7695 0,
7696 },
7697 {"let x = 10; return x;",
7698 2 * kPointerSize,
7699 1,
7700 19,
7701 {
7702 B(LdaTheHole), //
7703 B(Star), R(0), //
7704 B(LdaSmi8), U8(10), //
7705 B(Star), R(0), //
7706 B(JumpIfNotHole), U8(11), //
7707 B(LdaConstant), U8(0), //
7708 B(Star), R(1), //
7709 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
7710 B(Return) //
7711 },
7712 1,
7713 {"x"}},
7714 {"let x = ( x = 20);",
7715 3 * kPointerSize,
7716 1,
7717 26,
7718 {
7719 B(LdaTheHole), //
7720 B(Star), R(0), //
7721 B(LdaSmi8), U8(20), //
7722 B(Star), R(1), //
7723 B(Ldar), R(0), //
7724 B(JumpIfNotHole), U8(11), //
7725 B(LdaConstant), U8(0), //
7726 B(Star), R(2), //
7727 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7728 B(Ldar), R(1), //
7729 B(Star), R(0), //
7730 B(LdaUndefined), //
7731 B(Return) //
7732 },
7733 1,
7734 {"x"}},
7735 {"let x = 10; x = 20;",
7736 3 * kPointerSize,
7737 1,
7738 30,
7739 {
7740 B(LdaTheHole), //
7741 B(Star), R(0), //
7742 B(LdaSmi8), U8(10), //
7743 B(Star), R(0), //
7744 B(LdaSmi8), U8(20), //
7745 B(Star), R(1), //
7746 B(Ldar), R(0), //
7747 B(JumpIfNotHole), U8(11), //
7748 B(LdaConstant), U8(0), //
7749 B(Star), R(2), //
7750 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7751 B(Ldar), R(1), //
7752 B(Star), R(0), //
7753 B(LdaUndefined), //
7754 B(Return) //
7755 },
7756 1,
7757 {"x"}},
7758 };
7759
7760 for (size_t i = 0; i < arraysize(snippets); i++) {
7761 Handle<BytecodeArray> bytecode_array =
7762 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7763 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7764 }
7765 }
7766
7767 TEST(LegacyConstVariable) {
7768 InitializedHandleScope handle_scope;
7769 BytecodeGeneratorHelper helper;
7770
7771 ExpectedSnippet<const char*> snippets[] = {
7772 {"const x = 10;",
7773 2 * kPointerSize,
7774 1,
7775 18,
7776 {
7777 B(LdaTheHole), //
7778 B(Star), R(0), //
7779 B(LdaSmi8), U8(10), //
7780 B(Star), R(1), //
7781 B(Ldar), R(0), //
7782 B(JumpIfNotHole), U8(5), //
7783 B(Mov), R(1), R(0), //
7784 B(Ldar), R(1), //
7785 B(LdaUndefined), //
7786 B(Return) //
7787 },
7788 0,
7789 },
7790 {"const x = 10; return x;",
7791 2 * kPointerSize,
7792 1,
7793 22,
7794 {
7795 B(LdaTheHole), //
7796 B(Star), R(0), //
7797 B(LdaSmi8), U8(10), //
7798 B(Star), R(1), //
7799 B(Ldar), R(0), //
7800 B(JumpIfNotHole), U8(5), //
7801 B(Mov), R(1), R(0), //
7802 B(Ldar), R(1), //
7803 B(Ldar), R(0), //
7804 B(JumpIfNotHole), U8(3), //
7805 B(LdaUndefined), //
7806 B(Return) //
7807 },
7808 0,
7809 },
7810 {"const x = ( x = 20);",
7811 2 * kPointerSize,
7812 1,
7813 22,
7814 {
7815 B(LdaTheHole), //
7816 B(Star), R(0), //
7817 B(LdaSmi8), U8(20), //
7818 B(Star), R(1), //
7819 B(Ldar), R(0), //
7820 B(Ldar), R(1), //
7821 B(Ldar), R(0), //
7822 B(JumpIfNotHole), U8(5), //
7823 B(Mov), R(1), R(0), //
7824 B(Ldar), R(1), //
7825 B(LdaUndefined), //
7826 B(Return) //
7827 },
7828 0,
7829 },
7830 {"const x = 10; x = 20;",
7831 2 * kPointerSize,
7832 1,
7833 26,
7834 {
7835 B(LdaTheHole), //
7836 B(Star), R(0), //
7837 B(LdaSmi8), U8(10), //
7838 B(Star), R(1), //
7839 B(Ldar), R(0), //
7840 B(JumpIfNotHole), U8(5), //
7841 B(Mov), R(1), R(0), //
7842 B(Ldar), R(1), //
7843 B(LdaSmi8), U8(20), //
7844 B(Star), R(1), //
7845 B(Ldar), R(0), //
7846 B(Ldar), R(1), //
7847 B(LdaUndefined), //
7848 B(Return) //
7849 },
7850 0,
7851 },
7852 };
7853
7854 for (size_t i = 0; i < arraysize(snippets); i++) {
7855 Handle<BytecodeArray> bytecode_array =
7856 helper.MakeBytecodeForFunctionBodyWithLegacyConst(
7857 snippets[i].code_snippet);
7858 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7859 }
7860 }
7861
7862 TEST(ConstVariableContextSlot) {
7863 InitializedHandleScope handle_scope;
7864 BytecodeGeneratorHelper helper;
7865
7866 int closure = Register::function_closure().index();
7867 int context = Register::current_context().index();
7868
7869 // TODO(mythria): Add tests for initialization of this via super calls.
7870 // TODO(mythria): Add tests that walk the context chain.
7871 ExpectedSnippet<InstanceType> snippets[] = {
7872 {"const x = 10; function f1() {return x;}",
7873 2 * kPointerSize,
7874 1,
7875 23,
7876 {
7877 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
7878 U8(1), //
7879 B(PushContext), R(1), //
7880 B(LdaTheHole), //
7881 B(StaContextSlot), R(context), U8(4), //
7882 B(CreateClosure), U8(0), U8(0), //
7883 B(Star), R(0), //
7884 B(LdaSmi8), U8(10), //
7885 B(StaContextSlot), R(context), U8(4), //
7886 B(LdaUndefined), //
7887 B(Return) //
7888 },
7889 1,
7890 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
7891 {"const x = 10; function f1() {return x;} return x;",
7892 3 * kPointerSize,
7893 1,
7894 36,
7895 {
7896 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
7897 U8(1), //
7898 B(PushContext), R(1), //
7899 B(LdaTheHole), //
7900 B(StaContextSlot), R(context), U8(4), //
7901 B(CreateClosure), U8(0), U8(0), //
7902 B(Star), R(0), //
7903 B(LdaSmi8), U8(10), //
7904 B(StaContextSlot), R(context), U8(4), //
7905 B(LdaContextSlot), R(context), U8(4), //
7906 B(JumpIfNotHole), U8(11), //
7907 B(LdaConstant), U8(1), //
7908 B(Star), R(2), //
7909 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
7910 B(Return) //
7911 },
7912 2,
7913 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
7914 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
7915 {"const x = (x = 20); function f1() {return x;}",
7916 4 * kPointerSize,
7917 1,
7918 49,
7919 {
7920 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
7921 U8(1), //
7922 B(PushContext), R(1), //
7923 B(LdaTheHole), //
7924 B(StaContextSlot), R(context), U8(4), //
7925 B(CreateClosure), U8(0), U8(0), //
7926 B(Star), R(0), //
7927 B(LdaSmi8), U8(20), //
7928 B(Star), R(2), //
7929 B(LdaContextSlot), R(context), U8(4), //
7930 B(JumpIfNotHole), U8(11), //
7931 B(LdaConstant), U8(1), //
7932 B(Star), R(3), //
7933 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
7934 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
7935 U8(0), //
7936 B(Ldar), R(2), //
7937 B(StaContextSlot), R(context), U8(4), //
7938 B(StaContextSlot), R(context), U8(4), //
7939 B(LdaUndefined), //
7940 B(Return) //
7941 },
7942 2,
7943 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
7944 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
7945 {"const x = 10; x = 20; function f1() {return x;}",
7946 4 * kPointerSize,
7947 1,
7948 51,
7949 {
7950 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
7951 U8(1), //
7952 B(PushContext), R(1), //
7953 B(LdaTheHole), //
7954 B(StaContextSlot), R(context), U8(4), //
7955 B(CreateClosure), U8(0), U8(0), //
7956 B(Star), R(0), //
7957 B(LdaSmi8), U8(10), //
7958 B(StaContextSlot), R(context), U8(4), //
7959 B(LdaSmi8), U8(20), //
7960 B(Star), R(2), //
7961 B(LdaContextSlot), R(context), U8(4), //
7962 B(JumpIfNotHole), U8(11), //
7963 B(LdaConstant), U8(1), //
7964 B(Star), R(3), //
7965 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
7966 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), //
7967 U8(0), //
7968 B(Ldar), R(2), //
7969 B(StaContextSlot), R(context), U8(4), //
7970 B(LdaUndefined), //
7971 B(Return) //
7972 },
7973 2,
7974 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
7975 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
7976 };
7977
7978 for (size_t i = 0; i < arraysize(snippets); i++) {
7979 Handle<BytecodeArray> bytecode_array =
7980 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7981 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7982 }
7983 }
7984
7985 TEST(LetVariableContextSlot) {
7986 InitializedHandleScope handle_scope;
7987 BytecodeGeneratorHelper helper;
7988
7989 int closure = Register::function_closure().index();
7990 int context = Register::current_context().index();
7991
7992 ExpectedSnippet<InstanceType> snippets[] = {
7993 {"let x = 10; function f1() {return x;}",
7994 2 * kPointerSize,
7995 1,
7996 23,
7997 {
7998 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
7999 U8(1), //
8000 B(PushContext), R(1), //
8001 B(LdaTheHole), //
8002 B(StaContextSlot), R(context), U8(4), //
8003 B(CreateClosure), U8(0), U8(0), //
8004 B(Star), R(0), //
8005 B(LdaSmi8), U8(10), //
8006 B(StaContextSlot), R(context), U8(4), //
8007 B(LdaUndefined), //
8008 B(Return) //
8009 },
8010 1,
8011 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
8012 {"let x = 10; function f1() {return x;} return x;",
8013 3 * kPointerSize,
8014 1,
8015 36,
8016 {
8017 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8018 U8(1), //
8019 B(PushContext), R(1), //
8020 B(LdaTheHole), //
8021 B(StaContextSlot), R(context), U8(4), //
8022 B(CreateClosure), U8(0), U8(0), //
8023 B(Star), R(0), //
8024 B(LdaSmi8), U8(10), //
8025 B(StaContextSlot), R(context), U8(4), //
8026 B(LdaContextSlot), R(context), U8(4), //
8027 B(JumpIfNotHole), U8(11), //
8028 B(LdaConstant), U8(1), //
8029 B(Star), R(2), //
8030 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), //
8031 B(Return) //
8032 },
8033 2,
8034 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8035 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8036 {"let x = (x = 20); function f1() {return x;}",
8037 4 * kPointerSize,
8038 1,
8039 44,
8040 {
8041 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8042 U8(1), //
8043 B(PushContext), R(1), //
8044 B(LdaTheHole), //
8045 B(StaContextSlot), R(context), U8(4), //
8046 B(CreateClosure), U8(0), U8(0), //
8047 B(Star), R(0), //
8048 B(LdaSmi8), U8(20), //
8049 B(Star), R(2), //
8050 B(LdaContextSlot), R(context), U8(4), //
8051 B(JumpIfNotHole), U8(11), //
8052 B(LdaConstant), U8(1), //
8053 B(Star), R(3), //
8054 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8055 B(Ldar), R(2), //
8056 B(StaContextSlot), R(context), U8(4), //
8057 B(StaContextSlot), R(context), U8(4), //
8058 B(LdaUndefined), //
8059 B(Return) //
8060 },
8061 2,
8062 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8063 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8064 {"let x = 10; x = 20; function f1() {return x;}",
8065 4 * kPointerSize,
8066 1,
8067 46,
8068 {
8069 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
8070 U8(1), //
8071 B(PushContext), R(1), //
8072 B(LdaTheHole), //
8073 B(StaContextSlot), R(context), U8(4), //
8074 B(CreateClosure), U8(0), U8(0), //
8075 B(Star), R(0), //
8076 B(LdaSmi8), U8(10), //
8077 B(StaContextSlot), R(context), U8(4), //
8078 B(LdaSmi8), U8(20), //
8079 B(Star), R(2), //
8080 B(LdaContextSlot), R(context), U8(4), //
8081 B(JumpIfNotHole), U8(11), //
8082 B(LdaConstant), U8(1), //
8083 B(Star), R(3), //
8084 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), //
8085 B(Ldar), R(2), //
8086 B(StaContextSlot), R(context), U8(4), //
8087 B(LdaUndefined), //
8088 B(Return) //
8089 },
8090 2,
8091 {InstanceType::SHARED_FUNCTION_INFO_TYPE,
8092 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
8093 };
8094
8095 for (size_t i = 0; i < arraysize(snippets); i++) {
8096 Handle<BytecodeArray> bytecode_array =
8097 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
8098 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
8099 }
8100 }
rmcilroy 2016/02/03 12:28:27 Nice set of tests, thanks!
8101
7504 TEST(DoExpression) { 8102 TEST(DoExpression) {
7505 bool old_flag = FLAG_harmony_do_expressions; 8103 bool old_flag = FLAG_harmony_do_expressions;
7506 FLAG_harmony_do_expressions = true; 8104 FLAG_harmony_do_expressions = true;
7507 8105
7508 InitializedHandleScope handle_scope; 8106 InitializedHandleScope handle_scope;
7509 BytecodeGeneratorHelper helper; 8107 BytecodeGeneratorHelper helper;
7510 8108
7511 ExpectedSnippet<const char*> snippets[] = { 8109 ExpectedSnippet<const char*> snippets[] = {
7512 {"var a = do { }; return a;", 8110 {"var a = do { }; return a;",
7513 2 * kPointerSize, 8111 2 * kPointerSize,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7559 Handle<BytecodeArray> bytecode_array = 8157 Handle<BytecodeArray> bytecode_array =
7560 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 8158 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
7561 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 8159 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
7562 } 8160 }
7563 FLAG_harmony_do_expressions = old_flag; 8161 FLAG_harmony_do_expressions = old_flag;
7564 } 8162 }
7565 8163
7566 } // namespace interpreter 8164 } // namespace interpreter
7567 } // namespace internal 8165 } // namespace internal
7568 } // namespace v8 8166 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698