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

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: Sync test bytecode sequences to avoid unnecessary Ldar/Star instructions. 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 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 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 2610
2611 Handle<i::Object> return_value = callable().ToHandleChecked(); 2611 Handle<i::Object> return_value = callable().ToHandleChecked();
2612 CHECK(return_value->SameValue(*loops[i].second)); 2612 CHECK(return_value->SameValue(*loops[i].second));
2613 } 2613 }
2614 } 2614 }
2615 2615
2616 2616
2617 TEST(InterpreterForIn) { 2617 TEST(InterpreterForIn) {
2618 HandleAndZoneScope handles; 2618 HandleAndZoneScope handles;
2619 2619
2620 // TODO(oth): Add a test here for delete mid-loop when delete is ready.
2621 std::pair<const char*, int> for_in_samples[] = { 2620 std::pair<const char*, int> for_in_samples[] = {
2622 {"function f() {\n" 2621 {"function f() {\n"
2623 " var r = -1;\n" 2622 " var r = -1;\n"
2624 " for (var a in null) { r = a; }\n" 2623 " for (var a in null) { r = a; }\n"
2625 " return r;\n" 2624 " return r;\n"
2626 "}", 2625 "}",
2627 -1}, 2626 -1},
2628 {"function f() {\n" 2627 {"function f() {\n"
2629 " var r = -1;\n" 2628 " var r = -1;\n"
2630 " for (var a in undefined) { r = a; }\n" 2629 " for (var a in undefined) { r = a; }\n"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 InterpreterTester tester(handles.main_isolate(), 2942 InterpreterTester tester(handles.main_isolate(),
2944 "function f() { this.a = new.target; }"); 2943 "function f() { this.a = new.target; }");
2945 auto callable = tester.GetCallable<>(); 2944 auto callable = tester.GetCallable<>();
2946 callable().ToHandleChecked(); 2945 callable().ToHandleChecked();
2947 2946
2948 Handle<Object> new_target_name = v8::Utils::OpenHandle( 2947 Handle<Object> new_target_name = v8::Utils::OpenHandle(
2949 *CompileRun("(function() { return (new f()).a.name; })();")); 2948 *CompileRun("(function() { return (new f()).a.name; })();"));
2950 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f"))); 2949 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f")));
2951 } 2950 }
2952 2951
2952
2953 TEST(InterpreterAssignmentInExpressions) {
2954 HandleAndZoneScope handles;
2955
2956 std::pair<const char*, int> samples[] = {
2957 {"function f() {\n"
2958 " var x = 7;\n"
2959 " var y = x + (x = 1) + (x = 2);\n"
2960 " return y;\n"
2961 "}",
2962 10},
2963 {"function f() {\n"
2964 " var x = 7;\n"
2965 " var y = x + (x = 1) + (x = 2);\n"
2966 " return x;\n"
2967 "}",
2968 2},
2969 {"function f() {\n"
2970 " var x = 55;\n"
2971 " x = x + (x = 100) + (x = 101);\n"
2972 " return x;\n"
2973 "}",
2974 256},
2975 {"function f() {\n"
2976 " var x = 7;\n"
2977 " return ++x + x + x++;\n"
2978 "}",
2979 24},
2980 {"function f() {\n"
2981 " var x = 7;\n"
2982 " var y = 1 + ++x + x + x++;\n"
2983 " return x;\n"
2984 "}",
2985 9},
2986 {"function f() {\n"
2987 " var x = 7;\n"
2988 " var y = ++x + x + x++;\n"
2989 " return x;\n"
2990 "}",
2991 9},
2992 {"function f() {\n"
2993 " var x = 7, y = 100, z = 1000;\n"
2994 " return x + (x += 3) + y + (y *= 10) + (z *= 7) + z;\n"
2995 "}",
2996 15117},
2997 {"function f() {\n"
2998 " var inner = function (x) { return x + (x = 2) + (x = 4) + x; };\n"
2999 " return inner(1);\n"
3000 "}",
3001 11},
3002 {"function f() {\n"
3003 " var x = 1, y = 2;\n"
3004 " x = x + (x = 3) + y + (y = 4), y = y + (y = 5) + y + x;\n"
3005 " return x + y;\n"
3006 "}",
3007 10 + 24},
3008 {"function f() {\n"
3009 " var x = 0;\n"
3010 " var y = x | (x = 1) | (x = 2);\n"
3011 " return x;\n"
3012 "}",
3013 2},
3014 {"function f() {\n"
3015 " var x = 0;\n"
3016 " var y = x || (x = 1);\n"
3017 " return x;\n"
3018 "}",
3019 1},
3020 {"function f() {\n"
3021 " var x = 1;\n"
3022 " var y = x && (x = 2) && (x = 3);\n"
3023 " return x;\n"
3024 "}",
3025 3},
3026 {"function f() {\n"
3027 " var x = 1;\n"
3028 " var y = x || (x = 2);\n"
3029 " return x;\n"
3030 "}",
3031 1},
3032 {"function f() {\n"
3033 " var x = 1;\n"
3034 " x = (x << (x = 3)) | (x = 16);\n"
3035 " return x;\n"
3036 "}",
3037 24},
3038 {"function f() {\n"
3039 " var r = 7;\n"
3040 " var s = 11;\n"
3041 " var t = 13;\n"
3042 " var u = r + s + t + (r = 10) + (s = 20) +"
3043 " (t = (r + s)) + r + s + t;\n"
3044 " return r + s + t + u;\n"
3045 "}",
3046 211},
3047 {"function f() {\n"
3048 " var r = 7;\n"
3049 " var s = 11;\n"
3050 " var t = 13;\n"
3051 " return r > (3 * s * (s = 1)) ? (t + (t += 1)) : (r + (r = 4));\n"
3052 "}",
3053 11},
3054 {"function f() {\n"
3055 " var r = 7;\n"
3056 " var s = 11;\n"
3057 " var t = 13;\n"
3058 " return r > (3 * s * (s = 0)) ? (t + (t += 1)) : (r + (r = 4));\n"
3059 "}",
3060 27},
3061 {"function f() {\n"
3062 " var r = 7;\n"
3063 " var s = 11;\n"
3064 " var t = 13;\n"
3065 " return (r + (r = 5)) > s ? r : t;\n"
3066 "}",
3067 5},
3068 {"function f(a) {\n"
3069 " return a + (arguments[0] = 10);\n"
3070 "}",
3071 50},
3072 {"function f(a) {\n"
3073 " return a + (arguments[0] = 10) + a;\n"
3074 "}",
3075 60},
3076 {"function f(a) {\n"
3077 " return a + (arguments[0] = 10) + arguments[0];\n"
3078 "}",
3079 60},
3080 };
3081
3082 const int arg_value = 40;
3083 for (size_t i = 0; i < arraysize(samples); i++) {
3084 InterpreterTester tester(handles.main_isolate(), samples[i].first);
3085 auto callable = tester.GetCallable<Handle<Object>>();
3086 Handle<Object> return_val =
3087 callable(handle(Smi::FromInt(arg_value), handles.main_isolate()))
3088 .ToHandleChecked();
3089 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
3090 }
3091 }
3092
3093
2953 } // namespace interpreter 3094 } // namespace interpreter
2954 } // namespace internal 3095 } // namespace internal
2955 } // namespace v8 3096 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698