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

Unified Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1634153002: [Interpreter] Adds support for const/let variables to interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased the patch Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 124f12508c64a951382604da53b4c28018e4068a..8ccc7331f1c1edc678db85ea6877cdfbab5db3b5 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;
+ 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);
@@ -2299,30 +2306,35 @@ 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,
+ 3,
{InstanceType::FIXED_ARRAY_TYPE,
- InstanceType::SHARED_FUNCTION_INFO_TYPE}},
+ InstanceType::SHARED_FUNCTION_INFO_TYPE,
+ InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
{"let x = 1;\n"
"outer: {\n"
" inner: {\n"
@@ -2335,7 +2347,7 @@ TEST(BreakableBlocks) {
"x = 4;",
6 * kPointerSize,
1,
- 72,
+ 130,
{
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
U8(1), //
@@ -2357,22 +2369,48 @@ 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
+ 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
+ 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++) {
@@ -3005,51 +3043,72 @@ 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++) {
@@ -5526,7 +5585,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);
}
}
@@ -6424,27 +6484,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), //
}},
};
@@ -6462,27 +6533,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 =
@@ -7282,6 +7364,609 @@ TEST(DeleteLookupSlotInEval) {
}
}
+TEST(ConstVariable) {
+ InitializedHandleScope handle_scope;
+ BytecodeGeneratorHelper helper;
+
+ 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);",
+ 2 * kPointerSize,
+ 1,
+ 27,
+ {
+ B(LdaTheHole), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(20), //
+ B(LdaConstant), U8(0), //
+ B(Star), R(1), //
+ B(Ldar), R(0), //
+ B(JumpIfNotHole), U8(7), //
+ B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
+ B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(1), //
+ U8(1), //
+ B(Star), R(0), //
+ B(LdaUndefined), //
+ B(Return) //
+ },
+ 1,
+ {"x"}},
+ {"const x = 10; x = 20;",
+ 2 * kPointerSize,
+ 1,
+ 29,
+ {
+ B(LdaTheHole), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(10), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(20), //
+ B(LdaConstant), U8(0), //
+ B(Star), R(1), //
+ B(Ldar), R(0), //
+ B(JumpIfNotHole), U8(7), //
+ B(CallRuntime), U16(Runtime::kThrowReferenceError), R(1), U8(1), //
+ B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(1), //
+ U8(1), //
+ 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;",
+ 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,
+ 18,
+ {
+ B(LdaTheHole), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(20), //
+ 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; x = 20;",
+ 2 * kPointerSize,
+ 1,
+ 20,
+ {
+ 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(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;}",
+ 3 * 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(20), //
+ 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(LdaConstant), U8(1), //
+ B(Star), R(2), //
+ B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(2), //
+ U8(1), //
+ 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;}",
+ 3 * kPointerSize,
+ 1,
+ 48,
+ {
+ 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(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(LdaConstant), U8(1), //
+ B(Star), R(2), //
+ B(CallRuntime), U16(Runtime::kThrowConstAssignError), R(2), //
+ U8(1), //
+ 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);
+ }
+}
+
+TEST(LegacyConstVariableContextSlot) {
+ InitializedHandleScope handle_scope;
+ BytecodeGeneratorHelper helper;
+
+ int closure = Register::function_closure().index();
+ int context = Register::current_context().index();
+
+ ExpectedSnippet<InstanceType> snippets[] = {
+ {"const x = 10; function f1() {return x;} return x;",
+ 3 * kPointerSize,
+ 1,
+ 39,
+ {
+ 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(Star), R(2), //
+ B(LdaContextSlot), R(context), U8(4), //
+ B(JumpIfNotHole), U8(7), //
+ B(Ldar), R(2), //
+ B(StaContextSlot), R(context), U8(4), //
+ B(Ldar), R(2), //
+ B(LdaContextSlot), R(context), U8(4), //
+ B(JumpIfNotHole), U8(3), //
+ B(LdaUndefined), //
+ B(Return) //
+ },
+ 1,
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
+ {"const x = (x = 20); function f1() {return x;}",
+ 3 * kPointerSize,
+ 1,
+ 34,
+ {
+ 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(7), //
+ B(Ldar), R(2), //
+ B(StaContextSlot), R(context), U8(4), //
+ B(Ldar), R(2), //
+ B(LdaUndefined), //
+ B(Return) //
+ },
+ 1,
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
+ {"const x = 10; x = 20; function f1() {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(Star), R(2), //
+ B(LdaContextSlot), R(context), U8(4), //
+ B(JumpIfNotHole), U8(7), //
+ B(Ldar), R(2), //
+ B(StaContextSlot), R(context), U8(4), //
+ B(Ldar), R(2), //
+ B(LdaSmi8), U8(20), //
+ B(LdaUndefined), //
+ B(Return) //
+ },
+ 1,
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}}};
+
+ for (size_t i = 0; i < arraysize(snippets); i++) {
+ Handle<BytecodeArray> bytecode_array =
+ helper.MakeBytecodeForFunctionBodyWithLegacyConst(
+ snippets[i].code_snippet);
+ CheckBytecodeArrayEqual(snippets[i], bytecode_array);
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698