| Index: test/cctest/test-parsing.cc
|
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
|
| index b04fb94d3ac92801f23ef9b44ecade040319e1a8..8fa445de6aca435061b2043a0f1ac53fe2635731 100644
|
| --- a/test/cctest/test-parsing.cc
|
| +++ b/test/cctest/test-parsing.cc
|
| @@ -5698,6 +5698,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';",
|
| @@ -5825,6 +5827,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';",
|
| @@ -5857,6 +5861,215 @@ TEST(ImportExportParsingErrors) {
|
| }
|
| }
|
|
|
| +TEST(ModuleAwaitReserved) {
|
| + i::FLAG_harmony_modules = true;
|
| +
|
| + // 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 {}"
|
| + };
|
| +
|
| + i::Isolate* isolate = CcTest::i_isolate();
|
| + i::Factory* factory = isolate->factory();
|
| +
|
| + v8::HandleScope handles(CcTest::isolate());
|
| + v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
|
| + v8::Context::Scope context_scope(context);
|
| +
|
| + isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
|
| + 128 * 1024);
|
| +
|
| + for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
|
| + i::Handle<i::String> source =
|
| + factory->NewStringFromAsciiChecked(kErrorSources[i]);
|
| +
|
| + i::Handle<i::Script> script = factory->NewScript(source);
|
| + i::Zone zone;
|
| + i::ParseInfo info(&zone, script);
|
| + i::Parser parser(&info);
|
| + info.set_module();
|
| + CHECK(!parser.Parse(&info));
|
| + }
|
| + for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
|
| + i::Handle<i::String> source =
|
| + factory->NewStringFromAsciiChecked(kErrorSources[i]);
|
| +
|
| + i::Handle<i::Script> script = factory->NewScript(source);
|
| + i::Zone zone;
|
| + i::ParseInfo info(&zone, script);
|
| + i::Parser parser(&info);
|
| + CHECK(parser.Parse(&info));
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(ModuleAwaitPermitted) {
|
| + i::FLAG_harmony_modules = true;
|
| +
|
| + // clang-format off
|
| + const char* kErrorSources[] = {
|
| + "({}).await;",
|
| + "({ await: null });",
|
| + "({ await() {} });",
|
| + "({ get await() {} });",
|
| + "({ set await(x) {} });",
|
| + "(class { await() {} });",
|
| + "(class { static await() {} });",
|
| + "(class { *await() {} });",
|
| + "(class { static *await() {} });"
|
| + };
|
| + // clang-format on
|
| +
|
| + i::Isolate* isolate = CcTest::i_isolate();
|
| + i::Factory* factory = isolate->factory();
|
| +
|
| + v8::HandleScope handles(CcTest::isolate());
|
| + v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
|
| + v8::Context::Scope context_scope(context);
|
| +
|
| + isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
|
| + 128 * 1024);
|
| +
|
| + for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
|
| + i::Handle<i::String> source =
|
| + factory->NewStringFromAsciiChecked(kErrorSources[i]);
|
| +
|
| + i::Handle<i::Script> script = factory->NewScript(source);
|
| + i::Zone zone;
|
| + i::ParseInfo info(&zone, script);
|
| + i::Parser parser(&info);
|
| + info.set_module();
|
| + CHECK(parser.Parse(&info));
|
| + }
|
| +}
|
| +
|
| +TEST(EnumReserved) {
|
| + i::FLAG_harmony_modules = true;
|
| +
|
| + // 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 {}"
|
| + };
|
| +
|
| + i::Isolate* isolate = CcTest::i_isolate();
|
| + i::Factory* factory = isolate->factory();
|
| +
|
| + v8::HandleScope handles(CcTest::isolate());
|
| + v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
|
| + v8::Context::Scope context_scope(context);
|
| +
|
| + isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
|
| + 128 * 1024);
|
| +
|
| + for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
|
| + i::Handle<i::String> source =
|
| + factory->NewStringFromAsciiChecked(kErrorSources[i]);
|
| +
|
| + i::Handle<i::Script> script = factory->NewScript(source);
|
| + i::Zone zone;
|
| + i::ParseInfo info(&zone, script);
|
| + i::Parser parser(&info);
|
| + info.set_module();
|
| + CHECK(!parser.Parse(&info));
|
| + }
|
| + for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
|
| + i::Handle<i::String> source =
|
| + factory->NewStringFromAsciiChecked(kErrorSources[i]);
|
| +
|
| + i::Handle<i::Script> script = factory->NewScript(source);
|
| + i::Zone zone;
|
| + i::ParseInfo info(&zone, script);
|
| + i::Parser parser(&info);
|
| + CHECK(!parser.Parse(&info));
|
| + }
|
| +}
|
| +
|
|
|
| TEST(ModuleParsingInternals) {
|
| i::FLAG_harmony_modules = true;
|
|
|