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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1412683011: [Interpreter] Enable assignments in expressions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Additional tests for conditional expressions. Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(rmcilroy): Remove this define after this flag is turned on globally 5 // TODO(rmcilroy): Remove this define after this flag is turned on globally
6 #define V8_IMMINENT_DEPRECATION_WARNINGS 6 #define V8_IMMINENT_DEPRECATION_WARNINGS
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/execution.h" 10 #include "src/execution.h"
(...skipping 2613 matching lines...) Expand 10 before | Expand all | Expand 10 after
2624 2624
2625 Handle<i::Object> return_value = callable().ToHandleChecked(); 2625 Handle<i::Object> return_value = callable().ToHandleChecked();
2626 CHECK(return_value->SameValue(*loops[i].second)); 2626 CHECK(return_value->SameValue(*loops[i].second));
2627 } 2627 }
2628 } 2628 }
2629 2629
2630 2630
2631 TEST(InterpreterForIn) { 2631 TEST(InterpreterForIn) {
2632 HandleAndZoneScope handles; 2632 HandleAndZoneScope handles;
2633 2633
2634 // TODO(oth): Add a test here for delete mid-loop when delete is ready.
2635 std::pair<const char*, int> for_in_samples[] = { 2634 std::pair<const char*, int> for_in_samples[] = {
2636 {"function f() {\n" 2635 {"function f() {\n"
2637 " var r = -1;\n" 2636 " var r = -1;\n"
2638 " for (var a in null) { r = a; }\n" 2637 " for (var a in null) { r = a; }\n"
2639 " return r;\n" 2638 " return r;\n"
2640 "}", 2639 "}",
2641 -1}, 2640 -1},
2642 {"function f() {\n" 2641 {"function f() {\n"
2643 " var r = -1;\n" 2642 " var r = -1;\n"
2644 " for (var a in undefined) { r = a; }\n" 2643 " for (var a in undefined) { r = a; }\n"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2891 for (size_t i = 0; i < arraysize(switch_ops); i++) { 2890 for (size_t i = 0; i < arraysize(switch_ops); i++) {
2892 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first)); 2891 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first));
2893 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2892 InterpreterTester tester(handles.main_isolate(), source.c_str());
2894 auto callable = tester.GetCallable<>(); 2893 auto callable = tester.GetCallable<>();
2895 2894
2896 Handle<i::Object> return_value = callable().ToHandleChecked(); 2895 Handle<i::Object> return_value = callable().ToHandleChecked();
2897 CHECK(return_value->SameValue(*switch_ops[i].second)); 2896 CHECK(return_value->SameValue(*switch_ops[i].second));
2898 } 2897 }
2899 } 2898 }
2900 2899
2900
2901 TEST(InterpreterAssignmentInExpressions) {
2902 HandleAndZoneScope handles;
2903
2904 std::pair<const char*, int> samples[] = {
2905 {"function f() {\n"
2906 " var x = 7;\n"
2907 " var y = x + (x = 1) + (x = 2);\n"
2908 " return y;\n"
2909 "}",
2910 10},
2911 {"function f() {\n"
2912 " var x = 7;\n"
2913 " var y = x + (x = 1) + (x = 2);\n"
2914 " return x;\n"
2915 "}",
2916 2},
2917 {"function f() {\n"
2918 " var x = 55;\n"
2919 " x = x + (x = 100) + (x = 101);\n"
2920 " return x;\n"
2921 "}",
2922 256},
2923 {"function f() {\n"
2924 " var x = 7;\n"
2925 " return ++x + x + x++;\n"
2926 "}",
2927 24},
2928 {"function f() {\n"
2929 " var x = 7;\n"
2930 " var y = ++x + x + x++;\n"
2931 " return x;\n"
2932 "}",
2933 9},
2934 {"function f() {\n"
2935 " var x = 7, y = 100, z = 1000;\n"
2936 " return x + (x += 3) + y + (y *= 10) + (z *= 7) + z;\n"
2937 "}",
2938 15117},
2939 {"function f() {\n"
2940 " var inner = function (x) { return x + (x = 2) + (x = 4) + x; };\n"
2941 " return inner(1);\n"
2942 "}",
2943 11},
2944 {"function f() {\n"
2945 " var x = 1, y = 2;\n"
2946 " x = x + (x = 3) + y + (y = 4), y = y + (y = 5) + y + x;\n"
2947 " return x + y;\n"
2948 "}",
2949 10 + 24},
2950 {"function f() {\n"
2951 " var x = 0;\n"
2952 " var y = x | (x = 1) | (x = 2);\n"
2953 " return x;\n"
2954 "}",
2955 2},
2956 {"function f() {\n"
2957 " var x = 0;\n"
2958 " var y = x || (x = 1);\n"
2959 " return x;\n"
2960 "}",
2961 1},
2962 {"function f() {\n"
2963 " var x = 1;\n"
2964 " var y = x && (x = 2) && (x = 3);\n"
2965 " return x;\n"
2966 "}",
2967 3},
2968 {"function f() {\n"
2969 " var x = 1;\n"
2970 " var y = x || (x = 2);\n"
2971 " return x;\n"
2972 "}",
2973 1},
2974 {"function f() {\n"
2975 " var x = 1;\n"
2976 " x = (x << (x = 3)) | (x = 16);\n"
2977 " return x;\n"
2978 "}",
2979 24},
2980 {"function f() {\n"
2981 " var r = 7;\n"
2982 " var s = 11;\n"
2983 " var t = 13;\n"
2984 " var u = r + s + t + (r = 10) + (s = 20) +"
2985 " (t = (r + s)) + r + s + t;\n"
2986 " return r + s + t + u;\n"
2987 "}",
2988 211},
2989 {"function f() {\n"
2990 " var r = 7;\n"
2991 " var s = 11;\n"
2992 " var t = 13;\n"
2993 " return r > (3 * s * (s = 1)) ? (t + (t += 1)) : (r + (r = 4));\n"
2994 "}",
2995 11},
2996 {"function f() {\n"
2997 " var r = 7;\n"
2998 " var s = 11;\n"
2999 " var t = 13;\n"
3000 " return r > (3 * s * (s = 0)) ? (t + (t += 1)) : (r + (r = 4));\n"
3001 "}",
3002 27},
3003 {"function f() {\n"
3004 " var r = 7;\n"
3005 " var s = 11;\n"
3006 " var t = 13;\n"
3007 " return (r + (r = 5)) > s ? r : t;\n"
3008 "}",
3009 5},
3010 };
3011
3012 for (size_t i = 0; i < arraysize(samples); i++) {
3013 InterpreterTester tester(handles.main_isolate(), samples[i].first);
3014 auto callable = tester.GetCallable<>();
3015 Handle<Object> return_val = callable().ToHandleChecked();
3016 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
3017 }
3018 }
3019
2901 } // namespace interpreter 3020 } // namespace interpreter
2902 } // namespace internal 3021 } // namespace internal
2903 } // namespace v8 3022 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698