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

Unified Diff: test/cctest/test-parsing.cc

Issue 1723313002: [parser] Enforce module-specific identifier restriction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Relax assertion criteria Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/token.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index d8e5580b8ad78de5513cf40587a8f4876a9804fc..a28c235c5e3f036049c8cdf32d6ba6fedcdcacd1 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1542,11 +1542,10 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
uintptr_t stack_limit = isolate->stack_guard()->real_climit();
int preparser_materialized_literals = -1;
int parser_materialized_literals = -2;
- bool test_preparser = !is_module;
// Preparse the data.
i::CompleteParserRecorder log;
- if (test_preparser) {
nickie 2016/05/03 17:07:52 If I understand it right, this change requires the
+ {
i::Scanner scanner(isolate->unicode_cache());
i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
i::Zone zone(CcTest::i_isolate()->allocator());
@@ -1603,7 +1602,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
CHECK(false);
}
- if (test_preparser && !preparse_error) {
+ if (!preparse_error) {
v8::base::OS::Print(
"Parser failed on:\n"
"\t%s\n"
@@ -1614,7 +1613,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
CHECK(false);
}
// Check that preparser and parser produce the same error.
- if (test_preparser) {
+ {
i::Handle<i::String> preparser_message =
FormatMessage(log.ErrorMessageData());
if (!i::String::Equals(message_string, preparser_message)) {
@@ -1629,7 +1628,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
CHECK(false);
}
}
- } else if (test_preparser && preparse_error) {
+ } else if (preparse_error) {
v8::base::OS::Print(
"Preparser failed on:\n"
"\t%s\n"
@@ -1646,8 +1645,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
"However, parser and preparser succeeded",
source->ToCString().get());
CHECK(false);
- } else if (test_preparser &&
- preparser_materialized_literals != parser_materialized_literals) {
+ } else if (preparser_materialized_literals != parser_materialized_literals) {
v8::base::OS::Print(
"Preparser materialized literals (%d) differ from Parser materialized "
"literals (%d) on:\n"
@@ -5476,6 +5474,8 @@ TEST(BasicImportExportParsing) {
"export { static } from 'm.js'",
"export { let } from 'm.js'",
"var a; export { a as b, a as c };",
+ "var a; export { a as await };",
+ "var a; export { a as enum };",
"import 'somemodule.js';",
"import { } from 'm.js';",
@@ -5601,6 +5601,8 @@ TEST(ImportExportParsingErrors) {
"import { y as yield } from 'm.js'",
"import { s as static } from 'm.js'",
"import { l as let } from 'm.js'",
+ "import { a as await } from 'm.js';",
+ "import { a as enum } from 'm.js';",
"import { x }, def from 'm.js';",
"import def, def2 from 'm.js';",
"import * as x, def from 'm.js';",
@@ -5670,6 +5672,142 @@ TEST(ModuleTopLevelFunctionDecl) {
}
}
+TEST(ModuleAwaitReserved) {
+ // clang-format off
+ const char* kErrorSources[] = {
+ "await;",
+ "await: ;",
+ "var await;",
+ "var [await] = [];",
+ "var { await } = {};",
+ "var { x: await } = {};",
+ "{ var await; }",
+ "let await;",
+ "let [await] = [];",
+ "let { await } = {};",
+ "let { x: await } = {};",
+ "{ let await; }",
+ "const await = null;",
+ "const [await] = [];",
+ "const { await } = {};",
+ "const { x: await } = {};",
+ "{ const await = null; }",
+ "function await() {}",
+ "function f(await) {}",
+ "function* await() {}",
+ "function* g(await) {}",
+ "(function await() {});",
+ "(function (await) {});",
+ "(function* await() {});",
+ "(function* (await) {});",
+ "(await) => {};",
+ "await => {};",
+ "class await {}",
+ "class C { constructor(await) {} }",
+ "class C { m(await) {} }",
+ "class C { static m(await) {} }",
+ "class C { *m(await) {} }",
+ "class C { static *m(await) {} }",
+ "(class await {})",
+ "(class { constructor(await) {} });",
+ "(class { m(await) {} });",
+ "(class { static m(await) {} });",
+ "(class { *m(await) {} });",
+ "(class { static *m(await) {} });",
+ "({ m(await) {} });",
+ "({ *m(await) {} });",
+ "({ set p(await) {} });",
+ "try {} catch (await) {}",
+ "try {} catch (await) {} finally {}",
+ NULL
+ };
+ // clang-format on
+ const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
+
+ RunModuleParserSyncTest(context_data, kErrorSources, kError);
+}
+
+TEST(ModuleAwaitReservedPreParse) {
+ const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
+ const char* error_data[] = {"function f() { var await = 0; }", NULL};
+
+ RunModuleParserSyncTest(context_data, error_data, kError);
+}
+
+TEST(ModuleAwaitPermitted) {
+ // clang-format off
+ const char* kValidSources[] = {
+ "({}).await;",
+ "({ await: null });",
+ "({ await() {} });",
+ "({ get await() {} });",
+ "({ set await(x) {} });",
+ "(class { await() {} });",
+ "(class { static await() {} });",
+ "(class { *await() {} });",
+ "(class { static *await() {} });",
+ NULL
+ };
+ // clang-format on
+ const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
+
+ RunModuleParserSyncTest(context_data, kValidSources, kSuccess);
+}
+
+TEST(EnumReserved) {
+ // clang-format off
+ const char* kErrorSources[] = {
+ "enum;",
+ "enum: ;",
+ "var enum;",
+ "var [enum] = [];",
+ "var { enum } = {};",
+ "var { x: enum } = {};",
+ "{ var enum; }",
+ "let enum;",
+ "let [enum] = [];",
+ "let { enum } = {};",
+ "let { x: enum } = {};",
+ "{ let enum; }",
+ "const enum = null;",
+ "const [enum] = [];",
+ "const { enum } = {};",
+ "const { x: enum } = {};",
+ "{ const enum = null; }",
+ "function enum() {}",
+ "function f(enum) {}",
+ "function* enum() {}",
+ "function* g(enum) {}",
+ "(function enum() {});",
+ "(function (enum) {});",
+ "(function* enum() {});",
+ "(function* (enum) {});",
+ "(enum) => {};",
+ "enum => {};",
+ "class enum {}",
+ "class C { constructor(enum) {} }",
+ "class C { m(enum) {} }",
+ "class C { static m(enum) {} }",
+ "class C { *m(enum) {} }",
+ "class C { static *m(enum) {} }",
+ "(class enum {})",
+ "(class { constructor(enum) {} });",
+ "(class { m(enum) {} });",
+ "(class { static m(enum) {} });",
+ "(class { *m(enum) {} });",
+ "(class { static *m(enum) {} });",
+ "({ m(enum) {} });",
+ "({ *m(enum) {} });",
+ "({ set p(enum) {} });",
+ "try {} catch (enum) {}",
+ "try {} catch (enum) {} finally {}",
+ NULL
+ };
+ // clang-format on
+ const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
+
+ RunModuleParserSyncTest(context_data, kErrorSources, kError);
+}
TEST(ModuleParsingInternals) {
i::Isolate* isolate = CcTest::i_isolate();
« no previous file with comments | « src/parsing/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698