OLD | NEW |
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 Loading... |
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; |
| 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 2205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2292 B(Ldar), R(0), // | 2299 B(Ldar), R(0), // |
2293 B(Return), // | 2300 B(Return), // |
2294 }}, | 2301 }}, |
2295 {"outer: {\n" | 2302 {"outer: {\n" |
2296 " let y = 10;" | 2303 " let y = 10;" |
2297 " function f() { return y; }\n" | 2304 " function f() { return y; }\n" |
2298 " break outer;\n" | 2305 " break outer;\n" |
2299 "}\n", | 2306 "}\n", |
2300 5 * kPointerSize, | 2307 5 * kPointerSize, |
2301 1, | 2308 1, |
2302 39, | 2309 50, |
2303 { | 2310 { |
2304 B(LdaConstant), U8(0), // | 2311 B(LdaConstant), U8(0), // |
2305 B(Star), R(3), // | 2312 B(Star), R(3), // |
2306 B(Ldar), R(closure), // | 2313 B(Ldar), R(closure), // |
2307 B(Star), R(4), // | 2314 B(Star), R(4), // |
2308 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // | 2315 B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // |
2309 B(PushContext), R(2), // | 2316 B(PushContext), R(2), // |
2310 B(LdaTheHole), // | 2317 B(LdaTheHole), // |
2311 B(StaContextSlot), R(context), U8(4), // | 2318 B(StaContextSlot), R(context), U8(4), // |
2312 B(CreateClosure), U8(1), U8(0), // | 2319 B(CreateClosure), U8(1), U8(0), // |
2313 B(Star), R(0), // | 2320 B(Star), R(0), // |
2314 B(LdaSmi8), U8(10), // | 2321 B(LdaSmi8), U8(10), // |
2315 B(StaContextSlot), R(context), U8(4), // | 2322 B(StaContextSlot), R(context), U8(4), // |
2316 B(Ldar), R(0), // | 2323 B(Ldar), R(0), // |
2317 B(Star), R(1), // | 2324 B(JumpIfNotHole), U8(11), // |
2318 B(Jump), U8(2), // | 2325 B(LdaConstant), U8(2), // |
2319 B(PopContext), R(2), // | 2326 B(Star), R(3), // |
2320 B(LdaUndefined), // | 2327 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
2321 B(Return), // | 2328 B(Star), R(1), // |
| 2329 B(Jump), U8(2), // |
| 2330 B(PopContext), R(2), // |
| 2331 B(LdaUndefined), // |
| 2332 B(Return), // |
2322 }, | 2333 }, |
2323 2, | 2334 3, |
2324 {InstanceType::FIXED_ARRAY_TYPE, | 2335 {InstanceType::FIXED_ARRAY_TYPE, |
2325 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2336 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 2337 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
2326 {"let x = 1;\n" | 2338 {"let x = 1;\n" |
2327 "outer: {\n" | 2339 "outer: {\n" |
2328 " inner: {\n" | 2340 " inner: {\n" |
2329 " let y = 2;\n" | 2341 " let y = 2;\n" |
2330 " function f() { return x + y; }\n" | 2342 " function f() { return x + y; }\n" |
2331 " if (y) break outer;\n" | 2343 " if (y) break outer;\n" |
2332 " y = 3;\n" | 2344 " y = 3;\n" |
2333 " }\n" | 2345 " }\n" |
2334 "}\n" | 2346 "}\n" |
2335 "x = 4;", | 2347 "x = 4;", |
2336 6 * kPointerSize, | 2348 6 * kPointerSize, |
2337 1, | 2349 1, |
2338 72, | 2350 130, |
2339 { | 2351 { |
2340 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 2352 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
2341 U8(1), // | 2353 U8(1), // |
2342 B(PushContext), R(2), // | 2354 B(PushContext), R(2), // |
2343 B(LdaTheHole), // | 2355 B(LdaTheHole), // |
2344 B(StaContextSlot), R(context), U8(4), // | 2356 B(StaContextSlot), R(context), U8(4), // |
2345 B(LdaSmi8), U8(1), // | 2357 B(LdaSmi8), U8(1), // |
2346 B(StaContextSlot), R(context), U8(4), // | 2358 B(StaContextSlot), R(context), U8(4), // |
2347 B(LdaConstant), U8(0), // | 2359 B(LdaConstant), U8(0), // |
2348 B(Star), R(4), // | 2360 B(Star), R(4), // |
2349 B(Ldar), R(closure), // | 2361 B(Ldar), R(closure), // |
2350 B(Star), R(5), // | 2362 B(Star), R(5), // |
2351 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // | 2363 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
2352 B(PushContext), R(3), // | 2364 B(PushContext), R(3), // |
2353 B(LdaTheHole), // | 2365 B(LdaTheHole), // |
2354 B(StaContextSlot), R(context), U8(4), // | 2366 B(StaContextSlot), R(context), U8(4), // |
2355 B(CreateClosure), U8(1), U8(0), // | 2367 B(CreateClosure), U8(1), U8(0), // |
2356 B(Star), R(0), // | 2368 B(Star), R(0), // |
2357 B(LdaSmi8), U8(2), // | 2369 B(LdaSmi8), U8(2), // |
2358 B(StaContextSlot), R(context), U8(4), // | 2370 B(StaContextSlot), R(context), U8(4), // |
2359 B(Ldar), R(0), // | 2371 B(Ldar), R(0), // |
2360 B(Star), R(1), // | 2372 B(JumpIfNotHole), U8(11), // |
2361 B(LdaContextSlot), R(context), U8(4), // | 2373 B(LdaConstant), U8(2), // |
2362 B(JumpIfToBooleanFalse), U8(6), // | 2374 B(Star), R(4), // |
2363 B(PopContext), R(3), // | 2375 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), |
2364 B(Jump), U8(9), // | 2376 U8(1), // 58 |
2365 B(LdaSmi8), U8(3), // | 2377 B(Star), R(1), // |
2366 B(StaContextSlot), R(context), U8(4), // | 2378 B(LdaContextSlot), R(context), U8(4), // |
2367 B(PopContext), R(3), // | 2379 B(JumpIfNotHole), U8(11), // |
2368 B(LdaSmi8), U8(4), // | 2380 B(LdaConstant), U8(3), // |
2369 B(StaContextSlot), R(context), U8(4), // | 2381 B(Star), R(4), // |
2370 B(LdaUndefined), // | 2382 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
2371 B(Return), // | 2383 B(JumpIfToBooleanFalse), U8(6), // |
2372 }, | 2384 B(PopContext), R(3), // |
2373 2, | 2385 B(Jump), U8(27), // |
2374 {InstanceType::FIXED_ARRAY_TYPE, | 2386 B(LdaSmi8), U8(3), // |
2375 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2387 B(Star), R(4), // |
| 2388 B(LdaContextSlot), R(context), U8(4), // |
| 2389 B(JumpIfNotHole), U8(11), // |
| 2390 B(LdaConstant), U8(3), // |
| 2391 B(Star), R(5), // |
| 2392 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), // |
| 2393 B(Ldar), R(4), // 100 |
| 2394 B(StaContextSlot), R(context), U8(4), // |
| 2395 B(PopContext), R(3), // |
| 2396 B(LdaSmi8), U8(4), // |
| 2397 B(Star), R(4), // |
| 2398 B(LdaContextSlot), R(context), U8(4), // |
| 2399 B(JumpIfNotHole), U8(11), // |
| 2400 B(LdaConstant), U8(4), // |
| 2401 B(Star), R(5), // |
| 2402 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), // |
| 2403 B(Ldar), R(4), // |
| 2404 B(StaContextSlot), R(context), U8(4), // |
| 2405 B(LdaUndefined), // |
| 2406 B(Return), // |
| 2407 }, |
| 2408 5, |
| 2409 {InstanceType::FIXED_ARRAY_TYPE, |
| 2410 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 2411 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 2412 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 2413 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
2376 }; | 2414 }; |
2377 | 2415 |
2378 for (size_t i = 0; i < arraysize(snippets); i++) { | 2416 for (size_t i = 0; i < arraysize(snippets); i++) { |
2379 Handle<BytecodeArray> bytecode_array = | 2417 Handle<BytecodeArray> bytecode_array = |
2380 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2418 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2381 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2419 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2382 } | 2420 } |
2383 } | 2421 } |
2384 | 2422 |
2385 | 2423 |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2998 B(Inc), // | 3036 B(Inc), // |
2999 B(Star), R(1), // | 3037 B(Star), R(1), // |
3000 B(Jump), U8(-26), // | 3038 B(Jump), U8(-26), // |
3001 B(Ldar), R(0), // | 3039 B(Ldar), R(0), // |
3002 B(Return), // | 3040 B(Return), // |
3003 }, | 3041 }, |
3004 0}, | 3042 0}, |
3005 {"var a = 0;\n" | 3043 {"var a = 0;\n" |
3006 "while (a) {\n" | 3044 "while (a) {\n" |
3007 " { \n" | 3045 " { \n" |
3008 " let z = 1;\n" | 3046 " let z = 1;\n" |
3009 " function f() { z = 2; }\n" | 3047 " function f() { z = 2; }\n" |
3010 " if (z) continue;\n" | 3048 " if (z) continue;\n" |
3011 " z++;\n" | 3049 " z++;\n" |
3012 " }\n" | 3050 " }\n" |
3013 "}\n", | 3051 "}\n", |
3014 6 * kPointerSize, | 3052 7 * kPointerSize, |
3015 1, | 3053 1, |
3016 65, | 3054 116, |
3017 { | 3055 { |
3018 B(LdaZero), // | 3056 B(LdaZero), // |
3019 B(Star), R(1), // | 3057 B(Star), R(1), // |
3020 B(Ldar), R(1), // | 3058 B(Ldar), R(1), // |
3021 B(JumpIfToBooleanFalse), U8(58), // | 3059 B(JumpIfToBooleanFalse), U8(109), // |
3022 B(LdaConstant), U8(0), // | 3060 B(LdaConstant), U8(0), // |
3023 B(Star), R(4), // | 3061 B(Star), R(4), // |
3024 B(Ldar), R(closure), // | 3062 B(Ldar), R(closure), // |
3025 B(Star), R(5), // | 3063 B(Star), R(5), // |
3026 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // | 3064 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
3027 B(PushContext), R(3), // | 3065 B(PushContext), R(3), // |
3028 B(LdaTheHole), // | 3066 B(LdaTheHole), // |
3029 B(StaContextSlot), R(context), U8(4), // | 3067 B(StaContextSlot), R(context), U8(4), // |
3030 B(CreateClosure), U8(1), U8(0), // | 3068 B(CreateClosure), U8(1), U8(0), // |
3031 B(Star), R(0), // | 3069 B(Star), R(0), // |
3032 B(LdaSmi8), U8(1), // | 3070 B(LdaSmi8), U8(1), // |
3033 B(StaContextSlot), R(context), U8(4), // | 3071 B(StaContextSlot), R(context), U8(4), // |
3034 B(Ldar), R(0), // | 3072 B(Ldar), R(0), // |
3035 B(Star), R(2), // | 3073 B(JumpIfNotHole), U8(11), // |
3036 B(LdaContextSlot), R(context), U8(4), // | 3074 B(LdaConstant), U8(2), // |
3037 B(JumpIfToBooleanFalse), U8(6), // | 3075 B(Star), R(4), // |
3038 B(PopContext), R(3), // | 3076 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
3039 B(Jump), U8(-44), // | 3077 B(Star), R(2), // |
3040 B(LdaContextSlot), R(context), U8(4), // | 3078 B(LdaContextSlot), R(context), U8(4), // |
3041 B(ToNumber), // | 3079 B(JumpIfNotHole), U8(11), // |
3042 B(Star), R(4), // | 3080 B(LdaConstant), U8(3), // |
3043 B(Inc), // | 3081 B(Star), R(4), // |
3044 B(StaContextSlot), R(context), U8(4), // | 3082 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
3045 B(PopContext), R(3), // | 3083 B(JumpIfToBooleanFalse), U8(6), // |
3046 B(Jump), U8(-58), // | 3084 B(PopContext), R(3), // |
3047 B(LdaUndefined), // | 3085 B(Jump), U8(-66), // |
3048 B(Return), // | 3086 B(LdaContextSlot), R(context), U8(4), // |
3049 }, | 3087 B(JumpIfNotHole), U8(11), // |
3050 2, | 3088 B(LdaConstant), U8(3), // |
3051 {InstanceType::FIXED_ARRAY_TYPE, | 3089 B(Star), R(4), // |
3052 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3090 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
| 3091 B(ToNumber), // |
| 3092 B(Star), R(4), // |
| 3093 B(Inc), // |
| 3094 B(Star), R(5), // |
| 3095 B(LdaContextSlot), R(context), U8(4), // |
| 3096 B(JumpIfNotHole), U8(11), // |
| 3097 B(LdaConstant), U8(3), // |
| 3098 B(Star), R(6), // |
| 3099 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(6), U8(1), // |
| 3100 B(Ldar), R(5), // |
| 3101 B(StaContextSlot), R(context), U8(4), // |
| 3102 B(PopContext), R(3), // |
| 3103 B(Jump), U8(-109), // |
| 3104 B(LdaUndefined), // |
| 3105 B(Return), // |
| 3106 }, |
| 3107 4, |
| 3108 {InstanceType::FIXED_ARRAY_TYPE, |
| 3109 InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 3110 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 3111 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
3053 }; | 3112 }; |
3054 | 3113 |
3055 for (size_t i = 0; i < arraysize(snippets); i++) { | 3114 for (size_t i = 0; i < arraysize(snippets); i++) { |
3056 Handle<BytecodeArray> bytecode_array = | 3115 Handle<BytecodeArray> bytecode_array = |
3057 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3116 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
3058 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3117 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3059 } | 3118 } |
3060 } | 3119 } |
3061 | 3120 |
3062 | 3121 |
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5519 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), // | 5578 B(CallRuntime), U16(Runtime::kNewSyntaxError), R(1), U8(2), // |
5520 B(Throw), // | 5579 B(Throw), // |
5521 }, | 5580 }, |
5522 2, | 5581 2, |
5523 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), | 5582 {helper.factory()->NewNumberFromInt(MessageTemplate::kVarRedeclaration), |
5524 helper.factory()->NewStringFromAsciiChecked("a")}}, | 5583 helper.factory()->NewStringFromAsciiChecked("a")}}, |
5525 }; | 5584 }; |
5526 | 5585 |
5527 for (size_t i = 0; i < arraysize(snippets); i++) { | 5586 for (size_t i = 0; i < arraysize(snippets); i++) { |
5528 Handle<BytecodeArray> bytecode_array = | 5587 Handle<BytecodeArray> bytecode_array = |
5529 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 5588 helper.MakeBytecodeForFunctionBodyWithLegacyConst( |
| 5589 snippets[i].code_snippet); |
5530 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5590 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
5531 } | 5591 } |
5532 } | 5592 } |
5533 | 5593 |
5534 | 5594 |
5535 TEST(ForIn) { | 5595 TEST(ForIn) { |
5536 InitializedHandleScope handle_scope; | 5596 InitializedHandleScope handle_scope; |
5537 BytecodeGeneratorHelper helper; | 5597 BytecodeGeneratorHelper helper; |
5538 Zone zone; | 5598 Zone zone; |
5539 | 5599 |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6417 | 6477 |
6418 | 6478 |
6419 TEST(ThisFunction) { | 6479 TEST(ThisFunction) { |
6420 InitializedHandleScope handle_scope; | 6480 InitializedHandleScope handle_scope; |
6421 BytecodeGeneratorHelper helper; | 6481 BytecodeGeneratorHelper helper; |
6422 | 6482 |
6423 int closure = Register::function_closure().index(); | 6483 int closure = Register::function_closure().index(); |
6424 | 6484 |
6425 ExpectedSnippet<int> snippets[] = { | 6485 ExpectedSnippet<int> snippets[] = { |
6426 {"var f;\n f = function f() { }", | 6486 {"var f;\n f = function f() { }", |
6427 1 * kPointerSize, | 6487 2 * kPointerSize, |
6428 1, | 6488 1, |
6429 9, | 6489 18, |
6430 { | 6490 { |
6431 B(LdaTheHole), // | 6491 B(LdaTheHole), // |
6432 B(Star), R(0), // | 6492 B(Star), R(0), // |
6433 B(Ldar), R(closure), // | 6493 B(Ldar), R(closure), // |
6434 B(Star), R(0), // | 6494 B(Star), R(1), // |
6435 B(LdaUndefined), // | 6495 B(Ldar), R(0), // |
6436 B(Return), // | 6496 B(JumpIfNotHole), U8(5), // |
| 6497 B(Mov), R(1), R(0), // |
| 6498 B(Ldar), R(1), // |
| 6499 B(LdaUndefined), // |
| 6500 B(Return), // |
6437 }}, | 6501 }}, |
6438 {"var f;\n f = function f() { return f; }", | 6502 {"var f;\n f = function f() { return f; }", |
6439 1 * kPointerSize, | 6503 2 * kPointerSize, |
6440 1, | 6504 1, |
6441 8, | 6505 22, |
6442 { | 6506 { |
6443 B(LdaTheHole), // | 6507 B(LdaTheHole), // |
6444 B(Star), R(0), // | 6508 B(Star), R(0), // |
6445 B(Ldar), R(closure), // | 6509 B(Ldar), R(closure), // |
6446 B(Star), R(0), // | 6510 B(Star), R(1), // |
6447 B(Return), // | 6511 B(Ldar), R(0), // |
| 6512 B(JumpIfNotHole), U8(5), // |
| 6513 B(Mov), R(1), R(0), // |
| 6514 B(Ldar), R(1), // |
| 6515 B(Ldar), R(0), // |
| 6516 B(JumpIfNotHole), U8(3), // |
| 6517 B(LdaUndefined), // |
| 6518 B(Return), // |
6448 }}, | 6519 }}, |
6449 }; | 6520 }; |
6450 | 6521 |
6451 for (size_t i = 0; i < arraysize(snippets); i++) { | 6522 for (size_t i = 0; i < arraysize(snippets); i++) { |
6452 Handle<BytecodeArray> bytecode_array = | 6523 Handle<BytecodeArray> bytecode_array = |
6453 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 6524 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
6454 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6525 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
6455 } | 6526 } |
6456 } | 6527 } |
6457 | 6528 |
6458 | 6529 |
6459 TEST(NewTarget) { | 6530 TEST(NewTarget) { |
6460 InitializedHandleScope handle_scope; | 6531 InitializedHandleScope handle_scope; |
6461 BytecodeGeneratorHelper helper; | 6532 BytecodeGeneratorHelper helper; |
6462 | 6533 |
6463 int new_target = Register::new_target().index(); | 6534 int new_target = Register::new_target().index(); |
6464 | 6535 |
6465 ExpectedSnippet<int> snippets[] = { | 6536 ExpectedSnippet<InstanceType> snippets[] = { |
6466 {"return new.target;", | 6537 {"return new.target;", |
6467 1 * kPointerSize, | 6538 2 * kPointerSize, |
6468 1, | 6539 1, |
6469 5, | 6540 16, |
6470 { | 6541 { |
6471 B(Ldar), R(new_target), // | 6542 B(Ldar), R(new_target), // |
6472 B(Star), R(0), // | 6543 B(Star), R(0), // |
6473 B(Return), // | 6544 B(JumpIfNotHole), U8(11), // |
6474 }}, | 6545 B(LdaConstant), U8(0), // |
| 6546 B(Star), R(1), // |
| 6547 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| 6548 B(Return), // |
| 6549 }, |
| 6550 1, |
| 6551 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
6475 {"new.target;", | 6552 {"new.target;", |
6476 1 * kPointerSize, | 6553 2 * kPointerSize, |
6477 1, | 6554 1, |
6478 6, | 6555 17, |
6479 { | 6556 { |
6480 B(Ldar), R(new_target), // | 6557 B(Ldar), R(new_target), // |
6481 B(Star), R(0), // | 6558 B(Star), R(0), // |
6482 B(LdaUndefined), // | 6559 B(JumpIfNotHole), U8(11), // |
6483 B(Return), // | 6560 B(LdaConstant), U8(0), // |
6484 }}, | 6561 B(Star), R(1), // |
6485 }; | 6562 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| 6563 B(LdaUndefined), // |
| 6564 B(Return), // |
| 6565 }, |
| 6566 1, |
| 6567 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}}; |
6486 | 6568 |
6487 for (size_t i = 0; i < arraysize(snippets); i++) { | 6569 for (size_t i = 0; i < arraysize(snippets); i++) { |
6488 Handle<BytecodeArray> bytecode_array = | 6570 Handle<BytecodeArray> bytecode_array = |
6489 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6571 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
6490 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6572 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
6491 } | 6573 } |
6492 } | 6574 } |
6493 | 6575 |
6494 | 6576 |
6495 TEST(RemoveRedundantLdar) { | 6577 TEST(RemoveRedundantLdar) { |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7275 for (size_t i = 0; i < arraysize(snippets); i++) { | 7357 for (size_t i = 0; i < arraysize(snippets); i++) { |
7276 std::string script = std::string(function_prologue) + | 7358 std::string script = std::string(function_prologue) + |
7277 std::string(snippets[i].code_snippet) + | 7359 std::string(snippets[i].code_snippet) + |
7278 std::string(function_epilogue); | 7360 std::string(function_epilogue); |
7279 Handle<BytecodeArray> bytecode_array = | 7361 Handle<BytecodeArray> bytecode_array = |
7280 helper.MakeBytecode(script.c_str(), "*", "f"); | 7362 helper.MakeBytecode(script.c_str(), "*", "f"); |
7281 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 7363 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
7282 } | 7364 } |
7283 } | 7365 } |
7284 | 7366 |
| 7367 TEST(ConstVariable) { |
| 7368 InitializedHandleScope handle_scope; |
| 7369 BytecodeGeneratorHelper helper; |
| 7370 |
| 7371 ExpectedSnippet<const char*> snippets[] = { |
| 7372 { |
| 7373 "const x = 10;", |
| 7374 1 * kPointerSize, |
| 7375 1, |
| 7376 9, |
| 7377 { |
| 7378 B(LdaTheHole), // |
| 7379 B(Star), R(0), // |
| 7380 B(LdaSmi8), U8(10), // |
| 7381 B(Star), R(0), // |
| 7382 B(LdaUndefined), // |
| 7383 B(Return) // |
| 7384 }, |
| 7385 0, |
| 7386 }, |
| 7387 {"const x = 10; return x;", |
| 7388 2 * kPointerSize, |
| 7389 1, |
| 7390 19, |
| 7391 { |
| 7392 B(LdaTheHole), // |
| 7393 B(Star), R(0), // |
| 7394 B(LdaSmi8), U8(10), // |
| 7395 B(Star), R(0), // |
| 7396 B(JumpIfNotHole), U8(11), // |
| 7397 B(LdaConstant), U8(0), // |
| 7398 B(Star), R(1), // |
| 7399 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| 7400 B(Return) // |
| 7401 }, |
| 7402 1, |
| 7403 {"x"}}, |
| 7404 {"const x = ( x = 20);", |
| 7405 2 * kPointerSize, |
| 7406 1, |
| 7407 27, |
| 7408 { |
| 7409 B(LdaTheHole), // |
| 7410 B(Star), R(0), // |
| 7411 B(LdaSmi8), U8(20), // |
| 7412 B(LdaConstant), U8(0), // |
| 7413 B(Star), R(1), // |
| 7414 B(Ldar), R(0), // |
| 7415 B(JumpIfNotHole), U8(7), // |
| 7416 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| 7417 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(1), // |
| 7418 U8(1), // |
| 7419 B(Star), R(0), // |
| 7420 B(LdaUndefined), // |
| 7421 B(Return) // |
| 7422 }, |
| 7423 1, |
| 7424 {"x"}}, |
| 7425 {"const x = 10; x = 20;", |
| 7426 2 * kPointerSize, |
| 7427 1, |
| 7428 29, |
| 7429 { |
| 7430 B(LdaTheHole), // |
| 7431 B(Star), R(0), // |
| 7432 B(LdaSmi8), U8(10), // |
| 7433 B(Star), R(0), // |
| 7434 B(LdaSmi8), U8(20), // |
| 7435 B(LdaConstant), U8(0), // |
| 7436 B(Star), R(1), // |
| 7437 B(Ldar), R(0), // |
| 7438 B(JumpIfNotHole), U8(7), // |
| 7439 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| 7440 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(1), // |
| 7441 U8(1), // |
| 7442 B(LdaUndefined), // |
| 7443 B(Return) // |
| 7444 }, |
| 7445 1, |
| 7446 {"x"}}, |
| 7447 }; |
| 7448 |
| 7449 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7450 Handle<BytecodeArray> bytecode_array = |
| 7451 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7452 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7453 } |
| 7454 } |
| 7455 |
| 7456 TEST(LetVariable) { |
| 7457 InitializedHandleScope handle_scope; |
| 7458 BytecodeGeneratorHelper helper; |
| 7459 |
| 7460 ExpectedSnippet<const char*> snippets[] = { |
| 7461 { |
| 7462 "let x = 10;", |
| 7463 1 * kPointerSize, |
| 7464 1, |
| 7465 9, |
| 7466 { |
| 7467 B(LdaTheHole), // |
| 7468 B(Star), R(0), // |
| 7469 B(LdaSmi8), U8(10), // |
| 7470 B(Star), R(0), // |
| 7471 B(LdaUndefined), // |
| 7472 B(Return) // |
| 7473 }, |
| 7474 0, |
| 7475 }, |
| 7476 {"let x = 10; return x;", |
| 7477 2 * kPointerSize, |
| 7478 1, |
| 7479 19, |
| 7480 { |
| 7481 B(LdaTheHole), // |
| 7482 B(Star), R(0), // |
| 7483 B(LdaSmi8), U8(10), // |
| 7484 B(Star), R(0), // |
| 7485 B(JumpIfNotHole), U8(11), // |
| 7486 B(LdaConstant), U8(0), // |
| 7487 B(Star), R(1), // |
| 7488 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| 7489 B(Return) // |
| 7490 }, |
| 7491 1, |
| 7492 {"x"}}, |
| 7493 {"let x = ( x = 20);", |
| 7494 3 * kPointerSize, |
| 7495 1, |
| 7496 26, |
| 7497 { |
| 7498 B(LdaTheHole), // |
| 7499 B(Star), R(0), // |
| 7500 B(LdaSmi8), U8(20), // |
| 7501 B(Star), R(1), // |
| 7502 B(Ldar), R(0), // |
| 7503 B(JumpIfNotHole), U8(11), // |
| 7504 B(LdaConstant), U8(0), // |
| 7505 B(Star), R(2), // |
| 7506 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| 7507 B(Ldar), R(1), // |
| 7508 B(Star), R(0), // |
| 7509 B(LdaUndefined), // |
| 7510 B(Return) // |
| 7511 }, |
| 7512 1, |
| 7513 {"x"}}, |
| 7514 {"let x = 10; x = 20;", |
| 7515 3 * kPointerSize, |
| 7516 1, |
| 7517 30, |
| 7518 { |
| 7519 B(LdaTheHole), // |
| 7520 B(Star), R(0), // |
| 7521 B(LdaSmi8), U8(10), // |
| 7522 B(Star), R(0), // |
| 7523 B(LdaSmi8), U8(20), // |
| 7524 B(Star), R(1), // |
| 7525 B(Ldar), R(0), // |
| 7526 B(JumpIfNotHole), U8(11), // |
| 7527 B(LdaConstant), U8(0), // |
| 7528 B(Star), R(2), // |
| 7529 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| 7530 B(Ldar), R(1), // |
| 7531 B(Star), R(0), // |
| 7532 B(LdaUndefined), // |
| 7533 B(Return) // |
| 7534 }, |
| 7535 1, |
| 7536 {"x"}}, |
| 7537 }; |
| 7538 |
| 7539 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7540 Handle<BytecodeArray> bytecode_array = |
| 7541 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7542 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7543 } |
| 7544 } |
| 7545 |
| 7546 TEST(LegacyConstVariable) { |
| 7547 InitializedHandleScope handle_scope; |
| 7548 BytecodeGeneratorHelper helper; |
| 7549 |
| 7550 ExpectedSnippet<const char*> snippets[] = { |
| 7551 { |
| 7552 "const x = 10;", |
| 7553 2 * kPointerSize, |
| 7554 1, |
| 7555 18, |
| 7556 { |
| 7557 B(LdaTheHole), // |
| 7558 B(Star), R(0), // |
| 7559 B(LdaSmi8), U8(10), // |
| 7560 B(Star), R(1), // |
| 7561 B(Ldar), R(0), // |
| 7562 B(JumpIfNotHole), U8(5), // |
| 7563 B(Mov), R(1), R(0), // |
| 7564 B(Ldar), R(1), // |
| 7565 B(LdaUndefined), // |
| 7566 B(Return) // |
| 7567 }, |
| 7568 0, |
| 7569 }, |
| 7570 { |
| 7571 "const x = 10; return x;", |
| 7572 2 * kPointerSize, |
| 7573 1, |
| 7574 22, |
| 7575 { |
| 7576 B(LdaTheHole), // |
| 7577 B(Star), R(0), // |
| 7578 B(LdaSmi8), U8(10), // |
| 7579 B(Star), R(1), // |
| 7580 B(Ldar), R(0), // |
| 7581 B(JumpIfNotHole), U8(5), // |
| 7582 B(Mov), R(1), R(0), // |
| 7583 B(Ldar), R(1), // |
| 7584 B(Ldar), R(0), // |
| 7585 B(JumpIfNotHole), U8(3), // |
| 7586 B(LdaUndefined), // |
| 7587 B(Return) // |
| 7588 }, |
| 7589 0, |
| 7590 }, |
| 7591 { |
| 7592 "const x = ( x = 20);", |
| 7593 2 * kPointerSize, |
| 7594 1, |
| 7595 18, |
| 7596 { |
| 7597 B(LdaTheHole), // |
| 7598 B(Star), R(0), // |
| 7599 B(LdaSmi8), U8(20), // |
| 7600 B(Star), R(1), // |
| 7601 B(Ldar), R(0), // |
| 7602 B(JumpIfNotHole), U8(5), // |
| 7603 B(Mov), R(1), R(0), // |
| 7604 B(Ldar), R(1), // |
| 7605 B(LdaUndefined), // |
| 7606 B(Return) // |
| 7607 }, |
| 7608 0, |
| 7609 }, |
| 7610 { |
| 7611 "const x = 10; x = 20;", |
| 7612 2 * kPointerSize, |
| 7613 1, |
| 7614 20, |
| 7615 { |
| 7616 B(LdaTheHole), // |
| 7617 B(Star), R(0), // |
| 7618 B(LdaSmi8), U8(10), // |
| 7619 B(Star), R(1), // |
| 7620 B(Ldar), R(0), // |
| 7621 B(JumpIfNotHole), U8(5), // |
| 7622 B(Mov), R(1), R(0), // |
| 7623 B(Ldar), R(1), // |
| 7624 B(LdaSmi8), U8(20), // |
| 7625 B(LdaUndefined), // |
| 7626 B(Return) // |
| 7627 }, |
| 7628 0, |
| 7629 }, |
| 7630 }; |
| 7631 |
| 7632 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7633 Handle<BytecodeArray> bytecode_array = |
| 7634 helper.MakeBytecodeForFunctionBodyWithLegacyConst( |
| 7635 snippets[i].code_snippet); |
| 7636 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7637 } |
| 7638 } |
| 7639 |
| 7640 TEST(ConstVariableContextSlot) { |
| 7641 InitializedHandleScope handle_scope; |
| 7642 BytecodeGeneratorHelper helper; |
| 7643 |
| 7644 int closure = Register::function_closure().index(); |
| 7645 int context = Register::current_context().index(); |
| 7646 |
| 7647 // TODO(mythria): Add tests for initialization of this via super calls. |
| 7648 // TODO(mythria): Add tests that walk the context chain. |
| 7649 ExpectedSnippet<InstanceType> snippets[] = { |
| 7650 {"const x = 10; function f1() {return x;}", |
| 7651 2 * kPointerSize, |
| 7652 1, |
| 7653 23, |
| 7654 { |
| 7655 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7656 U8(1), // |
| 7657 B(PushContext), R(1), // |
| 7658 B(LdaTheHole), // |
| 7659 B(StaContextSlot), R(context), U8(4), // |
| 7660 B(CreateClosure), U8(0), U8(0), // |
| 7661 B(Star), R(0), // |
| 7662 B(LdaSmi8), U8(10), // |
| 7663 B(StaContextSlot), R(context), U8(4), // |
| 7664 B(LdaUndefined), // |
| 7665 B(Return) // |
| 7666 }, |
| 7667 1, |
| 7668 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 7669 {"const x = 10; function f1() {return x;} return x;", |
| 7670 3 * kPointerSize, |
| 7671 1, |
| 7672 36, |
| 7673 { |
| 7674 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7675 U8(1), // |
| 7676 B(PushContext), R(1), // |
| 7677 B(LdaTheHole), // |
| 7678 B(StaContextSlot), R(context), U8(4), // |
| 7679 B(CreateClosure), U8(0), U8(0), // |
| 7680 B(Star), R(0), // |
| 7681 B(LdaSmi8), U8(10), // |
| 7682 B(StaContextSlot), R(context), U8(4), // |
| 7683 B(LdaContextSlot), R(context), U8(4), // |
| 7684 B(JumpIfNotHole), U8(11), // |
| 7685 B(LdaConstant), U8(1), // |
| 7686 B(Star), R(2), // |
| 7687 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| 7688 B(Return) // |
| 7689 }, |
| 7690 2, |
| 7691 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7692 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7693 {"const x = (x = 20); function f1() {return x;}", |
| 7694 3 * kPointerSize, |
| 7695 1, |
| 7696 46, |
| 7697 { |
| 7698 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7699 U8(1), // |
| 7700 B(PushContext), R(1), // |
| 7701 B(LdaTheHole), // |
| 7702 B(StaContextSlot), R(context), U8(4), // |
| 7703 B(CreateClosure), U8(0), U8(0), // |
| 7704 B(Star), R(0), // |
| 7705 B(LdaSmi8), U8(20), // |
| 7706 B(LdaContextSlot), R(context), U8(4), // |
| 7707 B(JumpIfNotHole), U8(11), // |
| 7708 B(LdaConstant), U8(1), // |
| 7709 B(Star), R(2), // |
| 7710 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| 7711 B(LdaConstant), U8(1), // |
| 7712 B(Star), R(2), // |
| 7713 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(2), // |
| 7714 U8(1), // |
| 7715 B(StaContextSlot), R(context), U8(4), // |
| 7716 B(LdaUndefined), // |
| 7717 B(Return) // |
| 7718 }, |
| 7719 2, |
| 7720 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7721 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7722 {"const x = 10; x = 20; function f1() {return x;}", |
| 7723 3 * kPointerSize, |
| 7724 1, |
| 7725 48, |
| 7726 { |
| 7727 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7728 U8(1), // |
| 7729 B(PushContext), R(1), // |
| 7730 B(LdaTheHole), // |
| 7731 B(StaContextSlot), R(context), U8(4), // |
| 7732 B(CreateClosure), U8(0), U8(0), // |
| 7733 B(Star), R(0), // |
| 7734 B(LdaSmi8), U8(10), // |
| 7735 B(StaContextSlot), R(context), U8(4), // |
| 7736 B(LdaSmi8), U8(20), // |
| 7737 B(LdaContextSlot), R(context), U8(4), // |
| 7738 B(JumpIfNotHole), U8(11), // |
| 7739 B(LdaConstant), U8(1), // |
| 7740 B(Star), R(2), // |
| 7741 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| 7742 B(LdaConstant), U8(1), // |
| 7743 B(Star), R(2), // |
| 7744 B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(2), // |
| 7745 U8(1), // |
| 7746 B(LdaUndefined), // |
| 7747 B(Return) // |
| 7748 }, |
| 7749 2, |
| 7750 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7751 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7752 }; |
| 7753 |
| 7754 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7755 Handle<BytecodeArray> bytecode_array = |
| 7756 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7757 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7758 } |
| 7759 } |
| 7760 |
| 7761 TEST(LetVariableContextSlot) { |
| 7762 InitializedHandleScope handle_scope; |
| 7763 BytecodeGeneratorHelper helper; |
| 7764 |
| 7765 int closure = Register::function_closure().index(); |
| 7766 int context = Register::current_context().index(); |
| 7767 |
| 7768 ExpectedSnippet<InstanceType> snippets[] = { |
| 7769 {"let x = 10; function f1() {return x;}", |
| 7770 2 * kPointerSize, |
| 7771 1, |
| 7772 23, |
| 7773 { |
| 7774 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7775 U8(1), // |
| 7776 B(PushContext), R(1), // |
| 7777 B(LdaTheHole), // |
| 7778 B(StaContextSlot), R(context), U8(4), // |
| 7779 B(CreateClosure), U8(0), U8(0), // |
| 7780 B(Star), R(0), // |
| 7781 B(LdaSmi8), U8(10), // |
| 7782 B(StaContextSlot), R(context), U8(4), // |
| 7783 B(LdaUndefined), // |
| 7784 B(Return) // |
| 7785 }, |
| 7786 1, |
| 7787 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 7788 {"let x = 10; function f1() {return x;} return x;", |
| 7789 3 * kPointerSize, |
| 7790 1, |
| 7791 36, |
| 7792 { |
| 7793 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7794 U8(1), // |
| 7795 B(PushContext), R(1), // |
| 7796 B(LdaTheHole), // |
| 7797 B(StaContextSlot), R(context), U8(4), // |
| 7798 B(CreateClosure), U8(0), U8(0), // |
| 7799 B(Star), R(0), // |
| 7800 B(LdaSmi8), U8(10), // |
| 7801 B(StaContextSlot), R(context), U8(4), // |
| 7802 B(LdaContextSlot), R(context), U8(4), // |
| 7803 B(JumpIfNotHole), U8(11), // |
| 7804 B(LdaConstant), U8(1), // |
| 7805 B(Star), R(2), // |
| 7806 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| 7807 B(Return) // |
| 7808 }, |
| 7809 2, |
| 7810 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7811 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7812 {"let x = (x = 20); function f1() {return x;}", |
| 7813 4 * kPointerSize, |
| 7814 1, |
| 7815 44, |
| 7816 { |
| 7817 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7818 U8(1), // |
| 7819 B(PushContext), R(1), // |
| 7820 B(LdaTheHole), // |
| 7821 B(StaContextSlot), R(context), U8(4), // |
| 7822 B(CreateClosure), U8(0), U8(0), // |
| 7823 B(Star), R(0), // |
| 7824 B(LdaSmi8), U8(20), // |
| 7825 B(Star), R(2), // |
| 7826 B(LdaContextSlot), R(context), U8(4), // |
| 7827 B(JumpIfNotHole), U8(11), // |
| 7828 B(LdaConstant), U8(1), // |
| 7829 B(Star), R(3), // |
| 7830 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| 7831 B(Ldar), R(2), // |
| 7832 B(StaContextSlot), R(context), U8(4), // |
| 7833 B(StaContextSlot), R(context), U8(4), // |
| 7834 B(LdaUndefined), // |
| 7835 B(Return) // |
| 7836 }, |
| 7837 2, |
| 7838 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7839 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7840 {"let x = 10; x = 20; function f1() {return x;}", |
| 7841 4 * kPointerSize, |
| 7842 1, |
| 7843 46, |
| 7844 { |
| 7845 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7846 U8(1), // |
| 7847 B(PushContext), R(1), // |
| 7848 B(LdaTheHole), // |
| 7849 B(StaContextSlot), R(context), U8(4), // |
| 7850 B(CreateClosure), U8(0), U8(0), // |
| 7851 B(Star), R(0), // |
| 7852 B(LdaSmi8), U8(10), // |
| 7853 B(StaContextSlot), R(context), U8(4), // |
| 7854 B(LdaSmi8), U8(20), // |
| 7855 B(Star), R(2), // |
| 7856 B(LdaContextSlot), R(context), U8(4), // |
| 7857 B(JumpIfNotHole), U8(11), // |
| 7858 B(LdaConstant), U8(1), // |
| 7859 B(Star), R(3), // |
| 7860 B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| 7861 B(Ldar), R(2), // |
| 7862 B(StaContextSlot), R(context), U8(4), // |
| 7863 B(LdaUndefined), // |
| 7864 B(Return) // |
| 7865 }, |
| 7866 2, |
| 7867 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 7868 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 7869 }; |
| 7870 |
| 7871 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7872 Handle<BytecodeArray> bytecode_array = |
| 7873 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 7874 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7875 } |
| 7876 } |
| 7877 |
| 7878 TEST(LegacyConstVariableContextSlot) { |
| 7879 InitializedHandleScope handle_scope; |
| 7880 BytecodeGeneratorHelper helper; |
| 7881 |
| 7882 int closure = Register::function_closure().index(); |
| 7883 int context = Register::current_context().index(); |
| 7884 |
| 7885 ExpectedSnippet<InstanceType> snippets[] = { |
| 7886 {"const x = 10; function f1() {return x;} return x;", |
| 7887 3 * kPointerSize, |
| 7888 1, |
| 7889 39, |
| 7890 { |
| 7891 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7892 U8(1), // |
| 7893 B(PushContext), R(1), // |
| 7894 B(LdaTheHole), // |
| 7895 B(StaContextSlot), R(context), U8(4), // |
| 7896 B(CreateClosure), U8(0), U8(0), // |
| 7897 B(Star), R(0), // |
| 7898 B(LdaSmi8), U8(10), // |
| 7899 B(Star), R(2), // |
| 7900 B(LdaContextSlot), R(context), U8(4), // |
| 7901 B(JumpIfNotHole), U8(7), // |
| 7902 B(Ldar), R(2), // |
| 7903 B(StaContextSlot), R(context), U8(4), // |
| 7904 B(Ldar), R(2), // |
| 7905 B(LdaContextSlot), R(context), U8(4), // |
| 7906 B(JumpIfNotHole), U8(3), // |
| 7907 B(LdaUndefined), // |
| 7908 B(Return) // |
| 7909 }, |
| 7910 1, |
| 7911 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 7912 {"const x = (x = 20); function f1() {return x;}", |
| 7913 3 * kPointerSize, |
| 7914 1, |
| 7915 34, |
| 7916 { |
| 7917 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7918 U8(1), // |
| 7919 B(PushContext), R(1), // |
| 7920 B(LdaTheHole), // |
| 7921 B(StaContextSlot), R(context), U8(4), // |
| 7922 B(CreateClosure), U8(0), U8(0), // |
| 7923 B(Star), R(0), // |
| 7924 B(LdaSmi8), U8(20), // |
| 7925 B(Star), R(2), // |
| 7926 B(LdaContextSlot), R(context), U8(4), // |
| 7927 B(JumpIfNotHole), U8(7), // |
| 7928 B(Ldar), R(2), // |
| 7929 B(StaContextSlot), R(context), U8(4), // |
| 7930 B(Ldar), R(2), // |
| 7931 B(LdaUndefined), // |
| 7932 B(Return) // |
| 7933 }, |
| 7934 1, |
| 7935 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 7936 {"const x = 10; x = 20; function f1() {return x;}", |
| 7937 3 * kPointerSize, |
| 7938 1, |
| 7939 36, |
| 7940 { |
| 7941 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 7942 U8(1), // |
| 7943 B(PushContext), R(1), // |
| 7944 B(LdaTheHole), // |
| 7945 B(StaContextSlot), R(context), U8(4), // |
| 7946 B(CreateClosure), U8(0), U8(0), // |
| 7947 B(Star), R(0), // |
| 7948 B(LdaSmi8), U8(10), // |
| 7949 B(Star), R(2), // |
| 7950 B(LdaContextSlot), R(context), U8(4), // |
| 7951 B(JumpIfNotHole), U8(7), // |
| 7952 B(Ldar), R(2), // |
| 7953 B(StaContextSlot), R(context), U8(4), // |
| 7954 B(Ldar), R(2), // |
| 7955 B(LdaSmi8), U8(20), // |
| 7956 B(LdaUndefined), // |
| 7957 B(Return) // |
| 7958 }, |
| 7959 1, |
| 7960 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}}; |
| 7961 |
| 7962 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 7963 Handle<BytecodeArray> bytecode_array = |
| 7964 helper.MakeBytecodeForFunctionBodyWithLegacyConst( |
| 7965 snippets[i].code_snippet); |
| 7966 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 7967 } |
| 7968 } |
| 7969 |
7285 } // namespace interpreter | 7970 } // namespace interpreter |
7286 } // namespace internal | 7971 } // namespace internal |
7287 } // namespace v8 | 7972 } // namespace v8 |
OLD | NEW |