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

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

Issue 1390483002: [Interpreter] Unary operators - typeof, void, and logical not. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review comments on patch set 3. Created 5 years, 2 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
« no previous file with comments | « src/runtime/runtime-interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c41dee3df9beae2c73dda7ea0252e570974e97ea..58c15a316e7b81b90f9e845987998af7423d68cb 100644
--- a/test/cctest/interpreter/test-bytecode-generator.cc
+++ b/test/cctest/interpreter/test-bytecode-generator.cc
@@ -1260,6 +1260,124 @@ TEST(BasicLoops) {
}
}
+
+TEST(UnaryOperators) {
+ InitializedHandleScope handle_scope;
+ BytecodeGeneratorHelper helper;
+
+ ExpectedSnippet<int> snippets[] = {
+ {"var x = 0;"
+ "while (x != 10) {"
+ " x = x + 10;"
+ "}"
+ "return x;",
+ 2 * kPointerSize,
+ 1,
+ 29,
+ {
+ B(LdaZero), //
+ B(Star), R(0), //
+ B(Jump), U8(12), //
+ B(Ldar), R(0), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(10), //
+ B(Add), R(1), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(10), //
+ B(TestEqual), R(1), //
+ B(LogicalNot), //
+ B(JumpIfTrue), U8(-19), //
+ B(Ldar), R(0), //
+ B(Return), //
+ },
+ 0},
+ {"var x = false;"
+ "do {"
+ " x = !x;"
+ "} while(x == false);"
+ "return x;",
+ 2 * kPointerSize,
+ 1,
+ 20,
+ {
+ B(LdaFalse), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(LogicalNot), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(Star), R(1), //
+ B(LdaFalse), //
+ B(TestEqual), R(1), //
+ B(JumpIfTrue), U8(-12), //
+ B(Ldar), R(0), //
+ B(Return), //
+ },
+ 0},
+ {"var x = 101;"
+ "return void(x * 3);",
+ 2 * kPointerSize,
+ 1,
+ 14,
+ {
+ B(LdaSmi8), U8(101), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(3), //
+ B(Mul), R(1), //
+ B(LdaUndefined), //
+ B(Return), //
+ },
+ 0},
+ {"var x = 1234;"
+ "var y = void (x * x - 1);"
+ "return y;",
+ 4 * kPointerSize,
+ 1,
+ 24,
+ {
+ B(LdaConstant), U8(0), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(Star), R(3), //
+ B(Ldar), R(0), //
+ B(Mul), R(3), //
+ B(Star), R(2), //
+ B(LdaSmi8), U8(1), //
+ B(Sub), R(2), //
+ B(LdaUndefined), //
+ B(Star), R(1), //
+ B(Ldar), R(1), //
+ B(Return), //
+ },
+ 1,
+ {1234}},
+ {"var x = 13;"
+ "return typeof(x);",
+ 1 * kPointerSize,
+ 1,
+ 8,
+ {
+ B(LdaSmi8), U8(13), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(TypeOf), //
+ 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);
+ }
+}
+
+
} // namespace interpreter
} // namespace internal
} // namespace v8
« no previous file with comments | « src/runtime/runtime-interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698