| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // | 45 // |
| 46 // Note: We are storing the handle locations as key values in the hash map. | 46 // Note: We are storing the handle locations as key values in the hash map. |
| 47 // When inserting a new variable via Declare(), we rely on the fact that | 47 // When inserting a new variable via Declare(), we rely on the fact that |
| 48 // the handle location remains alive for the duration of that variable | 48 // the handle location remains alive for the duration of that variable |
| 49 // use. Because a Variable holding a handle with the same location exists | 49 // use. Because a Variable holding a handle with the same location exists |
| 50 // this is ensured. | 50 // this is ensured. |
| 51 | 51 |
| 52 static bool Match(void* key1, void* key2) { | 52 static bool Match(void* key1, void* key2) { |
| 53 String* name1 = *reinterpret_cast<String**>(key1); | 53 String* name1 = *reinterpret_cast<String**>(key1); |
| 54 String* name2 = *reinterpret_cast<String**>(key2); | 54 String* name2 = *reinterpret_cast<String**>(key2); |
| 55 ASSERT(name1->IsSymbol()); | 55 ASSERT(name1->IsInternalizedString()); |
| 56 ASSERT(name2->IsSymbol()); | 56 ASSERT(name2->IsInternalizedString()); |
| 57 return name1 == name2; | 57 return name1 == name2; |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 VariableMap::VariableMap(Zone* zone) | 61 VariableMap::VariableMap(Zone* zone) |
| 62 : ZoneHashMap(Match, 8, ZoneAllocationPolicy(zone)), | 62 : ZoneHashMap(Match, 8, ZoneAllocationPolicy(zone)), |
| 63 zone_(zone) {} | 63 zone_(zone) {} |
| 64 VariableMap::~VariableMap() {} | 64 VariableMap::~VariableMap() {} |
| 65 | 65 |
| 66 | 66 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 kCreatedInitialized); | 175 kCreatedInitialized); |
| 176 AllocateHeapSlot(variable); | 176 AllocateHeapSlot(variable); |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 void Scope::SetDefaults(ScopeType type, | 180 void Scope::SetDefaults(ScopeType type, |
| 181 Scope* outer_scope, | 181 Scope* outer_scope, |
| 182 Handle<ScopeInfo> scope_info) { | 182 Handle<ScopeInfo> scope_info) { |
| 183 outer_scope_ = outer_scope; | 183 outer_scope_ = outer_scope; |
| 184 type_ = type; | 184 type_ = type; |
| 185 scope_name_ = isolate_->factory()->empty_symbol(); | 185 scope_name_ = isolate_->factory()->empty_string(); |
| 186 dynamics_ = NULL; | 186 dynamics_ = NULL; |
| 187 receiver_ = NULL; | 187 receiver_ = NULL; |
| 188 function_ = NULL; | 188 function_ = NULL; |
| 189 arguments_ = NULL; | 189 arguments_ = NULL; |
| 190 illegal_redecl_ = NULL; | 190 illegal_redecl_ = NULL; |
| 191 scope_inside_with_ = false; | 191 scope_inside_with_ = false; |
| 192 scope_contains_with_ = false; | 192 scope_contains_with_ = false; |
| 193 scope_calls_eval_ = false; | 193 scope_calls_eval_ = false; |
| 194 // Inherit the strict mode from the parent scope. | 194 // Inherit the strict mode from the parent scope. |
| 195 language_mode_ = (outer_scope != NULL) | 195 language_mode_ = (outer_scope != NULL) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // Declare and allocate receiver (even for the global scope, and even | 328 // Declare and allocate receiver (even for the global scope, and even |
| 329 // if naccesses_ == 0). | 329 // if naccesses_ == 0). |
| 330 // NOTE: When loading parameters in the global scope, we must take | 330 // NOTE: When loading parameters in the global scope, we must take |
| 331 // care not to access them as properties of the global object, but | 331 // care not to access them as properties of the global object, but |
| 332 // instead load them directly from the stack. Currently, the only | 332 // instead load them directly from the stack. Currently, the only |
| 333 // such parameter is 'this' which is passed on the stack when | 333 // such parameter is 'this' which is passed on the stack when |
| 334 // invoking scripts | 334 // invoking scripts |
| 335 if (is_declaration_scope()) { | 335 if (is_declaration_scope()) { |
| 336 Variable* var = | 336 Variable* var = |
| 337 variables_.Declare(this, | 337 variables_.Declare(this, |
| 338 isolate_->factory()->this_symbol(), | 338 isolate_->factory()->this_string(), |
| 339 VAR, | 339 VAR, |
| 340 false, | 340 false, |
| 341 Variable::THIS, | 341 Variable::THIS, |
| 342 kCreatedInitialized); | 342 kCreatedInitialized); |
| 343 var->AllocateTo(Variable::PARAMETER, -1); | 343 var->AllocateTo(Variable::PARAMETER, -1); |
| 344 receiver_ = var; | 344 receiver_ = var; |
| 345 } else { | 345 } else { |
| 346 ASSERT(outer_scope() != NULL); | 346 ASSERT(outer_scope() != NULL); |
| 347 receiver_ = outer_scope()->receiver(); | 347 receiver_ = outer_scope()->receiver(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 if (is_function_scope()) { | 350 if (is_function_scope()) { |
| 351 // Declare 'arguments' variable which exists in all functions. | 351 // Declare 'arguments' variable which exists in all functions. |
| 352 // Note that it might never be accessed, in which case it won't be | 352 // Note that it might never be accessed, in which case it won't be |
| 353 // allocated during variable allocation. | 353 // allocated during variable allocation. |
| 354 variables_.Declare(this, | 354 variables_.Declare(this, |
| 355 isolate_->factory()->arguments_symbol(), | 355 isolate_->factory()->arguments_string(), |
| 356 VAR, | 356 VAR, |
| 357 true, | 357 true, |
| 358 Variable::ARGUMENTS, | 358 Variable::ARGUMENTS, |
| 359 kCreatedInitialized); | 359 kCreatedInitialized); |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 | 362 |
| 363 | 363 |
| 364 Scope* Scope::FinalizeBlockScope() { | 364 Scope* Scope::FinalizeBlockScope() { |
| 365 ASSERT(is_block_scope()); | 365 ASSERT(is_block_scope()); |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 return var->has_forced_context_allocation() || | 1191 return var->has_forced_context_allocation() || |
| 1192 scope_calls_eval_ || | 1192 scope_calls_eval_ || |
| 1193 inner_scope_calls_eval_ || | 1193 inner_scope_calls_eval_ || |
| 1194 scope_contains_with_; | 1194 scope_contains_with_; |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 | 1197 |
| 1198 bool Scope::HasArgumentsParameter() { | 1198 bool Scope::HasArgumentsParameter() { |
| 1199 for (int i = 0; i < params_.length(); i++) { | 1199 for (int i = 0; i < params_.length(); i++) { |
| 1200 if (params_[i]->name().is_identical_to( | 1200 if (params_[i]->name().is_identical_to( |
| 1201 isolate_->factory()->arguments_symbol())) { | 1201 isolate_->factory()->arguments_string())) { |
| 1202 return true; | 1202 return true; |
| 1203 } | 1203 } |
| 1204 } | 1204 } |
| 1205 return false; | 1205 return false; |
| 1206 } | 1206 } |
| 1207 | 1207 |
| 1208 | 1208 |
| 1209 void Scope::AllocateStackSlot(Variable* var) { | 1209 void Scope::AllocateStackSlot(Variable* var) { |
| 1210 var->AllocateTo(Variable::LOCAL, num_stack_slots_++); | 1210 var->AllocateTo(Variable::LOCAL, num_stack_slots_++); |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 | 1213 |
| 1214 void Scope::AllocateHeapSlot(Variable* var) { | 1214 void Scope::AllocateHeapSlot(Variable* var) { |
| 1215 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++); | 1215 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++); |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 | 1218 |
| 1219 void Scope::AllocateParameterLocals() { | 1219 void Scope::AllocateParameterLocals() { |
| 1220 ASSERT(is_function_scope()); | 1220 ASSERT(is_function_scope()); |
| 1221 Variable* arguments = LocalLookup(isolate_->factory()->arguments_symbol()); | 1221 Variable* arguments = LocalLookup(isolate_->factory()->arguments_string()); |
| 1222 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly | 1222 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly |
| 1223 | 1223 |
| 1224 bool uses_nonstrict_arguments = false; | 1224 bool uses_nonstrict_arguments = false; |
| 1225 | 1225 |
| 1226 if (MustAllocate(arguments) && !HasArgumentsParameter()) { | 1226 if (MustAllocate(arguments) && !HasArgumentsParameter()) { |
| 1227 // 'arguments' is used. Unless there is also a parameter called | 1227 // 'arguments' is used. Unless there is also a parameter called |
| 1228 // 'arguments', we must be conservative and allocate all parameters to | 1228 // 'arguments', we must be conservative and allocate all parameters to |
| 1229 // the context assuming they will be captured by the arguments object. | 1229 // the context assuming they will be captured by the arguments object. |
| 1230 // If we have a parameter named 'arguments', a (new) value is always | 1230 // If we have a parameter named 'arguments', a (new) value is always |
| 1231 // assigned to it via the function invocation. Then 'arguments' denotes | 1231 // assigned to it via the function invocation. Then 'arguments' denotes |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 var->AllocateTo(Variable::PARAMETER, i); | 1267 var->AllocateTo(Variable::PARAMETER, i); |
| 1268 } | 1268 } |
| 1269 } | 1269 } |
| 1270 } | 1270 } |
| 1271 } | 1271 } |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 | 1274 |
| 1275 void Scope::AllocateNonParameterLocal(Variable* var) { | 1275 void Scope::AllocateNonParameterLocal(Variable* var) { |
| 1276 ASSERT(var->scope() == this); | 1276 ASSERT(var->scope() == this); |
| 1277 ASSERT(!var->IsVariable(isolate_->factory()->result_symbol()) || | 1277 ASSERT(!var->IsVariable(isolate_->factory()->result_string()) || |
| 1278 !var->IsStackLocal()); | 1278 !var->IsStackLocal()); |
| 1279 if (var->IsUnallocated() && MustAllocate(var)) { | 1279 if (var->IsUnallocated() && MustAllocate(var)) { |
| 1280 if (MustAllocateInContext(var)) { | 1280 if (MustAllocateInContext(var)) { |
| 1281 AllocateHeapSlot(var); | 1281 AllocateHeapSlot(var); |
| 1282 } else { | 1282 } else { |
| 1283 AllocateStackSlot(var); | 1283 AllocateStackSlot(var); |
| 1284 } | 1284 } |
| 1285 } | 1285 } |
| 1286 } | 1286 } |
| 1287 | 1287 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 | 1352 |
| 1353 // Allocation done. | 1353 // Allocation done. |
| 1354 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1354 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 | 1357 |
| 1358 void Scope::AllocateModulesRecursively(Scope* host_scope) { | 1358 void Scope::AllocateModulesRecursively(Scope* host_scope) { |
| 1359 if (already_resolved()) return; | 1359 if (already_resolved()) return; |
| 1360 if (is_module_scope()) { | 1360 if (is_module_scope()) { |
| 1361 ASSERT(interface_->IsFrozen()); | 1361 ASSERT(interface_->IsFrozen()); |
| 1362 Handle<String> name = isolate_->factory()->LookupOneByteSymbol( | 1362 Handle<String> name = isolate_->factory()->InternalizeOneByteString( |
| 1363 STATIC_ASCII_VECTOR(".module")); | 1363 STATIC_ASCII_VECTOR(".module")); |
| 1364 ASSERT(module_var_ == NULL); | 1364 ASSERT(module_var_ == NULL); |
| 1365 module_var_ = host_scope->NewInternal(name); | 1365 module_var_ = host_scope->NewInternal(name); |
| 1366 ++host_scope->num_modules_; | 1366 ++host_scope->num_modules_; |
| 1367 } | 1367 } |
| 1368 | 1368 |
| 1369 for (int i = 0; i < inner_scopes_.length(); i++) { | 1369 for (int i = 0; i < inner_scopes_.length(); i++) { |
| 1370 Scope* inner_scope = inner_scopes_.at(i); | 1370 Scope* inner_scope = inner_scopes_.at(i); |
| 1371 inner_scope->AllocateModulesRecursively(host_scope); | 1371 inner_scope->AllocateModulesRecursively(host_scope); |
| 1372 } | 1372 } |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 | 1375 |
| 1376 int Scope::StackLocalCount() const { | 1376 int Scope::StackLocalCount() const { |
| 1377 return num_stack_slots() - | 1377 return num_stack_slots() - |
| 1378 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1378 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
| 1379 } | 1379 } |
| 1380 | 1380 |
| 1381 | 1381 |
| 1382 int Scope::ContextLocalCount() const { | 1382 int Scope::ContextLocalCount() const { |
| 1383 if (num_heap_slots() == 0) return 0; | 1383 if (num_heap_slots() == 0) return 0; |
| 1384 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1384 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1385 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1385 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1386 } | 1386 } |
| 1387 | 1387 |
| 1388 } } // namespace v8::internal | 1388 } } // namespace v8::internal |
| OLD | NEW |