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 30 matching lines...) Expand all Loading... |
41 #include "src/interpreter/bytecode-array-iterator.h" | 41 #include "src/interpreter/bytecode-array-iterator.h" |
42 #include "src/interpreter/bytecode-decoder.h" | 42 #include "src/interpreter/bytecode-decoder.h" |
43 #include "src/interpreter/interpreter.h" | 43 #include "src/interpreter/interpreter.h" |
44 #include "src/isolate-inl.h" | 44 #include "src/isolate-inl.h" |
45 #include "src/keys.h" | 45 #include "src/keys.h" |
46 #include "src/list.h" | 46 #include "src/list.h" |
47 #include "src/log.h" | 47 #include "src/log.h" |
48 #include "src/lookup.h" | 48 #include "src/lookup.h" |
49 #include "src/macro-assembler.h" | 49 #include "src/macro-assembler.h" |
50 #include "src/messages.h" | 50 #include "src/messages.h" |
| 51 #include "src/module-resolve-set-inl.h" |
51 #include "src/objects-body-descriptors-inl.h" | 52 #include "src/objects-body-descriptors-inl.h" |
52 #include "src/property-descriptor.h" | 53 #include "src/property-descriptor.h" |
53 #include "src/prototype.h" | 54 #include "src/prototype.h" |
54 #include "src/regexp/jsregexp.h" | 55 #include "src/regexp/jsregexp.h" |
55 #include "src/safepoint-table.h" | 56 #include "src/safepoint-table.h" |
56 #include "src/snapshot/code-serializer.h" | 57 #include "src/snapshot/code-serializer.h" |
57 #include "src/source-position-table.h" | 58 #include "src/source-position-table.h" |
58 #include "src/string-builder.h" | 59 #include "src/string-builder.h" |
59 #include "src/string-search.h" | 60 #include "src/string-search.h" |
60 #include "src/string-stream.h" | 61 #include "src/string-stream.h" |
(...skipping 19561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19622 | 19623 |
19623 Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name, | 19624 Handle<Object> Module::LoadImport(Handle<Module> module, Handle<String> name, |
19624 int module_request) { | 19625 int module_request) { |
19625 Isolate* isolate = module->GetIsolate(); | 19626 Isolate* isolate = module->GetIsolate(); |
19626 Handle<Module> requested_module( | 19627 Handle<Module> requested_module( |
19627 Module::cast(module->requested_modules()->get(module_request)), isolate); | 19628 Module::cast(module->requested_modules()->get(module_request)), isolate); |
19628 return Module::LoadExport(requested_module, name); | 19629 return Module::LoadExport(requested_module, name); |
19629 } | 19630 } |
19630 | 19631 |
19631 MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, | 19632 MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, |
19632 Handle<String> name, | 19633 Handle<String> name, int module_request, |
19633 int module_request) { | 19634 Module::ResolveSet* resolve_set, |
| 19635 Zone* zone) { |
19634 Isolate* isolate = module->GetIsolate(); | 19636 Isolate* isolate = module->GetIsolate(); |
19635 Handle<Module> requested_module( | 19637 Handle<Module> requested_module( |
19636 Module::cast(module->requested_modules()->get(module_request)), isolate); | 19638 Module::cast(module->requested_modules()->get(module_request)), isolate); |
19637 return Module::ResolveExport(requested_module, name); | 19639 return Module::ResolveExport(requested_module, name, resolve_set, zone); |
19638 } | 19640 } |
19639 | 19641 |
19640 MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, | 19642 MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, |
19641 Handle<String> name) { | 19643 Handle<String> name, |
19642 // TODO(neis): Detect cycles. | 19644 Module::ResolveSet* resolve_set, |
| 19645 Zone* zone) { |
| 19646 Isolate* isolate = module->GetIsolate(); |
19643 | 19647 |
19644 Isolate* isolate = module->GetIsolate(); | 19648 auto it = resolve_set->find(module); |
| 19649 if (it != resolve_set->end()) { |
| 19650 auto& name_set = it->second; |
| 19651 if (name_set->count(name)) { |
| 19652 THROW_NEW_ERROR(isolate, |
| 19653 NewSyntaxError(MessageTemplate::kCyclicModuleDependency), |
| 19654 Cell); |
| 19655 } |
| 19656 name_set->insert(name); |
| 19657 } else { |
| 19658 UnorderedStringSet* name_set = |
| 19659 new (zone->New(sizeof(UnorderedStringSet))) UnorderedStringSet(zone); |
| 19660 name_set->insert(name); |
| 19661 resolve_set->insert({module, name_set}); |
| 19662 } |
| 19663 |
19645 Handle<Object> object(module->exports()->Lookup(name), isolate); | 19664 Handle<Object> object(module->exports()->Lookup(name), isolate); |
19646 | 19665 |
19647 if (object->IsCell()) { | 19666 if (object->IsCell()) { |
19648 // Already resolved (e.g. because it's a local export). | 19667 // Already resolved (e.g. because it's a local export). |
19649 return Handle<Cell>::cast(object); | 19668 return Handle<Cell>::cast(object); |
19650 } | 19669 } |
19651 | 19670 |
19652 if (object->IsModuleInfoEntry()) { | 19671 if (object->IsModuleInfoEntry()) { |
19653 // Not yet resolved indirect export. | 19672 // Not yet resolved indirect export. |
19654 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); | 19673 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); |
19655 int module_request = Smi::cast(entry->module_request())->value(); | 19674 int module_request = Smi::cast(entry->module_request())->value(); |
19656 Handle<String> import_name(String::cast(entry->import_name()), isolate); | 19675 Handle<String> import_name(String::cast(entry->import_name()), isolate); |
19657 | 19676 |
19658 Handle<Cell> cell; | 19677 Handle<Cell> cell; |
19659 if (!ResolveImport(module, import_name, module_request).ToHandle(&cell)) { | 19678 if (!ResolveImport(module, import_name, module_request, resolve_set, zone) |
| 19679 .ToHandle(&cell)) { |
19660 return MaybeHandle<Cell>(); | 19680 return MaybeHandle<Cell>(); |
19661 } | 19681 } |
19662 | 19682 |
19663 // The export table may have changed but the entry in question should be | 19683 // The export table may have changed but the entry in question should be |
19664 // unchanged. | 19684 // unchanged. |
19665 Handle<ObjectHashTable> exports(module->exports(), isolate); | 19685 Handle<ObjectHashTable> exports(module->exports(), isolate); |
19666 DCHECK(exports->Lookup(name)->IsModuleInfoEntry()); | 19686 DCHECK(exports->Lookup(name)->IsModuleInfoEntry()); |
19667 | 19687 |
19668 exports = ObjectHashTable::Put(exports, name, cell); | 19688 exports = ObjectHashTable::Put(exports, name, cell); |
19669 module->set_exports(*exports); | 19689 module->set_exports(*exports); |
19670 return cell; | 19690 return cell; |
19671 } | 19691 } |
19672 | 19692 |
19673 DCHECK(object->IsTheHole(isolate)); | 19693 DCHECK(object->IsTheHole(isolate)); |
19674 // TODO(neis): Implement star exports. | 19694 // TODO(neis): Implement star exports. |
19675 | 19695 |
19676 // Unresolvable. | 19696 // Unresolvable. |
19677 THROW_NEW_ERROR(isolate, | 19697 THROW_NEW_ERROR(isolate, |
19678 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), | 19698 NewSyntaxError(MessageTemplate::kUnresolvableExport, name), |
19679 Cell); | 19699 Cell); |
19680 } | 19700 } |
19681 | 19701 |
19682 } // namespace internal | 19702 } // namespace internal |
19683 } // namespace v8 | 19703 } // namespace v8 |
OLD | NEW |