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 19889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19900 &loc); | 19900 &loc); |
19901 } | 19901 } |
19902 return MaybeHandle<Cell>(); | 19902 return MaybeHandle<Cell>(); |
19903 } | 19903 } |
19904 name_set->insert(name); | 19904 name_set->insert(name); |
19905 } | 19905 } |
19906 | 19906 |
19907 if (object->IsModuleInfoEntry()) { | 19907 if (object->IsModuleInfoEntry()) { |
19908 // Not yet resolved indirect export. | 19908 // Not yet resolved indirect export. |
19909 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); | 19909 Handle<ModuleInfoEntry> entry = Handle<ModuleInfoEntry>::cast(object); |
19910 int module_request = Smi::cast(entry->module_request())->value(); | |
19911 Handle<String> import_name(String::cast(entry->import_name()), isolate); | 19910 Handle<String> import_name(String::cast(entry->import_name()), isolate); |
19912 Handle<Script> script( | 19911 Handle<Script> script( |
19913 Script::cast(JSFunction::cast(module->code())->shared()->script()), | 19912 Script::cast(JSFunction::cast(module->code())->shared()->script()), |
19914 isolate); | 19913 isolate); |
19915 MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); | 19914 MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); |
19916 | 19915 |
19917 Handle<Cell> cell; | 19916 Handle<Cell> cell; |
19918 if (!ResolveImport(module, import_name, module_request, new_loc, true, | 19917 if (!ResolveImport(module, import_name, entry->module_request(), new_loc, |
19919 resolve_set) | 19918 true, resolve_set) |
19920 .ToHandle(&cell)) { | 19919 .ToHandle(&cell)) { |
19921 DCHECK(isolate->has_pending_exception()); | 19920 DCHECK(isolate->has_pending_exception()); |
19922 return MaybeHandle<Cell>(); | 19921 return MaybeHandle<Cell>(); |
19923 } | 19922 } |
19924 | 19923 |
19925 // The export table may have changed but the entry in question should be | 19924 // The export table may have changed but the entry in question should be |
19926 // unchanged. | 19925 // unchanged. |
19927 Handle<ObjectHashTable> exports(module->exports(), isolate); | 19926 Handle<ObjectHashTable> exports(module->exports(), isolate); |
19928 DCHECK(exports->Lookup(name)->IsModuleInfoEntry()); | 19927 DCHECK(exports->Lookup(name)->IsModuleInfoEntry()); |
19929 | 19928 |
(...skipping 16 matching lines...) Expand all Loading... | |
19946 // exports provide the name, make sure they all map it to the same cell. | 19945 // exports provide the name, make sure they all map it to the same cell. |
19947 Handle<Cell> unique_cell; | 19946 Handle<Cell> unique_cell; |
19948 Handle<FixedArray> special_exports(module->info()->special_exports(), | 19947 Handle<FixedArray> special_exports(module->info()->special_exports(), |
19949 isolate); | 19948 isolate); |
19950 for (int i = 0, n = special_exports->length(); i < n; ++i) { | 19949 for (int i = 0, n = special_exports->length(); i < n; ++i) { |
19951 i::Handle<i::ModuleInfoEntry> entry( | 19950 i::Handle<i::ModuleInfoEntry> entry( |
19952 i::ModuleInfoEntry::cast(special_exports->get(i)), isolate); | 19951 i::ModuleInfoEntry::cast(special_exports->get(i)), isolate); |
19953 if (!entry->export_name()->IsUndefined(isolate)) { | 19952 if (!entry->export_name()->IsUndefined(isolate)) { |
19954 continue; // Indirect export. | 19953 continue; // Indirect export. |
19955 } | 19954 } |
19956 int module_request = Smi::cast(entry->module_request())->value(); | |
19957 | 19955 |
19958 Handle<Script> script( | 19956 Handle<Script> script( |
19959 Script::cast(JSFunction::cast(module->code())->shared()->script()), | 19957 Script::cast(JSFunction::cast(module->code())->shared()->script()), |
19960 isolate); | 19958 isolate); |
19961 MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); | 19959 MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); |
19962 | 19960 |
19963 Handle<Cell> cell; | 19961 Handle<Cell> cell; |
19964 if (ResolveImport(module, name, module_request, new_loc, false, | 19962 if (ResolveImport(module, name, entry->module_request(), new_loc, false, |
19965 resolve_set) | 19963 resolve_set) |
19966 .ToHandle(&cell)) { | 19964 .ToHandle(&cell)) { |
19967 if (unique_cell.is_null()) unique_cell = cell; | 19965 if (unique_cell.is_null()) unique_cell = cell; |
19968 if (*unique_cell != *cell) { | 19966 if (*unique_cell != *cell) { |
19969 return isolate->Throw<Cell>( | 19967 return isolate->Throw<Cell>( |
19970 isolate->factory()->NewSyntaxError( | 19968 isolate->factory()->NewSyntaxError( |
19971 MessageTemplate::kAmbiguousExport, name), | 19969 MessageTemplate::kAmbiguousExport, name), |
19972 &loc); | 19970 &loc); |
19973 } | 19971 } |
19974 } else if (isolate->has_pending_exception()) { | 19972 } else if (isolate->has_pending_exception()) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20007 shared, | 20005 shared, |
20008 handle(Utils::OpenHandle(*context)->native_context(), isolate)); | 20006 handle(Utils::OpenHandle(*context)->native_context(), isolate)); |
20009 module->set_code(*function); | 20007 module->set_code(*function); |
20010 DCHECK(module->instantiated()); | 20008 DCHECK(module->instantiated()); |
20011 | 20009 |
20012 Handle<ModuleInfo> module_info(shared->scope_info()->ModuleDescriptorInfo(), | 20010 Handle<ModuleInfo> module_info(shared->scope_info()->ModuleDescriptorInfo(), |
20013 isolate); | 20011 isolate); |
20014 | 20012 |
20015 // Set up local exports. | 20013 // Set up local exports. |
20016 Handle<FixedArray> regular_exports(module_info->regular_exports(), isolate); | 20014 Handle<FixedArray> regular_exports(module_info->regular_exports(), isolate); |
20017 for (int i = 0, n = regular_exports->length(); i < n; i += 2) { | 20015 for (int i = 0, n = regular_exports->length(); i < n; i += 3) { |
20016 // TODO(neis): Make this more robust. | |
adamk
2016/10/31 18:25:04
Related to robustness, seems like this loop should
neis
2016/11/03 10:43:48
Sure, that's part of it.
| |
20018 Handle<FixedArray> export_names( | 20017 Handle<FixedArray> export_names( |
20019 FixedArray::cast(regular_exports->get(i + 1)), isolate); | 20018 FixedArray::cast(regular_exports->get(i + 2)), isolate); |
20020 CreateExport(module, export_names); | 20019 CreateExport(module, export_names); |
20021 } | 20020 } |
20022 | 20021 |
20023 // Partially set up indirect exports. | 20022 // Partially set up indirect exports. |
20024 // For each indirect export, we create the appropriate slot in the export | 20023 // For each indirect export, we create the appropriate slot in the export |
20025 // table and store its ModuleInfoEntry there. When we later find the correct | 20024 // table and store its ModuleInfoEntry there. When we later find the correct |
20026 // Cell in the module that actually provides the value, we replace the | 20025 // Cell in the module that actually provides the value, we replace the |
20027 // ModuleInfoEntry by that Cell (see ResolveExport). | 20026 // ModuleInfoEntry by that Cell (see ResolveExport). |
20028 Handle<FixedArray> special_exports(module_info->special_exports(), isolate); | 20027 Handle<FixedArray> special_exports(module_info->special_exports(), isolate); |
20029 for (int i = 0, n = special_exports->length(); i < n; ++i) { | 20028 for (int i = 0, n = special_exports->length(); i < n; ++i) { |
(...skipping 27 matching lines...) Expand all Loading... | |
20057 } | 20056 } |
20058 | 20057 |
20059 Zone zone(isolate->allocator(), ZONE_NAME); | 20058 Zone zone(isolate->allocator(), ZONE_NAME); |
20060 | 20059 |
20061 // Resolve imports. | 20060 // Resolve imports. |
20062 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); | 20061 Handle<FixedArray> regular_imports(module_info->regular_imports(), isolate); |
20063 for (int i = 0, n = regular_imports->length(); i < n; ++i) { | 20062 for (int i = 0, n = regular_imports->length(); i < n; ++i) { |
20064 Handle<ModuleInfoEntry> entry( | 20063 Handle<ModuleInfoEntry> entry( |
20065 ModuleInfoEntry::cast(regular_imports->get(i)), isolate); | 20064 ModuleInfoEntry::cast(regular_imports->get(i)), isolate); |
20066 Handle<String> name(String::cast(entry->import_name()), isolate); | 20065 Handle<String> name(String::cast(entry->import_name()), isolate); |
20067 int module_request = Smi::cast(entry->module_request())->value(); | |
20068 Handle<Script> script( | 20066 Handle<Script> script( |
20069 Script::cast(JSFunction::cast(module->code())->shared()->script()), | 20067 Script::cast(JSFunction::cast(module->code())->shared()->script()), |
20070 isolate); | 20068 isolate); |
20071 MessageLocation loc(script, entry->beg_pos(), entry->end_pos()); | 20069 MessageLocation loc(script, entry->beg_pos(), entry->end_pos()); |
20072 ResolveSet resolve_set(&zone); | 20070 ResolveSet resolve_set(&zone); |
20073 if (ResolveImport(module, name, module_request, loc, true, &resolve_set) | 20071 if (ResolveImport(module, name, entry->module_request(), loc, true, |
20072 &resolve_set) | |
20074 .is_null()) { | 20073 .is_null()) { |
20075 return false; | 20074 return false; |
20076 } | 20075 } |
20077 } | 20076 } |
20078 | 20077 |
20079 // Resolve indirect exports. | 20078 // Resolve indirect exports. |
20080 for (int i = 0, n = special_exports->length(); i < n; ++i) { | 20079 for (int i = 0, n = special_exports->length(); i < n; ++i) { |
20081 Handle<ModuleInfoEntry> entry( | 20080 Handle<ModuleInfoEntry> entry( |
20082 ModuleInfoEntry::cast(special_exports->get(i)), isolate); | 20081 ModuleInfoEntry::cast(special_exports->get(i)), isolate); |
20083 Handle<Object> name(entry->export_name(), isolate); | 20082 Handle<Object> name(entry->export_name(), isolate); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20147 | 20146 |
20148 Handle<FixedArray> special_exports(module->info()->special_exports(), | 20147 Handle<FixedArray> special_exports(module->info()->special_exports(), |
20149 isolate); | 20148 isolate); |
20150 for (int i = 0, n = special_exports->length(); i < n; ++i) { | 20149 for (int i = 0, n = special_exports->length(); i < n; ++i) { |
20151 Handle<ModuleInfoEntry> entry( | 20150 Handle<ModuleInfoEntry> entry( |
20152 ModuleInfoEntry::cast(special_exports->get(i)), isolate); | 20151 ModuleInfoEntry::cast(special_exports->get(i)), isolate); |
20153 if (!entry->export_name()->IsUndefined(isolate)) { | 20152 if (!entry->export_name()->IsUndefined(isolate)) { |
20154 continue; // Indirect export. | 20153 continue; // Indirect export. |
20155 } | 20154 } |
20156 | 20155 |
20157 int module_request = Smi::cast(entry->module_request())->value(); | |
20158 Handle<Module> requested_module( | 20156 Handle<Module> requested_module( |
20159 Module::cast(module->requested_modules()->get(module_request)), | 20157 Module::cast(module->requested_modules()->get(entry->module_request())), |
20160 isolate); | 20158 isolate); |
20161 | 20159 |
20162 // Recurse. | 20160 // Recurse. |
20163 FetchStarExports(requested_module, zone, visited); | 20161 FetchStarExports(requested_module, zone, visited); |
20164 | 20162 |
20165 // Collect all of [requested_module]'s exports that must be added to | 20163 // Collect all of [requested_module]'s exports that must be added to |
20166 // [module]'s exports (i.e. to [exports]). We record these in | 20164 // [module]'s exports (i.e. to [exports]). We record these in |
20167 // [more_exports]. Ambiguities (conflicting exports) are marked by mapping | 20165 // [more_exports]. Ambiguities (conflicting exports) are marked by mapping |
20168 // the name to undefined instead of a Cell. | 20166 // the name to undefined instead of a Cell. |
20169 Handle<ObjectHashTable> requested_exports(requested_module->exports(), | 20167 Handle<ObjectHashTable> requested_exports(requested_module->exports(), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20257 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20255 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
20258 .Check(); | 20256 .Check(); |
20259 } | 20257 } |
20260 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20258 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
20261 | 20259 |
20262 return ns; | 20260 return ns; |
20263 } | 20261 } |
20264 | 20262 |
20265 } // namespace internal | 20263 } // namespace internal |
20266 } // namespace v8 | 20264 } // namespace v8 |
OLD | NEW |