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

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

Issue 2199283002: [modules] Introduce new VariableLocation for module imports/exports. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comment Created 4 years, 4 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 5910 matching lines...) Expand 10 before | Expand all | Expand 10 after
5921 "export { x as y };" 5921 "export { x as y };"
5922 "import { q as z } from 'm.js';" 5922 "import { q as z } from 'm.js';"
5923 "import n from 'n.js';" 5923 "import n from 'n.js';"
5924 "export { a as b } from 'm.js';" 5924 "export { a as b } from 'm.js';"
5925 "export * from 'p.js';" 5925 "export * from 'p.js';"
5926 "export var foo;" 5926 "export var foo;"
5927 "export function goo() {};" 5927 "export function goo() {};"
5928 "export let hoo;" 5928 "export let hoo;"
5929 "export const joo = 42;" 5929 "export const joo = 42;"
5930 "export default (function koo() {});" 5930 "export default (function koo() {});"
5931 "import 'q.js'"; 5931 "import 'q.js';"
5932 "let nonexport = 42;"
5933 "import {m as mm} from 'm.js';"
5934 "import {aa} from 'm.js';"
5935 "export {aa as bb, x};"
5936 "import * as loo from 'bar.js';"
5937 "import * as foob from 'bar.js';"
5938 "export {foob};";
5932 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5939 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5933 i::Handle<i::Script> script = factory->NewScript(source); 5940 i::Handle<i::Script> script = factory->NewScript(source);
5934 i::Zone zone(CcTest::i_isolate()->allocator()); 5941 i::Zone zone(CcTest::i_isolate()->allocator());
5935 i::ParseInfo info(&zone, script); 5942 i::ParseInfo info(&zone, script);
5936 i::Parser parser(&info); 5943 i::Parser parser(&info);
5937 info.set_module(); 5944 info.set_module();
5938 CHECK(parser.Parse(&info)); 5945 CHECK(parser.Parse(&info));
5939 CHECK(i::Compiler::Analyze(&info)); 5946 CHECK(i::Compiler::Analyze(&info));
5940 i::FunctionLiteral* func = info.literal(); 5947 i::FunctionLiteral* func = info.literal();
5941 i::Scope* module_scope = func->scope(); 5948 i::Scope* module_scope = func->scope();
5942 i::Scope* outer_scope = module_scope->outer_scope(); 5949 i::Scope* outer_scope = module_scope->outer_scope();
5943 CHECK(outer_scope->is_script_scope()); 5950 CHECK(outer_scope->is_script_scope());
5944 CHECK_NULL(outer_scope->outer_scope()); 5951 CHECK_NULL(outer_scope->outer_scope());
5945 CHECK(module_scope->is_module_scope()); 5952 CHECK(module_scope->is_module_scope());
5953 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5954
5955 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5956 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET);
5957 CHECK(declarations->at(0)->proxy()->var()->location() ==
5958 i::VariableLocation::MODULE);
5959
5960 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
5961 CHECK(declarations->at(1)->proxy()->var()->mode() == i::CONST);
5962 CHECK(declarations->at(1)->proxy()->var()->location() ==
5963 i::VariableLocation::MODULE);
5964
5965 CHECK(declarations->at(2)->proxy()->raw_name()->IsOneByteEqualTo("n"));
5966 CHECK(declarations->at(2)->proxy()->var()->mode() == i::CONST);
5967 CHECK(declarations->at(2)->proxy()->var()->location() ==
5968 i::VariableLocation::MODULE);
5969
5970 CHECK(declarations->at(3)->proxy()->raw_name()->IsOneByteEqualTo("foo"));
5971 CHECK(declarations->at(3)->proxy()->var()->mode() == i::VAR);
5972 CHECK(declarations->at(3)->proxy()->var()->location() ==
5973 i::VariableLocation::MODULE);
5974
5975 CHECK(declarations->at(4)->proxy()->raw_name()->IsOneByteEqualTo("goo"));
5976 CHECK(declarations->at(4)->proxy()->var()->mode() == i::LET);
5977 CHECK(declarations->at(4)->proxy()->var()->location() ==
5978 i::VariableLocation::MODULE);
5979
5980 CHECK(declarations->at(5)->proxy()->raw_name()->IsOneByteEqualTo("hoo"));
5981 CHECK(declarations->at(5)->proxy()->var()->mode() == i::LET);
5982 CHECK(declarations->at(5)->proxy()->var()->location() ==
5983 i::VariableLocation::MODULE);
5984
5985 CHECK(declarations->at(6)->proxy()->raw_name()->IsOneByteEqualTo("joo"));
5986 CHECK(declarations->at(6)->proxy()->var()->mode() == i::CONST);
5987 CHECK(declarations->at(6)->proxy()->var()->location() ==
5988 i::VariableLocation::MODULE);
5989
5990 CHECK(
5991 declarations->at(7)->proxy()->raw_name()->IsOneByteEqualTo("*default*"));
5992 CHECK(declarations->at(7)->proxy()->var()->mode() == i::CONST);
5993 CHECK(declarations->at(7)->proxy()->var()->location() ==
5994 i::VariableLocation::MODULE);
5995
5996 CHECK(
5997 declarations->at(8)->proxy()->raw_name()->IsOneByteEqualTo("nonexport"));
5998 CHECK(declarations->at(8)->proxy()->var()->location() !=
5999 i::VariableLocation::MODULE);
6000
6001 CHECK(declarations->at(9)->proxy()->raw_name()->IsOneByteEqualTo("mm"));
6002 CHECK(declarations->at(9)->proxy()->var()->mode() == i::CONST);
6003 CHECK(declarations->at(9)->proxy()->var()->location() ==
6004 i::VariableLocation::MODULE);
6005
6006 CHECK(declarations->at(10)->proxy()->raw_name()->IsOneByteEqualTo("aa"));
6007 CHECK(declarations->at(10)->proxy()->var()->mode() == i::CONST);
6008 CHECK(declarations->at(10)->proxy()->var()->location() ==
6009 i::VariableLocation::MODULE);
6010
6011 CHECK(declarations->at(11)->proxy()->raw_name()->IsOneByteEqualTo("loo"));
6012 CHECK(declarations->at(11)->proxy()->var()->mode() == i::CONST);
6013 CHECK(declarations->at(11)->proxy()->var()->location() !=
6014 i::VariableLocation::MODULE);
6015
6016 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob"));
6017 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST);
6018 CHECK(declarations->at(12)->proxy()->var()->location() ==
6019 i::VariableLocation::MODULE);
6020
6021 CHECK_EQ(13, declarations->length());
6022
5946 i::ModuleDescriptor* descriptor = module_scope->module(); 6023 i::ModuleDescriptor* descriptor = module_scope->module();
5947 CHECK_NOT_NULL(descriptor); 6024 CHECK_NOT_NULL(descriptor);
5948 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5949 CHECK_EQ(8, declarations->length());
5950 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5951 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
5952 CHECK(declarations->at(2)->proxy()->raw_name()->IsOneByteEqualTo("n"));
5953 CHECK(declarations->at(3)->proxy()->raw_name()->IsOneByteEqualTo("foo"));
5954 CHECK(declarations->at(4)->proxy()->raw_name()->IsOneByteEqualTo("goo"));
5955 CHECK(declarations->at(5)->proxy()->raw_name()->IsOneByteEqualTo("hoo"));
5956 CHECK(declarations->at(6)->proxy()->raw_name()->IsOneByteEqualTo("joo"));
5957 CHECK(
5958 declarations->at(7)->proxy()->raw_name()->IsOneByteEqualTo("*default*"));
5959 // TODO(neis): Test more once we can inspect the imports/exports. 6025 // TODO(neis): Test more once we can inspect the imports/exports.
5960 } 6026 }
5961 6027
5962 6028
5963 TEST(DuplicateProtoError) { 6029 TEST(DuplicateProtoError) {
5964 const char* context_data[][2] = { 6030 const char* context_data[][2] = {
5965 {"({", "});"}, 6031 {"({", "});"},
5966 {"'use strict'; ({", "});"}, 6032 {"'use strict'; ({", "});"},
5967 {NULL, NULL} 6033 {NULL, NULL}
5968 }; 6034 };
(...skipping 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after
7986 "(a,);", 8052 "(a,);",
7987 "(a,b,c,);", 8053 "(a,b,c,);",
7988 NULL 8054 NULL
7989 }; 8055 };
7990 // clang-format on 8056 // clang-format on
7991 8057
7992 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8058 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
7993 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8059 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7994 arraysize(always_flags)); 8060 arraysize(always_flags));
7995 } 8061 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698