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