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

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

Issue 882893002: Implement ParseExportDeclaration per latest ES6 spec draft (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 4653 matching lines...) Expand 10 before | Expand all | Expand 10 after
4664 kAllowHarmonyComputedPropertyNames, 4664 kAllowHarmonyComputedPropertyNames,
4665 kAllowHarmonyObjectLiterals, 4665 kAllowHarmonyObjectLiterals,
4666 kAllowHarmonySloppy, 4666 kAllowHarmonySloppy,
4667 }; 4667 };
4668 RunParserSyncTest(context_data, error_data, kError, NULL, 0, 4668 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
4669 always_flags, arraysize(always_flags)); 4669 always_flags, arraysize(always_flags));
4670 } 4670 }
4671 4671
4672 4672
4673 TEST(BasicImportExportParsing) { 4673 TEST(BasicImportExportParsing) {
4674 const char kSource[] = 4674 const char* kSources[] = {
4675 "export let x = 0;" 4675 "export let x = 0;",
4676 "import y from 'http://module.com/foo.js';" 4676 "export var y = 0;",
adamk 2015/01/28 00:01:54 These lists of strings aren't supported by 'git cl
4677 "function f() {};" 4677 "export const z = 0;",
4678 "f();"; 4678 "export function func() { };",
4679 "export class C { };",
4680 "export { };",
4681 "function f() {}; f(); export { f };",
4682 "var a, b, c; export { a, b as baz, c };",
4683 "var d, e; export { d as dreary, e, };",
4684 "import y from 'http://module.com/foo.js';",
4685 "export default function f() {}",
4686 "export default class C {}",
4687 "export default 42",
4688 "var x; export default x = 7",
4689 "export { Q } from 'somemodule.js';",
4690 "export * from 'somemodule.js';"
4691 };
4679 4692
4680 i::Isolate* isolate = CcTest::i_isolate(); 4693 i::Isolate* isolate = CcTest::i_isolate();
4681 i::Factory* factory = isolate->factory(); 4694 i::Factory* factory = isolate->factory();
4682 4695
4683 v8::HandleScope handles(CcTest::isolate()); 4696 v8::HandleScope handles(CcTest::isolate());
4684 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 4697 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
4685 v8::Context::Scope context_scope(context); 4698 v8::Context::Scope context_scope(context);
4686 4699
4687 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 4700 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
4688 128 * 1024); 4701 128 * 1024);
4689 4702
4690 int kProgramByteSize = i::StrLength(kSource); 4703 for (unsigned i = 0; i < arraysize(kSources); ++i) {
4691 i::ScopedVector<char> program(kProgramByteSize + 1); 4704 int kProgramByteSize = i::StrLength(kSources[i]);
4692 i::SNPrintF(program, "%s", kSource); 4705 i::ScopedVector<char> program(kProgramByteSize + 1);
4693 i::Handle<i::String> source = 4706 i::SNPrintF(program, "%s", kSources[i]);
4707 i::Handle<i::String> source =
4694 factory->NewStringFromUtf8(i::CStrVector(program.start())) 4708 factory->NewStringFromUtf8(i::CStrVector(program.start()))
4695 .ToHandleChecked(); 4709 .ToHandleChecked();
4696 4710
4697 // Show that parsing as a module works 4711 // Show that parsing as a module works
4698 { 4712 {
4713 i::Handle<i::Script> script = factory->NewScript(source);
4714 i::CompilationInfoWithZone info(script);
4715 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4716 isolate->heap()->HashSeed(),
4717 isolate->unicode_cache()};
4718 i::Parser parser(&info, &parse_info);
4719 parser.set_allow_harmony_classes(true);
4720 parser.set_allow_harmony_modules(true);
4721 parser.set_allow_harmony_scoping(true);
4722 info.MarkAsModule();
4723 CHECK(parser.Parse());
4724 }
4725
4726 // And that parsing a script does not.
4727 {
4728 i::Handle<i::Script> script = factory->NewScript(source);
4729 i::CompilationInfoWithZone info(script);
4730 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4731 isolate->heap()->HashSeed(),
4732 isolate->unicode_cache()};
4733 i::Parser parser(&info, &parse_info);
4734 parser.set_allow_harmony_classes(true);
4735 parser.set_allow_harmony_modules(true);
4736 parser.set_allow_harmony_scoping(true);
4737 info.MarkAsGlobal();
4738 CHECK(!parser.Parse());
4739 }
4740 }
4741 }
4742
4743
4744 TEST(ImportExportParsingErrors) {
4745 const char* kErrorSources[] = {
4746 "export {",
4747 "var a; export { a",
arv (Not doing code reviews) 2015/01/28 02:57:19 Add test for `export {,}`?
adamk 2015/01/28 18:05:04 Done.
4748 "var a; export { a,",
4749 "var a; export { a, ;",
4750 "var a; export { a as };",
4751 "var a, b; export { a as , b};",
4752 "export }",
4753 "var foo, bar; export { foo bar };",
4754 "export { foo };",
4755 "export default;",
4756 "export default var x = 7;",
4757 "export default let x = 7;",
4758 "export default const x = 7;",
4759 "export *;",
4760 "export * from;",
4761 "export { Q } from;"
4762 "export default from 'module.js';"
4763 };
4764
4765 i::Isolate* isolate = CcTest::i_isolate();
4766 i::Factory* factory = isolate->factory();
4767
4768 v8::HandleScope handles(CcTest::isolate());
4769 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
4770 v8::Context::Scope context_scope(context);
4771
4772 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
4773 128 * 1024);
4774
4775 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
4776 int kProgramByteSize = i::StrLength(kErrorSources[i]);
4777 i::ScopedVector<char> program(kProgramByteSize + 1);
4778 i::SNPrintF(program, "%s", kErrorSources[i]);
4779 i::Handle<i::String> source =
4780 factory->NewStringFromUtf8(i::CStrVector(program.start()))
4781 .ToHandleChecked();
4782
4699 i::Handle<i::Script> script = factory->NewScript(source); 4783 i::Handle<i::Script> script = factory->NewScript(source);
4700 i::CompilationInfoWithZone info(script); 4784 i::CompilationInfoWithZone info(script);
4701 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 4785 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4702 isolate->heap()->HashSeed(), 4786 isolate->heap()->HashSeed(),
4703 isolate->unicode_cache()}; 4787 isolate->unicode_cache()};
4704 i::Parser parser(&info, &parse_info); 4788 i::Parser parser(&info, &parse_info);
4789 parser.set_allow_harmony_classes(true);
4705 parser.set_allow_harmony_modules(true); 4790 parser.set_allow_harmony_modules(true);
4706 parser.set_allow_harmony_scoping(true); 4791 parser.set_allow_harmony_scoping(true);
4707 info.MarkAsModule(); 4792 info.MarkAsModule();
4708 CHECK(parser.Parse());
4709 }
4710
4711 // And that parsing a script does not.
4712 {
4713 i::Handle<i::Script> script = factory->NewScript(source);
4714 i::CompilationInfoWithZone info(script);
4715 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4716 isolate->heap()->HashSeed(),
4717 isolate->unicode_cache()};
4718 i::Parser parser(&info, &parse_info);
4719 parser.set_allow_harmony_modules(true);
4720 parser.set_allow_harmony_scoping(true);
4721 info.MarkAsGlobal();
4722 CHECK(!parser.Parse()); 4793 CHECK(!parser.Parse());
4723 } 4794 }
4724 } 4795 }
OLDNEW
« src/parser.cc ('K') | « src/parser.cc ('k') | test/mjsunit/harmony/module-parsing.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698