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

Unified Diff: test/cctest/compiler/compiler/test-run-jsbranches.cc

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" Created 6 years, 5 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/compiler/compiler/test-run-jsbranches.cc
diff --git a/test/cctest/compiler/compiler/test-run-jsbranches.cc b/test/cctest/compiler/compiler/test-run-jsbranches.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2eb4fa6d0f758763672a50d743ef72382c0e4807
--- /dev/null
+++ b/test/cctest/compiler/compiler/test-run-jsbranches.cc
@@ -0,0 +1,262 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "test/cctest/compiler/function-tester.h"
+
+using namespace v8::internal;
+using namespace v8::internal::compiler;
+
+TEST(Conditional) {
+ FunctionTester T("(function(a) { return a ? 23 : 42; })");
+
+ T.CheckCall(T.Val(23), T.true_value(), T.undefined());
+ T.CheckCall(T.Val(42), T.false_value(), T.undefined());
+ T.CheckCall(T.Val(42), T.undefined(), T.undefined());
+ T.CheckCall(T.Val(42), T.Val(0.0), T.undefined());
+ T.CheckCall(T.Val(23), T.Val(999), T.undefined());
+ T.CheckCall(T.Val(23), T.Val("x"), T.undefined());
+}
+
+
+TEST(LogicalAnd) {
+ FunctionTester T("(function(a,b) { return a && b; })");
+
+ T.CheckCall(T.true_value(), T.true_value(), T.true_value());
+ T.CheckCall(T.false_value(), T.false_value(), T.true_value());
+ T.CheckCall(T.false_value(), T.true_value(), T.false_value());
+ T.CheckCall(T.false_value(), T.false_value(), T.false_value());
+
+ T.CheckCall(T.Val(999), T.Val(777), T.Val(999));
+ T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(999));
+ T.CheckCall(T.Val("b"), T.Val("a"), T.Val("b"));
+}
+
+
+TEST(LogicalOr) {
+ FunctionTester T("(function(a,b) { return a || b; })");
+
+ T.CheckCall(T.true_value(), T.true_value(), T.true_value());
+ T.CheckCall(T.true_value(), T.false_value(), T.true_value());
+ T.CheckCall(T.true_value(), T.true_value(), T.false_value());
+ T.CheckCall(T.false_value(), T.false_value(), T.false_value());
+
+ T.CheckCall(T.Val(777), T.Val(777), T.Val(999));
+ T.CheckCall(T.Val(999), T.Val(0.0), T.Val(999));
+ T.CheckCall(T.Val("a"), T.Val("a"), T.Val("b"));
+}
+
+
+TEST(LogicalEffect) {
+ FunctionTester T("(function(a,b) { a && (b = a); return b; })");
+
+ T.CheckCall(T.true_value(), T.true_value(), T.true_value());
+ T.CheckCall(T.true_value(), T.false_value(), T.true_value());
+ T.CheckCall(T.true_value(), T.true_value(), T.false_value());
+ T.CheckCall(T.false_value(), T.false_value(), T.false_value());
+
+ T.CheckCall(T.Val(777), T.Val(777), T.Val(999));
+ T.CheckCall(T.Val(999), T.Val(0.0), T.Val(999));
+ T.CheckCall(T.Val("a"), T.Val("a"), T.Val("b"));
+}
+
+
+TEST(IfStatement) {
+ FunctionTester T("(function(a) { if (a) { return 1; } else { return 2; } })");
+
+ T.CheckCall(T.Val(1), T.true_value(), T.undefined());
+ T.CheckCall(T.Val(2), T.false_value(), T.undefined());
+ T.CheckCall(T.Val(2), T.undefined(), T.undefined());
+ T.CheckCall(T.Val(2), T.Val(0.0), T.undefined());
+ T.CheckCall(T.Val(1), T.Val(999), T.undefined());
+ T.CheckCall(T.Val(1), T.Val("x"), T.undefined());
+}
+
+
+TEST(DoWhileStatement) {
+ FunctionTester T("(function(a,b) { do { a+=23; } while(a < b) return a; })");
+
+ T.CheckCall(T.Val(24), T.Val(1), T.Val(1));
+ T.CheckCall(T.Val(24), T.Val(1), T.Val(23));
+ T.CheckCall(T.Val(47), T.Val(1), T.Val(25));
+ T.CheckCall(T.Val("str23"), T.Val("str"), T.Val("str"));
+}
+
+
+TEST(WhileStatement) {
+ FunctionTester T("(function(a,b) { while(a < b) { a+=23; } return a; })");
+
+ T.CheckCall(T.Val(1), T.Val(1), T.Val(1));
+ T.CheckCall(T.Val(24), T.Val(1), T.Val(23));
+ T.CheckCall(T.Val(47), T.Val(1), T.Val(25));
+ T.CheckCall(T.Val("str"), T.Val("str"), T.Val("str"));
+}
+
+
+TEST(ForStatement) {
+ FunctionTester T("(function(a,b) { for (; a < b; a+=23) {} return a; })");
+
+ T.CheckCall(T.Val(1), T.Val(1), T.Val(1));
+ T.CheckCall(T.Val(24), T.Val(1), T.Val(23));
+ T.CheckCall(T.Val(47), T.Val(1), T.Val(25));
+ T.CheckCall(T.Val("str"), T.Val("str"), T.Val("str"));
+}
+
+
+static void TestForIn(const char* code) {
+ FunctionTester T(code);
+ T.CheckCall(T.undefined(), T.undefined());
+ T.CheckCall(T.undefined(), T.null());
+ T.CheckCall(T.undefined(), T.NewObject("({})"));
+ T.CheckCall(T.undefined(), T.Val(1));
+ T.CheckCall(T.Val("2"), T.Val("str"));
+ T.CheckCall(T.Val("a"), T.NewObject("({'a' : 1})"));
+ T.CheckCall(T.Val("2"), T.NewObject("([1, 2, 3])"));
+ T.CheckCall(T.Val("a"), T.NewObject("({'a' : 1, 'b' : 1})"), T.Val("b"));
+ T.CheckCall(T.Val("1"), T.NewObject("([1, 2, 3])"), T.Val("2"));
+}
+
+
+TEST(ForInStatement) {
+ // Variable assignment.
+ TestForIn(
+ "(function(a, b) {"
+ "var last;"
+ "for (var x in a) {"
+ " if (b) { delete a[b]; b = undefined; }"
+ " last = x;"
+ "}"
+ "return last;})");
+ // Indexed assignment.
+ TestForIn(
+ "(function(a, b) {"
+ "var array = [0, 1, undefined];"
+ "for (array[2] in a) {"
+ " if (b) { delete a[b]; b = undefined; }"
+ "}"
+ "return array[2];})");
+ // Named assignment.
+ TestForIn(
+ "(function(a, b) {"
+ "var obj = {'a' : undefined};"
+ "for (obj.a in a) {"
+ " if (b) { delete a[b]; b = undefined; }"
+ "}"
+ "return obj.a;})");
+}
+
+
+TEST(SwitchStatement) {
+ const char* src =
+ "(function(a,b) {"
+ " var r = '-';"
+ " switch (a) {"
+ " case 'x' : r += 'X-';"
+ " case b + 'b': r += 'B-';"
+ " default : r += 'D-';"
+ " case 'y' : r += 'Y-';"
+ " }"
+ " return r;"
+ "})";
+ FunctionTester T(src);
+
+ T.CheckCall(T.Val("-X-B-D-Y-"), T.Val("x"), T.Val("B"));
+ T.CheckCall(T.Val("-B-D-Y-"), T.Val("Bb"), T.Val("B"));
+ T.CheckCall(T.Val("-D-Y-"), T.Val("z"), T.Val("B"));
+ T.CheckCall(T.Val("-Y-"), T.Val("y"), T.Val("B"));
+
+ CompileRun("var c = 0; var o = { toString:function(){return c++} };");
+ T.CheckCall(T.Val("-D-Y-"), T.Val("1b"), T.NewObject("o"));
+ T.CheckCall(T.Val("-B-D-Y-"), T.Val("1b"), T.NewObject("o"));
+ T.CheckCall(T.Val("-D-Y-"), T.Val("1b"), T.NewObject("o"));
+}
+
+
+TEST(BlockBreakStatement) {
+ FunctionTester T("(function(a,b) { L:{ if (a) break L; b=1; } return b; })");
+
+ T.CheckCall(T.Val(7), T.true_value(), T.Val(7));
+ T.CheckCall(T.Val(1), T.false_value(), T.Val(7));
+}
+
+
+TEST(BlockReturnStatement) {
+ FunctionTester T("(function(a,b) { L:{ if (a) b=1; return b; } })");
+
+ T.CheckCall(T.Val(1), T.true_value(), T.Val(7));
+ T.CheckCall(T.Val(7), T.false_value(), T.Val(7));
+}
+
+
+TEST(NestedIfConditional) {
+ FunctionTester T("(function(a,b) { if (a) { b = (b?b:7) + 1; } return b; })");
+
+ T.CheckCall(T.Val(4), T.false_value(), T.Val(4));
+ T.CheckCall(T.Val(6), T.true_value(), T.Val(5));
+ T.CheckCall(T.Val(8), T.true_value(), T.undefined());
+}
+
+
+TEST(NestedIfLogical) {
+ const char* src =
+ "(function(a,b) {"
+ " if (a || b) { return 1; } else { return 2; }"
+ "})";
+ FunctionTester T(src);
+
+ T.CheckCall(T.Val(1), T.true_value(), T.true_value());
+ T.CheckCall(T.Val(1), T.false_value(), T.true_value());
+ T.CheckCall(T.Val(1), T.true_value(), T.false_value());
+ T.CheckCall(T.Val(2), T.false_value(), T.false_value());
+ T.CheckCall(T.Val(1), T.Val(1.0), T.Val(1.0));
+ T.CheckCall(T.Val(1), T.Val(0.0), T.Val(1.0));
+ T.CheckCall(T.Val(1), T.Val(1.0), T.Val(0.0));
+ T.CheckCall(T.Val(2), T.Val(0.0), T.Val(0.0));
+}
+
+
+TEST(NestedIfElseFor) {
+ const char* src =
+ "(function(a,b) {"
+ " if (!a) { return b - 3; } else { for (; a < b; a++); }"
+ " return a;"
+ "})";
+ FunctionTester T(src);
+
+ T.CheckCall(T.Val(1), T.false_value(), T.Val(4));
+ T.CheckCall(T.Val(2), T.true_value(), T.Val(2));
+ T.CheckCall(T.Val(3), T.Val(3), T.Val(1));
+}
+
+
+TEST(NestedWhileWhile) {
+ const char* src =
+ "(function(a) {"
+ " var i = a; while (false) while(false) return i;"
+ " return i;"
+ "})";
+ FunctionTester T(src);
+
+ T.CheckCall(T.Val(2.0), T.Val(2.0), T.Val(-1.0));
+ T.CheckCall(T.Val(65.0), T.Val(65.0), T.Val(-1.0));
+}
+
+
+TEST(NestedForIf) {
+ FunctionTester T("(function(a,b) { for (; a > 1; a--) if (b) return 1; })");
+
+ T.CheckCall(T.Val(1), T.Val(3), T.true_value());
+ T.CheckCall(T.undefined(), T.Val(2), T.false_value());
+ T.CheckCall(T.undefined(), T.Val(1), T.null());
+}
+
+
+TEST(NestedForConditional) {
+ FunctionTester T("(function(a,b) { for (; a > 1; a--) return b ? 1 : 2; })");
+
+ T.CheckCall(T.Val(1), T.Val(3), T.true_value());
+ T.CheckCall(T.Val(2), T.Val(2), T.false_value());
+ T.CheckCall(T.undefined(), T.Val(1), T.null());
+}
« no previous file with comments | « test/cctest/compiler/compiler/test-run-intrinsics.cc ('k') | test/cctest/compiler/compiler/test-run-jscalls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698