Chromium Code Reviews| 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 5834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 CheckModuleEntry(const i::ModuleDescriptor::ModuleEntry* entry, |
| 5849 const char* export_name, const char* local_name, const char* import_name, | 5849 const char* export_name, const char* local_name, const char* import_name, |
| 5850 const char* module_request) { | 5850 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 entry->export_name->IsOneByteEqualTo(export_name); | 5855 CHECK(entry->export_name->IsOneByteEqualTo(export_name)); |
|
neis
2016/08/24 14:46:04
!!!
adamk
2016/08/24 18:06:09
Ha!
| |
| 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 entry->local_name->IsOneByteEqualTo(local_name); | 5860 CHECK(entry->local_name->IsOneByteEqualTo(local_name)); |
| 5861 } | 5861 } |
| 5862 if (import_name == nullptr) { | 5862 if (import_name == nullptr) { |
| 5863 CHECK_NULL(entry->import_name); | 5863 CHECK_NULL(entry->import_name); |
| 5864 } else { | 5864 } else { |
| 5865 entry->import_name->IsOneByteEqualTo(import_name); | 5865 CHECK(entry->import_name->IsOneByteEqualTo(import_name)); |
| 5866 } | 5866 } |
| 5867 if (module_request == nullptr) { | 5867 if (module_request == nullptr) { |
| 5868 CHECK_NULL(entry->module_request); | 5868 CHECK_NULL(entry->module_request); |
| 5869 } else { | 5869 } else { |
| 5870 entry->module_request->IsOneByteEqualTo(module_request); | 5870 CHECK(entry->module_request->IsOneByteEqualTo(module_request)); |
| 5871 } | 5871 } |
| 5872 } | 5872 } |
| 5873 | 5873 |
| 5874 TEST(ModuleParsingInternals) { | 5874 TEST(ModuleParsingInternals) { |
| 5875 i::Isolate* isolate = CcTest::i_isolate(); | 5875 i::Isolate* isolate = CcTest::i_isolate(); |
| 5876 i::Factory* factory = isolate->factory(); | 5876 i::Factory* factory = isolate->factory(); |
| 5877 v8::HandleScope handles(CcTest::isolate()); | 5877 v8::HandleScope handles(CcTest::isolate()); |
| 5878 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 5878 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 5879 v8::Context::Scope context_scope(context); | 5879 v8::Context::Scope context_scope(context); |
| 5880 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5880 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| (...skipping 26 matching lines...) Expand all 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 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); | 5918 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); |
| 5918 CHECK_EQ(13, declarations->length()); | 5919 CHECK_EQ(13, declarations->length()); |
| 5919 | 5920 |
| 5920 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); | 5921 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); |
| 5921 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET); | 5922 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET); |
| 5922 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init()); | 5923 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init()); |
| 5923 CHECK(declarations->at(0)->proxy()->var()->location() == | 5924 CHECK(declarations->at(0)->proxy()->var()->location() == |
| 5924 i::VariableLocation::MODULE); | 5925 i::VariableLocation::MODULE); |
| 5925 | 5926 |
| 5926 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); | 5927 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5992 | 5993 |
| 5993 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); | 5994 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); |
| 5994 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); | 5995 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); |
| 5995 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); | 5996 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); |
| 5996 CHECK(declarations->at(12)->proxy()->var()->location() == | 5997 CHECK(declarations->at(12)->proxy()->var()->location() == |
| 5997 i::VariableLocation::MODULE); | 5998 i::VariableLocation::MODULE); |
| 5998 | 5999 |
| 5999 i::ModuleDescriptor* descriptor = module_scope->module(); | 6000 i::ModuleDescriptor* descriptor = module_scope->module(); |
| 6000 CHECK_NOT_NULL(descriptor); | 6001 CHECK_NOT_NULL(descriptor); |
| 6001 | 6002 |
| 6002 CHECK_EQ(11, descriptor->exports().length()); | 6003 CHECK_EQ(3, descriptor->special_exports().length()); |
| 6003 CheckModuleEntry( | 6004 CheckModuleEntry( |
| 6004 descriptor->exports().at(0), "y", "x", nullptr, nullptr); | 6005 descriptor->special_exports().at(0), "b", nullptr, "a", "m.js"); |
| 6005 CheckModuleEntry( | 6006 CheckModuleEntry( |
| 6006 descriptor->exports().at(1), "b", nullptr, "a", "m.js"); | 6007 descriptor->special_exports().at(1), nullptr, nullptr, nullptr, "p.js"); |
| 6007 CheckModuleEntry( | 6008 CheckModuleEntry( |
| 6008 descriptor->exports().at(2), nullptr, nullptr, nullptr, "p.js"); | 6009 descriptor->special_exports().at(2), "bb", nullptr, "aa", "m.js"); // !!! |
| 6009 CheckModuleEntry( | 6010 |
| 6010 descriptor->exports().at(3), "foo", "foo", nullptr, nullptr); | 6011 CHECK_EQ(8, descriptor->regular_exports().size()); |
| 6011 CheckModuleEntry( | 6012 entry = descriptor->regular_exports().find( |
| 6012 descriptor->exports().at(4), "goo", "goo", nullptr, nullptr); | 6013 declarations->at(3)->proxy()->raw_name())->second; |
| 6013 CheckModuleEntry( | 6014 CheckModuleEntry(entry, "foo", "foo", nullptr, nullptr); |
| 6014 descriptor->exports().at(5), "hoo", "hoo", nullptr, nullptr); | 6015 entry = descriptor->regular_exports().find( |
| 6015 CheckModuleEntry( | 6016 declarations->at(4)->proxy()->raw_name())->second; |
| 6016 descriptor->exports().at(6), "joo", "joo", nullptr, nullptr); | 6017 CheckModuleEntry(entry, "goo", "goo", nullptr, nullptr); |
| 6017 CheckModuleEntry( | 6018 entry = descriptor->regular_exports().find( |
| 6018 descriptor->exports().at(7), "default", "*default*", nullptr, nullptr); | 6019 declarations->at(5)->proxy()->raw_name())->second; |
| 6019 CheckModuleEntry( | 6020 CheckModuleEntry(entry, "hoo", "hoo", nullptr, nullptr); |
| 6020 descriptor->exports().at(8), "bb", nullptr, "aa", "m.js"); // !!! | 6021 entry = descriptor->regular_exports().find( |
| 6021 CheckModuleEntry( | 6022 declarations->at(6)->proxy()->raw_name())->second; |
| 6022 descriptor->exports().at(9), "x", "x", nullptr, nullptr); | 6023 CheckModuleEntry(entry, "joo", "joo", nullptr, nullptr); |
| 6023 CheckModuleEntry( | 6024 entry = descriptor->regular_exports().find( |
| 6024 descriptor->exports().at(10), "foob", "foob", nullptr, nullptr); | 6025 declarations->at(7)->proxy()->raw_name())->second; |
| 6026 CheckModuleEntry(entry, "default", "*default*", nullptr, nullptr); | |
| 6027 entry = descriptor->regular_exports().find( | |
| 6028 declarations->at(12)->proxy()->raw_name())->second; | |
| 6029 CheckModuleEntry(entry, "foob", "foob", nullptr, nullptr); | |
| 6030 // TODO(neis): The next lines are terrible. Find a better way. | |
| 6031 auto name_x = declarations->at(0)->proxy()->raw_name(); | |
| 6032 CHECK_EQ(2, descriptor->regular_exports().count(name_x)); | |
| 6033 auto it = descriptor->regular_exports().equal_range(name_x).first; | |
| 6034 entry = it->second; | |
| 6035 if (entry->export_name->IsOneByteEqualTo("y")) { | |
| 6036 CheckModuleEntry(entry, "y", "x", nullptr, nullptr); | |
| 6037 entry = (++it)->second; | |
| 6038 CheckModuleEntry(entry, "x", "x", nullptr, nullptr); | |
| 6039 } else { | |
| 6040 CheckModuleEntry(entry, "x", "x", nullptr, nullptr); | |
| 6041 entry = (++it)->second; | |
| 6042 CheckModuleEntry(entry, "y", "x", nullptr, nullptr); | |
| 6043 } | |
| 6025 | 6044 |
| 6026 CHECK_EQ(3, descriptor->special_imports().length()); | 6045 CHECK_EQ(3, descriptor->special_imports().length()); |
| 6027 CheckModuleEntry( | 6046 CheckModuleEntry( |
| 6028 descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js"); | 6047 descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js"); |
| 6029 CheckModuleEntry( | 6048 CheckModuleEntry( |
| 6030 descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js"); | 6049 descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js"); |
| 6031 CheckModuleEntry( | 6050 CheckModuleEntry( |
| 6032 descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js"); | 6051 descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js"); |
| 6033 | 6052 |
| 6034 CHECK_EQ(4, descriptor->regular_imports().size()); | 6053 CHECK_EQ(4, descriptor->regular_imports().size()); |
| 6035 const i::ModuleDescriptor::ModuleEntry* entry; | |
| 6036 entry = descriptor->regular_imports().find( | 6054 entry = descriptor->regular_imports().find( |
| 6037 declarations->at(1)->proxy()->raw_name())->second; | 6055 declarations->at(1)->proxy()->raw_name())->second; |
| 6038 CheckModuleEntry(entry, nullptr, "z", "q", "m.js"); | 6056 CheckModuleEntry(entry, nullptr, "z", "q", "m.js"); |
| 6039 entry = descriptor->regular_imports().find( | 6057 entry = descriptor->regular_imports().find( |
| 6040 declarations->at(2)->proxy()->raw_name())->second; | 6058 declarations->at(2)->proxy()->raw_name())->second; |
| 6041 CheckModuleEntry(entry, nullptr, "n", "default", "n.js"); | 6059 CheckModuleEntry(entry, nullptr, "n", "default", "n.js"); |
| 6042 entry = descriptor->regular_imports().find( | 6060 entry = descriptor->regular_imports().find( |
| 6043 declarations->at(9)->proxy()->raw_name())->second; | 6061 declarations->at(9)->proxy()->raw_name())->second; |
| 6044 CheckModuleEntry(entry, nullptr, "mm", "m", "m.js"); | 6062 CheckModuleEntry(entry, nullptr, "mm", "m", "m.js"); |
| 6045 entry = descriptor->regular_imports().find( | 6063 entry = descriptor->regular_imports().find( |
| (...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8151 "(a,);", | 8169 "(a,);", |
| 8152 "(a,b,c,);", | 8170 "(a,b,c,);", |
| 8153 NULL | 8171 NULL |
| 8154 }; | 8172 }; |
| 8155 // clang-format on | 8173 // clang-format on |
| 8156 | 8174 |
| 8157 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 8175 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
| 8158 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 8176 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 8159 arraysize(always_flags)); | 8177 arraysize(always_flags)); |
| 8160 } | 8178 } |
| OLD | NEW |