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

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: Rebase. 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 2600 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 2611
2612 Handle<i::Object> return_value = callable().ToHandleChecked(); 2612 Handle<i::Object> return_value = callable().ToHandleChecked();
2613 CHECK(return_value->SameValue(*loops[i].second)); 2613 CHECK(return_value->SameValue(*loops[i].second));
2614 } 2614 }
2615 } 2615 }
2616 2616
2617 2617
2618 TEST(InterpreterForIn) { 2618 TEST(InterpreterForIn) {
2619 HandleAndZoneScope handles; 2619 HandleAndZoneScope handles;
2620 2620
2621 // TODO(oth): Add a test here for delete mid-loop when delete is ready.
2622 std::pair<const char*, int> for_in_samples[] = { 2621 std::pair<const char*, int> for_in_samples[] = {
2623 {"function f() {\n" 2622 {"function f() {\n"
2624 " var r = -1;\n" 2623 " var r = -1;\n"
2625 " for (var a in null) { r = a; }\n" 2624 " for (var a in null) { r = a; }\n"
2626 " return r;\n" 2625 " return r;\n"
2627 "}", 2626 "}",
2628 -1}, 2627 -1},
2629 {"function f() {\n" 2628 {"function f() {\n"
2630 " var r = -1;\n" 2629 " var r = -1;\n"
2631 " for (var a in undefined) { r = a; }\n" 2630 " for (var a in undefined) { r = a; }\n"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 for (size_t i = 0; i < arraysize(switch_ops); i++) { 2877 for (size_t i = 0; i < arraysize(switch_ops); i++) {
2879 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first)); 2878 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first));
2880 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2879 InterpreterTester tester(handles.main_isolate(), source.c_str());
2881 auto callable = tester.GetCallable<>(); 2880 auto callable = tester.GetCallable<>();
2882 2881
2883 Handle<i::Object> return_value = callable().ToHandleChecked(); 2882 Handle<i::Object> return_value = callable().ToHandleChecked();
2884 CHECK(return_value->SameValue(*switch_ops[i].second)); 2883 CHECK(return_value->SameValue(*switch_ops[i].second));
2885 } 2884 }
2886 } 2885 }
2887 2886
2887
2888 TEST(InterpreterAssignmentInExpressions) {
2889 HandleAndZoneScope handles;
2890
2891 std::pair<const char*, int> samples[] = {
2892 {"function f() {\n"
2893 " var x = 7;\n"
2894 " var y = x + (x = 1) + (x = 2);\n"
2895 " return y;\n"
2896 "}",
2897 10},
2898 {"function f() {\n"
2899 " var x = 7;\n"
2900 " var y = x + (x = 1) + (x = 2);\n"
2901 " return x;\n"
2902 "}",
2903 2},
2904 {"function f() {\n"
2905 " var x = 55;\n"
2906 " x = x + (x = 100) + (x = 101);\n"
2907 " return x;\n"
2908 "}",
2909 256},
2910 {"function f() {\n"
2911 " var x = 7;\n"
2912 " return ++x + x + x++;\n"
2913 "}",
2914 24},
2915 {"function f() {\n"
2916 " var x = 7;\n"
2917 " var y = 1 + ++x + x + x++;\n"
2918 " return x;\n"
2919 "}",
2920 9},
2921 {"function f() {\n"
2922 " var x = 7;\n"
2923 " var y = ++x + x + x++;\n"
2924 " return x;\n"
2925 "}",
2926 9},
2927 {"function f() {\n"
2928 " var x = 7, y = 100, z = 1000;\n"
2929 " return x + (x += 3) + y + (y *= 10) + (z *= 7) + z;\n"
2930 "}",
2931 15117},
2932 {"function f() {\n"
2933 " var inner = function (x) { return x + (x = 2) + (x = 4) + x; };\n"
2934 " return inner(1);\n"
2935 "}",
2936 11},
2937 {"function f() {\n"
2938 " var x = 1, y = 2;\n"
2939 " x = x + (x = 3) + y + (y = 4), y = y + (y = 5) + y + x;\n"
2940 " return x + y;\n"
2941 "}",
2942 10 + 24},
2943 {"function f() {\n"
2944 " var x = 0;\n"
2945 " var y = x | (x = 1) | (x = 2);\n"
2946 " return x;\n"
2947 "}",
2948 2},
2949 {"function f() {\n"
2950 " var x = 0;\n"
2951 " var y = x || (x = 1);\n"
2952 " return x;\n"
2953 "}",
2954 1},
2955 {"function f() {\n"
2956 " var x = 1;\n"
2957 " var y = x && (x = 2) && (x = 3);\n"
2958 " return x;\n"
2959 "}",
2960 3},
2961 {"function f() {\n"
2962 " var x = 1;\n"
2963 " var y = x || (x = 2);\n"
2964 " return x;\n"
2965 "}",
2966 1},
2967 {"function f() {\n"
2968 " var x = 1;\n"
2969 " x = (x << (x = 3)) | (x = 16);\n"
2970 " return x;\n"
2971 "}",
2972 24},
2973 {"function f() {\n"
2974 " var r = 7;\n"
2975 " var s = 11;\n"
2976 " var t = 13;\n"
2977 " var u = r + s + t + (r = 10) + (s = 20) +"
2978 " (t = (r + s)) + r + s + t;\n"
2979 " return r + s + t + u;\n"
2980 "}",
2981 211},
2982 {"function f() {\n"
2983 " var r = 7;\n"
2984 " var s = 11;\n"
2985 " var t = 13;\n"
2986 " return r > (3 * s * (s = 1)) ? (t + (t += 1)) : (r + (r = 4));\n"
2987 "}",
2988 11},
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 = 0)) ? (t + (t += 1)) : (r + (r = 4));\n"
2994 "}",
2995 27},
2996 {"function f() {\n"
2997 " var r = 7;\n"
2998 " var s = 11;\n"
2999 " var t = 13;\n"
3000 " return (r + (r = 5)) > s ? r : t;\n"
3001 "}",
3002 5},
rmcilroy 2015/11/05 16:34:51 Could you add a test for something like: functio
oth 2015/11/12 11:32:15 Done.
3003 };
3004
3005 for (size_t i = 0; i < arraysize(samples); i++) {
3006 InterpreterTester tester(handles.main_isolate(), samples[i].first);
3007 auto callable = tester.GetCallable<>();
3008 Handle<Object> return_val = callable().ToHandleChecked();
3009 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
3010 }
3011 }
3012
2888 } // namespace interpreter 3013 } // namespace interpreter
2889 } // namespace internal 3014 } // namespace internal
2890 } // namespace v8 3015 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698