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

Side by Side Diff: src/objects.cc

Issue 2376563002: [modules] Don't throw when detecting cycle while processing star exports. (Closed)
Patch Set: Created 4 years, 2 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/objects.h ('k') | test/mjsunit/modules-fail-star-exports-conflict.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/modules-fail-star-exports-conflict.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698