| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "v8.h" | 7 #include "v8.h" |
| 8 | 8 |
| 9 #include "scopeinfo.h" | 9 #include "scopeinfo.h" |
| 10 #include "scopes.h" | 10 #include "scopes.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 for (int i = start; i < end; ++i) { | 274 for (int i = start; i < end; ++i) { |
| 275 if (name == get(i)) { | 275 if (name == get(i)) { |
| 276 return i - start; | 276 return i - start; |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 return -1; | 280 return -1; |
| 281 } | 281 } |
| 282 | 282 |
| 283 | 283 |
| 284 int ScopeInfo::ContextSlotIndex(String* name, | 284 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, |
| 285 Handle<String> name, |
| 285 VariableMode* mode, | 286 VariableMode* mode, |
| 286 InitializationFlag* init_flag) { | 287 InitializationFlag* init_flag) { |
| 287 ASSERT(name->IsInternalizedString()); | 288 ASSERT(name->IsInternalizedString()); |
| 288 ASSERT(mode != NULL); | 289 ASSERT(mode != NULL); |
| 289 ASSERT(init_flag != NULL); | 290 ASSERT(init_flag != NULL); |
| 290 if (length() > 0) { | 291 if (scope_info->length() > 0) { |
| 291 ContextSlotCache* context_slot_cache = GetIsolate()->context_slot_cache(); | 292 ContextSlotCache* context_slot_cache = |
| 292 int result = context_slot_cache->Lookup(this, name, mode, init_flag); | 293 scope_info->GetIsolate()->context_slot_cache(); |
| 294 int result = |
| 295 context_slot_cache->Lookup(*scope_info, *name, mode, init_flag); |
| 293 if (result != ContextSlotCache::kNotFound) { | 296 if (result != ContextSlotCache::kNotFound) { |
| 294 ASSERT(result < ContextLength()); | 297 ASSERT(result < scope_info->ContextLength()); |
| 295 return result; | 298 return result; |
| 296 } | 299 } |
| 297 | 300 |
| 298 int start = ContextLocalNameEntriesIndex(); | 301 int start = scope_info->ContextLocalNameEntriesIndex(); |
| 299 int end = ContextLocalNameEntriesIndex() + ContextLocalCount(); | 302 int end = scope_info->ContextLocalNameEntriesIndex() + |
| 303 scope_info->ContextLocalCount(); |
| 300 for (int i = start; i < end; ++i) { | 304 for (int i = start; i < end; ++i) { |
| 301 if (name == get(i)) { | 305 if (*name == scope_info->get(i)) { |
| 302 int var = i - start; | 306 int var = i - start; |
| 303 *mode = ContextLocalMode(var); | 307 *mode = scope_info->ContextLocalMode(var); |
| 304 *init_flag = ContextLocalInitFlag(var); | 308 *init_flag = scope_info->ContextLocalInitFlag(var); |
| 305 result = Context::MIN_CONTEXT_SLOTS + var; | 309 result = Context::MIN_CONTEXT_SLOTS + var; |
| 306 context_slot_cache->Update(this, name, *mode, *init_flag, result); | 310 context_slot_cache->Update( |
| 307 ASSERT(result < ContextLength()); | 311 *scope_info, *name, *mode, *init_flag, result); |
| 312 ASSERT(result < scope_info->ContextLength()); |
| 308 return result; | 313 return result; |
| 309 } | 314 } |
| 310 } | 315 } |
| 311 // Cache as not found. Mode and init flag don't matter. | 316 // Cache as not found. Mode and init flag don't matter. |
| 312 context_slot_cache->Update(this, name, INTERNAL, kNeedsInitialization, -1); | 317 context_slot_cache->Update( |
| 318 *scope_info, *name, INTERNAL, kNeedsInitialization, -1); |
| 313 } | 319 } |
| 314 return -1; | 320 return -1; |
| 315 } | 321 } |
| 316 | 322 |
| 317 | 323 |
| 318 int ScopeInfo::ParameterIndex(String* name) { | 324 int ScopeInfo::ParameterIndex(String* name) { |
| 319 ASSERT(name->IsInternalizedString()); | 325 ASSERT(name->IsInternalizedString()); |
| 320 if (length() > 0) { | 326 if (length() > 0) { |
| 321 // We must read parameters from the end since for | 327 // We must read parameters from the end since for |
| 322 // multiply declared parameters the value of the | 328 // multiply declared parameters the value of the |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 } else { | 549 } else { |
| 544 ASSERT(var->index() >= 0); | 550 ASSERT(var->index() >= 0); |
| 545 info->set_index(i, var->index()); | 551 info->set_index(i, var->index()); |
| 546 } | 552 } |
| 547 } | 553 } |
| 548 ASSERT(i == info->length()); | 554 ASSERT(i == info->length()); |
| 549 return info; | 555 return info; |
| 550 } | 556 } |
| 551 | 557 |
| 552 } } // namespace v8::internal | 558 } } // namespace v8::internal |
| OLD | NEW |