OLD | NEW |
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 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 { "function f() {", "}" }, | 953 { "function f() {", "}" }, |
954 { "var f = () => {", "};" }, | 954 { "var f = () => {", "};" }, |
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_SUPER_PROPERTY = 1 << 4, | 964 INNER_SUPER_PROPERTY = 1 << 4, |
964 }; | 965 }; |
965 | 966 |
966 static const struct { | 967 static const struct { |
967 const char* body; | 968 const char* body; |
968 int expected; | 969 int expected; |
969 } source_data[] = { | 970 } source_data[] = { |
970 {"", NONE}, | 971 {"", NONE}, |
971 {"return this", THIS}, | 972 {"return this", THIS}, |
972 {"return arguments", ARGUMENTS}, | 973 {"return arguments", ARGUMENTS}, |
(...skipping 20 matching lines...) Expand all Loading... |
993 {"return function (x) { return this + x }", NONE}, | 994 {"return function (x) { return this + x }", NONE}, |
994 {"return { m(x) { return super.m() + x } }", NONE}, | 995 {"return { m(x) { return super.m() + x } }", NONE}, |
995 {"var x = function () { this.foo = 42 };", NONE}, | 996 {"var x = function () { this.foo = 42 };", NONE}, |
996 {"var x = { m() { super.foo = 42 } };", NONE}, | 997 {"var x = { m() { super.foo = 42 } };", NONE}, |
997 {"if (1) { return function () { while (true) new this() } }", NONE}, | 998 {"if (1) { return function () { while (true) new this() } }", NONE}, |
998 {"if (1) { return { m() { while (true) super.m() } } }", NONE}, | 999 {"if (1) { return { m() { while (true) super.m() } } }", NONE}, |
999 {"return function (x) { return () => this }", NONE}, | 1000 {"return function (x) { return () => this }", NONE}, |
1000 {"return { m(x) { return () => super.m() } }", NONE}, | 1001 {"return { m(x) { return () => super.m() } }", NONE}, |
1001 // Flags must be correctly set when using block scoping. | 1002 // Flags must be correctly set when using block scoping. |
1002 {"\"use strict\"; while (true) { let x; this, arguments; }", | 1003 {"\"use strict\"; while (true) { let x; this, arguments; }", |
1003 ARGUMENTS | THIS}, | 1004 INNER_ARGUMENTS | THIS}, |
1004 {"\"use strict\"; while (true) { let x; this, super.f(), arguments; }", | 1005 {"\"use strict\"; while (true) { let x; this, super.f(), arguments; }", |
1005 ARGUMENTS | INNER_SUPER_PROPERTY | THIS}, | 1006 INNER_ARGUMENTS | INNER_SUPER_PROPERTY | THIS}, |
1006 {"\"use strict\"; if (foo()) { let x; this.f() }", THIS}, | 1007 {"\"use strict\"; if (foo()) { let x; this.f() }", THIS}, |
1007 {"\"use strict\"; if (foo()) { let x; super.f() }", | 1008 {"\"use strict\"; if (foo()) { let x; super.f() }", |
1008 INNER_SUPER_PROPERTY}, | 1009 INNER_SUPER_PROPERTY}, |
1009 {"\"use strict\"; if (1) {" | 1010 {"\"use strict\"; if (1) {" |
1010 " let x; return { m() { return this + super.m() + arguments } }" | 1011 " let x; return { m() { return this + super.m() + arguments } }" |
1011 "}", | 1012 "}", |
1012 NONE}, | 1013 NONE}, |
1013 }; | 1014 }; |
1014 | 1015 |
1015 i::Isolate* isolate = CcTest::i_isolate(); | 1016 i::Isolate* isolate = CcTest::i_isolate(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 i::Scope* script_scope = info.function()->scope(); | 1057 i::Scope* script_scope = info.function()->scope(); |
1057 CHECK(script_scope->is_script_scope()); | 1058 CHECK(script_scope->is_script_scope()); |
1058 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1059 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
1059 | 1060 |
1060 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1061 i::Scope* scope = script_scope->inner_scopes()->at(0); |
1061 // Adjust for constructor scope. | 1062 // Adjust for constructor scope. |
1062 if (j == 2) { | 1063 if (j == 2) { |
1063 CHECK_EQ(1, scope->inner_scopes()->length()); | 1064 CHECK_EQ(1, scope->inner_scopes()->length()); |
1064 scope = scope->inner_scopes()->at(0); | 1065 scope = scope->inner_scopes()->at(0); |
1065 } | 1066 } |
1066 // Arguments usage in an arrow function doesn't cause local allocation of | 1067 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, |
1067 // an arguments object. | 1068 scope->uses_arguments()); |
1068 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0 && j != 1, | |
1069 scope->arguments() != nullptr); | |
1070 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, | 1069 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, |
1071 scope->uses_super_property()); | 1070 scope->uses_super_property()); |
1072 if ((source_data[i].expected & THIS) != 0) { | 1071 if ((source_data[i].expected & THIS) != 0) { |
1073 // Currently the is_used() flag is conservative; all variables in a | 1072 // Currently the is_used() flag is conservative; all variables in a |
1074 // script scope are marked as used. | 1073 // script scope are marked as used. |
1075 CHECK(scope->LookupThis()->is_used()); | 1074 CHECK(scope->LookupThis()->is_used()); |
1076 } | 1075 } |
| 1076 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, |
| 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 } | 1080 } |
1080 } | 1081 } |
1081 } | 1082 } |
1082 | 1083 |
1083 | 1084 |
1084 TEST(ScopePositions) { | 1085 TEST(ScopePositions) { |
1085 // Test the parser for correctly setting the start and end positions | 1086 // Test the parser for correctly setting the start and end positions |
1086 // 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 |
(...skipping 5379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6466 const char* data[] = { | 6467 const char* data[] = { |
6467 "yield", | 6468 "yield", |
6468 "[yield]", | 6469 "[yield]", |
6469 "{ x : yield }", | 6470 "{ x : yield }", |
6470 NULL}; | 6471 NULL}; |
6471 // clang-format on | 6472 // clang-format on |
6472 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 6473 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
6473 arraysize(always_flags)); | 6474 arraysize(always_flags)); |
6474 } | 6475 } |
6475 } | 6476 } |
OLD | NEW |