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

Side by Side Diff: src/ast/scopes.cc

Issue 2302783002: [modules] Basic support of exports (Closed)
Patch Set: . Created 4 years, 3 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
OLDNEW
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/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) { 169 : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) {
170 Zone* zone = avfactory->zone(); 170 Zone* zone = avfactory->zone();
171 ModuleInfo* module_info = scope_info->ModuleDescriptorInfo(); 171 ModuleInfo* module_info = scope_info->ModuleDescriptorInfo();
172 172
173 set_language_mode(STRICT); 173 set_language_mode(STRICT);
174 module_descriptor_ = new (zone) ModuleDescriptor(zone); 174 module_descriptor_ = new (zone) ModuleDescriptor(zone);
175 175
176 // Deserialize special exports. 176 // Deserialize special exports.
177 Handle<FixedArray> special_exports = handle(module_info->special_exports()); 177 Handle<FixedArray> special_exports = handle(module_info->special_exports());
178 for (int i = 0, n = special_exports->length(); i < n; ++i) { 178 for (int i = 0, n = special_exports->length(); i < n; ++i) {
179 Handle<FixedArray> serialized_entry( 179 Handle<ModuleInfoEntry> serialized_entry(
180 FixedArray::cast(special_exports->get(i)), isolate); 180 ModuleInfoEntry::cast(special_exports->get(i)), isolate);
181 module_descriptor_->AddSpecialExport( 181 module_descriptor_->AddSpecialExport(
182 ModuleDescriptor::Entry::Deserialize(isolate, avfactory, 182 ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
183 serialized_entry), 183 serialized_entry),
184 avfactory->zone()); 184 avfactory->zone());
185 } 185 }
186 186
187 // Deserialize regular exports. 187 // Deserialize regular exports.
188 Handle<FixedArray> regular_exports = handle(module_info->regular_exports()); 188 Handle<FixedArray> regular_exports = handle(module_info->regular_exports());
189 for (int i = 0, n = regular_exports->length(); i < n; ++i) { 189 for (int i = 0, n = regular_exports->length(); i < n; ++i) {
190 Handle<FixedArray> serialized_entry( 190 Handle<ModuleInfoEntry> serialized_entry(
191 FixedArray::cast(regular_exports->get(i)), isolate); 191 ModuleInfoEntry::cast(regular_exports->get(i)), isolate);
192 module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize( 192 module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize(
193 isolate, avfactory, serialized_entry)); 193 isolate, avfactory, serialized_entry));
194 } 194 }
195 } 195 }
196 196
197 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) 197 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
198 : zone_(zone), 198 : zone_(zone),
199 outer_scope_(nullptr), 199 outer_scope_(nullptr),
200 variables_(zone), 200 variables_(zone),
201 locals_(0, zone), 201 locals_(0, zone),
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 Variable* var = scope->LookupLocal(name); 694 Variable* var = scope->LookupLocal(name);
695 if (var != NULL) return var; 695 if (var != NULL) return var;
696 } 696 }
697 return NULL; 697 return NULL;
698 } 698 }
699 699
700 Variable* DeclarationScope::DeclareParameter( 700 Variable* DeclarationScope::DeclareParameter(
701 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, 701 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest,
702 bool* is_duplicate, AstValueFactory* ast_value_factory) { 702 bool* is_duplicate, AstValueFactory* ast_value_factory) {
703 DCHECK(!already_resolved_); 703 DCHECK(!already_resolved_);
704 DCHECK(is_function_scope()); 704 DCHECK(is_function_scope() || is_module_scope());
705 DCHECK(!has_rest_); 705 DCHECK(!has_rest_);
706 DCHECK(!is_optional || !is_rest); 706 DCHECK(!is_optional || !is_rest);
707 Variable* var; 707 Variable* var;
708 if (mode == TEMPORARY) { 708 if (mode == TEMPORARY) {
709 var = NewTemporary(name); 709 var = NewTemporary(name);
710 } else { 710 } else {
711 var = Declare(zone(), this, name, mode, Variable::NORMAL, 711 var = Declare(zone(), this, name, mode, Variable::NORMAL,
712 kCreatedInitialized); 712 kCreatedInitialized);
713 // TODO(wingo): Avoid O(n^2) check. 713 // TODO(wingo): Avoid O(n^2) check.
714 *is_duplicate = IsDeclaredParameter(name); 714 *is_duplicate = IsDeclaredParameter(name);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 } 1002 }
1003 1003
1004 DeclarationScope* Scope::GetClosureScope() { 1004 DeclarationScope* Scope::GetClosureScope() {
1005 Scope* scope = this; 1005 Scope* scope = this;
1006 while (!scope->is_declaration_scope() || scope->is_block_scope()) { 1006 while (!scope->is_declaration_scope() || scope->is_block_scope()) {
1007 scope = scope->outer_scope(); 1007 scope = scope->outer_scope();
1008 } 1008 }
1009 return scope->AsDeclarationScope(); 1009 return scope->AsDeclarationScope();
1010 } 1010 }
1011 1011
1012 ModuleScope* Scope::GetModuleScope() {
1013 Scope* scope = this;
1014 DCHECK(!scope->is_script_scope());
1015 while (!scope->is_module_scope()) {
1016 scope = scope->outer_scope();
1017 DCHECK_NOT_NULL(scope);
1018 }
1019 return scope->AsModuleScope();
1020 }
1021
1012 DeclarationScope* Scope::GetReceiverScope() { 1022 DeclarationScope* Scope::GetReceiverScope() {
1013 Scope* scope = this; 1023 Scope* scope = this;
1014 while (!scope->is_script_scope() && 1024 while (!scope->is_script_scope() &&
1015 (!scope->is_function_scope() || 1025 (!scope->is_function_scope() ||
1016 scope->AsDeclarationScope()->is_arrow_scope())) { 1026 scope->AsDeclarationScope()->is_arrow_scope())) {
1017 scope = scope->outer_scope(); 1027 scope = scope->outer_scope();
1018 } 1028 }
1019 return scope->AsDeclarationScope(); 1029 return scope->AsDeclarationScope();
1020 } 1030 }
1021 1031
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 Variable* function = 1697 Variable* function =
1688 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1698 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1689 bool is_function_var_in_context = 1699 bool is_function_var_in_context =
1690 function != nullptr && function->IsContextSlot(); 1700 function != nullptr && function->IsContextSlot();
1691 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1701 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1692 (is_function_var_in_context ? 1 : 0); 1702 (is_function_var_in_context ? 1 : 0);
1693 } 1703 }
1694 1704
1695 } // namespace internal 1705 } // namespace internal
1696 } // namespace v8 1706 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698