| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 19689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19700 MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, | 19700 MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, |
| 19701 Handle<String> name, bool must_resolve, | 19701 Handle<String> name, bool must_resolve, |
| 19702 Module::ResolveSet* resolve_set) { | 19702 Module::ResolveSet* resolve_set) { |
| 19703 Isolate* isolate = module->GetIsolate(); | 19703 Isolate* isolate = module->GetIsolate(); |
| 19704 Handle<Object> object(module->exports()->Lookup(name), isolate); | 19704 Handle<Object> object(module->exports()->Lookup(name), isolate); |
| 19705 if (object->IsCell()) { | 19705 if (object->IsCell()) { |
| 19706 // Already resolved (e.g. because it's a local export). | 19706 // Already resolved (e.g. because it's a local export). |
| 19707 return Handle<Cell>::cast(object); | 19707 return Handle<Cell>::cast(object); |
| 19708 } | 19708 } |
| 19709 | 19709 |
| 19710 // Must be an indirect export of some sort, so we need to detect cycles. | 19710 // Check for cycle before recursing. |
| 19711 { | 19711 { |
| 19712 // Attempt insertion with a null string set. | 19712 // Attempt insertion with a null string set. |
| 19713 auto result = resolve_set->insert({module, nullptr}); | 19713 auto result = resolve_set->insert({module, nullptr}); |
| 19714 UnorderedStringSet*& name_set = result.first->second; | 19714 UnorderedStringSet*& name_set = result.first->second; |
| 19715 bool did_insert = result.second; | 19715 if (result.second) { |
| 19716 if (did_insert) { | |
| 19717 // |module| wasn't in the map previously, so allocate a new name set. | 19716 // |module| wasn't in the map previously, so allocate a new name set. |
| 19718 Zone* zone = resolve_set->zone(); | 19717 Zone* zone = resolve_set->zone(); |
| 19719 name_set = | 19718 name_set = |
| 19720 new (zone->New(sizeof(UnorderedStringSet))) UnorderedStringSet(zone); | 19719 new (zone->New(sizeof(UnorderedStringSet))) UnorderedStringSet(zone); |
| 19721 } else if (name_set->count(name)) { | 19720 } else if (name_set->count(name)) { |
| 19722 // TODO(adamk): Throwing here is incorrect in the case of star exports. | 19721 // Cycle detected. |
| 19723 THROW_NEW_ERROR( | 19722 if (must_resolve) { |
| 19724 isolate, | 19723 THROW_NEW_ERROR( |
| 19725 NewSyntaxError(MessageTemplate::kCyclicModuleDependency, name), Cell); | 19724 isolate, |
| 19725 NewSyntaxError(MessageTemplate::kCyclicModuleDependency, name), |
| 19726 Cell); |
| 19727 } |
| 19728 return MaybeHandle<Cell>(); |
| 19726 } | 19729 } |
| 19727 name_set->insert(name); | 19730 name_set->insert(name); |
| 19728 } | 19731 } |
| 19729 | 19732 |
| 19730 if (object->IsModuleInfoEntry()) { | 19733 if (object->IsModuleInfoEntry()) { |
| 19731 // Not yet resolved indirect export. | 19734 // Not yet resolved indirect export. |
| 19732 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); | 19735 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); |
| 19733 int module_request = Smi::cast(entry->module_request())->value(); | 19736 int module_request = Smi::cast(entry->module_request())->value(); |
| 19734 Handle<String> import_name(String::cast(entry->import_name()), isolate); | 19737 Handle<String> import_name(String::cast(entry->import_name()), isolate); |
| 19735 | 19738 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19895 .is_null()) { | 19898 .is_null()) { |
| 19896 return false; | 19899 return false; |
| 19897 } | 19900 } |
| 19898 } | 19901 } |
| 19899 | 19902 |
| 19900 return true; | 19903 return true; |
| 19901 } | 19904 } |
| 19902 | 19905 |
| 19903 } // namespace internal | 19906 } // namespace internal |
| 19904 } // namespace v8 | 19907 } // namespace v8 |
| OLD | NEW |