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

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

Issue 1092503003: [es6] Make ParseSuperExpression uses scopes instead (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add commented out js test Created 5 years, 8 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
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 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_ARGUMENTS = 1 << 3,
964 INNER_SUPER_PROPERTY = 1 << 4, 964 INNER_THIS = 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", INNER_THIS},
981 {"return x => super.f() + x", INNER_SUPER_PROPERTY}, 980 {"return x => super.f() + x", 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() } }", INNER_THIS},
995 // Note that propagation of the inner_uses_this() value does not 994 // Note that propagation of the inner_uses_this() value does not
996 // cross boundaries of normal functions onto parent scopes. 995 // cross boundaries of normal functions onto parent scopes.
997 {"return function (x) { return this + x }", NONE}, 996 {"return function (x) { return this + x }", NONE},
998 {"return { m(x) { return super.m() + x } }", NONE}, 997 {"return { m(x) { return super.m() + x } }", NONE},
999 {"var x = function () { this.foo = 42 };", NONE}, 998 {"var x = function () { this.foo = 42 };", NONE},
1000 {"var x = { m() { super.foo = 42 } };", NONE}, 999 {"var x = { m() { super.foo = 42 } };", NONE},
1001 {"if (1) { return function () { while (true) new this() } }", NONE}, 1000 {"if (1) { return function () { while (true) new this() } }", NONE},
1002 {"if (1) { return { m() { while (true) super.m() } } }", NONE}, 1001 {"if (1) { return { m() { while (true) super.m() } } }", NONE},
1003 {"return function (x) { return () => this }", NONE}, 1002 {"return function (x) { return () => this }", NONE},
1004 {"return { m(x) { return () => super.m() } }", NONE}, 1003 {"return { m(x) { return () => super.m() } }", NONE},
1005 // Flags must be correctly set when using block scoping. 1004 // Flags must be correctly set when using block scoping.
1006 {"\"use strict\"; while (true) { let x; this, arguments; }", 1005 {"\"use strict\"; while (true) { let x; this, arguments; }",
1007 INNER_ARGUMENTS | INNER_THIS}, 1006 INNER_ARGUMENTS | INNER_THIS},
1008 {"\"use strict\"; while (true) { let x; this, super.f(), arguments; }", 1007 {"\"use strict\"; while (true) { let x; this, super.f(), arguments; }",
1009 INNER_ARGUMENTS | INNER_SUPER_PROPERTY | INNER_THIS}, 1008 INNER_ARGUMENTS | SUPER_PROPERTY | INNER_THIS},
1010 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS}, 1009 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS},
1011 {"\"use strict\"; if (foo()) { let x; super.f() }", 1010 {"\"use strict\"; if (foo()) { let x; super.f() }", SUPER_PROPERTY},
1012 INNER_SUPER_PROPERTY},
1013 {"\"use strict\"; if (1) {" 1011 {"\"use strict\"; if (1) {"
1014 " let x; return { m() { return this + super.m() + arguments } }" 1012 " let x; return { m() { return this + super.m() + arguments } }"
1015 "}", 1013 "}",
1016 NONE}, 1014 NONE},
1017 }; 1015 };
1018 1016
1019 i::Isolate* isolate = CcTest::i_isolate(); 1017 i::Isolate* isolate = CcTest::i_isolate();
1020 i::Factory* factory = isolate->factory(); 1018 i::Factory* factory = isolate->factory();
1021 1019
1022 v8::HandleScope handles(CcTest::isolate()); 1020 v8::HandleScope handles(CcTest::isolate());
1023 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1021 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1024 v8::Context::Scope context_scope(context); 1022 v8::Context::Scope context_scope(context);
1025 1023
1026 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 1024 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
1027 128 * 1024); 1025 128 * 1024);
1028 1026
1029 for (unsigned j = 0; j < arraysize(surroundings); ++j) { 1027 for (unsigned j = 0; j < arraysize(surroundings); ++j) {
1030 for (unsigned i = 0; i < arraysize(source_data); ++i) { 1028 for (unsigned i = 0; i < arraysize(source_data); ++i) {
1031 // Super property is only allowed in constructor and method. 1029 // Super property is only allowed in constructor and method.
1032 if (((source_data[i].expected & SUPER_PROPERTY) || 1030 if (((source_data[i].expected & SUPER_PROPERTY) ||
1033 (source_data[i].expected & INNER_SUPER_PROPERTY) ||
1034 (source_data[i].expected == NONE)) && j != 2) { 1031 (source_data[i].expected == NONE)) && j != 2) {
1035 continue; 1032 continue;
1036 } 1033 }
1037 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + 1034 int kProgramByteSize = i::StrLength(surroundings[j].prefix) +
1038 i::StrLength(surroundings[j].suffix) + 1035 i::StrLength(surroundings[j].suffix) +
1039 i::StrLength(source_data[i].body); 1036 i::StrLength(source_data[i].body);
1040 i::ScopedVector<char> program(kProgramByteSize + 1); 1037 i::ScopedVector<char> program(kProgramByteSize + 1);
1041 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 1038 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
1042 source_data[i].body, surroundings[j].suffix); 1039 source_data[i].body, surroundings[j].suffix);
1043 i::Handle<i::String> source = 1040 i::Handle<i::String> source =
(...skipping 23 matching lines...) Expand all
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 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this());
1075 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, 1072 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0,
1076 scope->inner_uses_arguments()); 1073 scope->inner_uses_arguments());
1077 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0,
1078 scope->inner_uses_super_property());
1079 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0, 1074 CHECK_EQ((source_data[i].expected & INNER_THIS) != 0,
1080 scope->inner_uses_this()); 1075 scope->inner_uses_this());
1081 } 1076 }
1082 } 1077 }
1083 } 1078 }
1084 1079
1085 1080
1086 TEST(ScopePositions) { 1081 TEST(ScopePositions) {
1087 // Test the parser for correctly setting the start and end positions 1082 // Test the parser for correctly setting the start and end positions
1088 // of a scope. We check the scope positions of exactly one scope 1083 // of a scope. We check the scope positions of exactly one scope
(...skipping 5247 matching lines...) Expand 10 before | Expand all | Expand 10 after
6336 v8::Script::Compile(v8_str(script3)); 6331 v8::Script::Compile(v8_str(script3));
6337 CHECK(try_catch2.HasCaught()); 6332 CHECK(try_catch2.HasCaught());
6338 v8::String::Utf8Value exception(try_catch2.Exception()); 6333 v8::String::Utf8Value exception(try_catch2.Exception());
6339 CHECK_EQ(0, 6334 CHECK_EQ(0,
6340 strcmp( 6335 strcmp(
6341 "ReferenceError: In strong mode, using an undeclared global " 6336 "ReferenceError: In strong mode, using an undeclared global "
6342 "variable 'not_there3' is not allowed", 6337 "variable 'not_there3' is not allowed",
6343 *exception)); 6338 *exception));
6344 } 6339 }
6345 } 6340 }
OLDNEW
« src/preparser.h ('K') | « src/scopes.cc ('k') | test/mjsunit/harmony/super.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698