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 718473002: ES6: Add support for super in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix remaining code review issues Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | test/mjsunit/harmony/object-literals-super.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 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 if (!bad) { 912 if (!bad) {
913 i += input_offset; 913 i += input_offset;
914 character_length -= output_adjust; 914 character_length -= output_adjust;
915 } 915 }
916 } 916 }
917 } 917 }
918 return character_length; 918 return character_length;
919 } 919 }
920 920
921 921
922 TEST(ScopeUsesThisAndArguments) { 922 TEST(ScopeUsesArgumentsSuperThis) {
923 static const struct { 923 static const struct {
924 const char* prefix; 924 const char* prefix;
925 const char* suffix; 925 const char* suffix;
926 } surroundings[] = { 926 } surroundings[] = {
927 { "function f() {", "}" }, 927 { "function f() {", "}" },
928 { "var f = () => {", "}" }, 928 { "var f = () => {", "}" },
929 }; 929 };
930 930
931 enum Expected {
932 NONE = 0,
933 ARGUMENTS = 1,
934 SUPER = 2,
935 THIS = 4,
936 INNER_ARGUMENTS = 8,
937 INNER_SUPER = 16,
938 INNER_THIS = 32
939 };
940
931 static const struct { 941 static const struct {
932 const char* body; 942 const char* body;
933 bool uses_this; 943 int expected;
934 bool uses_arguments;
935 bool inner_uses_this;
936 bool inner_uses_arguments;
937 } source_data[] = { 944 } source_data[] = {
938 { "", 945 {"", NONE},
939 false, false, false, false }, 946 {"return this", THIS},
940 { "return this", 947 {"return arguments", ARGUMENTS},
941 true, false, false, false }, 948 {"return super()", SUPER},
942 { "return arguments", 949 {"return super.x", SUPER},
943 false, true, false, false }, 950 {"return arguments[0]", ARGUMENTS},
944 { "return arguments[0]", 951 {"return this + arguments[0]", ARGUMENTS | THIS},
945 false, true, false, false }, 952 {"return this + arguments[0] + super.x", ARGUMENTS | SUPER | THIS},
946 { "return this + arguments[0]", 953 {"return x => this + x", INNER_THIS},
947 true, true, false, false }, 954 {"return x => super() + x", INNER_SUPER},
948 { "return x => this + x", 955 {"this.foo = 42;", THIS},
949 false, false, true, false }, 956 {"this.foo();", THIS},
950 { "this.foo = 42;", 957 {"if (foo()) { this.f() }", THIS},
951 true, false, false, false }, 958 {"if (foo()) { super.f() }", SUPER},
952 { "this.foo();", 959 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS},
953 true, false, false, false }, 960 {"while (true) { this.f() }", THIS},
954 { "if (foo()) { this.f() }", 961 {"while (true) { super.f() }", SUPER},
955 true, false, false, false }, 962 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS},
956 { "if (arguments.length) { this.f() }", 963 // Multiple nesting levels must work as well.
957 true, true, false, false }, 964 {"while (true) { while (true) { while (true) return this } }", THIS},
958 { "while (true) { this.f() }", 965 {"while (true) { while (true) { while (true) return super() } }",
959 true, false, false, false }, 966 SUPER},
960 { "if (true) { while (true) this.foo(arguments) }", 967 {"if (1) { return () => { while (true) new this() } }", INNER_THIS},
961 true, true, false, false }, 968 {"if (1) { return () => { while (true) new super() } }", INNER_SUPER},
962 // Multiple nesting levels must work as well. 969 // Note that propagation of the inner_uses_this() value does not
963 { "while (true) { while (true) { while (true) return this } }", 970 // cross boundaries of normal functions onto parent scopes.
964 true, false, false, false }, 971 {"return function (x) { return this + x }", NONE},
965 { "if (1) { return () => { while (true) new this() } }", 972 {"return function (x) { return super() + x }", NONE},
966 false, false, true, false }, 973 {"var x = function () { this.foo = 42 };", NONE},
967 // Note that propagation of the inner_uses_this() value does not 974 {"var x = function () { super.foo = 42 };", NONE},
968 // cross boundaries of normal functions onto parent scopes. 975 {"if (1) { return function () { while (true) new this() } }", NONE},
969 { "return function (x) { return this + x }", 976 {"if (1) { return function () { while (true) new super() } }", NONE},
970 false, false, false, false }, 977 {"return function (x) { return () => this }", NONE},
971 { "var x = function () { this.foo = 42 };", 978 {"return function (x) { return () => super() }", NONE},
972 false, false, false, false }, 979 // Flags must be correctly set when using block scoping.
973 { "if (1) { return function () { while (true) new this() } }", 980 {"\"use strict\"; while (true) { let x; this, arguments; }",
974 false, false, false, false }, 981 INNER_ARGUMENTS | INNER_THIS},
975 { "return function (x) { return () => this }", 982 {"\"use strict\"; while (true) { let x; this, super(), arguments; }",
976 false, false, false, false }, 983 INNER_ARGUMENTS | INNER_SUPER | INNER_THIS},
977 // Flags must be correctly set when using block scoping. 984 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS},
978 { "\"use strict\"; while (true) { let x; this, arguments; }", 985 {"\"use strict\"; if (foo()) { let x; super.f() }", INNER_SUPER},
979 false, false, true, true }, 986 {"\"use strict\"; if (1) {"
980 { "\"use strict\"; if (foo()) { let x; this.f() }", 987 " let x; return function () { return this + super() + arguments }"
981 false, false, true, false }, 988 "}",
982 { "\"use strict\"; if (1) {" 989 NONE},
983 " let x; return function () { return this + arguments }" 990 };
984 "}",
985 false, false, false, false },
986 };
987 991
988 i::Isolate* isolate = CcTest::i_isolate(); 992 i::Isolate* isolate = CcTest::i_isolate();
989 i::Factory* factory = isolate->factory(); 993 i::Factory* factory = isolate->factory();
990 994
991 v8::HandleScope handles(CcTest::isolate()); 995 v8::HandleScope handles(CcTest::isolate());
992 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 996 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
993 v8::Context::Scope context_scope(context); 997 v8::Context::Scope context_scope(context);
994 998
995 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 999 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
996 128 * 1024); 1000 128 * 1024);
997 1001
998 for (unsigned j = 0; j < arraysize(surroundings); ++j) { 1002 for (unsigned j = 0; j < arraysize(surroundings); ++j) {
999 for (unsigned i = 0; i < arraysize(source_data); ++i) { 1003 for (unsigned i = 0; i < arraysize(source_data); ++i) {
1000 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + 1004 int kProgramByteSize = i::StrLength(surroundings[j].prefix) +
1001 i::StrLength(surroundings[j].suffix) + 1005 i::StrLength(surroundings[j].suffix) +
1002 i::StrLength(source_data[i].body); 1006 i::StrLength(source_data[i].body);
1003 i::ScopedVector<char> program(kProgramByteSize + 1); 1007 i::ScopedVector<char> program(kProgramByteSize + 1);
1004 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 1008 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
1005 source_data[i].body, surroundings[j].suffix); 1009 source_data[i].body, surroundings[j].suffix);
1006 i::Handle<i::String> source = 1010 i::Handle<i::String> source =
1007 factory->NewStringFromUtf8(i::CStrVector(program.start())) 1011 factory->NewStringFromUtf8(i::CStrVector(program.start()))
1008 .ToHandleChecked(); 1012 .ToHandleChecked();
1009 i::Handle<i::Script> script = factory->NewScript(source); 1013 i::Handle<i::Script> script = factory->NewScript(source);
1010 i::CompilationInfoWithZone info(script); 1014 i::CompilationInfoWithZone info(script);
1011 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 1015 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
1012 isolate->heap()->HashSeed(), 1016 isolate->heap()->HashSeed(),
1013 isolate->unicode_cache()}; 1017 isolate->unicode_cache()};
1014 i::Parser parser(&info, &parse_info); 1018 i::Parser parser(&info, &parse_info);
1015 parser.set_allow_arrow_functions(true); 1019 parser.set_allow_arrow_functions(true);
1020 parser.set_allow_classes(true);
1016 parser.set_allow_harmony_scoping(true); 1021 parser.set_allow_harmony_scoping(true);
1017 info.MarkAsGlobal(); 1022 info.MarkAsGlobal();
1018 parser.Parse(); 1023 parser.Parse();
1019 CHECK(i::Rewriter::Rewrite(&info)); 1024 CHECK(i::Rewriter::Rewrite(&info));
1020 CHECK(i::Scope::Analyze(&info)); 1025 CHECK(i::Scope::Analyze(&info));
1021 CHECK(info.function() != NULL); 1026 CHECK(info.function() != NULL);
1022 1027
1023 i::Scope* global_scope = info.function()->scope(); 1028 i::Scope* global_scope = info.function()->scope();
1024 CHECK(global_scope->is_global_scope()); 1029 CHECK(global_scope->is_global_scope());
1025 CHECK_EQ(1, global_scope->inner_scopes()->length()); 1030 CHECK_EQ(1, global_scope->inner_scopes()->length());
1026 1031
1027 i::Scope* scope = global_scope->inner_scopes()->at(0); 1032 i::Scope* scope = global_scope->inner_scopes()->at(0);
1028 CHECK_EQ(source_data[i].uses_this, scope->uses_this()); 1033 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0,
1029 CHECK_EQ(source_data[i].uses_arguments, scope->uses_arguments()); 1034 scope->uses_arguments());
1030 CHECK_EQ(source_data[i].inner_uses_this, scope->inner_uses_this()); 1035 CHECK_EQ((source_data[i].expected & SUPER) != 0, scope->uses_super());
1031 CHECK_EQ(source_data[i].inner_uses_arguments, 1036 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this());
1037 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0,
1032 scope->inner_uses_arguments()); 1038 scope->inner_uses_arguments());
1039 CHECK_EQ((source_data[i].expected & INNER_SUPER) != 0,
1040 scope->inner_uses_super());
1041 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0,
1042 scope->inner_uses_this());
1033 } 1043 }
1034 } 1044 }
1035 } 1045 }
1036 1046
1037 1047
1038 TEST(ScopePositions) { 1048 TEST(ScopePositions) {
1039 v8::internal::FLAG_harmony_scoping = true; 1049 v8::internal::FLAG_harmony_scoping = true;
1040 1050
1041 // Test the parser for correctly setting the start and end positions 1051 // Test the parser for correctly setting the start and end positions
1042 // of a scope. We check the scope positions of exactly one scope 1052 // of a scope. We check the scope positions of exactly one scope
(...skipping 3258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4301 const char* data[] = { 4311 const char* data[] = {
4302 "var foob\\u123r = 0;", 4312 "var foob\\u123r = 0;",
4303 "var \\u123roo = 0;", 4313 "var \\u123roo = 0;",
4304 "\"foob\\u123rr\"", 4314 "\"foob\\u123rr\"",
4305 // No escapes allowed in regexp flags 4315 // No escapes allowed in regexp flags
4306 "/regex/\\u0069g", 4316 "/regex/\\u0069g",
4307 "/regex/\\u006g", 4317 "/regex/\\u006g",
4308 NULL}; 4318 NULL};
4309 RunParserSyncTest(context_data, data, kError); 4319 RunParserSyncTest(context_data, data, kError);
4310 } 4320 }
OLDNEW
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | test/mjsunit/harmony/object-literals-super.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698