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 4650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4661 | 4661 |
4662 static const ParserFlag always_flags[] = { | 4662 static const ParserFlag always_flags[] = { |
4663 kAllowHarmonyClasses, | 4663 kAllowHarmonyClasses, |
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 | |
4672 | |
4673 TEST(BasicImportExportParsing) { | |
4674 const char kSource[] = | |
4675 "export let x = 0;" | |
4676 "import y from 'http://module.com/foo.js';" | |
4677 "function f() {};" | |
4678 "f();"; | |
4679 | |
4680 i::Isolate* isolate = CcTest::i_isolate(); | |
4681 i::Factory* factory = isolate->factory(); | |
4682 | |
4683 v8::HandleScope handles(CcTest::isolate()); | |
4684 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | |
4685 v8::Context::Scope context_scope(context); | |
4686 | |
4687 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | |
4688 128 * 1024); | |
4689 | |
4690 int kProgramByteSize = i::StrLength(kSource); | |
4691 i::ScopedVector<char> program(kProgramByteSize + 1); | |
4692 i::SNPrintF(program, "%s", kSource); | |
4693 i::Handle<i::String> source = | |
4694 factory->NewStringFromUtf8(i::CStrVector(program.start())) | |
4695 .ToHandleChecked(); | |
4696 | |
4697 // Show that parsing as a module works | |
4698 { | |
4699 i::Handle<i::Script> script = factory->NewScript(source); | |
4700 i::CompilationInfoWithZone info(script); | |
4701 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | |
4702 isolate->heap()->HashSeed(), | |
4703 isolate->unicode_cache()}; | |
4704 i::Parser parser(&info, &parse_info); | |
4705 parser.set_allow_harmony_modules(true); | |
4706 parser.set_allow_harmony_scoping(true); | |
4707 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()); | |
arv (Not doing code reviews)
2015/01/27 01:17:17
Would it not be cleaner if we added ParseScript an
adamk
2015/01/27 01:58:37
This was extracted from a branch where I had the w
rossberg
2015/01/27 20:00:56
I don't think we have a separate ParseEval either,
| |
4723 } | |
4724 } | |
OLD | NEW |