| 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 5827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5838 "try {} catch (enum) {}", | 5838 "try {} catch (enum) {}", |
| 5839 "try {} catch (enum) {} finally {}", | 5839 "try {} catch (enum) {} finally {}", |
| 5840 NULL | 5840 NULL |
| 5841 }; | 5841 }; |
| 5842 // clang-format on | 5842 // clang-format on |
| 5843 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; | 5843 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; |
| 5844 | 5844 |
| 5845 RunModuleParserSyncTest(context_data, kErrorSources, kError); | 5845 RunModuleParserSyncTest(context_data, kErrorSources, kError); |
| 5846 } | 5846 } |
| 5847 | 5847 |
| 5848 static void CheckModuleEntry(const i::ModuleDescriptor::ModuleEntry* entry, | 5848 static void CheckEntry(const i::ModuleDescriptor::Entry* entry, |
| 5849 const char* export_name, const char* local_name, const char* import_name, | 5849 const char* export_name, const char* local_name, |
| 5850 const char* module_request) { | 5850 const char* import_name, const char* module_request) { |
| 5851 CHECK_NOT_NULL(entry); | 5851 CHECK_NOT_NULL(entry); |
| 5852 if (export_name == nullptr) { | 5852 if (export_name == nullptr) { |
| 5853 CHECK_NULL(entry->export_name); | 5853 CHECK_NULL(entry->export_name); |
| 5854 } else { | 5854 } else { |
| 5855 CHECK(entry->export_name->IsOneByteEqualTo(export_name)); | 5855 CHECK(entry->export_name->IsOneByteEqualTo(export_name)); |
| 5856 } | 5856 } |
| 5857 if (local_name == nullptr) { | 5857 if (local_name == nullptr) { |
| 5858 CHECK_NULL(entry->local_name); | 5858 CHECK_NULL(entry->local_name); |
| 5859 } else { | 5859 } else { |
| 5860 CHECK(entry->local_name->IsOneByteEqualTo(local_name)); | 5860 CHECK(entry->local_name->IsOneByteEqualTo(local_name)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5907 i::Parser parser(&info); | 5907 i::Parser parser(&info); |
| 5908 info.set_module(); | 5908 info.set_module(); |
| 5909 CHECK(parser.Parse(&info)); | 5909 CHECK(parser.Parse(&info)); |
| 5910 CHECK(i::Compiler::Analyze(&info)); | 5910 CHECK(i::Compiler::Analyze(&info)); |
| 5911 i::FunctionLiteral* func = info.literal(); | 5911 i::FunctionLiteral* func = info.literal(); |
| 5912 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); | 5912 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); |
| 5913 i::Scope* outer_scope = module_scope->outer_scope(); | 5913 i::Scope* outer_scope = module_scope->outer_scope(); |
| 5914 CHECK(outer_scope->is_script_scope()); | 5914 CHECK(outer_scope->is_script_scope()); |
| 5915 CHECK_NULL(outer_scope->outer_scope()); | 5915 CHECK_NULL(outer_scope->outer_scope()); |
| 5916 CHECK(module_scope->is_module_scope()); | 5916 CHECK(module_scope->is_module_scope()); |
| 5917 const i::ModuleDescriptor::ModuleEntry* entry; | 5917 const i::ModuleDescriptor::Entry* entry; |
| 5918 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); | 5918 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); |
| 5919 CHECK_EQ(13, declarations->length()); | 5919 CHECK_EQ(13, declarations->length()); |
| 5920 | 5920 |
| 5921 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); | 5921 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); |
| 5922 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET); | 5922 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET); |
| 5923 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init()); | 5923 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init()); |
| 5924 CHECK(declarations->at(0)->proxy()->var()->location() == | 5924 CHECK(declarations->at(0)->proxy()->var()->location() == |
| 5925 i::VariableLocation::MODULE); | 5925 i::VariableLocation::MODULE); |
| 5926 | 5926 |
| 5927 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); | 5927 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5994 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); | 5994 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); |
| 5995 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); | 5995 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); |
| 5996 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); | 5996 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); |
| 5997 CHECK(declarations->at(12)->proxy()->var()->location() == | 5997 CHECK(declarations->at(12)->proxy()->var()->location() == |
| 5998 i::VariableLocation::MODULE); | 5998 i::VariableLocation::MODULE); |
| 5999 | 5999 |
| 6000 i::ModuleDescriptor* descriptor = module_scope->module(); | 6000 i::ModuleDescriptor* descriptor = module_scope->module(); |
| 6001 CHECK_NOT_NULL(descriptor); | 6001 CHECK_NOT_NULL(descriptor); |
| 6002 | 6002 |
| 6003 CHECK_EQ(3, descriptor->special_exports().length()); | 6003 CHECK_EQ(3, descriptor->special_exports().length()); |
| 6004 CheckModuleEntry(descriptor->special_exports().at(0), "b", nullptr, "a", | 6004 CheckEntry(descriptor->special_exports().at(0), "b", nullptr, "a", "m.js"); |
| 6005 "m.js"); | 6005 CheckEntry(descriptor->special_exports().at(1), nullptr, nullptr, nullptr, |
| 6006 CheckModuleEntry(descriptor->special_exports().at(1), nullptr, nullptr, | 6006 "p.js"); |
| 6007 nullptr, "p.js"); | 6007 CheckEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa", |
| 6008 CheckModuleEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa", | 6008 "m.js"); // !!! |
| 6009 "m.js"); // !!! | |
| 6010 | 6009 |
| 6011 CHECK_EQ(8, descriptor->regular_exports().size()); | 6010 CHECK_EQ(8, descriptor->regular_exports().size()); |
| 6012 entry = descriptor->regular_exports() | 6011 entry = descriptor->regular_exports() |
| 6013 .find(declarations->at(3)->proxy()->raw_name()) | 6012 .find(declarations->at(3)->proxy()->raw_name()) |
| 6014 ->second; | 6013 ->second; |
| 6015 CheckModuleEntry(entry, "foo", "foo", nullptr, nullptr); | 6014 CheckEntry(entry, "foo", "foo", nullptr, nullptr); |
| 6016 entry = descriptor->regular_exports() | 6015 entry = descriptor->regular_exports() |
| 6017 .find(declarations->at(4)->proxy()->raw_name()) | 6016 .find(declarations->at(4)->proxy()->raw_name()) |
| 6018 ->second; | 6017 ->second; |
| 6019 CheckModuleEntry(entry, "goo", "goo", nullptr, nullptr); | 6018 CheckEntry(entry, "goo", "goo", nullptr, nullptr); |
| 6020 entry = descriptor->regular_exports() | 6019 entry = descriptor->regular_exports() |
| 6021 .find(declarations->at(5)->proxy()->raw_name()) | 6020 .find(declarations->at(5)->proxy()->raw_name()) |
| 6022 ->second; | 6021 ->second; |
| 6023 CheckModuleEntry(entry, "hoo", "hoo", nullptr, nullptr); | 6022 CheckEntry(entry, "hoo", "hoo", nullptr, nullptr); |
| 6024 entry = descriptor->regular_exports() | 6023 entry = descriptor->regular_exports() |
| 6025 .find(declarations->at(6)->proxy()->raw_name()) | 6024 .find(declarations->at(6)->proxy()->raw_name()) |
| 6026 ->second; | 6025 ->second; |
| 6027 CheckModuleEntry(entry, "joo", "joo", nullptr, nullptr); | 6026 CheckEntry(entry, "joo", "joo", nullptr, nullptr); |
| 6028 entry = descriptor->regular_exports() | 6027 entry = descriptor->regular_exports() |
| 6029 .find(declarations->at(7)->proxy()->raw_name()) | 6028 .find(declarations->at(7)->proxy()->raw_name()) |
| 6030 ->second; | 6029 ->second; |
| 6031 CheckModuleEntry(entry, "default", "*default*", nullptr, nullptr); | 6030 CheckEntry(entry, "default", "*default*", nullptr, nullptr); |
| 6032 entry = descriptor->regular_exports() | 6031 entry = descriptor->regular_exports() |
| 6033 .find(declarations->at(12)->proxy()->raw_name()) | 6032 .find(declarations->at(12)->proxy()->raw_name()) |
| 6034 ->second; | 6033 ->second; |
| 6035 CheckModuleEntry(entry, "foob", "foob", nullptr, nullptr); | 6034 CheckEntry(entry, "foob", "foob", nullptr, nullptr); |
| 6036 // TODO(neis): The next lines are terrible. Find a better way. | 6035 // TODO(neis): The next lines are terrible. Find a better way. |
| 6037 auto name_x = declarations->at(0)->proxy()->raw_name(); | 6036 auto name_x = declarations->at(0)->proxy()->raw_name(); |
| 6038 CHECK_EQ(2, descriptor->regular_exports().count(name_x)); | 6037 CHECK_EQ(2, descriptor->regular_exports().count(name_x)); |
| 6039 auto it = descriptor->regular_exports().equal_range(name_x).first; | 6038 auto it = descriptor->regular_exports().equal_range(name_x).first; |
| 6040 entry = it->second; | 6039 entry = it->second; |
| 6041 if (entry->export_name->IsOneByteEqualTo("y")) { | 6040 if (entry->export_name->IsOneByteEqualTo("y")) { |
| 6042 CheckModuleEntry(entry, "y", "x", nullptr, nullptr); | 6041 CheckEntry(entry, "y", "x", nullptr, nullptr); |
| 6043 entry = (++it)->second; | 6042 entry = (++it)->second; |
| 6044 CheckModuleEntry(entry, "x", "x", nullptr, nullptr); | 6043 CheckEntry(entry, "x", "x", nullptr, nullptr); |
| 6045 } else { | 6044 } else { |
| 6046 CheckModuleEntry(entry, "x", "x", nullptr, nullptr); | 6045 CheckEntry(entry, "x", "x", nullptr, nullptr); |
| 6047 entry = (++it)->second; | 6046 entry = (++it)->second; |
| 6048 CheckModuleEntry(entry, "y", "x", nullptr, nullptr); | 6047 CheckEntry(entry, "y", "x", nullptr, nullptr); |
| 6049 } | 6048 } |
| 6050 | 6049 |
| 6051 CHECK_EQ(3, descriptor->special_imports().length()); | 6050 CHECK_EQ(3, descriptor->special_imports().length()); |
| 6052 CheckModuleEntry( | 6051 CheckEntry(descriptor->special_imports().at(0), nullptr, nullptr, nullptr, |
| 6053 descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js"); | 6052 "q.js"); |
| 6054 CheckModuleEntry( | 6053 CheckEntry(descriptor->special_imports().at(1), nullptr, "loo", nullptr, |
| 6055 descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js"); | 6054 "bar.js"); |
| 6056 CheckModuleEntry( | 6055 CheckEntry(descriptor->special_imports().at(2), nullptr, "foob", nullptr, |
| 6057 descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js"); | 6056 "bar.js"); |
| 6058 | 6057 |
| 6059 CHECK_EQ(4, descriptor->regular_imports().size()); | 6058 CHECK_EQ(4, descriptor->regular_imports().size()); |
| 6060 entry = descriptor->regular_imports().find( | 6059 entry = descriptor->regular_imports().find( |
| 6061 declarations->at(1)->proxy()->raw_name())->second; | 6060 declarations->at(1)->proxy()->raw_name())->second; |
| 6062 CheckModuleEntry(entry, nullptr, "z", "q", "m.js"); | 6061 CheckEntry(entry, nullptr, "z", "q", "m.js"); |
| 6063 entry = descriptor->regular_imports().find( | 6062 entry = descriptor->regular_imports().find( |
| 6064 declarations->at(2)->proxy()->raw_name())->second; | 6063 declarations->at(2)->proxy()->raw_name())->second; |
| 6065 CheckModuleEntry(entry, nullptr, "n", "default", "n.js"); | 6064 CheckEntry(entry, nullptr, "n", "default", "n.js"); |
| 6066 entry = descriptor->regular_imports().find( | 6065 entry = descriptor->regular_imports().find( |
| 6067 declarations->at(9)->proxy()->raw_name())->second; | 6066 declarations->at(9)->proxy()->raw_name())->second; |
| 6068 CheckModuleEntry(entry, nullptr, "mm", "m", "m.js"); | 6067 CheckEntry(entry, nullptr, "mm", "m", "m.js"); |
| 6069 entry = descriptor->regular_imports().find( | 6068 entry = descriptor->regular_imports().find( |
| 6070 declarations->at(10)->proxy()->raw_name())->second; | 6069 declarations->at(10)->proxy()->raw_name())->second; |
| 6071 CheckModuleEntry(entry, nullptr, "aa", "aa", "m.js"); | 6070 CheckEntry(entry, nullptr, "aa", "aa", "m.js"); |
| 6072 } | 6071 } |
| 6073 | 6072 |
| 6074 | 6073 |
| 6075 TEST(DuplicateProtoError) { | 6074 TEST(DuplicateProtoError) { |
| 6076 const char* context_data[][2] = { | 6075 const char* context_data[][2] = { |
| 6077 {"({", "});"}, | 6076 {"({", "});"}, |
| 6078 {"'use strict'; ({", "});"}, | 6077 {"'use strict'; ({", "});"}, |
| 6079 {NULL, NULL} | 6078 {NULL, NULL} |
| 6080 }; | 6079 }; |
| 6081 const char* error_data[] = { | 6080 const char* error_data[] = { |
| (...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8175 "(a,);", | 8174 "(a,);", |
| 8176 "(a,b,c,);", | 8175 "(a,b,c,);", |
| 8177 NULL | 8176 NULL |
| 8178 }; | 8177 }; |
| 8179 // clang-format on | 8178 // clang-format on |
| 8180 | 8179 |
| 8181 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 8180 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
| 8182 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 8181 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 8183 arraysize(always_flags)); | 8182 arraysize(always_flags)); |
| 8184 } | 8183 } |
| OLD | NEW |