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

Unified Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1509273005: Adds additional tests for bytecode graph builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/compiler/test-run-bytecode-graph-builder.cc
diff --git a/test/cctest/compiler/test-run-bytecode-graph-builder.cc b/test/cctest/compiler/test-run-bytecode-graph-builder.cc
index 8a836772426bfac34655c5bef22cf35a2f991399..1f5c4ea5f027fdccda02c4a494524b3026137575 100644
--- a/test/cctest/compiler/test-run-bytecode-graph-builder.cc
+++ b/test/cctest/compiler/test-run-bytecode-graph-builder.cc
@@ -200,9 +200,8 @@ TEST(BytecodeGraphBuilderReturnStatements) {
{"return 3.7e-60;", {factory->NewNumber(3.7e-60)}},
{"return -3.7e60;", {factory->NewNumber(-3.7e60)}},
{"return '';", {factory->NewStringFromStaticChars("")}},
- {"return 'catfood';", {factory->NewStringFromStaticChars("catfood")}}
- // TODO(oth): {"return NaN;", {factory->NewNumber(NAN)}}
- };
+ {"return 'catfood';", {factory->NewStringFromStaticChars("catfood")}},
+ {"return NaN;", {factory->NewNumber(NAN)}}};
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
for (size_t i = 0; i < num_snippets; i++) {
@@ -692,7 +691,11 @@ TEST(BytecodeGraphBuilderGlobals) {
SPACE, " var b = global_obj.name;\n") "global = 'xyz'; return "
"global };\n f();\n",
{factory->NewStringFromStaticChars("xyz")}},
- // TODO(rmcilroy): Add tests for typeof_mode once we have typeof support.
+ {"function f() { return typeof(undeclared_var); }\n; f();\n",
+ {factory->NewStringFromStaticChars("undefined")}},
+ {"var defined_var = 10; function f() { return typeof(defined_var); }\n; "
+ "f();\n",
+ {factory->NewStringFromStaticChars("number")}},
};
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
@@ -706,12 +709,36 @@ TEST(BytecodeGraphBuilderGlobals) {
TEST(BytecodeGraphBuilderCast) {
Michael Starzinger 2015/12/09 16:12:48 nit: We could rename this test to something like "
mythria 2015/12/09 17:19:47 Done.
- // TODO(mythria): tests for ToBoolean, ToObject, ToName, ToNumber.
- // They need other unimplemented features to test.
- // ToBoolean -> If
- // ToObject -> ForIn
- // ToNumber -> Inc/Dec
- // ToName -> CreateObjectLiteral
+ // TODO(mythria): tests for ToObject. Needs ForIn.
+ HandleAndZoneScope scope;
+ Isolate* isolate = scope.main_isolate();
+ Zone* zone = scope.main_zone();
+ Factory* factory = isolate->factory();
+
+ ExpectedSnippet<0> snippets[] = {
+ {"var a = 'val'; var obj = {[a] : 10}; return obj.val;",
+ {factory->NewNumberFromInt(10)}},
+ {"var a = 20; var obj = {[a] : 10}; return obj['20'];",
+ {factory->NewNumberFromInt(10)}},
+ {"var a = 20; var obj = {[a] : 10}; return obj[20];",
+ {factory->NewNumberFromInt(10)}},
+ {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];",
+ {factory->NewNumberFromInt(10)}},
+ {"var a = {val:23}; var obj = {[a] : 10}; return obj['[object Object]'];",
+ {factory->NewNumberFromInt(10)}},
mythria 2015/12/09 14:14:54 Is this test Ok? I will remove it if ToName of an
Michael Starzinger 2015/12/09 16:12:49 Acknowledged. Should be fine as it is. You could
mythria 2015/12/09 17:19:47 Thanks for the tests. Done.
+ };
+
+ size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
+ for (size_t i = 0; i < num_snippets; i++) {
+ ScopedVector<char> script(1024);
+ SNPrintF(script, "function %s() { %s }\n%s({});", kFunctionName,
+ snippets[i].code_snippet, kFunctionName);
+
+ BytecodeGraphTester tester(isolate, zone, script.start());
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*snippets[i].return_value()));
+ }
}
@@ -864,8 +891,6 @@ TEST(BytecodeGraphBuilderDelete) {
{"'use strict'; delete p1.name; return p1.val;",
{factory->NewNumberFromInt(10),
BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}},
- // TODO(mythria): Add tests for global and unallocated when we have
- // support for LdaContextSlot
};
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
@@ -883,6 +908,61 @@ TEST(BytecodeGraphBuilderDelete) {
}
+TEST(BytecodeGraphBuilderDeleteGlobal) {
+ HandleAndZoneScope scope;
+ Isolate* isolate = scope.main_isolate();
+ Zone* zone = scope.main_zone();
+ Factory* factory = isolate->factory();
+
+ ExpectedSnippet<0> snippets[] = {
+ {"var obj = {val : 10, type : 'int'};"
+ "function f() {return delete obj;};",
+ {factory->false_value()}},
+ {"var obj = {val : 10, type : 'int'};"
+ "function f() {return delete this;};",
+ {factory->true_value()}},
+ {"var obj = {val : 10, type : 'int'};"
+ "function f() {return delete obj.val;};",
+ {factory->true_value()}},
+ {"var obj = {val : 10, type : 'int'};"
+ "function f() {'use strict'; return delete obj.val;};",
+ {factory->true_value()}},
+ {"var obj = {val : 10, type : 'int'};"
+ "function f() {delete obj.val; return obj.val;};",
+ {factory->undefined_value()}},
+ {"var obj = {val : 10, type : 'int'};"
+ "function f() {'use strict'; delete obj.val; return obj.val;};",
+ {factory->undefined_value()}},
+ {"var obj = {1 : 10, 2 : 20};"
+ "function f() { return delete obj[1]; };",
+ {factory->true_value()}},
+ {"var obj = {1 : 10, 2 : 20};"
+ "function f() { 'use strict'; return delete obj[1];};",
+ {factory->true_value()}},
+ {"obj = {1 : 10, 2 : 20};"
+ "function f() { delete obj[1]; return obj[2];};",
+ {factory->NewNumberFromInt(20)}},
+ {"function f() {"
+ " var obj = {1 : 10, 2 : 20};"
+ " function inner() { return obj[1]; };"
+ " return delete obj[1];"
+ "}",
+ {factory->true_value()}},
+ };
+
+ size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
+ for (size_t i = 0; i < num_snippets; i++) {
+ ScopedVector<char> script(1024);
+ SNPrintF(script, "%s %s({});", snippets[i].code_snippet, kFunctionName);
+
+ BytecodeGraphTester tester(isolate, zone, script.start());
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*snippets[i].return_value()));
+ }
+}
+
+
bool get_compare_result(Token::Value opcode, Handle<Object> lhs_value,
Handle<Object> rhs_value) {
switch (opcode) {
@@ -1022,7 +1102,39 @@ TEST(BytecodeGraphBuilderTestIn) {
TEST(BytecodeGraphBuilderTestInstanceOf) {
- // TODO(mythria): Add tests when CreateLiterals/CreateClousre are supported.
+ HandleAndZoneScope scope;
+ Isolate* isolate = scope.main_isolate();
+ Zone* zone = scope.main_zone();
+ Factory* factory = isolate->factory();
+
+ ExpectedSnippet<1> snippets[] = {
+ {"return p1 instanceof Object;",
+ {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}},
+ {"return p1 instanceof String;",
+ {factory->false_value(), factory->NewStringFromStaticChars("string")}},
+ {"var cons = function() { this.val = 10; this.type = 'int'; };"
Michael Starzinger 2015/12/09 16:12:48 nit: Properties are never used, empty function wou
mythria 2015/12/09 17:19:47 Done.
+ "var obj = new cons();"
+ "return obj instanceof cons;",
+ {factory->true_value(), factory->undefined_value()}},
+ {"return typeof p1;",
+ {factory->NewStringFromStaticChars("boolean"), factory->true_value()}},
+ {"return typeof p1;",
+ {factory->NewStringFromStaticChars("string"),
+ factory->NewStringFromStaticChars("abc")}},
+ };
+
+ size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
+ for (size_t i = 0; i < num_snippets; i++) {
+ ScopedVector<char> script(1024);
+ SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName,
+ snippets[i].code_snippet, kFunctionName);
+
+ BytecodeGraphTester tester(isolate, zone, script.start());
+ auto callable = tester.GetCallable<Handle<Object>>();
+ Handle<Object> return_value =
+ callable(snippets[i].parameter(0)).ToHandleChecked();
+ CHECK(return_value->SameValue(*snippets[i].return_value()));
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698