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

Side by Side Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1819123002: Remove support for legacy const, part 1 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 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 #include <utility> 5 #include <utility>
6 6
7 #include "src/compiler/pipeline.h" 7 #include "src/compiler/pipeline.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/interpreter/bytecode-array-builder.h" 10 #include "src/interpreter/bytecode-array-builder.h"
(...skipping 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 for (size_t i = 0; i < arraysize(const_decl); i++) { 2828 for (size_t i = 0; i < arraysize(const_decl); i++) {
2829 ScopedVector<char> script(1024); 2829 ScopedVector<char> script(1024);
2830 SNPrintF(script, "%s %s %s", prologue, const_decl[i].code_snippet, 2830 SNPrintF(script, "%s %s %s", prologue, const_decl[i].code_snippet,
2831 epilogue); 2831 epilogue);
2832 2832
2833 BytecodeGraphTester tester(isolate, zone, script.start(), "*"); 2833 BytecodeGraphTester tester(isolate, zone, script.start(), "*");
2834 auto callable = tester.GetCallable<>(); 2834 auto callable = tester.GetCallable<>();
2835 Handle<Object> return_value = callable().ToHandleChecked(); 2835 Handle<Object> return_value = callable().ToHandleChecked();
2836 CHECK(return_value->SameValue(*const_decl[i].return_value())); 2836 CHECK(return_value->SameValue(*const_decl[i].return_value()));
2837 } 2837 }
2838
2839 // Tests for Legacy constant.
2840 bool old_flag_legacy_const = FLAG_legacy_const;
2841 FLAG_legacy_const = true;
2842
2843 ExpectedSnippet<0> legacy_const_decl[] = {
2844 {"return outerConst = 23;", {handle(Smi::FromInt(23), isolate)}},
2845 {"outerConst = 30; return outerConst;",
2846 {handle(Smi::FromInt(10), isolate)}},
2847 };
2848
2849 for (size_t i = 0; i < arraysize(legacy_const_decl); i++) {
2850 ScopedVector<char> script(1024);
2851 SNPrintF(script, "%s %s %s", prologue, legacy_const_decl[i].code_snippet,
2852 epilogue);
2853
2854 BytecodeGraphTester tester(isolate, zone, script.start(), "*");
2855 auto callable = tester.GetCallable<>();
2856 Handle<Object> return_value = callable().ToHandleChecked();
2857 CHECK(return_value->SameValue(*legacy_const_decl[i].return_value()));
2858 }
2859
2860 FLAG_legacy_const = old_flag_legacy_const;
2861 } 2838 }
2862 2839
2863 TEST(BytecodeGraphBuilderIllegalConstDeclaration) { 2840 TEST(BytecodeGraphBuilderIllegalConstDeclaration) {
2864 HandleAndZoneScope scope; 2841 HandleAndZoneScope scope;
2865 Isolate* isolate = scope.main_isolate(); 2842 Isolate* isolate = scope.main_isolate();
2866 Zone* zone = scope.main_zone(); 2843 Zone* zone = scope.main_zone();
2867 2844
2868 ExpectedSnippet<0, const char*> illegal_const_decl[] = { 2845 ExpectedSnippet<0, const char*> illegal_const_decl[] = {
2869 {"const x = x = 10 + 3; return x;", 2846 {"const x = x = 10 + 3; return x;",
2870 {"Uncaught ReferenceError: x is not defined"}}, 2847 {"Uncaught ReferenceError: x is not defined"}},
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 BytecodeGraphTester tester(isolate, zone, script.start()); 2881 BytecodeGraphTester tester(isolate, zone, script.start());
2905 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); 2882 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
2906 v8::Local<v8::String> expected_string = 2883 v8::Local<v8::String> expected_string =
2907 v8_str(illegal_const_decl[i].return_value()); 2884 v8_str(illegal_const_decl[i].return_value());
2908 CHECK( 2885 CHECK(
2909 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) 2886 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
2910 .FromJust()); 2887 .FromJust());
2911 } 2888 }
2912 } 2889 }
2913 2890
2914 TEST(BytecodeGraphBuilderLegacyConstDeclaration) {
2915 bool old_flag_legacy_const = FLAG_legacy_const;
2916 FLAG_legacy_const = true;
2917
2918 HandleAndZoneScope scope;
2919 Isolate* isolate = scope.main_isolate();
2920 Zone* zone = scope.main_zone();
2921
2922 ExpectedSnippet<0> snippets[] = {
2923 {"const x = (x = 10) + 3; return x;",
2924 {handle(Smi::FromInt(13), isolate)}},
2925 {"const x = 10; x = 20; return x;", {handle(Smi::FromInt(10), isolate)}},
2926 {"var a = 10;\n"
2927 "for (var i = 0; i < 10; ++i) {\n"
2928 " const x = i;\n" // Legacy constants are not block scoped.
2929 " a = a + x;\n"
2930 "}\n"
2931 "return a;\n",
2932 {handle(Smi::FromInt(10), isolate)}},
2933 {"const x = 20; eval('x = 10;'); return x;",
2934 {handle(Smi::FromInt(20), isolate)}},
2935 };
2936
2937 for (size_t i = 0; i < arraysize(snippets); i++) {
2938 ScopedVector<char> script(1024);
2939 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
2940 snippets[i].code_snippet, kFunctionName);
2941
2942 BytecodeGraphTester tester(isolate, zone, script.start());
2943 auto callable = tester.GetCallable<>();
2944 Handle<Object> return_value = callable().ToHandleChecked();
2945 CHECK(return_value->SameValue(*snippets[i].return_value()));
2946 }
2947
2948 FLAG_legacy_const = old_flag_legacy_const;
2949 }
2950
2951 TEST(BytecodeGraphBuilderDebuggerStatement) { 2891 TEST(BytecodeGraphBuilderDebuggerStatement) {
2952 FLAG_expose_debug_as = "debug"; 2892 FLAG_expose_debug_as = "debug";
2953 HandleAndZoneScope scope; 2893 HandleAndZoneScope scope;
2954 Isolate* isolate = scope.main_isolate(); 2894 Isolate* isolate = scope.main_isolate();
2955 Zone* zone = scope.main_zone(); 2895 Zone* zone = scope.main_zone();
2956 2896
2957 ExpectedSnippet<0> snippet = { 2897 ExpectedSnippet<0> snippet = {
2958 "var Debug = debug.Debug;" 2898 "var Debug = debug.Debug;"
2959 "var count = 0;" 2899 "var count = 0;"
2960 "function f() {" 2900 "function f() {"
(...skipping 14 matching lines...) Expand all
2975 2915
2976 BytecodeGraphTester tester(isolate, zone, script.start()); 2916 BytecodeGraphTester tester(isolate, zone, script.start());
2977 auto callable = tester.GetCallable<>(); 2917 auto callable = tester.GetCallable<>();
2978 Handle<Object> return_value = callable().ToHandleChecked(); 2918 Handle<Object> return_value = callable().ToHandleChecked();
2979 CHECK(return_value->SameValue(*snippet.return_value())); 2919 CHECK(return_value->SameValue(*snippet.return_value()));
2980 } 2920 }
2981 2921
2982 } // namespace compiler 2922 } // namespace compiler
2983 } // namespace internal 2923 } // namespace internal
2984 } // namespace v8 2924 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698