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

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

Issue 2224333002: [modules] Split imports into regular and special, store regular ones in a map. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « src/ast/scopes.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 5937 matching lines...) Expand 10 before | Expand all | Expand 10 after
5948 info.set_module(); 5948 info.set_module();
5949 CHECK(parser.Parse(&info)); 5949 CHECK(parser.Parse(&info));
5950 CHECK(i::Compiler::Analyze(&info)); 5950 CHECK(i::Compiler::Analyze(&info));
5951 i::FunctionLiteral* func = info.literal(); 5951 i::FunctionLiteral* func = info.literal();
5952 i::DeclarationScope* module_scope = func->scope(); 5952 i::DeclarationScope* module_scope = func->scope();
5953 i::Scope* outer_scope = module_scope->outer_scope(); 5953 i::Scope* outer_scope = module_scope->outer_scope();
5954 CHECK(outer_scope->is_script_scope()); 5954 CHECK(outer_scope->is_script_scope());
5955 CHECK_NULL(outer_scope->outer_scope()); 5955 CHECK_NULL(outer_scope->outer_scope());
5956 CHECK(module_scope->is_module_scope()); 5956 CHECK(module_scope->is_module_scope());
5957 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); 5957 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5958 CHECK_EQ(13, declarations->length());
5958 5959
5959 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); 5960 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5960 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET); 5961 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET);
5961 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init()); 5962 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init());
5962 CHECK(declarations->at(0)->proxy()->var()->location() == 5963 CHECK(declarations->at(0)->proxy()->var()->location() ==
5963 i::VariableLocation::MODULE); 5964 i::VariableLocation::MODULE);
5964 5965
5965 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); 5966 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
5966 CHECK(declarations->at(1)->proxy()->var()->mode() == i::CONST); 5967 CHECK(declarations->at(1)->proxy()->var()->mode() == i::CONST);
5967 CHECK(declarations->at(1)->proxy()->var()->binding_needs_init()); 5968 CHECK(declarations->at(1)->proxy()->var()->binding_needs_init());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
6028 CHECK(!declarations->at(11)->proxy()->var()->binding_needs_init()); 6029 CHECK(!declarations->at(11)->proxy()->var()->binding_needs_init());
6029 CHECK(declarations->at(11)->proxy()->var()->location() != 6030 CHECK(declarations->at(11)->proxy()->var()->location() !=
6030 i::VariableLocation::MODULE); 6031 i::VariableLocation::MODULE);
6031 6032
6032 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); 6033 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob"));
6033 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); 6034 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST);
6034 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); 6035 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init());
6035 CHECK(declarations->at(12)->proxy()->var()->location() == 6036 CHECK(declarations->at(12)->proxy()->var()->location() ==
6036 i::VariableLocation::MODULE); 6037 i::VariableLocation::MODULE);
6037 6038
6038 CHECK_EQ(13, declarations->length());
6039
6040 i::ModuleDescriptor* descriptor = module_scope->module(); 6039 i::ModuleDescriptor* descriptor = module_scope->module();
6041 CHECK_NOT_NULL(descriptor); 6040 CHECK_NOT_NULL(descriptor);
6042 // TODO(neis): Test more once we can inspect the imports/exports. 6041
6042 CHECK_EQ(11, descriptor->exports().length());
6043
6044 CHECK(descriptor->exports().at(0)->export_name->IsOneByteEqualTo("y"));
6045 CHECK(descriptor->exports().at(0)->local_name->IsOneByteEqualTo("x"));
6046 CHECK_NULL(descriptor->exports().at(0)->module_request);
6047 CHECK_NULL(descriptor->exports().at(0)->import_name);
6048
6049 CHECK(descriptor->exports().at(1)->export_name->IsOneByteEqualTo("b"));
6050 CHECK(descriptor->exports().at(1)->import_name->IsOneByteEqualTo("a"));
6051 CHECK(descriptor->exports().at(1)->module_request->IsOneByteEqualTo("m.js"));
6052 CHECK_NULL(descriptor->exports().at(1)->local_name);
6053
6054 CHECK(descriptor->exports().at(2)->module_request->IsOneByteEqualTo("p.js"));
6055 CHECK_NULL(descriptor->exports().at(2)->local_name);
6056 CHECK_NULL(descriptor->exports().at(2)->import_name);
6057 CHECK_NULL(descriptor->exports().at(2)->export_name);
6058
6059 CHECK(descriptor->exports().at(3)->export_name->IsOneByteEqualTo("foo"));
6060 CHECK(descriptor->exports().at(3)->local_name->IsOneByteEqualTo("foo"));
6061 CHECK_NULL(descriptor->exports().at(3)->module_request);
6062 CHECK_NULL(descriptor->exports().at(3)->import_name);
6063
6064 CHECK(descriptor->exports().at(4)->export_name->IsOneByteEqualTo("goo"));
6065 CHECK(descriptor->exports().at(4)->local_name->IsOneByteEqualTo("goo"));
6066 CHECK_NULL(descriptor->exports().at(4)->module_request);
6067 CHECK_NULL(descriptor->exports().at(4)->import_name);
6068
6069 CHECK(descriptor->exports().at(5)->export_name->IsOneByteEqualTo("hoo"));
6070 CHECK(descriptor->exports().at(5)->local_name->IsOneByteEqualTo("hoo"));
6071 CHECK_NULL(descriptor->exports().at(5)->module_request);
6072 CHECK_NULL(descriptor->exports().at(5)->import_name);
6073
6074 CHECK(descriptor->exports().at(6)->export_name->IsOneByteEqualTo("joo"));
6075 CHECK(descriptor->exports().at(6)->local_name->IsOneByteEqualTo("joo"));
6076 CHECK_NULL(descriptor->exports().at(6)->module_request);
6077 CHECK_NULL(descriptor->exports().at(6)->import_name);
6078
6079 CHECK(descriptor->exports().at(7)->export_name->IsOneByteEqualTo("default"));
6080 CHECK(descriptor->exports().at(7)->local_name->IsOneByteEqualTo("*default*"));
6081 CHECK_NULL(descriptor->exports().at(7)->module_request);
6082 CHECK_NULL(descriptor->exports().at(7)->import_name);
6083
6084 CHECK(descriptor->exports().at(8)->export_name->IsOneByteEqualTo("bb"));
6085 CHECK(descriptor->exports().at(8)->local_name->IsOneByteEqualTo("aa"));
6086 CHECK_NULL(descriptor->exports().at(8)->module_request);
6087 CHECK_NULL(descriptor->exports().at(8)->import_name);
6088
6089 CHECK(descriptor->exports().at(9)->export_name->IsOneByteEqualTo("x"));
6090 CHECK(descriptor->exports().at(9)->local_name->IsOneByteEqualTo("x"));
6091 CHECK_NULL(descriptor->exports().at(9)->module_request);
6092 CHECK_NULL(descriptor->exports().at(9)->import_name);
6093
6094 CHECK(descriptor->exports().at(10)->export_name->IsOneByteEqualTo("foob"));
6095 CHECK(descriptor->exports().at(10)->local_name->IsOneByteEqualTo("foob"));
6096 CHECK_NULL(descriptor->exports().at(10)->module_request);
6097 CHECK_NULL(descriptor->exports().at(10)->import_name);
6098
6099 CHECK_EQ(3, descriptor->special_imports().length());
6100
6101 CHECK_NULL(descriptor->special_imports().at(0)->local_name);
6102 CHECK_NULL(descriptor->special_imports().at(0)->export_name);
6103 CHECK_NULL(descriptor->special_imports().at(0)->import_name);
6104 CHECK(descriptor->special_imports().at(0)->module_request->IsOneByteEqualTo(
6105 "q.js"));
6106
6107 CHECK(
6108 descriptor->special_imports().at(1)->local_name->IsOneByteEqualTo("loo"));
6109 CHECK_NULL(descriptor->special_imports().at(1)->export_name);
6110 CHECK_NULL(descriptor->special_imports().at(1)->import_name);
6111 CHECK(descriptor->special_imports().at(1)->module_request->IsOneByteEqualTo(
6112 "bar.js"));
6113
6114 CHECK(descriptor->special_imports().at(2)->local_name->IsOneByteEqualTo(
6115 "foob"));
6116 CHECK_NULL(descriptor->special_imports().at(2)->export_name);
6117 CHECK_NULL(descriptor->special_imports().at(2)->import_name);
6118 CHECK(descriptor->special_imports().at(2)->module_request->IsOneByteEqualTo(
6119 "bar.js"));
6120
6121 CHECK_EQ(4, descriptor->regular_imports().size());
6122
6123 CHECK_NULL(descriptor->regular_imports()
6124 .find(declarations->at(1)->proxy()->raw_name())
6125 ->second->export_name);
6126 CHECK(descriptor->regular_imports()
6127 .find(declarations->at(1)->proxy()->raw_name())
6128 ->second->import_name->IsOneByteEqualTo("q"));
6129 CHECK(descriptor->regular_imports()
6130 .find(declarations->at(1)->proxy()->raw_name())
6131 ->second->module_request->IsOneByteEqualTo("m.js"));
6132
6133 CHECK_NULL(descriptor->regular_imports()
6134 .find(declarations->at(2)->proxy()->raw_name())
6135 ->second->export_name);
6136 CHECK(descriptor->regular_imports()
6137 .find(declarations->at(2)->proxy()->raw_name())
6138 ->second->import_name->IsOneByteEqualTo("default"));
6139 CHECK(descriptor->regular_imports()
6140 .find(declarations->at(2)->proxy()->raw_name())
6141 ->second->module_request->IsOneByteEqualTo("n.js"));
6142
6143 CHECK_NULL(descriptor->regular_imports()
6144 .find(declarations->at(9)->proxy()->raw_name())
6145 ->second->export_name);
6146 CHECK(descriptor->regular_imports()
6147 .find(declarations->at(9)->proxy()->raw_name())
6148 ->second->import_name->IsOneByteEqualTo("m"));
6149 CHECK(descriptor->regular_imports()
6150 .find(declarations->at(9)->proxy()->raw_name())
6151 ->second->module_request->IsOneByteEqualTo("m.js"));
6152
6153 CHECK_NULL(descriptor->regular_imports()
6154 .find(declarations->at(10)->proxy()->raw_name())
6155 ->second->export_name);
6156 CHECK(descriptor->regular_imports()
6157 .find(declarations->at(10)->proxy()->raw_name())
6158 ->second->import_name->IsOneByteEqualTo("aa"));
6159 CHECK(descriptor->regular_imports()
6160 .find(declarations->at(10)->proxy()->raw_name())
6161 ->second->module_request->IsOneByteEqualTo("m.js"));
6043 } 6162 }
6044 6163
6045 6164
6046 TEST(DuplicateProtoError) { 6165 TEST(DuplicateProtoError) {
6047 const char* context_data[][2] = { 6166 const char* context_data[][2] = {
6048 {"({", "});"}, 6167 {"({", "});"},
6049 {"'use strict'; ({", "});"}, 6168 {"'use strict'; ({", "});"},
6050 {NULL, NULL} 6169 {NULL, NULL}
6051 }; 6170 };
6052 const char* error_data[] = { 6171 const char* error_data[] = {
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after
8063 "(a,);", 8182 "(a,);",
8064 "(a,b,c,);", 8183 "(a,b,c,);",
8065 NULL 8184 NULL
8066 }; 8185 };
8067 // clang-format on 8186 // clang-format on
8068 8187
8069 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8188 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
8070 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8189 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
8071 arraysize(always_flags)); 8190 arraysize(always_flags));
8072 } 8191 }
OLDNEW
« no previous file with comments | « src/ast/scopes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698