| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/scopes.h" | 7 #include "src/scopes.h" |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 VariableMap::VariableMap(Zone* zone) | 27 VariableMap::VariableMap(Zone* zone) |
| 28 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), | 28 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), |
| 29 zone_(zone) {} | 29 zone_(zone) {} |
| 30 VariableMap::~VariableMap() {} | 30 VariableMap::~VariableMap() {} |
| 31 | 31 |
| 32 | 32 |
| 33 Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, | 33 Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, |
| 34 VariableMode mode, bool is_valid_lhs, | 34 VariableMode mode, bool is_valid_lhs, |
| 35 Variable::Kind kind, | 35 Variable::Kind kind, |
| 36 InitializationFlag initialization_flag, | 36 InitializationFlag initialization_flag, |
| 37 MaybeAssignedFlag maybe_assigned_flag, | 37 MaybeAssignedFlag maybe_assigned_flag) { |
| 38 Interface* interface) { | |
| 39 // AstRawStrings are unambiguous, i.e., the same string is always represented | 38 // AstRawStrings are unambiguous, i.e., the same string is always represented |
| 40 // by the same AstRawString*. | 39 // by the same AstRawString*. |
| 41 // FIXME(marja): fix the type of Lookup. | 40 // FIXME(marja): fix the type of Lookup. |
| 42 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash(), | 41 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash(), |
| 43 true, ZoneAllocationPolicy(zone())); | 42 true, ZoneAllocationPolicy(zone())); |
| 44 if (p->value == NULL) { | 43 if (p->value == NULL) { |
| 45 // The variable has not been declared yet -> insert it. | 44 // The variable has not been declared yet -> insert it. |
| 46 DCHECK(p->key == name); | 45 DCHECK(p->key == name); |
| 47 p->value = new (zone()) | 46 p->value = new (zone()) Variable(scope, name, mode, is_valid_lhs, kind, |
| 48 Variable(scope, name, mode, is_valid_lhs, kind, initialization_flag, | 47 initialization_flag, maybe_assigned_flag); |
| 49 maybe_assigned_flag, interface); | |
| 50 } | 48 } |
| 51 return reinterpret_cast<Variable*>(p->value); | 49 return reinterpret_cast<Variable*>(p->value); |
| 52 } | 50 } |
| 53 | 51 |
| 54 | 52 |
| 55 Variable* VariableMap::Lookup(const AstRawString* name) { | 53 Variable* VariableMap::Lookup(const AstRawString* name) { |
| 56 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash(), | 54 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash(), |
| 57 false, ZoneAllocationPolicy(NULL)); | 55 false, ZoneAllocationPolicy(NULL)); |
| 58 if (p != NULL) { | 56 if (p != NULL) { |
| 59 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); | 57 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 rest_parameter_ = var; | 464 rest_parameter_ = var; |
| 467 rest_index_ = num_parameters(); | 465 rest_index_ = num_parameters(); |
| 468 } | 466 } |
| 469 params_.Add(var, zone()); | 467 params_.Add(var, zone()); |
| 470 return var; | 468 return var; |
| 471 } | 469 } |
| 472 | 470 |
| 473 | 471 |
| 474 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 472 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
| 475 InitializationFlag init_flag, | 473 InitializationFlag init_flag, |
| 476 MaybeAssignedFlag maybe_assigned_flag, | 474 MaybeAssignedFlag maybe_assigned_flag) { |
| 477 Interface* interface) { | |
| 478 DCHECK(!already_resolved()); | 475 DCHECK(!already_resolved()); |
| 479 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 476 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are |
| 480 // introduces during variable allocation, INTERNAL variables are allocated | 477 // introduces during variable allocation, INTERNAL variables are allocated |
| 481 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). | 478 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). |
| 482 DCHECK(IsDeclaredVariableMode(mode)); | 479 DCHECK(IsDeclaredVariableMode(mode)); |
| 483 ++num_var_or_const_; | 480 ++num_var_or_const_; |
| 484 return variables_.Declare(this, name, mode, true, Variable::NORMAL, init_flag, | 481 return variables_.Declare(this, name, mode, true, Variable::NORMAL, init_flag, |
| 485 maybe_assigned_flag, interface); | 482 maybe_assigned_flag); |
| 486 } | 483 } |
| 487 | 484 |
| 488 | 485 |
| 489 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { | 486 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { |
| 490 DCHECK(is_script_scope()); | 487 DCHECK(is_script_scope()); |
| 491 return variables_.Declare(this, | 488 return variables_.Declare(this, |
| 492 name, | 489 name, |
| 493 DYNAMIC_GLOBAL, | 490 DYNAMIC_GLOBAL, |
| 494 true, | 491 true, |
| 495 Variable::NORMAL, | 492 Variable::NORMAL, |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 | 1094 |
| 1098 case DYNAMIC_LOOKUP: | 1095 case DYNAMIC_LOOKUP: |
| 1099 // The variable could not be resolved statically. | 1096 // The variable could not be resolved statically. |
| 1100 var = NonLocal(proxy->raw_name(), DYNAMIC); | 1097 var = NonLocal(proxy->raw_name(), DYNAMIC); |
| 1101 break; | 1098 break; |
| 1102 } | 1099 } |
| 1103 | 1100 |
| 1104 DCHECK(var != NULL); | 1101 DCHECK(var != NULL); |
| 1105 if (proxy->is_assigned()) var->set_maybe_assigned(); | 1102 if (proxy->is_assigned()) var->set_maybe_assigned(); |
| 1106 | 1103 |
| 1107 if (FLAG_harmony_modules) { | |
| 1108 bool ok; | |
| 1109 #ifdef DEBUG | |
| 1110 if (FLAG_print_interface_details) { | |
| 1111 PrintF("# Resolve %.*s:\n", var->raw_name()->length(), | |
| 1112 var->raw_name()->raw_data()); | |
| 1113 } | |
| 1114 #endif | |
| 1115 proxy->interface()->Unify(var->interface(), zone(), &ok); | |
| 1116 if (!ok) { | |
| 1117 #ifdef DEBUG | |
| 1118 if (FLAG_print_interfaces) { | |
| 1119 PrintF("SCOPES TYPE ERROR\n"); | |
| 1120 PrintF("proxy: "); | |
| 1121 proxy->interface()->Print(); | |
| 1122 PrintF("var: "); | |
| 1123 var->interface()->Print(); | |
| 1124 } | |
| 1125 #endif | |
| 1126 | |
| 1127 // Inconsistent use of module. Throw a syntax error. | |
| 1128 // TODO(rossberg): generate more helpful error message. | |
| 1129 MessageLocation location( | |
| 1130 info->script(), proxy->position(), proxy->position()); | |
| 1131 Isolate* isolate = info->isolate(); | |
| 1132 Factory* factory = isolate->factory(); | |
| 1133 Handle<JSArray> array = factory->NewJSArray(1); | |
| 1134 JSObject::SetElement(array, 0, var->name(), NONE, STRICT).Assert(); | |
| 1135 Handle<Object> error; | |
| 1136 MaybeHandle<Object> maybe_error = | |
| 1137 factory->NewSyntaxError("module_type_error", array); | |
| 1138 if (maybe_error.ToHandle(&error)) isolate->Throw(*error, &location); | |
| 1139 return false; | |
| 1140 } | |
| 1141 } | |
| 1142 | |
| 1143 proxy->BindTo(var); | 1104 proxy->BindTo(var); |
| 1144 | 1105 |
| 1145 return true; | 1106 return true; |
| 1146 } | 1107 } |
| 1147 | 1108 |
| 1148 | 1109 |
| 1149 bool Scope::ResolveVariablesRecursively(CompilationInfo* info, | 1110 bool Scope::ResolveVariablesRecursively(CompilationInfo* info, |
| 1150 AstNodeFactory* factory) { | 1111 AstNodeFactory* factory) { |
| 1151 DCHECK(info->script_scope()->is_script_scope()); | 1112 DCHECK(info->script_scope()->is_script_scope()); |
| 1152 | 1113 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 } | 1399 } |
| 1439 | 1400 |
| 1440 | 1401 |
| 1441 int Scope::ContextLocalCount() const { | 1402 int Scope::ContextLocalCount() const { |
| 1442 if (num_heap_slots() == 0) return 0; | 1403 if (num_heap_slots() == 0) return 0; |
| 1443 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1404 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1444 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1405 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1445 } | 1406 } |
| 1446 | 1407 |
| 1447 } } // namespace v8::internal | 1408 } } // namespace v8::internal |
| OLD | NEW |