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

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

Issue 1589173002: [modules] Support parsing anonymous default exports (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add negative generator test Created 4 years, 11 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
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5521 matching lines...) Expand 10 before | Expand all | Expand 10 after
5532 kAllowHarmonySloppy, 5532 kAllowHarmonySloppy,
5533 }; 5533 };
5534 RunParserSyncTest(context_data, error_data, kError, NULL, 0, 5534 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
5535 always_flags, arraysize(always_flags)); 5535 always_flags, arraysize(always_flags));
5536 } 5536 }
5537 5537
5538 5538
5539 TEST(BasicImportExportParsing) { 5539 TEST(BasicImportExportParsing) {
5540 i::FLAG_harmony_modules = true; 5540 i::FLAG_harmony_modules = true;
5541 5541
5542 // clang-format off
5542 const char* kSources[] = { 5543 const char* kSources[] = {
5543 "export let x = 0;", 5544 "export let x = 0;",
5544 "export var y = 0;", 5545 "export var y = 0;",
5545 "export const z = 0;", 5546 "export const z = 0;",
5546 "export function func() { };", 5547 "export function func() { };",
5547 "export class C { };", 5548 "export class C { };",
5548 "export { };", 5549 "export { };",
5549 "function f() {}; f(); export { f };", 5550 "function f() {}; f(); export { f };",
5550 "var a, b, c; export { a, b as baz, c };", 5551 "var a, b, c; export { a, b as baz, c };",
5551 "var d, e; export { d as dreary, e, };", 5552 "var d, e; export { d as dreary, e, };",
5552 "export default function f() {}", 5553 "export default function f() {}",
5554 "export default function() {}",
5555 "export default function*() {}",
5553 "export default class C {}", 5556 "export default class C {}",
5557 "export default class {}"
5558 "export default class extends C {}"
5554 "export default 42", 5559 "export default 42",
5555 "var x; export default x = 7", 5560 "var x; export default x = 7",
5556 "export { Q } from 'somemodule.js';", 5561 "export { Q } from 'somemodule.js';",
5557 "export * from 'somemodule.js';", 5562 "export * from 'somemodule.js';",
5558 "var foo; export { foo as for };", 5563 "var foo; export { foo as for };",
5559 "export { arguments } from 'm.js';", 5564 "export { arguments } from 'm.js';",
5560 "export { for } from 'm.js';", 5565 "export { for } from 'm.js';",
5561 "export { yield } from 'm.js'", 5566 "export { yield } from 'm.js'",
5562 "export { static } from 'm.js'", 5567 "export { static } from 'm.js'",
5563 "export { let } from 'm.js'", 5568 "export { let } from 'm.js'",
5564 "var a; export { a as b, a as c };", 5569 "var a; export { a as b, a as c };",
5565 5570
5566 "import 'somemodule.js';", 5571 "import 'somemodule.js';",
5567 "import { } from 'm.js';", 5572 "import { } from 'm.js';",
5568 "import { a } from 'm.js';", 5573 "import { a } from 'm.js';",
5569 "import { a, b as d, c, } from 'm.js';", 5574 "import { a, b as d, c, } from 'm.js';",
5570 "import * as thing from 'm.js';", 5575 "import * as thing from 'm.js';",
5571 "import thing from 'm.js';", 5576 "import thing from 'm.js';",
5572 "import thing, * as rest from 'm.js';", 5577 "import thing, * as rest from 'm.js';",
5573 "import thing, { a, b, c } from 'm.js';", 5578 "import thing, { a, b, c } from 'm.js';",
5574 "import { arguments as a } from 'm.js';", 5579 "import { arguments as a } from 'm.js';",
5575 "import { for as f } from 'm.js';", 5580 "import { for as f } from 'm.js';",
5576 "import { yield as y } from 'm.js';", 5581 "import { yield as y } from 'm.js';",
5577 "import { static as s } from 'm.js';", 5582 "import { static as s } from 'm.js';",
5578 "import { let as l } from 'm.js';", 5583 "import { let as l } from 'm.js';",
5579 }; 5584 };
5585 // clang-format on
5580 5586
5581 i::Isolate* isolate = CcTest::i_isolate(); 5587 i::Isolate* isolate = CcTest::i_isolate();
5582 i::Factory* factory = isolate->factory(); 5588 i::Factory* factory = isolate->factory();
5583 5589
5584 v8::HandleScope handles(CcTest::isolate()); 5590 v8::HandleScope handles(CcTest::isolate());
5585 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5591 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5586 v8::Context::Scope context_scope(context); 5592 v8::Context::Scope context_scope(context);
5587 5593
5588 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5594 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5589 128 * 1024); 5595 128 * 1024);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5626 info.set_global(); 5632 info.set_global();
5627 CHECK(!parser.Parse(&info)); 5633 CHECK(!parser.Parse(&info));
5628 } 5634 }
5629 } 5635 }
5630 } 5636 }
5631 5637
5632 5638
5633 TEST(ImportExportParsingErrors) { 5639 TEST(ImportExportParsingErrors) {
5634 i::FLAG_harmony_modules = true; 5640 i::FLAG_harmony_modules = true;
5635 5641
5642 // clang-format off
5636 const char* kErrorSources[] = { 5643 const char* kErrorSources[] = {
5637 "export {", 5644 "export {",
5638 "var a; export { a", 5645 "var a; export { a",
5639 "var a; export { a,", 5646 "var a; export { a,",
5640 "var a; export { a, ;", 5647 "var a; export { a, ;",
5641 "var a; export { a as };", 5648 "var a; export { a as };",
5642 "var a, b; export { a as , b};", 5649 "var a, b; export { a as , b};",
5643 "export }", 5650 "export }",
5644 "var foo, bar; export { foo bar };", 5651 "var foo, bar; export { foo bar };",
5645 "export { foo };", 5652 "export { foo };",
5646 "export { , };", 5653 "export { , };",
5647 "export default;", 5654 "export default;",
5648 "export default var x = 7;", 5655 "export default var x = 7;",
5649 "export default let x = 7;", 5656 "export default let x = 7;",
5650 "export default const x = 7;", 5657 "export default const x = 7;",
5651 "export *;", 5658 "export *;",
5652 "export * from;", 5659 "export * from;",
5653 "export { Q } from;", 5660 "export { Q } from;",
5654 "export default from 'module.js';", 5661 "export default from 'module.js';",
5655 "export { for }", 5662 "export { for }",
5656 "export { for as foo }", 5663 "export { for as foo }",
5657 "export { arguments }", 5664 "export { arguments }",
5658 "export { arguments as foo }", 5665 "export { arguments as foo }",
5659 "var a; export { a, a };", 5666 "var a; export { a, a };",
5660 "var a, b; export { a as b, b };", 5667 "var a, b; export { a as b, b };",
5661 "var a, b; export { a as c, b as c };", 5668 "var a, b; export { a as c, b as c };",
5662 "export default function f(){}; export default class C {};", 5669 "export default function f(){}; export default class C {};",
5663 "export default function f(){}; var a; export { a as default };", 5670 "export default function f(){}; var a; export { a as default };",
5671 "export function() {}",
5672 "export function*() {}",
5673 "export class {}",
5674 "export class extends C {}",
5664 5675
5665 "import from;", 5676 "import from;",
5666 "import from 'm.js';", 5677 "import from 'm.js';",
5667 "import { };", 5678 "import { };",
5668 "import {;", 5679 "import {;",
5669 "import };", 5680 "import };",
5670 "import { , };", 5681 "import { , };",
5671 "import { , } from 'm.js';", 5682 "import { , } from 'm.js';",
5672 "import { a } from;", 5683 "import { a } from;",
5673 "import { a } 'm.js';", 5684 "import { a } 'm.js';",
5674 "import , from 'm.js';", 5685 "import , from 'm.js';",
5675 "import a , from 'm.js';", 5686 "import a , from 'm.js';",
5676 "import a { b, c } from 'm.js';", 5687 "import a { b, c } from 'm.js';",
5677 "import arguments from 'm.js';", 5688 "import arguments from 'm.js';",
5678 "import eval from 'm.js';", 5689 "import eval from 'm.js';",
5679 "import { arguments } from 'm.js';", 5690 "import { arguments } from 'm.js';",
5680 "import { eval } from 'm.js';", 5691 "import { eval } from 'm.js';",
5681 "import { a as arguments } from 'm.js';", 5692 "import { a as arguments } from 'm.js';",
5682 "import { for } from 'm.js';", 5693 "import { for } from 'm.js';",
5683 "import { y as yield } from 'm.js'", 5694 "import { y as yield } from 'm.js'",
5684 "import { s as static } from 'm.js'", 5695 "import { s as static } from 'm.js'",
5685 "import { l as let } from 'm.js'", 5696 "import { l as let } from 'm.js'",
5686 "import { x }, def from 'm.js';", 5697 "import { x }, def from 'm.js';",
5687 "import def, def2 from 'm.js';", 5698 "import def, def2 from 'm.js';",
5688 "import * as x, def from 'm.js';", 5699 "import * as x, def from 'm.js';",
5689 "import * as x, * as y from 'm.js';", 5700 "import * as x, * as y from 'm.js';",
5690 "import {x}, {y} from 'm.js';", 5701 "import {x}, {y} from 'm.js';",
5691 "import * as x, {y} from 'm.js';", 5702 "import * as x, {y} from 'm.js';",
5692
5693 // TODO(ES6): These two forms should be supported
5694 "export default function() {};",
5695 "export default class {};"
5696 }; 5703 };
5704 // clang-format on
5697 5705
5698 i::Isolate* isolate = CcTest::i_isolate(); 5706 i::Isolate* isolate = CcTest::i_isolate();
5699 i::Factory* factory = isolate->factory(); 5707 i::Factory* factory = isolate->factory();
5700 5708
5701 v8::HandleScope handles(CcTest::isolate()); 5709 v8::HandleScope handles(CcTest::isolate());
5702 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5710 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5703 v8::Context::Scope context_scope(context); 5711 v8::Context::Scope context_scope(context);
5704 5712
5705 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5713 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5706 128 * 1024); 5714 128 * 1024);
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after
7830 } 7838 }
7831 7839
7832 7840
7833 TEST(MiscSyntaxErrors) { 7841 TEST(MiscSyntaxErrors) {
7834 const char* context_data[][2] = { 7842 const char* context_data[][2] = {
7835 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; 7843 {"'use strict'", ""}, {"", ""}, {NULL, NULL}};
7836 const char* error_data[] = {"for (();;) {}", NULL}; 7844 const char* error_data[] = {"for (();;) {}", NULL};
7837 7845
7838 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); 7846 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0);
7839 } 7847 }
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698