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/test-parsing.cc

Issue 1105453002: Revert of [strong] checking of this & super in constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « src/preparser.cc ('k') | test/mjsunit/strong/classes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5848 matching lines...) Expand 10 before | Expand all | Expand 10 after
5859 }; 5859 };
5860 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, 5860 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
5861 arraysize(always_flags)); 5861 arraysize(always_flags));
5862 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5862 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5863 arraysize(always_flags)); 5863 arraysize(always_flags));
5864 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5864 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5865 arraysize(always_flags)); 5865 arraysize(always_flags));
5866 } 5866 }
5867 5867
5868 5868
5869 TEST(StrongConstructorThis) { 5869 TEST(StrongSuperCalls) {
5870 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; 5870 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
5871 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; 5871 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
5872 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; 5872 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
5873 5873
5874 const char* error_data[] = { 5874 const char* data[] = {
5875 "class C { constructor() { this; } }", 5875 "class C extends Object { constructor() {} }",
5876 "class C { constructor() { this.a; } }", 5876 "class C extends Object { constructor() { (super()); } }",
5877 "class C { constructor() { this['a']; } }", 5877 "class C extends Object { constructor() { (() => super())(); } }",
5878 "class C { constructor() { (this); } }", 5878 "class C extends Object { constructor() { { super(); } } }",
5879 "class C { constructor() { this(); } }", 5879 "class C extends Object { constructor() { if (1) super(); } }",
5880 // TODO(rossberg): arrow functions not handled yet. 5880 "class C extends Object { constructor() { super(), super(); } }",
5881 // "class C { constructor() { () => this; } }", 5881 "class C extends Object { constructor() { super(); super(); } }",
5882 "class C { constructor() { this.a = 0, 0; } }", 5882 "class C extends Object { constructor() { super(); (super()); } }",
5883 "class C { constructor() { (this.a = 0); } }", 5883 "class C extends Object { constructor() { super(); { super() } } }",
5884 // "class C { constructor() { (() => this.a = 0)(); } }",
5885 "class C { constructor() { { this.a = 0; } } }",
5886 "class C { constructor() { if (1) this.a = 0; } }",
5887 "class C { constructor() { label: this.a = 0; } }",
5888 "class C { constructor() { this.a = this.b; } }",
5889 "class C { constructor() { this.a = {b: 1}; this.a.b } }",
5890 "class C { constructor() { this.a = {b: 1}; this.a.b = 0 } }",
5891 "class C { constructor() { this.a = function(){}; this.a() } }",
5892 NULL};
5893
5894 const char* success_data[] = {
5895 "class C { constructor() { this.a = 0; } }",
5896 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }",
5897 NULL}; 5884 NULL};
5898 5885
5899 static const ParserFlag always_flags[] = { 5886 static const ParserFlag always_flags[] = {
5900 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, 5887 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals,
5901 kAllowHarmonyArrowFunctions 5888 kAllowHarmonyArrowFunctions
5902 }; 5889 };
5903 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 5890 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags,
5904 always_flags, arraysize(always_flags)); 5891 arraysize(always_flags));
5905 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 5892 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5906 always_flags, arraysize(always_flags)); 5893 arraysize(always_flags));
5907 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 5894 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5908 always_flags, arraysize(always_flags)); 5895 arraysize(always_flags));
5909
5910 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
5911 always_flags, arraysize(always_flags));
5912 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
5913 always_flags, arraysize(always_flags));
5914 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
5915 always_flags, arraysize(always_flags));
5916 } 5896 }
5917 5897
5918 5898
5919 TEST(StrongConstructorSuper) {
5920 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
5921 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
5922 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
5923
5924 const char* error_data[] = {
5925 "class C extends Object { constructor() {} }",
5926 "class C extends Object { constructor() { super.a; } }",
5927 "class C extends Object { constructor() { super['a']; } }",
5928 "class C extends Object { constructor() { super.a = 0; } }",
5929 "class C extends Object { constructor() { (super.a); } }",
5930 // TODO(rossberg): arrow functions do not handle super yet.
5931 // "class C extends Object { constructor() { () => super.a; } }",
5932 "class C extends Object { constructor() { super(), 0; } }",
5933 "class C extends Object { constructor() { (super()); } }",
5934 // "class C extends Object { constructor() { (() => super())(); } }",
5935 "class C extends Object { constructor() { { super(); } } }",
5936 "class C extends Object { constructor() { if (1) super(); } }",
5937 "class C extends Object { constructor() { label: super(); } }",
5938 "class C extends Object { constructor() { super(), super(); } }",
5939 "class C extends Object { constructor() { super(); super(); } }",
5940 "class C extends Object { constructor() { super(); (super()); } }",
5941 "class C extends Object { constructor() { super(); { super() } } }",
5942 "class C extends Object { constructor() { this.a = 0, super(); } }",
5943 "class C extends Object { constructor() { this.a = 0; super(); } }",
5944 "class C extends Object { constructor() { super(this.a = 0); } }",
5945 "class C extends Object { constructor() { super().a; } }",
5946 NULL};
5947
5948 const char* success_data[] = {
5949 "class C extends Object { constructor() { super(); } }",
5950 "class C extends Object { constructor() { label: 66; super(); } }",
5951 "class C extends Object { constructor() { super(3); this.x = 0; } }",
5952 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }",
5953 NULL};
5954
5955 static const ParserFlag always_flags[] = {
5956 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals,
5957 kAllowHarmonyArrowFunctions
5958 };
5959 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
5960 always_flags, arraysize(always_flags));
5961 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
5962 always_flags, arraysize(always_flags));
5963 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
5964 always_flags, arraysize(always_flags));
5965
5966 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
5967 always_flags, arraysize(always_flags));
5968 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
5969 always_flags, arraysize(always_flags));
5970 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
5971 always_flags, arraysize(always_flags));
5972 }
5973
5974
5975 TEST(StrongConstructorReturns) { 5899 TEST(StrongConstructorReturns) {
5976 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; 5900 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
5977 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; 5901 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
5978 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; 5902 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
5979 5903
5980 const char* error_data[] = { 5904 const char* data[] = {
5981 "class C extends Object { constructor() { super(); return {}; } }", 5905 "class C extends Object { constructor() { super(); return {}; } }",
5982 "class C extends Object { constructor() { super(); { return {}; } } }", 5906 "class C extends Object { constructor() { super(); { return {}; } } }",
5983 "class C extends Object { constructor() { super(); if (1) return {}; } }", 5907 "class C extends Object { constructor() { super(); if (1) return {}; } }",
5984 "class C extends Object { constructor() { return; super(); } }", 5908 "class C extends Object { constructor() { return; super(); } }",
5985 "class C extends Object { constructor() { { return; } super(); } }", 5909 "class C extends Object { constructor() { { return; } super(); } }",
5986 "class C extends Object { constructor() { if (0) return; super(); } }", 5910 "class C extends Object { constructor() { if (0) return; super(); } }",
5987 "class C { constructor() { return; this.a = 0; } }",
5988 "class C { constructor() { { return; } this.a = 0; } }",
5989 "class C { constructor() { if (0) return; this.a = 0; } }",
5990 "class C { constructor() { this.a = 0; if (0) return; this.b = 0; } }",
5991 NULL};
5992
5993 const char* success_data[] = {
5994 "class C extends Object { constructor() { super(); return; } }",
5995 "class C extends Object { constructor() { super(); { return } } }",
5996 "class C extends Object { constructor() { super(); if (1) return; } }",
5997 "class C { constructor() { this.a = 0; return; } }",
5998 "class C { constructor() { this.a = 0; { return; } } }",
5999 "class C { constructor() { this.a = 0; if (0) return; 65; } }",
6000 "class C extends Array { constructor() { super(); this.a = 9; return } }",
6001 NULL}; 5911 NULL};
6002 5912
6003 static const ParserFlag always_flags[] = { 5913 static const ParserFlag always_flags[] = {
6004 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals 5914 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals
6005 }; 5915 };
6006 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 5916 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags,
6007 always_flags, arraysize(always_flags)); 5917 arraysize(always_flags));
6008 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 5918 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
6009 always_flags, arraysize(always_flags)); 5919 arraysize(always_flags));
6010 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 5920 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
6011 always_flags, arraysize(always_flags)); 5921 arraysize(always_flags));
6012
6013 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
6014 always_flags, arraysize(always_flags));
6015 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
6016 always_flags, arraysize(always_flags));
6017 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
6018 always_flags, arraysize(always_flags));
6019 } 5922 }
6020 5923
6021 5924
6022 TEST(StrongUndefinedLocal) { 5925 TEST(StrongUndefinedLocal) {
6023 const char* context_data[][2] = {{"", ""}, {NULL}}; 5926 const char* context_data[][2] = {{"", ""}, {NULL}};
6024 5927
6025 const char* data[] = { 5928 const char* data[] = {
6026 "function undefined() {'use strong';}", 5929 "function undefined() {'use strong';}",
6027 "function* undefined() {'use strong';}", 5930 "function* undefined() {'use strong';}",
6028 "(function undefined() {'use strong';});", 5931 "(function undefined() {'use strong';});",
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
6336 v8::Script::Compile(v8_str(script3)); 6239 v8::Script::Compile(v8_str(script3));
6337 CHECK(try_catch2.HasCaught()); 6240 CHECK(try_catch2.HasCaught());
6338 v8::String::Utf8Value exception(try_catch2.Exception()); 6241 v8::String::Utf8Value exception(try_catch2.Exception());
6339 CHECK_EQ(0, 6242 CHECK_EQ(0,
6340 strcmp( 6243 strcmp(
6341 "ReferenceError: In strong mode, using an undeclared global " 6244 "ReferenceError: In strong mode, using an undeclared global "
6342 "variable 'not_there3' is not allowed", 6245 "variable 'not_there3' is not allowed",
6343 *exception)); 6246 *exception));
6344 } 6247 }
6345 } 6248 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | test/mjsunit/strong/classes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698