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 b730fa63ebe15a0ff2f637a3da14b19dda0cc968..81f813eba9d6085fc85229585bc4794c5aa60f0d 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(); |
} |
@@ -74,6 +73,14 @@ class BytecodeGeneratorHelper { |
return MakeBytecode(program.start(), kFunctionName); |
} |
+ Handle<BytecodeArray> MakeBytecodeForFunctionBodyWithLegacyConst( |
+ const char* body) { |
+ 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.
|
+ Handle<BytecodeArray> bytecode_array = MakeBytecodeForFunctionBody(body); |
+ i::FLAG_legacy_const = false; |
+ return bytecode_array; |
+ } |
+ |
Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) { |
ScopedVector<char> program(3072); |
SNPrintF(program, "%s\n%s();", function, kFunctionName); |
@@ -2292,30 +2299,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" |
@@ -2328,10 +2339,10 @@ TEST(BreakableBlocks) { |
"x = 4;", |
6 * kPointerSize, |
1, |
- 72, |
+ 130, |
{ |
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
- U8(1), // |
+ U8(1), // |
B(PushContext), R(2), // |
B(LdaTheHole), // |
B(StaContextSlot), R(context), U8(4), // |
@@ -2350,22 +2361,47 @@ TEST(BreakableBlocks) { |
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(JumpIfNotHole), U8(11), // |
+ B(LdaConstant), U8(2), // |
+ B(Star), R(4), // |
+ B(CallRuntime), U16(Runtime::kThrowReferenceError), R(4), |
+ 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
|
+ 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), // 100 |
rmcilroy
2016/02/03 12:28:27
ditto
mythria
2016/02/04 10:28:53
Done.
|
+ 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++) { |
@@ -2998,51 +3034,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++) { |
@@ -5519,7 +5575,8 @@ TEST(IllegalRedeclaration) { |
for (size_t i = 0; i < arraysize(snippets); i++) { |
Handle<BytecodeArray> bytecode_array = |
- helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
+ helper.MakeBytecodeForFunctionBodyWithLegacyConst( |
+ snippets[i].code_snippet); |
CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
} |
} |
@@ -6417,27 +6474,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), // |
}}, |
}; |
@@ -6455,27 +6523,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 = |
@@ -7501,6 +7580,525 @@ TEST(WideRegisters) { |
} |
} |
+TEST(ConstVariable) { |
+ InitializedHandleScope handle_scope; |
+ BytecodeGeneratorHelper helper; |
+ |
+ ExpectedSnippet<const char*> snippets[] = { |
+ { |
+ "const x = 10;", |
rmcilroy
2016/02/03 12:28:26
Fix indentation
mythria
2016/02/04 10:28:53
Done.
|
+ 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), // |
+ 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; |
+ |
+ ExpectedSnippet<const char*> snippets[] = { |
+ { |
+ "let x = 10;", |
rmcilroy
2016/02/03 12:28:27
Fix indentation
mythria
2016/02/04 10:28:53
Done.
|
+ 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) { |
+ 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.MakeBytecodeForFunctionBodyWithLegacyConst( |
+ snippets[i].code_snippet); |
+ CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
+ } |
+} |
+ |
+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. |
+ 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[] = { |
+ {"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); |
+ } |
+} |
rmcilroy
2016/02/03 12:28:27
Nice set of tests, thanks!
|
+ |
TEST(DoExpression) { |
bool old_flag = FLAG_harmony_do_expressions; |
FLAG_harmony_do_expressions = true; |