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

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: Move AssignmentHazardHelper to be an inner class of BytecodeGenerator. 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2944 InterpreterTester tester(handles.main_isolate(), 2943 InterpreterTester tester(handles.main_isolate(),
2945 "function f() { this.a = new.target; }"); 2944 "function f() { this.a = new.target; }");
2946 auto callable = tester.GetCallable<>(); 2945 auto callable = tester.GetCallable<>();
2947 callable().ToHandleChecked(); 2946 callable().ToHandleChecked();
2948 2947
2949 Handle<Object> new_target_name = v8::Utils::OpenHandle( 2948 Handle<Object> new_target_name = v8::Utils::OpenHandle(
2950 *CompileRun("(function() { return (new f()).a.name; })();")); 2949 *CompileRun("(function() { return (new f()).a.name; })();"));
2951 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f"))); 2950 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f")));
2952 } 2951 }
2953 2952
2953
2954 TEST(InterpreterAssignmentInExpressions) {
2955 HandleAndZoneScope handles;
2956
2957 std::pair<const char*, int> samples[] = {
2958 {"function f() {\n"
2959 " var x = 7;\n"
2960 " var y = x + (x = 1) + (x = 2);\n"
2961 " return y;\n"
2962 "}",
2963 10},
2964 {"function f() {\n"
2965 " var x = 7;\n"
2966 " var y = x + (x = 1) + (x = 2);\n"
2967 " return x;\n"
2968 "}",
2969 2},
2970 {"function f() {\n"
2971 " var x = 55;\n"
2972 " x = x + (x = 100) + (x = 101);\n"
2973 " return x;\n"
2974 "}",
2975 256},
2976 {"function f() {\n"
2977 " var x = 7;\n"
2978 " return ++x + x + x++;\n"
2979 "}",
2980 24},
2981 {"function f() {\n"
2982 " var x = 7;\n"
2983 " var y = 1 + ++x + x + x++;\n"
2984 " return x;\n"
2985 "}",
2986 9},
2987 {"function f() {\n"
2988 " var x = 7;\n"
2989 " var y = ++x + x + x++;\n"
2990 " return x;\n"
2991 "}",
2992 9},
2993 {"function f() {\n"
2994 " var x = 7, y = 100, z = 1000;\n"
2995 " return x + (x += 3) + y + (y *= 10) + (z *= 7) + z;\n"
2996 "}",
2997 15117},
2998 {"function f() {\n"
2999 " var inner = function (x) { return x + (x = 2) + (x = 4) + x; };\n"
3000 " return inner(1);\n"
3001 "}",
3002 11},
3003 {"function f() {\n"
3004 " var x = 1, y = 2;\n"
3005 " x = x + (x = 3) + y + (y = 4), y = y + (y = 5) + y + x;\n"
3006 " return x + y;\n"
3007 "}",
3008 10 + 24},
3009 {"function f() {\n"
3010 " var x = 0;\n"
3011 " var y = x | (x = 1) | (x = 2);\n"
3012 " return x;\n"
3013 "}",
3014 2},
3015 {"function f() {\n"
3016 " var x = 0;\n"
3017 " var y = x || (x = 1);\n"
3018 " return x;\n"
3019 "}",
3020 1},
3021 {"function f() {\n"
3022 " var x = 1;\n"
3023 " var y = x && (x = 2) && (x = 3);\n"
3024 " return x;\n"
3025 "}",
3026 3},
3027 {"function f() {\n"
3028 " var x = 1;\n"
3029 " var y = x || (x = 2);\n"
3030 " return x;\n"
3031 "}",
3032 1},
3033 {"function f() {\n"
3034 " var x = 1;\n"
3035 " x = (x << (x = 3)) | (x = 16);\n"
3036 " return x;\n"
3037 "}",
3038 24},
3039 {"function f() {\n"
3040 " var r = 7;\n"
3041 " var s = 11;\n"
3042 " var t = 13;\n"
3043 " var u = r + s + t + (r = 10) + (s = 20) +"
3044 " (t = (r + s)) + r + s + t;\n"
3045 " return r + s + t + u;\n"
3046 "}",
3047 211},
3048 {"function f() {\n"
3049 " var r = 7;\n"
3050 " var s = 11;\n"
3051 " var t = 13;\n"
3052 " return r > (3 * s * (s = 1)) ? (t + (t += 1)) : (r + (r = 4));\n"
3053 "}",
3054 11},
3055 {"function f() {\n"
3056 " var r = 7;\n"
3057 " var s = 11;\n"
3058 " var t = 13;\n"
3059 " return r > (3 * s * (s = 0)) ? (t + (t += 1)) : (r + (r = 4));\n"
3060 "}",
3061 27},
3062 {"function f() {\n"
3063 " var r = 7;\n"
3064 " var s = 11;\n"
3065 " var t = 13;\n"
3066 " return (r + (r = 5)) > s ? r : t;\n"
3067 "}",
3068 5},
3069 {"function f(a) {\n"
3070 " return a + (arguments[0] = 10);\n"
3071 "}",
3072 50},
3073 {"function f(a) {\n"
3074 " return a + (arguments[0] = 10) + a;\n"
3075 "}",
3076 60},
3077 {"function f(a) {\n"
3078 " return a + (arguments[0] = 10) + arguments[0];\n"
3079 "}",
3080 60},
3081 };
3082
3083 const int arg_value = 40;
3084 for (size_t i = 0; i < arraysize(samples); i++) {
3085 InterpreterTester tester(handles.main_isolate(), samples[i].first);
3086 auto callable = tester.GetCallable<Handle<Object>>();
3087 Handle<Object> return_val =
3088 callable(handle(Smi::FromInt(arg_value), handles.main_isolate()))
3089 .ToHandleChecked();
3090 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
3091 }
3092 }
3093
3094
2954 } // namespace interpreter 3095 } // namespace interpreter
2955 } // namespace internal 3096 } // namespace internal
2956 } // namespace v8 3097 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698