OLD | NEW |
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 5680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5691 "var x; export default x = 7", | 5691 "var x; export default x = 7", |
5692 "export { Q } from 'somemodule.js';", | 5692 "export { Q } from 'somemodule.js';", |
5693 "export * from 'somemodule.js';", | 5693 "export * from 'somemodule.js';", |
5694 "var foo; export { foo as for };", | 5694 "var foo; export { foo as for };", |
5695 "export { arguments } from 'm.js';", | 5695 "export { arguments } from 'm.js';", |
5696 "export { for } from 'm.js';", | 5696 "export { for } from 'm.js';", |
5697 "export { yield } from 'm.js'", | 5697 "export { yield } from 'm.js'", |
5698 "export { static } from 'm.js'", | 5698 "export { static } from 'm.js'", |
5699 "export { let } from 'm.js'", | 5699 "export { let } from 'm.js'", |
5700 "var a; export { a as b, a as c };", | 5700 "var a; export { a as b, a as c };", |
| 5701 "var a; export { a as await };", |
| 5702 "var a; export { a as enum };", |
5701 | 5703 |
5702 "import 'somemodule.js';", | 5704 "import 'somemodule.js';", |
5703 "import { } from 'm.js';", | 5705 "import { } from 'm.js';", |
5704 "import { a } from 'm.js';", | 5706 "import { a } from 'm.js';", |
5705 "import { a, b as d, c, } from 'm.js';", | 5707 "import { a, b as d, c, } from 'm.js';", |
5706 "import * as thing from 'm.js';", | 5708 "import * as thing from 'm.js';", |
5707 "import thing from 'm.js';", | 5709 "import thing from 'm.js';", |
5708 "import thing, * as rest from 'm.js';", | 5710 "import thing, * as rest from 'm.js';", |
5709 "import thing, { a, b, c } from 'm.js';", | 5711 "import thing, { a, b, c } from 'm.js';", |
5710 "import { arguments as a } from 'm.js';", | 5712 "import { arguments as a } from 'm.js';", |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5818 "import a { b, c } from 'm.js';", | 5820 "import a { b, c } from 'm.js';", |
5819 "import arguments from 'm.js';", | 5821 "import arguments from 'm.js';", |
5820 "import eval from 'm.js';", | 5822 "import eval from 'm.js';", |
5821 "import { arguments } from 'm.js';", | 5823 "import { arguments } from 'm.js';", |
5822 "import { eval } from 'm.js';", | 5824 "import { eval } from 'm.js';", |
5823 "import { a as arguments } from 'm.js';", | 5825 "import { a as arguments } from 'm.js';", |
5824 "import { for } from 'm.js';", | 5826 "import { for } from 'm.js';", |
5825 "import { y as yield } from 'm.js'", | 5827 "import { y as yield } from 'm.js'", |
5826 "import { s as static } from 'm.js'", | 5828 "import { s as static } from 'm.js'", |
5827 "import { l as let } from 'm.js'", | 5829 "import { l as let } from 'm.js'", |
| 5830 "import { a as await } from 'm.js';", |
| 5831 "import { a as enum } from 'm.js';", |
5828 "import { x }, def from 'm.js';", | 5832 "import { x }, def from 'm.js';", |
5829 "import def, def2 from 'm.js';", | 5833 "import def, def2 from 'm.js';", |
5830 "import * as x, def from 'm.js';", | 5834 "import * as x, def from 'm.js';", |
5831 "import * as x, * as y from 'm.js';", | 5835 "import * as x, * as y from 'm.js';", |
5832 "import {x}, {y} from 'm.js';", | 5836 "import {x}, {y} from 'm.js';", |
5833 "import * as x, {y} from 'm.js';", | 5837 "import * as x, {y} from 'm.js';", |
5834 }; | 5838 }; |
5835 // clang-format on | 5839 // clang-format on |
5836 | 5840 |
5837 i::Isolate* isolate = CcTest::i_isolate(); | 5841 i::Isolate* isolate = CcTest::i_isolate(); |
(...skipping 12 matching lines...) Expand all Loading... |
5850 | 5854 |
5851 i::Handle<i::Script> script = factory->NewScript(source); | 5855 i::Handle<i::Script> script = factory->NewScript(source); |
5852 i::Zone zone; | 5856 i::Zone zone; |
5853 i::ParseInfo info(&zone, script); | 5857 i::ParseInfo info(&zone, script); |
5854 i::Parser parser(&info); | 5858 i::Parser parser(&info); |
5855 info.set_module(); | 5859 info.set_module(); |
5856 CHECK(!parser.Parse(&info)); | 5860 CHECK(!parser.Parse(&info)); |
5857 } | 5861 } |
5858 } | 5862 } |
5859 | 5863 |
| 5864 TEST(ModuleAwaitReserved) { |
| 5865 i::FLAG_harmony_modules = true; |
| 5866 |
| 5867 // clang-format off |
| 5868 const char* kErrorSources[] = { |
| 5869 "await;", |
| 5870 "await: ;", |
| 5871 "var await;", |
| 5872 "var [await] = [];", |
| 5873 "var { await } = {};", |
| 5874 "var { x: await } = {};", |
| 5875 "{ var await; }", |
| 5876 "let await;", |
| 5877 "let [await] = [];", |
| 5878 "let { await } = {};", |
| 5879 "let { x: await } = {};", |
| 5880 "{ let await; }", |
| 5881 "const await = null;", |
| 5882 "const [await] = [];", |
| 5883 "const { await } = {};", |
| 5884 "const { x: await } = {};", |
| 5885 "{ const await = null; }", |
| 5886 "function await() {}", |
| 5887 "function f(await) {}", |
| 5888 "function* await() {}", |
| 5889 "function* g(await) {}", |
| 5890 "(function await() {});", |
| 5891 "(function (await) {});", |
| 5892 "(function* await() {});", |
| 5893 "(function* (await) {});", |
| 5894 "(await) => {};", |
| 5895 "await => {};", |
| 5896 "class await {}", |
| 5897 "class C { constructor(await) {} }", |
| 5898 "class C { m(await) {} }", |
| 5899 "class C { static m(await) {} }", |
| 5900 "class C { *m(await) {} }", |
| 5901 "class C { static *m(await) {} }", |
| 5902 "(class await {})", |
| 5903 "(class { constructor(await) {} });", |
| 5904 "(class { m(await) {} });", |
| 5905 "(class { static m(await) {} });", |
| 5906 "(class { *m(await) {} });", |
| 5907 "(class { static *m(await) {} });", |
| 5908 "({ m(await) {} });", |
| 5909 "({ *m(await) {} });", |
| 5910 "({ set p(await) {} });", |
| 5911 "try {} catch (await) {}", |
| 5912 "try {} catch (await) {} finally {}" |
| 5913 }; |
| 5914 |
| 5915 i::Isolate* isolate = CcTest::i_isolate(); |
| 5916 i::Factory* factory = isolate->factory(); |
| 5917 |
| 5918 v8::HandleScope handles(CcTest::isolate()); |
| 5919 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5920 v8::Context::Scope context_scope(context); |
| 5921 |
| 5922 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5923 128 * 1024); |
| 5924 |
| 5925 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 5926 i::Handle<i::String> source = |
| 5927 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 5928 |
| 5929 i::Handle<i::Script> script = factory->NewScript(source); |
| 5930 i::Zone zone; |
| 5931 i::ParseInfo info(&zone, script); |
| 5932 i::Parser parser(&info); |
| 5933 info.set_module(); |
| 5934 CHECK(!parser.Parse(&info)); |
| 5935 } |
| 5936 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 5937 i::Handle<i::String> source = |
| 5938 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 5939 |
| 5940 i::Handle<i::Script> script = factory->NewScript(source); |
| 5941 i::Zone zone; |
| 5942 i::ParseInfo info(&zone, script); |
| 5943 i::Parser parser(&info); |
| 5944 CHECK(parser.Parse(&info)); |
| 5945 } |
| 5946 } |
| 5947 |
| 5948 |
| 5949 TEST(ModuleAwaitPermitted) { |
| 5950 i::FLAG_harmony_modules = true; |
| 5951 |
| 5952 // clang-format off |
| 5953 const char* kErrorSources[] = { |
| 5954 "({}).await;", |
| 5955 "({ await: null });", |
| 5956 "({ await() {} });", |
| 5957 "({ get await() {} });", |
| 5958 "({ set await(x) {} });", |
| 5959 "(class { await() {} });", |
| 5960 "(class { static await() {} });", |
| 5961 "(class { *await() {} });", |
| 5962 "(class { static *await() {} });" |
| 5963 }; |
| 5964 // clang-format on |
| 5965 |
| 5966 i::Isolate* isolate = CcTest::i_isolate(); |
| 5967 i::Factory* factory = isolate->factory(); |
| 5968 |
| 5969 v8::HandleScope handles(CcTest::isolate()); |
| 5970 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5971 v8::Context::Scope context_scope(context); |
| 5972 |
| 5973 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5974 128 * 1024); |
| 5975 |
| 5976 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 5977 i::Handle<i::String> source = |
| 5978 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 5979 |
| 5980 i::Handle<i::Script> script = factory->NewScript(source); |
| 5981 i::Zone zone; |
| 5982 i::ParseInfo info(&zone, script); |
| 5983 i::Parser parser(&info); |
| 5984 info.set_module(); |
| 5985 CHECK(parser.Parse(&info)); |
| 5986 } |
| 5987 } |
| 5988 |
| 5989 TEST(EnumReserved) { |
| 5990 i::FLAG_harmony_modules = true; |
| 5991 |
| 5992 // clang-format off |
| 5993 const char* kErrorSources[] = { |
| 5994 "enum;", |
| 5995 "enum: ;", |
| 5996 "var enum;", |
| 5997 "var [enum] = [];", |
| 5998 "var { enum } = {};", |
| 5999 "var { x: enum } = {};", |
| 6000 "{ var enum; }", |
| 6001 "let enum;", |
| 6002 "let [enum] = [];", |
| 6003 "let { enum } = {};", |
| 6004 "let { x: enum } = {};", |
| 6005 "{ let enum; }", |
| 6006 "const enum = null;", |
| 6007 "const [enum] = [];", |
| 6008 "const { enum } = {};", |
| 6009 "const { x: enum } = {};", |
| 6010 "{ const enum = null; }", |
| 6011 "function enum() {}", |
| 6012 "function f(enum) {}", |
| 6013 "function* enum() {}", |
| 6014 "function* g(enum) {}", |
| 6015 "(function enum() {});", |
| 6016 "(function (enum) {});", |
| 6017 "(function* enum() {});", |
| 6018 "(function* (enum) {});", |
| 6019 "(enum) => {};", |
| 6020 "enum => {};", |
| 6021 "class enum {}", |
| 6022 "class C { constructor(enum) {} }", |
| 6023 "class C { m(enum) {} }", |
| 6024 "class C { static m(enum) {} }", |
| 6025 "class C { *m(enum) {} }", |
| 6026 "class C { static *m(enum) {} }", |
| 6027 "(class enum {})", |
| 6028 "(class { constructor(enum) {} });", |
| 6029 "(class { m(enum) {} });", |
| 6030 "(class { static m(enum) {} });", |
| 6031 "(class { *m(enum) {} });", |
| 6032 "(class { static *m(enum) {} });", |
| 6033 "({ m(enum) {} });", |
| 6034 "({ *m(enum) {} });", |
| 6035 "({ set p(enum) {} });", |
| 6036 "try {} catch (enum) {}", |
| 6037 "try {} catch (enum) {} finally {}" |
| 6038 }; |
| 6039 |
| 6040 i::Isolate* isolate = CcTest::i_isolate(); |
| 6041 i::Factory* factory = isolate->factory(); |
| 6042 |
| 6043 v8::HandleScope handles(CcTest::isolate()); |
| 6044 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 6045 v8::Context::Scope context_scope(context); |
| 6046 |
| 6047 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 6048 128 * 1024); |
| 6049 |
| 6050 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 6051 i::Handle<i::String> source = |
| 6052 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 6053 |
| 6054 i::Handle<i::Script> script = factory->NewScript(source); |
| 6055 i::Zone zone; |
| 6056 i::ParseInfo info(&zone, script); |
| 6057 i::Parser parser(&info); |
| 6058 info.set_module(); |
| 6059 CHECK(!parser.Parse(&info)); |
| 6060 } |
| 6061 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
| 6062 i::Handle<i::String> source = |
| 6063 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
| 6064 |
| 6065 i::Handle<i::Script> script = factory->NewScript(source); |
| 6066 i::Zone zone; |
| 6067 i::ParseInfo info(&zone, script); |
| 6068 i::Parser parser(&info); |
| 6069 CHECK(!parser.Parse(&info)); |
| 6070 } |
| 6071 } |
| 6072 |
5860 | 6073 |
5861 TEST(ModuleParsingInternals) { | 6074 TEST(ModuleParsingInternals) { |
5862 i::FLAG_harmony_modules = true; | 6075 i::FLAG_harmony_modules = true; |
5863 | 6076 |
5864 i::Isolate* isolate = CcTest::i_isolate(); | 6077 i::Isolate* isolate = CcTest::i_isolate(); |
5865 i::Factory* factory = isolate->factory(); | 6078 i::Factory* factory = isolate->factory(); |
5866 v8::HandleScope handles(CcTest::isolate()); | 6079 v8::HandleScope handles(CcTest::isolate()); |
5867 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 6080 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
5868 v8::Context::Scope context_scope(context); | 6081 v8::Context::Scope context_scope(context); |
5869 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 6082 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
(...skipping 2111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7981 { NULL, NULL } | 8194 { NULL, NULL } |
7982 }; | 8195 }; |
7983 const char* error_data[] = { | 8196 const char* error_data[] = { |
7984 "var x = new.target", | 8197 "var x = new.target", |
7985 "function f() { return new.t\\u0061rget; }", | 8198 "function f() { return new.t\\u0061rget; }", |
7986 NULL | 8199 NULL |
7987 }; | 8200 }; |
7988 // clang-format on | 8201 // clang-format on |
7989 RunParserSyncTest(context_data, error_data, kError); | 8202 RunParserSyncTest(context_data, error_data, kError); |
7990 } | 8203 } |
OLD | NEW |