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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1129823002: Remove Scope::scope_uses_this_ flag (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 7 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
« src/preparser.h ('K') | « src/scopes.cc ('k') | no next file » | 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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 { "class C { constructor() {", "} }" }, 955 { "class C { constructor() {", "} }" },
956 }; 956 };
957 957
958 enum Expected { 958 enum Expected {
959 NONE = 0, 959 NONE = 0,
960 ARGUMENTS = 1, 960 ARGUMENTS = 1,
961 SUPER_PROPERTY = 1 << 1, 961 SUPER_PROPERTY = 1 << 1,
962 THIS = 1 << 2, 962 THIS = 1 << 2,
963 INNER_ARGUMENTS = 1 << 3, 963 INNER_ARGUMENTS = 1 << 3,
964 INNER_SUPER_PROPERTY = 1 << 4, 964 INNER_SUPER_PROPERTY = 1 << 4,
965 INNER_THIS = 1 << 5
966 }; 965 };
967 966
968 static const struct { 967 static const struct {
969 const char* body; 968 const char* body;
970 int expected; 969 int expected;
971 } source_data[] = { 970 } source_data[] = {
972 {"", NONE}, 971 {"", NONE},
973 {"return this", THIS}, 972 {"return this", THIS},
974 {"return arguments", ARGUMENTS}, 973 {"return arguments", ARGUMENTS},
975 {"return super.x", SUPER_PROPERTY}, 974 {"return super.x", SUPER_PROPERTY},
976 {"return arguments[0]", ARGUMENTS}, 975 {"return arguments[0]", ARGUMENTS},
977 {"return this + arguments[0]", ARGUMENTS | THIS}, 976 {"return this + arguments[0]", ARGUMENTS | THIS},
978 {"return this + arguments[0] + super.x", 977 {"return this + arguments[0] + super.x",
979 ARGUMENTS | SUPER_PROPERTY | THIS}, 978 ARGUMENTS | SUPER_PROPERTY | THIS},
980 {"return x => this + x", INNER_THIS}, 979 {"return x => this + x", THIS},
981 {"return x => super.f() + x", INNER_SUPER_PROPERTY}, 980 {"return x => super.f() + x", INNER_SUPER_PROPERTY},
982 {"this.foo = 42;", THIS}, 981 {"this.foo = 42;", THIS},
983 {"this.foo();", THIS}, 982 {"this.foo();", THIS},
984 {"if (foo()) { this.f() }", THIS}, 983 {"if (foo()) { this.f() }", THIS},
985 {"if (foo()) { super.f() }", SUPER_PROPERTY}, 984 {"if (foo()) { super.f() }", SUPER_PROPERTY},
986 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS}, 985 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS},
987 {"while (true) { this.f() }", THIS}, 986 {"while (true) { this.f() }", THIS},
988 {"while (true) { super.f() }", SUPER_PROPERTY}, 987 {"while (true) { super.f() }", SUPER_PROPERTY},
989 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS}, 988 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS},
990 // Multiple nesting levels must work as well. 989 // Multiple nesting levels must work as well.
991 {"while (true) { while (true) { while (true) return this } }", THIS}, 990 {"while (true) { while (true) { while (true) return this } }", THIS},
992 {"while (true) { while (true) { while (true) return super.f() } }", 991 {"while (true) { while (true) { while (true) return super.f() } }",
993 SUPER_PROPERTY}, 992 SUPER_PROPERTY},
994 {"if (1) { return () => { while (true) new this() } }", INNER_THIS}, 993 {"if (1) { return () => { while (true) new this() } }", THIS},
995 // Note that propagation of the inner_uses_this() value does not
996 // cross boundaries of normal functions onto parent scopes.
997 {"return function (x) { return this + x }", NONE}, 994 {"return function (x) { return this + x }", NONE},
998 {"return { m(x) { return super.m() + x } }", NONE}, 995 {"return { m(x) { return super.m() + x } }", NONE},
999 {"var x = function () { this.foo = 42 };", NONE}, 996 {"var x = function () { this.foo = 42 };", NONE},
1000 {"var x = { m() { super.foo = 42 } };", NONE}, 997 {"var x = { m() { super.foo = 42 } };", NONE},
1001 {"if (1) { return function () { while (true) new this() } }", NONE}, 998 {"if (1) { return function () { while (true) new this() } }", NONE},
1002 {"if (1) { return { m() { while (true) super.m() } } }", NONE}, 999 {"if (1) { return { m() { while (true) super.m() } } }", NONE},
1003 {"return function (x) { return () => this }", NONE}, 1000 {"return function (x) { return () => this }", NONE},
1004 {"return { m(x) { return () => super.m() } }", NONE}, 1001 {"return { m(x) { return () => super.m() } }", NONE},
1005 // Flags must be correctly set when using block scoping. 1002 // Flags must be correctly set when using block scoping.
1006 {"\"use strict\"; while (true) { let x; this, arguments; }", 1003 {"\"use strict\"; while (true) { let x; this, arguments; }",
1007 INNER_ARGUMENTS | INNER_THIS}, 1004 INNER_ARGUMENTS | THIS},
1008 {"\"use strict\"; while (true) { let x; this, super.f(), arguments; }", 1005 {"\"use strict\"; while (true) { let x; this, super.f(), arguments; }",
1009 INNER_ARGUMENTS | INNER_SUPER_PROPERTY | INNER_THIS}, 1006 INNER_ARGUMENTS | INNER_SUPER_PROPERTY | THIS},
1010 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS}, 1007 {"\"use strict\"; if (foo()) { let x; this.f() }", THIS},
1011 {"\"use strict\"; if (foo()) { let x; super.f() }", 1008 {"\"use strict\"; if (foo()) { let x; super.f() }",
1012 INNER_SUPER_PROPERTY}, 1009 INNER_SUPER_PROPERTY},
1013 {"\"use strict\"; if (1) {" 1010 {"\"use strict\"; if (1) {"
1014 " let x; return { m() { return this + super.m() + arguments } }" 1011 " let x; return { m() { return this + super.m() + arguments } }"
1015 "}", 1012 "}",
1016 NONE}, 1013 NONE},
1017 }; 1014 };
1018 1015
1019 i::Isolate* isolate = CcTest::i_isolate(); 1016 i::Isolate* isolate = CcTest::i_isolate();
1020 i::Factory* factory = isolate->factory(); 1017 i::Factory* factory = isolate->factory();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 i::Scope* scope = script_scope->inner_scopes()->at(0); 1061 i::Scope* scope = script_scope->inner_scopes()->at(0);
1065 // Adjust for constructor scope. 1062 // Adjust for constructor scope.
1066 if (j == 2) { 1063 if (j == 2) {
1067 CHECK_EQ(1, scope->inner_scopes()->length()); 1064 CHECK_EQ(1, scope->inner_scopes()->length());
1068 scope = scope->inner_scopes()->at(0); 1065 scope = scope->inner_scopes()->at(0);
1069 } 1066 }
1070 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, 1067 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0,
1071 scope->uses_arguments()); 1068 scope->uses_arguments());
1072 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, 1069 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0,
1073 scope->uses_super_property()); 1070 scope->uses_super_property());
1074 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); 1071 if ((source_data[i].expected & THIS) != 0) {
1072 // Currently the is_used() flag is conservative; all variables in a
1073 // script scope are marked as used.
1074 CHECK(scope->LookupThis()->is_used());
1075 }
1075 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, 1076 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0,
1076 scope->inner_uses_arguments()); 1077 scope->inner_uses_arguments());
1077 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0, 1078 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0,
1078 scope->inner_uses_super_property()); 1079 scope->inner_uses_super_property());
1079 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0,
1080 scope->inner_uses_this());
1081 } 1080 }
1082 } 1081 }
1083 } 1082 }
1084 1083
1085 1084
1086 TEST(ScopePositions) { 1085 TEST(ScopePositions) {
1087 // Test the parser for correctly setting the start and end positions 1086 // Test the parser for correctly setting the start and end positions
1088 // of a scope. We check the scope positions of exactly one scope 1087 // of a scope. We check the scope positions of exactly one scope
1089 // nested in the global scope of a program. 'inner source' is the 1088 // nested in the global scope of a program. 'inner source' is the
1090 // source code that determines the part of the source belonging 1089 // source code that determines the part of the source belonging
(...skipping 5377 matching lines...) Expand 10 before | Expand all | Expand 10 after
6468 const char* data[] = { 6467 const char* data[] = {
6469 "yield", 6468 "yield",
6470 "[yield]", 6469 "[yield]",
6471 "{ x : yield }", 6470 "{ x : yield }",
6472 NULL}; 6471 NULL};
6473 // clang-format on 6472 // clang-format on
6474 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6473 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6475 arraysize(always_flags)); 6474 arraysize(always_flags));
6476 } 6475 }
6477 } 6476 }
OLDNEW
« src/preparser.h ('K') | « src/scopes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698