| 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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 if (!bad) { | 913 if (!bad) { |
| 914 i += input_offset; | 914 i += input_offset; |
| 915 character_length -= output_adjust; | 915 character_length -= output_adjust; |
| 916 } | 916 } |
| 917 } | 917 } |
| 918 } | 918 } |
| 919 return character_length; | 919 return character_length; |
| 920 } | 920 } |
| 921 | 921 |
| 922 | 922 |
| 923 TEST(ScopeUsesArgumentsSuperThis) { | 923 TEST(ScopeUsesArgumentsSuper) { |
| 924 static const struct { | 924 static const struct { |
| 925 const char* prefix; | 925 const char* prefix; |
| 926 const char* suffix; | 926 const char* suffix; |
| 927 } surroundings[] = { | 927 } surroundings[] = { |
| 928 { "function f() {", "}" }, | 928 { "function f() {", "}" }, |
| 929 { "var f = () => {", "}" }, | 929 { "var f = () => {", "}" }, |
| 930 }; | 930 }; |
| 931 | 931 |
| 932 enum Expected { | 932 enum Expected { |
| 933 NONE = 0, | 933 NONE = 0, |
| 934 ARGUMENTS = 1, | 934 ARGUMENTS = 1, |
| 935 SUPER_PROPERTY = 2, | 935 SUPER_PROPERTY = 2, |
| 936 SUPER_CONSTRUCTOR_CALL = 4, | 936 SUPER_CONSTRUCTOR_CALL = 4, |
| 937 THIS = 8, | 937 INNER_ARGUMENTS = 8, |
| 938 INNER_ARGUMENTS = 16, | 938 INNER_SUPER_PROPERTY = 16, |
| 939 INNER_SUPER_PROPERTY = 32, | 939 INNER_SUPER_CONSTRUCTOR_CALL = 32, |
| 940 INNER_SUPER_CONSTRUCTOR_CALL = 64, | |
| 941 INNER_THIS = 128 | |
| 942 }; | 940 }; |
| 943 | 941 |
| 944 static const struct { | 942 static const struct { |
| 945 const char* body; | 943 const char* body; |
| 946 int expected; | 944 int expected; |
| 947 } source_data[] = { | 945 } source_data[] = { |
| 948 {"", NONE}, | 946 {"", NONE}, |
| 949 {"return this", THIS}, | |
| 950 {"return arguments", ARGUMENTS}, | 947 {"return arguments", ARGUMENTS}, |
| 951 {"return super()", SUPER_CONSTRUCTOR_CALL}, | 948 {"return super()", SUPER_CONSTRUCTOR_CALL}, |
| 952 {"return super.x", SUPER_PROPERTY}, | 949 {"return super.x", SUPER_PROPERTY}, |
| 953 {"return arguments[0]", ARGUMENTS}, | 950 {"return arguments[0]", ARGUMENTS}, |
| 954 {"return this + arguments[0]", ARGUMENTS | THIS}, | 951 {"return this + arguments[0]", ARGUMENTS }, |
| 955 {"return this + arguments[0] + super.x", | 952 {"return this + arguments[0] + super.x", |
| 956 ARGUMENTS | SUPER_PROPERTY | THIS}, | 953 ARGUMENTS | SUPER_PROPERTY }, |
| 957 {"return x => this + x", INNER_THIS}, | 954 {"return x => this + x", NONE}, |
| 958 {"return x => super() + x", INNER_SUPER_CONSTRUCTOR_CALL}, | 955 {"return x => super() + x", INNER_SUPER_CONSTRUCTOR_CALL}, |
| 959 {"this.foo = 42;", THIS}, | 956 {"this.foo = 42;", NONE}, |
| 960 {"this.foo();", THIS}, | 957 {"this.foo();", NONE}, |
| 961 {"if (foo()) { this.f() }", THIS}, | 958 {"if (foo()) { this.f() }", NONE}, |
| 962 {"if (foo()) { super.f() }", SUPER_PROPERTY}, | 959 {"if (foo()) { super.f() }", SUPER_PROPERTY}, |
| 963 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS}, | 960 {"if (arguments.length) { this.f() }", ARGUMENTS}, |
| 964 {"while (true) { this.f() }", THIS}, | 961 {"while (true) { this.f() }", NONE}, |
| 965 {"while (true) { super.f() }", SUPER_PROPERTY}, | 962 {"while (true) { super.f() }", SUPER_PROPERTY}, |
| 966 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS}, | 963 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS}, |
| 967 // Multiple nesting levels must work as well. | 964 // Multiple nesting levels must work as well. |
| 968 {"while (true) { while (true) { while (true) return this } }", THIS}, | 965 {"while (true) { while (true) { while (true) return this } }", NONE}, |
| 969 {"while (true) { while (true) { while (true) return super() } }", | 966 {"while (true) { while (true) { while (true) return super() } }", |
| 970 SUPER_CONSTRUCTOR_CALL}, | 967 SUPER_CONSTRUCTOR_CALL}, |
| 971 {"if (1) { return () => { while (true) new this() } }", INNER_THIS}, | 968 {"if (1) { return () => { while (true) new this() } }", NONE}, |
| 972 {"if (1) { return () => { while (true) new super() } }", NONE}, | 969 {"if (1) { return () => { while (true) new super() } }", NONE}, |
| 973 {"if (1) { return () => { while (true) new new super() } }", NONE}, | 970 {"if (1) { return () => { while (true) new new super() } }", NONE}, |
| 974 // Note that propagation of the inner_uses_this() value does not | |
| 975 // cross boundaries of normal functions onto parent scopes. | |
| 976 {"return function (x) { return this + x }", NONE}, | 971 {"return function (x) { return this + x }", NONE}, |
| 977 {"return function (x) { return super() + x }", NONE}, | 972 {"return function (x) { return super() + x }", NONE}, |
| 978 {"var x = function () { this.foo = 42 };", NONE}, | 973 {"var x = function () { this.foo = 42 };", NONE}, |
| 979 {"var x = function () { super.foo = 42 };", NONE}, | 974 {"var x = function () { super.foo = 42 };", NONE}, |
| 980 {"if (1) { return function () { while (true) new this() } }", NONE}, | 975 {"if (1) { return function () { while (true) new this() } }", NONE}, |
| 981 {"if (1) { return function () { while (true) new super() } }", NONE}, | 976 {"if (1) { return function () { while (true) new super() } }", NONE}, |
| 982 {"return function (x) { return () => this }", NONE}, | 977 {"return function (x) { return () => this }", NONE}, |
| 983 {"return function (x) { return () => super() }", NONE}, | 978 {"return function (x) { return () => super() }", NONE}, |
| 984 // Flags must be correctly set when using block scoping. | 979 // Flags must be correctly set when using block scoping. |
| 985 {"\"use strict\"; while (true) { let x; this, arguments; }", | 980 {"\"use strict\"; while (true) { let x; this, arguments; }", |
| 986 INNER_ARGUMENTS | INNER_THIS}, | 981 INNER_ARGUMENTS}, |
| 987 {"\"use strict\"; while (true) { let x; this, super(), arguments; }", | 982 {"\"use strict\"; while (true) { let x; this, super(), arguments; }", |
| 988 INNER_ARGUMENTS | INNER_SUPER_CONSTRUCTOR_CALL | INNER_THIS}, | 983 INNER_ARGUMENTS | INNER_SUPER_CONSTRUCTOR_CALL}, |
| 989 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS}, | 984 {"\"use strict\"; if (foo()) { let x; this.f() }", NONE}, |
| 990 {"\"use strict\"; if (foo()) { let x; super.f() }", | 985 {"\"use strict\"; if (foo()) { let x; super.f() }", |
| 991 INNER_SUPER_PROPERTY}, | 986 INNER_SUPER_PROPERTY}, |
| 992 {"\"use strict\"; if (1) {" | 987 {"\"use strict\"; if (1) {" |
| 993 " let x; return function () { return this + super() + arguments }" | 988 " let x; return function () { return this + super() + arguments }" |
| 994 "}", | 989 "}", |
| 995 NONE}, | 990 NONE}, |
| 996 }; | 991 }; |
| 997 | 992 |
| 998 i::Isolate* isolate = CcTest::i_isolate(); | 993 i::Isolate* isolate = CcTest::i_isolate(); |
| 999 i::Factory* factory = isolate->factory(); | 994 i::Factory* factory = isolate->factory(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 CHECK(script_scope->is_script_scope()); | 1030 CHECK(script_scope->is_script_scope()); |
| 1036 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1031 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
| 1037 | 1032 |
| 1038 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1033 i::Scope* scope = script_scope->inner_scopes()->at(0); |
| 1039 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, | 1034 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, |
| 1040 scope->uses_arguments()); | 1035 scope->uses_arguments()); |
| 1041 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, | 1036 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, |
| 1042 scope->uses_super_property()); | 1037 scope->uses_super_property()); |
| 1043 CHECK_EQ((source_data[i].expected & SUPER_CONSTRUCTOR_CALL) != 0, | 1038 CHECK_EQ((source_data[i].expected & SUPER_CONSTRUCTOR_CALL) != 0, |
| 1044 scope->uses_super_constructor_call()); | 1039 scope->uses_super_constructor_call()); |
| 1045 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); | |
| 1046 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, | 1040 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, |
| 1047 scope->inner_uses_arguments()); | 1041 scope->inner_uses_arguments()); |
| 1048 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0, | 1042 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0, |
| 1049 scope->inner_uses_super_property()); | 1043 scope->inner_uses_super_property()); |
| 1050 CHECK_EQ((source_data[i].expected & INNER_SUPER_CONSTRUCTOR_CALL) != 0, | 1044 CHECK_EQ((source_data[i].expected & INNER_SUPER_CONSTRUCTOR_CALL) != 0, |
| 1051 scope->inner_uses_super_constructor_call()); | 1045 scope->inner_uses_super_constructor_call()); |
| 1052 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0, | |
| 1053 scope->inner_uses_this()); | |
| 1054 } | 1046 } |
| 1055 } | 1047 } |
| 1056 } | 1048 } |
| 1057 | 1049 |
| 1058 | 1050 |
| 1059 TEST(ScopePositions) { | 1051 TEST(ScopePositions) { |
| 1060 v8::internal::FLAG_harmony_scoping = true; | 1052 v8::internal::FLAG_harmony_scoping = true; |
| 1061 | 1053 |
| 1062 // Test the parser for correctly setting the start and end positions | 1054 // Test the parser for correctly setting the start and end positions |
| 1063 // of a scope. We check the scope positions of exactly one scope | 1055 // of a scope. We check the scope positions of exactly one scope |
| (...skipping 3913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4977 "const x = 1;", | 4969 "const x = 1;", |
| 4978 "class C {}", | 4970 "class C {}", |
| 4979 NULL}; | 4971 NULL}; |
| 4980 | 4972 |
| 4981 static const ParserFlag always_flags[] = { | 4973 static const ParserFlag always_flags[] = { |
| 4982 kAllowHarmonyClasses, kAllowHarmonyScoping | 4974 kAllowHarmonyClasses, kAllowHarmonyScoping |
| 4983 }; | 4975 }; |
| 4984 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 4976 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 4985 always_flags, arraysize(always_flags)); | 4977 always_flags, arraysize(always_flags)); |
| 4986 } | 4978 } |
| OLD | NEW |