| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 int start = scope_info->ContextLocalNameEntriesIndex(); | 301 int start = scope_info->ContextLocalNameEntriesIndex(); |
| 302 int end = scope_info->ContextLocalNameEntriesIndex() + | 302 int end = scope_info->ContextLocalNameEntriesIndex() + |
| 303 scope_info->ContextLocalCount(); | 303 scope_info->ContextLocalCount(); |
| 304 for (int i = start; i < end; ++i) { | 304 for (int i = start; i < end; ++i) { |
| 305 if (*name == scope_info->get(i)) { | 305 if (*name == scope_info->get(i)) { |
| 306 int var = i - start; | 306 int var = i - start; |
| 307 *mode = scope_info->ContextLocalMode(var); | 307 *mode = scope_info->ContextLocalMode(var); |
| 308 *init_flag = scope_info->ContextLocalInitFlag(var); | 308 *init_flag = scope_info->ContextLocalInitFlag(var); |
| 309 result = Context::MIN_CONTEXT_SLOTS + var; | 309 result = Context::MIN_CONTEXT_SLOTS + var; |
| 310 context_slot_cache->Update( | 310 context_slot_cache->Update(scope_info, name, *mode, *init_flag, result); |
| 311 *scope_info, *name, *mode, *init_flag, result); | |
| 312 ASSERT(result < scope_info->ContextLength()); | 311 ASSERT(result < scope_info->ContextLength()); |
| 313 return result; | 312 return result; |
| 314 } | 313 } |
| 315 } | 314 } |
| 316 // Cache as not found. Mode and init flag don't matter. | 315 // Cache as not found. Mode and init flag don't matter. |
| 317 context_slot_cache->Update( | 316 context_slot_cache->Update( |
| 318 *scope_info, *name, INTERNAL, kNeedsInitialization, -1); | 317 scope_info, name, INTERNAL, kNeedsInitialization, -1); |
| 319 } | 318 } |
| 320 return -1; | 319 return -1; |
| 321 } | 320 } |
| 322 | 321 |
| 323 | 322 |
| 324 int ScopeInfo::ParameterIndex(String* name) { | 323 int ScopeInfo::ParameterIndex(String* name) { |
| 325 ASSERT(name->IsInternalizedString()); | 324 ASSERT(name->IsInternalizedString()); |
| 326 if (length() > 0) { | 325 if (length() > 0) { |
| 327 // We must read parameters from the end since for | 326 // We must read parameters from the end since for |
| 328 // multiply declared parameters the value of the | 327 // multiply declared parameters the value of the |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 if ((key.data == data) && key.name->Equals(name)) { | 424 if ((key.data == data) && key.name->Equals(name)) { |
| 426 Value result(values_[index]); | 425 Value result(values_[index]); |
| 427 if (mode != NULL) *mode = result.mode(); | 426 if (mode != NULL) *mode = result.mode(); |
| 428 if (init_flag != NULL) *init_flag = result.initialization_flag(); | 427 if (init_flag != NULL) *init_flag = result.initialization_flag(); |
| 429 return result.index() + kNotFound; | 428 return result.index() + kNotFound; |
| 430 } | 429 } |
| 431 return kNotFound; | 430 return kNotFound; |
| 432 } | 431 } |
| 433 | 432 |
| 434 | 433 |
| 435 void ContextSlotCache::Update(Object* data, | 434 void ContextSlotCache::Update(Handle<Object> data, |
| 436 String* name, | 435 Handle<String> name, |
| 437 VariableMode mode, | 436 VariableMode mode, |
| 438 InitializationFlag init_flag, | 437 InitializationFlag init_flag, |
| 439 int slot_index) { | 438 int slot_index) { |
| 439 DisallowHeapAllocation no_gc; |
| 440 String* internalized_name; | 440 String* internalized_name; |
| 441 ASSERT(slot_index > kNotFound); | 441 ASSERT(slot_index > kNotFound); |
| 442 if (name->GetIsolate()->heap()->InternalizeStringIfExists( | 442 if (name->GetIsolate()->heap()->InternalizeStringIfExists( |
| 443 name, &internalized_name)) { | 443 *name, &internalized_name)) { |
| 444 int index = Hash(data, internalized_name); | 444 int index = Hash(*data, internalized_name); |
| 445 Key& key = keys_[index]; | 445 Key& key = keys_[index]; |
| 446 key.data = data; | 446 key.data = *data; |
| 447 key.name = internalized_name; | 447 key.name = internalized_name; |
| 448 // Please note value only takes a uint as index. | 448 // Please note value only takes a uint as index. |
| 449 values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); | 449 values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); |
| 450 #ifdef DEBUG | 450 #ifdef DEBUG |
| 451 ValidateEntry(data, name, mode, init_flag, slot_index); | 451 ValidateEntry(data, name, mode, init_flag, slot_index); |
| 452 #endif | 452 #endif |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 | 456 |
| 457 void ContextSlotCache::Clear() { | 457 void ContextSlotCache::Clear() { |
| 458 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; | 458 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; |
| 459 } | 459 } |
| 460 | 460 |
| 461 | 461 |
| 462 #ifdef DEBUG | 462 #ifdef DEBUG |
| 463 | 463 |
| 464 void ContextSlotCache::ValidateEntry(Object* data, | 464 void ContextSlotCache::ValidateEntry(Handle<Object> data, |
| 465 String* name, | 465 Handle<String> name, |
| 466 VariableMode mode, | 466 VariableMode mode, |
| 467 InitializationFlag init_flag, | 467 InitializationFlag init_flag, |
| 468 int slot_index) { | 468 int slot_index) { |
| 469 DisallowHeapAllocation no_gc; |
| 469 String* internalized_name; | 470 String* internalized_name; |
| 470 if (name->GetIsolate()->heap()->InternalizeStringIfExists( | 471 if (name->GetIsolate()->heap()->InternalizeStringIfExists( |
| 471 name, &internalized_name)) { | 472 *name, &internalized_name)) { |
| 472 int index = Hash(data, name); | 473 int index = Hash(*data, *name); |
| 473 Key& key = keys_[index]; | 474 Key& key = keys_[index]; |
| 474 ASSERT(key.data == data); | 475 ASSERT(key.data == *data); |
| 475 ASSERT(key.name->Equals(name)); | 476 ASSERT(key.name->Equals(*name)); |
| 476 Value result(values_[index]); | 477 Value result(values_[index]); |
| 477 ASSERT(result.mode() == mode); | 478 ASSERT(result.mode() == mode); |
| 478 ASSERT(result.initialization_flag() == init_flag); | 479 ASSERT(result.initialization_flag() == init_flag); |
| 479 ASSERT(result.index() + kNotFound == slot_index); | 480 ASSERT(result.index() + kNotFound == slot_index); |
| 480 } | 481 } |
| 481 } | 482 } |
| 482 | 483 |
| 483 | 484 |
| 484 static void PrintList(const char* list_name, | 485 static void PrintList(const char* list_name, |
| 485 int nof_internal_slots, | 486 int nof_internal_slots, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } else { | 550 } else { |
| 550 ASSERT(var->index() >= 0); | 551 ASSERT(var->index() >= 0); |
| 551 info->set_index(i, var->index()); | 552 info->set_index(i, var->index()); |
| 552 } | 553 } |
| 553 } | 554 } |
| 554 ASSERT(i == info->length()); | 555 ASSERT(i == info->length()); |
| 555 return info; | 556 return info; |
| 556 } | 557 } |
| 557 | 558 |
| 558 } } // namespace v8::internal | 559 } } // namespace v8::internal |
| OLD | NEW |