Chromium Code Reviews| 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) { |
| 440 String* internalized_name; | 439 String* internalized_name; |
|
Yang
2014/04/30 15:14:26
Also add DisallowHeapAllocation scopes in all thos
Igor Sheludko
2014/04/30 17:02:13
Done.
| |
| 441 ASSERT(slot_index > kNotFound); | 440 ASSERT(slot_index > kNotFound); |
| 442 if (name->GetIsolate()->heap()->InternalizeStringIfExists( | 441 if (name->GetIsolate()->heap()->InternalizeStringIfExists( |
| 443 name, &internalized_name)) { | 442 *name, &internalized_name)) { |
| 444 int index = Hash(data, internalized_name); | 443 int index = Hash(*data, internalized_name); |
| 445 Key& key = keys_[index]; | 444 Key& key = keys_[index]; |
| 446 key.data = data; | 445 key.data = *data; |
| 447 key.name = internalized_name; | 446 key.name = internalized_name; |
| 448 // Please note value only takes a uint as index. | 447 // Please note value only takes a uint as index. |
| 449 values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); | 448 values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); |
| 450 #ifdef DEBUG | 449 #ifdef DEBUG |
| 451 ValidateEntry(data, name, mode, init_flag, slot_index); | 450 ValidateEntry(data, name, mode, init_flag, slot_index); |
| 452 #endif | 451 #endif |
| 453 } | 452 } |
| 454 } | 453 } |
| 455 | 454 |
| 456 | 455 |
| 457 void ContextSlotCache::Clear() { | 456 void ContextSlotCache::Clear() { |
| 458 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; | 457 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; |
| 459 } | 458 } |
| 460 | 459 |
| 461 | 460 |
| 462 #ifdef DEBUG | 461 #ifdef DEBUG |
| 463 | 462 |
| 464 void ContextSlotCache::ValidateEntry(Object* data, | 463 void ContextSlotCache::ValidateEntry(Handle<Object> data, |
| 465 String* name, | 464 Handle<String> name, |
| 466 VariableMode mode, | 465 VariableMode mode, |
| 467 InitializationFlag init_flag, | 466 InitializationFlag init_flag, |
| 468 int slot_index) { | 467 int slot_index) { |
| 469 String* internalized_name; | 468 String* internalized_name; |
| 470 if (name->GetIsolate()->heap()->InternalizeStringIfExists( | 469 if (name->GetIsolate()->heap()->InternalizeStringIfExists( |
| 471 name, &internalized_name)) { | 470 *name, &internalized_name)) { |
| 472 int index = Hash(data, name); | 471 int index = Hash(*data, *name); |
| 473 Key& key = keys_[index]; | 472 Key& key = keys_[index]; |
| 474 ASSERT(key.data == data); | 473 ASSERT(key.data == *data); |
| 475 ASSERT(key.name->Equals(name)); | 474 ASSERT(key.name->Equals(*name)); |
| 476 Value result(values_[index]); | 475 Value result(values_[index]); |
| 477 ASSERT(result.mode() == mode); | 476 ASSERT(result.mode() == mode); |
| 478 ASSERT(result.initialization_flag() == init_flag); | 477 ASSERT(result.initialization_flag() == init_flag); |
| 479 ASSERT(result.index() + kNotFound == slot_index); | 478 ASSERT(result.index() + kNotFound == slot_index); |
| 480 } | 479 } |
| 481 } | 480 } |
| 482 | 481 |
| 483 | 482 |
| 484 static void PrintList(const char* list_name, | 483 static void PrintList(const char* list_name, |
| 485 int nof_internal_slots, | 484 int nof_internal_slots, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 } else { | 548 } else { |
| 550 ASSERT(var->index() >= 0); | 549 ASSERT(var->index() >= 0); |
| 551 info->set_index(i, var->index()); | 550 info->set_index(i, var->index()); |
| 552 } | 551 } |
| 553 } | 552 } |
| 554 ASSERT(i == info->length()); | 553 ASSERT(i == info->length()); |
| 555 return info; | 554 return info; |
| 556 } | 555 } |
| 557 | 556 |
| 558 } } // namespace v8::internal | 557 } } // namespace v8::internal |
| OLD | NEW |