Chromium Code Reviews| Index: test/cctest/interpreter/test-bytecode-generator.cc |
| diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc |
| index 7a62265a79492cd2943762c0915b958edc21c13c..c6e0405d02a17943c2dfe888b3682e456183dc73 100644 |
| --- a/test/cctest/interpreter/test-bytecode-generator.cc |
| +++ b/test/cctest/interpreter/test-bytecode-generator.cc |
| @@ -27,7 +27,6 @@ class BytecodeGeneratorHelper { |
| i::FLAG_ignition_filter = StrDup(kFunctionName); |
| i::FLAG_always_opt = false; |
| i::FLAG_allow_natives_syntax = true; |
| - i::FLAG_legacy_const = true; |
| CcTest::i_isolate()->interpreter()->Initialize(); |
| } |
| @@ -2291,30 +2290,34 @@ TEST(BreakableBlocks) { |
| "}\n", |
| 5 * kPointerSize, |
| 1, |
| - 39, |
| + 50, |
| { |
| - B(LdaConstant), U8(0), // |
| - B(Star), R(3), // |
| - B(Ldar), R(closure), // |
| - B(Star), R(4), // |
| - B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // |
| - B(PushContext), R(2), // |
| - B(LdaTheHole), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(CreateClosure), U8(1), U8(0), // |
| - B(Star), R(0), // |
| - B(LdaSmi8), U8(10), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(Ldar), R(0), // |
| - B(Star), R(1), // |
| - B(Jump), U8(2), // |
| - B(PopContext), R(2), // |
| - B(LdaUndefined), // |
| - B(Return), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(3), // |
| + B(Ldar), R(closure), // |
| + B(Star), R(4), // |
| + B(CallRuntime), U16(Runtime::kPushBlockContext), R(3), U8(2), // |
| + B(PushContext), R(2), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(1), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(2), // |
| + B(Star), R(3), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| + B(Star), R(1), // |
| + B(Jump), U8(2), // |
| + B(PopContext), R(2), // |
| + B(LdaUndefined), // |
| + B(Return), // |
| }, |
| - 2, |
| - {InstanceType::FIXED_ARRAY_TYPE, |
| - InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| + 3, |
| + {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| {"let x = 1;\n" |
| "outer: {\n" |
| " inner: {\n" |
| @@ -2327,44 +2330,68 @@ TEST(BreakableBlocks) { |
| "x = 4;", |
| 6 * kPointerSize, |
| 1, |
| - 72, |
| + 130, |
| { |
| - B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| - U8(1), // |
| - B(PushContext), R(2), // |
| - B(LdaTheHole), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(LdaSmi8), U8(1), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(LdaConstant), U8(0), // |
| - B(Star), R(4), // |
| - B(Ldar), R(closure), // |
| - B(Star), R(5), // |
| - B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| - B(PushContext), R(3), // |
| - B(LdaTheHole), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(CreateClosure), U8(1), U8(0), // |
| - B(Star), R(0), // |
| - B(LdaSmi8), U8(2), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(Ldar), R(0), // |
| - B(Star), R(1), // |
| - B(LdaContextSlot), R(context), U8(4), // |
| - B(JumpIfToBooleanFalse), U8(6), // |
| - B(PopContext), R(3), // |
| - B(Jump), U8(9), // |
| - B(LdaSmi8), U8(3), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(PopContext), R(3), // |
| - B(LdaSmi8), U8(4), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(LdaUndefined), // |
| - B(Return), // |
| - }, |
| - 2, |
| - {InstanceType::FIXED_ARRAY_TYPE, |
| - InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(2), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaSmi8), U8(1), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(4), // |
| + B(Ldar), R(closure), // |
| + B(Star), R(5), // |
| + B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| + B(PushContext), R(3), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(1), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(2), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(2), // |
| + B(Star), R(4), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
| + B(Star), R(1), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(3), // |
| + B(Star), R(4), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
| + B(JumpIfToBooleanFalse), U8(6), // |
| + B(PopContext), R(3), // |
| + B(Jump), U8(27), // |
| + B(LdaSmi8), U8(3), // |
| + B(Star), R(4), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(3), // |
| + B(Star), R(5), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), // |
| + B(Ldar), R(4), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(PopContext), R(3), // |
| + B(LdaSmi8), U8(4), // |
| + B(Star), R(4), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(4), // |
| + B(Star), R(5), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(5), U8(1), // |
| + B(Ldar), R(4), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return), // |
| + }, |
| + 5, |
| + {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| }; |
| for (size_t i = 0; i < arraysize(snippets); i++) { |
| @@ -2997,51 +3024,71 @@ TEST(BasicLoops) { |
| {"var a = 0;\n" |
| "while (a) {\n" |
| " { \n" |
| - " let z = 1;\n" |
| - " function f() { z = 2; }\n" |
| - " if (z) continue;\n" |
| - " z++;\n" |
| - " }\n" |
| - "}\n", |
| - 6 * kPointerSize, |
| - 1, |
| - 65, |
| - { |
| - B(LdaZero), // |
| - B(Star), R(1), // |
| - B(Ldar), R(1), // |
| - B(JumpIfToBooleanFalse), U8(58), // |
| - B(LdaConstant), U8(0), // |
| - B(Star), R(4), // |
| - B(Ldar), R(closure), // |
| - B(Star), R(5), // |
| - B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| - B(PushContext), R(3), // |
| - B(LdaTheHole), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(CreateClosure), U8(1), U8(0), // |
| - B(Star), R(0), // |
| - B(LdaSmi8), U8(1), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(Ldar), R(0), // |
| - B(Star), R(2), // |
| - B(LdaContextSlot), R(context), U8(4), // |
| - B(JumpIfToBooleanFalse), U8(6), // |
| - B(PopContext), R(3), // |
| - B(Jump), U8(-44), // |
| - B(LdaContextSlot), R(context), U8(4), // |
| - B(ToNumber), // |
| - B(Star), R(4), // |
| - B(Inc), // |
| - B(StaContextSlot), R(context), U8(4), // |
| - B(PopContext), R(3), // |
| - B(Jump), U8(-58), // |
| - B(LdaUndefined), // |
| - B(Return), // |
| - }, |
| - 2, |
| - {InstanceType::FIXED_ARRAY_TYPE, |
| - InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| + " let z = 1;\n" |
| + " function f() { z = 2; }\n" |
| + " if (z) continue;\n" |
| + " z++;\n" |
| + " }\n" |
| + "}\n", |
| + 7 * kPointerSize, |
| + 1, |
| + 116, |
| + { |
| + B(LdaZero), // |
| + B(Star), R(1), // |
| + B(Ldar), R(1), // |
| + B(JumpIfToBooleanFalse), U8(109), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(4), // |
| + B(Ldar), R(closure), // |
| + B(Star), R(5), // |
| + B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| + B(PushContext), R(3), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(1), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(1), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(2), // |
| + B(Star), R(4), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
| + B(Star), R(2), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(3), // |
| + B(Star), R(4), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
| + B(JumpIfToBooleanFalse), U8(6), // |
| + B(PopContext), R(3), // |
| + B(Jump), U8(-66), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(3), // |
| + B(Star), R(4), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), U8(1), // |
| + B(ToNumber), // |
| + B(Star), R(4), // |
| + B(Inc), // |
| + B(Star), R(5), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(3), // |
| + B(Star), R(6), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(6), U8(1), // |
| + B(Ldar), R(5), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(PopContext), R(3), // |
| + B(Jump), U8(-109), // |
| + B(LdaUndefined), // |
| + B(Return), // |
| + }, |
| + 4, |
| + {InstanceType::FIXED_ARRAY_TYPE, InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| }; |
| for (size_t i = 0; i < arraysize(snippets); i++) { |
| @@ -5625,6 +5672,9 @@ TEST(CreateRestArguments) { |
| } |
| TEST(IllegalRedeclaration) { |
| + bool old_legacy_const_flag = FLAG_legacy_const; |
| + FLAG_legacy_const = true; |
| + |
| InitializedHandleScope handle_scope; |
| BytecodeGeneratorHelper helper; |
| @@ -5654,6 +5704,8 @@ TEST(IllegalRedeclaration) { |
| helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| } |
| + |
| + FLAG_legacy_const = old_legacy_const_flag; |
| } |
| @@ -6549,27 +6601,38 @@ TEST(ThisFunction) { |
| ExpectedSnippet<int> snippets[] = { |
| {"var f;\n f = function f() { }", |
| - 1 * kPointerSize, |
| + 2 * kPointerSize, |
| 1, |
| - 9, |
| + 18, |
| { |
| - B(LdaTheHole), // |
| - B(Star), R(0), // |
| - B(Ldar), R(closure), // |
| - B(Star), R(0), // |
| - B(LdaUndefined), // |
| - B(Return), // |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(Ldar), R(closure), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(5), // |
| + B(Mov), R(1), R(0), // |
| + B(Ldar), R(1), // |
| + B(LdaUndefined), // |
| + B(Return), // |
| }}, |
| {"var f;\n f = function f() { return f; }", |
| - 1 * kPointerSize, |
| + 2 * kPointerSize, |
| 1, |
| - 8, |
| + 22, |
| { |
| - B(LdaTheHole), // |
| - B(Star), R(0), // |
| - B(Ldar), R(closure), // |
| - B(Star), R(0), // |
| - B(Return), // |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(Ldar), R(closure), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(5), // |
| + B(Mov), R(1), R(0), // |
| + B(Ldar), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(3), // |
| + B(LdaUndefined), // |
| + B(Return), // |
| }}, |
| }; |
| @@ -6587,27 +6650,38 @@ TEST(NewTarget) { |
| int new_target = Register::new_target().index(); |
| - ExpectedSnippet<int> snippets[] = { |
| + ExpectedSnippet<InstanceType> snippets[] = { |
| {"return new.target;", |
| - 1 * kPointerSize, |
| + 2 * kPointerSize, |
| 1, |
| - 5, |
| + 16, |
| { |
| - B(Ldar), R(new_target), // |
| - B(Star), R(0), // |
| - B(Return), // |
| - }}, |
| + B(Ldar), R(new_target), // |
| + B(Star), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(1), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| + B(Return), // |
| + }, |
| + 1, |
| + {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| {"new.target;", |
| - 1 * kPointerSize, |
| + 2 * kPointerSize, |
| 1, |
| - 6, |
| + 17, |
| { |
| - B(Ldar), R(new_target), // |
| - B(Star), R(0), // |
| - B(LdaUndefined), // |
| - B(Return), // |
| - }}, |
| - }; |
| + B(Ldar), R(new_target), // |
| + B(Star), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(1), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| + B(LdaUndefined), // |
| + B(Return), // |
| + }, |
| + 1, |
| + {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}}; |
| for (size_t i = 0; i < arraysize(snippets); i++) { |
| Handle<BytecodeArray> bytecode_array = |
| @@ -7633,6 +7707,521 @@ TEST(WideRegisters) { |
| } |
| } |
| +TEST(ConstVariable) { |
| + InitializedHandleScope handle_scope; |
| + BytecodeGeneratorHelper helper; |
| + |
|
rmcilroy
2016/02/04 15:19:39
nit - please add
// clang-format off
and at th
mythria
2016/02/04 16:08:00
Done.
|
| + ExpectedSnippet<const char*> snippets[] = { |
| + {"const x = 10;", |
| + 1 * kPointerSize, |
| + 1, |
| + 9, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(0), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 0}, |
| + {"const x = 10; return x;", |
| + 2 * kPointerSize, |
| + 1, |
| + 19, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(1), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {"x"}}, |
| + {"const x = ( x = 20);", |
| + 3 * kPointerSize, |
| + 1, |
| + 31, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(2), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| + B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), // |
| + U8(0), // |
|
rmcilroy
2016/02/04 15:19:39
/* */ U8(0)
(and below).
mythria
2016/02/04 16:07:59
Done.
|
| + B(Ldar), R(1), // |
| + B(Star), R(0), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {"x"}}, |
| + {"const x = 10; x = 20;", |
| + 3 * kPointerSize, |
| + 1, |
| + 35, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(2), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| + B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), // |
| + U8(0), // |
| + B(Ldar), R(1), // |
| + B(Star), R(0), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {"x"}}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(snippets); i++) { |
| + Handle<BytecodeArray> bytecode_array = |
| + helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| + CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| + } |
| +} |
| + |
| +TEST(LetVariable) { |
| + InitializedHandleScope handle_scope; |
| + BytecodeGeneratorHelper helper; |
| + |
|
rmcilroy
2016/02/04 15:19:39
ditto
mythria
2016/02/04 16:08:00
Done.
|
| + ExpectedSnippet<const char*> snippets[] = { |
| + {"let x = 10;", |
| + 1 * kPointerSize, |
| + 1, |
| + 9, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(0), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 0}, |
| + {"let x = 10; return x;", |
| + 2 * kPointerSize, |
| + 1, |
| + 19, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(1), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {"x"}}, |
| + {"let x = (x = 20);", |
| + 3 * kPointerSize, |
| + 1, |
| + 26, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(2), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| + B(Ldar), R(1), // |
| + B(Star), R(0), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {"x"}}, |
| + {"let x = 10; x = 20;", |
| + 3 * kPointerSize, |
| + 1, |
| + 30, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(0), // |
| + B(Star), R(2), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| + B(Ldar), R(1), // |
| + B(Star), R(0), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {"x"}}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(snippets); i++) { |
| + Handle<BytecodeArray> bytecode_array = |
| + helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| + CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| + } |
| +} |
| + |
| +TEST(LegacyConstVariable) { |
| + bool old_legacy_const_flag = FLAG_legacy_const; |
| + FLAG_legacy_const = true; |
| + |
| + InitializedHandleScope handle_scope; |
| + BytecodeGeneratorHelper helper; |
| + |
| + ExpectedSnippet<const char*> snippets[] = { |
| + {"const x = 10;", |
| + 2 * kPointerSize, |
| + 1, |
| + 18, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(5), // |
| + B(Mov), R(1), R(0), // |
| + B(Ldar), R(1), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 0}, |
| + {"const x = 10; return x;", |
| + 2 * kPointerSize, |
| + 1, |
| + 22, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(5), // |
| + B(Mov), R(1), R(0), // |
| + B(Ldar), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(3), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 0}, |
| + {"const x = ( x = 20);", |
| + 2 * kPointerSize, |
| + 1, |
| + 22, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(Ldar), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(5), // |
| + B(Mov), R(1), R(0), // |
| + B(Ldar), R(1), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 0}, |
| + {"const x = 10; x = 20;", |
| + 2 * kPointerSize, |
| + 1, |
| + 26, |
| + { |
| + B(LdaTheHole), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(JumpIfNotHole), U8(5), // |
| + B(Mov), R(1), R(0), // |
| + B(Ldar), R(1), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(1), // |
| + B(Ldar), R(0), // |
| + B(Ldar), R(1), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 0}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(snippets); i++) { |
| + Handle<BytecodeArray> bytecode_array = |
| + helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| + CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| + } |
| + |
| + FLAG_legacy_const = old_legacy_const_flag; |
| +} |
| + |
| +TEST(ConstVariableContextSlot) { |
| + InitializedHandleScope handle_scope; |
| + BytecodeGeneratorHelper helper; |
| + |
| + int closure = Register::function_closure().index(); |
| + int context = Register::current_context().index(); |
| + |
| + // TODO(mythria): Add tests for initialization of this via super calls. |
| + // TODO(mythria): Add tests that walk the context chain. |
|
rmcilroy
2016/02/04 15:19:39
ditto
mythria
2016/02/04 16:07:59
Done.
|
| + ExpectedSnippet<InstanceType> snippets[] = { |
| + {"const x = 10; function f1() {return x;}", |
| + 2 * kPointerSize, |
| + 1, |
| + 23, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| + {"const x = 10; function f1() {return x;} return x;", |
| + 3 * kPointerSize, |
| + 1, |
| + 36, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(1), // |
| + B(Star), R(2), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| + B(Return) // |
| + }, |
| + 2, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| + {"const x = (x = 20); function f1() {return x;}", |
| + 4 * kPointerSize, |
| + 1, |
| + 49, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(2), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(1), // |
| + B(Star), R(3), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| + B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), // |
| + U8(0), // |
| + B(Ldar), R(2), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 2, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| + {"const x = 10; x = 20; function f1() {return x;}", |
| + 4 * kPointerSize, |
| + 1, |
| + 51, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(2), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(1), // |
| + B(Star), R(3), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| + B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(0), // |
| + U8(0), // |
| + B(Ldar), R(2), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 2, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(snippets); i++) { |
| + Handle<BytecodeArray> bytecode_array = |
| + helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| + CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| + } |
| +} |
| + |
| +TEST(LetVariableContextSlot) { |
| + InitializedHandleScope handle_scope; |
| + BytecodeGeneratorHelper helper; |
| + |
| + int closure = Register::function_closure().index(); |
| + int context = Register::current_context().index(); |
| + |
| + ExpectedSnippet<InstanceType> snippets[] = { |
|
rmcilroy
2016/02/04 15:19:39
ditto
mythria
2016/02/04 16:07:59
Done.
|
| + {"let x = 10; function f1() {return x;}", |
| + 2 * kPointerSize, |
| + 1, |
| + 23, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 1, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| + {"let x = 10; function f1() {return x;} return x;", |
| + 3 * kPointerSize, |
| + 1, |
| + 36, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(1), // |
| + B(Star), R(2), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(2), U8(1), // |
| + B(Return) // |
| + }, |
| + 2, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| + {"let x = (x = 20); function f1() {return x;}", |
| + 4 * kPointerSize, |
| + 1, |
| + 44, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(2), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(1), // |
| + B(Star), R(3), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| + B(Ldar), R(2), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 2, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| + {"let x = 10; x = 20; function f1() {return x;}", |
| + 4 * kPointerSize, |
| + 1, |
| + 46, |
| + { |
| + B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| + U8(1), // |
| + B(PushContext), R(1), // |
| + B(LdaTheHole), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(CreateClosure), U8(0), U8(0), // |
| + B(Star), R(0), // |
| + B(LdaSmi8), U8(10), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaSmi8), U8(20), // |
| + B(Star), R(2), // |
| + B(LdaContextSlot), R(context), U8(4), // |
| + B(JumpIfNotHole), U8(11), // |
| + B(LdaConstant), U8(1), // |
| + B(Star), R(3), // |
| + B(CallRuntime), U16(Runtime::kThrowReferenceError), R(3), U8(1), // |
| + B(Ldar), R(2), // |
| + B(StaContextSlot), R(context), U8(4), // |
| + B(LdaUndefined), // |
| + B(Return) // |
| + }, |
| + 2, |
| + {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(snippets); i++) { |
| + Handle<BytecodeArray> bytecode_array = |
| + helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| + CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| + } |
| +} |
| + |
| TEST(DoExpression) { |
| bool old_flag = FLAG_harmony_do_expressions; |
| FLAG_harmony_do_expressions = true; |