OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/ast/modules.h" | 5 #include "src/ast/modules.h" |
6 #include "src/ast/ast-value-factory.h" | 6 #include "src/ast/ast-value-factory.h" |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 result->export_name = FromStringOrUndefined( | 103 result->export_name = FromStringOrUndefined( |
104 isolate, avfactory, handle(entry->export_name(), isolate)); | 104 isolate, avfactory, handle(entry->export_name(), isolate)); |
105 result->local_name = FromStringOrUndefined( | 105 result->local_name = FromStringOrUndefined( |
106 isolate, avfactory, handle(entry->local_name(), isolate)); | 106 isolate, avfactory, handle(entry->local_name(), isolate)); |
107 result->import_name = FromStringOrUndefined( | 107 result->import_name = FromStringOrUndefined( |
108 isolate, avfactory, handle(entry->import_name(), isolate)); | 108 isolate, avfactory, handle(entry->import_name(), isolate)); |
109 result->module_request = Smi::cast(entry->module_request())->value(); | 109 result->module_request = Smi::cast(entry->module_request())->value(); |
110 return result; | 110 return result; |
111 } | 111 } |
112 | 112 |
113 Handle<FixedArray> ModuleDescriptor::SerializeRegularExports(Isolate* isolate, | |
114 Zone* zone) const { | |
115 // We serialize regular exports in a way that lets us later iterate over their | |
116 // local names and for each local name immediately access all its export | |
117 // names. (Regular exports have neither import name nor module request.) | |
118 | |
119 ZoneVector<Handle<Object>> data(zone); | |
120 data.reserve(2 * static_cast<int>(regular_exports_.size())); | |
adamk
2016/09/21 17:52:15
No need for static_cast here, let's just pretend s
| |
121 | |
122 int i = 0; | |
adamk
2016/09/21 17:52:15
I don't see this used
| |
123 for (auto it = regular_exports_.begin(); it != regular_exports_.end();) { | |
124 // Find out how many export names this local name has. | |
125 auto next = it; | |
126 int size = 0; | |
127 do { | |
128 ++next; | |
129 ++size; | |
130 } while (next != regular_exports_.end() && next->first == it->first); | |
131 | |
132 Handle<FixedArray> export_names = isolate->factory()->NewFixedArray(size); | |
133 data.push_back(it->second->local_name->string()); | |
134 data.push_back(export_names); | |
135 | |
136 // Collect the export names. | |
137 int j = 0; | |
adamk
2016/09/21 17:52:15
I think you could call this "i" instead.
| |
138 for (; it != next; ++it) { | |
139 export_names->set(j++, *it->second->export_name->string()); | |
140 } | |
141 DCHECK_EQ(j, size); | |
142 | |
143 // Continue with the next distinct key. | |
144 DCHECK(it == next); | |
145 } | |
146 | |
147 // We cannot create the FixedArray earlier because we only now know the | |
148 // precise size (the number of unique keys in regular_exports). | |
149 Handle<FixedArray> result = isolate->factory()->NewFixedArray(data.size()); | |
150 for (int i = 0, n = data.size(); i < n; ++i) { | |
151 result->set(i, *data[i]); | |
152 } | |
153 return result; | |
154 } | |
155 | |
156 void ModuleDescriptor::DeserializeRegularExports(Isolate* isolate, | |
157 AstValueFactory* avfactory, | |
158 Handle<FixedArray> data) { | |
159 for (int i = 0, length_i = data->length(); i < length_i;) { | |
160 Handle<String> local_name(String::cast(data->get(i++)), isolate); | |
161 Handle<FixedArray> export_names(FixedArray::cast(data->get(i++)), isolate); | |
162 | |
163 for (int j = 0, length_j = export_names->length(); j < length_j; ++j) { | |
164 Handle<String> export_name(String::cast(export_names->get(j)), isolate); | |
165 | |
166 Entry* entry = | |
167 new (avfactory->zone()) Entry(Scanner::Location::invalid()); | |
168 entry->local_name = avfactory->GetString(local_name); | |
169 entry->export_name = avfactory->GetString(export_name); | |
170 | |
171 AddRegularExport(entry); | |
172 } | |
173 } | |
174 } | |
175 | |
113 void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { | 176 void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { |
114 for (auto it = regular_exports_.begin(); it != regular_exports_.end();) { | 177 for (auto it = regular_exports_.begin(); it != regular_exports_.end();) { |
115 Entry* entry = it->second; | 178 Entry* entry = it->second; |
116 DCHECK_NOT_NULL(entry->local_name); | 179 DCHECK_NOT_NULL(entry->local_name); |
117 auto import = regular_imports_.find(entry->local_name); | 180 auto import = regular_imports_.find(entry->local_name); |
118 if (import != regular_imports_.end()) { | 181 if (import != regular_imports_.end()) { |
119 // Found an indirect export. Patch export entry and move it from regular | 182 // Found an indirect export. Patch export entry and move it from regular |
120 // to special. | 183 // to special. |
121 DCHECK_NULL(entry->import_name); | 184 DCHECK_NULL(entry->import_name); |
122 DCHECK_LT(entry->module_request, 0); | 185 DCHECK_LT(entry->module_request, 0); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 return false; | 262 return false; |
200 } | 263 } |
201 } | 264 } |
202 | 265 |
203 MakeIndirectExportsExplicit(zone); | 266 MakeIndirectExportsExplicit(zone); |
204 return true; | 267 return true; |
205 } | 268 } |
206 | 269 |
207 } // namespace internal | 270 } // namespace internal |
208 } // namespace v8 | 271 } // namespace v8 |
OLD | NEW |