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 4663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4674 const char* kSources[] = { | 4674 const char* kSources[] = { |
4675 "export let x = 0;", | 4675 "export let x = 0;", |
4676 "export var y = 0;", | 4676 "export var y = 0;", |
4677 "export const z = 0;", | 4677 "export const z = 0;", |
4678 "export function func() { };", | 4678 "export function func() { };", |
4679 "export class C { };", | 4679 "export class C { };", |
4680 "export { };", | 4680 "export { };", |
4681 "function f() {}; f(); export { f };", | 4681 "function f() {}; f(); export { f };", |
4682 "var a, b, c; export { a, b as baz, c };", | 4682 "var a, b, c; export { a, b as baz, c };", |
4683 "var d, e; export { d as dreary, e, };", | 4683 "var d, e; export { d as dreary, e, };", |
4684 "import y from 'http://module.com/foo.js';", | |
4685 "export default function f() {}", | 4684 "export default function f() {}", |
4686 "export default class C {}", | 4685 "export default class C {}", |
4687 "export default 42", | 4686 "export default 42", |
4688 "var x; export default x = 7", | 4687 "var x; export default x = 7", |
4689 "export { Q } from 'somemodule.js';", | 4688 "export { Q } from 'somemodule.js';", |
4690 "export * from 'somemodule.js';" | 4689 "export * from 'somemodule.js';", |
| 4690 "var foo; export { foo as for };", |
| 4691 "export { arguments } from 'm.js';", |
| 4692 "export { for } from 'm.js';", |
| 4693 "export { yield } from 'm.js'", |
| 4694 "export { static } from 'm.js'", |
| 4695 "export { let } from 'm.js'", |
| 4696 |
| 4697 "import 'somemodule.js';", |
| 4698 "import { } from 'm.js';", |
| 4699 "import { a } from 'm.js';", |
| 4700 "import { a, b as d, c, } from 'm.js';", |
| 4701 "import * as thing from 'm.js';", |
| 4702 "import thing from 'm.js';", |
| 4703 "import thing, * as rest from 'm.js';", |
| 4704 "import thing, { a, b, c } from 'm.js';", |
| 4705 "import { arguments as a } from 'm.js';", |
| 4706 "import { for as f } from 'm.js';", |
| 4707 "import { yield as y } from 'm.js';", |
| 4708 "import { static as s } from 'm.js';", |
| 4709 "import { let as l } from 'm.js';", |
4691 }; | 4710 }; |
4692 | 4711 |
4693 i::Isolate* isolate = CcTest::i_isolate(); | 4712 i::Isolate* isolate = CcTest::i_isolate(); |
4694 i::Factory* factory = isolate->factory(); | 4713 i::Factory* factory = isolate->factory(); |
4695 | 4714 |
4696 v8::HandleScope handles(CcTest::isolate()); | 4715 v8::HandleScope handles(CcTest::isolate()); |
4697 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 4716 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
4698 v8::Context::Scope context_scope(context); | 4717 v8::Context::Scope context_scope(context); |
4699 | 4718 |
4700 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 4719 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
(...skipping 12 matching lines...) Expand all Loading... |
4713 i::Handle<i::Script> script = factory->NewScript(source); | 4732 i::Handle<i::Script> script = factory->NewScript(source); |
4714 i::CompilationInfoWithZone info(script); | 4733 i::CompilationInfoWithZone info(script); |
4715 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 4734 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
4716 isolate->heap()->HashSeed(), | 4735 isolate->heap()->HashSeed(), |
4717 isolate->unicode_cache()}; | 4736 isolate->unicode_cache()}; |
4718 i::Parser parser(&info, &parse_info); | 4737 i::Parser parser(&info, &parse_info); |
4719 parser.set_allow_harmony_classes(true); | 4738 parser.set_allow_harmony_classes(true); |
4720 parser.set_allow_harmony_modules(true); | 4739 parser.set_allow_harmony_modules(true); |
4721 parser.set_allow_harmony_scoping(true); | 4740 parser.set_allow_harmony_scoping(true); |
4722 info.MarkAsModule(); | 4741 info.MarkAsModule(); |
4723 CHECK(parser.Parse()); | 4742 if (!parser.Parse()) { |
| 4743 i::Handle<i::JSObject> exception_handle( |
| 4744 i::JSObject::cast(isolate->pending_exception())); |
| 4745 i::Handle<i::String> message_string = |
| 4746 i::Handle<i::String>::cast(i::Object::GetProperty( |
| 4747 isolate, exception_handle, "message").ToHandleChecked()); |
| 4748 |
| 4749 v8::base::OS::Print( |
| 4750 "Parser failed on:\n" |
| 4751 "\t%s\n" |
| 4752 "with error:\n" |
| 4753 "\t%s\n" |
| 4754 "However, we expected no error.", |
| 4755 source->ToCString().get(), message_string->ToCString().get()); |
| 4756 CHECK(false); |
| 4757 } |
4724 } | 4758 } |
4725 | 4759 |
4726 // And that parsing a script does not. | 4760 // And that parsing a script does not. |
4727 { | 4761 { |
4728 i::Handle<i::Script> script = factory->NewScript(source); | 4762 i::Handle<i::Script> script = factory->NewScript(source); |
4729 i::CompilationInfoWithZone info(script); | 4763 i::CompilationInfoWithZone info(script); |
4730 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 4764 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
4731 isolate->heap()->HashSeed(), | 4765 isolate->heap()->HashSeed(), |
4732 isolate->unicode_cache()}; | 4766 isolate->unicode_cache()}; |
4733 i::Parser parser(&info, &parse_info); | 4767 i::Parser parser(&info, &parse_info); |
(...skipping 20 matching lines...) Expand all Loading... |
4754 "export { foo };", | 4788 "export { foo };", |
4755 "export { , };", | 4789 "export { , };", |
4756 "export default;", | 4790 "export default;", |
4757 "export default var x = 7;", | 4791 "export default var x = 7;", |
4758 "export default let x = 7;", | 4792 "export default let x = 7;", |
4759 "export default const x = 7;", | 4793 "export default const x = 7;", |
4760 "export *;", | 4794 "export *;", |
4761 "export * from;", | 4795 "export * from;", |
4762 "export { Q } from;", | 4796 "export { Q } from;", |
4763 "export default from 'module.js';", | 4797 "export default from 'module.js';", |
| 4798 "export { for }", |
| 4799 "export { for as foo }", |
| 4800 "export { arguments }", |
| 4801 "export { arguments as foo }", |
| 4802 |
| 4803 "import from;", |
| 4804 "import from 'm.js';", |
| 4805 "import { };", |
| 4806 "import {;", |
| 4807 "import };", |
| 4808 "import { , };", |
| 4809 "import { , } from 'm.js';", |
| 4810 "import { a } from;", |
| 4811 "import { a } 'm.js';", |
| 4812 "import , from 'm.js';", |
| 4813 "import a , from 'm.js';", |
| 4814 "import a { b, c } from 'm.js';", |
| 4815 "import arguments from 'm.js';", |
| 4816 "import eval from 'm.js';", |
| 4817 "import { arguments } from 'm.js';", |
| 4818 "import { eval } from 'm.js';", |
| 4819 "import { a as arguments } from 'm.js';", |
| 4820 "import { for } from 'm.js';", |
| 4821 "import { y as yield } from 'm.js'", |
| 4822 "import { s as static } from 'm.js'", |
| 4823 "import { l as let } from 'm.js'", |
| 4824 "import { x }, def from 'm.js';", |
| 4825 "import def, def2 from 'm.js';", |
| 4826 "import * as x, def from 'm.js';", |
| 4827 "import * as x, * as y from 'm.js';", |
| 4828 "import {x}, {y} from 'm.js';", |
| 4829 "import * as x, {y} from 'm.js';", |
4764 | 4830 |
4765 // TODO(ES6): These two forms should be supported | 4831 // TODO(ES6): These two forms should be supported |
4766 "export default function() {};", | 4832 "export default function() {};", |
4767 "export default class {};" | 4833 "export default class {};" |
4768 }; | 4834 }; |
4769 | 4835 |
4770 i::Isolate* isolate = CcTest::i_isolate(); | 4836 i::Isolate* isolate = CcTest::i_isolate(); |
4771 i::Factory* factory = isolate->factory(); | 4837 i::Factory* factory = isolate->factory(); |
4772 | 4838 |
4773 v8::HandleScope handles(CcTest::isolate()); | 4839 v8::HandleScope handles(CcTest::isolate()); |
(...skipping 17 matching lines...) Expand all Loading... |
4791 isolate->heap()->HashSeed(), | 4857 isolate->heap()->HashSeed(), |
4792 isolate->unicode_cache()}; | 4858 isolate->unicode_cache()}; |
4793 i::Parser parser(&info, &parse_info); | 4859 i::Parser parser(&info, &parse_info); |
4794 parser.set_allow_harmony_classes(true); | 4860 parser.set_allow_harmony_classes(true); |
4795 parser.set_allow_harmony_modules(true); | 4861 parser.set_allow_harmony_modules(true); |
4796 parser.set_allow_harmony_scoping(true); | 4862 parser.set_allow_harmony_scoping(true); |
4797 info.MarkAsModule(); | 4863 info.MarkAsModule(); |
4798 CHECK(!parser.Parse()); | 4864 CHECK(!parser.Parse()); |
4799 } | 4865 } |
4800 } | 4866 } |
OLD | NEW |