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

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

Issue 1396693003: [Interpreter] Add function literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_newcontext
Patch Set: Make CreateClosure a bytecode 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
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 a73cabab080e53bf65e06b302dac66b8c3c50d38..878069b993a5c2b943cff8c85e9e1702c575928c 100644
--- a/test/cctest/interpreter/test-bytecode-generator.cc
+++ b/test/cctest/interpreter/test-bytecode-generator.cc
@@ -121,6 +121,11 @@ static void CheckConstant(Handle<Object> expected, Object* actual) {
}
+static void CheckConstant(InstanceType expected, Object* actual) {
Michael Starzinger 2015/10/09 13:19:00 nit: How would you feel about s/CheckConstant/Chec
rmcilroy 2015/10/12 17:00:15 This would require rewriting the CheckBytecodeArra
Michael Starzinger 2015/10/13 07:56:14 Acknowledged. Yep, fine with me.
+ CHECK_EQ(expected, HeapObject::cast(actual)->map()->instance_type());
+}
+
+
template <typename T>
static void CheckBytecodeArrayEqual(struct ExpectedSnippet<T> expected,
Handle<BytecodeArray> actual,
@@ -1744,6 +1749,63 @@ TEST(UnaryOperators) {
}
+TEST(FunctionLiterals) {
+ InitializedHandleScope handle_scope;
+ BytecodeGeneratorHelper helper;
+
+ ExpectedSnippet<InstanceType> snippets[] = {
+ {"return function(){ }",
+ 0,
+ 1,
+ 5,
+ {
+ B(LdaConstant), U8(0), //
+ B(CreateClosure), U8(0), //
+ B(Return) //
+ },
+ 1,
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
+ {"return (function(){ })()",
+ 2 * kPointerSize,
+ 1,
+ 14,
+ {
+ B(LdaConstant), U8(0), //
+ B(CreateClosure), U8(0), //
+ B(Star), R(0), //
+ B(LdaUndefined), //
+ B(Star), R(1), //
+ B(Call), R(0), R(1), U8(0), //
+ B(Return) //
+ },
+ 1,
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
+ {"return (function(x){ return x; })(1)",
+ 3 * kPointerSize,
+ 1,
+ 18,
+ {
+ B(LdaConstant), U8(0), //
+ B(CreateClosure), U8(0), //
+ B(Star), R(0), //
+ B(LdaUndefined), //
+ B(Star), R(1), //
+ B(LdaSmi8), U8(1), //
+ B(Star), R(2), //
+ B(Call), R(0), R(1), U8(1), //
+ B(Return) //
+ },
+ 1,
+ {InstanceType::SHARED_FUNCTION_INFO_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);
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698