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

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

Issue 766663003: harmony-classes: Implement 'super(...)' call syntactic restriction. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Patch for landing Created 6 years 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 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 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = 2, 935 SUPER_PROPERTY = 2,
936 THIS = 4, 936 SUPER_CONSTRUCTOR_CALL = 4,
937 INNER_ARGUMENTS = 8, 937 THIS = 8,
938 INNER_SUPER = 16, 938 INNER_ARGUMENTS = 16,
939 INNER_THIS = 32 939 INNER_SUPER_PROPERTY = 32,
940 INNER_SUPER_CONSTRUCTOR_CALL = 64,
941 INNER_THIS = 128
940 }; 942 };
941 943
942 static const struct { 944 static const struct {
943 const char* body; 945 const char* body;
944 int expected; 946 int expected;
945 } source_data[] = { 947 } source_data[] = {
946 {"", NONE}, 948 {"", NONE},
947 {"return this", THIS}, 949 {"return this", THIS},
948 {"return arguments", ARGUMENTS}, 950 {"return arguments", ARGUMENTS},
949 {"return super()", SUPER}, 951 {"return super()", SUPER_CONSTRUCTOR_CALL},
950 {"return super.x", SUPER}, 952 {"return super.x", SUPER_PROPERTY},
951 {"return arguments[0]", ARGUMENTS}, 953 {"return arguments[0]", ARGUMENTS},
952 {"return this + arguments[0]", ARGUMENTS | THIS}, 954 {"return this + arguments[0]", ARGUMENTS | THIS},
953 {"return this + arguments[0] + super.x", ARGUMENTS | SUPER | THIS}, 955 {"return this + arguments[0] + super.x",
956 ARGUMENTS | SUPER_PROPERTY | THIS},
954 {"return x => this + x", INNER_THIS}, 957 {"return x => this + x", INNER_THIS},
955 {"return x => super() + x", INNER_SUPER}, 958 {"return x => super() + x", INNER_SUPER_CONSTRUCTOR_CALL},
956 {"this.foo = 42;", THIS}, 959 {"this.foo = 42;", THIS},
957 {"this.foo();", THIS}, 960 {"this.foo();", THIS},
958 {"if (foo()) { this.f() }", THIS}, 961 {"if (foo()) { this.f() }", THIS},
959 {"if (foo()) { super.f() }", SUPER}, 962 {"if (foo()) { super.f() }", SUPER_PROPERTY},
960 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS}, 963 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS},
961 {"while (true) { this.f() }", THIS}, 964 {"while (true) { this.f() }", THIS},
962 {"while (true) { super.f() }", SUPER}, 965 {"while (true) { super.f() }", SUPER_PROPERTY},
963 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS}, 966 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS},
964 // Multiple nesting levels must work as well. 967 // Multiple nesting levels must work as well.
965 {"while (true) { while (true) { while (true) return this } }", THIS}, 968 {"while (true) { while (true) { while (true) return this } }", THIS},
966 {"while (true) { while (true) { while (true) return super() } }", 969 {"while (true) { while (true) { while (true) return super() } }",
967 SUPER}, 970 SUPER_CONSTRUCTOR_CALL},
968 {"if (1) { return () => { while (true) new this() } }", INNER_THIS}, 971 {"if (1) { return () => { while (true) new this() } }", INNER_THIS},
969 {"if (1) { return () => { while (true) new super() } }", INNER_SUPER}, 972 {"if (1) { return () => { while (true) new super() } }", NONE},
973 {"if (1) { return () => { while (true) new new super() } }", NONE},
970 // Note that propagation of the inner_uses_this() value does not 974 // Note that propagation of the inner_uses_this() value does not
971 // cross boundaries of normal functions onto parent scopes. 975 // cross boundaries of normal functions onto parent scopes.
972 {"return function (x) { return this + x }", NONE}, 976 {"return function (x) { return this + x }", NONE},
973 {"return function (x) { return super() + x }", NONE}, 977 {"return function (x) { return super() + x }", NONE},
974 {"var x = function () { this.foo = 42 };", NONE}, 978 {"var x = function () { this.foo = 42 };", NONE},
975 {"var x = function () { super.foo = 42 };", NONE}, 979 {"var x = function () { super.foo = 42 };", NONE},
976 {"if (1) { return function () { while (true) new this() } }", NONE}, 980 {"if (1) { return function () { while (true) new this() } }", NONE},
977 {"if (1) { return function () { while (true) new super() } }", NONE}, 981 {"if (1) { return function () { while (true) new super() } }", NONE},
978 {"return function (x) { return () => this }", NONE}, 982 {"return function (x) { return () => this }", NONE},
979 {"return function (x) { return () => super() }", NONE}, 983 {"return function (x) { return () => super() }", NONE},
980 // Flags must be correctly set when using block scoping. 984 // Flags must be correctly set when using block scoping.
981 {"\"use strict\"; while (true) { let x; this, arguments; }", 985 {"\"use strict\"; while (true) { let x; this, arguments; }",
982 INNER_ARGUMENTS | INNER_THIS}, 986 INNER_ARGUMENTS | INNER_THIS},
983 {"\"use strict\"; while (true) { let x; this, super(), arguments; }", 987 {"\"use strict\"; while (true) { let x; this, super(), arguments; }",
984 INNER_ARGUMENTS | INNER_SUPER | INNER_THIS}, 988 INNER_ARGUMENTS | INNER_SUPER_CONSTRUCTOR_CALL | INNER_THIS},
985 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS}, 989 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS},
986 {"\"use strict\"; if (foo()) { let x; super.f() }", INNER_SUPER}, 990 {"\"use strict\"; if (foo()) { let x; super.f() }",
991 INNER_SUPER_PROPERTY},
987 {"\"use strict\"; if (1) {" 992 {"\"use strict\"; if (1) {"
988 " let x; return function () { return this + super() + arguments }" 993 " let x; return function () { return this + super() + arguments }"
989 "}", 994 "}",
990 NONE}, 995 NONE},
991 }; 996 };
992 997
993 i::Isolate* isolate = CcTest::i_isolate(); 998 i::Isolate* isolate = CcTest::i_isolate();
994 i::Factory* factory = isolate->factory(); 999 i::Factory* factory = isolate->factory();
995 1000
996 v8::HandleScope handles(CcTest::isolate()); 1001 v8::HandleScope handles(CcTest::isolate());
(...skipping 29 matching lines...) Expand all
1026 CHECK(i::Scope::Analyze(&info)); 1031 CHECK(i::Scope::Analyze(&info));
1027 CHECK(info.function() != NULL); 1032 CHECK(info.function() != NULL);
1028 1033
1029 i::Scope* script_scope = info.function()->scope(); 1034 i::Scope* script_scope = info.function()->scope();
1030 CHECK(script_scope->is_script_scope()); 1035 CHECK(script_scope->is_script_scope());
1031 CHECK_EQ(1, script_scope->inner_scopes()->length()); 1036 CHECK_EQ(1, script_scope->inner_scopes()->length());
1032 1037
1033 i::Scope* scope = script_scope->inner_scopes()->at(0); 1038 i::Scope* scope = script_scope->inner_scopes()->at(0);
1034 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, 1039 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0,
1035 scope->uses_arguments()); 1040 scope->uses_arguments());
1036 CHECK_EQ((source_data[i].expected & SUPER) != 0, scope->uses_super()); 1041 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0,
1042 scope->uses_super_property());
1043 CHECK_EQ((source_data[i].expected & SUPER_CONSTRUCTOR_CALL) != 0,
1044 scope->uses_super_constructor_call());
1037 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); 1045 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this());
1038 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, 1046 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0,
1039 scope->inner_uses_arguments()); 1047 scope->inner_uses_arguments());
1040 CHECK_EQ((source_data[i].expected & INNER_SUPER) != 0, 1048 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0,
1041 scope->inner_uses_super()); 1049 scope->inner_uses_super_property());
1050 CHECK_EQ((source_data[i].expected & INNER_SUPER_CONSTRUCTOR_CALL) != 0,
1051 scope->inner_uses_super_constructor_call());
1042 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0, 1052 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0,
1043 scope->inner_uses_this()); 1053 scope->inner_uses_this());
1044 } 1054 }
1045 } 1055 }
1046 } 1056 }
1047 1057
1048 1058
1049 TEST(ScopePositions) { 1059 TEST(ScopePositions) {
1050 v8::internal::FLAG_harmony_scoping = true; 1060 v8::internal::FLAG_harmony_scoping = true;
1051 1061
(...skipping 3452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4504 always_false_flags, arraysize(always_false_flags)); 4514 always_false_flags, arraysize(always_false_flags));
4505 4515
4506 const char* good_data[] = { 4516 const char* good_data[] = {
4507 "let = 1;", 4517 "let = 1;",
4508 "for(let = 1;;){}", 4518 "for(let = 1;;){}",
4509 NULL}; 4519 NULL};
4510 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, 4520 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0,
4511 always_true_flags, arraysize(always_true_flags), 4521 always_true_flags, arraysize(always_true_flags),
4512 always_false_flags, arraysize(always_false_flags)); 4522 always_false_flags, arraysize(always_false_flags));
4513 } 4523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698